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