SPRU513Y August 2001 – June 2022 SM320F28335-EP
In Section 9.6.5.3.1, the linker takes all the .text sections from the input files and combines them into the .text output section. The linker concatenates the .text input sections in the order that it encounters them in the input files. The linker performs similar operations with the .data and .ebss or .bss sections. You can use this type of specification for any output section.
You can explicitly specify the input sections that form an output section. Each input section is identified by its filename and section name. If the filename is hyphenated (or contains special characters), enclose it within quotes:
SECTIONS
{
.text : /* Build .text output section */
{
f1.c.obj(.text) /* Link .text section from f1.c.obj */
f2.c.obj(sec1) /* Link sec1 section from f2.c.obj */
"f3-new.c.obj" /* Link ALL sections from f3-new.c.obj */
f4.c.obj(.text,sec2) /* Link .text and sec2 from f4.c.obj */
}
}
It is not necessary for input sections to have the same name as each other or as the output section they become part of. If a file is listed with no sections, all of its sections are included in the output section. If any additional input sections have the same name as an output section but are not explicitly specified by the SECTIONS directive, they are automatically linked in at the end of the output section. For example, if the linker found more .text sections in the preceding example and these .text sections were not specified anywhere in the SECTIONS directive, the linker would concatenate these extra sections after f4.c.obj(sec2).
The specifications in Section 9.6.5.3.1 are actually a shorthand method for the following:
SECTIONS
{
.text: { *(.text) }
.data: { *(.data) }
.ebss: { *(.ebss) }
}
The specification *(.text) means the unallocated .text sections from all input files. This format is useful if:
The following example illustrates the two purposes above:
SECTIONS
{
.text : {
abc.c.obj(xqt)
*(.text)
}
.data : {
*(.data)
fil.c.obj(table)
}
}
In this example, the .text output section contains a named section xqt from file abc.c.obj, which is followed by all the .text input sections. The .data section contains all the .data input sections, followed by a named section table from the file fil.c.obj. This method includes all the unallocated sections. For example, if one of the .text input sections was already included in another output section when the linker encountered *(.text), the linker could not include that first .text input section in the second output section.
Each input section acts as a prefix to gather longer-named sections. For example, the pattern *(.data) matches .dataspecial. Thus, prefixes enable subsections, which are described in the following section.