__ATTRIBUTE__ is actually a GCC-specific syntax that is used to set function properties, variable properties, class properties
Syntax: Previously mentioned in struct alignment in C, which was used to tell the compiler how to align the struct
, in fact, he has a lot of usage, you can set a lot of properties.
Syntax: __attribute__ (parameter)
For variables:
int a __attribute__ ((xxxxx)) = 10; can also be placed in front of the variable, more flexible
int a __attribute__ ((xxxxx)); can also be placed in front of the variable, more flexible
For structs:
struct info{
.....
} __attribute__ ((xxxxx));
struct info{
.....
} __attribute__ ((xxxxx)) SB;
struct info{
.....
}SB __attribute__ ((xxxxx));
For functions:
void __attribute__ ((xxxxx)) func (void); Note that it can be placed in front of void, as long as
void func (void) __attribute__ ((xxxxx)); is in the left or right of the Func (void)
void __attribute__ ((xxxxx)) func (void)
{
}
For example:
struct fd{
...
...
}__sttribute__ ((Align (4))) FD; Specifies the byte alignment of a struct FD class
int Cpu_mmc_init (bd_t *bis) __attribute__ ((Weak, alias ("__def_mmc_init"));
There are two properties involved:
Weak property: Makes Cpu_mmc_init a weak label (I estimate is an internal link), not a global label
, and even if the Cpu_mmc_init function is undefined, calling the Cpu_mmc_init compiler will not be an error, but
There is no meaning, so it is usually with the alias attribute.
Alias property: Specifies that Cpu_mmc_init is an alias for the later "__def_mmc_init" function, so
If the Cpu_mmc_init function is not defined, then calling Cpu_mmc_init is actually calling __def_mmc_init
function, if the definition does not call this, note that the __def_mmc_init function must be defined.
Unused property: Specifies that the variable or function does not output a warning message if it is not used.
Section property: Specifies that the function or a variable is the last link in our specified segment, Usage: sections
(". U_boot_cmd"), note that the segment name used in our link script is actually a variable form, he is
It doesn't need to be defined, it can be used directly, that is, we can use a segment name arbitrarily in the connection script, if
We have the section in our C that will link to that paragraph, and if not, skip directly. Note that in our
Kernel driver is generally used __section__ to replace our section, the specific differences are unknown.
__ATTRIBUTE__ ((__section__ (". U_kernel_cmd")))
Align property: setting byte alignment
Linux GCC supported syntax __attribute__ property settings