@end ifinfo
@ifinfo
-This file documents the GNU linker LD.
+This file documents the @sc{gnu} linker LD.
Copyright (C) 1991, 92, 93, 94, 1995 Free Software Foundation, Inc.
@sp 1
@subtitle @code{ld} version 2
@subtitle January 1994
-@author Steve Chamberlain and Roland Pesch
+@author Steve Chamberlain
@author Cygnus Support
@page
@tex
{\parskip=0pt
\hfill Cygnus Support\par
-\hfill steve\@cygnus.com, pesch\@cygnus.com\par
+\hfill steve\@cygnus.com, doc\@cygnus.com\par
\hfill {\it Using LD, the GNU linker}\par
\hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
-\hfill and Roland Pesch (pesch\@cygnus.com)\par
}
\global\parindent=0pt % Steve likes it this way.
@end tex
@ifinfo
@node Top
@top Using ld
-This file documents the GNU linker ld.
+This file documents the @sc{gnu} linker ld.
@menu
* Overview:: Overview
@node Overview
@chapter Overview
-@cindex GNU linker
+@cindex @sc{gnu} linker
@cindex what is this?
@code{ld} combines a number of object and archive files, relocates
their data and ties up symbol references. Usually the last step in
available kind of object file. @xref{BFD}, for more information.
@end ifclear
-Aside from its flexibility, the GNU linker is more helpful than other
+Aside from its flexibility, the @sc{gnu} linker is more helpful than other
linkers in providing diagnostic information. Many linkers abandon
execution immediately upon encountering an error; whenever possible,
@code{ld} continues executing, allowing you to identify other errors
@node Invocation
@chapter Invocation
-The GNU linker @code{ld} is meant to cover a broad range of situations,
+The @sc{gnu} linker @code{ld} is meant to cover a broad range of situations,
and to be as compatible as possible with other linkers. As a result,
you have many choices to control its behavior.
[ -Bstatic ] [ -Bdynamic ] [ -Bsymbolic ]
[ -c @var{MRI-commandfile} ] [ -d | -dc | -dp ]
[ -defsym @var{symbol}=@var{expression} ]
- [ -dynamic-linker @var{file} ] [ -embedded-relocs ]
+ [ -dynamic-linker @var{file} ] [ -embedded-relocs ] [ -export-dynamic ]
[ -e @var{entry} ] [ -F ] [ -F @var{format} ]
- [ -format @var{input-format} ] [ -g ] [ -G @var{size} ] [ -help ]
- [ -i ] [ -l@var{archive} ] [ -L@var{searchdir} ] [ -M ]
- [ -Map @var{mapfile} ] [ -m @var{emulation} ] [ -N | -n ]
- [ -noinhibit-exec ] [ -no-keep-memory ] [ -oformat @var{output-format} ]
- [ -R @var{filename} ] [ -relax ] [ -retain-symbols-file @var{filename} ]
+ [ -format @var{input-format} ] [ -g ] [ -G @var{size} ]
+ [ -help ] [ -i ] [ -l@var{archive} ] [ -L@var{searchdir} ]
+ [ -M ] [ -Map @var{mapfile} ] [ -m @var{emulation} ]
+ [ -N | -n ] [ -noinhibit-exec ] [ -no-keep-memory ]
+ [ -oformat @var{output-format} ] [ -R @var{filename} ]
+ [ -relax ] [ -retain-symbols-file @var{filename} ]
[ -r | -Ur ] [ -rpath @var{dir} ] [-rpath-link @var{dir} ]
[ -S ] [ -s ] [ -soname @var{name} ] [ -shared ]
[ -sort-common ] [ -stats ] [ -T @var{commandfile} ]
[ -u @var{symbol}] [-V] [-v] [ -verbose] [ -version ]
[ -warn-common ] [ -warn-constructors] [ -warn-once ]
[ -y @var{symbol} ] [ -X ] [-x ]
- [ -( [ archives ] -) ] [ --start-group [ archives ] --end-group ]
- [ -split-by-reloc @var{count} ] [ -split-by-file ] [ --whole-archive ]
+ [ -( [ archives ] -) ]
+ [ --start-group [ archives ] --end-group ]
+ [ -split-by-reloc @var{count} ] [ -split-by-file ]
+ [ --whole-archive ]
@end smallexample
This plethora of command-line options may seem intimidating, but in
object files on a standard, supported Unix system. On such a system, to
link a file @code{hello.o}:
-@example
+@smallexample
ld -o @var{output} /lib/crt0.o hello.o -lc
-@end example
+@end smallexample
This tells @code{ld} to produce a file called @var{output} as the
result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
@cindex binary input format
@kindex -b @var{format}
@cindex input format
-@item -b @var{input-format}
@cindex input format
+@item -b @var{input-format}
@code{ld} may be configured to support more than one kind of object
file. If your @code{ld} is configured this way, you can use the
@samp{-b} option to specify the binary format for input object files
@cindex common allocation
@kindex -d
-@item -d
@kindex -dc
-@itemx -dc
@kindex -dp
+@item -d
+@itemx -dc
@itemx -dp
These three options are equivalent; multiple forms are supported for
compatibility with other linkers. They
@kindex -embedded-relocs
@item -embedded-relocs
This option is only meaningful when linking MIPS embedded PIC code,
-generated by the -membedded-pic option to the GNU compiler and
+generated by the -membedded-pic option to the @sc{gnu} compiler and
assembler. It causes the linker to create a table which may be used at
runtime to relocate any data which was statically initialized to pointer
values. See the code in testsuite/ld-empic for details.
discussion of defaults and other ways of specifying the
entry point.
+@cindex dynamic symbol table
+@kindex -export-dynamic
+@item -export-dynamic
+When creating an ELF file, add all symbols to the dynamic symbol table.
+Normally, the dynamic symbol table contains only symbols which are used
+by a dynamic object. This option is needed for some uses of
+@code{dlopen}.
+
@ifclear SingleFormat
@kindex -F
@item -F
Set the text segment to be read only, and mark the output as
@code{NMAGIC} if possible.
-@item -noinhibit-exec
@cindex output file after errors
@kindex -noinhibit-exec
+@item -noinhibit-exec
Retain the executable output file whenever it is still usable.
Normally, the linker will not produce an output file if it encounters
errors during the link process; it exits without writing an output file
when it issues any error whatsoever.
-@item -no-keep-memory
@cindex memory usage
@kindex -no-keep-memory
+@item -no-keep-memory
@code{ld} normally optimizes for speed over memory usage by caching the
symbol tables of input files in memory. This option tells @code{ld} to
instead optimize for memory usage, by rereading the symbol tables as
necessary. This may be required if @code{ld} runs out of memory space
while linking a large executable.
-@item -o @var{output}
@kindex -o @var{output}
@cindex naming the output file
+@item -o @var{output}
Use @var{output} as the name for the program produced by @code{ld}; if this
option is not specified, the name @file{a.out} is used by default. The
script command @code{OUTPUT} can also specify the output file name.
this option overrides it. @xref{BFD}.
@end ifclear
-@item -R @var{filename}
@kindex -R @var{file}
@cindex symbol-only input
+@item -R @var{filename}
Read symbol names and their addresses from @var{filename}, but do not
relocate it or include it in the output. This allows your output file
to refer symbolically to absolute locations of memory defined in other
programs.
-
+
+For compatibility with other ELF linkers, if the @code{-R} option is
+followed by a directory name, rather than a file name, it is treated as
+the @code{-rpath} option.
+
@kindex -relax
@cindex synthesizing linker
@cindex relaxing addressing modes
ignored.
@end ifset
-@item -retain-symbols-file @var{filename}
@cindex retaining specified symbols
@cindex stripping all but some symbols
@cindex symbols, retaining selectively
+@item -retain-symbols-file @var{filename}
Retain @emph{only} the symbols listed in the file @var{filename},
discarding all others. @var{filename} is simply a flat file, with one
symbol name per line. This option is especially useful in environments
them to locate shared objects at runtime. The @code{-rpath} option is
also used when locating shared objects which are needed by shared
objects explicitly included in the link; see the description of the
-@code{-rpath-link} option.
+@code{-rpath-link} option. If @code{-rpath} is not used when linking an
+ELF executable, the contents of the environment variable
+@code{LD_RUN_PATH} will be used if it is defined.
The @code{-rpath} option may also be used on SunOS. By default, on
SunOS, the linker will form a runtime search patch out of all the
options, ignoring the @code{-L} options. This can be useful when using
gcc, which adds many @code{-L} options which may be on NFS mounted
filesystems.
+
+For compatibility with other ELF linkers, if the @code{-R} option is
+followed by a directory name, rather than a file name, it is treated as
+the @code{-rpath} option.
@end ifset
@ifset GENERIC
used at runtime, whereas the @code{-rpath-link} option is only effective
at link time.
@item
+On an ELF system, if the @code{-rpath} and @code{rpath-link} options
+were not used, search the contents of the environment variable
+@code{LD_RUN_PATH}.
+@item
On SunOS, if the @code{-rpath} option was not used, search any
directories specified using @code{-L} options.
@item
Omit all symbol information from the output file.
@ifset GENERIC
-@item -soname @var{name}
@cindex runtime library name
@kindex -soname
+@item -soname @var{name}
When creating an ELF shared object, set the internal DT_SONAME field to
the specified name. When an executable is linked with a shared object
which has a DT_SONAME field, then when the executable is run the dynamic
then everything else. This is to prevent gaps between symbols due to
alignment constraints. This option disables that sorting.
-@item -split-by-reloc @var{count}
@kindex split
+@item -split-by-reloc @var{count}
Trys to creates extra sections in the output file so that no single output section
in the file contains more than @var{count} relocations. This
is useful when generating huge relocatable for downloading into
more than @var{count} relocations one output section will contain that
many relocations.
-@item -split-by-file
@kindex split
+@item -split-by-file
Similar to -split-by-reloc but creates a new output section for each
input file.
Compute and display statistics about the operation of the linker,
such as execution time and memory usage.
-@item -Tbss @var{org}
@kindex -Tbss @var{org}
-@itemx -Tdata @var{org}
@kindex -Tdata @var{org}
-@itemx -Ttext @var{org}
@kindex -Ttext @var{org}
@cindex segment origins, cmd line
+@item -Tbss @var{org}
+@itemx -Tdata @var{org}
+@itemx -Ttext @var{org}
Use @var{org} as the starting address for---respectively---the
@code{bss}, @code{data}, or the @code{text} segment of the output file.
@var{org} must be a single hexadecimal integer;
for compatibility with other linkers, you may omit the leading
@samp{0x} usually associated with hexadecimal values.
-@item -T @var{commandfile}
-@itemx -T@var{commandfile}
@kindex -T @var{script}
@cindex script files
+@item -T @var{commandfile}
+@itemx -T@var{commandfile}
Read link commands from the file @var{commandfile}. These commands
replace @code{ld}'s default link script (rather than adding
to it), so @var{commandfile} must specify everything necessary to describe
trouble). The @samp{-traditional-format} switch tells @code{ld} to not
combine duplicate entries.
-@item -u @var{symbol}
@kindex -u @var{symbol}
@cindex undefined symbol
+@item -u @var{symbol}
Force @var{symbol} to be entered in the output file as an undefined symbol.
Doing this may, for example, trigger linking of additional modules from
standard libraries. @samp{-u} may be repeated with different option
Display the version number for @code{ld}. The @code{-V} option also
lists the supported emulations.
-@item -version
@kindex -version
+@item -version
Display the version number for @code{ld} and exit.
-@item -warn-common
@kindex -warn-comon
@cindex warnings, on combining symbols
@cindex combining symbols, warnings on
+@item -warn-common
Warn when a common symbol is combined with another common symbol or with
a symbol definition. Unix linkers allow this somewhat sloppy practice,
but linkers on some other operating systems do not. This option allows
@item -x
Delete all local symbols.
-@item -y @var{symbol}
@kindex -y @var{symbol}
@cindex symbol tracing
+@item -y @var{symbol}
Print the name of each linked file in which @var{symbol} appears. This
option may be given any number of times. On many systems it is necessary
to prepend an underscore.
This option is useful when you have an undefined symbol in your link but
don't know where the reference is coming from.
-@item -( @var{archives} -)
-@itemx --start-group @var{archives} --end-group
@kindex -(
@cindex groups of archives
+@item -( @var{archives} -)
+@itemx --start-group @var{archives} --end-group
The @var{archives} should be a list of archive files. They may be
either explicit file names, or @samp{-l} options.
* Expressions:: Expressions
* MEMORY:: MEMORY Command
* SECTIONS:: SECTIONS Command
+* PHDRS:: PHDRS Command
* Entry Point:: The Entry Point
* Option Commands:: Option Commands
@end menu
@cindex octal integers
An octal integer is @samp{0} followed by zero or more of the octal
digits (@samp{01234567}).
-@example
+@smallexample
_as_octal = 0157255;
-@end example
+@end smallexample
@cindex decimal integers
A decimal integer starts with a non-zero digit followed by zero or
more digits (@samp{0123456789}).
-@example
+@smallexample
_as_decimal = 57005;
-@end example
+@end smallexample
@cindex hexadecimal integers
@kindex 0x
A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
-@example
+@smallexample
_as_hex = 0xdead;
-@end example
+@end smallexample
@cindex negative integers
To write a negative integer, use
the prefix operator @samp{-}; @pxref{Operators}.
-@example
+@smallexample
_as_neg = -57005;
-@end example
+@end smallexample
@cindex scaled integers
@cindex K and M integer suffixes
@c END TEXI2ROFF-KILL
respectively. For example, the following all refer to the same quantity:
-@example
+@smallexample
_fourk_1 = 4K;
_fourk_2 = 4096;
_fourk_3 = 0x1000;
-@end example
+@end smallexample
@node Symbols
@subsection Symbol Names
and hyphens. Unquoted symbol names must not conflict with any
keywords. You can specify a symbol which contains odd characters or has
the same name as a keyword, by surrounding the symbol name in double quotes:
-@example
+@smallexample
"SECTION" = 9;
"with a space" = "also with a space" + 10;
-@end example
+@end smallexample
Since symbols can contain many non-alphabetic characters, it is safest
to delimit symbols with spaces. For example, @samp{A-B} is one symbol,
@cindex holes
This may be used to create holes in the output section. The location
counter may never be moved backwards.
-@example
+@smallexample
SECTIONS
@{
output :
file3(.text)
@} = 0x1234;
@}
-@end example
+@end smallexample
@noindent
In the previous example, @code{file1} is located at the beginning of the
output section, then there is a 1000 byte gap. Then @code{file2}
@vfill
@end iftex
-@need 5000
+@need 2000
@node Operators
@subsection Operators
@cindex Operators for arithmetic
@c TEXI2ROFF-KILL
@ifinfo
@c END TEXI2ROFF-KILL
-@example
+@smallexample
precedence associativity Operators Notes
(highest)
1 left ! - ~ (1)
10 right ? :
11 right &= += -= *= /= (2)
(lowest)
-@end example
+@end smallexample
Notes:
(1) Prefix operators
(2) @xref{Assignment}
@end ifinfo
@tex
\vskip \baselineskip
-%"lispnarrowing" is the extra indent used generally for @example
+%"lispnarrowing" is the extra indent used generally for @smallexample
\hskip\lispnarrowing\vbox{\offinterlineskip
\hrule
\halign
section definition by using the absolute assignment function
@code{ABSOLUTE}. For example, to create an absolute symbol whose address
is the last byte of an output section named @code{.data}:
-@example
+@smallexample
SECTIONS@{ @dots{}
.data :
@{
_edata = ABSOLUTE(.) ;
@}
@dots{} @}
-@end example
+@end smallexample
The linker tries to put off the evaluation of an assignment until all
the terms in the source expression are known (@pxref{Evaluation}). For
counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the
result of an expression is required, but the value is not available,
then an error results. For example, a script like the following
-@example
+@smallexample
SECTIONS @{ @dots{}
text 9+this_isnt_constant :
@{ @dots{}
@}
@dots{} @}
-@end example
+@end smallexample
@kindex Non constant expression
@noindent
will cause the error message ``@code{Non constant expression for initial
The command language includes a number of built-in
functions for use in link script expressions.
@table @code
-@item ABSOLUTE(@var{exp})
@kindex ABSOLUTE(@var{exp})
@cindex expression, absolute
+@item ABSOLUTE(@var{exp})
Return the absolute (non-relocatable, as opposed to non-negative) value
of the expression @var{exp}. Primarily useful to assign an absolute
value to a symbol within a section definition, where symbol values are
normally section-relative.
-@item ADDR(@var{section})
@kindex ADDR(@var{section})
@cindex section address
+@item ADDR(@var{section})
Return the absolute address of the named @var{section}. Your script must
previously have defined the location of that section. In the following
example, @code{symbol_1} and @code{symbol_2} are assigned identical
values:
-@example
+@smallexample
+@group
SECTIONS@{ @dots{}
.output1 :
@{
symbol_2 = start_of_output_1;
@}
@dots{} @}
-@end example
+@end group
+@end smallexample
-@item ALIGN(@var{exp})
@kindex ALIGN(@var{exp})
@cindex rounding up location counter
+@item ALIGN(@var{exp})
Return the result of the current location counter (@code{.}) aligned to
the next @var{exp} boundary. @var{exp} must be an expression whose
value is a power of two. This is equivalent to
-@example
+@smallexample
(. + @var{exp} - 1) & ~(@var{exp} - 1)
-@end example
+@end smallexample
@code{ALIGN} doesn't change the value of the location counter---it just
does arithmetic on it. As an example, to align the output @code{.data}
section to the next @code{0x2000} byte boundary after the preceding
section and to set a variable within the section to the next
@code{0x8000} boundary after the input sections:
-@example
+@smallexample
+@group
SECTIONS@{ @dots{}
.data ALIGN(0x2000): @{
*(.data)
variable = ALIGN(0x8000);
@}
@dots{} @}
-@end example
+@end group
+@end smallexample
@noindent
The first use of @code{ALIGN} in this example specifies the location of
a section because it is used as the optional @var{start} attribute of a
The built-in @code{NEXT} is closely related to @code{ALIGN}.
-@item DEFINED(@var{symbol})
@kindex DEFINED(@var{symbol})
@cindex symbol defaults
+@item DEFINED(@var{symbol})
Return 1 if @var{symbol} is in the linker global symbol table and is
defined, otherwise return 0. You can use this function to provide default
values for symbols. For example, the following command-file fragment shows how
existed, its value is preserved:
@smallexample
+@group
SECTIONS@{ @dots{}
.text : @{
begin = DEFINED(begin) ? begin : . ;
@dots{}
@}
@dots{} @}
+@end group
@end smallexample
-@item NEXT(@var{exp})
@kindex NEXT(@var{exp})
@cindex unallocated address, next
+@item NEXT(@var{exp})
Return the next unallocated address that is a multiple of @var{exp}.
This function is closely related to @code{ALIGN(@var{exp})}; unless you
use the @code{MEMORY} command to define discontinuous memory for the
output file, the two functions are equivalent.
-@item SIZEOF(@var{section})
@kindex SIZEOF(@var{section})
@cindex section size
+@item SIZEOF(@var{section})
Return the size in bytes of the named @var{section}, if that section has
been allocated. In the following example, @code{symbol_1} and
@code{symbol_2} are assigned identical values:
@c What does it return if the section hasn't been allocated? 0?
-@example
+@smallexample
+@group
SECTIONS@{ @dots{}
.output @{
.start = . ;
symbol_1 = .end - .start ;
symbol_2 = SIZEOF(.output);
@dots{} @}
+@end group
+@end smallexample
-@end example
-
-@item SIZEOF_HEADERS
@kindex SIZEOF_HEADERS
@cindex header size
-@itemx sizeof_headers
@kindex sizeof_headers
+@item SIZEOF_HEADERS
+@itemx sizeof_headers
Return the size in bytes of the output file's headers. You can use this number
as the start address of the first section, if you choose, to facilitate
paging.
command; however, you can define as many blocks of memory within it as
you wish. The syntax is:
-@example
+@smallexample
+@group
MEMORY
@{
@var{name} (@var{attr}) : ORIGIN = @var{origin}, LENGTH = @var{len}
@dots{}
@}
-@end example
+@end group
+@end smallexample
@table @code
@cindex naming memory regions
@item @var{name}
allocation---one starting at 0 for 256 kilobytes, and the other
starting at @code{0x40000000} for four megabytes:
-@example
+@smallexample
+@group
MEMORY
@{
rom : ORIGIN = 0, LENGTH = 256K
ram : org = 0x40000000, l = 4M
@}
-@end example
+@end group
+@end smallexample
Once you have defined a region of memory named @var{mem}, you can direct
specific output sections there by using a command ending in
fill pattern, and target memory region. Most of
these specifications are optional; the simplest form of a section
definition is
-@example
+@smallexample
SECTIONS @{ @dots{}
@var{secname} : @{
@var{contents}
@}
@dots{} @}
-@end example
+@end smallexample
@cindex naming output sections
@noindent
@var{secname} is the name of the output section, and @var{contents} a
The linker will not create output sections which do not have any
contents. This is for convenience when referring to input sections that
may or may not exist. For example,
-@example
-.foo @{ *(.foo @}
-@end example
+@smallexample
+.foo @{ *(.foo) @}
+@end smallexample
will only create a @samp{.foo} section in the output file if there is a
@samp{.foo} section in at least one input file.
only those sections which have not yet been allocated are used.
To specify a list of particular files by name:
-@example
+@smallexample
.data : @{ afile.o bfile.o cfile.o @}
-@end example
+@end smallexample
@noindent
The example also illustrates that multiple statements can be included in
the contents of a section definition, since each file name is a separate
For example, to copy sections @code{1} through @code{4} from an Oasys file
into the @code{.text} section of an @code{a.out} file, and sections @code{13}
and @code{14} into the @code{.data} section:
-@example
+@smallexample
+@group
SECTIONS @{
.text :@{
*("1" "2" "3" "4")
*("13" "14")
@}
@}
-@end example
+@end group
+@end smallexample
@cindex @code{[@var{section}@dots{}]}, not supported
@samp{[ @var{section} @dots{} ]} used to be accepted as an alternate way
@code{.bss}, taking the input for each from the correspondingly named
sections of all the input files:
-@example
+@smallexample
+@group
SECTIONS @{
.text : @{ *(.text) @}
.data : @{ *(.data) @}
.bss : @{ *(.bss) *(COMMON) @}
@}
-@end example
+@end group
+@end smallexample
The following example reads all of the sections from file @code{all.o}
and places them at the start of output section @code{outputa} which
All of the remaining @code{.input1} and @code{.input2} sections from any
files are written to output section @code{outputc}.
-@example
+@smallexample
+@group
SECTIONS @{
outputa 0x10000 :
@{
*(.input2)
@}
@}
-@end example
+@end group
+@end smallexample
@node Section Data Expressions
@subsection Section Data Expressions
data written from that input file. For instance, with @code{a.out}
files it is conventional to have a symbol for each input file. You can
accomplish this by defining the output @code{.text} section as follows:
-@example
+@smallexample
+@group
SECTIONS @{
.text 0x2020 :
@{
@}
@dots{}
@}
-@end example
+@end group
+@end smallexample
If @code{sample.ld} is a file containing this script, and @code{a.o},
@code{b.o}, @code{c.o}, and @code{d.o} are four input files with
contents like the following---
-@example
+@smallexample
+@group
/* a.c */
afunction() @{ @}
int adata=1;
int abss;
-@end example
+@end group
+@end smallexample
@noindent
@samp{ld -M -T sample.ld a.o b.o c.o d.o} would create a map like this,
containing symbols matching the object file names:
-@example
+@smallexample
00000000 A __DYNAMIC
00004020 B _abss
00004000 D _adata
00002038 t b.o
00002050 t c.o
00002068 t d.o
-@end example
+@end smallexample
@kindex @var{symbol} = @var{expression} ;
@kindex @var{symbol} @var{f}= @var{expression} ;
definition, the value is relative to the beginning of the section
(@pxref{Assignment}). If you write
-@example
+@smallexample
+@group
SECTIONS @{
abs = 14 ;
@dots{}
abs2 = 14 + ADDR(.data);
@dots{}
@}
-@end example
+@end group
+@end smallexample
@c FIXME: Try above example!
@noindent
appropriate for the output file format (@pxref{BFD}).
@end ifclear
-@item FILL(@var{expression})
@kindex FILL(@var{expression})
@cindex holes, filling
@cindex unspecified memory
+@item FILL(@var{expression})
Specify the ``fill pattern'' for the current section. Any otherwise
unspecified regions of memory within the section (for example, regions
you skip over by assigning a new value to the location counter @samp{.})
optional portions:
@smallexample
+@group
SECTIONS @{
@dots{}
@var{secname} @var{start} BLOCK(@var{align}) (NOLOAD) : AT ( @var{ldadr} )
- @{ @var{contents} @} >@var{region} =@var{fill}
+ @{ @var{contents} @} >@var{region} :@var{phdr} =@var{fill}
@dots{}
@}
+@end group
@end smallexample
@var{secname} and @var{contents} are required. @xref{Section
Definition}, and @pxref{Section Placement} for details on
@var{contents}. The remaining elements---@var{start},
@code{BLOCK(@var{align)}}, @code{(NOLOAD)}, @code{AT ( @var{ldadr} )},
-@code{>@var{region}}, and @code{=@var{fill}}---are all optional.
+@code{>@var{region}}, @code{:@var{phdr}}, and @code{=@var{fill}}---are
+all optional.
@table @code
@cindex start address, section
example generates section @var{output} at location
@code{0x40000000}:
-@example
+@smallexample
+@group
SECTIONS @{
@dots{}
output 0x40000000: @{
@}
@dots{}
@}
-@end example
+@end group
+@end smallexample
@kindex BLOCK(@var{align})
@cindex section alignment
@code{ROM} segment is addressed at memory location @samp{0} and does not
need to be loaded into each object file:
-@example
+@smallexample
+@group
SECTIONS @{
ROM 0 (NOLOAD) : @{ @dots{} @}
@dots{}
@}
-@end example
+@end group
+@end smallexample
@kindex AT ( @var{ldadr} )
@cindex specify load address
@code{0x2000}:
@smallexample
+@group
SECTIONS
@{
.text 0x1000 : @{ *(.text) _etext = . ; @}
.bss 0x3000 :
@{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@}
@}
+@end group
@end smallexample
The run-time initialization code (for C programs, usually @code{crt0})
address:
@smallexample
+@group
char *src = _etext;
char *dst = _data;
/* Zero bss */
for (dst = _bstart; dst< _bend; dst++)
*dst = 0;
+@end group
@end smallexample
@kindex >@var{region}
Assign this section to a previously defined region of memory.
@xref{MEMORY}.
+@kindex :@var{phdr}
+@cindex section, assigning to program header
+@cindex program headers and sections
+@item :@var{phdr}
+Assign this section to a segment described by a program header.
+@xref{PHDRS}. If a section is assigned to one or more segments, than
+all subsequent allocated sections will be assigned to those segments as
+well, unless they use an explicitly @code{:@var{phdr}} modifier. To
+prevent a section from being assigned to a segment when it would
+normally default to one, use @code{:NONE}.
+
@kindex =@var{fill}
@cindex section fill pattern
@cindex fill pattern, entire section
@end table
+@node PHDRS
+@section ELF Program Headers
+@kindex PHDRS
+@kindex program headers
+@kindex ELF program headers
+
+The ELF object file format uses @dfn{program headers}, which are read by
+the system loader and describe how the program should be loaded into
+memory. These program headers must be set correctly in order to run the
+program on a native ELF system. The linker will create reasonable
+program headers by default. However, in some cases, it is desirable to
+specify the program headers more precisely; the @code{PHDRS} command may
+be used for this purpose. When the @code{PHDRS} command is used, the
+linker will not generate any program headers itself.
+
+The @code{PHDRS} command is only meaningful when generating an ELF
+output file. It is ignored in other cases. This manual does not
+describe the details of how the system loader interprets program
+headers; for more information, see the ELF ABI. The program headers of
+an ELF file may be displayed using the @samp{-p} option of the
+@code{objdump} command.
+
+This is the syntax of the @code{PHDRS} command. The words @code{PHDRS},
+@code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
+
+@smallexample
+@group
+PHDRS
+@{
+ @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
+ [ FLAGS ( @var{flags} ) ] ;
+@}
+@end group
+@end smallexample
+
+The @var{name} is used only for reference in the @code{SECTIONS} command
+of the linker script. It does not get put into the output file.
+
+Certain program header types describe segments of memory which are
+loaded from the file by the system loader. In the linker script, the
+contents of these segments are specified by directing allocated output
+sections to be placed in the segment. To do this, the command
+describing the output section in the @code{SECTIONS} command should use
+@samp{:@var{name}}, where @var{name} is the name of the program header
+as it appears in the @code{PHDRS} command. @xref{Section Options}.
+
+It is normal for certain sections to appear in more than one segment.
+This merely implies that one segment of memory contains another. This
+is specified by repeating @samp{:@var{name}}, using it once for each
+program header in which the section is to appear.
+
+If a section is placed in one or more segments using @samp{:@var{name}},
+then all subsequent allocated sections which do not specify
+@samp{:@var{name}} are placed in the same segments. This is for
+convenience, since generally a whole set of contiguous sections will be
+placed in a single segment. To prevent a section from being assigned to
+a segment when it would normally default to one, use @code{:NONE}.
+
+The @code{FILEHDR} and @code{PHDRS} keywords which may appear after the
+program header type also indicate contents of the segment of memory.
+The @code{FILEHDR} keyword means that the segment should include the ELF
+file header. The @code{PHDRS} keyword means that the segment should
+include the ELF program headers themselves.
+
+The @var{type} may be one of the following. The numbers indicate the
+value of the keyword.
+
+@table @asis
+@item @code{PT_NULL} (0)
+Indicates an unused program header.
+
+@item @code{PT_LOAD} (1)
+Indicates that this program header describes a segment to be loaded from
+the file.
+
+@item @code{PT_DYNAMIC} (2)
+Indicates a segment where dynamic linking information can be found.
+
+@item @code{PT_INTERP} (3)
+Indicates a segment where the name of the program interpreter may be
+found.
+
+@item @code{PT_NOTE} (4)
+Indicates a segment holding note information.
+
+@item @code{PT_SHLIB} (5)
+A reserved program header type, defined but not specified by the ELF
+ABI.
+
+@item @code{PT_PHDR} (6)
+Indicates a segment where the program headers may be found.
+
+@item @var{expression}
+An expression giving the numeric type of the program header. This may
+be used for types not defined above.
+@end table
+
+It is possible to specify that a segment should be loaded at a
+particular address in memory. This is done using an @code{AT}
+expression. This is identical to the @code{AT} command used in the
+@code{SECTIONS} command (@pxref{Section Options}). Using the @code{AT}
+command for a program header overrides any information in the
+@code{SECTIONS} command.
+
+Normally the segment flags are set based on the sections. The
+@code{FLAGS} keyword may be used to explicitly specify the segment
+flags. The value of @var{flags} must be an integer. It is used to
+set the @code{p_flags} field of the program header.
+
+Here is an example of the use of @code{PHDRS}. This shows a typical set
+of program headers used on a native ELF system.
+
+@example
+@group
+PHDRS
+@{
+ headers PT_PHDR PHDRS ;
+ interp PT_INTERP ;
+ text PT_LOAD FILEHDR PHDRS ;
+ data PT_LOAD ;
+ dynamic PT_DYNAMIC ;
+@}
+
+SECTIONS
+@{
+ . = SIZEOF_HEADERS;
+ .interp : @{ *(.interp) @} :text :interp
+ .text : @{ *(.text) @} :text
+ .rodata : @{ *(.rodata) @} /* defaults to :text */
+ @dots{}
+ . = . + 0x1000; /* move to a new page in memory */
+ .data : @{ *(.data) @} :data
+ .dynamic : @{ *(.dynamic) @} :data :dynamic
+ @dots{}
+@}
+@end group
+@end example
+
@node Entry Point
@section The Entry Point
@kindex ENTRY(@var{symbol})
The linker command language includes a command specifically for
defining the first executable instruction in an output file (its
@dfn{entry point}). Its argument is a symbol name:
-@example
+@smallexample
ENTRY(@var{symbol})
-@end example
+@end smallexample
Like symbol assignments, the @code{ENTRY} command may be placed either
as an independent command in the command file, or among the section
input files, you can simply define it, assigning it an appropriate
value---
-@example
+@smallexample
start = 0x2020;
-@end example
+@end smallexample
@noindent
The example shows an absolute address, but you can use any expression.
convention for the entry point, you can just assign the value of
whatever symbol contains the start address to @code{start}:
-@example
+@smallexample
start = other_symbol ;
-@end example
+@end smallexample
@node Option Commands
@section Option Commands
@w{@code{__CTOR_LIST__}} at the start, and @w{@code{__CTOR_LIST_END}} at
the end; destructor data is bracketed similarly, between
@w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_LIST_END}}. (The compiler
-must arrange to actually run this code; GNU C++ calls constructors from
+must arrange to actually run this code; @sc{gnu} C++ calls constructors from
a subroutine @code{__main}, which it inserts automatically into the
startup code for @code{main}, and destructors from @code{_exit}.)
@ref{Options,,Command Line Options}.
@ignore
-@item MAP ( @var{name} )
@kindex MAP ( @var{name} )
+@item MAP ( @var{name} )
@c MAP(...) appears to look for an F in the arg, ignoring all other
@c chars; if it finds one, it sets "map_option_f" to true. But nothing
@c checks map_option_f. Apparently a stub for the future...
@end ignore
-@item OUTPUT ( @var{filename} )
@kindex OUTPUT ( @var{filename} )
@cindex naming the output file
+@item OUTPUT ( @var{filename} )
Use this command to name the link output file @var{filename}. The
effect of @code{OUTPUT(@var{filename})} is identical to the effect of
@w{@samp{-o @var{filename}}}, which overrides it. You can use this
command to supply a default output-file name other than @code{a.out}.
@ifclear SingleFormat
-@item OUTPUT_ARCH ( @var{bfdname} )
@kindex OUTPUT_ARCH ( @var{bfdname} )
@cindex machine architecture, output
+@item OUTPUT_ARCH ( @var{bfdname} )
Specify a particular output machine architecture, with one of the names
used by the BFD back-end routines (@pxref{BFD}). This command is often
unnecessary; the architecture is most often set implicitly by either the
system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT}
command.
-@item OUTPUT_FORMAT ( @var{bfdname} )
@kindex OUTPUT_FORMAT ( @var{bfdname} )
@cindex format, output file
+@item OUTPUT_FORMAT ( @var{bfdname} )
When @code{ld} is configured to support multiple object code formats,
you can use this command to specify a particular output format.
@var{bfdname} is one of the names used by the BFD back-end routines
input files.
@end ifclear
-@item SEARCH_DIR ( @var{path} )
@kindex SEARCH_DIR ( @var{path} )
@cindex path for libraries
@cindex search path, libraries
+@item SEARCH_DIR ( @var{path} )
Add @var{path} to the list of paths where @code{ld} looks for
archive libraries. @code{SEARCH_DIR(@var{path})} has the same
effect as @samp{-L@var{path}} on the command line.
-@item STARTUP ( @var{filename} )
@kindex STARTUP ( @var{filename} )
@cindex first input file
+@item STARTUP ( @var{filename} )
Ensure that @var{filename} is the first input file used in the link
process.
@ifclear SingleFormat
-@item TARGET ( @var{format} )
@cindex input file format
@kindex TARGET ( @var{format} )
+@item TARGET ( @var{format} )
When @code{ld} is configured to support multiple object code formats,
you can use this command to change the input-file object code format
(like the command-line option @samp{-b} or its synonym @samp{-format}).
you specify the @samp{-relax} command-line option.
@table @emph
-@item relaxing address modes
@cindex relaxing on H8/300
+@item relaxing address modes
@code{ld} finds all @code{jsr} and @code{jmp} instructions whose
targets are within eight bits, and turns them into eight-bit
program-counter relative @code{bsr} and @code{bra} instructions,
respectively.
-@item synthesizing instructions
@cindex synthesizing on H8/300
+@item synthesizing instructions
@c FIXME: specifically mov.b, or any mov instructions really?
@code{ld} finds all @code{mov.b} instructions which use the
sixteen-bit absolute address form, but refer to the top
paths, and in any paths you specify with @samp{-L}) for a library with
the names
-@example
+@smallexample
+@group
try
libtry.a
tryca
libtryca.a
-@end example
+@end group
+@end smallexample
@noindent
The first two possibilities would be considered in any event; the last
@table @code
@cindex @code{ABSOLUTE} (MRI)
@item ABSOLUTE @var{secname}
-@item ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
+@itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
Normally, @code{ld} includes in the output file all sections from all
the input files. However, in an MRI-compatible script, you can use the
@code{ABSOLUTE} command to restrict the sections that will be present in
@cindex @code{LOAD} (MRI)
@item LOAD @var{filename}
-@item LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
+@itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
Include one or more object file @var{filename} in the link; this has the
same effect as specifying @var{filename} directly on the @code{ld}
command line.
\centerline{{\sl\fontname\tensl\/}}
\centerline{are used for emphasis.}\vfill}
\page\colophon
-% Blame: pesch@cygnus.com, 28mar91.
+% Blame: doc@cygnus.com, 28mar91.
@end tex