Associating Input Sections With Output Sections

Normally the linker stores sections from input object code in the sections of the linker's output file that have the same name. The linker command file's SECTIONS and GROUP directives allow you to specify other ways to associate input object code with sections in linker output. Associating object code with sections in linker output shows an example.

Listing 1. Associating object code with sections in linker output
SECTIONS
{
   GROUP :
   {
      .myText : { main.o (.text) }
      .text : ( *(.text) }
   } > text

}

This example defines a section in the output file named .myText . This section will contain the objects that are in the .text section in the object code taken from the input file named main.o . The example also defines a section in the output file named .text . This section will contain all objects in the .text sections of all input files containing object code. Both these sections in the output file, .myText and .text , will be loaded in the memory area named text on the target platform.

The SECTIONS and GROUP directives also allow you to filter what kinds of object code from input files will be stored in a section in the output file. Filter types for object code in input files shows the kinds of data that may be filtered.

Table 1. Filter types for object code in input files
This filter allows input objects that have these permissions and contain this kind of object code
TEXT readable, executable initialized
CODE readable, executable initialized
DATA readable, writable initialized
BSS readable, writable uninitialized
CONST readable initialized
MIXED readable, writable, executable initialized
VLECODE readable, executable initialized

Filtering objects from input files shows an example.

Listing 2. Filtering objects from input files
SECTIONS
{
   .text (TEXT) : { } > text
   .bss (BSS) : { } > data

}

This example defines a section in the output file named .text . The linker will only store objects from input object code that are readable, executable, and initialized. This example also defines a section in the output file named .bss . This section will only contain objects from the linker's input files that are readable, writable, and uninitialized.

Related information
Specifying Link Order in the IDE
Dead-Stripping
Defining the Target's Memory Map
Defining Sections in the Output File
Controlling Alignment
Specifying Memory Area Locations and Sizes
Creating Memory Gaps
Creating Symbols
Linker Command File Syntax
Commands, Directives, and Keywords