]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/ld.texinfo
New file bfdsumm.texi to share with ld.
[thirdparty/binutils-gdb.git] / ld / ld.texinfo
CommitLineData
f22eee08 1\input texinfo
c8072296 2@setfilename ld.info
b4d4e8e3 3@syncodeindex ky cp
ec40bbb8
DM
4@c @include configdoc.texi
5
6@c @smallbook
c8072296 7@c @cropmarks
1c48127e
RP
8
9@ifinfo
10@format
11START-INFO-DIR-ENTRY
8ddef552 12* Ld:: The GNU linker.
1c48127e
RP
13END-INFO-DIR-ENTRY
14@end format
15@end ifinfo
16
b4d4e8e3 17@ifinfo
246504a5 18This file documents the GNU linker LD.
b4d4e8e3 19
d76ae847 20Copyright (C) 1991, 1992, 1993 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
d76ae847 51@subtitle March 1993
c8072296
RP
52@author Steve Chamberlain and Roland Pesch
53@author Cygnus Support
b4d4e8e3
RP
54@page
55
56@tex
b4d4e8e3
RP
57{\parskip=0pt
58\hfill Cygnus Support\par
2c5c0674 59\hfill steve\@cygnus.com, pesch\@cygnus.com\par
ec40bbb8
DM
60\hfill {\it Using LD, the GNU linker}\par
61\hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com), March 1993.\par
b4d4e8e3
RP
62}
63\global\parindent=0pt % Steve likes it this way.
64@end tex
65
f22eee08 66@vskip 0pt plus 1filll
d76ae847 67Copyright @copyright{} 1991, 1992, 1993 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
246504a5 87This file documents the 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
100@ifset I960
101* i960:: ld and the Intel 960 family
102@end ifset
103@end ifclear
104@ifclear SingleFormat
2d59b2c3 105* BFD:: BFD
ec40bbb8
DM
106@end ifclear
107@c Following blank line required for remaining bug in makeinfo conds/menus
108
2d59b2c3
RP
109* MRI:: MRI Compatible Script Files
110* Index:: Index
2c5c0674 111@end menu
ec40bbb8 112@end ifinfo
2c5c0674 113
ec40bbb8 114@node Overview
f22eee08
RP
115@chapter Overview
116
2c5c0674
RP
117@cindex GNU linker
118@cindex what is this?
246504a5 119@code{ld} combines a number of object and archive files, relocates
ec40bbb8
DM
120their data and ties up symbol references. Usually the last step in
121compiling a program is to run @code{ld}.
f22eee08 122
246504a5 123@code{ld} accepts Linker Command Language files written in
2c5c0674 124a superset of AT&T's Link Editor Command Language syntax,
b4d4e8e3 125to provide explicit and total control over the linking process.
f22eee08 126
ec40bbb8 127@ifclear SingleFormat
246504a5
RP
128This version of @code{ld} uses the general purpose BFD libraries
129to operate on object files. This allows @code{ld} to read, combine, and
b4d4e8e3
RP
130write object files in many different formats---for example, COFF or
131@code{a.out}. Different formats may be linked together to produce any
132available kind of object file. @xref{BFD} for a list of formats
133supported on various architectures.
ec40bbb8 134@end ifclear
f22eee08 135
2c5c0674
RP
136Aside from its flexibility, the GNU linker is more helpful than other
137linkers in providing diagnostic information. Many linkers abandon
138execution immediately upon encountering an error; whenever possible,
246504a5 139@code{ld} continues executing, allowing you to identify other errors
2c5c0674
RP
140(or, in some cases, to get an output file in spite of the error).
141
ec40bbb8 142@node Invocation
2c5c0674
RP
143@chapter Invocation
144
246504a5 145The GNU linker @code{ld} is meant to cover a broad range of situations,
2c5c0674 146and to be as compatible as possible with other linkers. As a result,
ec40bbb8 147you have many choices to control its behavior.
2c5c0674 148
ec40bbb8 149@ifset UsesEnvVars
2c5c0674 150@menu
2d59b2c3
RP
151* Options:: Command Line Options
152* Environment:: Environment Variables
2c5c0674 153@end menu
f22eee08 154
ec40bbb8 155@node Options
2c5c0674 156@section Command Line Options
ec40bbb8 157@end ifset
2c5c0674
RP
158
159@cindex command line
160@cindex options
ec40bbb8 161Here is a summary of the options you can use on the @code{ld} command
2c5c0674 162line:
f22eee08 163
ec40bbb8 164@c FIXME! -relax only avail h8/300, i960. Conditionals screwed in examples.
c8072296 165@smallexample
8ddef552 166ld [-o @var{output} ] @var{objfile}@dots{}
cb70c872
RP
167 [ -A@var{architecture} ] [ -b @var{input-format} ] [ -Bstatic ]
168 [ -c @var{MRI-commandfile} ] [ -d | -dc | -dp ]
d76ae847 169 [ -defsym @var{symbol}=@var{expression} ]
cb70c872 170 [ -e @var{entry} ] [ -F ] [ -F @var{format} ]
8ddef552 171 [ -format @var{input-format} ] [ -g ] [ -G @var{size} ] [ -i ]
d18a4527
DM
172 [ -l@var{ar} ] [ -L@var{searchdir} ] [ -M ] [ -Map @var{mapfile} ]
173 [ -m @var{emulation} ] [ -N | -n ] [ -noinhibit-exec ]
346535cc
DM
174 [ -oformat @var{output-format} ] [ -R @var{filename} ] [ -relax ]
175 [ -r | -Ur ] [ -S ] [ -s ] [ -T @var{commandfile} ]
176 [ -Ttext @var{textorg} ] [ -Tdata @var{dataorg} ]
d18a4527 177 [ -Tbss @var{bssorg} ] [ -t ] [ -u @var{sym}] [-V] [-v] [ -X ] [-x ]
346535cc 178 [ -y@var{symbol} ]
c8072296 179@end smallexample
b4d4e8e3
RP
180
181This plethora of command-line options may seem intimidating, but in
182actual practice few of them are used in any particular context.
2c5c0674 183@cindex standard Unix system
246504a5 184For instance, a frequent use of @code{ld} is to link standard Unix
b4d4e8e3
RP
185object files on a standard, supported Unix system. On such a system, to
186link a file @code{hello.o}:
ec40bbb8 187
f22eee08 188@example
ec40bbb8 189ld -o @var{output} /lib/crt0.o hello.o -lc
f22eee08 190@end example
ec40bbb8 191
d76ae847 192This tells @code{ld} to produce a file called @var{output} as the
b4d4e8e3 193result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
ec40bbb8
DM
194the library @code{libc.a}, which will come from the standard search
195directories. (See the discussion of the @samp{-l} option below.)
f22eee08 196
246504a5 197The command-line options to @code{ld} may be specified in any order, and
ec40bbb8 198may be repeated at will. Repeating most options with a
f22eee08 199different argument will either have no further effect, or override prior
ec40bbb8 200occurrences (those further to the left on the command line) of that
f22eee08
RP
201option.
202
ec40bbb8 203@ifclear SingleFormat
2c5c0674 204The exceptions---which may meaningfully be used more than once---are
ec40bbb8
DM
205@samp{-A}, @samp{-b} (or its synonym @samp{-format}), @samp{-defsym},
206@samp{-L}, @samp{-l}, @samp{-R}, and @samp{-u}.
207@end ifclear
208@ifset SingleFormat
209The exceptions---which may meaningfully be used more than once---are
210@samp{-A}, @samp{-defsym}, @samp{-L}, @samp{-l}, @samp{-R}, and @samp{-u}.
211@end ifset
f22eee08 212
2c5c0674 213@cindex object files
8ddef552 214The list of object files to be linked together, shown as @var{objfile}@dots{},
ec40bbb8
DM
215may follow, precede, or be mixed in with command-line options, except that
216an @var{objfile} argument may not be placed between an option and
b4d4e8e3 217its argument.
f22eee08 218
2c5c0674 219Usually the linker is invoked with at least one object file, but other
ec40bbb8
DM
220forms of binary input files can also be specified with @samp{-l},
221@samp{-R}, and the script command language. If @emph{no} binary input
2c5c0674
RP
222files at all are specified, the linker does not produce any output, and
223issues the message @samp{No input files}.
224
225Option arguments must either follow the option letter without intervening
f22eee08
RP
226whitespace, or be given as separate arguments immediately following the
227option that requires them.
228
229@table @code
8ddef552 230@item @var{objfile}@dots{}
ec40bbb8 231The object files to be linked.
f22eee08 232
ec40bbb8 233@ifset I960
2c5c0674
RP
234@cindex architectures
235@kindex -A@var{arch}
b4d4e8e3 236@item -A@var{architecture}
246504a5
RP
237In the current release of @code{ld}, this option is useful only for the
238Intel 960 family of architectures. In that @code{ld} configuration, the
1c48127e
RP
239@var{architecture} argument identifies the particular architecture in
240the 960 family, enabling some safeguards and modifying the
d76ae847
RP
241archive-library search path. @xref{i960,,@code{ld} and the Intel 960
242family}, for details.
b4d4e8e3 243
246504a5 244Future releases of @code{ld} may support similar functionality for
b4d4e8e3 245other architecture families.
ec40bbb8 246@end ifset
b4d4e8e3 247
ec40bbb8 248@ifclear SingleFormat
2c5c0674
RP
249@cindex binary input format
250@kindex -b @var{format}
251@cindex input format
252@item -b @var{input-format}
253@cindex input format
254Specify the binary format for input object files that follow this option
255on the command line. You don't usually need to specify this, as
246504a5 256@code{ld} is configured to expect as a default input format the most
2c5c0674 257usual format on each machine. @var{input-format} is a text string, the
d76ae847 258name of a particular format supported by the BFD libraries.
346535cc
DM
259(You can list the available binary formats with @samp{objdump -i}.)
260@w{@samp{-format @var{input-format}}} has the same effect, as does the
261script command @code{TARGET}. @xref{BFD}.
2c5c0674
RP
262
263You may want to use this option if you are linking files with an unusual
ec40bbb8 264binary format. You can also use @samp{-b} to switch formats explicitly (when
2c5c0674 265linking object files of different formats), by including
ec40bbb8 266@samp{-b @var{input-format}} before each group of object files in a
2c5c0674
RP
267particular format.
268
269The default format is taken from the environment variable
ec40bbb8
DM
270@code{GNUTARGET}.
271@ifset UsesEnvVars
272@xref{Environment}.
273@end ifset
274You can also define the input
d76ae847
RP
275format from a script, using the command @code{TARGET}; see @ref{Other
276Commands}.
ec40bbb8 277@end ifclear
2c5c0674
RP
278
279@kindex -Bstatic
f22eee08 280@item -Bstatic
ec40bbb8
DM
281Ignored. This option is accepted for command-line compatibility with
282the SunOS linker.
f22eee08 283
2d59b2c3
RP
284@kindex -c @var{MRI-cmdfile}
285@cindex compatibility, MRI
286@item -c @var{MRI-commandfile}
287For compatibility with linkers produced by MRI, @code{ld} accepts script
288files written in an alternate, restricted command language, described in
d76ae847 289@ref{MRI,,MRI Compatible Script Files}. Introduce MRI script files with
ec40bbb8 290the option @samp{-c}; use the @samp{-T} option to run linker
d76ae847 291scripts written in the general-purpose @code{ld} scripting language.
8ddef552
DM
292If @var{MRI-cmdfile} does not exist, @code{ld} looks for it in the directories
293specified by any @samp{-L} options.
b4d4e8e3 294
2c5c0674
RP
295@cindex common allocation
296@kindex -d
b4d4e8e3 297@item -d
2c5c0674 298@kindex -dc
b4d4e8e3 299@itemx -dc
2c5c0674 300@kindex -dp
b4d4e8e3
RP
301@itemx -dp
302These three options are equivalent; multiple forms are supported for
ec40bbb8 303compatibility with other linkers. They
2c5c0674 304assign space to common symbols even if a relocatable output file is
ec40bbb8 305specified (with @samp{-r}). The script command
d76ae847
RP
306@code{FORCE_COMMON_ALLOCATION} has the same effect. @xref{Other
307Commands}.
b4d4e8e3 308
2c5c0674 309@cindex symbols, from command line
d76ae847
RP
310@kindex -defsym @var{symbol}=@var{exp}
311@item -defsym @var{symbol}=@var{expression}
2c5c0674
RP
312Create a global symbol in the output file, containing the absolute
313address given by @var{expression}. You may use this option as many
314times as necessary to define multiple symbols in the command line. A
315limited form of arithmetic is supported for the @var{expression} in this
316context: you may give a hexadecimal constant or the name of an existing
317symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
318constants or symbols. If you need more elaborate expressions, consider
d76ae847
RP
319using the linker command language from a script (@pxref{Assignment, ,
320Assignment: Symbol Definitions}). @emph{Note:} there should be no
321white space between @var{symbol}, the equals sign (``@key{=}''), and
322@var{expression}.
2c5c0674
RP
323
324@cindex entry point, from command line
325@kindex -e @var{entry}
f22eee08
RP
326@item -e @var{entry}
327Use @var{entry} as the explicit symbol for beginning execution of your
b4d4e8e3
RP
328program, rather than the default entry point. @xref{Entry Point}, for a
329discussion of defaults and other ways of specifying the
330entry point.
f22eee08 331
ec40bbb8 332@ifclear SingleFormat
2c5c0674 333@kindex -F
b4d4e8e3 334@item -F
2c5c0674 335@itemx -F@var{format}
ec40bbb8
DM
336Ignored. Some older linkers used this option throughout a compilation
337toolchain for specifying object-file format for both input and output
338object files. The mechanisms @code{ld} uses for this purpose (the
339@samp{-b} or @samp{-format} options for input files, the @code{TARGET}
340command in linker scripts for output files, the @code{GNUTARGET}
341environment variable) are more flexible, but @code{ld} accepts the
342@samp{-F} option for compatibility with scripts written to call the old
343linker.
2c5c0674
RP
344
345@kindex -format
346@item -format @var{input-format}
ec40bbb8
DM
347Synonym for @samp{-b @var{input-format}}.
348@end ifclear
2c5c0674
RP
349
350@kindex -g
b4d4e8e3 351@item -g
ec40bbb8 352Ignored. Provided for compatibility with other tools.
b4d4e8e3 353
8ddef552
DM
354@kindex -G
355@cindex object size
356@item -G@var{value}
357@itemx -G @var{value}
358Set the maximum size of objects to be optimized using the GP register to
359@var{size} under MIPS ECOFF. Ignored for other object file formats.
360
2c5c0674
RP
361@kindex -i
362@cindex incremental link
f22eee08 363@item -i
ec40bbb8 364Perform an incremental link (same as option @samp{-r}).
f22eee08 365
2c5c0674
RP
366@cindex archive files, from cmd line
367@kindex -l@var{ar}
b4d4e8e3 368@item -l@var{ar}
ec40bbb8 369Add archive file @var{ar} to the list of files to link. This
f22eee08 370option may be used any number of times. @code{ld} will search its
b4d4e8e3 371path-list for occurrences of @code{lib@var{ar}.a} for every @var{ar}
f22eee08
RP
372specified.
373
2c5c0674
RP
374@cindex search directory, from cmd line
375@kindex -L@var{dir}
b4d4e8e3 376@item -L@var{searchdir}
ec40bbb8 377Add path @var{searchdir} to the list of paths that @code{ld} will search
8ddef552
DM
378for archive libraries and @code{ld} control scripts. You may use this
379option any number of times.
f22eee08 380
ec40bbb8 381@ifset UsesEnvVars
2c5c0674 382The default set of paths searched (without being specified with
ec40bbb8
DM
383@samp{-L}) depends on which emulation mode @code{ld} is using, and in
384some cases also on how it was configured. @xref{Environment}.
385@end ifset
386
387The paths can also be specified in a link script with the
388@code{SEARCH_DIR} command.
f22eee08 389
2c5c0674
RP
390@cindex link map
391@kindex -M
f22eee08 392@item -M
ec40bbb8 393Print (to the standard output) a link map---diagnostic information
f22eee08
RP
394about where symbols are mapped by @code{ld}, and information on global
395common storage allocation.
396
d18a4527
DM
397@cindex link map
398@kindex -Map
399@item -Map @var{mapfile}
400Print to the file @var{mapfile} a link map---diagnostic information
401about where symbols are mapped by @code{ld}, and information on global
402common storage allocation.
403
8ddef552
DM
404@cindex emulation
405@kindex -m @var{emulation}
406@item -m@var{emulation}
407@itemx -m @var{emulation}
408Emulate the @var{emulation} linker. You can list the available
409emulations with the @samp{-V} option. The
410default is the system for which you configured @code{ld}.
411
2c5c0674
RP
412@kindex -N
413@cindex read/write from cmd line
414@kindex OMAGIC
f22eee08 415@item -N
ec40bbb8
DM
416Set the text and data sections to be readable and writable. Also, do
417not page-align the data segment. If the output format supports Unix
418style magic numbers, mark the output as @code{OMAGIC}.
f22eee08
RP
419
420@item -n
2c5c0674
RP
421@kindex -n
422@cindex read-only text
423@kindex NMAGIC
ec40bbb8
DM
424Set the text segment to be read only, and mark the output as
425@code{NMAGIC} if possible.
f22eee08 426
b4d4e8e3 427@item -noinhibit-exec
2c5c0674
RP
428@cindex output file after errors
429@kindex -noinhibit-exec
ec40bbb8 430Retain the executable output file whenever it is still usable.
b4d4e8e3 431Normally, the linker will not produce an output file if it encounters
ec40bbb8
DM
432errors during the link process; it exits without writing an output file
433when it issues any error whatsoever.
b4d4e8e3 434
f22eee08 435@item -o @var{output}
2c5c0674
RP
436@kindex -o @var{output}
437@cindex naming the output file
ec40bbb8
DM
438Use @var{output} as the name for the program produced by @code{ld}; if this
439option is not specified, the name @file{a.out} is used by default. The
2c5c0674 440script command @code{OUTPUT} can also specify the output file name.
f22eee08 441
346535cc
DM
442@kindex -oformat
443@item -oformat @var{output-format}
444Specify the binary format for the output object file. You don't usually
445need to specify this, as @code{ld} is configured to produce as a default
446output format the most usual format on each machine.
447@var{output-format} is a text string, the name of a particular format
448supported by the BFD libraries. (You can list the available binary
449formats with @samp{objdump -i}.) The script command
450@code{OUTPUT_FORMAT} can also specify the output format, but this option
451overrides it. @xref{BFD}.
452
b4d4e8e3 453@item -R @var{filename}
2c5c0674
RP
454@kindex -R @var{file}
455@cindex symbol-only input
ec40bbb8
DM
456On some platforms, this option performs global optimizations
457that become possible when the linker resolves addressing in the
458program, such as relaxing address modes and synthesizing new
459instructions in the output object file.
460
1c48127e
RP
461@item -relax
462@kindex -relax
463@cindex synthesizing linker
464@cindex relaxing addressing modes
465An option with machine dependent effects. Currently this option is only
ec40bbb8
DM
466supported on the H8/300.
467@ifset H8300
468@xref{H8/300,,@code{ld} and the H8/300}.
469@end ifset
1c48127e 470
ec40bbb8
DM
471On some platforms, use option performs global optimizations that
472become possible when the linker resolves addressing in the program, such
1c48127e
RP
473as relaxing address modes and synthesizing new instructions in the
474output object file.
475
476On platforms where this is not supported, @samp{-relax} is accepted, but
ec40bbb8 477ignored.
1c48127e 478
f22eee08 479@item -r
b4d4e8e3 480@cindex partial link
2c5c0674
RP
481@cindex relocatable output
482@kindex -r
ec40bbb8 483Generate relocatable output---i.e., generate an output file that can in
246504a5 484turn serve as input to @code{ld}. This is often called @dfn{partial
2c5c0674
RP
485linking}. As a side effect, in environments that support standard Unix
486magic numbers, this option also sets the output file's magic number to
487@code{OMAGIC}.
488@c ; see @code{-N}.
489If this option is not specified, an absolute file is produced. When
490linking C++ programs, this option @emph{will not} resolve references to
ec40bbb8 491constructors; to do that, use @samp{-Ur}.
2c5c0674
RP
492
493This option does the same as @code{-i}.
f22eee08
RP
494
495@item -S
2c5c0674
RP
496@kindex -S
497@cindex strip debugger symbols
ec40bbb8 498Omit debugger symbol information (but not all symbols) from the output file.
f22eee08
RP
499
500@item -s
2c5c0674
RP
501@kindex -s
502@cindex strip all symbols
ec40bbb8 503Omit all symbol information from the output file.
f22eee08 504
d76ae847
RP
505@item -Tbss @var{bssorg}
506@kindex -Tbss @var{bssorg}
507@itemx -Tdata @var{dataorg}
508@kindex -Tdata @var{dataorg}
509@itemx -Ttext @var{textorg}
510@kindex -Ttext @var{textorg}
2c5c0674
RP
511@cindex segment origins, cmd line
512Use @var{org} as the starting address for---respectively---the
b4d4e8e3 513@code{bss}, @code{data}, or the @code{text} segment of the output file.
ec40bbb8
DM
514@var{org} must be a single hexadecimal integer;
515for compatibility with other linkers, you may omit the leading
d76ae847 516@samp{0x} usually associated with hexadecimal values.
f22eee08 517
b4d4e8e3
RP
518@item -T @var{commandfile}
519@itemx -T@var{commandfile}
2c5c0674 520@kindex -T @var{script}
2d59b2c3 521@cindex script files
ec40bbb8
DM
522Read link commands from the file
523@var{commandfile}. These commands completely override @code{ld}'s
2d59b2c3
RP
524default link format (rather than adding to it); @var{commandfile} must
525specify everything necessary to describe the target format.
526@xref{Commands}.
8ddef552
DM
527If @var{commandfile} does not exist, @code{ld} looks for it in the directories
528specified by any @samp{-L} options.
2d59b2c3
RP
529
530You may also include a script of link commands directly in the command
d76ae847 531line by bracketing it between @samp{@{} and @samp{@}}.
f22eee08
RP
532
533@item -t
2c5c0674
RP
534@kindex -t
535@cindex verbose
536@cindex input files, displaying
ec40bbb8 537Print the names of the input files as @code{ld} processes them.
f22eee08
RP
538
539@item -u @var{sym}
2c5c0674
RP
540@kindex -u @var{sym}
541@cindex undefined symbol
ec40bbb8
DM
542Force @var{sym} to be entered in the output file as an undefined symbol.
543Doing this may, for example, trigger linking of additional modules from
544standard libraries. @samp{-u} may be repeated with different option
2c5c0674
RP
545arguments to enter additional undefined symbols.
546@c Nice idea, but no such command: This option is equivalent
547@c to the @code{EXTERN} linker command.
f22eee08 548
b4d4e8e3 549@item -Ur
2c5c0674 550@kindex -Ur
b4d4e8e3
RP
551@cindex constructors
552For anything other than C++ programs, this option is equivalent to
ec40bbb8
DM
553@samp{-r}: it generates relocatable output---i.e., an output file that can in
554turn serve as input to @code{ld}. When linking C++ programs, @samp{-Ur}
555@emph{will} resolve references to constructors, unlike @samp{-r}.
b4d4e8e3 556
8ddef552
DM
557@item -V
558@kindex -V
559@cindex version
560Display the version number for @code{ld} and list the supported emulations.
561Print which input files can and can not be opened.
562
b4d4e8e3 563@item -v
2c5c0674 564@kindex -v
b4d4e8e3 565@cindex version
246504a5 566Display the version number for @code{ld}.
8ddef552 567Print which input files can and can not be opened.
b4d4e8e3 568
f22eee08 569@item -X
2c5c0674
RP
570@kindex -X
571@cindex local symbols, deleting
572@cindex L, deleting symbols beginning
ec40bbb8 573If @samp{-s} or @samp{-S} is also specified, delete only local symbols
f22eee08
RP
574beginning with @samp{L}.
575
b4d4e8e3 576@item -x
2c5c0674
RP
577@kindex -x
578@cindex deleting local symbols
ec40bbb8 579If @samp{-s} or @samp{-S} is also specified, delete all local symbols,
b4d4e8e3
RP
580not just those beginning with @samp{L}.
581
ec40bbb8 582@item -y@var{symbol}
d76ae847
RP
583@kindex -y@var{symbol}
584@cindex symbol tracing
ec40bbb8 585Print the name of each linked file in which @var{symbol} appears. This
d76ae847
RP
586option may be given any number of times. On many systems it is necessary
587to prepend an underscore.
588
589This option is useful when you have an undefined symbol in your link but
590don't know where the reference is coming from.
f22eee08 591@end table
b4d4e8e3 592
ec40bbb8
DM
593@ifset UsesEnvVars
594@node Environment
2c5c0674
RP
595@section Environment Variables
596
d76ae847
RP
597You can change the behavior of @code{ld} with the environment
598variable @code{GNUTARGET}.
2c5c0674
RP
599
600@kindex GNUTARGET
601@cindex default input format
602@code{GNUTARGET} determines the input-file object format if you don't
ec40bbb8 603use @samp{-b} (or its synonym @samp{-format}). Its value should be one
2c5c0674 604of the BFD names for an input format (@pxref{BFD}). If there is no
246504a5 605@code{GNUTARGET} in the environment, @code{ld} uses the natural format
2c5c0674
RP
606of the host. If @code{GNUTARGET} is set to @code{default} then BFD attempts to discover the
607input format by examining binary input files; this method often
608succeeds, but there are potential ambiguities, since there is no method
ec40bbb8 609of ensuring that the magic number used to specify object-file formats is
2c5c0674
RP
610unique. However, the configuration procedure for BFD on each system
611places the conventional format for that system first in the search-list,
612so ambiguities are resolved in favor of convention.
ec40bbb8 613@end ifset
2c5c0674 614
ec40bbb8 615@node Commands
2c5c0674 616@chapter Command Language
f22eee08 617
2c5c0674 618@cindex command files
ec40bbb8 619The command language provides explicit control over the link process,
b4d4e8e3 620allowing complete specification of the mapping between the linker's
ec40bbb8 621input files and its output. It controls:
b4d4e8e3 622@itemize @bullet
2c5c0674
RP
623@item
624input files
625@item
626file formats
627@item
628output file format
629@item
630addresses of sections
631@item
632placement of common blocks
b4d4e8e3 633@end itemize
f22eee08 634
2c5c0674 635You may supply a command file (also known as a link script) to the
ec40bbb8 636linker either explicitly through the @samp{-T} option, or implicitly as
2c5c0674
RP
637an ordinary file. If the linker opens a file which it cannot recognize
638as a supported object or archive format, it tries to interpret the file
639as a command file.
640
246504a5 641You can also include a script directly on the @code{ld} command line,
2c5c0674
RP
642delimited by the characters @samp{@{} and @samp{@}}.
643
644@menu
2d59b2c3
RP
645* Scripts:: Linker Scripts
646* Expressions:: Expressions
647* MEMORY:: MEMORY Command
648* SECTIONS:: SECTIONS Command
649* Entry Point:: The Entry Point
650* Other Commands:: Other Commands
2c5c0674
RP
651@end menu
652
ec40bbb8 653@node Scripts
b4d4e8e3 654@section Linker Scripts
246504a5 655The @code{ld} command language is a collection of statements; some are
ec40bbb8
DM
656simple keywords setting a particular option, some are used to select and
657group input files or name output files; and two statement
b4d4e8e3
RP
658types have a fundamental and pervasive impact on the linking process.
659
2c5c0674
RP
660@cindex fundamental script commands
661@cindex commands, fundamental
662@cindex output file layout
663@cindex layout of output file
246504a5 664The most fundamental command of the @code{ld} command language is the
b4d4e8e3
RP
665@code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command
666script must have a @code{SECTIONS} command: it specifies a
667``picture'' of the output file's layout, in varying degrees of detail.
668No other command is required in all cases.
669
670The @code{MEMORY} command complements @code{SECTIONS} by describing the
2c5c0674 671available memory in the target architecture. This command is optional;
246504a5 672if you don't use a @code{MEMORY} command, @code{ld} assumes sufficient
2c5c0674
RP
673memory is available in a contiguous block for all output.
674@xref{MEMORY}.
b4d4e8e3 675
2c5c0674
RP
676@cindex comments
677You may include comments in linker scripts just as in C: delimited
678by @samp{/*} and @samp{*/}. As in C, comments are syntactically
679equivalent to whitespace.
680
ec40bbb8 681@node Expressions
f22eee08 682@section Expressions
2c5c0674
RP
683@cindex expression syntax
684@cindex arithmetic
b4d4e8e3
RP
685Many useful commands involve arithmetic expressions. The syntax for
686expressions in the command language is identical to that of C
687expressions, with the following features:
688@itemize @bullet
2c5c0674
RP
689@item
690All expressions evaluated as integers and
f22eee08 691are of ``long'' or ``unsigned long'' type.
2c5c0674
RP
692@item
693All constants are integers.
694@item
695All of the C arithmetic operators are provided.
696@item
697You may reference, define, and create global variables.
698@item
699You may call special purpose built-in functions.
b4d4e8e3 700@end itemize
f22eee08 701
2c5c0674 702@menu
2d59b2c3
RP
703* Integers:: Integers
704* Symbols:: Symbol Names
705* Location Counter:: The Location Counter
706* Operators:: Operators
707* Evaluation:: Evaluation
708* Assignment:: Assignment: Defining Symbols
709* Built-ins:: Built-In Functions
2c5c0674
RP
710@end menu
711
ec40bbb8 712@node Integers
f22eee08 713@subsection Integers
2c5c0674
RP
714@cindex integer notation
715@cindex octal integers
f22eee08
RP
716An octal integer is @samp{0} followed by zero or more of the octal
717digits (@samp{01234567}).
b4d4e8e3 718@example
2c5c0674 719_as_octal = 0157255;
b4d4e8e3 720@end example
f22eee08 721
2c5c0674 722@cindex decimal integers
f22eee08
RP
723A decimal integer starts with a non-zero digit followed by zero or
724more digits (@samp{0123456789}).
b4d4e8e3 725@example
2c5c0674 726_as_decimal = 57005;
b4d4e8e3 727@end example
f22eee08 728
2c5c0674
RP
729@cindex hexadecimal integers
730@kindex 0x
f22eee08
RP
731A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or
732more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}.
b4d4e8e3
RP
733@example
734_as_hex = 0xdead;
735@end example
f22eee08 736
2c5c0674 737@cindex negative integers
ec40bbb8 738To write a negative integer, use
b4d4e8e3
RP
739the prefix operator @samp{-}; @pxref{Operators}.
740@example
b4d4e8e3
RP
741_as_neg = -57005;
742@end example
f22eee08 743
2c5c0674
RP
744@cindex scaled integers
745@cindex K and M integer suffixes
746@cindex M and K integer suffixes
747@cindex suffixes for integers
748@cindex integer suffixes
b4d4e8e3
RP
749Additionally the suffixes @code{K} and @code{M} may be used to scale a
750constant by
c8072296
RP
751@c TEXI2ROFF-KILL
752@ifinfo
753@c END TEXI2ROFF-KILL
754@code{1024} or @code{1024*1024}
755@c TEXI2ROFF-KILL
756@end ifinfo
f22eee08 757@tex
b4d4e8e3 758${\rm 1024}$ or ${\rm 1024}^2$
f22eee08 759@end tex
c8072296 760@c END TEXI2ROFF-KILL
ec40bbb8 761respectively. For example, the following all refer to the same quantity:
f22eee08
RP
762
763@example
2c5c0674
RP
764 _fourk_1 = 4K;
765 _fourk_2 = 4096;
766 _fourk_3 = 0x1000;
f22eee08 767@end example
b4d4e8e3 768
ec40bbb8 769@node Symbols
b4d4e8e3 770@subsection Symbol Names
2c5c0674
RP
771@cindex symbol names
772@cindex names
773@cindex quoted symbol names
774@kindex "
b4d4e8e3 775Unless quoted, symbol names start with a letter, underscore, point or
2c5c0674 776hyphen and may include any letters, underscores, digits, points,
b4d4e8e3
RP
777and minus signs. Unquoted symbol names must not conflict with any
778keywords. You can specify a symbol which contains odd characters or has
779the same name as a keyword, by surrounding the symbol name in double quotes:
780@example
781 "SECTION" = 9;
782 "with a space" = "also with a space" + 10;
783@end example
784
ec40bbb8 785@node Location Counter
b4d4e8e3 786@subsection The Location Counter
2c5c0674
RP
787@kindex .
788@cindex dot
789@cindex location counter
790@cindex current output location
b4d4e8e3
RP
791The special linker variable @dfn{dot} @samp{.} always contains the
792current output location counter. Since the @code{.} always refers to
793a location in an output section, it must always appear in an
794expression within a @code{SECTIONS} command. The @code{.} symbol
795may appear anywhere that an ordinary symbol is allowed in an
796expression, but its assignments have a side effect. Assigning a value
797to the @code{.} symbol will cause the location counter to be moved.
2c5c0674 798@cindex holes
b4d4e8e3
RP
799This may be used to create holes in the output section. The location
800counter may never be moved backwards.
801@example
2c5c0674
RP
802SECTIONS
803@{
804 output :
b4d4e8e3 805 @{
2c5c0674
RP
806 file1(.text)
807 . = . + 1000;
808 file2(.text)
809 . += 1000;
810 file3(.text)
811 @} = 0x1234;
812@}
b4d4e8e3 813@end example
2c5c0674
RP
814@noindent
815In the previous example, @code{file1} is located at the beginning of the
816output section, then there is a 1000 byte gap. Then @code{file2}
817appears, also with a 1000 byte gap following before @code{file3} is
818loaded. The notation @samp{= 0x1234} specifies what data to write in
819the gaps (@pxref{Section Options}).
b4d4e8e3 820
ec40bbb8 821@node Operators
f22eee08 822@subsection Operators
2c5c0674
RP
823@cindex Operators for arithmetic
824@cindex arithmetic operators
825@cindex precedence in expressions
b4d4e8e3 826The linker recognizes the standard C set of arithmetic operators, with
f22eee08 827the standard bindings and precedence levels:
c8072296 828@c TEXI2ROFF-KILL
b4d4e8e3 829@ifinfo
c8072296 830@c END TEXI2ROFF-KILL
f22eee08 831@example
c8072296 832precedence associativity Operators Notes
b4d4e8e3 833(highest)
c8072296
RP
8341 left ! - ~ (1)
8352 left * / %
8363 left + -
8374 left >> <<
8385 left == != > < <= >=
8396 left &
8407 left |
8418 left &&
8429 left ||
84310 right ? :
84411 right &= += -= *= /= (2)
b4d4e8e3 845(lowest)
f22eee08 846@end example
2c5c0674
RP
847Notes:
848(1) Prefix operators
849(2) @xref{Assignment}
c8072296 850@c TEXI2ROFF-KILL
b4d4e8e3 851@end ifinfo
f22eee08 852@tex
2c5c0674
RP
853\vskip \baselineskip
854%"lispnarrowing" is the extra indent used generally for @example
855\hskip\lispnarrowing\vbox{\offinterlineskip
f22eee08
RP
856\hrule
857\halign
2c5c0674
RP
858{\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
859height2pt&\omit&&\omit&&\omit&\cr
860&Precedence&& Associativity &&{\rm Operators}&\cr
861height2pt&\omit&&\omit&&\omit&\cr
f22eee08 862\noalign{\hrule}
2c5c0674 863height2pt&\omit&&\omit&&\omit&\cr
b4d4e8e3 864&highest&&&&&\cr
2c5c0674
RP
865% '176 is tilde, '~' in tt font
866&1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
867&2&&left&&* / \%&\cr
868&3&&left&&+ -&\cr
869&4&&left&&>> <<&\cr
870&5&&left&&== != > < <= >=&\cr
f22eee08 871&6&&left&&\&&\cr
f22eee08 872&7&&left&&|&\cr
f22eee08 873&8&&left&&{\&\&}&\cr
f22eee08 874&9&&left&&||&\cr
2c5c0674
RP
875&10&&right&&? :&\cr
876&11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr
b4d4e8e3 877&lowest&&&&&\cr
2c5c0674 878height2pt&\omit&&\omit&&\omit&\cr}
f22eee08
RP
879\hrule}
880@end tex
2c5c0674
RP
881@iftex
882{
883@obeylines@parskip=0pt@parindent=0pt
884@dag@quad Prefix operators.
885@ddag@quad @xref{Assignment}.
886}
887@end iftex
c8072296 888@c END TEXI2ROFF-KILL
f22eee08 889
ec40bbb8 890@node Evaluation
b4d4e8e3
RP
891@subsection Evaluation
892
2c5c0674
RP
893@cindex lazy evaluation
894@cindex expression evaluation order
b4d4e8e3
RP
895The linker uses ``lazy evaluation'' for expressions; it only calculates
896an expression when absolutely necessary. The linker needs the value of
897the start address, and the lengths of memory regions, in order to do any
898linking at all; these values are computed as soon as possible when the
899linker reads in the command file. However, other values (such as symbol
900values) are not known or needed until after storage allocation. Such
901values are evaluated later, when other information (such as the sizes of
902output sections) is available for use in the symbol assignment
903expression.
904
ec40bbb8 905@node Assignment
b4d4e8e3 906@subsection Assignment: Defining Symbols
2c5c0674
RP
907@cindex assignment in scripts
908@cindex symbol definition, scripts
909@cindex variables, defining
b4d4e8e3
RP
910You may create global symbols, and assign values (addresses) to global
911symbols, using any of the C assignment operators:
912
913@table @code
914@item @var{symbol} = @var{expression} ;
2c5c0674 915@itemx @var{symbol} &= @var{expression} ;
b4d4e8e3
RP
916@itemx @var{symbol} += @var{expression} ;
917@itemx @var{symbol} -= @var{expression} ;
918@itemx @var{symbol} *= @var{expression} ;
919@itemx @var{symbol} /= @var{expression} ;
920@end table
921
246504a5 922Two things distinguish assignment from other operators in @code{ld}
b4d4e8e3
RP
923expressions.
924@itemize @bullet
2c5c0674
RP
925@item
926Assignment may only be used at the root of an expression;
b4d4e8e3 927@samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error.
2c5c0674
RP
928
929@kindex ;
930@cindex semicolon
931@item
d76ae847
RP
932You must place a trailing semicolon (``@key{;}'') at the end of an
933assignment statement.
b4d4e8e3
RP
934@end itemize
935
936Assignment statements may appear:
937@itemize @bullet
2c5c0674 938@item
246504a5 939as commands in their own right in an @code{ld} script; or
2c5c0674
RP
940@item
941as independent statements within a @code{SECTIONS} command; or
942@item
943as part of the contents of a section definition in a
b4d4e8e3
RP
944@code{SECTIONS} command.
945@end itemize
946
947The first two cases are equivalent in effect---both define a symbol with
ec40bbb8 948an absolute address. The last case defines a symbol whose address is
b4d4e8e3
RP
949relative to a particular section (@pxref{SECTIONS}).
950
2c5c0674
RP
951@cindex absolute and relocatable symbols
952@cindex relocatable and absolute symbols
953@cindex symbols, relocatable and absolute
954When a linker expression is evaluated and assigned to a variable, it is
955given either an absolute or a relocatable type. An absolute expression
956type is one in which the symbol contains the value that it will have in
ec40bbb8 957the output file, a relocatable expression type is one in which the
2c5c0674 958value is expressed as a fixed offset from the base of a section.
b4d4e8e3
RP
959
960The type of the expression is controlled by its position in the script
2c5c0674
RP
961file. A symbol assigned within a section definition is created relative
962to the base of the section; a symbol assigned in any other place is
963created as an absolute symbol. Since a symbol created within a
964section definition is relative to the base of the section, it
965will remain relocatable if relocatable output is requested. A symbol
966may be created with an absolute value even when assigned to within a
967section definition by using the absolute assignment function
968@code{ABSOLUTE}. For example, to create an absolute symbol whose address
969is the last byte of an output section named @code{.data}:
b4d4e8e3 970@example
2c5c0674 971SECTIONS@{ @dots{}
b4d4e8e3
RP
972.data :
973 @{
974 *(.data)
975 _edata = ABSOLUTE(.) ;
976 @}
2c5c0674 977@dots{} @}
b4d4e8e3
RP
978@end example
979
2c5c0674
RP
980The linker tries to put off the evaluation of an assignment until all
981the terms in the source expression are known (@pxref{Evaluation}). For
ec40bbb8 982instance, the sizes of sections cannot be known until after allocation,
2c5c0674
RP
983so assignments dependent upon these are not performed until after
984allocation. Some expressions, such as those depending upon the location
985counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the
986result of an expression is required, but the value is not available,
987then an error results. For example, a script like the following
b4d4e8e3 988@example
2c5c0674 989SECTIONS @{ @dots{}
cb70c872 990 text 9+this_isnt_constant :
b4d4e8e3
RP
991 @{ @dots{}
992 @}
2c5c0674 993@dots{} @}
b4d4e8e3 994@end example
2c5c0674
RP
995@kindex Non constant expression
996@noindent
997will cause the error message ``@code{Non constant expression for initial
b4d4e8e3
RP
998address}''.
999
ec40bbb8 1000@node Built-ins
2c5c0674
RP
1001@subsection Built-In Functions
1002@cindex functions in expression language
ec40bbb8 1003The command language includes a number of built-in
2c5c0674
RP
1004functions for use in link script expressions.
1005@table @code
1006@item ABSOLUTE(@var{exp})
1007@kindex ABSOLUTE(@var{exp})
1008@cindex expression, absolute
ec40bbb8
DM
1009Return the absolute (non-relocatable, as opposed to non-negative) value
1010of the expression @var{exp}. Primarily useful to assign an absolute
1011value to a symbol within a section definition, where symbol values are
1012normally section-relative.
2c5c0674
RP
1013
1014@item ADDR(@var{section})
1015@kindex ADDR(@var{section})
1016@cindex section address
ec40bbb8 1017Return the absolute address of the named @var{section}. Your script must
b4d4e8e3 1018previously have defined the location of that section. In the following
ec40bbb8 1019example, @code{symbol_1} and @code{symbol_2} are assigned identical
b4d4e8e3 1020values:
f22eee08 1021@example
2c5c0674 1022SECTIONS@{ @dots{}
cb70c872 1023 .output1 :
f22eee08 1024 @{
2c5c0674
RP
1025 start_of_output_1 = ABSOLUTE(.);
1026 @dots{}
f22eee08 1027 @}
cb70c872 1028 .output :
f22eee08
RP
1029 @{
1030 symbol_1 = ADDR(.output1);
1031 symbol_2 = start_of_output_1;
1032 @}
2c5c0674
RP
1033@dots{} @}
1034@end example
1035
1036@item ALIGN(@var{exp})
1037@kindex ALIGN(@var{exp})
1038@cindex rounding up location counter
ec40bbb8 1039Return the result of the current location counter (@code{.}) aligned to
2c5c0674
RP
1040the next @var{exp} boundary. @var{exp} must be an expression whose
1041value is a power of two. This is equivalent to
1042@example
cb70c872 1043(. + @var{exp} - 1) & ~(@var{exp} - 1)
2c5c0674
RP
1044@end example
1045
1046@code{ALIGN} doesn't change the value of the location counter---it just
1047does arithmetic on it. As an example, to align the output @code{.data}
1048section to the next @code{0x2000} byte boundary after the preceding
1049section and to set a variable within the section to the next
1050@code{0x8000} boundary after the input sections:
1051@example
1052SECTIONS@{ @dots{}
1053 .data ALIGN(0x2000): @{
1054 *(.data)
1055 variable = ALIGN(0x8000);
1056 @}
1057@dots{} @}
1058@end example
1059@noindent
1060The first use of @code{ALIGN} in this example specifies the location of
1061a section because it is used as the optional @var{start} attribute of a
1062section definition (@pxref{Section Options}). The second use simply
1063defines the value of a variable.
1064
1065The built-in @code{NEXT} is closely related to @code{ALIGN}.
1066
1067@item DEFINED(@var{symbol})
1068@kindex DEFINED(@var{symbol})
1069@cindex symbol defaults
ec40bbb8
DM
1070Return 1 if @var{symbol} is in the linker global symbol table and is
1071defined, otherwise return 0. You can use this function to provide default
1072values for symbols. For example, the following command-file fragment shows how
2c5c0674
RP
1073to set a global symbol @code{begin} to the first location in the
1074@code{.text} section---but if a symbol called @code{begin} already
1075existed, its value is preserved:
c8072296 1076@smallexample
2c5c0674 1077SECTIONS@{ @dots{}
cb70c872 1078 .text : @{
2c5c0674
RP
1079 begin = DEFINED(begin) ? begin : . ;
1080 @dots{}
1081 @}
1082@dots{} @}
c8072296 1083@end smallexample
f22eee08 1084
2c5c0674
RP
1085@item NEXT(@var{exp})
1086@kindex NEXT(@var{exp})
1087@cindex unallocated address, next
ec40bbb8
DM
1088Return the next unallocated address that is a multiple of @var{exp}.
1089This function is closely related to @code{ALIGN(@var{exp})}; unless you
2c5c0674 1090use the @code{MEMORY} command to define discontinuous memory for the
ec40bbb8 1091output file, the two functions are equivalent.
2c5c0674
RP
1092
1093@item SIZEOF(@var{section})
1094@kindex SIZEOF(@var{section})
1095@cindex section size
ec40bbb8
DM
1096Return the size in bytes of the named @var{section}, if that section has
1097been allocated. In the following example, @code{symbol_1} and
f22eee08 1098@code{symbol_2} are assigned identical values:
ec40bbb8 1099@c What does it return if the section hasn't been allocated? 0?
f22eee08 1100@example
2c5c0674 1101SECTIONS@{ @dots{}
f22eee08
RP
1102 .output @{
1103 .start = . ;
2c5c0674 1104 @dots{}
cb70c872 1105 .end = . ;
f22eee08 1106 @}
cb70c872 1107 symbol_1 = .end - .start ;
f22eee08 1108 symbol_2 = SIZEOF(.output);
2c5c0674 1109@dots{} @}
f22eee08 1110
f22eee08 1111@end example
b4d4e8e3 1112
2c5c0674
RP
1113@item SIZEOF_HEADERS
1114@kindex SIZEOF_HEADERS
1115@cindex header size
1116@itemx sizeof_headers
1117@kindex sizeof_headers
ec40bbb8 1118Return the size in bytes of the output file's headers. You can use this number
2c5c0674
RP
1119as the start address of the first section, if you choose, to facilitate
1120paging.
1121
1122@end table
1123
ec40bbb8 1124@node MEMORY
b4d4e8e3 1125@section MEMORY Command
2c5c0674
RP
1126@kindex MEMORY
1127@cindex regions of memory
1128@cindex discontinuous memory
1129@cindex allocating memory
ec40bbb8
DM
1130The linker's default configuration permits allocation of all available memory.
1131You can override this configuration by using the @code{MEMORY} command. The
b4d4e8e3
RP
1132@code{MEMORY} command describes the location and size of blocks of
1133memory in the target. By using it carefully, you can describe which
1134memory regions may be used by the linker, and which memory regions it
1135must avoid. The linker does not shuffle sections to fit into the
1136available regions, but does move the requested sections into the correct
1137regions and issue errors when the regions become too full.
1138
ec40bbb8 1139The command files may contain at most one use of the @code{MEMORY}
b4d4e8e3
RP
1140command; however, you can define as many blocks of memory within it as
1141you wish. The syntax is:
c8072296 1142
f22eee08 1143@example
b4d4e8e3
RP
1144MEMORY
1145 @{
cb70c872 1146 @var{name} (@var{attr}) : ORIGIN = @var{origin}, LENGTH = @var{len}
2c5c0674 1147 @dots{}
b4d4e8e3 1148 @}
f22eee08
RP
1149@end example
1150@table @code
1151@item @var{name}
2c5c0674 1152@cindex naming memory regions
f22eee08
RP
1153is a name used internally by the linker to refer to the region. Any
1154symbol name may be used. The region names are stored in a separate
ec40bbb8 1155name space, and will not conflict with symbols, file names or section
b4d4e8e3
RP
1156names. Use distinct names to specify multiple regions.
1157@item (@var{attr})
2c5c0674
RP
1158@cindex memory region attributes
1159is an optional list of attributes, permitted for compatibility with the
246504a5 1160AT&T linker but not used by @code{ld} beyond checking that the
2c5c0674
RP
1161attribute list is valid. Valid attribute lists must be made up of the
1162characters ``@code{LIRWX}''. If you omit the attribute list, you may
1163omit the parentheses around it as well.
f22eee08 1164@item @var{origin}
cb70c872
RP
1165@kindex ORIGIN =
1166@kindex o =
1167@kindex org =
ec40bbb8
DM
1168is the start address of the region in physical memory. It is
1169an expression that must evaluate to a constant before
f22eee08
RP
1170memory allocation is performed. The keyword @code{ORIGIN} may be
1171abbreviated to @code{org} or @code{o}.
1172@item @var{len}
cb70c872
RP
1173@kindex LENGTH =
1174@kindex len =
1175@kindex l =
b4d4e8e3 1176is the size in bytes of the region (an expression).
2c5c0674 1177The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
f22eee08
RP
1178@end table
1179
1180For example, to specify that memory has two regions available for
ec40bbb8 1181allocation---one starting at 0 for 256 kilobytes, and the other
2c5c0674 1182starting at @code{0x40000000} for four megabytes:
f22eee08
RP
1183
1184@example
b4d4e8e3
RP
1185MEMORY
1186 @{
cb70c872
RP
1187 rom : ORIGIN = 0, LENGTH = 256K
1188 ram : org = 0x40000000, l = 4M
b4d4e8e3 1189 @}
f22eee08
RP
1190@end example
1191
b4d4e8e3 1192Once you have defined a region of memory named @var{mem}, you can direct
2c5c0674
RP
1193specific output sections there by using a command ending in
1194@samp{>@var{mem}} within the @code{SECTIONS} command (@pxref{Section
1195Options}). If the combined output sections directed to a region are too
1196big for the region, the linker will issue an error message.
b4d4e8e3 1197
ec40bbb8 1198@node SECTIONS
b4d4e8e3 1199@section SECTIONS Command
2c5c0674 1200@kindex SECTIONS
b4d4e8e3
RP
1201The @code{SECTIONS} command controls exactly where input sections are
1202placed into output sections, their order and to which output sections
1203they are allocated.
1204
1205You may use at most one @code{SECTIONS} command in a commands file,
1206but you can have as many statements within it as you wish. Statements
1207within the @code{SECTIONS} command can do one of three things:
1208@itemize @bullet
1209@item
1210define the entry point;
1211@item
1212assign a value to a symbol;
1213@item
1214describe the placement of a named output section, and what input
1215sections make it up.
1216@end itemize
1217
1218The first two possibilities---defining the entry point, and defining
2c5c0674 1219symbols---can also be done outside the @code{SECTIONS} command:
b4d4e8e3
RP
1220@pxref{Entry Point}, @pxref{Assignment}. They are permitted here as
1221well for your convenience in reading the script, so that symbols or the
1222entry point can be defined at meaningful points in your output-file
1223layout.
f22eee08 1224
b4d4e8e3 1225When no @code{SECTIONS} command is specified, the default action
f22eee08 1226of the linker is to place each input section into an identically named
b4d4e8e3
RP
1227output section in the order that the sections are first encountered in
1228the input files; if all input sections are present in the first file,
1229for example, the order of sections in the output file will match the
1230order in the first input file.
1231
2c5c0674 1232@menu
2d59b2c3
RP
1233* Section Definition:: Section Definitions
1234* Section Contents:: Section Contents
1235* Section Options:: Optional Section Attributes
2c5c0674
RP
1236@end menu
1237
ec40bbb8 1238@node Section Definition
b4d4e8e3 1239@subsection Section Definitions
2c5c0674 1240@cindex section definition
b4d4e8e3
RP
1241The most frequently used statement in the @code{SECTIONS} command is
1242the @dfn{section definition}, which you can use to specify the
1243properties of an output section: its location, alignment, contents,
ec40bbb8 1244fill pattern, and target memory region. Most of
b4d4e8e3
RP
1245these specifications are optional; the simplest form of a section
1246definition is
1247@example
2c5c0674 1248SECTIONS @{ @dots{}
b4d4e8e3
RP
1249@var{secname} : @{
1250 @var{contents}
1251 @}
2c5c0674 1252@dots{} @}
b4d4e8e3 1253@end example
2c5c0674 1254@cindex naming output sections
b4d4e8e3
RP
1255@noindent
1256@var{secname} is the name of the output section, and @var{contents} a
ec40bbb8 1257specification of what goes there---for example, a list of input files or
b4d4e8e3 1258sections of input files. As you might assume, the whitespace shown is
ec40bbb8 1259optional. You do need the colon @samp{:} and the braces @samp{@{@}},
b4d4e8e3
RP
1260however.
1261
1262@var{secname} must meet the constraints of your output format. In
1263formats which only support a limited number of sections, such as
1264@code{a.out}, the name must be one of the names supported by the format
2c5c0674
RP
1265(@code{a.out}, for example, allows only @code{.text}, @code{.data} or
1266@code{.bss}). If the output format supports any number of sections, but
1267with numbers and not names (as is the case for Oasys), the name should be
1268supplied as a quoted numeric string. A section name may consist of any
1269sequence characters, but any name which does not conform to the standard
246504a5 1270@code{ld} symbol name syntax must be quoted.
ec40bbb8 1271@xref{Symbols, , Symbol Names}.
2c5c0674 1272
ec40bbb8 1273@node Section Contents
b4d4e8e3 1274@subsection Section Contents
2c5c0674 1275@cindex contents of a section
b4d4e8e3 1276In a section definition, you can specify the contents of an output section by
ec40bbb8
DM
1277listing particular object files, by listing particular input-file
1278sections, or by a combination of the two. You can also place arbitrary
b4d4e8e3
RP
1279data in the section, and define symbols relative to the beginning of the
1280section.
1281
1282The @var{contents} of a section definition may include any of the
1283following kinds of statement. You can include as many of these as you
1284like in a single section definition, separated from one another by
1285whitespace.
f22eee08 1286
b4d4e8e3 1287@table @code
b4d4e8e3 1288@item @var{filename}
2c5c0674
RP
1289@kindex @var{filename}
1290@cindex input files, section defn
1291@cindex files, including in output sections
b4d4e8e3 1292You may simply name a particular input file to be placed in the current
2c5c0674
RP
1293output section; @emph{all} sections from that file are placed in the
1294current section definition. To specify a list of particular files by
1295name:
f22eee08 1296@example
cb70c872 1297.data : @{ afile.o bfile.o cfile.o @}
f22eee08 1298@end example
2c5c0674
RP
1299@noindent
1300The example also illustrates that multiple statements can be included in
ec40bbb8 1301the contents of a section definition, since each file name is a separate
2c5c0674 1302statement.
f22eee08 1303
b4d4e8e3
RP
1304If the file name has already been mentioned in another section
1305definition, with an explicit section name list, then only those sections
1306which have not yet been allocated are used.
1307
2c5c0674
RP
1308@item @var{filename}( @var{section} )
1309@itemx @var{filename}( @var{section}, @var{section}, @dots{} )
1310@itemx @var{filename}( @var{section} @var{section} @dots{} )
1311@kindex @var{filename}(@var{section})
1312@cindex files and sections, section defn
1313You can name one or more sections from your input files, for
1314insertion in the current output section. If you wish to specify a list
1315of input-file sections inside the parentheses, you may separate the
1316section names by either commas or whitespace.
1317
b4d4e8e3
RP
1318@item * (@var{section})
1319@itemx * (@var{section}, @var{section}, @dots{})
2c5c0674
RP
1320@itemx * (@var{section} @var{section} @dots{}
1321@cindex input sections to output section
1322@kindex *(@var{section})
b4d4e8e3 1323Instead of explicitly naming particular input files in a link control
246504a5 1324script, you can refer to @emph{all} files from the @code{ld} command
ec40bbb8 1325line: use @samp{*} instead of a particular file name before the
b4d4e8e3
RP
1326parenthesized input-file section list.
1327
ec40bbb8 1328For example, to copy sections @code{1} through @code{4} from an Oasys file
b4d4e8e3
RP
1329into the @code{.text} section of an @code{a.out} file, and sections @code{13}
1330and @code{14} into the @code{.data} section:
1331@example
2c5c0674 1332SECTIONS @{
b4d4e8e3
RP
1333 .text :@{
1334 *("1" "2" "3" "4")
1335 @}
f22eee08 1336
b4d4e8e3
RP
1337 .data :@{
1338 *("13" "14")
f22eee08 1339 @}
b4d4e8e3 1340@}
f22eee08
RP
1341@end example
1342
b4d4e8e3
RP
1343If you have already explicitly included some files by name, @samp{*}
1344refers to all @emph{remaining} files---those whose places in the output
1345file have not yet been defined.
1346
1347@item [ @var{section} ]
1348@itemx [ @var{section}, @var{section}, @dots{} ]
1349@itemx [ @var{section} @var{section} @dots{} ]
2c5c0674 1350@kindex [ @var{sections} ]
b4d4e8e3
RP
1351This is an alternate notation to specify named sections from all
1352unallocated input files; its effect is exactly the same as that of
8ddef552 1353@samp{* (@var{section}@dots{})}
b4d4e8e3
RP
1354
1355@item @var{filename}@code{( COMMON )}
d76ae847
RP
1356@itemx ( COMMON )
1357@kindex ( COMMON )
2c5c0674
RP
1358@cindex uninitialized data
1359@cindex commons in output
b4d4e8e3 1360Specify where in your output file to place uninitialized data
d76ae847 1361with this notation. @code{*(COMMON)} by itself refers to all
b4d4e8e3
RP
1362uninitialized data from all input files (so far as it is not yet
1363allocated); @var{filename}@code{(COMMON)} refers to uninitialized data
1364from a particular file. Both are special cases of the general
1365mechanisms for specifying where to place input-file sections:
246504a5 1366@code{ld} permits you to refer to uninitialized data as if it
b4d4e8e3
RP
1367were in an input-file section named @code{COMMON}, regardless of the
1368input file's format.
1369@end table
1370
2c5c0674 1371For example, the following command script arranges the output file into
b4d4e8e3
RP
1372three consecutive sections, named @code{.text}, @code{.data}, and
1373@code{.bss}, taking the input for each from the correspondingly named
1374sections of all the input files:
f22eee08 1375@example
2c5c0674 1376SECTIONS @{
d76ae847
RP
1377 .text : @{ *(.text) @}
1378 .data : @{ *(.data) @}
1379 .bss : @{ *(.bss) *(COMMON) @}
2c5c0674 1380@}
f22eee08 1381@end example
b4d4e8e3
RP
1382
1383The following example reads all of the sections from file @code{all.o}
1384and places them at the start of output section @code{outputa} which
1385starts at location @code{0x10000}. All of section @code{.input1} from
1386file @code{foo.o} follows immediately, in the same output section. All
1387of section @code{.input2} from @code{foo.o} goes into output section
1388@code{outputb}, followed by section @code{.input1} from @code{foo1.o}.
1389All of the remaining @code{.input1} and @code{.input2} sections from any
1390files are written to output section @code{outputc}.
1391
1392@example
2c5c0674 1393SECTIONS @{
b4d4e8e3
RP
1394 outputa 0x10000 :
1395 @{
1396 all.o
1397 foo.o (.input1)
f22eee08 1398 @}
b4d4e8e3
RP
1399 outputb :
1400 @{
1401 foo.o (.input2)
1402 foo1.o (.input1)
f22eee08 1403 @}
b4d4e8e3
RP
1404 outputc :
1405 @{
1406 *(.input1)
1407 *(.input2)
f22eee08 1408 @}
2c5c0674 1409@}
b4d4e8e3
RP
1410@end example
1411
1412There are still more kinds of statements permitted in the contents of
2c5c0674 1413output section definitions. The foregoing statements permitted you to
b4d4e8e3
RP
1414arrange, in your output file, data originating from your input files.
1415You can also place data directly in an output section from the link
1416command script. Most of these additional statements involve
1417expressions; @pxref{Expressions}. Although these statements are shown
1418separately here for ease of presentation, no such segregation is needed
1419within a section definition in the @code{SECTIONS} command; you can
1420intermix them freely with any of the statements we've just described.
f22eee08 1421
b4d4e8e3
RP
1422@table @code
1423@item CREATE_OBJECT_SYMBOLS
2c5c0674
RP
1424@kindex CREATE_OBJECT_SYMBOLS
1425@cindex input filename symbols
1426@cindex filename symbols
ec40bbb8
DM
1427Create a symbol for each input file
1428in the current section, set to the address of the first byte of
f22eee08 1429data written from the input file. For instance, with @code{a.out}
b4d4e8e3
RP
1430files it is conventional to have a symbol for each input file. You can
1431accomplish this by defining the output @code{.text} section as follows:
1432@example
1433SECTIONS @{
1434 .text 0x2020 :
1435 @{
1436 CREATE_OBJECT_SYMBOLS
1437 *(.text)
1438 _etext = ALIGN(0x2000);
f22eee08 1439 @}
2c5c0674
RP
1440 @dots{}
1441@}
f22eee08 1442@end example
b4d4e8e3
RP
1443
1444If @code{objsym} is a file containing this script, and @code{a.o},
1445@code{b.o}, @code{c.o}, and @code{d.o} are four input files with
1446contents like the following---
f22eee08 1447@example
b4d4e8e3
RP
1448/* a.c */
1449
2c5c0674 1450afunction() @{ @}
b4d4e8e3
RP
1451int adata=1;
1452int abss;
1453@end example
f22eee08 1454
b4d4e8e3 1455@noindent
246504a5 1456@samp{ld -M sample a.o b.o c.o d.o} would create a map like this,
b4d4e8e3
RP
1457containing symbols matching the object file names:
1458@example
f22eee08
RP
145900000000 A __DYNAMIC
146000004020 B _abss
146100004000 D _adata
146200002020 T _afunction
146300004024 B _bbss
146400004008 D _bdata
146500002038 T _bfunction
146600004028 B _cbss
146700004010 D _cdata
146800002050 T _cfunction
14690000402c B _dbss
147000004018 D _ddata
147100002068 T _dfunction
147200004020 D _edata
147300004030 B _end
147400004000 T _etext
147500002020 t a.o
147600002038 t b.o
147700002050 t c.o
147800002068 t d.o
f22eee08
RP
1479@end example
1480
b4d4e8e3 1481@item @var{symbol} = @var{expression} ;
2c5c0674 1482@kindex @var{symbol} = @var{expression} ;
b4d4e8e3 1483@itemx @var{symbol} @var{f}= @var{expression} ;
2c5c0674
RP
1484@kindex @var{symbol} @var{f}= @var{expression} ;
1485@var{symbol} is any symbol name (@pxref{Symbols}). ``@var{f}=''
1486refers to any of the operators @code{&= += -= *= /=} which combine
1487arithmetic and assignment.
1488
1489@cindex assignment, in section defn
1490When you assign a value to a symbol within a particular section
1491definition, the value is relative to the beginning of the section
1492(@pxref{Assignment}). If you write
b4d4e8e3 1493@example
2c5c0674 1494SECTIONS @{
b4d4e8e3 1495 abs = 14 ;
2c5c0674 1496 @dots{}
cb70c872 1497 .data : @{ @dots{} rel = 14 ; @dots{} @}
b4d4e8e3 1498 abs2 = 14 + ADDR(.data);
2c5c0674
RP
1499 @dots{}
1500@}
f22eee08 1501@end example
2c5c0674 1502@c FIXME: Try above example!
b4d4e8e3 1503@noindent
ec40bbb8 1504@code{abs} and @code{rel} do not have the same value; @code{rel} has the
b4d4e8e3
RP
1505same value as @code{abs2}.
1506
b4d4e8e3 1507@item BYTE(@var{expression})
2c5c0674 1508@kindex BYTE(@var{expression})
b4d4e8e3 1509@itemx SHORT(@var{expression})
2c5c0674 1510@kindex SHORT(@var{expression})
b4d4e8e3 1511@itemx LONG(@var{expression})
2c5c0674
RP
1512@kindex LONG(@var{expression})
1513@cindex direct output
b4d4e8e3
RP
1514By including one of these three statements in a section definition, you
1515can explicitly place one, two, or four bytes (respectively) at the
ec40bbb8
DM
1516current address of that section.
1517
1518@ifclear SingleFormat
1519Multiple-byte quantities are represented in whatever byte order is
1520appropriate for the output file format (@pxref{BFD}).
1521@end ifclear
b4d4e8e3
RP
1522
1523@item FILL(@var{expression})
2c5c0674
RP
1524@kindex FILL(@var{expression})
1525@cindex holes, filling
1526@cindex unspecified memory
b4d4e8e3
RP
1527Specifies the ``fill pattern'' for the current section. Any otherwise
1528unspecified regions of memory within the section (for example, regions
1529you skip over by assigning a new value to the location counter @samp{.})
1530are filled with the two least significant bytes from the
1531@var{expression} argument. A @code{FILL} statement covers memory
1532locations @emph{after} the point it occurs in the section definition; by
1533including more than one @code{FILL} statement, you can have different
1534fill patterns in different parts of an output section.
1535@end table
1536
ec40bbb8 1537@node Section Options
b4d4e8e3 1538@subsection Optional Section Attributes
2c5c0674 1539@cindex section defn, full syntax
b4d4e8e3
RP
1540Here is the full syntax of a section definition, including all the
1541optional portions:
1542
d76ae847 1543@smallexample
2c5c0674
RP
1544SECTIONS @{
1545@dots{}
d76ae847 1546@var{secname} @var{start} BLOCK(@var{align}) (NOLOAD) : @{ @var{contents} @} =@var{fill} >@var{region}
2c5c0674 1547@dots{}
b4d4e8e3 1548@}
d76ae847 1549@end smallexample
b4d4e8e3
RP
1550
1551@var{secname} and @var{contents} are required. @xref{Section
2c5c0674
RP
1552Definition}, and @pxref{Section Contents} for details on @var{contents}.
1553The remaining elements---@var{start}, @code{BLOCK(@var{align)}},
d76ae847
RP
1554@code{(NOLOAD)} @code{=@var{fill}}, and @code{>@var{region}}---are all
1555optional.
f22eee08 1556
b4d4e8e3
RP
1557@table @code
1558@item @var{start}
2c5c0674
RP
1559@cindex start address, section
1560@cindex section start
1561@cindex section address
b4d4e8e3
RP
1562You can force the output section to be loaded at a specified address by
1563specifying @var{start} immediately following the section name.
1564@var{start} can be represented as any expression. The following
1565example generates section @var{output} at location
1566@code{0x40000000}:
1567@example
1568SECTIONS @{
2c5c0674 1569 @dots{}
b4d4e8e3
RP
1570 output 0x40000000: @{
1571 @dots{}
1572 @}
2c5c0674 1573 @dots{}
b4d4e8e3 1574@}
f22eee08 1575@end example
f22eee08 1576
b4d4e8e3 1577@item BLOCK(@var{align})
2c5c0674
RP
1578@kindex BLOCK(@var{align})
1579@cindex section alignment
1580@cindex aligning sections
ec40bbb8 1581You can include @code{BLOCK()} specification to advance
2c5c0674
RP
1582the location counter @code{.} prior to the beginning of the section, so
1583that the section will begin at the specified alignment. @var{align} is
1584an expression.
f22eee08 1585
d76ae847
RP
1586@item (NOLOAD)
1587@kindex NOLOAD
1588@cindex prevent unnecessary loading
1589Use @samp{(NOLOAD)} to prevent a section from being loaded into memory
1590each time it is accessed. For example, in the script sample below, the
1591@code{ROM} segment is addressed at memory location @samp{0} and does not
1592need to be loaded into each object file:
1593@example
1594SECTIONS @{
1595 ROM 0 (NOLOAD) : @{ @dots{} @}
1596 @dots{}
1597@}
1598@end example
1599
b4d4e8e3 1600@item =@var{fill}
2c5c0674
RP
1601@kindex =@var{fill}
1602@cindex section fill pattern
1603@cindex fill pattern, entire section
ec40bbb8 1604Including
b4d4e8e3 1605@code{=@var{fill}} in a section definition specifies the initial fill
ec40bbb8
DM
1606value for that section.
1607You may use any expression to specify @var{fill}.
1608Any unallocated holes in the current output
b4d4e8e3
RP
1609section when written to the output file will be filled with the two
1610least significant bytes of the value, repeated as necessary. You can
1611also change the fill value with a @code{FILL} statement in the
1612@var{contents} of a section definition.
f22eee08 1613
b4d4e8e3 1614@item >@var{region}
2c5c0674
RP
1615@kindex >@var{region}
1616@cindex section, assigning to memory region
1617@cindex memory regions and sections
1618Assign this section to a previously defined region of memory.
1619@xref{MEMORY}.
f22eee08 1620
f22eee08 1621@end table
b4d4e8e3 1622
ec40bbb8 1623@node Entry Point
b4d4e8e3 1624@section The Entry Point
2c5c0674
RP
1625@kindex ENTRY(@var{symbol})
1626@cindex start of execution
1627@cindex first instruction
b4d4e8e3
RP
1628The linker command language includes a command specifically for
1629defining the first executable instruction in an output file (its
1630@dfn{entry point}). Its argument is a symbol name:
f22eee08 1631@example
b4d4e8e3 1632ENTRY(@var{symbol})
f22eee08 1633@end example
b4d4e8e3
RP
1634
1635Like symbol assignments, the @code{ENTRY} command may be placed either
1636as an independent command in the command file, or among the section
1637definitions within the @code{SECTIONS} command---whatever makes the most
1638sense for your layout.
1639
2c5c0674 1640@cindex entry point, defaults
b4d4e8e3
RP
1641@code{ENTRY} is only one of several ways of choosing the entry point.
1642You may indicate it in any of the following ways (shown in descending
1643order of priority: methods higher in the list override methods lower down).
f22eee08
RP
1644@itemize @bullet
1645@item
ec40bbb8 1646the @samp{-e} @var{entry} command-line option;
f22eee08 1647@item
2c5c0674 1648the @code{ENTRY(@var{symbol}} command in a linker control script;
f22eee08 1649@item
b4d4e8e3 1650the value of the symbol @code{start}, if present;
f22eee08 1651@item
b4d4e8e3 1652the value of the symbol @code{_main}, if present;
f22eee08 1653@item
b4d4e8e3 1654the address of the first byte of the @code{.text} section, if present;
f22eee08 1655@item
b4d4e8e3 1656The address @code{0}.
f22eee08 1657@end itemize
b4d4e8e3 1658
2c5c0674
RP
1659For example, you can use these rules to generate an entry point with an
1660assignment statement: if no symbol @code{start} is defined within your
1661input files, you can simply define it, assigning it an appropriate
1662value---
f22eee08 1663@example
b4d4e8e3 1664start = 0x2020;
f22eee08 1665@end example
b4d4e8e3
RP
1666
1667@noindent
1668The example shows an absolute address, but you can use any expression.
1669For example, if your input object files use some other symbol-name
1670convention for the entry point, you can just assign the value of
1671whatever symbol contains the start address to @code{start}:
f22eee08 1672@example
cb70c872 1673start = other_symbol ;
f22eee08 1674@end example
f22eee08 1675
ec40bbb8 1676@node Other Commands
b4d4e8e3
RP
1677@section Other Commands
1678The command language includes a number of other commands that you can
1679use for specialized purposes. They are similar in purpose to
1680command-line options.
1681
1682@table @code
1683@item FLOAT
2c5c0674 1684@kindex FLOAT
b4d4e8e3 1685@itemx NOFLOAT
2c5c0674
RP
1686@kindex NOFLOAT
1687These keywords were used in some older linkers to request a particular
246504a5 1688math subroutine library. @code{ld} doesn't use the keywords, assuming
2c5c0674
RP
1689instead that any necessary subroutines are in libraries specified using
1690the general mechanisms for linking to archives; but to permit the use of
1691scripts that were written for the older linkers, the keywords
1692@code{FLOAT} and @code{NOFLOAT} are accepted and ignored.
1693
1694@item FORCE_COMMON_ALLOCATION
1695@kindex FORCE_COMMON_ALLOCATION
1696@cindex common allocation
ec40bbb8 1697This command has the same effect as the @samp{-d} command-line option:
2c5c0674 1698to make @code{ld} assign space to common symbols even if a relocatable
ec40bbb8 1699output file is specified (@samp{-r}).
b4d4e8e3 1700
b4d4e8e3 1701@item INPUT ( @var{file}, @var{file}, @dots{} )
2c5c0674 1702@kindex INPUT ( @var{files} )
b4d4e8e3 1703@itemx INPUT ( @var{file} @var{file} @dots{} )
2c5c0674
RP
1704@cindex binary input files
1705Use this command to include binary input files in the link, without
1706including them in a particular section definition. Files specified this
1707way are treated identically to object files listed on the command line.
b4d4e8e3 1708
2c5c0674 1709@ignore
b4d4e8e3 1710@item MAP ( @var{name} )
2c5c0674
RP
1711@kindex MAP ( @var{name} )
1712@c MAP(...) appears to look for an F in the arg, ignoring all other
1713@c chars; if it finds one, it sets "map_option_f" to true. But nothing
1714@c checks map_option_f. Apparently a stub for the future...
1715@end ignore
b4d4e8e3
RP
1716
1717@item OUTPUT ( @var{filename} )
2c5c0674
RP
1718@kindex OUTPUT ( @var{filename} )
1719@cindex naming the output file
d76ae847
RP
1720Use this command to name the link output file @var{filename}. The
1721effect of @code{OUTPUT(@var{filename})} is identical to the effect of
ec40bbb8 1722@w{@samp{-o @var{filename}}}, and whichever is encountered last will
2c5c0674
RP
1723control the name actually used to name the output file. In particular,
1724you can use this command to supply a default output-file name other than
d76ae847 1725@code{a.out}.
2c5c0674 1726
ec40bbb8 1727@ifclear SingleFormat
2c5c0674
RP
1728@item OUTPUT_ARCH ( @var{bfdname} )
1729@kindex OUTPUT_ARCH ( @var{bfdname} )
1730@cindex machine architecture, output
1731Specify a particular output machine architecture, with one of the names
1732used by the BFD back-end routines (@pxref{BFD}). This command is often
1733unnecessary; the architecture is most often set implicitly by either the
1734system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT}
ec40bbb8 1735command.
2c5c0674
RP
1736
1737@item OUTPUT_FORMAT ( @var{bfdname} )
1738@kindex OUTPUT_FORMAT ( @var{bfdname} )
1739@cindex format, output file
1740Specify a particular output format, with one of the names used by the
1741BFD back-end routines (@pxref{BFD}). This selection will only affect
1742the output file; the related command @code{TARGET} affects primarily
ec40bbb8
DM
1743input files.
1744@end ifclear
2c5c0674
RP
1745
1746@item SEARCH_DIR ( @var{path} )
1747@kindex SEARCH_DIR ( @var{path} )
1748@cindex path for libraries
1749@cindex search path, libraries
246504a5 1750Add @var{path} to the list of paths where @code{ld} looks for
2c5c0674 1751archive libraries. @code{SEARCH_DIR(@var{path})} has the same
ec40bbb8 1752effect as @samp{-L@var{path}} on the command line.
2c5c0674
RP
1753
1754@item STARTUP ( @var{filename} )
1755@kindex STARTUP ( @var{filename} )
1756@cindex first input file
1757Ensure that @var{filename} is the first input file used in the link
1758process.
b4d4e8e3 1759
ec40bbb8 1760@ifclear SingleFormat
b4d4e8e3 1761@item TARGET ( @var{format} )
2c5c0674
RP
1762@cindex input file format
1763@kindex TARGET ( @var{format} )
1764Change the input-file object code format (like the command-line option
ec40bbb8 1765@samp{-b} or its synonym @samp{-format}). The argument @var{format} is
2c5c0674 1766one of the strings used by BFD to name binary formats. In the current
246504a5 1767@code{ld} implementation, if @code{TARGET} is specified but
2c5c0674 1768@code{OUTPUT_FORMAT} is not, the last @code{TARGET} argument is also
246504a5 1769used as the default format for the @code{ld} output file.
ec40bbb8 1770@xref{BFD}.
2c5c0674
RP
1771
1772@kindex GNUTARGET
246504a5 1773If you don't use the @code{TARGET} command, @code{ld} uses the value of
2c5c0674 1774the environment variable @code{GNUTARGET}, if available, to select the
246504a5 1775output file format. If that variable is also absent, @code{ld} uses
2c5c0674 1776the default format configured for your machine in the BFD libraries.
ec40bbb8 1777@end ifclear
b4d4e8e3
RP
1778@end table
1779
ec40bbb8
DM
1780@ifset GENERIC
1781@node Machine Dependent
1c48127e
RP
1782@chapter Machine Dependent Features
1783
1784@cindex machine dependencies
246504a5
RP
1785@code{ld} has additional features on some platforms; the following
1786sections describe them. Machines where @code{ld} has no additional
1c48127e
RP
1787functionality are not listed.
1788
1789@menu
246504a5
RP
1790* H8/300:: @code{ld} and the H8/300
1791* i960:: @code{ld} and the Intel 960 family
1c48127e 1792@end menu
ec40bbb8
DM
1793@end ifset
1794
1795@c FIXME! This could use @up/@down, but there seems to be a conflict
1796@c between those and node-defaulting.
1797@ifset H8300
1798@ifclear GENERIC
1799@up
1800@end ifclear
1801@node H8/300
246504a5 1802@section @code{ld} and the H8/300
1c48127e
RP
1803
1804@cindex H8/300 support
246504a5 1805For the H8/300, @code{ld} can perform these global optimizations when
1c48127e
RP
1806you specify the @samp{-relax} command-line option.
1807
1808@table @emph
1809@item relaxing address modes
d76ae847 1810@cindex relaxing on H8/300
246504a5 1811@code{ld} finds all @code{jsr} and @code{jmp} instructions whose
1c48127e
RP
1812targets are within eight bits, and turns them into eight-bit
1813program-counter relative @code{bsr} and @code{bra} instructions,
1814respectively.
1815
1816@item synthesizing instructions
d76ae847 1817@cindex synthesizing on H8/300
1c48127e 1818@c FIXME: specifically mov.b, or any mov instructions really?
246504a5 1819@code{ld} finds all @code{mov.b} instructions which use the
1c48127e
RP
1820sixteen-bit absolute address form, but refer to the top
1821page of memory, and changes them to use the eight-bit address form.
1822(That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
1823@samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
1824top page of memory).
1825@end table
ec40bbb8
DM
1826@ifclear GENERIC
1827@down
1828@end ifclear
1829@end ifset
1830
1831@ifset I960
1832@ifclear GENERIC
1833@up
1834@end ifclear
1835@node i960
246504a5 1836@section @code{ld} and the Intel 960 family
1c48127e
RP
1837
1838@cindex i960 support
d76ae847 1839
1c48127e
RP
1840You can use the @samp{-A@var{architecture}} command line option to
1841specify one of the two-letter names identifying members of the 960
1842family; the option specifies the desired output target, and warns of any
1843incompatible instructions in the input files. It also modifies the
1844linker's search strategy for archive libraries, to support the use of
1845libraries specific to each particular architecture, by including in the
1846search loop names suffixed with the string identifying the architecture.
1847
246504a5 1848For example, if your @code{ld} command line included @w{@samp{-ACA}} as
1c48127e 1849well as @w{@samp{-ltry}}, the linker would look (in its built-in search
ec40bbb8 1850paths, and in any paths you specify with @samp{-L}) for a library with
1c48127e 1851the names
ec40bbb8 1852
1c48127e
RP
1853@example
1854try
1855libtry.a
1856tryca
1857libtryca.a
1858@end example
ec40bbb8 1859
1c48127e
RP
1860@noindent
1861The first two possibilities would be considered in any event; the last
1862two are due to the use of @w{@samp{-ACA}}.
1863
ec40bbb8 1864You can meaningfully use @samp{-A} more than once on a command line, since
1c48127e 1865the 960 architecture family allows combination of target architectures; each
ec40bbb8 1866use will add another pair of name variants to search for when @w{@samp{-l}}
1c48127e 1867specifies a library.
ec40bbb8
DM
1868@ifclear GENERIC
1869@down
1870@end ifclear
1871@end ifset
1c48127e 1872
ec40bbb8
DM
1873@ifclear SingleFormat
1874@node BFD
f22eee08
RP
1875@chapter BFD
1876
2c5c0674
RP
1877@cindex back end
1878@cindex object file management
1879The linker accesses object and archive files using the BFD libraries.
1880These libraries allow the linker to use the same routines to operate on
1881object files whatever the object file format. A different object file
1882format can be supported simply by creating a new BFD back end and adding
1c48127e
RP
1883it to the library. You can use @code{objdump -i}
1884(@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
1885list all the formats available for each architecture under BFD. This
1886was the list of formats, and of architectures supported for each format,
1887as of the time this manual was prepared:
2c5c0674
RP
1888@cindex formats available
1889@cindex architectures available
2c5c0674 1890@example
1c48127e
RP
1891BFD header file version 0.18
1892a.out-i386
1893 (header big endian, data big endian)
1894 m68k:68020
1895 a29k
1896 sparc
1897 i386
1898a.out-sunos-big
1899 (header big endian, data big endian)
1900 m68k:68020
1901 a29k
1902 sparc
1903 i386
1904b.out.big
1905 (header big endian, data little endian)
1906 i960:core
1907b.out.little
1908 (header little endian, data little endian)
1909 i960:core
1910coff-a29k-big
1911 (header big endian, data big endian)
1912 a29k
1913coff-h8300
1914 (header big endian, data big endian)
1915 H8/300
1916coff-i386
1917 (header little endian, data little endian)
1918 i386
1919coff-Intel-big
1920 (header big endian, data little endian)
1921 i960:core
1922coff-Intel-little
1923 (header little endian, data little endian)
1924 i960:core
1925coff-m68k
1926 (header big endian, data big endian)
1927 m68k:68020
1928coff-m88kbcs
1929 (header big endian, data big endian)
1930 m88k:88100
1931ecoff-bigmips
1932 (header big endian, data big endian)
1933 mips
1934ecoff-littlemips
1935 (header little endian, data little endian)
1936 mips
1937elf-big
1938 (header big endian, data big endian)
1939 m68k:68020
1940 vax
1941 i960:core
1942 a29k
1943 sparc
1944 mips
1945 i386
1946 m88k:88100
1947 H8/300
1948 rs6000:6000
1949elf-little
1950 (header little endian, data little endian)
1951 m68k:68020
1952 vax
1953 i960:core
1954 a29k
1955 sparc
1956 mips
1957 i386
1958 m88k:88100
1959 H8/300
1960 rs6000:6000
1961ieee
1962 (header big endian, data big endian)
1963 m68k:68020
1964 vax
1965 i960:core
1966 a29k
1967 sparc
1968 mips
1969 i386
1970 m88k:88100
1971 H8/300
1972 rs6000:6000
1973srec
1974 (header big endian, data big endian)
1975 m68k:68020
1976 vax
1977 i960:core
1978 a29k
1979 sparc
1980 mips
1981 i386
1982 m88k:88100
1983 H8/300
1984 rs6000:6000
2c5c0674 1985@end example
f22eee08 1986
2c5c0674
RP
1987@cindex BFD requirements
1988@cindex requirements for BFD
1989As with most implementations, BFD is a compromise between
f22eee08 1990several conflicting requirements. The major factor influencing
2c5c0674
RP
1991BFD design was efficiency: any time used converting between
1992formats is time which would not have been spent had BFD not
f22eee08 1993been involved. This is partly offset by abstraction payback; since
2c5c0674 1994BFD simplifies applications and back ends, more time and care
f22eee08
RP
1995may be spent optimizing algorithms for a greater speed.
1996
2c5c0674
RP
1997One minor artifact of the BFD solution which you should bear in
1998mind is the potential for information loss. There are two places where
ec40bbb8 1999useful information can be lost using the BFD mechanism: during
2c5c0674
RP
2000conversion and during output. @xref{BFD information loss}.
2001
2002@menu
2d59b2c3
RP
2003* BFD outline:: How it works: an outline of BFD
2004* BFD information loss:: Information Loss
2005* Mechanism:: Mechanism
2c5c0674 2006@end menu
f22eee08 2007
ec40bbb8 2008@node BFD outline
b4d4e8e3 2009@section How it works: an outline of BFD
2c5c0674
RP
2010@cindex opening object files
2011When an object file is opened, BFD subroutines automatically
b4d4e8e3
RP
2012determine the format of the input object file, and build a descriptor in
2013memory with pointers to routines that will be used to access elements of
2014the object file's data structures.
f22eee08 2015
ec40bbb8 2016As different information from the the object files is required,
2c5c0674 2017BFD reads from different sections of the file and processes them.
ec40bbb8 2018For example, a very common operation for the linker is processing symbol
2c5c0674 2019tables. Each BFD back end provides a routine for converting
b4d4e8e3
RP
2020between the object file's representation of symbols and an internal
2021canonical format. When the linker asks for the symbol table of an object
ec40bbb8 2022file, it calls through the memory pointer to the BFD
b4d4e8e3
RP
2023back end routine which reads and converts the table into a canonical
2024form. The linker then operates upon the common form. When the link is
2025finished and the linker writes the symbol table of the output file,
2c5c0674 2026another BFD back end routine is called which takes the newly
b4d4e8e3
RP
2027created symbol table and converts it into the chosen output format.
2028
ec40bbb8 2029@node BFD information loss
b4d4e8e3
RP
2030@section Information Loss
2031@emph{Information can be lost during output.} The output formats
2c5c0674 2032supported by BFD do not provide identical facilities, and
b4d4e8e3
RP
2033information which may be described in one form has nowhere to go in
2034another format. One example of this is alignment information in
2035@code{b.out}. There is nowhere in an @code{a.out} format file to store
2036alignment information on the contained data, so when a file is linked
2037from @code{b.out} and an @code{a.out} image is produced, alignment
2038information will not propagate to the output file. (The linker will
2039still use the alignment information internally, so the link is performed
2040correctly).
f22eee08
RP
2041
2042Another example is COFF section names. COFF files may contain an
2043unlimited number of sections, each one with a textual section name. If
ec40bbb8
DM
2044the target of the link is a format which does not have many sections (e.g.,
2045@code{a.out}) or has sections without names (e.g., the Oasys format) the
b4d4e8e3
RP
2046link cannot be done simply. You can circumvent this problem by
2047describing the desired input-to-output section mapping with the command
2048language.
2049
2c5c0674
RP
2050@emph{Information can be lost during canonicalization.} The BFD
2051internal canonical form of the external formats is not exhaustive; there
2052are structures in input formats for which there is no direct
2053representation internally. This means that the BFD back ends
2054cannot maintain all possible data richness through the transformation
2055between external to internal and back to external formats.
f22eee08
RP
2056
2057This limitation is only a problem when using the linker to read one
2c5c0674
RP
2058format and write another. Each BFD back end is responsible for
2059maintaining as much data as possible, and the internal BFD
2060canonical form has structures which are opaque to the BFD core,
f22eee08 2061and exported only to the back ends. When a file is read in one format,
2c5c0674 2062the canonical form is generated for BFD and the linker. At the
ec40bbb8 2063same time, the back end saves away any information which would otherwise
2c5c0674 2064be lost. If the data is then written back in the same format, the back
b4d4e8e3 2065end routine will be able to use the canonical form provided by the
2c5c0674 2066BFD core as well as the information it prepared earlier. Since
ec40bbb8
DM
2067there is a great deal of commonality between back ends,
2068there is no information lost when
b4d4e8e3
RP
2069linking big endian COFF to little endian COFF, or from @code{a.out} to
2070@code{b.out}. When a mixture of formats is linked, the information is
2071only lost from the files whose format differs from the destination.
2072
ec40bbb8 2073@node Mechanism
f22eee08 2074@section Mechanism
ec40bbb8 2075The greatest potential for loss of information occurs when there is the least
b4d4e8e3 2076overlap between the information provided by the source format, that
ec40bbb8 2077stored by the canonical format, and that needed by the
b4d4e8e3 2078destination format. A brief description of the canonical form may help
ec40bbb8 2079you understand which kinds of data you can count on preserving across
b4d4e8e3 2080conversions.
2c5c0674
RP
2081@cindex BFD canonical format
2082@cindex internal object-file format
b4d4e8e3
RP
2083
2084@table @emph
2085@item files
ec40bbb8 2086Information on target machine architecture, particular implementation,
b4d4e8e3 2087and format type are stored on a per-file basis. Other information
ec40bbb8
DM
2088includes a demand pagable bit and a write protected bit.
2089Information like Unix magic numbers is not stored here---only the magic
2090numbers' meaning, so a @code{ZMAGIC} file would have both the demand pagable
b4d4e8e3
RP
2091bit and the write protected text bit set.
2092
2c5c0674
RP
2093The byte order of the target is stored on a per-file basis, so that big-
2094and little-endian object files may be linked with one another.
b4d4e8e3
RP
2095
2096@item sections
f22eee08 2097Each section in the input file contains the name of the section, the
ec40bbb8 2098original address in the object file, various options, size and alignment
2c5c0674 2099information and pointers into other BFD data structures.
b4d4e8e3
RP
2100
2101@item symbols
f22eee08 2102Each symbol contains a pointer to the object file which originally
ec40bbb8 2103defined it, its name, its value, and various option bits. When a
2c5c0674
RP
2104BFD back end reads in a symbol table, the back end relocates all
2105symbols to make them relative to the base of the section where they were
ec40bbb8
DM
2106defined. Doing this ensures that each symbol points to its containing
2107section. Each symbol also has a varying amount of hidden
2c5c0674
RP
2108private data for the BFD back end. Since the symbol points to the
2109original file, the private data format for that symbol is accessible.
246504a5 2110@code{ld} can operate on a collection of symbols of wildly different
2c5c0674 2111formats without problems.
f22eee08
RP
2112
2113Normal global and simple local symbols are maintained on output, so an
b4d4e8e3
RP
2114output file (no matter its format) will retain symbols pointing to
2115functions and to global, static, and common variables. Some symbol
ec40bbb8 2116information is not worth retaining; in @code{a.out}, type information is
b4d4e8e3
RP
2117stored in the symbol table as long symbol names. This information would
2118be useless to most COFF debuggers and may be thrown away with
2119appropriate command line switches. (The GNU debugger @code{gdb} does
2120support @code{a.out} style debugging information in COFF).
f22eee08
RP
2121
2122There is one word of type information within the symbol, so if the
ec40bbb8 2123format supports symbol type information within symbols (for example, COFF,
f22eee08 2124IEEE, Oasys) and the type is simple enough to fit within one word
ec40bbb8 2125(nearly everything but aggregates), the information will be preserved.
f22eee08
RP
2126
2127@item relocation level
2c5c0674 2128Each canonical BFD relocation record contains a pointer to the symbol to
f22eee08 2129relocate to, the offset of the data to relocate, the section the data
ec40bbb8
DM
2130is in, and a pointer to a relocation type descriptor. Relocation is
2131performed by passing messages through the relocation type
2132descriptor and the symbol pointer. Therefore, relocations can be performed
2133on output data using a relocation method that is only available in one of the
f22eee08
RP
2134input formats. For instance, Oasys provides a byte relocation format.
2135A relocation record requesting this relocation type would point
2136indirectly to a routine to perform this, so the relocation may be
2137performed on a byte being written to a COFF file, even though 68k COFF
2138has no such relocation type.
1c48127e 2139@c FIXME why specific reference to 68K above?
f22eee08
RP
2140
2141@item line numbers
2c5c0674
RP
2142Object formats can contain, for debugging purposes, some form of mapping
2143between symbols, source line numbers, and addresses in the output file.
2144These addresses have to be relocated along with the symbol information.
b4d4e8e3
RP
2145Each symbol with an associated list of line number records points to the
2146first record of the list. The head of a line number list consists of a
ec40bbb8 2147pointer to the symbol, which allows finding out the address of the
b4d4e8e3
RP
2148function whose line number is being described. The rest of the list is
2149made up of pairs: offsets into the section and line numbers. Any format
2150which can simply derive this information can pass it successfully
f22eee08
RP
2151between formats (COFF, IEEE and Oasys).
2152@end table
ec40bbb8 2153@end ifclear
f22eee08 2154
ec40bbb8 2155@node MRI
2d59b2c3
RP
2156@appendix MRI Compatible Script Files
2157@cindex MRI compatibility
2158To aid users making the transition to @sc{gnu} @code{ld} from the MRI
2159linker, @code{ld} can use MRI compatible linker scripts as an
2160alternative to the more general-purpose linker scripting language
2161described in @ref{Commands,,Command Language}. MRI compatible linker
2162scripts have a much simpler command set than the scripting language
2163otherwise used with @code{ld}. @sc{gnu} @code{ld} supports the most
2164commonly used MRI linker commands; these commands are described here.
2165
2166You can specify a file containing an MRI-compatible script using the
2167@samp{-c} command-line option.
2168
2169Each command in an MRI-compatible script occupies its own line; each
2170command line starts with the keyword that identifies the command (though
2171blank lines are also allowed for punctuation). If a line of an
2172MRI-compatible script begins with an unrecognized keyword, @code{ld}
2173issues a warning message, but continues processing the script.
2174
2175Lines beginning with @samp{*} are comments.
2176
2177You can write these commands using all upper-case letters, or all
2178lower case; for example, @samp{chip} is the same as @samp{CHIP}.
2179The following list shows only the upper-case form of each command.
2180
2181@table @code
2182@item ABSOLUTE @var{secname}
2183@item ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
2184@cindex @code{ABSOLUTE} (MRI)
2185Normally, @code{ld} includes in the output file all sections from all
2186the input files. However, in an MRI-compatible script, you can use the
2187@code{ABSOLUTE} command to restrict the sections that will be present in
2188your output program. If the @code{ABSOLUTE} command is used at all in a
2189script, then only the sections named explicitly in @code{ABSOLUTE}
2190commands will appear in the linker output. You can still use other
2191input sections (whatever you select on the command line, or using
7b015547 2192@code{LOAD}) to resolve addresses in the output file.
2d59b2c3
RP
2193
2194@item ALIAS @var{out-secname}, @var{in-secname}
2195@cindex @code{ALIAS} (MRI)
2196Use this command to place the data from input section @var{in-secname}
2197in a section called @var{out-secname} in the linker output file.
2198
2199@var{in-secname} may be an integer.
2200
2201@item BASE @var{expression}
2202@cindex @code{BASE} (MRI)
2203Use the value of @var{expression} as the lowest address (other than
2204absolute addresses) in the output file.
2205
2206@item CHIP @var{expression}
2207@itemx CHIP @var{expression}, @var{expression}
2208@cindex @code{CHIP} (MRI)
ec40bbb8 2209This command does nothing; it is accepted only for compatibility.
2d59b2c3
RP
2210
2211@item END
2212@cindex @code{END} (MRI)
2213This command does nothing whatever; it's only accepted for compatibility.
2214
2215@item FORMAT @var{output-format}
2216@cindex @code{FORMAT} (MRI)
2217Similar to the @code{OUTPUT_FORMAT} command in the more general linker
2218language, but restricted to one of these output formats:
2219@enumerate
2220@item
2221S-records, if @var{output-format} is @samp{S}
2222
2223@item
2224IEEE, if @var{output-format} is @samp{IEEE}
2225
2226@item
2227COFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is
2228@samp{COFF}
2229@end enumerate
2230
8ddef552 2231@item LIST @var{anything}@dots{}
2d59b2c3
RP
2232@cindex @code{LIST} (MRI)
2233Print (to the standard output file) a link map, as produced by the
2234@code{ld} command-line option @samp{-M}.
2235
ec40bbb8
DM
2236The keyword @code{LIST} may be followed by anything on the
2237same line, with no change in its effect.
2d59b2c3
RP
2238
2239@item LOAD @var{filename}
2240@item LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
2241@cindex @code{LOAD} (MRI)
2242Include one or more object file @var{filename} in the link; this has the
2243same effect as specifying @var{filename} directly on the @code{ld}
2244command line.
2245
2246@item NAME @var{output-name}
2247@cindex @code{NAME} (MRI)
2248@var{output-name} is the name for the program produced by @code{ld}; the
2249MRI-compatible command @code{NAME} is equivalent to the command-line
2250option @samp{-o} or the general script language command @code{OUTPUT}.
2251
2252@item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
2253@itemx ORDER @var{secname} @var{secname} @var{secname}
2254@cindex @code{ORDER} (MRI)
ec40bbb8
DM
2255Normally, @code{ld} orders the sections in its output file in the
2256order in which they first appear in the input files. In an MRI-compatible
2257script, you can override this ordering with the @code{ORDER} command. The
2d59b2c3
RP
2258sections you list with @code{ORDER} will appear first in your output
2259file, in the order specified.
2260
2261@item PUBLIC @var{name}=@var{expression}
2262@itemx PUBLIC @var{name},@var{expression}
2263@itemx PUBLIC @var{name} @var{expression}
2264@cindex @code{PUBLIC} (MRI)
ec40bbb8 2265Supply a value (@var{expression}) for external symbol
2d59b2c3
RP
2266@var{name} used in the linker input files.
2267
2268@item SECT @var{secname}, @var{expression}
2269@itemx SECT @var{secname}=@var{expression}
2270@itemx SECT @var{secname} @var{expression}
2271@cindex @code{SECT} (MRI)
2272You can use any of these three forms of the @code{SECT} command to
2273specify the start address (@var{expression}) for section @var{secname}.
2274If you have more than one @code{SECT} statement for the same
2275@var{secname}, only the @emph{first} sets the start address.
2276@end table
2277
2278
ec40bbb8 2279@node Index
2c5c0674
RP
2280@unnumbered Index
2281
2282@printindex cp
2283
2284@tex
2285% I think something like @colophon should be in texinfo. In the
2286% meantime:
2287\long\def\colophon{\hbox to0pt{}\vfill
2288\centerline{The body of this manual is set in}
2289\centerline{\fontname\tenrm,}
2290\centerline{with headings in {\bf\fontname\tenbf}}
2291\centerline{and examples in {\tt\fontname\tentt}.}
2292\centerline{{\it\fontname\tenit\/} and}
2293\centerline{{\sl\fontname\tensl\/}}
2294\centerline{are used for emphasis.}\vfill}
2295\page\colophon
2296% Blame: pesch@cygnus.com, 28mar91.
2297@end tex
2298
2299
b4d4e8e3 2300@contents
f22eee08
RP
2301@bye
2302
2303