SLAU131V October 2004 – February 2020
The linker assigns each output section two locations in target memory: the location where the section will be loaded and the location where it will be run. Usually, these are the same, and you can think of each section as having only a single address. The process of locating the output section in the target's memory and assigning its address(es) is called placement. For more information about using separate load and run placement, see Section 8.5.6.
If you do not tell the linker how a section is to be allocated, it uses a default algorithm to place the section. Generally, the linker puts sections wherever they fit into configured memory. You can override this default placement for a section by defining it within a SECTIONS directive and providing instructions on how to allocate it.
You control placement by specifying one or more allocation parameters. Each parameter consists of a keyword, an optional equal sign or greater-than sign, and a value optionally enclosed in parentheses. If load and run placement are separate, all parameters following the keyword LOAD apply to load placement, and those following the keyword RUN apply to run placement. The allocation parameters are:
Binding | allocates a section at a specific address.
.text: load = 0x1000
|
Named memory | allocates the section into a range defined in the MEMORY directive with the specified name (like SLOW_MEM) or attributes.
.text: load > SLOW_MEM
|
Alignment | uses the align or palign keyword to specify the section must start on an address boundary.
.text: align = 0x100
|
Blocking | uses the block keyword to specify the section must fit between two address aligned to the blocking factor. If a section is too large, it starts on an address boundary.
.text: block(0x100)
|
For the load (usually the only) allocation, use a greater-than sign and omit the load keyword:
.text: > SLOW_MEM
.text: {...} > SLOW_MEM
.text: > 0x4000
If more than one parameter is used, you can string them together as follows:
.text: > SLOW_MEM align 16
Or if you prefer, use parentheses for readability:
.text: load = (SLOW_MEM align(16))
You can also use an input section specification to identify the sections from input files that are combined to form an output section. See Section 8.5.5.3.
Additional information about controlling the order in which code and data are placed in memory is provided in the FAQ topic on section placement.