10.7. Default Placement Algorithm

The MEMORY and SECTIONS directives provide flexible methods for building, combining, and allocating sections. However, any memory locations or sections you choose not to specify must still be handled by the linker. The linker uses algorithms to build and allocate sections in coordination with any specifications you do supply.

If you do not use the MEMORY and SECTIONS directives, the linker allocates output sections as though the memory map and section definitions shown in the following example were specified.

{
    RAM      : origin = 0x00000000, length = 0xFFFFFFFF
}

SECTIONS
{
    .text :  ALIGN(4)   {} > RAM
    .const:  ALIGN(4)   {} > RAM
    .rodata: ALIGN(4)   {} > RAM
    .data :  ALIGN(4)   {} > RAM
    .bss  :  ALIGN(4)   {} > RAM
    .cinit:  ALIGN(4)   {} > RAM      /* -c option only */
    .pinit:  ALIGN(4)   {} > RAM      /* -c option only */
}

See Combining Input Sections for information about default memory allocation.

All .text input sections are concatenated to form a .text output section in the executable output file, and all .data input sections are combined to form a .data output section.

If you use a SECTIONS directive, the linker performs no part of this default allocation. Instead, allocation is performed according to the rules specified by the SECTIONS directive and the general algorithm described next in How the Allocation Algorithm Creates Output Sections.

Contents: