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