The section function 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
function should appear.
The section function attribute follows the general syntax for function attributes: in the prototype declaration, the attribute specifier follows the function declarator; in the function definition, it precedes the declarator. C++ does not accept the attribute before the function declarator in function definitions. The following diagram shows the supported forms of the function attribute.
>>-__attribute__--((--+-section-----+--(--"section_name"--)--))->< '-__section__-'
where section_name is a string literal.
Each defined function can reside in only one section. The section indicated in a function definition should match that in any previous declaration. The section indicated in a function definition cannot be overwritten, whereas one in a function declaration can be overwritten by a later specification. Moreover, if a section attribute is applied to a function declaration, the function will be placed in the specified section only if it is defined in the same compilation unit.
Related References