checkpoint
[deliverable/binutils-gdb.git] / ld / ld.texinfo
CommitLineData
f22eee08 1\input texinfo
c8072296 2@setfilename ld.info
b4d4e8e3 3@syncodeindex ky cp
7f9ae73e 4@include configdoc.texi
8de26d62 5@c (configdoc.texi is generated by the Makefile)
ec40bbb8
DM
6
7@c @smallbook
1c48127e
RP
8
9@ifinfo
10@format
11START-INFO-DIR-ENTRY
f9d3d71a 12* Ld: (ld). The GNU linker.
1c48127e
RP
13END-INFO-DIR-ENTRY
14@end format
15@end ifinfo
16
b4d4e8e3 17@ifinfo
c653b370 18This file documents the @sc{gnu} linker LD.
b4d4e8e3 19
5a59e34d 20Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
b4d4e8e3
RP
21
22Permission is granted to make and distribute verbatim copies of
23this manual provided the copyright notice and this permission notice
24are preserved on all copies.
25
d76ae847
RP
26Permission is granted to copy and distribute modified versions of this
27manual under the conditions for verbatim copying, provided also that
28the entire resulting derived work is distributed under the terms of a
29permission notice identical to this one.
30
31Permission is granted to copy and distribute translations of this manual
32into another language, under the above conditions for modified versions.
33
b4d4e8e3
RP
34@ignore
35Permission is granted to process this file through Tex and print the
36results, provided the printed document carries copying permission
37notice identical to this one except for the removal of this paragraph
38(this paragraph not being relevant to the printed manual).
39
40@end ignore
b4d4e8e3 41@end ifinfo
2c5c0674
RP
42@iftex
43@finalout
b4d4e8e3 44@setchapternewpage odd
246504a5 45@settitle Using LD, the GNU linker
f22eee08 46@titlepage
246504a5 47@title Using ld
c8072296 48@subtitle The GNU linker
f22eee08 49@sp 1
cb70c872 50@subtitle @code{ld} version 2
d4e5e3c3 51@subtitle January 1994
c653b370 52@author Steve Chamberlain
c8072296 53@author Cygnus Support
b4d4e8e3
RP
54@page
55
56@tex
b4d4e8e3
RP
57{\parskip=0pt
58\hfill Cygnus Support\par
c653b370 59\hfill steve\@cygnus.com, doc\@cygnus.com\par
ec40bbb8 60\hfill {\it Using LD, the GNU linker}\par
d4e5e3c3 61\hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
b4d4e8e3
RP
62}
63\global\parindent=0pt % Steve likes it this way.
64@end tex
65
f22eee08 66@vskip 0pt plus 1filll
5a59e34d 67Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
f22eee08
RP
68
69Permission is granted to make and distribute verbatim copies of
70this manual provided the copyright notice and this permission notice
71are preserved on all copies.
72
73Permission is granted to copy and distribute modified versions of this
74manual under the conditions for verbatim copying, provided also that
75the entire resulting derived work is distributed under the terms of a
76permission notice identical to this one.
77
78Permission is granted to copy and distribute translations of this manual
79into another language, under the above conditions for modified versions.
f22eee08 80@end titlepage
2c5c0674 81@end iftex
b4d4e8e3 82@c FIXME: Talk about importance of *order* of args, cmds to linker!
f22eee08 83
f22eee08 84@ifinfo
ec40bbb8
DM
85@node Top
86@top Using ld
c653b370 87This file documents the @sc{gnu} linker ld.
f22eee08 88
2c5c0674 89@menu
2d59b2c3
RP
90* Overview:: Overview
91* Invocation:: Invocation
92* Commands:: Command Language
ec40bbb8 93@ifset GENERIC
2d59b2c3 94* Machine Dependent:: Machine Dependent Features
ec40bbb8
DM
95@end ifset
96@ifclear GENERIC
97@ifset H8300
98* H8/300:: ld and the H8/300
99@end ifset
f9d3d71a
ILT
100@ifset Hitachi
101* Hitachi:: ld and other Hitachi micros
102@end ifset
ec40bbb8
DM
103@ifset I960
104* i960:: ld and the Intel 960 family
105@end ifset
106@end ifclear
107@ifclear SingleFormat
2d59b2c3 108* BFD:: BFD
ec40bbb8
DM
109@end ifclear
110@c Following blank line required for remaining bug in makeinfo conds/menus
111
9fde46a4 112* Reporting Bugs:: Reporting Bugs
2d59b2c3
RP
113* MRI:: MRI Compatible Script Files
114* Index:: Index
2c5c0674 115@end menu
ec40bbb8 116@end ifinfo
2c5c0674 117
ec40bbb8 118@node Overview
f22eee08
RP
119@chapter Overview
120
c653b370 121@cindex @sc{gnu} linker
2c5c0674 122@cindex what is this?
246504a5 123@code{ld} combines a number of object and archive files, relocates
ec40bbb8
DM
124their data and ties up symbol references. Usually the last step in
125compiling a program is to run @code{ld}.
f22eee08 126
246504a5 127@code{ld} accepts Linker Command Language files written in
2c5c0674 128a superset of AT&T's Link Editor Command Language syntax,
b4d4e8e3 129to provide explicit and total control over the linking process.
f22eee08 130
ec40bbb8 131@ifclear SingleFormat
246504a5
RP
132This version of @code{ld} uses the general purpose BFD libraries
133to operate on object files. This allows @code{ld} to read, combine, and
b4d4e8e3
RP
134write object files in many different formats---for example, COFF or
135@code{a.out}. Different formats may be linked together to produce any
d4e5e3c3 136available kind of object file. @xref{BFD}, for more information.
ec40bbb8 137@end ifclear
f22eee08 138
c653b370 139Aside from its flexibility, the @sc{gnu} linker is more helpful than other
2c5c0674
RP
140linkers in providing diagnostic information. Many linkers abandon
141execution immediately upon encountering an error; whenever possible,
246504a5 142@code{ld} continues executing, allowing you to identify other errors
2c5c0674
RP
143(or, in some cases, to get an output file in spite of the error).
144
ec40bbb8 145@node Invocation
2c5c0674
RP
146@chapter Invocation
147
c653b370 148The @sc{gnu} linker @code{ld} is meant to cover a broad range of situations,
2c5c0674 149and to be as compatible as possible with other linkers. As a result,
ec40bbb8 150you have many choices to control its behavior.
2c5c0674 151
ec40bbb8 152@ifset UsesEnvVars
2c5c0674 153@menu
2d59b2c3
RP
154* Options:: Command Line Options
155* Environment:: Environment Variables
2c5c0674 156@end menu
f22eee08 157
ec40bbb8 158@node Options
2c5c0674 159@section Command Line Options
ec40bbb8 160@end ifset
2c5c0674
RP
161
162@cindex command line
163@cindex options
67afbcea
DE
164The linker supports a plethora of command-line options, but in actual
165practice few of them are used in any particular context.
2c5c0674 166@cindex standard Unix system
246504a5 167For instance, a frequent use of @code{ld} is to link standard Unix
b4d4e8e3
RP
168object files on a standard, supported Unix system. On such a system, to
169link a file @code{hello.o}:
ec40bbb8 170
c653b370 171@smallexample
ec40bbb8 172ld -o @var{output} /lib/crt0.o hello.o -lc
c653b370 173@end smallexample
ec40bbb8 174
d76ae847 175This tells @code{ld} to produce a file called @var{output} as the
b4d4e8e3 176result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
ec40bbb8
DM
177the library @code{libc.a}, which will come from the standard search
178directories. (See the discussion of the @samp{-l} option below.)
f22eee08 179
246504a5 180The command-line options to @code{ld} may be specified in any order, and
67afbcea
DE
181may be repeated at will. Repeating most options with a different
182argument will either have no further effect, or override prior
ec40bbb8 183occurrences (those further to the left on the command line) of that
67afbcea
DE
184option. Options which may be meaningfully specified more than once are
185noted in the descriptions below.
f22eee08 186
2c5c0674 187@cindex object files
67afbcea
DE
188Non-option arguments are objects files which are to be linked together.
189They may follow, precede, or be mixed in with command-line options,
190except that an object file argument may not be placed between an option
191and its argument.
f22eee08 192
7f9ae73e
RP
193Usually the linker is invoked with at least one object file, but you can
194specify other forms of binary input files using @samp{-l}, @samp{-R},
195and the script command language. If @emph{no} binary input files at all
196are specified, the linker does not produce any output, and issues the
197message @samp{No input files}.
2c5c0674 198
0b3499f6
ILT
199If the linker can not recognize the format of an object file, it will
200assume that it is a linker script. A script specified in this way
201augments the main linker script used for the link (either the default
202linker script or the one specified by using @samp{-T}). This feature
203permits the linker to link against a file which appears to be an object
204or an archive, but actually merely defines some symbol values, or uses
cc28f8fb
ILT
205@code{INPUT} or @code{GROUP} to load other objects. Note that
206specifying a script in this way should only be used to augment the main
207linker script; if you want to use some command that logically can only
208appear once, such as the @code{SECTIONS} or @code{MEMORY} command, you
209must replace the default linker script using the @samp{-T} option.
210@xref{Commands}.
0b3499f6 211
d4e5e3c3
DM
212For options whose names are a single letter,
213option arguments must either follow the option letter without intervening
f22eee08
RP
214whitespace, or be given as separate arguments immediately following the
215option that requires them.
216
d4e5e3c3
DM
217For options whose names are multiple letters, either one dash or two can
218precede the option name; for example, @samp{--oformat} and
9fde46a4 219@samp{--oformat} are equivalent. Arguments to multiple-letter options
d4e5e3c3
DM
220must either be separated from the option name by an equals sign, or be
221given as separate arguments immediately following the option that
222requires them. For example, @samp{--oformat srec} and
223@samp{--oformat=srec} are equivalent. Unique abbreviations of the names
224of multiple-letter options are accepted.
225
f22eee08 226@table @code
67afbcea
DE
227@kindex -a@var{keyword}
228@item -a@var{keyword}
229This option is supported for HP/UX compatibility. The @var{keyword}
230argument must be one of the strings @samp{archive}, @samp{shared}, or
231@samp{default}. @samp{-aarchive} is functionally equivalent to
232@samp{-Bstatic}, and the other two keywords are functionally equivalent
233to @samp{-Bdynamic}. This option may be used any number of times.
234
ec40bbb8 235@ifset I960
2c5c0674
RP
236@cindex architectures
237@kindex -A@var{arch}
b4d4e8e3 238@item -A@var{architecture}
67afbcea
DE
239@kindex --architecture=@var{arch}
240@itemx --architecture=@var{architecture}
246504a5
RP
241In the current release of @code{ld}, this option is useful only for the
242Intel 960 family of architectures. In that @code{ld} configuration, the
1c48127e
RP
243@var{architecture} argument identifies the particular architecture in
244the 960 family, enabling some safeguards and modifying the
d76ae847
RP
245archive-library search path. @xref{i960,,@code{ld} and the Intel 960
246family}, for details.
b4d4e8e3 247
246504a5 248Future releases of @code{ld} may support similar functionality for
b4d4e8e3 249other architecture families.
ec40bbb8 250@end ifset
b4d4e8e3 251
ec40bbb8 252@ifclear SingleFormat
2c5c0674
RP
253@cindex binary input format
254@kindex -b @var{format}
67afbcea 255@kindex --format=@var{format}
2c5c0674 256@cindex input format
2c5c0674 257@cindex input format
c653b370 258@item -b @var{input-format}
67afbcea 259@itemx --format=@var{input-format}
1fb57a5d
RP
260@code{ld} may be configured to support more than one kind of object
261file. If your @code{ld} is configured this way, you can use the
262@samp{-b} option to specify the binary format for input object files
263that follow this option on the command line. Even when @code{ld} is
264configured to support alternative object formats, you don't usually need
265to specify this, as @code{ld} should be configured to expect as a
266default input format the most usual format on each machine.
267@var{input-format} is a text string, the name of a particular format
268supported by the BFD libraries. (You can list the available binary
67afbcea 269formats with @samp{objdump -i}.)
1fb57a5d 270@xref{BFD}.
2c5c0674
RP
271
272You may want to use this option if you are linking files with an unusual
ec40bbb8 273binary format. You can also use @samp{-b} to switch formats explicitly (when
2c5c0674 274linking object files of different formats), by including
ec40bbb8 275@samp{-b @var{input-format}} before each group of object files in a
2c5c0674
RP
276particular format.
277
278The default format is taken from the environment variable
ec40bbb8
DM
279@code{GNUTARGET}.
280@ifset UsesEnvVars
281@xref{Environment}.
282@end ifset
283You can also define the input
867a1b8a 284format from a script, using the command @code{TARGET}; see @ref{Option
d76ae847 285Commands}.
ec40bbb8 286@end ifclear
2c5c0674 287
2d59b2c3 288@kindex -c @var{MRI-cmdfile}
67afbcea 289@kindex --mri-script=@var{MRI-cmdfile}
2d59b2c3
RP
290@cindex compatibility, MRI
291@item -c @var{MRI-commandfile}
67afbcea 292@itemx --mri-script=@var{MRI-commandfile}
2d59b2c3
RP
293For compatibility with linkers produced by MRI, @code{ld} accepts script
294files written in an alternate, restricted command language, described in
d76ae847 295@ref{MRI,,MRI Compatible Script Files}. Introduce MRI script files with
ec40bbb8 296the option @samp{-c}; use the @samp{-T} option to run linker
d76ae847 297scripts written in the general-purpose @code{ld} scripting language.
8ddef552
DM
298If @var{MRI-cmdfile} does not exist, @code{ld} looks for it in the directories
299specified by any @samp{-L} options.
b4d4e8e3 300
2c5c0674
RP
301@cindex common allocation
302@kindex -d
2c5c0674 303@kindex -dc
2c5c0674 304@kindex -dp
c653b370
ILT
305@item -d
306@itemx -dc
b4d4e8e3
RP
307@itemx -dp
308These three options are equivalent; multiple forms are supported for
ec40bbb8 309compatibility with other linkers. They
2c5c0674 310assign space to common symbols even if a relocatable output file is
ec40bbb8 311specified (with @samp{-r}). The script command
867a1b8a 312@code{FORCE_COMMON_ALLOCATION} has the same effect. @xref{Option
d76ae847 313Commands}.
b4d4e8e3 314
2c5c0674
RP
315@cindex entry point, from command line
316@kindex -e @var{entry}
67afbcea 317@kindex --entry=@var{entry}
f22eee08 318@item -e @var{entry}
67afbcea 319@itemx --entry=@var{entry}
f22eee08 320Use @var{entry} as the explicit symbol for beginning execution of your
b4d4e8e3
RP
321program, rather than the default entry point. @xref{Entry Point}, for a
322discussion of defaults and other ways of specifying the
323entry point.
f22eee08 324
c653b370 325@cindex dynamic symbol table
7ec9d825 326@kindex -E
9fde46a4 327@kindex --export-dynamic
7ec9d825 328@item -E
9fde46a4 329@itemx --export-dynamic
67afbcea 330When creating a dynamically linked executable, add all symbols to the
5a59e34d
ILT
331dynamic symbol table. The dynamic symbol table is the set of symbols
332which are visible from dynamic objects at run time.
333
334If you do not use this option, the dynamic symbol table will normally
335contain only those symbols which are referenced by some dynamic object
336mentioned in the link.
337
338If you use @code{dlopen} to load a dynamic object which needs to refer
339back to the symbols defined by the program, rather than some other
340dynamic object, then you will probably need to use this option when
341linking the program itself.
c653b370 342
de220cbd
ILT
343@kindex -f
344@kindex --auxiliary
345@item -f
346@itemx --auxiliary @var{name}
347When creating an ELF shared object, set the internal DT_AUXILIARY field
348to the specified name. This tells the dynamic linker that the symbol
349table of the shared object should be used as an auxiliary filter on the
350symbol table of the shared object @var{name}.
351
cc28f8fb
ILT
352If you later link a program against this filter object, then, when you
353run the program, the dynamic linker will see the DT_AUXILIARY field. If
354the dynamic linker resolves any symbols from the filter object, it will
355first check whether there is a definition in the shared object
356@var{name}. If there is one, it will be used instead of the definition
357in the filter object. The shared object @var{name} need not exist.
358Thus the shared object @var{name} may be used to provide an alternative
359implementation of certain functions, perhaps for debugging or for
360machine specific performance.
361
5a59e34d
ILT
362This option may be specified more than once. The DT_AUXILIARY entries
363will be created in the order in which they appear on the command line.
364
2c5c0674 365@kindex -F
de220cbd
ILT
366@kindex --filter
367@item -F @var{name}
368@itemx --filter @var{name}
369When creating an ELF shared object, set the internal DT_FILTER field to
370the specified name. This tells the dynamic linker that the symbol table
cc28f8fb
ILT
371of the shared object which is being created should be used as a filter
372on the symbol table of the shared object @var{name}.
373
374If you later link a program against this filter object, then, when you
375run the program, the dynamic linker will see the DT_FILTER field. The
376dynamic linker will resolve symbols according to the symbol table of the
377filter object as usual, but it will actually link to the definitions
378found in the shared object @var{name}. Thus the filter object can be
379used to select a subset of the symbols provided by the object
380@var{name}.
de220cbd
ILT
381
382Some older linkers used the @code{-F} option throughout a compilation
ec40bbb8 383toolchain for specifying object-file format for both input and output
de220cbd
ILT
384object files. The @sc{gnu} linker uses other mechanisms for this
385purpose: the @code{-b}, @code{--format}, @code{--oformat} options, the
386@code{TARGET} command in linker scripts, and the @code{GNUTARGET}
387environment variable. The @sc{gnu} linker will ignore the @code{-F}
388option when not creating an ELF shared object.
2c5c0674 389
a1d393cf
ILT
390@kindex --force-exe-suffix
391@item --force-exe-suffix
392Make sure that an output file has a .exe suffix.
393
394If a successfully built fully linked output file does not have a
395@code{.exe} or @code{.dll} suffix, this option forces the linker to copy
396the output file to one of the same name with a @code{.exe} suffix. This
397option is useful when using unmodified Unix makefiles on a Microsoft
398Windows host, since some versions of Windows won't run an image unless
399it ends in a @code{.exe} suffix.
400
2c5c0674 401@kindex -g
b4d4e8e3 402@item -g
ec40bbb8 403Ignored. Provided for compatibility with other tools.
b4d4e8e3 404
8ddef552 405@kindex -G
67afbcea 406@kindex --gpsize
8ddef552
DM
407@cindex object size
408@item -G@var{value}
67afbcea 409@itemx --gpsize=@var{value}
8ddef552 410Set the maximum size of objects to be optimized using the GP register to
67afbcea
DE
411@var{size}. This is only meaningful for object file formats such as
412MIPS ECOFF which supports putting large and small objects into different
413sections. This is ignored for other object file formats.
8ddef552 414
67afbcea
DE
415@cindex runtime library name
416@kindex -h@var{name}
417@kindex -soname=@var{name}
418@item -h@var{name}
419@itemx -soname=@var{name}
420When creating an ELF shared object, set the internal DT_SONAME field to
421the specified name. When an executable is linked with a shared object
422which has a DT_SONAME field, then when the executable is run the dynamic
423linker will attempt to load the shared object specified by the DT_SONAME
424field rather than the using the file name given to the linker.
de87cdb4 425
2c5c0674
RP
426@kindex -i
427@cindex incremental link
f22eee08 428@item -i
ec40bbb8 429Perform an incremental link (same as option @samp{-r}).
f22eee08 430
2c5c0674 431@cindex archive files, from cmd line
de87cdb4 432@kindex -l@var{archive}
67afbcea
DE
433@kindex --library=@var{archive}
434@item -l@var{archive}
435@itemx --library=@var{archive}
436Add archive file @var{archive} to the list of files to link. This
f22eee08 437option may be used any number of times. @code{ld} will search its
67afbcea 438path-list for occurrences of @code{lib@var{archive}.a} for every
4164f2d5
ILT
439@var{archive} specified.
440
441On systems which support shared libraries, @code{ld} may also search for
442libraries with extensions other than @code{.a}. Specifically, on ELF
443and SunOS systems, @code{ld} will search a directory for a library with
444an extension of @code{.so} before searching for one with an extension of
445@code{.a}. By convention, a @code{.so} extension indicates a shared
446library.
f22eee08 447
b61364cc
ILT
448The linker will search an archive only once, at the location where it is
449specified on the command line. If the archive defines a symbol which
450was undefined in some object which appeared before the archive on the
451command line, the linker will include the appropriate file(s) from the
452archive. However, an undefined symbol in an object appearing later on
453the command line will not cause the linker to search the archive again.
454
455See the @code{-(} option for a way to force the linker to search
456archives multiple times.
457
458You may list the same archive multiple times on the command line.
459
460@ifset GENERIC
461This type of archive searching is standard for Unix linkers. However,
462if you are using @code{ld} on AIX, note that it is different from the
463behaviour of the AIX linker.
464@end ifset
465
2c5c0674
RP
466@cindex search directory, from cmd line
467@kindex -L@var{dir}
67afbcea 468@kindex --library-path=@var{dir}
b4d4e8e3 469@item -L@var{searchdir}
67afbcea 470@itemx --library-path=@var{searchdir}
ec40bbb8 471Add path @var{searchdir} to the list of paths that @code{ld} will search
8ddef552 472for archive libraries and @code{ld} control scripts. You may use this
0b0642d6
ILT
473option any number of times. The directories are searched in the order
474in which they are specified on the command line. Directories specified
475on the command line are searched before the default directories. All
476@code{-L} options apply to all @code{-l} options, regardless of the
477order in which the options appear.
f22eee08 478
ec40bbb8 479@ifset UsesEnvVars
2c5c0674 480The default set of paths searched (without being specified with
ec40bbb8
DM
481@samp{-L}) depends on which emulation mode @code{ld} is using, and in
482some cases also on how it was configured. @xref{Environment}.
483@end ifset
484
485The paths can also be specified in a link script with the
0b0642d6
ILT
486@code{SEARCH_DIR} command. Directories specified this way are searched
487at the point in which the linker script appears in the command line.
f22eee08 488
8ddef552
DM
489@cindex emulation
490@kindex -m @var{emulation}
491@item -m@var{emulation}
8ddef552 492Emulate the @var{emulation} linker. You can list the available
01bc8f35
ILT
493emulations with the @samp{--verbose} or @samp{-V} options. The default
494depends on how your @code{ld} was configured.
8ddef552 495
67afbcea
DE
496@cindex link map
497@kindex -M
498@kindex --print-map
499@item -M
500@itemx --print-map
501Print (to the standard output) a link map---diagnostic information about
502where symbols are mapped by @code{ld}, and information on global common
503storage allocation.
504
505@kindex -n
506@cindex read-only text
507@cindex NMAGIC
508@kindex --nmagic
509@item -n
510@itemx --nmagic
511Set the text segment to be read only, and mark the output as
512@code{NMAGIC} if possible.
513
2c5c0674 514@kindex -N
67afbcea 515@kindex --omagic
2c5c0674 516@cindex read/write from cmd line
67afbcea 517@cindex OMAGIC
f22eee08 518@item -N
67afbcea 519@itemx --omagic
ec40bbb8
DM
520Set the text and data sections to be readable and writable. Also, do
521not page-align the data segment. If the output format supports Unix
522style magic numbers, mark the output as @code{OMAGIC}.
f22eee08 523
67afbcea
DE
524@kindex -o @var{output}
525@kindex --output=@var{output}
526@cindex naming the output file
527@item -o @var{output}
528@itemx --output=@var{output}
529Use @var{output} as the name for the program produced by @code{ld}; if this
530option is not specified, the name @file{a.out} is used by default. The
531script command @code{OUTPUT} can also specify the output file name.
f22eee08 532
67afbcea
DE
533@cindex partial link
534@cindex relocatable output
535@kindex -r
536@kindex --relocateable
537@item -r
538@itemx --relocateable
539Generate relocatable output---i.e., generate an output file that can in
540turn serve as input to @code{ld}. This is often called @dfn{partial
541linking}. As a side effect, in environments that support standard Unix
542magic numbers, this option also sets the output file's magic number to
543@code{OMAGIC}.
544@c ; see @code{-N}.
545If this option is not specified, an absolute file is produced. When
546linking C++ programs, this option @emph{will not} resolve references to
547constructors; to do that, use @samp{-Ur}.
548
549This option does the same thing as @samp{-i}.
550
551@kindex -R @var{file}
552@kindex --just-symbols=@var{file}
553@cindex symbol-only input
554@item -R @var{filename}
555@itemx --just-symbols=@var{filename}
556Read symbol names and their addresses from @var{filename}, but do not
557relocate it or include it in the output. This allows your output file
558to refer symbolically to absolute locations of memory defined in other
559programs. You may use this option more than once.
560
561For compatibility with other ELF linkers, if the @code{-R} option is
562followed by a directory name, rather than a file name, it is treated as
563the @code{-rpath} option.
564
565@kindex -s
566@kindex --strip-all
567@cindex strip all symbols
568@item -s
569@itemx --strip-all
570Omit all symbol information from the output file.
571
572@kindex -S
573@kindex --strip-debug
574@cindex strip debugger symbols
575@item -S
576@itemx --strip-debug
577Omit debugger symbol information (but not all symbols) from the output file.
578
579@kindex -t
580@kindex --trace
581@cindex input files, displaying
582@item -t
583@itemx --trace
584Print the names of the input files as @code{ld} processes them.
585
586@kindex -T @var{script}
587@kindex --script=@var{script}
588@cindex script files
589@item -T @var{commandfile}
590@itemx --script=@var{commandfile}
591Read link commands from the file @var{commandfile}. These commands
cc28f8fb
ILT
592replace @code{ld}'s default link script (rather than adding to it), so
593@var{commandfile} must specify everything necessary to describe the
594target format. You must use this option if you want to use a command
595which can only appear once in a linker script, such as the
596@code{SECTIONS} or @code{MEMORY} command. @xref{Commands}. If
597@var{commandfile} does not exist, @code{ld} looks for it in the
598directories specified by any preceding @samp{-L} options. Multiple
599@samp{-T} options accumulate.
67afbcea
DE
600
601@kindex -u @var{symbol}
602@kindex --undefined=@var{symbol}
603@cindex undefined symbol
604@item -u @var{symbol}
605@itemx --undefined=@var{symbol}
606Force @var{symbol} to be entered in the output file as an undefined symbol.
607Doing this may, for example, trigger linking of additional modules from
608standard libraries. @samp{-u} may be repeated with different option
609arguments to enter additional undefined symbols.
610@c Nice idea, but no such command: This option is equivalent
611@c to the @code{EXTERN} linker command.
612
613@kindex -v
614@kindex -V
615@kindex --version
616@cindex version
617@item -v
618@itemx --version
619@itemx -V
620Display the version number for @code{ld}. The @code{-V} option also
621lists the supported emulations.
622
623@kindex -x
624@kindex --discard-all
625@cindex deleting local symbols
626@item -x
627@itemx --discard-all
628Delete all local symbols.
629
630@kindex -X
631@kindex --discard-locals
632@cindex local symbols, deleting
633@cindex L, deleting symbols beginning
634@item -X
635@itemx --discard-locals
636Delete all temporary local symbols. For most targets, this is all local
637symbols whose names begin with @samp{L}.
638
639@kindex -y @var{symbol}
640@kindex --trace-symbol=@var{symbol}
641@cindex symbol tracing
642@item -y @var{symbol}
643@itemx --trace-symbol=@var{symbol}
644Print the name of each linked file in which @var{symbol} appears. This
645option may be given any number of times. On many systems it is necessary
646to prepend an underscore.
647
648This option is useful when you have an undefined symbol in your link but
649don't know where the reference is coming from.
650
651@kindex -Y @var{path}
652@item -Y @var{path}
653Add @var{path} to the default library search path. This option exists
654for Solaris compatibility.
655
656@kindex -z @var{keyword}
657@item -z @var{keyword}
658This option is ignored for Solaris compatibility.
659
660@kindex -(
661@cindex groups of archives
662@item -( @var{archives} -)
663@itemx --start-group @var{archives} --end-group
664The @var{archives} should be a list of archive files. They may be
665either explicit file names, or @samp{-l} options.
666
667The specified archives are searched repeatedly until no new undefined
668references are created. Normally, an archive is searched only once in
669the order that it is specified on the command line. If a symbol in that
670archive is needed to resolve an undefined symbol referred to by an
671object in an archive that appears later on the command line, the linker
672would not be able to resolve that reference. By grouping the archives,
673they all be searched repeatedly until all possible references are
674resolved.
675
676Using this option has a significant performance cost. It is best to use
677it only when there are unavoidable circular references between two or
678more archives.
679
680@kindex -assert @var{keyword}
681@item -assert @var{keyword}
682This option is ignored for SunOS compatibility.
683
684@kindex -Bdynamic
685@kindex -dy
686@kindex -call_shared
687@item -Bdynamic
688@itemx -dy
689@itemx -call_shared
690Link against dynamic libraries. This is only meaningful on platforms
691for which shared libraries are supported. This option is normally the
692default on such platforms. The different variants of this option are
693for compatibility with various systems. You may use this option
694multiple times on the command line: it affects library searching for
695@code{-l} options which follow it.
696
697@kindex -Bstatic
698@kindex -dn
699@kindex -non_shared
700@kindex -static
701@item -Bstatic
702@itemx -dn
703@itemx -non_shared
704@itemx -static
705Do not link against shared libraries. This is only meaningful on
706platforms for which shared libraries are supported. The different
707variants of this option are for compatibility with various systems. You
708may use this option multiple times on the command line: it affects
709library searching for @code{-l} options which follow it.
710
711@kindex -Bsymbolic
712@item -Bsymbolic
713When creating a shared library, bind references to global symbols to the
714definition within the shared library, if any. Normally, it is possible
715for a program linked against a shared library to override the definition
716within the shared library. This option is only meaningful on ELF
717platforms which support shared libraries.
718
86bc0974
ILT
719@cindex cross reference table
720@kindex --cref
721@item --cref
722Output a cross reference table. If a linker map file is being
723generated, the cross reference table is printed to the map file.
724Otherwise, it is printed on the standard output.
725
726The format of the table is intentionally simple, so that it may be
727easily processed by a script if necessary. The symbols are printed out,
728sorted by name. For each symbol, a list of file names is given. If the
729symbol is defined, the first file listed is the location of the
730definition. The remaining files contain references to the symbol.
731
67afbcea
DE
732@cindex symbols, from command line
733@kindex --defsym @var{symbol}=@var{exp}
734@item --defsym @var{symbol}=@var{expression}
735Create a global symbol in the output file, containing the absolute
736address given by @var{expression}. You may use this option as many
737times as necessary to define multiple symbols in the command line. A
738limited form of arithmetic is supported for the @var{expression} in this
739context: you may give a hexadecimal constant or the name of an existing
740symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
741constants or symbols. If you need more elaborate expressions, consider
742using the linker command language from a script (@pxref{Assignment, ,
743Assignment: Symbol Definitions}). @emph{Note:} there should be no
744white space between @var{symbol}, the equals sign (``@key{=}''), and
745@var{expression}.
746
747@cindex dynamic linker, from command line
748@kindex --dynamic-linker @var{file}
749@item --dynamic-linker @var{file}
750Set the name of the dynamic linker. This is only meaningful when
751generating dynamically linked ELF executables. The default dynamic
752linker is normally correct; don't use this unless you know what you are
753doing.
754
755@cindex big-endian objects
756@cindex endianness
757@kindex -EB
758@item -EB
759Link big-endian objects. This affects the default output format.
760
761@cindex little-endian objects
762@kindex -EL
763@item -EL
764Link little-endian objects. This affects the default output format.
765
766@cindex MIPS embedded PIC code
9fde46a4
ILT
767@kindex --embedded-relocs
768@item --embedded-relocs
67afbcea
DE
769This option is only meaningful when linking MIPS embedded PIC code,
770generated by the -membedded-pic option to the @sc{gnu} compiler and
771assembler. It causes the linker to create a table which may be used at
772runtime to relocate any data which was statically initialized to pointer
773values. See the code in testsuite/ld-empic for details.
774
775@cindex help
776@cindex usage
777@kindex --help
778@item --help
779Print a summary of the command-line options on the standard output and exit.
780
781@cindex link map
782@kindex -Map
783@item -Map @var{mapfile}
784Print to the file @var{mapfile} a link map---diagnostic information
785about where symbols are mapped by @code{ld}, and information on global
786common storage allocation.
b4d4e8e3 787
4551e108 788@cindex memory usage
67afbcea
DE
789@kindex --no-keep-memory
790@item --no-keep-memory
4551e108
ILT
791@code{ld} normally optimizes for speed over memory usage by caching the
792symbol tables of input files in memory. This option tells @code{ld} to
793instead optimize for memory usage, by rereading the symbol tables as
794necessary. This may be required if @code{ld} runs out of memory space
795while linking a large executable.
796
5a59e34d
ILT
797@kindex --no-warn-mismatch
798@item --no-warn-mismatch
799Normally @code{ld} will give an error if you try to link together input
800files that are mismatched for some reason, perhaps because they have
801been compiled for different processors or for different endiannesses.
802This option tells @code{ld} that it should silently permit such possible
803errors. This option should only be used with care, in cases when you
804have taken some special action that ensures that the linker errors are
805inappropriate.
806
67afbcea
DE
807@kindex --no-whole-archive
808@item --no-whole-archive
809Turn off the effect of the @code{--whole-archive} option for subsequent
810archive files.
811
812@cindex output file after errors
813@kindex --noinhibit-exec
814@item --noinhibit-exec
815Retain the executable output file whenever it is still usable.
816Normally, the linker will not produce an output file if it encounters
817errors during the link process; it exits without writing an output file
818when it issues any error whatsoever.
f22eee08 819
7f9ae73e 820@ifclear SingleFormat
9fde46a4
ILT
821@kindex --oformat
822@item --oformat @var{output-format}
1fb57a5d
RP
823@code{ld} may be configured to support more than one kind of object
824file. If your @code{ld} is configured this way, you can use the
9fde46a4 825@samp{--oformat} option to specify the binary format for the output
1fb57a5d
RP
826object file. Even when @code{ld} is configured to support alternative
827object formats, you don't usually need to specify this, as @code{ld}
828should be configured to produce as a default output format the most
829usual format on each machine. @var{output-format} is a text string, the
830name of a particular format supported by the BFD libraries. (You can
831list the available binary formats with @samp{objdump -i}.) The script
832command @code{OUTPUT_FORMAT} can also specify the output format, but
833this option overrides it. @xref{BFD}.
7f9ae73e 834@end ifclear
346535cc 835
67afbcea
DE
836@kindex -qmagic
837@item -qmagic
838This option is ignored for Linux compatibility.
c653b370 839
67afbcea
DE
840@kindex -Qy
841@item -Qy
842This option is ignored for SVR4 compatibility.
c653b370 843
67afbcea 844@kindex --relax
1c48127e
RP
845@cindex synthesizing linker
846@cindex relaxing addressing modes
67afbcea 847@item --relax
1fb57a5d
RP
848An option with machine dependent effects.
849@ifset GENERIC
67afbcea 850This option is only supported on a few targets.
1fb57a5d 851@end ifset
ec40bbb8
DM
852@ifset H8300
853@xref{H8/300,,@code{ld} and the H8/300}.
854@end ifset
1fb57a5d
RP
855@ifset I960
856@xref{i960,, @code{ld} and the Intel 960 family}.
857@end ifset
1c48127e 858
67afbcea
DE
859On some platforms, the @samp{--relax} option performs global
860optimizations that become possible when the linker resolves addressing
861in the program, such as relaxing address modes and synthesizing new
862instructions in the output object file.
1c48127e 863
1fb57a5d 864@ifset GENERIC
9fde46a4
ILT
865On platforms where this is not supported, @samp{--relax} is accepted,
866but ignored.
1fb57a5d 867@end ifset
1c48127e 868
7c8fab26
RP
869@cindex retaining specified symbols
870@cindex stripping all but some symbols
871@cindex symbols, retaining selectively
67afbcea 872@item --retain-symbols-file @var{filename}
7c8fab26
RP
873Retain @emph{only} the symbols listed in the file @var{filename},
874discarding all others. @var{filename} is simply a flat file, with one
875symbol name per line. This option is especially useful in environments
876@ifset GENERIC
877(such as VxWorks)
878@end ifset
879where a large global symbol table is accumulated gradually, to conserve
880run-time memory.
881
9fde46a4 882@samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
7c8fab26
RP
883or symbols needed for relocations.
884
9fde46a4 885You may only specify @samp{--retain-symbols-file} once in the command
7c8fab26
RP
886line. It overrides @samp{-s} and @samp{-S}.
887
a1ad915d
ILT
888@ifset GENERIC
889@item -rpath @var{dir}
890@cindex runtime library search path
891@kindex -rpath
0b0642d6
ILT
892Add a directory to the runtime library search path. This is used when
893linking an ELF executable with shared objects. All @code{-rpath}
894arguments are concatenated and passed to the runtime linker, which uses
e54bf1c1
ILT
895them to locate shared objects at runtime. The @code{-rpath} option is
896also used when locating shared objects which are needed by shared
897objects explicitly included in the link; see the description of the
c653b370
ILT
898@code{-rpath-link} option. If @code{-rpath} is not used when linking an
899ELF executable, the contents of the environment variable
900@code{LD_RUN_PATH} will be used if it is defined.
0b0642d6
ILT
901
902The @code{-rpath} option may also be used on SunOS. By default, on
903SunOS, the linker will form a runtime search patch out of all the
e54bf1c1 904@code{-L} options it is given. If a @code{-rpath} option is used, the
0b0642d6
ILT
905runtime search path will be formed exclusively using the @code{-rpath}
906options, ignoring the @code{-L} options. This can be useful when using
907gcc, which adds many @code{-L} options which may be on NFS mounted
908filesystems.
c653b370
ILT
909
910For compatibility with other ELF linkers, if the @code{-R} option is
911followed by a directory name, rather than a file name, it is treated as
912the @code{-rpath} option.
a1ad915d
ILT
913@end ifset
914
e54bf1c1
ILT
915@ifset GENERIC
916@cindex link-time runtime library search path
917@kindex -rpath-link
918@item -rpath-link @var{DIR}
919When using ELF or SunOS, one shared library may require another. This
920happens when an @code{ld -shared} link includes a shared library as one
921of the input files.
922
923When the linker encounters such a dependency when doing a non-shared,
924non-relocateable link, it will automatically try to locate the required
925shared library and include it in the link, if it is not included
926explicitly. In such a case, the @code{-rpath-link} option
927specifies the first set of directories to search. The
928@code{-rpath-link} option may specify a sequence of directory names
929either by specifying a list of names separated by colons, or by
930appearing multiple times.
931
932The linker uses the following search paths to locate required shared
933libraries.
934@enumerate
935@item
936Any directories specified by @code{-rpath-link} options.
937@item
938Any directories specified by @code{-rpath} options. The difference
939between @code{-rpath} and @code{-rpath-link} is that directories
940specified by @code{-rpath} options are included in the executable and
941used at runtime, whereas the @code{-rpath-link} option is only effective
942at link time.
943@item
c653b370
ILT
944On an ELF system, if the @code{-rpath} and @code{rpath-link} options
945were not used, search the contents of the environment variable
946@code{LD_RUN_PATH}.
947@item
e54bf1c1
ILT
948On SunOS, if the @code{-rpath} option was not used, search any
949directories specified using @code{-L} options.
950@item
951For a native linker, the contents of the environment variable
952@code{LD_LIBRARY_PATH}.
953@item
954The default directories, normally @file{/lib} and @file{/usr/lib}.
955@end enumerate
956
957If the required shared library is not found, the linker will issue a
958warning and continue with the link.
959@end ifset
960
67afbcea
DE
961@kindex -shared
962@kindex -Bshareable
4551e108 963@item -shared
67afbcea 964@itemx -Bshareable
4551e108 965@cindex shared libraries
67afbcea
DE
966Create a shared library. This is currently only supported on ELF, XCOFF
967and SunOS platforms. On SunOS, the linker will automatically create a
e54bf1c1
ILT
968shared library if the @code{-e} option is not used and there are
969undefined symbols in the link.
4551e108 970
67afbcea
DE
971@item --sort-common
972@kindex --sort-common
973This option tells @code{ld} to sort the common symbols by size when it
974places them in the appropriate output sections. First come all the one
975byte symbols, then all the two bytes, then all the four bytes, and then
976everything else. This is to prevent gaps between symbols due to
977alignment constraints.
978
979@kindex --split-by-file
980@item --split-by-file
981Similar to @code{--split-by-reloc} but creates a new output section for
982each input file.
983
984@kindex --split-by-reloc
985@item --split-by-reloc @var{count}
986Trys to creates extra sections in the output file so that no single
987output section in the file contains more than @var{count} relocations.
988This is useful when generating huge relocatable for downloading into
989certain real time kernels with the COFF object file format; since COFF
990cannot represent more than 65535 relocations in a single section. Note
991that this will fail to work with object file formats which do not
992support arbitrary sections. The linker will not split up individual
993input sections for redistribution, so if a single input section contains
01bc8f35
ILT
994more than @var{count} relocations one output section will contain that
995many relocations.
996
67afbcea
DE
997@kindex --stats
998@item --stats
999Compute and display statistics about the operation of the linker, such
1000as execution time and memory usage.
f22eee08 1001
9fde46a4 1002@kindex --traditional-format
c96386c4 1003@cindex traditional format
9fde46a4 1004@item --traditional-format
c96386c4
ILT
1005For some targets, the output of @code{ld} is different in some ways from
1006the output of some existing linker. This switch requests @code{ld} to
1007use the traditional format instead.
1008
1009@cindex dbx
1010For example, on SunOS, @code{ld} combines duplicate entries in the
1011symbol string table. This can reduce the size of an output file with
1012full debugging information by over 30 percent. Unfortunately, the SunOS
1013@code{dbx} program can not read the resulting program (@code{gdb} has no
9fde46a4 1014trouble). The @samp{--traditional-format} switch tells @code{ld} to not
c96386c4
ILT
1015combine duplicate entries.
1016
67afbcea
DE
1017@kindex -Tbss @var{org}
1018@kindex -Tdata @var{org}
1019@kindex -Ttext @var{org}
1020@cindex segment origins, cmd line
1021@item -Tbss @var{org}
1022@itemx -Tdata @var{org}
1023@itemx -Ttext @var{org}
1024Use @var{org} as the starting address for---respectively---the
1025@code{bss}, @code{data}, or the @code{text} segment of the output file.
1026@var{org} must be a single hexadecimal integer;
1027for compatibility with other linkers, you may omit the leading
1028@samp{0x} usually associated with hexadecimal values.
f22eee08 1029
2c5c0674 1030@kindex -Ur
b4d4e8e3 1031@cindex constructors
d4e5e3c3 1032@item -Ur
b4d4e8e3 1033For anything other than C++ programs, this option is equivalent to
ec40bbb8
DM
1034@samp{-r}: it generates relocatable output---i.e., an output file that can in
1035turn serve as input to @code{ld}. When linking C++ programs, @samp{-Ur}
1fb57a5d 1036@emph{does} resolve references to constructors, unlike @samp{-r}.
3e27cc11 1037It does not work to use @samp{-Ur} on files that were themselves linked
1fb57a5d 1038with @samp{-Ur}; once the constructor table has been built, it cannot
3e27cc11
DM
1039be added to. Use @samp{-Ur} only for the last partial link, and
1040@samp{-r} for the others.
b4d4e8e3 1041
01bc8f35 1042@kindex --verbose
cf2e4f5f 1043@cindex verbose
01bc8f35 1044@item --verbose
1fb57a5d 1045Display the version number for @code{ld} and list the linker emulations
cf2e4f5f
ILT
1046supported. Display which input files can and cannot be opened. Display
1047the linker script if using a default builtin script.
8ddef552 1048
5a59e34d
ILT
1049@kindex --version-script=@var{version-scriptfile}
1050@cindex version script, symbol versions
1051@itemx --version-script=@var{version-scriptfile}
1052Specify the name of a version script to the linker. This is typically
1053used when creating shared libraries to specify additional information
1054about the version heirarchy for the library being created. This option
1055is only meaningful on ELF platforms which support shared libraries.
1056@xref{Version Script}.
1057
458fc056 1058@kindex --warn-comon
7f9ae73e
RP
1059@cindex warnings, on combining symbols
1060@cindex combining symbols, warnings on
458fc056 1061@item --warn-common
2a28d8b0
DM
1062Warn when a common symbol is combined with another common symbol or with
1063a symbol definition. Unix linkers allow this somewhat sloppy practice,
1064but linkers on some other operating systems do not. This option allows
1065you to find potential problems from combining global symbols.
1cd4cca9
DM
1066Unfortunately, some C libraries use this practice, so you may get some
1067warnings about symbols in the libraries as well as in your programs.
2a28d8b0
DM
1068
1069There are three kinds of global symbols, illustrated here by C examples:
1070
1071@table @samp
1072@item int i = 1;
1073A definition, which goes in the initialized data section of the output
1074file.
1075
1076@item extern int i;
1077An undefined reference, which does not allocate space.
1078There must be either a definition or a common symbol for the
1079variable somewhere.
1080
1081@item int i;
1082A common symbol. If there are only (one or more) common symbols for a
1083variable, it goes in the uninitialized data area of the output file.
1084The linker merges multiple common symbols for the same variable into a
1085single symbol. If they are of different sizes, it picks the largest
1086size. The linker turns a common symbol into a declaration, if there is
1087a definition of the same variable.
1088@end table
1089
458fc056
ILT
1090The @samp{--warn-common} option can produce five kinds of warnings.
1091Each warning consists of a pair of lines: the first describes the symbol
1092just encountered, and the second describes the previous symbol
1093encountered with the same name. One or both of the two symbols will be
1094a common symbol.
2a28d8b0
DM
1095
1096@enumerate
1097@item
1098Turning a common symbol into a reference, because there is already a
1099definition for the symbol.
1100@smallexample
8920addc
RP
1101@var{file}(@var{section}): warning: common of `@var{symbol}'
1102 overridden by definition
2a28d8b0
DM
1103@var{file}(@var{section}): warning: defined here
1104@end smallexample
1105
1106@item
1107Turning a common symbol into a reference, because a later definition for
1108the symbol is encountered. This is the same as the previous case,
1109except that the symbols are encountered in a different order.
1110@smallexample
8920addc
RP
1111@var{file}(@var{section}): warning: definition of `@var{symbol}'
1112 overriding common
2a28d8b0
DM
1113@var{file}(@var{section}): warning: common is here
1114@end smallexample
1115
1116@item
1117Merging a common symbol with a previous same-sized common symbol.
1118@smallexample
8920addc
RP
1119@var{file}(@var{section}): warning: multiple common
1120 of `@var{symbol}'
2a28d8b0
DM
1121@var{file}(@var{section}): warning: previous common is here
1122@end smallexample
1123
1124@item
1125Merging a common symbol with a previous larger common symbol.
1126@smallexample
8920addc
RP
1127@var{file}(@var{section}): warning: common of `@var{symbol}'
1128 overridden by larger common
2a28d8b0
DM
1129@var{file}(@var{section}): warning: larger common is here
1130@end smallexample
1131
1132@item
1133Merging a common symbol with a previous smaller common symbol. This is
1134the same as the previous case, except that the symbols are
1135encountered in a different order.
1136@smallexample
8920addc
RP
1137@var{file}(@var{section}): warning: common of `@var{symbol}'
1138 overriding smaller common
2a28d8b0
DM
1139@var{file}(@var{section}): warning: smaller common is here
1140@end smallexample
1141@end enumerate
1142
458fc056
ILT
1143@kindex --warn-constructors
1144@item --warn-constructors
0b0642d6
ILT
1145Warn if any global constructors are used. This is only useful for a few
1146object file formats. For formats like COFF or ELF, the linker can not
1147detect the use of global constructors.
1148
458fc056
ILT
1149@kindex --warn-multiple-gp
1150@item --warn-multiple-gp
4b7d2399
ILT
1151Warn if multiple global pointer values are required in the output file.
1152This is only meaningful for certain processors, such as the Alpha.
1153Specifically, some processors put large-valued constants in a special
1154section. A special register (the global pointer) points into the middle
1155of this section, so that constants can be loaded efficiently via a
1156base-register relative addressing mode. Since the offset in
1157base-register relative mode is fixed and relatively small (e.g., 16
1158bits), this limits the maximum size of the constant pool. Thus, in
1159large programs, it is often necessary to use multiple global pointer
1160values in order to be able to address all possible constants. This
1161option causes a warning to be issued whenever this case occurs.
1162
458fc056 1163@kindex --warn-once
01bc8f35
ILT
1164@cindex warnings, on undefined symbols
1165@cindex undefined symbols, warnings on
458fc056 1166@item --warn-once
01bc8f35
ILT
1167Only warn once for each undefined symbol, rather than once per module
1168which refers to it.
1169
458fc056
ILT
1170@kindex --warn-section-align
1171@cindex warnings, on section alignment
1172@cindex section alignment, warnings on
1173@item --warn-section-align
1174Warn if the address of an output section is changed because of
1175alignment. Typically, the alignment will be set by an input section.
1176The address will only be changed if it not explicitly specified; that
1177is, if the @code{SECTIONS} command does not specify a start address for
1178the section (@pxref{SECTIONS}).
1179
4551e108
ILT
1180@kindex --whole-archive
1181@cindex including an entire archive
4b7d2399 1182@item --whole-archive
3c8deccc
ILT
1183For each archive mentioned on the command line after the
1184@code{--whole-archive} option, include every object file in the archive
1185in the link, rather than searching the archive for the required object
1186files. This is normally used to turn an archive file into a shared
1187library, forcing every object to be included in the resulting shared
67afbcea 1188library. This option may be used more than once.
4551e108 1189
e3d73386
ILT
1190@kindex --wrap
1191@item --wrap @var{symbol}
1192Use a wrapper function for @var{symbol}. Any undefined reference to
1193@var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any
1194undefined reference to @code{__real_@var{symbol}} will be resolved to
1195@var{symbol}.
1196
1197This can be used to provide a wrapper for a system function. The
1198wrapper function should be called @code{__wrap_@var{symbol}}. If it
1199wishes to call the system function, it should call
1200@code{__real_@var{symbol}}.
1201
1202Here is a trivial example:
1203
1204@smallexample
1205void *
1206__wrap_malloc (int c)
1207@{
1208 printf ("malloc called with %ld\n", c);
1209 return __real_malloc (c);
1210@}
1211@end smallexample
1212
1213If you link other code with this file using @code{--wrap malloc}, then
1214all calls to @code{malloc} will call the function @code{__wrap_malloc}
1215instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will
1216call the real @code{malloc} function.
1217
1218You may wish to provide a @code{__real_malloc} function as well, so that
1219links without the @code{--wrap} option will succeed. If you do this,
1220you should not put the definition of @code{__real_malloc} in the same
1221file as @code{__wrap_malloc}; if you do, the assembler may resolve the
1222call before the linker has a chance to wrap it to @code{malloc}.
1223
f22eee08 1224@end table
b4d4e8e3 1225
ec40bbb8
DM
1226@ifset UsesEnvVars
1227@node Environment
2c5c0674
RP
1228@section Environment Variables
1229
d76ae847
RP
1230You can change the behavior of @code{ld} with the environment
1231variable @code{GNUTARGET}.
2c5c0674
RP
1232
1233@kindex GNUTARGET
1234@cindex default input format
1235@code{GNUTARGET} determines the input-file object format if you don't
9fde46a4 1236use @samp{-b} (or its synonym @samp{--format}). Its value should be one
2c5c0674 1237of the BFD names for an input format (@pxref{BFD}). If there is no
246504a5 1238@code{GNUTARGET} in the environment, @code{ld} uses the natural format
9fde46a4
ILT
1239of the target. If @code{GNUTARGET} is set to @code{default} then BFD
1240attempts to discover the input format by examining binary input files;
1241this method often succeeds, but there are potential ambiguities, since
1242there is no method of ensuring that the magic number used to specify
1243object-file formats is unique. However, the configuration procedure for
1244BFD on each system places the conventional format for that system first
1245in the search-list, so ambiguities are resolved in favor of convention.
ec40bbb8 1246@end ifset
2c5c0674 1247
ec40bbb8 1248@node Commands
2c5c0674 1249@chapter Command Language
f22eee08 1250
2c5c0674 1251@cindex command files
ec40bbb8 1252The command language provides explicit control over the link process,
b4d4e8e3 1253allowing complete specification of the mapping between the linker's
ec40bbb8 1254input files and its output. It controls:
b4d4e8e3 1255@itemize @bullet
2c5c0674
RP
1256@item
1257input files
1258@item
1259file formats
1260@item
867a1b8a 1261output file layout
2c5c0674
RP
1262@item
1263addresses of sections
1264@item
1265placement of common blocks
b4d4e8e3 1266@end itemize
f22eee08 1267
f9c5c231 1268You may supply a command file (also known as a linker script) to the
ec40bbb8 1269linker either explicitly through the @samp{-T} option, or implicitly as
f9c5c231
ILT
1270an ordinary file. Normally you should use the @samp{-T} option. An
1271implicit linker script should only be used when you want to augment,
1272rather than replace, the default linker script; typically an implicit
1273linker script would consist only of @code{INPUT} or @code{GROUP}
1274commands.
1275
1276If the linker opens a file which it cannot recognize as a supported
1277object or archive format, nor as a linker script, it reports an error.
2c5c0674 1278
2c5c0674 1279@menu
2d59b2c3
RP
1280* Scripts:: Linker Scripts
1281* Expressions:: Expressions
1282* MEMORY:: MEMORY Command
1283* SECTIONS:: SECTIONS Command
c653b370 1284* PHDRS:: PHDRS Command
2d59b2c3 1285* Entry Point:: The Entry Point
5a59e34d 1286* Version Script:: Version Script
867a1b8a 1287* Option Commands:: Option Commands
2c5c0674
RP
1288@end menu
1289
ec40bbb8 1290@node Scripts
b4d4e8e3 1291@section Linker Scripts
246504a5 1292The @code{ld} command language is a collection of statements; some are
ec40bbb8
DM
1293simple keywords setting a particular option, some are used to select and
1294group input files or name output files; and two statement
b4d4e8e3
RP
1295types have a fundamental and pervasive impact on the linking process.
1296
2c5c0674
RP
1297@cindex fundamental script commands
1298@cindex commands, fundamental
1299@cindex output file layout
1300@cindex layout of output file
246504a5 1301The most fundamental command of the @code{ld} command language is the
b4d4e8e3
RP
1302@code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command
1303script must have a @code{SECTIONS} command: it specifies a
1304``picture'' of the output file's layout, in varying degrees of detail.
1305No other command is required in all cases.
1306
1307The @code{MEMORY} command complements @code{SECTIONS} by describing the
2c5c0674 1308available memory in the target architecture. This command is optional;
246504a5 1309if you don't use a @code{MEMORY} command, @code{ld} assumes sufficient
2c5c0674
RP
1310memory is available in a contiguous block for all output.
1311@xref{MEMORY}.
b4d4e8e3 1312
2c5c0674
RP
1313@cindex comments
1314You may include comments in linker scripts just as in C: delimited
1315by @samp{/*} and @samp{*/}. As in C, comments are syntactically
1316equivalent to whitespace.
1317
ec40bbb8 1318@node Expressions
f22eee08 1319@section Expressions
2c5c0674
RP
1320@cindex expression syntax
1321@cindex arithmetic
b4d4e8e3
RP
1322Many useful commands involve arithmetic expressions. The syntax for
1323expressions in the command language is identical to that of C
1324expressions, with the following features:
1325@itemize @bullet
2c5c0674
RP
1326@item
1327All expressions evaluated as integers and
f22eee08 1328are of ``long'' or ``unsigned long'' type.
2c5c0674
RP
1329@item
1330All constants are integers.
1331@item
1332All of the C arithmetic operators are provided.
1333@item
1334You may reference, define, and create global variables.
1335@item
1336You may call special purpose built-in functions.
b4d4e8e3 1337@end itemize
f22eee08 1338
2c5c0674 1339@menu
2d59b2c3
RP
1340* Integers:: Integers
1341* Symbols:: Symbol Names
1342* Location Counter:: The Location Counter
1343* Operators:: Operators
1344* Evaluation:: Evaluation
1345* Assignment:: Assignment: Defining Symbols
867a1b8a 1346* Arithmetic Functions:: Built-In Functions
67afbcea 1347* Semicolons:: Semicolon Usage
2c5c0674
RP
1348@end menu
1349
ec40bbb8 1350@node Integers
f22eee08 1351@subsection Integers
2c5c0674
RP
1352@cindex integer notation
1353@cindex octal integers
f22eee08
RP
1354An octal integer is @samp{0} followed by zero or more of the octal
1355digits (@samp{01234567}).
c653b370 1356@smallexample
2c5c0674 1357_as_octal = 0157255;
c653b370 1358@end smallexample
f22eee08 1359
2c5c0674 1360@cindex decimal integers
f22eee08
RP
1361A decimal integer starts with a non-zero digit followed by zero or
1362more digits (@samp{0123456789}).
c653b370 1363@smallexample
2c5c0674 1364_as_decimal = 57005;
c653b370 1365@end smallexample
f22eee08 1366
2c5c0674
RP
1367@cindex hexadecimal integers
1368@kindex 0x
f22eee08
RP
1369A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
1370more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
c653b370 1371@smallexample
b4d4e8e3 1372_as_hex = 0xdead;
c653b370 1373@end smallexample
f22eee08 1374
2c5c0674 1375@cindex negative integers
ec40bbb8 1376To write a negative integer, use
baaaf6f2 1377the prefix operator @samp{-} (@pxref{Operators}).
c653b370 1378@smallexample
b4d4e8e3 1379_as_neg = -57005;
c653b370 1380@end smallexample
f22eee08 1381
2c5c0674
RP
1382@cindex scaled integers
1383@cindex K and M integer suffixes
1384@cindex M and K integer suffixes
1385@cindex suffixes for integers
1386@cindex integer suffixes
b4d4e8e3
RP
1387Additionally the suffixes @code{K} and @code{M} may be used to scale a
1388constant by
c8072296
RP
1389@c TEXI2ROFF-KILL
1390@ifinfo
1391@c END TEXI2ROFF-KILL
1392@code{1024} or @code{1024*1024}
1393@c TEXI2ROFF-KILL
1394@end ifinfo
f22eee08 1395@tex
b4d4e8e3 1396${\rm 1024}$ or ${\rm 1024}^2$
f22eee08 1397@end tex
c8072296 1398@c END TEXI2ROFF-KILL
ec40bbb8 1399respectively. For example, the following all refer to the same quantity:
f22eee08 1400
c653b370 1401@smallexample
2c5c0674
RP
1402 _fourk_1 = 4K;
1403 _fourk_2 = 4096;
1404 _fourk_3 = 0x1000;
c653b370 1405@end smallexample
b4d4e8e3 1406
ec40bbb8 1407@node Symbols
b4d4e8e3 1408@subsection Symbol Names
2c5c0674
RP
1409@cindex symbol names
1410@cindex names
1411@cindex quoted symbol names
1412@kindex "
1fb57a5d
RP
1413Unless quoted, symbol names start with a letter, underscore, or point
1414and may include any letters, underscores, digits, points,
1415and hyphens. Unquoted symbol names must not conflict with any
b4d4e8e3
RP
1416keywords. You can specify a symbol which contains odd characters or has
1417the same name as a keyword, by surrounding the symbol name in double quotes:
c653b370 1418@smallexample
b4d4e8e3
RP
1419 "SECTION" = 9;
1420 "with a space" = "also with a space" + 10;
c653b370 1421@end smallexample
b4d4e8e3 1422
1fb57a5d
RP
1423Since symbols can contain many non-alphabetic characters, it is safest
1424to delimit symbols with spaces. For example, @samp{A-B} is one symbol,
1425whereas @samp{A - B} is an expression involving subtraction.
1426
ec40bbb8 1427@node Location Counter
b4d4e8e3 1428@subsection The Location Counter
2c5c0674
RP
1429@kindex .
1430@cindex dot
1431@cindex location counter
1432@cindex current output location
b4d4e8e3
RP
1433The special linker variable @dfn{dot} @samp{.} always contains the
1434current output location counter. Since the @code{.} always refers to
1435a location in an output section, it must always appear in an
1436expression within a @code{SECTIONS} command. The @code{.} symbol
1437may appear anywhere that an ordinary symbol is allowed in an
1438expression, but its assignments have a side effect. Assigning a value
1439to the @code{.} symbol will cause the location counter to be moved.
2c5c0674 1440@cindex holes
b4d4e8e3
RP
1441This may be used to create holes in the output section. The location
1442counter may never be moved backwards.
c653b370 1443@smallexample
2c5c0674
RP
1444SECTIONS
1445@{
d4e5e3c3
DM
1446 output :
1447 @{
1448 file1(.text)
1449 . = . + 1000;
1450 file2(.text)
1451 . += 1000;
1452 file3(.text)
1453 @} = 0x1234;
2c5c0674 1454@}
c653b370 1455@end smallexample
2c5c0674
RP
1456@noindent
1457In the previous example, @code{file1} is located at the beginning of the
1458output section, then there is a 1000 byte gap. Then @code{file2}
1459appears, also with a 1000 byte gap following before @code{file3} is
1460loaded. The notation @samp{= 0x1234} specifies what data to write in
1461the gaps (@pxref{Section Options}).
b4d4e8e3 1462
d4e5e3c3
DM
1463@iftex
1464@vfill
1465@end iftex
1466
c653b370 1467@need 2000
ec40bbb8 1468@node Operators
f22eee08 1469@subsection Operators
2c5c0674
RP
1470@cindex Operators for arithmetic
1471@cindex arithmetic operators
1472@cindex precedence in expressions
b4d4e8e3 1473The linker recognizes the standard C set of arithmetic operators, with
f22eee08 1474the standard bindings and precedence levels:
c8072296 1475@c TEXI2ROFF-KILL
b4d4e8e3 1476@ifinfo
c8072296 1477@c END TEXI2ROFF-KILL
c653b370 1478@smallexample
c8072296 1479precedence associativity Operators Notes
b4d4e8e3 1480(highest)
c8072296
RP
14811 left ! - ~ (1)
14822 left * / %
14833 left + -
14844 left >> <<
14855 left == != > < <= >=
14866 left &
14877 left |
14888 left &&
14899 left ||
149010 right ? :
149111 right &= += -= *= /= (2)
b4d4e8e3 1492(lowest)
c653b370 1493@end smallexample
2c5c0674
RP
1494Notes:
1495(1) Prefix operators
baaaf6f2 1496(2) @xref{Assignment}.
c8072296 1497@c TEXI2ROFF-KILL
b4d4e8e3 1498@end ifinfo
f22eee08 1499@tex
2c5c0674 1500\vskip \baselineskip
feb20cfb 1501%"lispnarrowing" is the extra indent used generally for smallexample
2c5c0674 1502\hskip\lispnarrowing\vbox{\offinterlineskip
f22eee08
RP
1503\hrule
1504\halign
2c5c0674
RP
1505{\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
1506height2pt&\omit&&\omit&&\omit&\cr
1507&Precedence&& Associativity &&{\rm Operators}&\cr
1508height2pt&\omit&&\omit&&\omit&\cr
f22eee08 1509\noalign{\hrule}
2c5c0674 1510height2pt&\omit&&\omit&&\omit&\cr
b4d4e8e3 1511&highest&&&&&\cr
2c5c0674
RP
1512% '176 is tilde, '~' in tt font
1513&1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
1514&2&&left&&* / \%&\cr
1515&3&&left&&+ -&\cr
1516&4&&left&&>> <<&\cr
1517&5&&left&&== != > < <= >=&\cr
f22eee08 1518&6&&left&&\&&\cr
f22eee08 1519&7&&left&&|&\cr
f22eee08 1520&8&&left&&{\&\&}&\cr
f22eee08 1521&9&&left&&||&\cr
2c5c0674
RP
1522&10&&right&&? :&\cr
1523&11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr
b4d4e8e3 1524&lowest&&&&&\cr
2c5c0674 1525height2pt&\omit&&\omit&&\omit&\cr}
f22eee08
RP
1526\hrule}
1527@end tex
2c5c0674
RP
1528@iftex
1529{
1530@obeylines@parskip=0pt@parindent=0pt
1531@dag@quad Prefix operators.
1532@ddag@quad @xref{Assignment}.
1533}
1534@end iftex
c8072296 1535@c END TEXI2ROFF-KILL
f22eee08 1536
ec40bbb8 1537@node Evaluation
b4d4e8e3
RP
1538@subsection Evaluation
1539
2c5c0674
RP
1540@cindex lazy evaluation
1541@cindex expression evaluation order
b4d4e8e3
RP
1542The linker uses ``lazy evaluation'' for expressions; it only calculates
1543an expression when absolutely necessary. The linker needs the value of
1544the start address, and the lengths of memory regions, in order to do any
1545linking at all; these values are computed as soon as possible when the
1546linker reads in the command file. However, other values (such as symbol
1547values) are not known or needed until after storage allocation. Such
1548values are evaluated later, when other information (such as the sizes of
1549output sections) is available for use in the symbol assignment
1550expression.
1551
ec40bbb8 1552@node Assignment
b4d4e8e3 1553@subsection Assignment: Defining Symbols
2c5c0674
RP
1554@cindex assignment in scripts
1555@cindex symbol definition, scripts
1556@cindex variables, defining
b4d4e8e3
RP
1557You may create global symbols, and assign values (addresses) to global
1558symbols, using any of the C assignment operators:
1559
1560@table @code
1561@item @var{symbol} = @var{expression} ;
2c5c0674 1562@itemx @var{symbol} &= @var{expression} ;
b4d4e8e3
RP
1563@itemx @var{symbol} += @var{expression} ;
1564@itemx @var{symbol} -= @var{expression} ;
1565@itemx @var{symbol} *= @var{expression} ;
1566@itemx @var{symbol} /= @var{expression} ;
1567@end table
1568
246504a5 1569Two things distinguish assignment from other operators in @code{ld}
b4d4e8e3
RP
1570expressions.
1571@itemize @bullet
2c5c0674
RP
1572@item
1573Assignment may only be used at the root of an expression;
b4d4e8e3 1574@samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error.
2c5c0674
RP
1575
1576@kindex ;
1577@cindex semicolon
1578@item
d76ae847
RP
1579You must place a trailing semicolon (``@key{;}'') at the end of an
1580assignment statement.
b4d4e8e3
RP
1581@end itemize
1582
1583Assignment statements may appear:
1584@itemize @bullet
2c5c0674 1585@item
246504a5 1586as commands in their own right in an @code{ld} script; or
2c5c0674
RP
1587@item
1588as independent statements within a @code{SECTIONS} command; or
1589@item
1590as part of the contents of a section definition in a
b4d4e8e3
RP
1591@code{SECTIONS} command.
1592@end itemize
1593
1594The first two cases are equivalent in effect---both define a symbol with
ec40bbb8 1595an absolute address. The last case defines a symbol whose address is
b4d4e8e3
RP
1596relative to a particular section (@pxref{SECTIONS}).
1597
2c5c0674
RP
1598@cindex absolute and relocatable symbols
1599@cindex relocatable and absolute symbols
1600@cindex symbols, relocatable and absolute
1601When a linker expression is evaluated and assigned to a variable, it is
1602given either an absolute or a relocatable type. An absolute expression
1603type is one in which the symbol contains the value that it will have in
867a1b8a 1604the output file; a relocatable expression type is one in which the
2c5c0674 1605value is expressed as a fixed offset from the base of a section.
b4d4e8e3
RP
1606
1607The type of the expression is controlled by its position in the script
2c5c0674
RP
1608file. A symbol assigned within a section definition is created relative
1609to the base of the section; a symbol assigned in any other place is
1610created as an absolute symbol. Since a symbol created within a
1611section definition is relative to the base of the section, it
1612will remain relocatable if relocatable output is requested. A symbol
1613may be created with an absolute value even when assigned to within a
1614section definition by using the absolute assignment function
1615@code{ABSOLUTE}. For example, to create an absolute symbol whose address
1616is the last byte of an output section named @code{.data}:
c653b370 1617@smallexample
2c5c0674 1618SECTIONS@{ @dots{}
d4e5e3c3
DM
1619 .data :
1620 @{
1621 *(.data)
1622 _edata = ABSOLUTE(.) ;
1623 @}
2c5c0674 1624@dots{} @}
c653b370 1625@end smallexample
b4d4e8e3 1626
2c5c0674
RP
1627The linker tries to put off the evaluation of an assignment until all
1628the terms in the source expression are known (@pxref{Evaluation}). For
ec40bbb8 1629instance, the sizes of sections cannot be known until after allocation,
2c5c0674
RP
1630so assignments dependent upon these are not performed until after
1631allocation. Some expressions, such as those depending upon the location
1632counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the
1633result of an expression is required, but the value is not available,
1634then an error results. For example, a script like the following
c653b370 1635@smallexample
2c5c0674 1636SECTIONS @{ @dots{}
d4e5e3c3
DM
1637 text 9+this_isnt_constant :
1638 @{ @dots{}
1639 @}
2c5c0674 1640@dots{} @}
c653b370 1641@end smallexample
2c5c0674
RP
1642@kindex Non constant expression
1643@noindent
1644will cause the error message ``@code{Non constant expression for initial
0b3499f6
ILT
1645address}''.
1646
1647@cindex provide
1648In some cases, it is desirable for a linker script to define a symbol
1649only if it is referenced, and only if it is not defined by any object
1650included in the link. For example, traditional linkers defined the
1651symbol @samp{etext}. However, ANSI C requires that the user be able to
1652use @samp{etext} as a function name without encountering an error.
1653The @code{PROVIDE} keyword may be used to define a symbol, such as
1654@samp{etext}, only if it is referenced but not defined. The syntax is
1655@code{PROVIDE(@var{symbol} = @var{expression})}.
b4d4e8e3 1656
867a1b8a
DM
1657@node Arithmetic Functions
1658@subsection Arithmetic Functions
2c5c0674 1659@cindex functions in expression language
ec40bbb8 1660The command language includes a number of built-in
2c5c0674
RP
1661functions for use in link script expressions.
1662@table @code
2c5c0674
RP
1663@kindex ABSOLUTE(@var{exp})
1664@cindex expression, absolute
c653b370 1665@item ABSOLUTE(@var{exp})
ec40bbb8
DM
1666Return the absolute (non-relocatable, as opposed to non-negative) value
1667of the expression @var{exp}. Primarily useful to assign an absolute
1668value to a symbol within a section definition, where symbol values are
1669normally section-relative.
2c5c0674 1670
2c5c0674
RP
1671@kindex ADDR(@var{section})
1672@cindex section address
c653b370 1673@item ADDR(@var{section})
ec40bbb8 1674Return the absolute address of the named @var{section}. Your script must
b4d4e8e3 1675previously have defined the location of that section. In the following
ec40bbb8 1676example, @code{symbol_1} and @code{symbol_2} are assigned identical
b4d4e8e3 1677values:
c653b370
ILT
1678@smallexample
1679@group
2c5c0674 1680SECTIONS@{ @dots{}
d4e5e3c3
DM
1681 .output1 :
1682 @{
1683 start_of_output_1 = ABSOLUTE(.);
1684 @dots{}
1685 @}
1686 .output :
1687 @{
1688 symbol_1 = ADDR(.output1);
1689 symbol_2 = start_of_output_1;
1690 @}
2c5c0674 1691@dots{} @}
c653b370
ILT
1692@end group
1693@end smallexample
2c5c0674 1694
5735ac9e
ILT
1695@kindex LOADADDR(@var{section})
1696@cindex section load address
1697@item LOADADDR(@var{section})
1698Return the absolute load address of the named @var{section}. This is
1699normally the same as @code{ADDR}, but it may be different if the
1700@code{AT} keyword is used in the section definition (@pxref{Section
1701Options}).
1702
2c5c0674
RP
1703@kindex ALIGN(@var{exp})
1704@cindex rounding up location counter
c653b370 1705@item ALIGN(@var{exp})
ec40bbb8 1706Return the result of the current location counter (@code{.}) aligned to
2c5c0674
RP
1707the next @var{exp} boundary. @var{exp} must be an expression whose
1708value is a power of two. This is equivalent to
c653b370 1709@smallexample
cb70c872 1710(. + @var{exp} - 1) & ~(@var{exp} - 1)
c653b370 1711@end smallexample
2c5c0674
RP
1712
1713@code{ALIGN} doesn't change the value of the location counter---it just
1714does arithmetic on it. As an example, to align the output @code{.data}
1715section to the next @code{0x2000} byte boundary after the preceding
1716section and to set a variable within the section to the next
1717@code{0x8000} boundary after the input sections:
c653b370
ILT
1718@smallexample
1719@group
2c5c0674 1720SECTIONS@{ @dots{}
d4e5e3c3
DM
1721 .data ALIGN(0x2000): @{
1722 *(.data)
1723 variable = ALIGN(0x8000);
1724 @}
2c5c0674 1725@dots{} @}
c653b370
ILT
1726@end group
1727@end smallexample
2c5c0674
RP
1728@noindent
1729The first use of @code{ALIGN} in this example specifies the location of
1730a section because it is used as the optional @var{start} attribute of a
1731section definition (@pxref{Section Options}). The second use simply
1732defines the value of a variable.
1733
1734The built-in @code{NEXT} is closely related to @code{ALIGN}.
1735
2c5c0674
RP
1736@kindex DEFINED(@var{symbol})
1737@cindex symbol defaults
c653b370 1738@item DEFINED(@var{symbol})
ec40bbb8
DM
1739Return 1 if @var{symbol} is in the linker global symbol table and is
1740defined, otherwise return 0. You can use this function to provide default
1741values for symbols. For example, the following command-file fragment shows how
2c5c0674
RP
1742to set a global symbol @code{begin} to the first location in the
1743@code{.text} section---but if a symbol called @code{begin} already
1744existed, its value is preserved:
d4e5e3c3 1745
c8072296 1746@smallexample
c653b370 1747@group
2c5c0674 1748SECTIONS@{ @dots{}
d4e5e3c3
DM
1749 .text : @{
1750 begin = DEFINED(begin) ? begin : . ;
1751 @dots{}
1752 @}
2c5c0674 1753@dots{} @}
c653b370 1754@end group
c8072296 1755@end smallexample
f22eee08 1756
2c5c0674
RP
1757@kindex NEXT(@var{exp})
1758@cindex unallocated address, next
c653b370 1759@item NEXT(@var{exp})
ec40bbb8
DM
1760Return the next unallocated address that is a multiple of @var{exp}.
1761This function is closely related to @code{ALIGN(@var{exp})}; unless you
2c5c0674 1762use the @code{MEMORY} command to define discontinuous memory for the
ec40bbb8 1763output file, the two functions are equivalent.
2c5c0674 1764
2c5c0674
RP
1765@kindex SIZEOF(@var{section})
1766@cindex section size
c653b370 1767@item SIZEOF(@var{section})
ec40bbb8
DM
1768Return the size in bytes of the named @var{section}, if that section has
1769been allocated. In the following example, @code{symbol_1} and
f22eee08 1770@code{symbol_2} are assigned identical values:
ec40bbb8 1771@c What does it return if the section hasn't been allocated? 0?
c653b370
ILT
1772@smallexample
1773@group
2c5c0674 1774SECTIONS@{ @dots{}
d4e5e3c3
DM
1775 .output @{
1776 .start = . ;
1777 @dots{}
1778 .end = . ;
1779 @}
1780 symbol_1 = .end - .start ;
1781 symbol_2 = SIZEOF(.output);
2c5c0674 1782@dots{} @}
c653b370
ILT
1783@end group
1784@end smallexample
f22eee08 1785
2c5c0674
RP
1786@kindex SIZEOF_HEADERS
1787@cindex header size
2c5c0674 1788@kindex sizeof_headers
c653b370
ILT
1789@item SIZEOF_HEADERS
1790@itemx sizeof_headers
ec40bbb8 1791Return the size in bytes of the output file's headers. You can use this number
2c5c0674
RP
1792as the start address of the first section, if you choose, to facilitate
1793paging.
1794
b61364cc
ILT
1795@kindex MAX
1796@item MAX(@var{exp1}, @var{exp2})
1797Returns the maximum of @var{exp1} and @var{exp2}.
1798
1799@kindex MIN
1800@item MIN(@var{exp1}, @var{exp2})
1801Returns the minimum of @var{exp1} and @var{exp2}.
1802
2c5c0674
RP
1803@end table
1804
67afbcea
DE
1805@node Semicolons
1806@subsection Semicolons
1807
1808Semicolons (``@key{;}'') are required in the following places. In all
1809other places they can appear for aesthetic reasons but are otherwise ignored.
1810
1811@table @code
1812@item Assignment
1813Semicolons must appear at the end of assignment expressions.
1814@xref{Assignment}
1815
1816@item PHDRS
1817Semicolons must appear at the end of a @code{PHDRS} statement.
1818@xref{PHDRS}
1819@end table
1820
ec40bbb8 1821@node MEMORY
867a1b8a 1822@section Memory Layout
2c5c0674
RP
1823@kindex MEMORY
1824@cindex regions of memory
1825@cindex discontinuous memory
1826@cindex allocating memory
ec40bbb8
DM
1827The linker's default configuration permits allocation of all available memory.
1828You can override this configuration by using the @code{MEMORY} command. The
b4d4e8e3
RP
1829@code{MEMORY} command describes the location and size of blocks of
1830memory in the target. By using it carefully, you can describe which
1831memory regions may be used by the linker, and which memory regions it
1832must avoid. The linker does not shuffle sections to fit into the
1833available regions, but does move the requested sections into the correct
1834regions and issue errors when the regions become too full.
1835
867a1b8a 1836A command file may contain at most one use of the @code{MEMORY}
b4d4e8e3
RP
1837command; however, you can define as many blocks of memory within it as
1838you wish. The syntax is:
c8072296 1839
c653b370
ILT
1840@smallexample
1841@group
b4d4e8e3 1842MEMORY
d4e5e3c3
DM
1843 @{
1844 @var{name} (@var{attr}) : ORIGIN = @var{origin}, LENGTH = @var{len}
1845 @dots{}
1846 @}
c653b370
ILT
1847@end group
1848@end smallexample
f22eee08 1849@table @code
2c5c0674 1850@cindex naming memory regions
d4e5e3c3 1851@item @var{name}
f22eee08
RP
1852is a name used internally by the linker to refer to the region. Any
1853symbol name may be used. The region names are stored in a separate
ec40bbb8 1854name space, and will not conflict with symbols, file names or section
b4d4e8e3 1855names. Use distinct names to specify multiple regions.
d4e5e3c3 1856
2c5c0674 1857@cindex memory region attributes
d4e5e3c3 1858@item (@var{attr})
5a59e34d
ILT
1859is an optional list of attributes that specify whether to use a
1860particular memory to place sections that are not listed in the linker
1861script. Valid attribute lists must be made up of the characters
1862``@code{ALIRWX}'' that match section attributes. If you omit the
1863attribute list, you may omit the parentheses around it as well. The
1864attributes currently supported are:
1865
1866@table @samp
1867@item @code{Letter}
1868@code{Section Attribute}
1869
1870@item @code{R}
1871Read-only sections.
1872
1873@item @code{W}
1874Read/write sections.
1875
1876@item @code{X}
1877Sections containing executable code.
1878
1879@item @code{A}
1880Allocated sections.
1881
1882@item @code{I}
1883Initialized sections.
1884
1885@item @code{L}
1886Same as @code{I}.
1887
1888@item @code{!}
1889Invert the sense of any of the following attributes.
1890@end table
d4e5e3c3 1891
cb70c872
RP
1892@kindex ORIGIN =
1893@kindex o =
1894@kindex org =
d4e5e3c3 1895@item @var{origin}
ec40bbb8
DM
1896is the start address of the region in physical memory. It is
1897an expression that must evaluate to a constant before
f22eee08 1898memory allocation is performed. The keyword @code{ORIGIN} may be
867a1b8a 1899abbreviated to @code{org} or @code{o} (but not, for example, @samp{ORG}).
d4e5e3c3 1900
cb70c872
RP
1901@kindex LENGTH =
1902@kindex len =
1903@kindex l =
d4e5e3c3 1904@item @var{len}
b4d4e8e3 1905is the size in bytes of the region (an expression).
2c5c0674 1906The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
f22eee08
RP
1907@end table
1908
1909For example, to specify that memory has two regions available for
5a59e34d
ILT
1910allocation---one starting at 0 for 256 kilobytes, and the other starting
1911at @code{0x40000000} for four megabytes. The @code{rom} memory region
1912will get all sections without an explicit memory register that are
1913either read-only or contain code, while the @code{ram} memory region
1914will get the sections.
f22eee08 1915
c653b370
ILT
1916@smallexample
1917@group
b4d4e8e3 1918MEMORY
d4e5e3c3 1919 @{
5a59e34d
ILT
1920 rom (rx) : ORIGIN = 0, LENGTH = 256K
1921 ram (!rx) : org = 0x40000000, l = 4M
d4e5e3c3 1922 @}
c653b370
ILT
1923@end group
1924@end smallexample
f22eee08 1925
b4d4e8e3 1926Once you have defined a region of memory named @var{mem}, you can direct
2c5c0674
RP
1927specific output sections there by using a command ending in
1928@samp{>@var{mem}} within the @code{SECTIONS} command (@pxref{Section
1929Options}). If the combined output sections directed to a region are too
1930big for the region, the linker will issue an error message.
b4d4e8e3 1931
ec40bbb8 1932@node SECTIONS
867a1b8a 1933@section Specifying Output Sections
67c4333b 1934
2c5c0674 1935@kindex SECTIONS
b4d4e8e3 1936The @code{SECTIONS} command controls exactly where input sections are
867a1b8a
DM
1937placed into output sections, their order in the output file, and to
1938which output sections they are allocated.
b4d4e8e3 1939
867a1b8a 1940You may use at most one @code{SECTIONS} command in a script file,
b4d4e8e3
RP
1941but you can have as many statements within it as you wish. Statements
1942within the @code{SECTIONS} command can do one of three things:
67c4333b 1943
b4d4e8e3
RP
1944@itemize @bullet
1945@item
1946define the entry point;
67c4333b 1947
b4d4e8e3
RP
1948@item
1949assign a value to a symbol;
67c4333b 1950
b4d4e8e3 1951@item
867a1b8a
DM
1952describe the placement of a named output section, and which input
1953sections go into it.
b4d4e8e3
RP
1954@end itemize
1955
8920addc
RP
1956You can also use the first two operations---defining the entry point and
1957defining symbols---outside the @code{SECTIONS} command: @pxref{Entry
baaaf6f2 1958Point}, and @ref{Assignment}. They are permitted here as well for
8920addc
RP
1959your convenience in reading the script, so that symbols and the entry
1960point can be defined at meaningful points in your output-file layout.
f22eee08 1961
67c4333b 1962If you do not use a @code{SECTIONS} command, the linker places each input
867a1b8a
DM
1963section into an identically named output section in the order that the
1964sections are first encountered in the input files. If all input sections
1965are present in the first file, for example, the order of sections in the
1966output file will match the order in the first input file.
b4d4e8e3 1967
2c5c0674 1968@menu
2d59b2c3 1969* Section Definition:: Section Definitions
867a1b8a
DM
1970* Section Placement:: Section Placement
1971* Section Data Expressions:: Section Data Expressions
2d59b2c3 1972* Section Options:: Optional Section Attributes
b61364cc 1973* Overlays:: Overlays
2c5c0674
RP
1974@end menu
1975
ec40bbb8 1976@node Section Definition
b4d4e8e3 1977@subsection Section Definitions
2c5c0674 1978@cindex section definition
b4d4e8e3 1979The most frequently used statement in the @code{SECTIONS} command is
867a1b8a 1980the @dfn{section definition}, which specifies the
b4d4e8e3 1981properties of an output section: its location, alignment, contents,
ec40bbb8 1982fill pattern, and target memory region. Most of
b4d4e8e3
RP
1983these specifications are optional; the simplest form of a section
1984definition is
c653b370 1985@smallexample
2c5c0674 1986SECTIONS @{ @dots{}
d4e5e3c3
DM
1987 @var{secname} : @{
1988 @var{contents}
1989 @}
2c5c0674 1990@dots{} @}
c653b370 1991@end smallexample
2c5c0674 1992@cindex naming output sections
b4d4e8e3
RP
1993@noindent
1994@var{secname} is the name of the output section, and @var{contents} a
ec40bbb8 1995specification of what goes there---for example, a list of input files or
5a59e34d
ILT
1996sections of input files (@pxref{Section Placement}). The whitespace
1997around @var{secname} is required, so that the section name is
1998unambiguous. The other whitespace shown is optional. You do need the
1999colon @samp{:} and the braces @samp{@{@}}, however.
b4d4e8e3
RP
2000
2001@var{secname} must meet the constraints of your output format. In
2002formats which only support a limited number of sections, such as
2003@code{a.out}, the name must be one of the names supported by the format
2c5c0674
RP
2004(@code{a.out}, for example, allows only @code{.text}, @code{.data} or
2005@code{.bss}). If the output format supports any number of sections, but
2006with numbers and not names (as is the case for Oasys), the name should be
2007supplied as a quoted numeric string. A section name may consist of any
867a1b8a 2008sequence of characters, but any name which does not conform to the standard
246504a5 2009@code{ld} symbol name syntax must be quoted.
ec40bbb8 2010@xref{Symbols, , Symbol Names}.
2c5c0674 2011
cf2e4f5f
ILT
2012The special @var{secname} @samp{/DISCARD/} may be used to discard input
2013sections. Any sections which are assigned to an output section named
2014@samp{/DISCARD/} are not included in the final link output.
2015
f9d3d71a
ILT
2016The linker will not create output sections which do not have any
2017contents. This is for convenience when referring to input sections that
2018may or may not exist. For example,
c653b370
ILT
2019@smallexample
2020.foo @{ *(.foo) @}
2021@end smallexample
f9d3d71a
ILT
2022will only create a @samp{.foo} section in the output file if there is a
2023@samp{.foo} section in at least one input file.
2024
867a1b8a
DM
2025@node Section Placement
2026@subsection Section Placement
67c4333b 2027
2c5c0674 2028@cindex contents of a section
67c4333b
RP
2029In a section definition, you can specify the contents of an output
2030section by listing particular input files, by listing particular
2031input-file sections, or by a combination of the two. You can also place
2032arbitrary data in the section, and define symbols relative to the
2033beginning of the section.
b4d4e8e3
RP
2034
2035The @var{contents} of a section definition may include any of the
2036following kinds of statement. You can include as many of these as you
2037like in a single section definition, separated from one another by
86bc0974 2038whitespace.
f22eee08 2039
b4d4e8e3 2040@table @code
2c5c0674
RP
2041@kindex @var{filename}
2042@cindex input files, section defn
2043@cindex files, including in output sections
d4e5e3c3 2044@item @var{filename}
b4d4e8e3 2045You may simply name a particular input file to be placed in the current
2c5c0674 2046output section; @emph{all} sections from that file are placed in the
867a1b8a
DM
2047current section definition. If the file name has already been mentioned
2048in another section definition, with an explicit section name list, then
2049only those sections which have not yet been allocated are used.
2050
2051To specify a list of particular files by name:
c653b370 2052@smallexample
cb70c872 2053.data : @{ afile.o bfile.o cfile.o @}
c653b370 2054@end smallexample
2c5c0674
RP
2055@noindent
2056The example also illustrates that multiple statements can be included in
ec40bbb8 2057the contents of a section definition, since each file name is a separate
2c5c0674 2058statement.
f22eee08 2059
d4e5e3c3
DM
2060@kindex @var{filename}(@var{section})
2061@cindex files and sections, section defn
2c5c0674 2062@item @var{filename}( @var{section} )
4fea1383 2063@itemx @var{filename}( @var{section} , @var{section}, @dots{} )
2c5c0674 2064@itemx @var{filename}( @var{section} @var{section} @dots{} )
5a59e34d
ILT
2065You can name one or more sections from your input files, for insertion
2066in the current output section. If you wish to specify a list of
2067input-file sections inside the parentheses, separate the section names
2068with whitespace.
2c5c0674 2069
d4e5e3c3
DM
2070@cindex input sections to output section
2071@kindex *(@var{section})
b4d4e8e3
RP
2072@item * (@var{section})
2073@itemx * (@var{section}, @var{section}, @dots{})
836a5ee4 2074@itemx * (@var{section} @var{section} @dots{})
b4d4e8e3 2075Instead of explicitly naming particular input files in a link control
246504a5 2076script, you can refer to @emph{all} files from the @code{ld} command
ec40bbb8 2077line: use @samp{*} instead of a particular file name before the
b4d4e8e3
RP
2078parenthesized input-file section list.
2079
867a1b8a
DM
2080If you have already explicitly included some files by name, @samp{*}
2081refers to all @emph{remaining} files---those whose places in the output
2082file have not yet been defined.
2083
ec40bbb8 2084For example, to copy sections @code{1} through @code{4} from an Oasys file
b4d4e8e3
RP
2085into the @code{.text} section of an @code{a.out} file, and sections @code{13}
2086and @code{14} into the @code{.data} section:
c653b370
ILT
2087@smallexample
2088@group
2c5c0674 2089SECTIONS @{
d4e5e3c3
DM
2090 .text :@{
2091 *("1" "2" "3" "4")
2092 @}
2093
2094 .data :@{
2095 *("13" "14")
2096 @}
b4d4e8e3 2097@}
c653b370
ILT
2098@end group
2099@end smallexample
f22eee08 2100
d4e5e3c3 2101@cindex @code{[@var{section}@dots{}]}, not supported
836a5ee4
DM
2102@samp{[ @var{section} @dots{} ]} used to be accepted as an alternate way
2103to specify named sections from all unallocated input files. Because
2104some operating systems (VMS) allow brackets in file names, that notation
2105is no longer supported.
2106
2c5c0674
RP
2107@cindex uninitialized data
2108@cindex commons in output
d4e5e3c3
DM
2109@kindex *( COMMON )
2110@item @var{filename}@code{( COMMON )}
2111@itemx *( COMMON )
b4d4e8e3 2112Specify where in your output file to place uninitialized data
d76ae847 2113with this notation. @code{*(COMMON)} by itself refers to all
b4d4e8e3
RP
2114uninitialized data from all input files (so far as it is not yet
2115allocated); @var{filename}@code{(COMMON)} refers to uninitialized data
2116from a particular file. Both are special cases of the general
2117mechanisms for specifying where to place input-file sections:
246504a5 2118@code{ld} permits you to refer to uninitialized data as if it
b4d4e8e3
RP
2119were in an input-file section named @code{COMMON}, regardless of the
2120input file's format.
2121@end table
2122
86bc0974 2123In any place where you may use a specific file or section name, you may
c2ba3684
ILT
2124also use a wildcard pattern. The linker handles wildcards much as the
2125Unix shell does. A @samp{*} character matches any number of characters.
2126A @samp{?} character matches any single character. The sequence
2127@samp{[@var{chars}]} will match a single instance of any of the
86bc0974
ILT
2128@var{chars}; the @samp{-} character may be used to specify a range of
2129characters, as in @samp{[a-z]} to match any lower case letter. A
2130@samp{\} character may be used to quote the following character.
2131
c2ba3684
ILT
2132When a file name is matched with a wildcard, the wildcard characters
2133will not match a @samp{/} character (used to separate directory names on
86bc0974 2134Unix). A pattern consisting of a single @samp{*} character is an
c2ba3684
ILT
2135exception; it will always match any file name. In a section name, the
2136wildcard characters will match a @samp{/} character.
2137
2138Wildcards only match files which are explicitly specified on the command
2139line. The linker does not search directories to expand wildcards.
2140However, if you specify a simple file name---a name with no wildcard
2141characters---in a linker script, and the file name is not also specified
2142on the command line, the linker will attempt to open the file as though
2143it appeared on the command line.
86bc0974
ILT
2144
2145In the following example, the command script arranges the output file
2146into three consecutive sections, named @code{.text}, @code{.data}, and
b4d4e8e3
RP
2147@code{.bss}, taking the input for each from the correspondingly named
2148sections of all the input files:
d4e5e3c3 2149
c653b370
ILT
2150@smallexample
2151@group
2c5c0674 2152SECTIONS @{
d76ae847
RP
2153 .text : @{ *(.text) @}
2154 .data : @{ *(.data) @}
2155 .bss : @{ *(.bss) *(COMMON) @}
2c5c0674 2156@}
c653b370
ILT
2157@end group
2158@end smallexample
b4d4e8e3
RP
2159
2160The following example reads all of the sections from file @code{all.o}
2161and places them at the start of output section @code{outputa} which
2162starts at location @code{0x10000}. All of section @code{.input1} from
2163file @code{foo.o} follows immediately, in the same output section. All
2164of section @code{.input2} from @code{foo.o} goes into output section
2165@code{outputb}, followed by section @code{.input1} from @code{foo1.o}.
2166All of the remaining @code{.input1} and @code{.input2} sections from any
2167files are written to output section @code{outputc}.
2168
c653b370
ILT
2169@smallexample
2170@group
2c5c0674 2171SECTIONS @{
d4e5e3c3
DM
2172 outputa 0x10000 :
2173 @{
2174 all.o
2175 foo.o (.input1)
2176 @}
2177 outputb :
2178 @{
2179 foo.o (.input2)
2180 foo1.o (.input1)
2181 @}
2182 outputc :
2183 @{
2184 *(.input1)
2185 *(.input2)
2186 @}
2c5c0674 2187@}
c653b370
ILT
2188@end group
2189@end smallexample
b4d4e8e3 2190
86bc0974
ILT
2191This example shows how wildcard patterns might be used to partition
2192files. All @code{.text} sections are placed in @code{.text}, and all
2193@code{.bss} sections are placed in @code{.bss}. For all files beginning
2194with an upper case character, the @code{.data} section is placed into
2195@code{.DATA}; for all other files, the @code{.data} section is placed
2196into @code{.data}.
2197
2198@smallexample
2199@group
2200SECTIONS @{
2201 .text : @{ *(.text) @}
2202 .DATA : @{ [A-Z]*(.data) @}
2203 .data : @{ *(.data) @}
2204 .bss : @{ *(.bss) @}
2205@}
2206@end group
2207@end smallexample
2208
867a1b8a
DM
2209@node Section Data Expressions
2210@subsection Section Data Expressions
67c4333b 2211
867a1b8a 2212@cindex expressions in a section
67c4333b
RP
2213The foregoing statements arrange, in your output file, data originating
2214from your input files. You can also place data directly in an output
2215section from the link command script. Most of these additional
baaaf6f2 2216statements involve expressions (@pxref{Expressions}). Although these
67c4333b
RP
2217statements are shown separately here for ease of presentation, no such
2218segregation is needed within a section definition in the @code{SECTIONS}
2219command; you can intermix them freely with any of the statements we've
2220just described.
f22eee08 2221
b4d4e8e3 2222@table @code
2c5c0674
RP
2223@cindex input filename symbols
2224@cindex filename symbols
d4e5e3c3
DM
2225@kindex CREATE_OBJECT_SYMBOLS
2226@item CREATE_OBJECT_SYMBOLS
ec40bbb8
DM
2227Create a symbol for each input file
2228in the current section, set to the address of the first byte of
867a1b8a 2229data written from that input file. For instance, with @code{a.out}
b4d4e8e3
RP
2230files it is conventional to have a symbol for each input file. You can
2231accomplish this by defining the output @code{.text} section as follows:
c653b370
ILT
2232@smallexample
2233@group
b4d4e8e3 2234SECTIONS @{
d4e5e3c3
DM
2235 .text 0x2020 :
2236 @{
2237 CREATE_OBJECT_SYMBOLS
2238 *(.text)
2239 _etext = ALIGN(0x2000);
2240 @}
2241 @dots{}
2c5c0674 2242@}
c653b370
ILT
2243@end group
2244@end smallexample
b4d4e8e3 2245
867a1b8a 2246If @code{sample.ld} is a file containing this script, and @code{a.o},
b4d4e8e3
RP
2247@code{b.o}, @code{c.o}, and @code{d.o} are four input files with
2248contents like the following---
c653b370
ILT
2249@smallexample
2250@group
b4d4e8e3
RP
2251/* a.c */
2252
2c5c0674 2253afunction() @{ @}
b4d4e8e3
RP
2254int adata=1;
2255int abss;
c653b370
ILT
2256@end group
2257@end smallexample
f22eee08 2258
b4d4e8e3 2259@noindent
867a1b8a 2260@samp{ld -M -T sample.ld a.o b.o c.o d.o} would create a map like this,
b4d4e8e3 2261containing symbols matching the object file names:
c653b370 2262@smallexample
f22eee08
RP
226300000000 A __DYNAMIC
226400004020 B _abss
226500004000 D _adata
226600002020 T _afunction
226700004024 B _bbss
226800004008 D _bdata
226900002038 T _bfunction
227000004028 B _cbss
227100004010 D _cdata
227200002050 T _cfunction
22730000402c B _dbss
227400004018 D _ddata
227500002068 T _dfunction
227600004020 D _edata
227700004030 B _end
227800004000 T _etext
227900002020 t a.o
228000002038 t b.o
228100002050 t c.o
228200002068 t d.o
c653b370 2283@end smallexample
f22eee08 2284
2c5c0674 2285@kindex @var{symbol} = @var{expression} ;
2c5c0674 2286@kindex @var{symbol} @var{f}= @var{expression} ;
d4e5e3c3
DM
2287@item @var{symbol} = @var{expression} ;
2288@itemx @var{symbol} @var{f}= @var{expression} ;
2c5c0674
RP
2289@var{symbol} is any symbol name (@pxref{Symbols}). ``@var{f}=''
2290refers to any of the operators @code{&= += -= *= /=} which combine
2291arithmetic and assignment.
2292
2293@cindex assignment, in section defn
2294When you assign a value to a symbol within a particular section
2295definition, the value is relative to the beginning of the section
2296(@pxref{Assignment}). If you write
d4e5e3c3 2297
c653b370
ILT
2298@smallexample
2299@group
2c5c0674 2300SECTIONS @{
b4d4e8e3 2301 abs = 14 ;
2c5c0674 2302 @dots{}
cb70c872 2303 .data : @{ @dots{} rel = 14 ; @dots{} @}
b4d4e8e3 2304 abs2 = 14 + ADDR(.data);
2c5c0674
RP
2305 @dots{}
2306@}
c653b370
ILT
2307@end group
2308@end smallexample
d4e5e3c3 2309
2c5c0674 2310@c FIXME: Try above example!
b4d4e8e3 2311@noindent
ec40bbb8 2312@code{abs} and @code{rel} do not have the same value; @code{rel} has the
b4d4e8e3
RP
2313same value as @code{abs2}.
2314
2c5c0674 2315@kindex BYTE(@var{expression})
2c5c0674 2316@kindex SHORT(@var{expression})
2c5c0674 2317@kindex LONG(@var{expression})
c477527c 2318@kindex QUAD(@var{expression})
5a59e34d 2319@kindex SQUAD(@var{expression})
2c5c0674 2320@cindex direct output
d4e5e3c3
DM
2321@item BYTE(@var{expression})
2322@itemx SHORT(@var{expression})
2323@itemx LONG(@var{expression})
2324@itemx QUAD(@var{expression})
5a59e34d 2325@itemx SQUAD(@var{expression})
c477527c 2326By including one of these four statements in a section definition, you
5a59e34d
ILT
2327can explicitly place one, two, four, eight unsigned, or eight signed
2328bytes (respectively) at the current address of that section. When using
2329a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the same.
2330When both host and target are 32 bits, @code{QUAD} uses an unsigned 32
2331bit value, and @code{SQUAD} sign extends the value. Both will use the
2332correct endianness when writing out the value.
ec40bbb8
DM
2333
2334@ifclear SingleFormat
2335Multiple-byte quantities are represented in whatever byte order is
2336appropriate for the output file format (@pxref{BFD}).
2337@end ifclear
b4d4e8e3 2338
2c5c0674
RP
2339@kindex FILL(@var{expression})
2340@cindex holes, filling
2341@cindex unspecified memory
c653b370 2342@item FILL(@var{expression})
867a1b8a 2343Specify the ``fill pattern'' for the current section. Any otherwise
b4d4e8e3
RP
2344unspecified regions of memory within the section (for example, regions
2345you skip over by assigning a new value to the location counter @samp{.})
2346are filled with the two least significant bytes from the
2347@var{expression} argument. A @code{FILL} statement covers memory
2348locations @emph{after} the point it occurs in the section definition; by
2349including more than one @code{FILL} statement, you can have different
2350fill patterns in different parts of an output section.
2351@end table
2352
ec40bbb8 2353@node Section Options
b4d4e8e3 2354@subsection Optional Section Attributes
2c5c0674 2355@cindex section defn, full syntax
b4d4e8e3
RP
2356Here is the full syntax of a section definition, including all the
2357optional portions:
2358
d76ae847 2359@smallexample
c653b370 2360@group
2c5c0674
RP
2361SECTIONS @{
2362@dots{}
67c4333b 2363@var{secname} @var{start} BLOCK(@var{align}) (NOLOAD) : AT ( @var{ldadr} )
c653b370 2364 @{ @var{contents} @} >@var{region} :@var{phdr} =@var{fill}
2c5c0674 2365@dots{}
b4d4e8e3 2366@}
c653b370 2367@end group
d76ae847 2368@end smallexample
b4d4e8e3
RP
2369
2370@var{secname} and @var{contents} are required. @xref{Section
baaaf6f2 2371Definition}, and @ref{Section Placement}, for details on
67c4333b
RP
2372@var{contents}. The remaining elements---@var{start},
2373@code{BLOCK(@var{align)}}, @code{(NOLOAD)}, @code{AT ( @var{ldadr} )},
c653b370
ILT
2374@code{>@var{region}}, @code{:@var{phdr}}, and @code{=@var{fill}}---are
2375all optional.
f22eee08 2376
b4d4e8e3 2377@table @code
2c5c0674
RP
2378@cindex start address, section
2379@cindex section start
2380@cindex section address
d4e5e3c3 2381@item @var{start}
b4d4e8e3
RP
2382You can force the output section to be loaded at a specified address by
2383specifying @var{start} immediately following the section name.
2384@var{start} can be represented as any expression. The following
2385example generates section @var{output} at location
2386@code{0x40000000}:
d4e5e3c3 2387
c653b370
ILT
2388@smallexample
2389@group
b4d4e8e3 2390SECTIONS @{
d4e5e3c3
DM
2391 @dots{}
2392 output 0x40000000: @{
2393 @dots{}
2394 @}
2395 @dots{}
b4d4e8e3 2396@}
c653b370
ILT
2397@end group
2398@end smallexample
f22eee08 2399
2c5c0674
RP
2400@kindex BLOCK(@var{align})
2401@cindex section alignment
2402@cindex aligning sections
d4e5e3c3 2403@item BLOCK(@var{align})
ec40bbb8 2404You can include @code{BLOCK()} specification to advance
2c5c0674
RP
2405the location counter @code{.} prior to the beginning of the section, so
2406that the section will begin at the specified alignment. @var{align} is
2407an expression.
f22eee08 2408
d76ae847
RP
2409@kindex NOLOAD
2410@cindex prevent unnecessary loading
67c4333b
RP
2411@cindex loading, preventing
2412@item (NOLOAD)
5a59e34d
ILT
2413The @samp{(NOLOAD)} directive will mark a section to not be loaded at
2414run time. The linker will process the section normally, but will mark
2415it so that a program loader will not load it into memory. For example,
2416in the script sample below, the @code{ROM} section is addressed at
2417memory location @samp{0} and does not need to be loaded when the program
2418is run. The contents of the @code{ROM} section will appear in the
2419linker output file as usual.
67c4333b 2420
c653b370
ILT
2421@smallexample
2422@group
d76ae847 2423SECTIONS @{
d4e5e3c3
DM
2424 ROM 0 (NOLOAD) : @{ @dots{} @}
2425 @dots{}
d76ae847 2426@}
c653b370
ILT
2427@end group
2428@end smallexample
d76ae847 2429
67c4333b
RP
2430@kindex AT ( @var{ldadr} )
2431@cindex specify load address
2432@cindex load address, specifying
2433@item AT ( @var{ldadr} )
2434The expression @var{ldadr} that follows the @code{AT} keyword specifies
2435the load address of the section. The default (if you do not use the
2436@code{AT} keyword) is to make the load address the same as the
2437relocation address. This feature is designed to make it easy to build a
2438ROM image. For example, this @code{SECTIONS} definition creates two
2439output sections: one called @samp{.text}, which starts at @code{0x1000},
2440and one called @samp{.mdata}, which is loaded at the end of the
2441@samp{.text} section even though its relocation address is
2442@code{0x2000}. The symbol @code{_data} is defined with the value
2443@code{0x2000}:
2444
2445@smallexample
c653b370 2446@group
67c4333b 2447SECTIONS
139c8857
RP
2448 @{
2449 .text 0x1000 : @{ *(.text) _etext = . ; @}
2450 .mdata 0x2000 :
2451 AT ( ADDR(.text) + SIZEOF ( .text ) )
2452 @{ _data = . ; *(.data); _edata = . ; @}
2453 .bss 0x3000 :
2454 @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@}
67c4333b 2455@}
c653b370 2456@end group
67c4333b
RP
2457@end smallexample
2458
2459The run-time initialization code (for C programs, usually @code{crt0})
2460for use with a ROM generated this way has to include something like
2461the following, to copy the initialized data from the ROM image to its runtime
2462address:
2463
139c8857 2464@smallexample
c653b370 2465@group
67c4333b
RP
2466char *src = _etext;
2467char *dst = _data;
2468
139c8857 2469/* ROM has data at end of text; copy it. */
67c4333b 2470while (dst < _edata) @{
139c8857 2471 *dst++ = *src++;
67c4333b
RP
2472@}
2473
2474/* Zero bss */
2475for (dst = _bstart; dst< _bend; dst++)
139c8857 2476 *dst = 0;
c653b370 2477@end group
139c8857 2478@end smallexample
67c4333b 2479
f9d3d71a
ILT
2480@kindex >@var{region}
2481@cindex section, assigning to memory region
2482@cindex memory regions and sections
2483@item >@var{region}
2484Assign this section to a previously defined region of memory.
2485@xref{MEMORY}.
2486
c653b370
ILT
2487@kindex :@var{phdr}
2488@cindex section, assigning to program header
2489@cindex program headers and sections
2490@item :@var{phdr}
2491Assign this section to a segment described by a program header.
baaaf6f2 2492@xref{PHDRS}. If a section is assigned to one or more segments, then
c653b370
ILT
2493all subsequent allocated sections will be assigned to those segments as
2494well, unless they use an explicitly @code{:@var{phdr}} modifier. To
2495prevent a section from being assigned to a segment when it would
2496normally default to one, use @code{:NONE}.
2497
2c5c0674
RP
2498@kindex =@var{fill}
2499@cindex section fill pattern
2500@cindex fill pattern, entire section
d4e5e3c3
DM
2501@item =@var{fill}
2502Including @code{=@var{fill}} in a section definition specifies the
2503initial fill value for that section. You may use any expression to
2504specify @var{fill}. Any unallocated holes in the current output section
2505when written to the output file will be filled with the two least
2506significant bytes of the value, repeated as necessary. You can also
2507change the fill value with a @code{FILL} statement in the @var{contents}
2508of a section definition.
f22eee08 2509
f22eee08 2510@end table
b4d4e8e3 2511
b61364cc
ILT
2512@node Overlays
2513@subsection Overlays
2514@kindex OVERLAY
2515@cindex overlays
2516
2517The @code{OVERLAY} command provides an easy way to describe sections
2518which are to be loaded as part of a single memory image but are to be
2519run at the same memory address. At run time, some sort of overlay
2520manager will copy the overlaid sections in and out of the runtime memory
2521address as required, perhaps by simply manipulating addressing bits.
2522This approach can be useful, for example, when a certain region of
2523memory is faster than another.
2524
2525The @code{OVERLAY} command is used within a @code{SECTIONS} command. It
2526appears as follows:
2527@smallexample
2528@group
2529 OVERLAY @var{start} : [ NOCROSSREFS ] AT ( @var{ldaddr} )
2530 @{
2531 @var{secname1} @{ @var{contents} @} :@var{phdr} =@var{fill}
2532 @var{secname2} @{ @var{contents} @} :@var{phdr} =@var{fill}
2533 @dots{}
2534 @} >@var{region} :@var{phdr} =@var{fill}
2535@end group
2536@end smallexample
2537
2538Everything is optional except @code{OVERLAY} (a keyword), and each
2539section must have a name (@var{secname1} and @var{secname2} above). The
2540section definitions within the @code{OVERLAY} construct are identical to
2541those within the general @code{SECTIONS} contruct (@pxref{SECTIONS}),
2542except that no addresses and no memory regions may be defined for
2543sections within an @code{OVERLAY}.
2544
2545The sections are all defined with the same starting address. The load
2546addresses of the sections are arranged such that they are consecutive in
2547memory starting at the load address used for the @code{OVERLAY} as a
2548whole (as with normal section definitions, the load address is optional,
2549and defaults to the start address; the start address is also optional,
2550and defaults to @code{.}).
2551
2552If the @code{NOCROSSREFS} keyword is used, and there any references
2553among the sections, the linker will report an error. Since the sections
2554all run at the same address, it normally does not make sense for one
2555section to refer directly to another. @xref{Option Commands,
2556NOCROSSREFS}.
2557
2558For each section within the @code{OVERLAY}, the linker automatically
2559defines two symbols. The symbol @code{__load_start_@var{secname}} is
2560defined as the starting load address of the section. The symbol
2561@code{__load_stop_@var{secname}} is defined as the final load address of
2562the section. Any characters within @var{secname} which are not legal
2563within C identifiers are removed. C (or assembler) code may use these
2564symbols to move the overlaid sections around as necessary.
2565
2566At the end of the overlay, the value of @code{.} is set to the start
2567address of the overlay plus the size of the largest section.
2568
2569Here is an example. Remember that this would appear inside a
2570@code{SECTIONS} construct.
2571
2572@smallexample
2573@group
2574 OVERLAY 0x1000 : AT (0x4000)
2575 @{
2576 .text0 @{ o1/*.o(.text) @}
2577 .text1 @{ o2/*.o(.text) @}
2578 @}
2579@end group
2580@end smallexample
2581
2582This will define both @code{.text0} and @code{.text1} to start at
2583address 0x1000. @code{.text0} will be loaded at address 0x4000, and
2584@code{.text1} will be loaded immediately after @code{.text0}. The
2585following symbols will be defined: @code{__load_start_text0},
2586@code{__load_stop_text0}, @code{__load_start_text1},
2587@code{__load_stop_text1}.
2588
2589C code to copy overlay @code{.text1} into the overlay area might look
2590like the following.
2591
2592@smallexample
2593@group
2594 extern char __load_start_text1, __load_stop_text1;
2595 memcpy ((char *) 0x1000, &__load_start_text1,
2596 &__load_stop_text1 - &__load_start_text1);
2597@end group
2598@end smallexample
2599
2600Note that the @code{OVERLAY} command is just syntactic sugar, since
2601everything it does can be done using the more basic commands. The above
2602example could have been written identically as follows.
2603
2604@smallexample
2605@group
2606 .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
2607 __load_start_text0 = LOADADDR (.text0);
2608 __load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0);
2609 .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
2610 __load_start_text1 = LOADADDR (.text1);
2611 __load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1);
2612 . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
2613@end group
2614@end smallexample
2615
c653b370
ILT
2616@node PHDRS
2617@section ELF Program Headers
2618@kindex PHDRS
b61364cc
ILT
2619@cindex program headers
2620@cindex ELF program headers
c653b370
ILT
2621
2622The ELF object file format uses @dfn{program headers}, which are read by
2623the system loader and describe how the program should be loaded into
2624memory. These program headers must be set correctly in order to run the
2625program on a native ELF system. The linker will create reasonable
2626program headers by default. However, in some cases, it is desirable to
2627specify the program headers more precisely; the @code{PHDRS} command may
2628be used for this purpose. When the @code{PHDRS} command is used, the
2629linker will not generate any program headers itself.
2630
2631The @code{PHDRS} command is only meaningful when generating an ELF
2632output file. It is ignored in other cases. This manual does not
2633describe the details of how the system loader interprets program
2634headers; for more information, see the ELF ABI. The program headers of
2635an ELF file may be displayed using the @samp{-p} option of the
2636@code{objdump} command.
2637
2638This is the syntax of the @code{PHDRS} command. The words @code{PHDRS},
2639@code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
2640
2641@smallexample
2642@group
2643PHDRS
2644@{
2645 @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
2646 [ FLAGS ( @var{flags} ) ] ;
2647@}
2648@end group
2649@end smallexample
2650
2651The @var{name} is used only for reference in the @code{SECTIONS} command
2652of the linker script. It does not get put into the output file.
2653
2654Certain program header types describe segments of memory which are
2655loaded from the file by the system loader. In the linker script, the
2656contents of these segments are specified by directing allocated output
2657sections to be placed in the segment. To do this, the command
2658describing the output section in the @code{SECTIONS} command should use
2659@samp{:@var{name}}, where @var{name} is the name of the program header
2660as it appears in the @code{PHDRS} command. @xref{Section Options}.
2661
2662It is normal for certain sections to appear in more than one segment.
2663This merely implies that one segment of memory contains another. This
2664is specified by repeating @samp{:@var{name}}, using it once for each
2665program header in which the section is to appear.
2666
2667If a section is placed in one or more segments using @samp{:@var{name}},
2668then all subsequent allocated sections which do not specify
2669@samp{:@var{name}} are placed in the same segments. This is for
2670convenience, since generally a whole set of contiguous sections will be
2671placed in a single segment. To prevent a section from being assigned to
2672a segment when it would normally default to one, use @code{:NONE}.
2673
2674The @code{FILEHDR} and @code{PHDRS} keywords which may appear after the
2675program header type also indicate contents of the segment of memory.
2676The @code{FILEHDR} keyword means that the segment should include the ELF
2677file header. The @code{PHDRS} keyword means that the segment should
2678include the ELF program headers themselves.
2679
2680The @var{type} may be one of the following. The numbers indicate the
2681value of the keyword.
2682
2683@table @asis
2684@item @code{PT_NULL} (0)
2685Indicates an unused program header.
2686
2687@item @code{PT_LOAD} (1)
2688Indicates that this program header describes a segment to be loaded from
2689the file.
2690
2691@item @code{PT_DYNAMIC} (2)
2692Indicates a segment where dynamic linking information can be found.
2693
2694@item @code{PT_INTERP} (3)
2695Indicates a segment where the name of the program interpreter may be
2696found.
2697
2698@item @code{PT_NOTE} (4)
2699Indicates a segment holding note information.
2700
2701@item @code{PT_SHLIB} (5)
2702A reserved program header type, defined but not specified by the ELF
2703ABI.
2704
2705@item @code{PT_PHDR} (6)
2706Indicates a segment where the program headers may be found.
2707
2708@item @var{expression}
2709An expression giving the numeric type of the program header. This may
2710be used for types not defined above.
2711@end table
2712
2713It is possible to specify that a segment should be loaded at a
2714particular address in memory. This is done using an @code{AT}
2715expression. This is identical to the @code{AT} command used in the
2716@code{SECTIONS} command (@pxref{Section Options}). Using the @code{AT}
2717command for a program header overrides any information in the
2718@code{SECTIONS} command.
2719
2720Normally the segment flags are set based on the sections. The
2721@code{FLAGS} keyword may be used to explicitly specify the segment
2722flags. The value of @var{flags} must be an integer. It is used to
2723set the @code{p_flags} field of the program header.
2724
2725Here is an example of the use of @code{PHDRS}. This shows a typical set
2726of program headers used on a native ELF system.
2727
2728@example
2729@group
2730PHDRS
2731@{
2732 headers PT_PHDR PHDRS ;
2733 interp PT_INTERP ;
2734 text PT_LOAD FILEHDR PHDRS ;
2735 data PT_LOAD ;
2736 dynamic PT_DYNAMIC ;
2737@}
2738
2739SECTIONS
2740@{
2741 . = SIZEOF_HEADERS;
2742 .interp : @{ *(.interp) @} :text :interp
2743 .text : @{ *(.text) @} :text
2744 .rodata : @{ *(.rodata) @} /* defaults to :text */
2745 @dots{}
2746 . = . + 0x1000; /* move to a new page in memory */
2747 .data : @{ *(.data) @} :data
2748 .dynamic : @{ *(.dynamic) @} :data :dynamic
2749 @dots{}
2750@}
2751@end group
2752@end example
2753
ec40bbb8 2754@node Entry Point
b4d4e8e3 2755@section The Entry Point
2c5c0674
RP
2756@kindex ENTRY(@var{symbol})
2757@cindex start of execution
2758@cindex first instruction
b4d4e8e3
RP
2759The linker command language includes a command specifically for
2760defining the first executable instruction in an output file (its
2761@dfn{entry point}). Its argument is a symbol name:
c653b370 2762@smallexample
b4d4e8e3 2763ENTRY(@var{symbol})
c653b370 2764@end smallexample
b4d4e8e3
RP
2765
2766Like symbol assignments, the @code{ENTRY} command may be placed either
2767as an independent command in the command file, or among the section
2768definitions within the @code{SECTIONS} command---whatever makes the most
2769sense for your layout.
2770
2c5c0674 2771@cindex entry point, defaults
b4d4e8e3
RP
2772@code{ENTRY} is only one of several ways of choosing the entry point.
2773You may indicate it in any of the following ways (shown in descending
2774order of priority: methods higher in the list override methods lower down).
f22eee08
RP
2775@itemize @bullet
2776@item
ec40bbb8 2777the @samp{-e} @var{entry} command-line option;
f22eee08 2778@item
8de26d62 2779the @code{ENTRY(@var{symbol})} command in a linker control script;
f22eee08 2780@item
b4d4e8e3 2781the value of the symbol @code{start}, if present;
f22eee08 2782@item
b4d4e8e3 2783the address of the first byte of the @code{.text} section, if present;
f22eee08 2784@item
b4d4e8e3 2785The address @code{0}.
f22eee08 2786@end itemize
b4d4e8e3 2787
2c5c0674
RP
2788For example, you can use these rules to generate an entry point with an
2789assignment statement: if no symbol @code{start} is defined within your
2790input files, you can simply define it, assigning it an appropriate
2791value---
d4e5e3c3 2792
c653b370 2793@smallexample
b4d4e8e3 2794start = 0x2020;
c653b370 2795@end smallexample
b4d4e8e3
RP
2796
2797@noindent
2798The example shows an absolute address, but you can use any expression.
2799For example, if your input object files use some other symbol-name
2800convention for the entry point, you can just assign the value of
2801whatever symbol contains the start address to @code{start}:
d4e5e3c3 2802
c653b370 2803@smallexample
cb70c872 2804start = other_symbol ;
c653b370 2805@end smallexample
f22eee08 2806
5a59e34d
ILT
2807@node Version Script
2808@section Version Script
2809@kindex VERSION @{script text@}
2810@cindex symbol versions
2811@cindex version script
2812@cindex versions of symbols
2813The linker command script includes a command specifically for
2814specifying a version script, and is only meaningful for ELF platforms
2815that support shared libraries. A version script can be
2816build directly into the linker script that you are using, or you
2817can supply the version script as just another input file to the linker
2818at the time that you link. The command script syntax is:
2819@smallexample
2820VERSION @{ version script contents @}
2821@end smallexample
2822The version script can also be specified to the linker by means of the
2823@samp{--version-script} linker command line option.
2824Version scripts are only meaningful when creating shared libraries.
2825
2826The format of the version script itself is identical to that used by
2827Sun's linker in Solaris 2.5. Versioning is done by defining a tree of
2828version nodes with the names and interdependencies specified in the
2829version script. The version script can specify which symbols are bound
2830to which version nodes, and it can reduce a specified set of symbols to
2831local scope so that they are not globally visible outside of the shared
2832library.
2833
2834The easiest way to demonstrate the version script language is with a few
2835examples.
2836
2837@smallexample
2838VERS_1.1 @{
2839 global:
2840 foo1;
2841 local:
2842 old*;
2843 original*;
2844 new*;
2845@};
2846
2847VERS_1.2 @{
2848 foo2;
2849@} VERS_1.1;
2850
2851VERS_2.0 @{
2852 bar1; bar2;
2853@} VERS_1.2;
2854@end smallexample
2855
2856In this example, three version nodes are defined. @samp{VERS_1.1} is the
2857first version node defined, and has no other dependencies. The symbol
2858@samp{foo1} is bound to this version node, and a number of symbols
2859that have appeared within various object files are reduced in scope to
2860local so that they are not visible outside of the shared library.
2861
2862Next, the node @samp{VERS_1.2} is defined. It depends upon
2863@samp{VERS_1.1}. The symbol @samp{foo2} is bound to this version node.
2864
2865Finally, the node @samp{VERS_2.0} is defined. It depends upon
2866@samp{VERS_1.2}. The symbols @samp{bar1} and @samp{bar2} are bound to
2867this version node.
2868
2869Symbols defined in the library which aren't specifically bound to a
2870version node are effectively bound to an unspecified base version of the
2871library. It is possible to bind all otherwise unspecified symbols to a
2872given version node using @samp{global: *} somewhere in the version
2873script.
2874
2875Lexically the names of the version nodes have no specific meaning other
2876than what they might suggest to the person reading them. The @samp{2.0}
2877version could just as well have appeared in between @samp{1.1} and
2878@samp{1.2}. However, this would be a confusing way to write a version
2879script.
2880
2881When you link an application against a shared library that has versioned
2882symbols, the application itself knows which version of each symbol it requires,
2883and it also knows which version nodes it needs from each shared library it is
2884linked against. Thus at runtime, the dynamic loader can make a quick check to
2885make sure that the libraries you have linked against do in fact supply all
2886of the version nodes that the application will need to resolve all of the
2887dynamic symbols. In this way it is possible for the dynamic linker to know
2888with certainty that all external symbols that it needs will be resolvable
2889without having to search for each symbol reference.
2890
2891The symbol versioning is in effect a much more sophisticated way of
2892doing minor version checking that SunOS does. The fundamental problem
2893that is being addressed here is that typically references to external
2894functions are bound on an as-needed basis, and are not all bound when
2895the application starts up. If a shared library is out of date, a
2896required interface may be missing; when the application tries to use
2897that interface, it may suddenly and unexpectedly fail. With symbol
2898versioning, the user will get a warning when they start their program if
2899the libraries being used with the application are too old.
2900
2901There are several GNU extensions to Sun's versioning approach. The
2902first of these is the ability to bind a symbol to a version node in the
2903source file where the symbol is defined instead of in the versioning
2904script. This was done mainly to reduce the burden on the library
2905maintainer. This can be done by putting something like:
2906
2907@smallexample
2908__asm__(".symver original_foo,foo@@VERS_1.1");
2909@end smallexample
2910
2911in the C source file. This renamed the function @samp{original_foo} to
2912be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
2913The @samp{local:} directive can be used to prevent the symbol
2914@samp{original_foo} from being exported.
2915
2916The second GNU extension is to allow multiple versions of the same function
2917to appear in a given shared library. In this way an incompatible change to
2918an interface can take place without increasing the major version number of
2919the shared library, while still allowing applications linked against the old
2920interface to continue to function.
2921
2922This can only be accomplished by using multiple @samp{.symver}
2923directives in the assembler. An example of this would be:
2924
2925@smallexample
2926__asm__(".symver original_foo,foo@@");
2927__asm__(".symver old_foo,foo@@VERS_1.1");
2928__asm__(".symver old_foo1,foo@@VERS_1.2");
2929__asm__(".symver new_foo,foo@@@@VERS_2.0");
2930@end smallexample
2931
2932In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
2933unspecified base version of the symbol. The source file that contains this
2934example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
2935@samp{old_foo1}, and @samp{new_foo}.
2936
2937When you have multiple definitions of a given symbol, there needs to be
2938some way to specify a default version to which external references to
2939this symbol will be bound. This can be accomplished with the
2940@samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. Only one version of
2941a symbol can be declared 'default' in this manner - otherwise you would
2942effectively have multiple definitions of the same symbol.
2943
2944If you wish to bind a reference to a specific version of the symbol
2945within the shared library, you can use the aliases of convenience
2946(i.e. @samp{old_foo}), or you can use the @samp{.symver} directive to
2947specifically bind to an external version of the function in question.
2948
867a1b8a
DM
2949@node Option Commands
2950@section Option Commands
b4d4e8e3
RP
2951The command language includes a number of other commands that you can
2952use for specialized purposes. They are similar in purpose to
2953command-line options.
2954
2955@table @code
1fb57a5d
RP
2956@kindex CONSTRUCTORS
2957@cindex C++ constructors, arranging in link
2958@cindex constructors, arranging in link
2959@item CONSTRUCTORS
a1d393cf
ILT
2960When linking using the @code{a.out} object file format, the linker uses
2961an unusual set construct to support C++ global constructors and
2962destructors. When linking object file formats which do not support
2963arbitrary sections, such as @code{ECOFF} and @code{XCOFF}, the linker
2964will automatically recognize C++ global constructors and destructors by
2965name. For these object file formats, the @code{CONSTRUCTORS} command
2966tells the linker where this information should be placed. The
2967@code{CONSTRUCTORS} command is ignored for other object file formats.
2968
2969The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
2970constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end. The
2971first word in the list is the number of entries, followed by the address
2972of each constructor or destructor, followed by a zero word. The
2973compiler must arrange to actually run the code. For these object file
2974formats @sc{gnu} C++ calls constructors from a subroutine @code{__main};
2975a call to @code{__main} is automatically inserted into the startup code
2976for @code{main}. @sc{gnu} C++ runs destructors either by using
2977@code{atexit}, or directly from the function @code{exit}.
2978
2979For object file formats such as @code{COFF} or @code{ELF} which support
2980multiple sections, @sc{gnu} C++ will normally arrange to put the
2981addresses of global constructors and destructors into the @code{.ctors}
2982and @code{.dtors} sections. Placing the following sequence into your
2983linker script will build the sort of table which the @sc{gnu} C++
2984runtime code expects to see.
2985
2986@smallexample
2987 __CTOR_LIST__ = .;
2988 LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
2989 *(.ctors)
2990 LONG(0)
2991 __CTOR_END__ = .;
2992 __DTOR_LIST__ = .;
2993 LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
2994 *(.dtors)
2995 LONG(0)
2996 __DTOR_END__ = .;
2997@end smallexample
2998
2999Normally the compiler and linker will handle these issues automatically,
3000and you will not need to concern yourself with them. However, you may
3001need to consider this if you are using C++ and writing your own linker
3002scripts.
1fb57a5d 3003
d4e5e3c3 3004@need 1000
2c5c0674 3005@kindex FLOAT
2c5c0674 3006@kindex NOFLOAT
1fb57a5d
RP
3007@item FLOAT
3008@itemx NOFLOAT
2c5c0674 3009These keywords were used in some older linkers to request a particular
246504a5 3010math subroutine library. @code{ld} doesn't use the keywords, assuming
2c5c0674
RP
3011instead that any necessary subroutines are in libraries specified using
3012the general mechanisms for linking to archives; but to permit the use of
3013scripts that were written for the older linkers, the keywords
3014@code{FLOAT} and @code{NOFLOAT} are accepted and ignored.
3015
2c5c0674
RP
3016@kindex FORCE_COMMON_ALLOCATION
3017@cindex common allocation
1fb57a5d 3018@item FORCE_COMMON_ALLOCATION
ec40bbb8 3019This command has the same effect as the @samp{-d} command-line option:
2c5c0674 3020to make @code{ld} assign space to common symbols even if a relocatable
ec40bbb8 3021output file is specified (@samp{-r}).
b4d4e8e3 3022
5a59e34d
ILT
3023@kindex INCLUDE @var{filename}
3024@cindex including a linker script
3025@item INCLUDE @var{filename}
3026Include the linker script @var{filename} at this point. The file will
3027be searched for in the current directory, and in any directory specified
3028with the @code{-L} option. You can nest calls to @code{INCLUDE} up to
302910 levels deep.
3030
2c5c0674 3031@kindex INPUT ( @var{files} )
2c5c0674 3032@cindex binary input files
1fb57a5d
RP
3033@item INPUT ( @var{file}, @var{file}, @dots{} )
3034@itemx INPUT ( @var{file} @var{file} @dots{} )
2c5c0674 3035Use this command to include binary input files in the link, without
7f9ae73e
RP
3036including them in a particular section definition.
3037Specify the full name for each @var{file}, including @samp{.a} if
3038required.
3039
3040@code{ld} searches for each @var{file} through the archive-library
3041search path, just as for files you specify on the command line.
3042See the description of @samp{-L} in @ref{Options,,Command Line
3043Options}.
b4d4e8e3 3044
01bc8f35
ILT
3045If you use @samp{-l@var{file}}, @code{ld} will transform the name to
3046@code{lib@var{file}.a} as with the command line argument @samp{-l}.
3047
0b3499f6
ILT
3048@kindex GROUP ( @var{files} )
3049@cindex grouping input files
3050@item GROUP ( @var{file}, @var{file}, @dots{} )
3051@itemx GROUP ( @var{file} @var{file} @dots{} )
3052This command is like @code{INPUT}, except that the named files should
3053all be archives, and they are searched repeatedly until no new undefined
3054references are created. See the description of @samp{-(} in
3055@ref{Options,,Command Line Options}.
3056
2c5c0674 3057@ignore
2c5c0674 3058@kindex MAP ( @var{name} )
c653b370 3059@item MAP ( @var{name} )
2c5c0674
RP
3060@c MAP(...) appears to look for an F in the arg, ignoring all other
3061@c chars; if it finds one, it sets "map_option_f" to true. But nothing
3062@c checks map_option_f. Apparently a stub for the future...
3063@end ignore
b4d4e8e3 3064
2c5c0674
RP
3065@kindex OUTPUT ( @var{filename} )
3066@cindex naming the output file
c653b370 3067@item OUTPUT ( @var{filename} )
d76ae847
RP
3068Use this command to name the link output file @var{filename}. The
3069effect of @code{OUTPUT(@var{filename})} is identical to the effect of
c477527c
ILT
3070@w{@samp{-o @var{filename}}}, which overrides it. You can use this
3071command to supply a default output-file name other than @code{a.out}.
2c5c0674 3072
ec40bbb8 3073@ifclear SingleFormat
2c5c0674
RP
3074@kindex OUTPUT_ARCH ( @var{bfdname} )
3075@cindex machine architecture, output
c653b370 3076@item OUTPUT_ARCH ( @var{bfdname} )
2c5c0674
RP
3077Specify a particular output machine architecture, with one of the names
3078used by the BFD back-end routines (@pxref{BFD}). This command is often
3079unnecessary; the architecture is most often set implicitly by either the
3080system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT}
ec40bbb8 3081command.
2c5c0674 3082
2c5c0674
RP
3083@kindex OUTPUT_FORMAT ( @var{bfdname} )
3084@cindex format, output file
c653b370 3085@item OUTPUT_FORMAT ( @var{bfdname} )
1fb57a5d
RP
3086When @code{ld} is configured to support multiple object code formats,
3087you can use this command to specify a particular output format.
3088@var{bfdname} is one of the names used by the BFD back-end routines
3089(@pxref{BFD}). The effect is identical to the effect of the
9fde46a4
ILT
3090@samp{--oformat} command-line option. This selection affects only the
3091output file; the related command @code{TARGET} affects primarily input
3092files.
ec40bbb8 3093@end ifclear
2c5c0674 3094
2c5c0674
RP
3095@kindex SEARCH_DIR ( @var{path} )
3096@cindex path for libraries
3097@cindex search path, libraries
c653b370 3098@item SEARCH_DIR ( @var{path} )
246504a5 3099Add @var{path} to the list of paths where @code{ld} looks for
2c5c0674 3100archive libraries. @code{SEARCH_DIR(@var{path})} has the same
ec40bbb8 3101effect as @samp{-L@var{path}} on the command line.
2c5c0674 3102
2c5c0674
RP
3103@kindex STARTUP ( @var{filename} )
3104@cindex first input file
c653b370 3105@item STARTUP ( @var{filename} )
2c5c0674
RP
3106Ensure that @var{filename} is the first input file used in the link
3107process.
b4d4e8e3 3108
ec40bbb8 3109@ifclear SingleFormat
2c5c0674
RP
3110@cindex input file format
3111@kindex TARGET ( @var{format} )
c653b370 3112@item TARGET ( @var{format} )
1fb57a5d
RP
3113When @code{ld} is configured to support multiple object code formats,
3114you can use this command to change the input-file object code format
9fde46a4 3115(like the command-line option @samp{-b} or its synonym @samp{--format}).
1fb57a5d
RP
3116The argument @var{format} is one of the strings used by BFD to name
3117binary formats. If @code{TARGET} is specified but @code{OUTPUT_FORMAT}
3118is not, the last @code{TARGET} argument is also used as the default
3119format for the @code{ld} output file. @xref{BFD}.
2c5c0674
RP
3120
3121@kindex GNUTARGET
246504a5 3122If you don't use the @code{TARGET} command, @code{ld} uses the value of
2c5c0674 3123the environment variable @code{GNUTARGET}, if available, to select the
246504a5 3124output file format. If that variable is also absent, @code{ld} uses
2c5c0674 3125the default format configured for your machine in the BFD libraries.
ec40bbb8 3126@end ifclear
582dd77f
ILT
3127
3128@cindex cross references
3129@kindex NOCROSSREFS ( @var{sections} )
3130@item NOCROSSREFS ( @var{section} @var{section} @dots{} )
3131This command may be used to tell @code{ld} to issue an error about any
3132references among certain sections.
3133
3134In certain types of programs, particularly on embedded systems, when one
3135section is loaded into memory, another section will not be. Any direct
3136references between the two sections would be errors. For example, it
3137would be an error if code in one section called a function defined in
3138the other section.
3139
3140The @code{NOCROSSREFS} command takes a list of section names. If
3141@code{ld} detects any cross references between the sections, it reports
3142an error and returns a non-zero exit status. The @code{NOCROSSREFS}
3143command uses output section names, defined in the @code{SECTIONS}
3144command. It does not use the names of input sections.
b4d4e8e3
RP
3145@end table
3146
ec40bbb8
DM
3147@ifset GENERIC
3148@node Machine Dependent
1c48127e
RP
3149@chapter Machine Dependent Features
3150
3151@cindex machine dependencies
246504a5
RP
3152@code{ld} has additional features on some platforms; the following
3153sections describe them. Machines where @code{ld} has no additional
1c48127e
RP
3154functionality are not listed.
3155
3156@menu
246504a5
RP
3157* H8/300:: @code{ld} and the H8/300
3158* i960:: @code{ld} and the Intel 960 family
1c48127e 3159@end menu
ec40bbb8
DM
3160@end ifset
3161
7f9ae73e 3162@c FIXME! This could use @raisesections/@lowersections, but there seems to be a conflict
ec40bbb8
DM
3163@c between those and node-defaulting.
3164@ifset H8300
3165@ifclear GENERIC
7f9ae73e 3166@raisesections
ec40bbb8
DM
3167@end ifclear
3168@node H8/300
246504a5 3169@section @code{ld} and the H8/300
1c48127e
RP
3170
3171@cindex H8/300 support
246504a5 3172For the H8/300, @code{ld} can perform these global optimizations when
9fde46a4 3173you specify the @samp{--relax} command-line option.
1c48127e
RP
3174
3175@table @emph
d76ae847 3176@cindex relaxing on H8/300
c653b370 3177@item relaxing address modes
246504a5 3178@code{ld} finds all @code{jsr} and @code{jmp} instructions whose
1c48127e
RP
3179targets are within eight bits, and turns them into eight-bit
3180program-counter relative @code{bsr} and @code{bra} instructions,
3181respectively.
3182
d76ae847 3183@cindex synthesizing on H8/300
c653b370 3184@item synthesizing instructions
1c48127e 3185@c FIXME: specifically mov.b, or any mov instructions really?
246504a5 3186@code{ld} finds all @code{mov.b} instructions which use the
1c48127e
RP
3187sixteen-bit absolute address form, but refer to the top
3188page of memory, and changes them to use the eight-bit address form.
3189(That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
3190@samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
3191top page of memory).
3192@end table
ec40bbb8 3193@ifclear GENERIC
7f9ae73e 3194@lowersections
ec40bbb8
DM
3195@end ifclear
3196@end ifset
3197
f9d3d71a
ILT
3198@ifclear GENERIC
3199@ifset Hitachi
3200@c This stuff is pointless to say unless you're especially concerned
3201@c with Hitachi chips; don't enable it for generic case, please.
3202@node Hitachi
3203@chapter @code{ld} and other Hitachi chips
3204
3205@code{ld} also supports the H8/300H, the H8/500, and the Hitachi SH. No
3206special features, commands, or command-line options are required for
3207these chips.
3208@end ifset
3209@end ifclear
3210
ec40bbb8
DM
3211@ifset I960
3212@ifclear GENERIC
7f9ae73e 3213@raisesections
ec40bbb8
DM
3214@end ifclear
3215@node i960
246504a5 3216@section @code{ld} and the Intel 960 family
1c48127e
RP
3217
3218@cindex i960 support
d76ae847 3219
1c48127e
RP
3220You can use the @samp{-A@var{architecture}} command line option to
3221specify one of the two-letter names identifying members of the 960
3222family; the option specifies the desired output target, and warns of any
3223incompatible instructions in the input files. It also modifies the
3224linker's search strategy for archive libraries, to support the use of
3225libraries specific to each particular architecture, by including in the
3226search loop names suffixed with the string identifying the architecture.
3227
246504a5 3228For example, if your @code{ld} command line included @w{@samp{-ACA}} as
1c48127e 3229well as @w{@samp{-ltry}}, the linker would look (in its built-in search
ec40bbb8 3230paths, and in any paths you specify with @samp{-L}) for a library with
1c48127e 3231the names
ec40bbb8 3232
c653b370
ILT
3233@smallexample
3234@group
1c48127e
RP
3235try
3236libtry.a
3237tryca
3238libtryca.a
c653b370
ILT
3239@end group
3240@end smallexample
ec40bbb8 3241
1c48127e
RP
3242@noindent
3243The first two possibilities would be considered in any event; the last
3244two are due to the use of @w{@samp{-ACA}}.
3245
ec40bbb8 3246You can meaningfully use @samp{-A} more than once on a command line, since
1c48127e 3247the 960 architecture family allows combination of target architectures; each
ec40bbb8 3248use will add another pair of name variants to search for when @w{@samp{-l}}
1c48127e 3249specifies a library.
1fb57a5d 3250
9fde46a4 3251@cindex @code{--relax} on i960
1fb57a5d 3252@cindex relaxing on i960
9fde46a4
ILT
3253@code{ld} supports the @samp{--relax} option for the i960 family. If
3254you specify @samp{--relax}, @code{ld} finds all @code{balx} and
3255@code{calx} instructions whose targets are within 24 bits, and turns
3256them into 24-bit program-counter relative @code{bal} and @code{cal}
1fb57a5d
RP
3257instructions, respectively. @code{ld} also turns @code{cal}
3258instructions into @code{bal} instructions when it determines that the
3259target subroutine is a leaf routine (that is, the target subroutine does
3260not itself call any subroutines).
3261
ec40bbb8 3262@ifclear GENERIC
7f9ae73e 3263@lowersections
ec40bbb8
DM
3264@end ifclear
3265@end ifset
1c48127e 3266
ec40bbb8
DM
3267@ifclear SingleFormat
3268@node BFD
f22eee08
RP
3269@chapter BFD
3270
2c5c0674
RP
3271@cindex back end
3272@cindex object file management
d4e5e3c3
DM
3273@cindex object formats available
3274@kindex objdump -i
2c5c0674
RP
3275The linker accesses object and archive files using the BFD libraries.
3276These libraries allow the linker to use the same routines to operate on
3277object files whatever the object file format. A different object file
3278format can be supported simply by creating a new BFD back end and adding
d4e5e3c3
DM
3279it to the library. To conserve runtime memory, however, the linker and
3280associated tools are usually configured to support only a subset of the
3281object file formats available. You can use @code{objdump -i}
1c48127e 3282(@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
d4e5e3c3 3283list all the formats available for your configuration.
f22eee08 3284
2c5c0674
RP
3285@cindex BFD requirements
3286@cindex requirements for BFD
3287As with most implementations, BFD is a compromise between
f22eee08 3288several conflicting requirements. The major factor influencing
2c5c0674
RP
3289BFD design was efficiency: any time used converting between
3290formats is time which would not have been spent had BFD not
f22eee08 3291been involved. This is partly offset by abstraction payback; since
2c5c0674 3292BFD simplifies applications and back ends, more time and care
f22eee08
RP
3293may be spent optimizing algorithms for a greater speed.
3294
2c5c0674
RP
3295One minor artifact of the BFD solution which you should bear in
3296mind is the potential for information loss. There are two places where
ec40bbb8 3297useful information can be lost using the BFD mechanism: during
2c5c0674
RP
3298conversion and during output. @xref{BFD information loss}.
3299
3300@menu
2d59b2c3 3301* BFD outline:: How it works: an outline of BFD
2c5c0674 3302@end menu
f22eee08 3303
ec40bbb8 3304@node BFD outline
b4d4e8e3 3305@section How it works: an outline of BFD
2c5c0674 3306@cindex opening object files
3e27cc11 3307@include bfdsumm.texi
ec40bbb8 3308@end ifclear
f22eee08 3309
9fde46a4
ILT
3310@node Reporting Bugs
3311@chapter Reporting Bugs
3312@cindex bugs in @code{ld}
3313@cindex reporting bugs in @code{ld}
3314
3315Your bug reports play an essential role in making @code{ld} reliable.
3316
3317Reporting a bug may help you by bringing a solution to your problem, or
3318it may not. But in any case the principal function of a bug report is
3319to help the entire community by making the next version of @code{ld}
3320work better. Bug reports are your contribution to the maintenance of
3321@code{ld}.
3322
3323In order for a bug report to serve its purpose, you must include the
3324information that enables us to fix the bug.
3325
3326@menu
3327* Bug Criteria:: Have you found a bug?
3328* Bug Reporting:: How to report bugs
3329@end menu
3330
3331@node Bug Criteria
3332@section Have you found a bug?
3333@cindex bug criteria
3334
3335If you are not sure whether you have found a bug, here are some guidelines:
3336
3337@itemize @bullet
3338@cindex fatal signal
3339@cindex linker crash
3340@cindex crash of linker
3341@item
3342If the linker gets a fatal signal, for any input whatever, that is a
3343@code{ld} bug. Reliable linkers never crash.
3344
3345@cindex error on valid input
3346@item
3347If @code{ld} produces an error message for valid input, that is a bug.
3348
3349@cindex invalid input
3350@item
3351If @code{ld} does not produce an error message for invalid input, that
3352may be a bug. In the general case, the linker can not verify that
3353object files are correct.
3354
3355@item
3356If you are an experienced user of linkers, your suggestions for
3357improvement of @code{ld} are welcome in any case.
3358@end itemize
3359
3360@node Bug Reporting
3361@section How to report bugs
3362@cindex bug reports
3363@cindex @code{ld} bugs, reporting
3364
3365A number of companies and individuals offer support for @sc{gnu}
3366products. If you obtained @code{ld} from a support organization, we
3367recommend you contact that organization first.
3368
3369You can find contact information for many support companies and
3370individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
3371distribution.
3372
3373In any event, we also recommend that you send bug reports for @code{ld}
3374to @samp{bug-gnu-utils@@prep.ai.mit.edu}.
3375
3376The fundamental principle of reporting bugs usefully is this:
3377@strong{report all the facts}. If you are not sure whether to state a
3378fact or leave it out, state it!
3379
3380Often people omit facts because they think they know what causes the
3381problem and assume that some details do not matter. Thus, you might
3382assume that the name of a symbol you use in an example does not matter.
3383Well, probably it does not, but one cannot be sure. Perhaps the bug is
3384a stray memory reference which happens to fetch from the location where
3385that name is stored in memory; perhaps, if the name were different, the
3386contents of that location would fool the linker into doing the right
3387thing despite the bug. Play it safe and give a specific, complete
3388example. That is the easiest thing for you to do, and the most helpful.
3389
3390Keep in mind that the purpose of a bug report is to enable us to fix the bug if
3391it is new to us. Therefore, always write your bug reports on the assumption
3392that the bug has not been reported previously.
3393
3394Sometimes people give a few sketchy facts and ask, ``Does this ring a
3395bell?'' Those bug reports are useless, and we urge everyone to
3396@emph{refuse to respond to them} except to chide the sender to report
3397bugs properly.
3398
3399To enable us to fix the bug, you should include all these things:
3400
3401@itemize @bullet
3402@item
3403The version of @code{ld}. @code{ld} announces it if you start it with
3404the @samp{--version} argument.
3405
3406Without this, we will not know whether there is any point in looking for
3407the bug in the current version of @code{ld}.
3408
3409@item
3410Any patches you may have applied to the @code{ld} source, including any
3411patches made to the @code{BFD} library.
3412
3413@item
3414The type of machine you are using, and the operating system name and
3415version number.
3416
3417@item
3418What compiler (and its version) was used to compile @code{ld}---e.g.
3419``@code{gcc-2.7}''.
3420
3421@item
3422The command arguments you gave the linker to link your example and
3423observe the bug. To guarantee you will not omit something important,
3424list them all. A copy of the Makefile (or the output from make) is
3425sufficient.
3426
3427If we were to try to guess the arguments, we would probably guess wrong
3428and then we might not encounter the bug.
3429
3430@item
3431A complete input file, or set of input files, that will reproduce the
3432bug. It is generally most helpful to send the actual object files,
3433uuencoded if necessary to get them through the mail system. Making them
3434available for anonymous FTP is not as good, but may be the only
3435reasonable choice for large object files.
3436
3437If the source files were assembled using @code{gas} or compiled using
3438@code{gcc}, then it may be OK to send the source files rather than the
3439object files. In this case, be sure to say exactly what version of
3440@code{gas} or @code{gcc} was used to produce the object files. Also say
3441how @code{gas} or @code{gcc} were configured.
3442
3443@item
3444A description of what behavior you observe that you believe is
3445incorrect. For example, ``It gets a fatal signal.''
3446
3447Of course, if the bug is that @code{ld} gets a fatal signal, then we
3448will certainly notice it. But if the bug is incorrect output, we might
3449not notice unless it is glaringly wrong. You might as well not give us
3450a chance to make a mistake.
3451
3452Even if the problem you experience is a fatal signal, you should still
3453say so explicitly. Suppose something strange is going on, such as, your
3454copy of @code{ld} is out of synch, or you have encountered a bug in the
3455C library on your system. (This has happened!) Your copy might crash
3456and ours would not. If you told us to expect a crash, then when ours
3457fails to crash, we would know that the bug was not happening for us. If
3458you had not told us to expect a crash, then we would not be able to draw
3459any conclusion from our observations.
3460
3461@item
3462If you wish to suggest changes to the @code{ld} source, send us context
3463diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
3464@samp{-p} option. Always send diffs from the old file to the new file.
3465If you even discuss something in the @code{ld} source, refer to it by
3466context, not by line number.
3467
3468The line numbers in our development sources will not match those in your
3469sources. Your line numbers would convey no useful information to us.
3470@end itemize
3471
3472Here are some things that are not necessary:
3473
3474@itemize @bullet
3475@item
3476A description of the envelope of the bug.
3477
3478Often people who encounter a bug spend a lot of time investigating
3479which changes to the input file will make the bug go away and which
3480changes will not affect it.
3481
3482This is often time consuming and not very useful, because the way we
3483will find the bug is by running a single example under the debugger
3484with breakpoints, not by pure deduction from a series of examples.
3485We recommend that you save your time for something else.
3486
3487Of course, if you can find a simpler example to report @emph{instead}
3488of the original one, that is a convenience for us. Errors in the
3489output will be easier to spot, running under the debugger will take
3490less time, and so on.
3491
3492However, simplification is not vital; if you do not want to do this,
3493report the bug anyway and send us the entire test case you used.
3494
3495@item
3496A patch for the bug.
3497
3498A patch for the bug does help us if it is a good one. But do not omit
3499the necessary information, such as the test case, on the assumption that
3500a patch is all we need. We might see problems with your patch and decide
3501to fix the problem another way, or we might not understand it at all.
3502
de220cbd
ILT
3503Sometimes with a program as complicated as @code{ld} it is very hard to
3504construct an example that will make the program follow a certain path
3505through the code. If you do not send us the example, we will not be
3506able to construct one, so we will not be able to verify that the bug is
3507fixed.
9fde46a4
ILT
3508
3509And if we cannot understand what bug you are trying to fix, or why your
3510patch should be an improvement, we will not install it. A test case will
3511help us to understand.
3512
3513@item
3514A guess about what the bug is or what it depends on.
3515
3516Such guesses are usually wrong. Even we cannot guess right about such
3517things without first using the debugger to find the facts.
3518@end itemize
3519
ec40bbb8 3520@node MRI
2d59b2c3
RP
3521@appendix MRI Compatible Script Files
3522@cindex MRI compatibility
3523To aid users making the transition to @sc{gnu} @code{ld} from the MRI
3524linker, @code{ld} can use MRI compatible linker scripts as an
3525alternative to the more general-purpose linker scripting language
3526described in @ref{Commands,,Command Language}. MRI compatible linker
3527scripts have a much simpler command set than the scripting language
3528otherwise used with @code{ld}. @sc{gnu} @code{ld} supports the most
3529commonly used MRI linker commands; these commands are described here.
3530
867a1b8a
DM
3531In general, MRI scripts aren't of much use with the @code{a.out} object
3532file format, since it only has three sections and MRI scripts lack some
3533features to make use of them.
3534
2d59b2c3
RP
3535You can specify a file containing an MRI-compatible script using the
3536@samp{-c} command-line option.
3537
3538Each command in an MRI-compatible script occupies its own line; each
3539command line starts with the keyword that identifies the command (though
3540blank lines are also allowed for punctuation). If a line of an
3541MRI-compatible script begins with an unrecognized keyword, @code{ld}
3542issues a warning message, but continues processing the script.
3543
3544Lines beginning with @samp{*} are comments.
3545
3546You can write these commands using all upper-case letters, or all
3547lower case; for example, @samp{chip} is the same as @samp{CHIP}.
3548The following list shows only the upper-case form of each command.
3549
3550@table @code
d4e5e3c3 3551@cindex @code{ABSOLUTE} (MRI)
2d59b2c3 3552@item ABSOLUTE @var{secname}
c653b370 3553@itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
2d59b2c3
RP
3554Normally, @code{ld} includes in the output file all sections from all
3555the input files. However, in an MRI-compatible script, you can use the
3556@code{ABSOLUTE} command to restrict the sections that will be present in
3557your output program. If the @code{ABSOLUTE} command is used at all in a
3558script, then only the sections named explicitly in @code{ABSOLUTE}
3559commands will appear in the linker output. You can still use other
3560input sections (whatever you select on the command line, or using
7b015547 3561@code{LOAD}) to resolve addresses in the output file.
2d59b2c3 3562
2d59b2c3 3563@cindex @code{ALIAS} (MRI)
d4e5e3c3 3564@item ALIAS @var{out-secname}, @var{in-secname}
2d59b2c3
RP
3565Use this command to place the data from input section @var{in-secname}
3566in a section called @var{out-secname} in the linker output file.
3567
3568@var{in-secname} may be an integer.
3569
e54bf1c1
ILT
3570@cindex @code{ALIGN} (MRI)
3571@item ALIGN @var{secname} = @var{expression}
3572Align the section called @var{secname} to @var{expression}. The
3573@var{expression} should be a power of two.
3574
2d59b2c3 3575@cindex @code{BASE} (MRI)
d4e5e3c3 3576@item BASE @var{expression}
2d59b2c3
RP
3577Use the value of @var{expression} as the lowest address (other than
3578absolute addresses) in the output file.
3579
d4e5e3c3 3580@cindex @code{CHIP} (MRI)
2d59b2c3
RP
3581@item CHIP @var{expression}
3582@itemx CHIP @var{expression}, @var{expression}
ec40bbb8 3583This command does nothing; it is accepted only for compatibility.
2d59b2c3 3584
2d59b2c3 3585@cindex @code{END} (MRI)
d4e5e3c3 3586@item END
2d59b2c3
RP
3587This command does nothing whatever; it's only accepted for compatibility.
3588
2d59b2c3 3589@cindex @code{FORMAT} (MRI)
d4e5e3c3 3590@item FORMAT @var{output-format}
2d59b2c3
RP
3591Similar to the @code{OUTPUT_FORMAT} command in the more general linker
3592language, but restricted to one of these output formats:
d4e5e3c3 3593
2d59b2c3
RP
3594@enumerate
3595@item
3596S-records, if @var{output-format} is @samp{S}
3597
3598@item
3599IEEE, if @var{output-format} is @samp{IEEE}
3600
3601@item
3602COFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is
3603@samp{COFF}
3604@end enumerate
3605
2d59b2c3 3606@cindex @code{LIST} (MRI)
d4e5e3c3 3607@item LIST @var{anything}@dots{}
2d59b2c3
RP
3608Print (to the standard output file) a link map, as produced by the
3609@code{ld} command-line option @samp{-M}.
3610
ec40bbb8
DM
3611The keyword @code{LIST} may be followed by anything on the
3612same line, with no change in its effect.
2d59b2c3 3613
d4e5e3c3 3614@cindex @code{LOAD} (MRI)
2d59b2c3 3615@item LOAD @var{filename}
c653b370 3616@itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
2d59b2c3
RP
3617Include one or more object file @var{filename} in the link; this has the
3618same effect as specifying @var{filename} directly on the @code{ld}
3619command line.
3620
2d59b2c3 3621@cindex @code{NAME} (MRI)
d4e5e3c3 3622@item NAME @var{output-name}
2d59b2c3
RP
3623@var{output-name} is the name for the program produced by @code{ld}; the
3624MRI-compatible command @code{NAME} is equivalent to the command-line
3625option @samp{-o} or the general script language command @code{OUTPUT}.
3626
d4e5e3c3 3627@cindex @code{ORDER} (MRI)
2d59b2c3
RP
3628@item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
3629@itemx ORDER @var{secname} @var{secname} @var{secname}
ec40bbb8
DM
3630Normally, @code{ld} orders the sections in its output file in the
3631order in which they first appear in the input files. In an MRI-compatible
3632script, you can override this ordering with the @code{ORDER} command. The
2d59b2c3
RP
3633sections you list with @code{ORDER} will appear first in your output
3634file, in the order specified.
3635
d4e5e3c3 3636@cindex @code{PUBLIC} (MRI)
2d59b2c3
RP
3637@item PUBLIC @var{name}=@var{expression}
3638@itemx PUBLIC @var{name},@var{expression}
3639@itemx PUBLIC @var{name} @var{expression}
ec40bbb8 3640Supply a value (@var{expression}) for external symbol
2d59b2c3
RP
3641@var{name} used in the linker input files.
3642
d4e5e3c3 3643@cindex @code{SECT} (MRI)
2d59b2c3
RP
3644@item SECT @var{secname}, @var{expression}
3645@itemx SECT @var{secname}=@var{expression}
3646@itemx SECT @var{secname} @var{expression}
2d59b2c3
RP
3647You can use any of these three forms of the @code{SECT} command to
3648specify the start address (@var{expression}) for section @var{secname}.
3649If you have more than one @code{SECT} statement for the same
3650@var{secname}, only the @emph{first} sets the start address.
3651@end table
3652
ec40bbb8 3653@node Index
2c5c0674
RP
3654@unnumbered Index
3655
3656@printindex cp
3657
3658@tex
3659% I think something like @colophon should be in texinfo. In the
3660% meantime:
3661\long\def\colophon{\hbox to0pt{}\vfill
3662\centerline{The body of this manual is set in}
3663\centerline{\fontname\tenrm,}
3664\centerline{with headings in {\bf\fontname\tenbf}}
3665\centerline{and examples in {\tt\fontname\tentt}.}
3666\centerline{{\it\fontname\tenit\/} and}
3667\centerline{{\sl\fontname\tensl\/}}
3668\centerline{are used for emphasis.}\vfill}
3669\page\colophon
c653b370 3670% Blame: doc@cygnus.com, 28mar91.
2c5c0674
RP
3671@end tex
3672
3673
b4d4e8e3 3674@contents
f22eee08
RP
3675@bye
3676
3677
This page took 0.406707 seconds and 4 git commands to generate.