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 PRU 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 .args section contains arguments in the argv array to be passed to main. This section is read-only.
- The .binit section contains boot time copy tables. This is a read-only section. For details on BINIT, see the PRU Assembly Language Tools User's Guide.
- The .cinit section contains tables for initializing global data at runtime.
- The .ovly section contains copy tables other than boot time (.binit) copy tables. This is a read-only section.
- The .data section contains initialized near data.
- The .fardata section contains initialized far data.
- The .init_array section contains global constructor tables to be called at startup.
- The .rodata section contains constant read-only near data.
- The .rofardata section contains constant read-only far data.
- The .text section contains all the executable code. This section is usually read-only.
- 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:
- The .bss section reserves space for uninitialized near data (stored at addresses reachable with a 16-bit address).
- The .farbss section reserves space for uninitialized far data (stored at addresses only reachable with a 32-bit address).
- The .stack section reserves memory for the C/C++ software stack.
- The .sysmem section reserves space for dynamic memory allocation. The reserved 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.9.3 and Section 5.9.5).
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 |
.args |
ROM or RAM |
.init_array |
ROM or RAM |
.bss |
RAM |
.rodata |
ROM or RAM |
.cinit |
ROM or RAM |
.rofardata |
ROM or RAM |
.data |
RAM |
.stack |
RAM |
.farbss |
RAM |
.sysmem |
RAM |
.fardata |
ROM or RAM |
.text |
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 PRU Assembly Language Tools User's Guide.