In a section definition, you can specify the contents of an output section by listing particular input files, by listing particular input-file sections, or by a combination of the two. You can also place arbitrary data in the section, and define symbols relative to the beginning of the section.
The contents of a section definition may include any of the following kinds of statement. You can include as many of these as you like in a single section definition, separated from one another by whitespace.
filename
.data : { afile.o bfile.o cfile.o }The example also illustrates that multiple statements can be included in the contents of a section definition, since each file name is a separate statement.
filename( section )
filename( section, section, ... )
filename( section section ... )
* (section)
* (section, section, ...)
* (section section ...)
ld
command
line: use `*' instead of a particular file name before the
parenthesized input-file section list.
If you have already explicitly included some files by name, `*'
refers to all remaining files--those whose places in the output
file have not yet been defined.
For example, to copy sections 1
through 4
from an Oasys file
into the .text
section of an a.out
file, and sections 13
and 14
into the .data
section:
SECTIONS { .text :{ *("1" "2" "3" "4") } .data :{ *("13" "14") } }`[ section ... ]' used to be accepted as an alternate way to specify named sections from all unallocated input files. Because some operating systems (VMS) allow brackets in file names, that notation is no longer supported.
filename( COMMON )
*( COMMON )
*(COMMON)
by itself refers to all
uninitialized data from all input files (so far as it is not yet
allocated); filename(COMMON)
refers to uninitialized data
from a particular file. Both are special cases of the general
mechanisms for specifying where to place input-file sections:
ld
permits you to refer to uninitialized data as if it
were in an input-file section named COMMON
, regardless of the
input file's format.
For example, the following command script arranges the output file into
three consecutive sections, named .text
, .data
, and
.bss
, taking the input for each from the correspondingly named
sections of all the input files:
SECTIONS { .text : { *(.text) } .data : { *(.data) } .bss : { *(.bss) *(COMMON) } }
The following example reads all of the sections from file all.o
and places them at the start of output section outputa
which
starts at location 0x10000
. All of section .input1
from
file foo.o
follows immediately, in the same output section. All
of section .input2
from foo.o
goes into output section
outputb
, followed by section .input1
from foo1.o
.
All of the remaining .input1
and .input2
sections from any
files are written to output section outputc
.
SECTIONS { outputa 0x10000 : { all.o foo.o (.input1) } outputb : { foo.o (.input2) foo1.o (.input1) } outputc : { *(.input1) *(.input2) } }