10.7.1. How the Allocation Algorithm Creates Output Sections

An output section can be formed in one of two ways:

  • Method 1: As the result of a SECTIONS directive definition.

  • Method 2: By combining input sections with the same name into an output section that is not defined in a SECTIONS directive.

If an output section is formed as a result of a SECTIONS directive, this definition completely determines the section’s contents. (See The SECTIONS Directive for examples of how to define an output section’s content.)

If an output section is formed by combining input sections not specified by a SECTIONS directive, the linker combines all such input sections that have the same name into an output section with that name. For example, suppose the files f1.c.o and f2.c.o both contain named sections called Vectors and that the SECTIONS directive does not define an output section for them. The linker combines the two Vectors sections from the input files into a single output section named Vectors, allocates it into memory, and includes it in the output file.

By default, the linker does not display a message when it creates an output section that is not defined in the SECTIONS directive. You can use the --warn_sections linker option (see Display a Message When an Undefined Output Section Is Created (--warn_sections)) to cause the linker to display a message when it creates a new output section.

After the linker determines the composition of all output sections, it must allocate them into configured memory. The MEMORY directive specifies which portions of memory are configured. If there is no MEMORY directive, the linker uses the default configuration as shown in Default Placement Algorithm. (See The MEMORY Directive for more information on configuring memory.)