6.1.1 Sections
The compiler produces relocatable blocks of code and data called sections. The sections are allocated into memory in a variety of ways to conform to a variety of system configurations. For more information about sections and allocating them, see the introductory object file information in the ARM Assembly Language Tools User's Guide.
There are two basic types of sections:
- Initialized sections contain data or executable code. Initialized sections are usually, but not always, read-only. The C/C++ compiler creates the following initialized sections:
- The .binit section contains boot time copy tables. This is a read-only section. For details on BINIT, see the ARM Assembly Language Tools User's Guide.
- The .init_array section contains global constructor tables.
- The .ovly section contains copy tables for unions in which different sections have the same run address. This is a read-only section.
- The .data section contains initialized global and static variables.
- The .const section contains read-only data, typically string constants and static-scoped objects defined with the C/C++ qualifier const. Note that not all static-scoped objects marked "const" are placed in the .const section (see Section 5.7.1). This is a read-only section.
- contains string constants and data defined with the C/C++ qualifier const (provided the constant is not also defined as volatile).
- The .text section contains all the executable code. It also contains string literals, switch tables, and compiler-generated constants. This section is usually read-only. Note that some string literals may instead be placed in .const:.string. The placement of string literals depends on the size of the string and the use of the --embedded_constants option.
- The .TI.crctab section contains CRC checking tables. This is a read-only section.
- Uninitialized sections reserve space in memory (usually RAM). A program can use this space at run time to create and store variables. The compiler creates the following uninitialized sections:
- For EABI only, the .bss section reserves space for uninitialized global and static variables. Uninitialized variables that are also unused are usually created as common symbols (unless you specify --common=off) instead of being placed in .bss so that they can be excluded from the resulting application.
- The .stack section reserves memory for the C/C++ software stack.
- The .sysmem section reserves space for dynamic memory allocation. This space is used by dynamic memory allocation routines, such as malloc(), calloc(), realloc(), or new(). If a C/C++ program does not use these functions, the compiler does not create the .sysmem section.
The assembler creates the default sections .text, .bss, and .data. You can instruct the compiler to create additional sections by using the CODE_SECTION and DATA_SECTION pragmas (see Section 5.11.5 and Section 5.11.8).
The linker takes the individual sections from different object files and combines sections that have the same name. The resulting output sections and the appropriate placement in memory for each section are listed in Table 6-1. You can place these output sections anywhere in the address space as needed to meet system requirements.
Table 6-1 Summary of Sections and Memory Placement
Section |
Type of Memory |
Section |
Type of Memory |
.bss |
RAM |
.pinit |
ROM or RAM |
.cinit |
ROM or RAM |
.stack |
RAM |
.const |
ROM or RAM |
.sysmem |
RAM |
.data |
RAM |
.text |
ROM or RAM |
.init_array |
ROM or RAM |
|
|
You can use the SECTIONS directive in the linker command file to customize the section-allocation process. For more information about allocating sections into memory, see the linker description chapter in the ARM Assembly Language Tools User's Guide.