C16 Attributes

Attributes supply compilers with more detailed information on the use of functions or variables. This enables them to apply more precise optimization options in order to generate better code, or permits formulations that would not be possible in normal C. A range of code output details can also be influenced.

GCC supports dozens of attributes for all possible purposes. These are described in the GCC documentation. This section describes the attributes used by the kernel.

Attributes are specified by prefixing the declaration of a variable or function with the keyword _attribute_((list)) as follows:

struct xyy { } _attribute((_aligned_(SMP_CACHE_BYTES))

The following attributes are used in the kernel sources:

□ noreturn is specified if a function does not return to the caller. Optimization contributes to slightly better code (however, because functions that do not return usually cause programs to abort, the fact that the code is better is of little relevance). This attribute is used primarily to prevent compiler warnings about non-initialized variables that can occur in corresponding code.

In the kernel, this keyword is appropriate for functions that trigger a panic or stop the machine once it has been shut down normally.

□ regparam is an IA-32-specific directive that specifies that function arguments are to be passed in registers and not on the stack as they usually would be. It requires a parameter to indicate the maximum number of arguments that can be passed in this way — provided there are enough free registers. Given the scarcity of registers in this architecture, this is never certain. The eax, edx, and ecx registers are used for this purpose.

The kernel defines the following macros that use the attribute:

Continue reading here: Includeasmx86linkage32h

Was this article helpful?

0 0