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