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