Chapter 4. Linker Scripts
37
This works because
returns the current location counter aligned upward to the specified value.
ALIGN
Specifying
for a section will change the value of the location counter.
address
4.6.4. Input Section Description
The most common output section command is an input section description.
The input section description is the most basic linker script operation. You use output sections to tell
the linker how to lay out your program in memory. You use input section descriptions to tell the linker
how to map the input files into your memory layout.
4.6.4.1. Input Section Basics
An input section description consists of a file name optionally followed by a list of section names in
parentheses.
The file name and the section name may be wildcard patterns, which we describe further below (refer
to Section 4.6.4.2 Input Section Wildcard Patterns).
The most common input section description is to include all input sections with a particular name in
the output section. For example, to include all input
sections, you would write:
.text
*(.text)
Here the
is a wildcard which matches any file name. To exclude a list of files from matching the
*
file name wildcard, EXCLUDE_FILE may be used to match all files except the ones specified in the
EXCLUDE_FILE list. For example:
(*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors))
will cause all .ctors sections from all files except
and
to be included.
crtend.o
otherfile.o
There are two ways to include more than one section:
*(.text .rdata)
*(.text) *(.rdata)
The difference between these is the order in which the
and
input sections will appear
.text
.rdata
in the output section. In the first example, they will be intermingled, appearing in the same order as
they are found in the linker input. In the second example, all
input sections will appear first,
.text
followed by all
input sections.
.rdata
You can specify a file name to include sections from a particular file. You would do this if one or more
of your files contain special data that needs to be at a particular location in memory. For example:
data.o(.data)
If you use a file name without a list of sections, then all sections in the input file will be included in
the output section. This is not commonly done, but it may by useful on occasion. For example:
data.o
When you use a file name which does not contain any wild card characters, the linker will first see if
you also specified the file name on the linker command line or in an
command. If you did not,
INPUT
the linker will attempt to open the file as an input file, as though it appeared on the command line.
Note that this differs from an
command, because the linker will not search for the file in the
INPUT
archive search path.
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