SPRUIG8J January 2018 – March 2024
The smallest unit of an object file is a section. A section is a block of code or data that occupies contiguous space in the memory map. Each section of an object file is separate and distinct.
ELF format executable object files contain segments. An ELF segment is a meta-section. It represents a contiguous region of target memory. It is a collection of sections that have the same property, such as writeable or readable. An ELF loader needs the segment information, but does not need the section information. The ELF standard allows the linker to omit ELF section information entirely from the executable object file.
Object files usually contain three default sections:
.text section | Contains executable code (1) |
.data section | Usually contains initialized data |
.bss | Usually reserves space for uninitialized variables |
The linker allows you to create, name, and link other kinds of sections. The .text, .data, and .bss sections are archetypes for how sections are handled.
There are two basic types of sections:
Initialized sections | Contain data or code. The .text and .data sections are initialized. |
Uninitialized sections | Reserve space in the memory map for uninitialized data. The .bss section is uninitialized. |
One of the linker's functions is to relocate sections into the target system's memory map; this function is called placement. Because most systems contain several types of memory, using sections can help you use target memory more efficiently. All sections are independently relocatable; you can place any section into any allocated block of target memory. For example, you can define a section that contains an initialization routine and then allocate the routine in a portion of the memory map that contains ROM. For information on section placement, see Section 11.3.5.
Figure 8-1 shows the relationship between sections in an object file and a hypothetical target memory. ROM may be EEPROM, FLASH or some other type of physical memory in an actual system.