Simple Linker Script Example - Red Hat ENTERPRISE LINUX 3 - USING ID Using Instructions

Using ld, the gnu linker
Hide thumbs Also See for ENTERPRISE LINUX 3 - USING ID:
Table of Contents

Advertisement

30
4.2. Linker Script Format
Linker scripts are text files.
You write a linker script as a series of commands. Each command is either a keyword, possibly
followed by arguments, or an assignment to a symbol. You may separate commands using semicolons.
Whitespace is generally ignored.
Strings such as file or format names can normally be entered directly. If the file name contains a
character such as a comma which would otherwise serve to separate file names, you may put the file
name in double quotes. There is no way to use a double quote character in a file name.
You may include comments in linker scripts just as in C, delimited by
are syntactically equivalent to whitespace.

4.3. Simple Linker Script Example

Many linker scripts are fairly simple.
The simplest possible linker script has just one command:
mand to describe the memory layout of the output file.
The
command is a powerful command. Here we will describe a simple use of it. Let's
SECTIONS
assume your program consists only of code, initialized data, and uninitialized data. These will be
in the
,
.text
.data
sections which appear in your input files.
For this example, let's say that the code should be loaded at address 0x10000, and that the data should
start at address 0x8000000. Here is a linker script which will do that:
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}
You write the
SECTIONS
ments and output section descriptions enclosed in curly braces.
The first line inside the
, which is the location counter. If you do not specify the address of an output section in some other
.
way (other ways are described later), the address is set from the current value of the location counter.
The location counter is then incremented by the size of the output section. At the start of the
command, the location counter has the value
The second line defines an output section,
for now. Within the curly braces after the output section name, you list the names of the input sections
which should be placed into this output section. The
expression
*(.text)
Since the location counter is
the address of the
.text
The remaining lines define the
output section at address
.data
value of the location counter will be
is that the linker will place the
memory
, and
sections, respectively. Let's assume further that these are the only
.bss
command as the keyword
command of the above example sets the value of the special symbol
SECTIONS
.text
means all
input sections in all input files.
.text
when the output section
0x10000
section in the output file to be
and
.data
0x8000000
0x8000000
output section immediately after the
.bss
SECTIONS
, followed by a series of symbol assign-
SECTIONS
.
0
. The colon is required syntax which may be ignored
is a wildcard which matches any file name. The
*
0x10000
sections in the output file. The linker will place the
.bss
. After the linker places the
plus the size of the
Chapter 4. Linker Scripts
and
. As in C, comments
/*
*/
. You use the
SECTIONS
is defined, the linker will set
.text
.
output section, the
.data
output section. The effect
.data
output section in
.data
com-
SECTIONS

Advertisement

Table of Contents
loading
Need help?

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

Subscribe to Our Youtube Channel

This manual is also suitable for:

Enterprise linux 3

Table of Contents