The sections are placed in the following order:
-
By attribute as follows:
- Read-only code.
- Read-only data.
- Read-write code.
- Read-write data.
- Zero-initialized data.
- By input section name if they have the same attributes. Names
are considered to be case-sensitive and are compared in alphabetical order using
the ASCII collation sequence for characters.
- By a tie-breaker if they have the same attributes and section
names. By default, it is the order that armlink processes the section. You can override the tie-breaker
and sorting by input section name with the
FIRST
or LAST
input section
attribute.
Note:
The sorting order is unaffected by ordering of section
selectors within execution regions.
These rules mean that the positions of input sections with identical
attributes and names included from libraries depend on the order the linker
processes objects. This can be difficult to predict when many libraries are present
on the command line. The --tiebreaker=cmdline
option
uses a more predictable order based on the order the section appears on the command
line.
The base address of each input section is determined by the sorting
order defined by the linker, and is correctly aligned within the output section that
contains it.
The linker produces one output section for each attribute present in
the execution region:
- One execute-only (XO) section if
the execution region contains only XO sections.
- One RO section if the execution region contains read-only code
or data.
- One RW section if the execution region contains read-write code
or data.
- One ZI section if the execution region contains zero-initialized
data.
Note:
If an attempt is made to place data in an XO only execution
region, then the linker generates an error.
XO sections lose the XO property if mixed with RO code in the
same Execution region.
The XO and RO output sections can be protected at run-time on systems
that have memory management hardware. RO and XO sections can be placed in ROM or
Flash.
Alternative sorting orders are available with the --sort=algorithm
command-line option. The linker might change
the algorithm
to
minimize the amount of veneers generated if no algorithm is chosen.
Note:
XO memory
is supported only for Arm®v7‑M and Armv8‑M architectures.
Example
The following scatter file shows how the linker places sections:
LoadRegion 0x8000
{
ExecRegion1 0x0000 0x4000
{
*(sections)
*(moresections)
}
ExecRegion2 0x4000 0x2000
{
*(evenmoresections)
}
}
The order of execution regions within the load region is not altered by the
linker.