How the linker resolves multiple matches when processing scatter files
An input section must be unique. In the case of multiple matches, the linker attempts to assign the input section to a region based on the attributes of the input section description.
The linker assignment of the input section is based on a
and module_select_pattern
pair that is the most specific.
However, if a unique match cannot be found, the linker faults the scatter-loading
description.input_section_selector
The following variables describe how the linker matches multiple input sections:
m1
andm2
represent module selector patterns.s1
ands2
represent input section selectors.
For example, if input section A matches m1,s1
for execution region
R1, and A matches m2,s2
for execution region R2, the linker:
- Assigns A to R1 if
m1,s1
is more specific thanm2,s2
. - Assigns A to R2 if
m2,s2
is more specific thanm1,s1
. - Diagnoses the scatter-loading description as faulty if
m1,s1
is not more specific thanm2,s2
andm2,s2
is not more specific thanm1,s1
.
armlink
uses the following strategy
to determine the most specific
, module_select_pattern
pair:input_section_selector
- Resolving the priority of two module_selector, section_selector pairs m1, s1 and m2, s2
-
The strategy starts with two
pairs.module_select_pattern, input_section_selector
m1,s1
is more specific thanm2,s2
only if any of the following are true:s1
is either a literal input section name, that is it contains no pattern characters, or a section type ands2
matches input section attributes.m1
is more specific thanm2
.s1
is more specific thans2
.
The conditions are tested in order so condition 1 takes precedence over condition 2 and 3, and condition 2 takes precedence over condition 3.
- Resolving the priority of two module selectors m1 and m2 in isolation
- For the module selector patterns,
m1
is more specific thanm2
if the text stringm1
matches patternm2
and the text stringm2
does not match patternm1
. - Resolving the priority of two section selectors s1 and s2 in isolation
-
For the input section selectors:
- If one of
s1
ors2
matches the input section name or type and the other matches the input section attributes,s1
ands2
are unordered and the description is diagnosed as faulty. - If both
s1
ands2
match the input section name or type, the following relationships determine whether s1 is more specific than s2:- Section type is more specific than section name.
- If both
s1
ands2
match input section type,s1
ands2
are unordered and the description is diagnosed as faulty. - If
s1
ands2
are both patterns matching section names, the same definition as for module selector patterns is used.
- If both
s1
ands2
match input section attributes, the following relationships determine whethers1
is more specific thans2
s:ENTRY
is more specific thanRO-CODE
,RO-DATA
,RW-CODE
, orRW-DATA
.RO-CODE
is more specific thanRO
.RO-DATA
is more specific thanRO
.RW-CODE
is more specific thanRW
.RW-DATA
is more specific thanRW
.- There are no other members of the (
s1
more specific thans2
) relationship between section attributes.
- If one of
This matching strategy has the following consequences:
- Descriptions do not depend on the order they are written in the file.
- Generally, the more specific the description of an object, the more specific the description of the input sections it contains.
- The
s are not examined unless:input_section_selector
- Object selection is inconclusive.
- One selector specifies a literal input section name or a section type and the other selects by attribute. In this case, the explicit input section name or type is more specific than any attribute. This is true even if the object selector associated with the input section name is less specific than that of the attribute.
The .ANY
module selector is available to assign any sections that
cannot be resolved from the scatter-loading description.
Example
The following example shows multiple execution regions and pattern matching:
LR_1 0x040000 { ER_ROM 0x040000 ; The startup exec region address is the same { ; as the load address. application.o (+ENTRY) ; The section containing the entry point from } ; the object is placed here. ER_RAM1 0x048000 { application.o (+RO-CODE) ; Other RO code from the object goes here } ER_RAM2 0x050000 { application.o (+RO-DATA) ; The RO data goes here } ER_RAM3 0x060000 { application.o (+RW) ; RW code and data go here } ER_RAM4 +0 ; Follows on from end of ER_R3 { *.o (+RO, +RW, +ZI) ; Everything except for application.o goes here } }