The section variable attribute specifies the section in the object file in which the compiler should place its generated code. The language feature provides the ability to control the section in which a variable should appear.
section variable attribute syntax >>-declarator---------------------------------------------------> >--__attribute__--((--+-section-----+--(--"--section_name--"--)--))->< '-__section__-'
The section_name specifies a named section as a string literal, maximum length of 16 characters, not counting spaces. Spaces in the string are ignored.
The section variable attribute can be applied to a declaration or definition of the following types of variables:
A section attribute applied to a local variable with automatic storage duration is ignored with a warning because such variables are stored on the stack.
A
section attribute applied to a structure member is ignored with a warning.
A section attribute applied to an uninitialized global variable is ignored
without a warning; the symbols for uninitialized global variables are always
placed in the common section.
When multiple section attributes are applied to a variable declaration, the last specification prevails. The section indicated in the prevailing variable declaration should match that of the variable definition because a variable definition cannot be overwritten. Each defined variable can reside in only one section.
A named section can be used for multiple variables, but not for both variables and functions in the same compilation unit.
Related information