Defining Sections in the Output File

Use the linker command file's SECTIONS directive to

Use GROUP directives in a SECTIONS directive to organize objects.

The linker will only create a section in the output file if the section is not empty, even if the section is defined in a SECTIONS or GROUP directive.

SECTIONS and GROUP example shows an example.

Listing 1. SECTIONS and GROUP example
SECTIONS
{
   GROUP : 
   {
      .text : {}
      .rodata : {}
   } > text

   GROUP
   {
      .sdata : {}
      .sbss : {}
   } > data

   GROUP
   {
      .sdata2 : {}
      .sbss2 : {}
   } > data

}

This example defines the .text and .rodata sections in the output file and specifies that they should be loaded in the memory area named text on the target platform at runtime. The example then defines sections named .sdata and .sbss . These sections will be loaded in the memory named data . The last GROUP directive in the example defines sections named .sdata2 , and .sbss2 . These sections will also be loaded in the memory area named data , after the sections .sdata and .sbss .

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