Kenkron
Kenkron

Reputation: 573

What does __devexit mean in a function declaration?

A driver I looked at has

static void __devexit rtsx_remove(struct pci_dev *pci)

What does __devexit mean in the context of the function definition? Other functions I've seen have, at most, static and a return type.

Upvotes: 10

Views: 1540

Answers (3)

Robert
Robert

Reputation: 351

These attributes were used in the Linux Kernel on certain driver functions and data declarations, putting them in a separate section that could be discarded under certain circumstances.

However, they are no longer used (or defined) from 3.10.x onward. See: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=54b956b903607

Upvotes: 1

user3079266
user3079266

Reputation:

Long-ish story short:

This is a macro that expands to a set of gcc attributes. They are a way of providing the compiler with special information about various stuff in your code, like, in this case, a function.

Different compilers have different syntaxis for this purpose, it isn't standartized. For example, gcc uses attributes, but other compilers use different constructs.

Long-ish story long-ish:

So, I'm no Linux kernel expert, but judging by the source code, this macro is used for Hotplug. I believe it signifies that the function should do something with a specific device exiting.

For example, the function you provided seems to be from the set of Hotplug functions for working with a Realtek PCI-Express card reader driver.

What does that macro actually do? Well, let's take a closer look at the macro's definition:

#define __devexit        __section(.devexit.text) __exitused __cold

The first part is __section(.devexit.text):

# define __section(S) __attribute__ ((__section__(#S)))

As you can see, this creates an __attribute__(__section__()) with the section name being ".devexit.text". This means that gcc will compile the assembly code of a function with this attribute into a named section in the compiled binary with the name .devexit.text (instead of the default section).

The second part is __exitused (defined to something only if the MODULE macro is defined):

#define __exitused  __used

And __used is, depending on the gcc version, defined either like this:

# define __used                 __attribute__((__used__))

or like this:

# define __used                 __attribute__((__unused__))

The former makes sure the function that has this attribute is compiled even if it is not referenced anywhere. The latter suppresses compiler warnings in the same case, although it doesn't affect the compilation in any way.

And, finally, __cold:

#define __cold                  __attribute__((__cold__))

This is an attribute that informs the compiler that the function with this attribute is not going to be called often, so that it can optimize accordingly.

Sooo, what do we have in the end? Looks like functions marked with __devexit are just functions that aren't called often (if called at all), and stuffed into a named section.

All the source code was taken from here. It looks like the macro has now actually been removed from the Linux Kernel.

Upvotes: 4

Kenkron
Kenkron

Reputation: 573

"...It is most likely just an annotation..." --barak manos

Eureka! It turns out that the mystery element is maybe called an annotation, which adds extra information about a function. This extra information can be checked by the compiler to catch bugs that might otherwise go unnoticed.

Edit: @MattMcNabb says it's not an annotation. Added uncertainty.

Upvotes: 1

Related Questions