pragma Linker_Section ( [Entity =>] LOCAL_NAME, [Section =>] static_string_EXPRESSION);
LOCAL_NAME must refer to an object, type, or subprogram that is
declared at the library level. This pragma specifies the name of the
linker section for the given entity. It is equivalent to
__attribute__((section)) in GNU C and causes LOCAL_NAME to
be placed in the static_string_EXPRESSION section of the
executable (assuming the linker doesn't rename the section).
GNAT also provides an implementation defined aspect of the same name.
In the case of specifying this aspect for a type, the effect is to specify the corresponding for all library level objects of the type which do not have an explicit linker section set. Note that this only applies to whole objects, not to components of composite objects.
In the case of a subprogram, the linker section applies to all previously declared matching overloaded subprograms in the current declarative part which do not already have a linker section assigned. The linker section aspect is useful in this case for specifying different linker sections for different elements of such an overloaded set.
Note that an empty string specifies that no linker section is specified. This is not quite the same as omitting the pragma or aspect, since it can be used to specify that one element of an overloaded set of subprograms has the default linker section, or that one object of a type for which a linker section is specified should has the default linker section.
The compiler normally places library-level entities in standard sections
depending on the class: procedures and functions generally go in the
.text section, initialized variables in the
and uninitialized variables in the
Other, special sections may exist on given target machines to map special hardware, for example I/O ports or flash memory. This pragma is a means to defer the final layout of the executable to the linker, thus fully working at the symbolic level with the compiler.
Some file formats do not support arbitrary sections so not all target
machines support this pragma. The use of this pragma may cause a program
execution to be erroneous if it is used to place an entity into an
inappropriate section (e.g. a modified variable into the
section). See also
-- Example of the use of pragma Linker_Section package IO_Card is Port_A : Integer; pragma Volatile (Port_A); pragma Linker_Section (Port_A, ".bss.port_a"); Port_B : Integer; pragma Volatile (Port_B); pragma Linker_Section (Port_B, ".bss.port_b"); type Port_Type is new Integer with Linker_Section => ".bss"; PA : Port_Type with Linker_Section => ".bss.PA"; PB : Port_Type; -- ends up in linker section ".bss" procedure Q with Linker_Section => "Qsection"; end IO_Card;