SPRAB89A September 2011 – March 2014
In a relocatable object file output by the compiler or assembler, variables are allocated into sections using default rules and compiler directives. A section is an indivisible unit of allocation in a relocatable file. Sections often contain objects with similar properties. Various sections are designated for data, depending on whether the section is initialized, whether it is writable or read-only, how it will be addressed, and what kind of data it contains.
The ABI designates static data sections as near or far. Near sections can be addressed using efficient near DP-relative addressing, but their size and placement is constrained. Conventions for placement of static variables into sections and for how they are addressed are covered in Section 4.3.2.
The linker combines sections from object files to form segments in an ELF load module (executable or shared library). A segment is a continuous range of memory allocated to a load module, representing part of the execution image of the program.
A load module may contain one or more data segments, into which the linker allocates stack, heap, and static variables. Items may be grouped into a single segment or multiple segments, subject only to these restrictions:
A segment is designated as DP-relative if it is accessed using DP-relative addressing. A single DP-relative segment may contain a mixture of near and far addressing, provided it meets the constraints listed previously.
The run-time environment can dynamically allocate or resize uninitialized data segments, to allocate space for items such as the stack and heap.
Figure 4-1 shows the data sections defined by the ABI, and an abstract mapping of sections into segments. The mapping is only representative; the specific configuration may vary by platform or system. Initialized sections are shaded blue; uninitialized sections are shaded gray.
The .const and .fardata:.const sections contain read-only constants. The .const section contains position-independent constants. Depending on the platform, the .const section may be in read-only memory, and may be addressed using absolute addressing, or in position-independent models, relative to code via PC-relative addressing. On some platforms such as Linux that share read-only segments, const objects whose initializers contain address constants cannot be shared. Accordingly, they are placed into a distinct section called .fardata:.const, so named because it can be considered part of .fardata, in the data segment.
The .rodata section contains read-only constants addressable with near DP-relative addressing.
The .neardata and .fardata sections contain initialized read-write variables. These sections correspond to the .data section commonly found on other architectures.
The .bss and .far sections contain uninitialized variables.
The .common and .scommon sections contain common-block symbols allocated by the linker. These are not actual sections in the object files. Instead, the section names are a convention in the linker command file for placing variables. These sections should not be used for other purposes.
The .got and .dsbt sections contain data structures related to dynamic linking. See Chapter 6.
Additional special sections that can be placed by the linker command file are listed in Section 13.4.5.