Chapter 4. Linker Scripts
4.6.4.3. Input Section for Common Symbols
A special notation is needed for common symbols, because in many object file formats common
symbols do not have a particular input section. The linker treats common symbols as though they are
in an input section named
You may use file names with the
this to place common symbols from a particular input file in one section while common symbols from
other input files are placed in another section.
In most cases, common symbols in input files will be placed in the
example:
.bss { *(.bss) *(COMMON) }
Some object file formats have more than one type of common symbol. For example, the MIPS ELF
object file format distinguishes standard common symbols and small common symbols. In this case,
the linker will use a different special section name for other types of common symbols. In the case of
MIPS ELF, the linker uses
symbols. This permits you to map the different types of common symbols into memory at different
locations.
You will sometimes see
is equivalent to
*(COMMON)
4.6.4.4. Input Section and Garbage Collection
When link-time garbage collection is in use (
should not be eliminated. This is accomplished by surrounding an input section's wildcard entry with
, as in
KEEP()
KEEP(*(.init))
4.6.4.5. Input Section Example
The following example is a complete linker script. It tells the linker to read all of the sections from
file
and place them at the start of output section
all.o
All of section
.input1
section
from
.input2
. All of the remaining
foo1.o
section
.
outputc
SECTIONS {
outputa 0x10000 :
{
all.o
foo.o (.input1)
}
outputb :
{
foo.o (.input2)
foo1.o (.input1)
}
outputc :
{
*(.input1)
*(.input2)
}
}
.
COMMON
section just as with any other input sections. You can use
COMMON
for standard common symbols and
COMMON
in old linker scripts. This notation is now considered obsolete. It
[COMMON]
.
or
KEEP(SORT(*)(.ctors))
from file
follows immediately, in the same output section. All of
foo.o
goes into output section
foo.o
and
.input1
), it is often useful to mark sections that
-gc-sections
.
outputa
, followed by section
outputb
sections from any files are written to output
.input2
section in the output file. For
.bss
for small common
.scommon
which starts at location
.input1
39
.
0x10000
from
Need help?
Do you have a question about the ENTERPRISE LINUX 3 - USING ID and is the answer not in the manual?
Questions and answers