SPRAD28 October 2022 AM2431 , AM2432 , AM2434 , AM2631 , AM2631-Q1 , AM2632 , AM2632-Q1 , AM2634 , AM2634-Q1 , AM263P4 , AM263P4-Q1 , AM26C31 , AM26C31-EP , AM26C31M , AM26C32 , AM26C32-EP , AM26C32C , AM26C32M , AM26LS31 , AM26LS31M , AM26LS32A , AM26LS32AC , AM26LS32AM , AM26LS33A , AM26LS33A-SP , AM26LS33AM , AM26LV31 , AM26LV31E , AM26LV31E-EP , AM26LV32 , AM26LV32E , AM26LV32E-EP , AM26S10 , AM2732 , AM2732-Q1
The SECTIONS directive contains most of the interesting code. The key thing to understand is that the SECTIONS directives does two things at once:
Describing the SECTIONS directive requires an understanding of these terms:
In theory, you cannot know anything about the contents of an input section based on the name alone. Nonetheless, input sections with these names usually have these contents:
Name | Initialized | Notes |
---|---|---|
.text | Yes | Executable code |
.bss | No | Global variables |
.cinit | Yes | Tables which initialize global variables |
.data (EABI) | Yes and No | Initialized coming out of the assembler; changed to uninitialized by the linker |
.data (COFF ABI) | Yes | Initialized data |
.stack | No | System stack |
.sysmem or .heap | No | Malloc heap (malloc(), calloc(), realloc()..) |
.const | Yes | Initialized global variables |
.switch | Yes | Jump tables for certain switch statements |
.init_array or .pinit | Yes | Table of C++ constructors called at startup |
.cio | No | Buffer for stdio functions |
.rodata | Yes | Contains read-only data, typically string constants and static-scoped objects. |
Here is a part of the sections direcative of the Am243x:
Grouping and aligning is done quite often inside linker.cmd file. The assembler generally has a .align directive embedded in code, but doing palign(8) in linker ensures proper alignment. palign(8) is not necessary for code sections, code is typically aligned to 4 byte boundary so that Arm instructions are aligned correctly. It is necessary for sections like the heap and stacks. Other data sections are 8-byte aligned to ensure max data size of long long (64 bits) are aligned. Note that palign only ensures section start and size are 8 byte aligned, it doesn't ensure individual members in sections are aligned.
Grouping is done for various reasons, sections like BSS need grouping so that a symbol for start and end get defined, which is used in C runtime init phase before main to memset BSS section to 0.
Some sections are grouped to enable overlay with other specific sections. For example, ICSS firmware is needed only at initialization and is overlaid with ICSS_MEM section as ICSS_MEM section is used only after firmware is loaded, after which the firmware is no longer required and can be overwritten.
Grouping is generally done as it is easy to check in map file the size of section if is grouped.
In order to understand more of the syntax inside linker.cmd, see the TI Linker Command File Primer