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