]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/ld.texinfo
Fix the behaviour of --allow-shlib-undefined, so that it does what it claims
[thirdparty/binutils-gdb.git] / ld / ld.texinfo
CommitLineData
252b5132
RH
1\input texinfo
2@setfilename ld.info
a2b64bed 3@c Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
9c8ebd6a 4@c 2001, 2002, 2003 Free Software Foundation, Inc.
252b5132
RH
5@syncodeindex ky cp
6@include configdoc.texi
7@c (configdoc.texi is generated by the Makefile)
8@include ldver.texi
9
10@c @smallbook
11
ff5dcc92
SC
12@macro gcctabopt{body}
13@code{\body\}
14@end macro
15
0285c67d
NC
16@c man begin NAME
17@ifset man
18@c Configure for the generation of man pages
19@set UsesEnvVars
20@set GENERIC
21@set A29K
22@set ARC
23@set ARM
24@set D10V
25@set D30V
26@set H8/300
27@set H8/500
28@set HPPA
29@set I370
30@set I80386
31@set I860
32@set I960
33@set M32R
34@set M68HC11
35@set M680X0
36@set MCORE
37@set MIPS
3c3bdf30 38@set MMIX
2469cfa2 39@set MSP430
0285c67d
NC
40@set PDP11
41@set PJ
42@set SH
43@set SPARC
44@set C54X
45@set V850
46@set VAX
2ca22b03 47@set WIN32
0285c67d
NC
48@end ifset
49@c man end
50
252b5132
RH
51@ifinfo
52@format
53START-INFO-DIR-ENTRY
54* Ld: (ld). The GNU linker.
55END-INFO-DIR-ENTRY
56@end format
57@end ifinfo
58
59@ifinfo
60This file documents the @sc{gnu} linker LD version @value{VERSION}.
61
62bf86b4 62Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000,
9c8ebd6a 632001, 2002, 2003 Free Software Foundation, Inc.
252b5132 64
252b5132 65@ignore
cf055d54
NC
66
67Permission is granted to copy, distribute and/or modify this document
68under the terms of the GNU Free Documentation License, Version 1.1
69or any later version published by the Free Software Foundation;
70with no Invariant Sections, with no Front-Cover Texts, and with no
71Back-Cover Texts. A copy of the license is included in the
72section entitled "GNU Free Documentation License".
73
252b5132
RH
74Permission is granted to process this file through Tex and print the
75results, provided the printed document carries copying permission
76notice identical to this one except for the removal of this paragraph
77(this paragraph not being relevant to the printed manual).
78
79@end ignore
80@end ifinfo
81@iftex
82@finalout
83@setchapternewpage odd
84@settitle Using LD, the GNU linker
85@titlepage
86@title Using ld
87@subtitle The GNU linker
88@sp 1
89@subtitle @code{ld} version 2
90@subtitle Version @value{VERSION}
91@author Steve Chamberlain
92@author Ian Lance Taylor
252b5132
RH
93@page
94
95@tex
96{\parskip=0pt
704c465c
NC
97\hfill Red Hat Inc\par
98\hfill nickc\@credhat.com, doc\@redhat.com\par
252b5132
RH
99\hfill {\it Using LD, the GNU linker}\par
100\hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
101}
102\global\parindent=0pt % Steve likes it this way.
103@end tex
104
105@vskip 0pt plus 1filll
0285c67d 106@c man begin COPYRIGHT
9c8ebd6a
DJ
107Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001,
1082002, 2003 Free Software Foundation, Inc.
252b5132 109
0285c67d
NC
110Permission is granted to copy, distribute and/or modify this document
111under the terms of the GNU Free Documentation License, Version 1.1
112or any later version published by the Free Software Foundation;
113with no Invariant Sections, with no Front-Cover Texts, and with no
114Back-Cover Texts. A copy of the license is included in the
115section entitled "GNU Free Documentation License".
116@c man end
252b5132 117
252b5132
RH
118@end titlepage
119@end iftex
120@c FIXME: Talk about importance of *order* of args, cmds to linker!
121
84ec0e6d 122@ifnottex
252b5132
RH
123@node Top
124@top Using ld
125This file documents the @sc{gnu} linker ld version @value{VERSION}.
126
cf055d54
NC
127This document is distributed under the terms of the GNU Free
128Documentation License. A copy of the license is included in the
129section entitled "GNU Free Documentation License".
130
252b5132
RH
131@menu
132* Overview:: Overview
133* Invocation:: Invocation
134* Scripts:: Linker Scripts
135@ifset GENERIC
136* Machine Dependent:: Machine Dependent Features
137@end ifset
138@ifclear GENERIC
139@ifset H8300
140* H8/300:: ld and the H8/300
141@end ifset
142@ifset Hitachi
143* Hitachi:: ld and other Hitachi micros
144@end ifset
145@ifset I960
146* i960:: ld and the Intel 960 family
147@end ifset
74459f0e
TW
148@ifset TICOFF
149* TI COFF:: ld and the TI COFF
150@end ifset
2ca22b03
NC
151@ifset WIN32
152* Win32:: ld and WIN32 (cygwin/mingw)
153@end ifset
252b5132
RH
154@end ifclear
155@ifclear SingleFormat
156* BFD:: BFD
157@end ifclear
158@c Following blank line required for remaining bug in makeinfo conds/menus
159
160* Reporting Bugs:: Reporting Bugs
161* MRI:: MRI Compatible Script Files
704c465c 162* GNU Free Documentation License:: GNU Free Documentation License
252b5132
RH
163* Index:: Index
164@end menu
84ec0e6d 165@end ifnottex
252b5132
RH
166
167@node Overview
168@chapter Overview
169
170@cindex @sc{gnu} linker
171@cindex what is this?
0285c67d 172
0879a67a 173@ifset man
0285c67d 174@c man begin SYNOPSIS
ff5dcc92 175ld [@b{options}] @var{objfile} @dots{}
0285c67d
NC
176@c man end
177
178@c man begin SEEALSO
179ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
180the Info entries for @file{binutils} and
181@file{ld}.
182@c man end
183@end ifset
184
185@c man begin DESCRIPTION
186
ff5dcc92 187@command{ld} combines a number of object and archive files, relocates
252b5132 188their data and ties up symbol references. Usually the last step in
ff5dcc92 189compiling a program is to run @command{ld}.
252b5132 190
ff5dcc92 191@command{ld} accepts Linker Command Language files written in
252b5132
RH
192a superset of AT&T's Link Editor Command Language syntax,
193to provide explicit and total control over the linking process.
194
0285c67d
NC
195@ifset man
196@c For the man only
197This man page does not describe the command language; see the
ff5dcc92 198@command{ld} entry in @code{info}, or the manual
0285c67d
NC
199ld: the GNU linker, for full details on the command language and
200on other aspects of the GNU linker.
201@end ifset
202
252b5132 203@ifclear SingleFormat
ff5dcc92
SC
204This version of @command{ld} uses the general purpose BFD libraries
205to operate on object files. This allows @command{ld} to read, combine, and
252b5132
RH
206write object files in many different formats---for example, COFF or
207@code{a.out}. Different formats may be linked together to produce any
208available kind of object file. @xref{BFD}, for more information.
209@end ifclear
210
211Aside from its flexibility, the @sc{gnu} linker is more helpful than other
212linkers in providing diagnostic information. Many linkers abandon
213execution immediately upon encountering an error; whenever possible,
ff5dcc92 214@command{ld} continues executing, allowing you to identify other errors
252b5132
RH
215(or, in some cases, to get an output file in spite of the error).
216
0285c67d
NC
217@c man end
218
252b5132
RH
219@node Invocation
220@chapter Invocation
221
0285c67d
NC
222@c man begin DESCRIPTION
223
ff5dcc92 224The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
252b5132
RH
225and to be as compatible as possible with other linkers. As a result,
226you have many choices to control its behavior.
227
0285c67d
NC
228@c man end
229
252b5132
RH
230@ifset UsesEnvVars
231@menu
232* Options:: Command Line Options
233* Environment:: Environment Variables
234@end menu
235
236@node Options
237@section Command Line Options
238@end ifset
239
240@cindex command line
241@cindex options
0285c67d
NC
242
243@c man begin OPTIONS
244
252b5132
RH
245The linker supports a plethora of command-line options, but in actual
246practice few of them are used in any particular context.
247@cindex standard Unix system
ff5dcc92 248For instance, a frequent use of @command{ld} is to link standard Unix
252b5132
RH
249object files on a standard, supported Unix system. On such a system, to
250link a file @code{hello.o}:
251
252@smallexample
253ld -o @var{output} /lib/crt0.o hello.o -lc
254@end smallexample
255
ff5dcc92 256This tells @command{ld} to produce a file called @var{output} as the
252b5132
RH
257result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
258the library @code{libc.a}, which will come from the standard search
259directories. (See the discussion of the @samp{-l} option below.)
260
ff5dcc92 261Some of the command-line options to @command{ld} may be specified at any
511ab9e9
ILT
262point in the command line. However, options which refer to files, such
263as @samp{-l} or @samp{-T}, cause the file to be read at the point at
264which the option appears in the command line, relative to the object
265files and other file options. Repeating non-file options with a
266different argument will either have no further effect, or override prior
252b5132
RH
267occurrences (those further to the left on the command line) of that
268option. Options which may be meaningfully specified more than once are
269noted in the descriptions below.
270
271@cindex object files
511ab9e9
ILT
272Non-option arguments are object files or archives which are to be linked
273together. They may follow, precede, or be mixed in with command-line
274options, except that an object file argument may not be placed between
275an option and its argument.
252b5132
RH
276
277Usually the linker is invoked with at least one object file, but you can
278specify other forms of binary input files using @samp{-l}, @samp{-R},
279and the script command language. If @emph{no} binary input files at all
280are specified, the linker does not produce any output, and issues the
281message @samp{No input files}.
282
283If the linker can not recognize the format of an object file, it will
284assume that it is a linker script. A script specified in this way
285augments the main linker script used for the link (either the default
286linker script or the one specified by using @samp{-T}). This feature
287permits the linker to link against a file which appears to be an object
288or an archive, but actually merely defines some symbol values, or uses
289@code{INPUT} or @code{GROUP} to load other objects. Note that
114283d8
NC
290specifying a script in this way merely augments the main linker script;
291use the @samp{-T} option to replace the default linker script entirely.
252b5132
RH
292@xref{Scripts}.
293
294For options whose names are a single letter,
295option arguments must either follow the option letter without intervening
296whitespace, or be given as separate arguments immediately following the
297option that requires them.
298
299For options whose names are multiple letters, either one dash or two can
e4897a32
NC
300precede the option name; for example, @samp{-trace-symbol} and
301@samp{--trace-symbol} are equivalent. Note - there is one exception to
302this rule. Multiple letter options that start with a lower case 'o' can
303only be preceeded by two dashes. This is to reduce confusion with the
304@samp{-o} option. So for example @samp{-omagic} sets the output file
305name to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the
306output.
307
308Arguments to multiple-letter options must either be separated from the
309option name by an equals sign, or be given as separate arguments
310immediately following the option that requires them. For example,
311@samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent.
312Unique abbreviations of the names of multiple-letter options are
313accepted.
252b5132 314
4e53152f
NC
315Note - if the linker is being invoked indirectly, via a compiler driver
316(eg @samp{gcc}) then all the linker command line options should be
fa19fce0
NC
317prefixed by @samp{-Wl,} (or whatever is appropriate for the particular
318compiler driver) like this:
4e53152f
NC
319
320@smallexample
321 gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
322@end smallexample
323
324This is important, because otherwise the compiler driver program may
325silently drop the linker options, resulting in a bad link.
326
327Here is a table of the generic command line switches accepted by the GNU
328linker:
329
ff5dcc92 330@table @gcctabopt
252b5132
RH
331@kindex -a@var{keyword}
332@item -a@var{keyword}
333This option is supported for HP/UX compatibility. The @var{keyword}
334argument must be one of the strings @samp{archive}, @samp{shared}, or
335@samp{default}. @samp{-aarchive} is functionally equivalent to
336@samp{-Bstatic}, and the other two keywords are functionally equivalent
337to @samp{-Bdynamic}. This option may be used any number of times.
338
339@ifset I960
340@cindex architectures
341@kindex -A@var{arch}
342@item -A@var{architecture}
343@kindex --architecture=@var{arch}
344@itemx --architecture=@var{architecture}
ff5dcc92
SC
345In the current release of @command{ld}, this option is useful only for the
346Intel 960 family of architectures. In that @command{ld} configuration, the
252b5132
RH
347@var{architecture} argument identifies the particular architecture in
348the 960 family, enabling some safeguards and modifying the
ff5dcc92 349archive-library search path. @xref{i960,,@command{ld} and the Intel 960
252b5132
RH
350family}, for details.
351
ff5dcc92 352Future releases of @command{ld} may support similar functionality for
252b5132
RH
353other architecture families.
354@end ifset
355
356@ifclear SingleFormat
357@cindex binary input format
358@kindex -b @var{format}
359@kindex --format=@var{format}
360@cindex input format
361@cindex input format
362@item -b @var{input-format}
363@itemx --format=@var{input-format}
ff5dcc92
SC
364@command{ld} may be configured to support more than one kind of object
365file. If your @command{ld} is configured this way, you can use the
252b5132 366@samp{-b} option to specify the binary format for input object files
ff5dcc92 367that follow this option on the command line. Even when @command{ld} is
252b5132 368configured to support alternative object formats, you don't usually need
ff5dcc92 369to specify this, as @command{ld} should be configured to expect as a
252b5132
RH
370default input format the most usual format on each machine.
371@var{input-format} is a text string, the name of a particular format
372supported by the BFD libraries. (You can list the available binary
373formats with @samp{objdump -i}.)
374@xref{BFD}.
375
376You may want to use this option if you are linking files with an unusual
377binary format. You can also use @samp{-b} to switch formats explicitly (when
378linking object files of different formats), by including
379@samp{-b @var{input-format}} before each group of object files in a
a1ab1d2a 380particular format.
252b5132
RH
381
382The default format is taken from the environment variable
383@code{GNUTARGET}.
384@ifset UsesEnvVars
385@xref{Environment}.
386@end ifset
387You can also define the input format from a script, using the command
0285c67d
NC
388@code{TARGET};
389@ifclear man
390see @ref{Format Commands}.
391@end ifclear
252b5132
RH
392@end ifclear
393
394@kindex -c @var{MRI-cmdfile}
395@kindex --mri-script=@var{MRI-cmdfile}
396@cindex compatibility, MRI
397@item -c @var{MRI-commandfile}
398@itemx --mri-script=@var{MRI-commandfile}
ff5dcc92 399For compatibility with linkers produced by MRI, @command{ld} accepts script
252b5132 400files written in an alternate, restricted command language, described in
0285c67d
NC
401@ifclear man
402@ref{MRI,,MRI Compatible Script Files}.
403@end ifclear
404@ifset man
405the MRI Compatible Script Files section of GNU ld documentation.
406@end ifset
407Introduce MRI script files with
252b5132 408the option @samp{-c}; use the @samp{-T} option to run linker
ff5dcc92
SC
409scripts written in the general-purpose @command{ld} scripting language.
410If @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories
252b5132
RH
411specified by any @samp{-L} options.
412
413@cindex common allocation
414@kindex -d
415@kindex -dc
416@kindex -dp
a1ab1d2a 417@item -d
252b5132
RH
418@itemx -dc
419@itemx -dp
420These three options are equivalent; multiple forms are supported for
421compatibility with other linkers. They assign space to common symbols
422even if a relocatable output file is specified (with @samp{-r}). The
423script command @code{FORCE_COMMON_ALLOCATION} has the same effect.
424@xref{Miscellaneous Commands}.
425
426@cindex entry point, from command line
427@kindex -e @var{entry}
428@kindex --entry=@var{entry}
a1ab1d2a 429@item -e @var{entry}
252b5132
RH
430@itemx --entry=@var{entry}
431Use @var{entry} as the explicit symbol for beginning execution of your
432program, rather than the default entry point. If there is no symbol
433named @var{entry}, the linker will try to parse @var{entry} as a number,
434and use that as the entry address (the number will be interpreted in
435base 10; you may use a leading @samp{0x} for base 16, or a leading
436@samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults
437and other ways of specifying the entry point.
438
439@cindex dynamic symbol table
440@kindex -E
441@kindex --export-dynamic
442@item -E
443@itemx --export-dynamic
444When creating a dynamically linked executable, add all symbols to the
445dynamic symbol table. The dynamic symbol table is the set of symbols
446which are visible from dynamic objects at run time.
447
448If you do not use this option, the dynamic symbol table will normally
449contain only those symbols which are referenced by some dynamic object
450mentioned in the link.
451
452If you use @code{dlopen} to load a dynamic object which needs to refer
453back to the symbols defined by the program, rather than some other
454dynamic object, then you will probably need to use this option when
455linking the program itself.
456
cb840a31
L
457You can also use the version script to control what symbols should
458be added to the dynamic symbol table if the output format supports it.
459See the description of @samp{--version-script} in @ref{VERSION}.
460
252b5132
RH
461@cindex big-endian objects
462@cindex endianness
463@kindex -EB
464@item -EB
465Link big-endian objects. This affects the default output format.
466
467@cindex little-endian objects
468@kindex -EL
469@item -EL
470Link little-endian objects. This affects the default output format.
471
472@kindex -f
473@kindex --auxiliary
474@item -f
475@itemx --auxiliary @var{name}
476When creating an ELF shared object, set the internal DT_AUXILIARY field
477to the specified name. This tells the dynamic linker that the symbol
478table of the shared object should be used as an auxiliary filter on the
479symbol table of the shared object @var{name}.
480
481If you later link a program against this filter object, then, when you
482run the program, the dynamic linker will see the DT_AUXILIARY field. If
483the dynamic linker resolves any symbols from the filter object, it will
484first check whether there is a definition in the shared object
485@var{name}. If there is one, it will be used instead of the definition
486in the filter object. The shared object @var{name} need not exist.
487Thus the shared object @var{name} may be used to provide an alternative
488implementation of certain functions, perhaps for debugging or for
489machine specific performance.
490
491This option may be specified more than once. The DT_AUXILIARY entries
492will be created in the order in which they appear on the command line.
493
494@kindex -F
495@kindex --filter
496@item -F @var{name}
497@itemx --filter @var{name}
498When creating an ELF shared object, set the internal DT_FILTER field to
499the specified name. This tells the dynamic linker that the symbol table
500of the shared object which is being created should be used as a filter
501on the symbol table of the shared object @var{name}.
502
503If you later link a program against this filter object, then, when you
504run the program, the dynamic linker will see the DT_FILTER field. The
505dynamic linker will resolve symbols according to the symbol table of the
506filter object as usual, but it will actually link to the definitions
507found in the shared object @var{name}. Thus the filter object can be
508used to select a subset of the symbols provided by the object
509@var{name}.
510
ff5dcc92 511Some older linkers used the @option{-F} option throughout a compilation
252b5132
RH
512toolchain for specifying object-file format for both input and output
513object files. The @sc{gnu} linker uses other mechanisms for this
ff5dcc92 514purpose: the @option{-b}, @option{--format}, @option{--oformat} options, the
252b5132 515@code{TARGET} command in linker scripts, and the @code{GNUTARGET}
ff5dcc92 516environment variable. The @sc{gnu} linker will ignore the @option{-F}
252b5132
RH
517option when not creating an ELF shared object.
518
3dbf70a2
MM
519@cindex finalization function
520@kindex -fini
521@item -fini @var{name}
522When creating an ELF executable or shared object, call NAME when the
523executable or shared object is unloaded, by setting DT_FINI to the
524address of the function. By default, the linker uses @code{_fini} as
525the function to call.
526
252b5132
RH
527@kindex -g
528@item -g
529Ignored. Provided for compatibility with other tools.
530
531@kindex -G
532@kindex --gpsize
533@cindex object size
534@item -G@var{value}
535@itemx --gpsize=@var{value}
536Set the maximum size of objects to be optimized using the GP register to
537@var{size}. This is only meaningful for object file formats such as
538MIPS ECOFF which supports putting large and small objects into different
539sections. This is ignored for other object file formats.
540
541@cindex runtime library name
542@kindex -h@var{name}
543@kindex -soname=@var{name}
544@item -h@var{name}
545@itemx -soname=@var{name}
546When creating an ELF shared object, set the internal DT_SONAME field to
547the specified name. When an executable is linked with a shared object
548which has a DT_SONAME field, then when the executable is run the dynamic
549linker will attempt to load the shared object specified by the DT_SONAME
550field rather than the using the file name given to the linker.
551
552@kindex -i
553@cindex incremental link
554@item -i
555Perform an incremental link (same as option @samp{-r}).
556
3dbf70a2
MM
557@cindex initialization function
558@kindex -init
559@item -init @var{name}
560When creating an ELF executable or shared object, call NAME when the
561executable or shared object is loaded, by setting DT_INIT to the address
562of the function. By default, the linker uses @code{_init} as the
563function to call.
564
252b5132
RH
565@cindex archive files, from cmd line
566@kindex -l@var{archive}
567@kindex --library=@var{archive}
568@item -l@var{archive}
569@itemx --library=@var{archive}
570Add archive file @var{archive} to the list of files to link. This
ff5dcc92 571option may be used any number of times. @command{ld} will search its
252b5132
RH
572path-list for occurrences of @code{lib@var{archive}.a} for every
573@var{archive} specified.
574
ff5dcc92 575On systems which support shared libraries, @command{ld} may also search for
252b5132 576libraries with extensions other than @code{.a}. Specifically, on ELF
ff5dcc92 577and SunOS systems, @command{ld} will search a directory for a library with
252b5132
RH
578an extension of @code{.so} before searching for one with an extension of
579@code{.a}. By convention, a @code{.so} extension indicates a shared
580library.
581
582The linker will search an archive only once, at the location where it is
583specified on the command line. If the archive defines a symbol which
584was undefined in some object which appeared before the archive on the
585command line, the linker will include the appropriate file(s) from the
586archive. However, an undefined symbol in an object appearing later on
587the command line will not cause the linker to search the archive again.
588
ff5dcc92 589See the @option{-(} option for a way to force the linker to search
252b5132
RH
590archives multiple times.
591
592You may list the same archive multiple times on the command line.
593
594@ifset GENERIC
595This type of archive searching is standard for Unix linkers. However,
ff5dcc92 596if you are using @command{ld} on AIX, note that it is different from the
252b5132
RH
597behaviour of the AIX linker.
598@end ifset
599
600@cindex search directory, from cmd line
601@kindex -L@var{dir}
602@kindex --library-path=@var{dir}
a1ab1d2a 603@item -L@var{searchdir}
252b5132 604@itemx --library-path=@var{searchdir}
ff5dcc92
SC
605Add path @var{searchdir} to the list of paths that @command{ld} will search
606for archive libraries and @command{ld} control scripts. You may use this
252b5132
RH
607option any number of times. The directories are searched in the order
608in which they are specified on the command line. Directories specified
609on the command line are searched before the default directories. All
ff5dcc92 610@option{-L} options apply to all @option{-l} options, regardless of the
252b5132
RH
611order in which the options appear.
612
9c8ebd6a
DJ
613If @var{searchdir} begins with @code{=}, then the @code{=} will be replaced
614by the @dfn{sysroot prefix}, a path specified when the linker is configured.
615
252b5132
RH
616@ifset UsesEnvVars
617The default set of paths searched (without being specified with
ff5dcc92 618@samp{-L}) depends on which emulation mode @command{ld} is using, and in
252b5132
RH
619some cases also on how it was configured. @xref{Environment}.
620@end ifset
621
622The paths can also be specified in a link script with the
623@code{SEARCH_DIR} command. Directories specified this way are searched
624at the point in which the linker script appears in the command line.
625
626@cindex emulation
627@kindex -m @var{emulation}
628@item -m@var{emulation}
629Emulate the @var{emulation} linker. You can list the available
630emulations with the @samp{--verbose} or @samp{-V} options.
631
632If the @samp{-m} option is not used, the emulation is taken from the
633@code{LDEMULATION} environment variable, if that is defined.
634
635Otherwise, the default emulation depends upon how the linker was
636configured.
637
638@cindex link map
639@kindex -M
640@kindex --print-map
641@item -M
642@itemx --print-map
643Print a link map to the standard output. A link map provides
644information about the link, including the following:
645
646@itemize @bullet
647@item
648Where object files and symbols are mapped into memory.
649@item
650How common symbols are allocated.
651@item
652All archive members included in the link, with a mention of the symbol
653which caused the archive member to be brought in.
654@end itemize
655
656@kindex -n
657@cindex read-only text
658@cindex NMAGIC
659@kindex --nmagic
660@item -n
661@itemx --nmagic
fa19fce0 662Turn off page alignment of sections, and mark the output as
a1ab1d2a 663@code{NMAGIC} if possible.
252b5132
RH
664
665@kindex -N
666@kindex --omagic
667@cindex read/write from cmd line
668@cindex OMAGIC
a1ab1d2a 669@item -N
252b5132
RH
670@itemx --omagic
671Set the text and data sections to be readable and writable. Also, do
63fd3b82
NC
672not page-align the data segment, and disable linking against shared
673libraries. If the output format supports Unix style magic numbers,
674mark the output as @code{OMAGIC}.
675
676@kindex --no-omagic
677@cindex OMAGIC
678@item --no-omagic
679This option negates most of the effects of the @option{-N} option. It
680sets the text section to be read-only, and forces the data segment to
681be page-aligned. Note - this option does not enable linking against
682shared libraries. Use @option{-Bdynamic} for this.
252b5132
RH
683
684@kindex -o @var{output}
685@kindex --output=@var{output}
686@cindex naming the output file
687@item -o @var{output}
688@itemx --output=@var{output}
ff5dcc92 689Use @var{output} as the name for the program produced by @command{ld}; if this
252b5132
RH
690option is not specified, the name @file{a.out} is used by default. The
691script command @code{OUTPUT} can also specify the output file name.
692
693@kindex -O @var{level}
694@cindex generating optimized output
695@item -O @var{level}
ff5dcc92 696If @var{level} is a numeric values greater than zero @command{ld} optimizes
252b5132
RH
697the output. This might take significantly longer and therefore probably
698should only be enabled for the final binary.
699
a712da20
NC
700@kindex -q
701@kindex --emit-relocs
702@cindex retain relocations in final executable
703@item -q
704@itemx --emit-relocs
705Leave relocation sections and contents in fully linked exececutables.
706Post link analysis and optimization tools may need this information in
707order to perform correct modifications of executables. This results
708in larger executables.
709
dbab7a7b
NC
710This option is currently only supported on ELF platforms.
711
252b5132
RH
712@cindex partial link
713@cindex relocatable output
714@kindex -r
715@kindex --relocateable
716@item -r
717@itemx --relocateable
718Generate relocatable output---i.e., generate an output file that can in
ff5dcc92 719turn serve as input to @command{ld}. This is often called @dfn{partial
252b5132
RH
720linking}. As a side effect, in environments that support standard Unix
721magic numbers, this option also sets the output file's magic number to
722@code{OMAGIC}.
ff5dcc92 723@c ; see @option{-N}.
252b5132
RH
724If this option is not specified, an absolute file is produced. When
725linking C++ programs, this option @emph{will not} resolve references to
726constructors; to do that, use @samp{-Ur}.
727
62bf86b4
HPN
728When an input file does not have the same format as the output file,
729partial linking is only supported if that input file does not contain any
730relocations. Different output formats can have further restrictions; for
731example some @code{a.out}-based formats do not support partial linking
732with input files in other formats at all.
733
252b5132
RH
734This option does the same thing as @samp{-i}.
735
736@kindex -R @var{file}
737@kindex --just-symbols=@var{file}
738@cindex symbol-only input
739@item -R @var{filename}
740@itemx --just-symbols=@var{filename}
741Read symbol names and their addresses from @var{filename}, but do not
742relocate it or include it in the output. This allows your output file
743to refer symbolically to absolute locations of memory defined in other
744programs. You may use this option more than once.
745
ff5dcc92 746For compatibility with other ELF linkers, if the @option{-R} option is
252b5132 747followed by a directory name, rather than a file name, it is treated as
ff5dcc92 748the @option{-rpath} option.
252b5132
RH
749
750@kindex -s
751@kindex --strip-all
752@cindex strip all symbols
a1ab1d2a 753@item -s
252b5132
RH
754@itemx --strip-all
755Omit all symbol information from the output file.
756
757@kindex -S
758@kindex --strip-debug
759@cindex strip debugger symbols
a1ab1d2a 760@item -S
252b5132
RH
761@itemx --strip-debug
762Omit debugger symbol information (but not all symbols) from the output file.
763
764@kindex -t
765@kindex --trace
766@cindex input files, displaying
a1ab1d2a 767@item -t
252b5132 768@itemx --trace
ff5dcc92 769Print the names of the input files as @command{ld} processes them.
252b5132
RH
770
771@kindex -T @var{script}
772@kindex --script=@var{script}
773@cindex script files
774@item -T @var{scriptfile}
775@itemx --script=@var{scriptfile}
776Use @var{scriptfile} as the linker script. This script replaces
ff5dcc92 777@command{ld}'s default linker script (rather than adding to it), so
252b5132 778@var{commandfile} must specify everything necessary to describe the
114283d8
NC
779output file. @xref{Scripts}. If @var{scriptfile} does not exist in
780the current directory, @code{ld} looks for it in the directories
781specified by any preceding @samp{-L} options. Multiple @samp{-T}
782options accumulate.
252b5132
RH
783
784@kindex -u @var{symbol}
785@kindex --undefined=@var{symbol}
786@cindex undefined symbol
787@item -u @var{symbol}
788@itemx --undefined=@var{symbol}
789Force @var{symbol} to be entered in the output file as an undefined
790symbol. Doing this may, for example, trigger linking of additional
791modules from standard libraries. @samp{-u} may be repeated with
792different option arguments to enter additional undefined symbols. This
793option is equivalent to the @code{EXTERN} linker script command.
794
795@kindex -Ur
796@cindex constructors
a1ab1d2a 797@item -Ur
252b5132
RH
798For anything other than C++ programs, this option is equivalent to
799@samp{-r}: it generates relocatable output---i.e., an output file that can in
ff5dcc92 800turn serve as input to @command{ld}. When linking C++ programs, @samp{-Ur}
252b5132
RH
801@emph{does} resolve references to constructors, unlike @samp{-r}.
802It does not work to use @samp{-Ur} on files that were themselves linked
803with @samp{-Ur}; once the constructor table has been built, it cannot
804be added to. Use @samp{-Ur} only for the last partial link, and
805@samp{-r} for the others.
806
577a0623
AM
807@kindex --unique[=@var{SECTION}]
808@item --unique[=@var{SECTION}]
809Creates a separate output section for every input section matching
810@var{SECTION}, or if the optional wildcard @var{SECTION} argument is
811missing, for every orphan input section. An orphan section is one not
812specifically mentioned in a linker script. You may use this option
813multiple times on the command line; It prevents the normal merging of
814input sections with the same name, overriding output section assignments
815in a linker script.
a854a4a7 816
252b5132
RH
817@kindex -v
818@kindex -V
819@kindex --version
820@cindex version
821@item -v
822@itemx --version
823@itemx -V
ff5dcc92 824Display the version number for @command{ld}. The @option{-V} option also
252b5132
RH
825lists the supported emulations.
826
827@kindex -x
828@kindex --discard-all
829@cindex deleting local symbols
830@item -x
831@itemx --discard-all
832Delete all local symbols.
833
834@kindex -X
835@kindex --discard-locals
836@cindex local symbols, deleting
837@cindex L, deleting symbols beginning
a1ab1d2a 838@item -X
252b5132
RH
839@itemx --discard-locals
840Delete all temporary local symbols. For most targets, this is all local
841symbols whose names begin with @samp{L}.
842
843@kindex -y @var{symbol}
844@kindex --trace-symbol=@var{symbol}
845@cindex symbol tracing
846@item -y @var{symbol}
847@itemx --trace-symbol=@var{symbol}
848Print the name of each linked file in which @var{symbol} appears. This
849option may be given any number of times. On many systems it is necessary
850to prepend an underscore.
851
852This option is useful when you have an undefined symbol in your link but
853don't know where the reference is coming from.
854
855@kindex -Y @var{path}
856@item -Y @var{path}
857Add @var{path} to the default library search path. This option exists
858for Solaris compatibility.
859
860@kindex -z @var{keyword}
861@item -z @var{keyword}
e0ee487b
L
862The recognized keywords are @code{initfirst}, @code{interpose},
863@code{loadfltr}, @code{nodefaultlib}, @code{nodelete}, @code{nodlopen},
8bd621d8
AM
864@code{nodump}, @code{now}, @code{origin}, @code{combreloc}, @code{nocombreloc}
865and @code{nocopyreloc}.
866The other keywords are
e0ee487b
L
867ignored for Solaris compatibility. @code{initfirst} marks the object
868to be initialized first at runtime before any other objects.
869@code{interpose} marks the object that its symbol table interposes
870before all symbols but the primary executable. @code{loadfltr} marks
871the object that its filtees be processed immediately at runtime.
872@code{nodefaultlib} marks the object that the search for dependencies
873of this object will ignore any default library search paths.
874@code{nodelete} marks the object shouldn't be unloaded at runtime.
875@code{nodlopen} marks the object not available to @code{dlopen}.
876@code{nodump} marks the object can not be dumped by @code{dldump}.
877@code{now} marks the object with the non-lazy runtime binding.
878@code{origin} marks the object may contain $ORIGIN.
a1ab1d2a 879@code{defs} disallows undefined symbols.
aa713662 880@code{muldefs} allows multiple definitions.
db6751f2
JJ
881@code{combreloc} combines multiple reloc sections and sorts them
882to make dynamic symbol lookup caching possible.
883@code{nocombreloc} disables multiple reloc sections combining.
8bd621d8 884@code{nocopyreloc} disables production of copy relocs.
252b5132
RH
885
886@kindex -(
887@cindex groups of archives
888@item -( @var{archives} -)
889@itemx --start-group @var{archives} --end-group
890The @var{archives} should be a list of archive files. They may be
891either explicit file names, or @samp{-l} options.
892
893The specified archives are searched repeatedly until no new undefined
894references are created. Normally, an archive is searched only once in
895the order that it is specified on the command line. If a symbol in that
896archive is needed to resolve an undefined symbol referred to by an
897object in an archive that appears later on the command line, the linker
898would not be able to resolve that reference. By grouping the archives,
899they all be searched repeatedly until all possible references are
900resolved.
901
902Using this option has a significant performance cost. It is best to use
903it only when there are unavoidable circular references between two or
904more archives.
905
69da35b5
NC
906@kindex --accept-unknown-input-arch
907@kindex --no-accept-unknown-input-arch
908@item --accept-unknown-input-arch
909@itemx --no-accept-unknown-input-arch
910Tells the linker to accept input files whose architecture cannot be
2ca22b03 911recognised. The assumption is that the user knows what they are doing
69da35b5
NC
912and deliberately wants to link in these unknown input files. This was
913the default behaviour of the linker, before release 2.14. The default
914behaviour from release 2.14 onwards is to reject such input files, and
915so the @samp{--accept-unknown-input-arch} option has been added to
916restore the old behaviour.
2ca22b03 917
252b5132
RH
918@kindex -assert @var{keyword}
919@item -assert @var{keyword}
920This option is ignored for SunOS compatibility.
921
922@kindex -Bdynamic
923@kindex -dy
924@kindex -call_shared
925@item -Bdynamic
926@itemx -dy
927@itemx -call_shared
928Link against dynamic libraries. This is only meaningful on platforms
929for which shared libraries are supported. This option is normally the
930default on such platforms. The different variants of this option are
931for compatibility with various systems. You may use this option
932multiple times on the command line: it affects library searching for
ff5dcc92 933@option{-l} options which follow it.
252b5132 934
a1ab1d2a
UD
935@kindex -Bgroup
936@item -Bgroup
937Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
938section. This causes the runtime linker to handle lookups in this
939object and its dependencies to be performed only inside the group.
ff5dcc92 940@option{--no-undefined} is implied. This option is only meaningful on ELF
a1ab1d2a
UD
941platforms which support shared libraries.
942
252b5132
RH
943@kindex -Bstatic
944@kindex -dn
945@kindex -non_shared
946@kindex -static
a1ab1d2a 947@item -Bstatic
252b5132
RH
948@itemx -dn
949@itemx -non_shared
950@itemx -static
951Do not link against shared libraries. This is only meaningful on
952platforms for which shared libraries are supported. The different
953variants of this option are for compatibility with various systems. You
954may use this option multiple times on the command line: it affects
ff5dcc92 955library searching for @option{-l} options which follow it.
252b5132
RH
956
957@kindex -Bsymbolic
958@item -Bsymbolic
959When creating a shared library, bind references to global symbols to the
960definition within the shared library, if any. Normally, it is possible
961for a program linked against a shared library to override the definition
962within the shared library. This option is only meaningful on ELF
963platforms which support shared libraries.
964
965@kindex --check-sections
966@kindex --no-check-sections
967@item --check-sections
308b1ffd 968@itemx --no-check-sections
252b5132
RH
969Asks the linker @emph{not} to check section addresses after they have
970been assigned to see if there any overlaps. Normally the linker will
971perform this check, and if it finds any overlaps it will produce
972suitable error messages. The linker does know about, and does make
973allowances for sections in overlays. The default behaviour can be
974restored by using the command line switch @samp{--check-sections}.
975
976@cindex cross reference table
977@kindex --cref
978@item --cref
979Output a cross reference table. If a linker map file is being
980generated, the cross reference table is printed to the map file.
981Otherwise, it is printed on the standard output.
982
983The format of the table is intentionally simple, so that it may be
984easily processed by a script if necessary. The symbols are printed out,
985sorted by name. For each symbol, a list of file names is given. If the
986symbol is defined, the first file listed is the location of the
987definition. The remaining files contain references to the symbol.
988
4818e05f
AM
989@cindex common allocation
990@kindex --no-define-common
991@item --no-define-common
992This option inhibits the assignment of addresses to common symbols.
993The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
994@xref{Miscellaneous Commands}.
995
996The @samp{--no-define-common} option allows decoupling
997the decision to assign addresses to Common symbols from the choice
998of the output file type; otherwise a non-Relocatable output type
999forces assigning addresses to Common symbols.
1000Using @samp{--no-define-common} allows Common symbols that are referenced
1001from a shared library to be assigned addresses only in the main program.
1002This eliminates the unused duplicate space in the shared library,
1003and also prevents any possible confusion over resolving to the wrong
1004duplicate when there are many dynamic modules with specialized search
1005paths for runtime symbol resolution.
1006
252b5132
RH
1007@cindex symbols, from command line
1008@kindex --defsym @var{symbol}=@var{exp}
1009@item --defsym @var{symbol}=@var{expression}
1010Create a global symbol in the output file, containing the absolute
1011address given by @var{expression}. You may use this option as many
1012times as necessary to define multiple symbols in the command line. A
1013limited form of arithmetic is supported for the @var{expression} in this
1014context: you may give a hexadecimal constant or the name of an existing
1015symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
1016constants or symbols. If you need more elaborate expressions, consider
1017using the linker command language from a script (@pxref{Assignments,,
1018Assignment: Symbol Definitions}). @emph{Note:} there should be no white
1019space between @var{symbol}, the equals sign (``@key{=}''), and
1020@var{expression}.
1021
1022@cindex demangling, from command line
28c309a2 1023@kindex --demangle[=@var{style}]
252b5132 1024@kindex --no-demangle
28c309a2 1025@item --demangle[=@var{style}]
252b5132
RH
1026@itemx --no-demangle
1027These options control whether to demangle symbol names in error messages
1028and other output. When the linker is told to demangle, it tries to
1029present symbol names in a readable fashion: it strips leading
1030underscores if they are used by the object file format, and converts C++
a1ab1d2a
UD
1031mangled symbol names into user readable names. Different compilers have
1032different mangling styles. The optional demangling style argument can be used
1033to choose an appropriate demangling style for your compiler. The linker will
28c309a2
NC
1034demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
1035is set. These options may be used to override the default.
252b5132
RH
1036
1037@cindex dynamic linker, from command line
506eee22 1038@kindex -I@var{file}
252b5132
RH
1039@kindex --dynamic-linker @var{file}
1040@item --dynamic-linker @var{file}
1041Set the name of the dynamic linker. This is only meaningful when
1042generating dynamically linked ELF executables. The default dynamic
1043linker is normally correct; don't use this unless you know what you are
1044doing.
1045
1046@cindex MIPS embedded PIC code
1047@kindex --embedded-relocs
1048@item --embedded-relocs
1049This option is only meaningful when linking MIPS embedded PIC code,
1050generated by the -membedded-pic option to the @sc{gnu} compiler and
1051assembler. It causes the linker to create a table which may be used at
1052runtime to relocate any data which was statically initialized to pointer
1053values. See the code in testsuite/ld-empic for details.
1054
7ce691ae
C
1055
1056@kindex --fatal-warnings
1057@item --fatal-warnings
1058Treat all warnings as errors.
1059
252b5132
RH
1060@kindex --force-exe-suffix
1061@item --force-exe-suffix
1062Make sure that an output file has a .exe suffix.
1063
1064If a successfully built fully linked output file does not have a
1065@code{.exe} or @code{.dll} suffix, this option forces the linker to copy
1066the output file to one of the same name with a @code{.exe} suffix. This
1067option is useful when using unmodified Unix makefiles on a Microsoft
1068Windows host, since some versions of Windows won't run an image unless
1069it ends in a @code{.exe} suffix.
1070
1071@kindex --gc-sections
1072@kindex --no-gc-sections
1073@cindex garbage collection
1074@item --no-gc-sections
1075@itemx --gc-sections
1076Enable garbage collection of unused input sections. It is ignored on
1077targets that do not support this option. This option is not compatible
1078with @samp{-r}, nor should it be used with dynamic linking. The default
1079behaviour (of not performing this garbage collection) can be restored by
1080specifying @samp{--no-gc-sections} on the command line.
1081
1082@cindex help
1083@cindex usage
1084@kindex --help
1085@item --help
1086Print a summary of the command-line options on the standard output and exit.
1087
ea20a7da
CC
1088@kindex --target-help
1089@item --target-help
1090Print a summary of all target specific options on the standard output and exit.
1091
252b5132
RH
1092@kindex -Map
1093@item -Map @var{mapfile}
1094Print a link map to the file @var{mapfile}. See the description of the
1095@samp{-M} option, above.
1096
1097@cindex memory usage
1098@kindex --no-keep-memory
1099@item --no-keep-memory
ff5dcc92
SC
1100@command{ld} normally optimizes for speed over memory usage by caching the
1101symbol tables of input files in memory. This option tells @command{ld} to
252b5132 1102instead optimize for memory usage, by rereading the symbol tables as
ff5dcc92 1103necessary. This may be required if @command{ld} runs out of memory space
252b5132
RH
1104while linking a large executable.
1105
1106@kindex --no-undefined
a1ab1d2a 1107@kindex -z defs
252b5132 1108@item --no-undefined
a1ab1d2a 1109@itemx -z defs
252b5132 1110Normally when creating a non-symbolic shared library, undefined symbols
ae9a127f
NC
1111are allowed and left to be resolved by the runtime loader. This option
1112disallows such undefined symbols if they come from regular object
1113files. The switch @samp{--no-allow-shlib-undefined} controls the
1114behaviour for shared objects being linked into the shared library.
252b5132 1115
aa713662
L
1116@kindex --allow-multiple-definition
1117@kindex -z muldefs
1118@item --allow-multiple-definition
1119@itemx -z muldefs
1120Normally when a symbol is defined multiple times, the linker will
1121report a fatal error. These options allow multiple definitions and the
1122first definition will be used.
1123
b79e8c78 1124@kindex --allow-shlib-undefined
ae9a127f 1125@kindex --no-allow-shlib-undefined
b79e8c78 1126@item --allow-shlib-undefined
ae9a127f
NC
1127@itemx --no-allow-shlib-undefined
1128Allow (the default) or disallow undefined symbols in shared objects.
1129The setting of this switch overrides @samp {--no-undefined} where
1130shared objects are concerned. Thus if @samp {--no-undefined} is set
1131but @samp {--no-allow-shlib-undefined} is not, the net result will be
1132that undefined symbols in regular object files will trigger an error,
1133but undefined symbols in shared objects will be ignored.
1134
1135The reason that @samp{--allow-shlib-undefined} is the default is that
1136the shared object being specified at link time may not be the same one
1137that is available at load time, so the symbols might actually be
1138resolvable at load time. Plus there are some systems, (eg BeOS) where
1139undefined symbols in shared libraries is normal since the kernel
1140patches them at load time to select which function is most appropriate
1141for the current architecture. eg. to dynamically select an appropriate
1142memset function. Apparently it is also normal for HPPA shared
1143libraries to have undefined symbols.
b79e8c78 1144
31941635
L
1145@kindex --no-undefined-version
1146@item --no-undefined-version
1147Normally when a symbol has an undefined version, the linker will ignore
1148it. This option disallows symbols with undefined version and a fatal error
1149will be issued instead.
1150
252b5132
RH
1151@kindex --no-warn-mismatch
1152@item --no-warn-mismatch
ff5dcc92 1153Normally @command{ld} will give an error if you try to link together input
252b5132
RH
1154files that are mismatched for some reason, perhaps because they have
1155been compiled for different processors or for different endiannesses.
ff5dcc92 1156This option tells @command{ld} that it should silently permit such possible
252b5132
RH
1157errors. This option should only be used with care, in cases when you
1158have taken some special action that ensures that the linker errors are
1159inappropriate.
1160
1161@kindex --no-whole-archive
1162@item --no-whole-archive
ff5dcc92 1163Turn off the effect of the @option{--whole-archive} option for subsequent
252b5132
RH
1164archive files.
1165
1166@cindex output file after errors
1167@kindex --noinhibit-exec
1168@item --noinhibit-exec
1169Retain the executable output file whenever it is still usable.
1170Normally, the linker will not produce an output file if it encounters
1171errors during the link process; it exits without writing an output file
1172when it issues any error whatsoever.
1173
0a9c1c8e
CD
1174@kindex -nostdlib
1175@item -nostdlib
1176Only search library directories explicitly specified on the
1177command line. Library directories specified in linker scripts
1178(including linker scripts specified on the command line) are ignored.
1179
252b5132
RH
1180@ifclear SingleFormat
1181@kindex --oformat
1182@item --oformat @var{output-format}
ff5dcc92
SC
1183@command{ld} may be configured to support more than one kind of object
1184file. If your @command{ld} is configured this way, you can use the
252b5132 1185@samp{--oformat} option to specify the binary format for the output
ff5dcc92
SC
1186object file. Even when @command{ld} is configured to support alternative
1187object formats, you don't usually need to specify this, as @command{ld}
252b5132
RH
1188should be configured to produce as a default output format the most
1189usual format on each machine. @var{output-format} is a text string, the
1190name of a particular format supported by the BFD libraries. (You can
1191list the available binary formats with @samp{objdump -i}.) The script
1192command @code{OUTPUT_FORMAT} can also specify the output format, but
1193this option overrides it. @xref{BFD}.
1194@end ifclear
1195
1196@kindex -qmagic
1197@item -qmagic
1198This option is ignored for Linux compatibility.
1199
1200@kindex -Qy
1201@item -Qy
1202This option is ignored for SVR4 compatibility.
1203
1204@kindex --relax
1205@cindex synthesizing linker
1206@cindex relaxing addressing modes
1207@item --relax
a1ab1d2a 1208An option with machine dependent effects.
252b5132
RH
1209@ifset GENERIC
1210This option is only supported on a few targets.
1211@end ifset
1212@ifset H8300
ff5dcc92 1213@xref{H8/300,,@command{ld} and the H8/300}.
252b5132
RH
1214@end ifset
1215@ifset I960
ff5dcc92 1216@xref{i960,, @command{ld} and the Intel 960 family}.
252b5132
RH
1217@end ifset
1218
1219
1220On some platforms, the @samp{--relax} option performs global
1221optimizations that become possible when the linker resolves addressing
1222in the program, such as relaxing address modes and synthesizing new
1223instructions in the output object file.
1224
1225On some platforms these link time global optimizations may make symbolic
1226debugging of the resulting executable impossible.
1227@ifset GENERIC
1228This is known to be
1229the case for the Matsushita MN10200 and MN10300 family of processors.
1230@end ifset
1231
1232@ifset GENERIC
1233On platforms where this is not supported, @samp{--relax} is accepted,
1234but ignored.
1235@end ifset
1236
1237@cindex retaining specified symbols
1238@cindex stripping all but some symbols
1239@cindex symbols, retaining selectively
1240@item --retain-symbols-file @var{filename}
1241Retain @emph{only} the symbols listed in the file @var{filename},
1242discarding all others. @var{filename} is simply a flat file, with one
1243symbol name per line. This option is especially useful in environments
1244@ifset GENERIC
1245(such as VxWorks)
1246@end ifset
1247where a large global symbol table is accumulated gradually, to conserve
1248run-time memory.
1249
1250@samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
1251or symbols needed for relocations.
1252
1253You may only specify @samp{--retain-symbols-file} once in the command
1254line. It overrides @samp{-s} and @samp{-S}.
1255
1256@ifset GENERIC
1257@item -rpath @var{dir}
1258@cindex runtime library search path
1259@kindex -rpath
1260Add a directory to the runtime library search path. This is used when
ff5dcc92 1261linking an ELF executable with shared objects. All @option{-rpath}
252b5132 1262arguments are concatenated and passed to the runtime linker, which uses
ff5dcc92 1263them to locate shared objects at runtime. The @option{-rpath} option is
252b5132
RH
1264also used when locating shared objects which are needed by shared
1265objects explicitly included in the link; see the description of the
ff5dcc92 1266@option{-rpath-link} option. If @option{-rpath} is not used when linking an
252b5132
RH
1267ELF executable, the contents of the environment variable
1268@code{LD_RUN_PATH} will be used if it is defined.
1269
ff5dcc92 1270The @option{-rpath} option may also be used on SunOS. By default, on
252b5132 1271SunOS, the linker will form a runtime search patch out of all the
ff5dcc92
SC
1272@option{-L} options it is given. If a @option{-rpath} option is used, the
1273runtime search path will be formed exclusively using the @option{-rpath}
1274options, ignoring the @option{-L} options. This can be useful when using
1275gcc, which adds many @option{-L} options which may be on NFS mounted
252b5132
RH
1276filesystems.
1277
ff5dcc92 1278For compatibility with other ELF linkers, if the @option{-R} option is
252b5132 1279followed by a directory name, rather than a file name, it is treated as
ff5dcc92 1280the @option{-rpath} option.
252b5132
RH
1281@end ifset
1282
1283@ifset GENERIC
1284@cindex link-time runtime library search path
1285@kindex -rpath-link
1286@item -rpath-link @var{DIR}
1287When using ELF or SunOS, one shared library may require another. This
1288happens when an @code{ld -shared} link includes a shared library as one
1289of the input files.
1290
1291When the linker encounters such a dependency when doing a non-shared,
1292non-relocatable link, it will automatically try to locate the required
1293shared library and include it in the link, if it is not included
ff5dcc92 1294explicitly. In such a case, the @option{-rpath-link} option
252b5132 1295specifies the first set of directories to search. The
ff5dcc92 1296@option{-rpath-link} option may specify a sequence of directory names
252b5132
RH
1297either by specifying a list of names separated by colons, or by
1298appearing multiple times.
1299
28c309a2
NC
1300This option should be used with caution as it overrides the search path
1301that may have been hard compiled into a shared library. In such a case it
1302is possible to use unintentionally a different search path than the
1303runtime linker would do.
1304
252b5132
RH
1305The linker uses the following search paths to locate required shared
1306libraries.
1307@enumerate
1308@item
ff5dcc92 1309Any directories specified by @option{-rpath-link} options.
252b5132 1310@item
ff5dcc92
SC
1311Any directories specified by @option{-rpath} options. The difference
1312between @option{-rpath} and @option{-rpath-link} is that directories
1313specified by @option{-rpath} options are included in the executable and
1314used at runtime, whereas the @option{-rpath-link} option is only effective
dcb0bd0e 1315at link time. It is for the native linker only.
252b5132 1316@item
ff5dcc92 1317On an ELF system, if the @option{-rpath} and @code{rpath-link} options
252b5132 1318were not used, search the contents of the environment variable
dcb0bd0e 1319@code{LD_RUN_PATH}. It is for the native linker only.
252b5132 1320@item
ff5dcc92
SC
1321On SunOS, if the @option{-rpath} option was not used, search any
1322directories specified using @option{-L} options.
252b5132
RH
1323@item
1324For a native linker, the contents of the environment variable
1325@code{LD_LIBRARY_PATH}.
1326@item
ec4eb78a
L
1327For a native ELF linker, the directories in @code{DT_RUNPATH} or
1328@code{DT_RPATH} of a shared library are searched for shared
1329libraries needed by it. The @code{DT_RPATH} entries are ignored if
1330@code{DT_RUNPATH} entries exist.
1331@item
252b5132
RH
1332The default directories, normally @file{/lib} and @file{/usr/lib}.
1333@item
1334For a native linker on an ELF system, if the file @file{/etc/ld.so.conf}
1335exists, the list of directories found in that file.
1336@end enumerate
1337
1338If the required shared library is not found, the linker will issue a
1339warning and continue with the link.
1340@end ifset
1341
1342@kindex -shared
1343@kindex -Bshareable
1344@item -shared
1345@itemx -Bshareable
1346@cindex shared libraries
1347Create a shared library. This is currently only supported on ELF, XCOFF
1348and SunOS platforms. On SunOS, the linker will automatically create a
ff5dcc92 1349shared library if the @option{-e} option is not used and there are
252b5132
RH
1350undefined symbols in the link.
1351
1352@item --sort-common
1353@kindex --sort-common
ff5dcc92 1354This option tells @command{ld} to sort the common symbols by size when it
252b5132 1355places them in the appropriate output sections. First come all the one
563e308f 1356byte symbols, then all the two byte, then all the four byte, and then
252b5132
RH
1357everything else. This is to prevent gaps between symbols due to
1358alignment constraints.
1359
1360@kindex --split-by-file
a854a4a7 1361@item --split-by-file [@var{size}]
ff5dcc92 1362Similar to @option{--split-by-reloc} but creates a new output section for
a854a4a7
AM
1363each input file when @var{size} is reached. @var{size} defaults to a
1364size of 1 if not given.
252b5132
RH
1365
1366@kindex --split-by-reloc
a854a4a7
AM
1367@item --split-by-reloc [@var{count}]
1368Tries to creates extra sections in the output file so that no single
252b5132 1369output section in the file contains more than @var{count} relocations.
a854a4a7 1370This is useful when generating huge relocatable files for downloading into
252b5132
RH
1371certain real time kernels with the COFF object file format; since COFF
1372cannot represent more than 65535 relocations in a single section. Note
1373that this will fail to work with object file formats which do not
1374support arbitrary sections. The linker will not split up individual
1375input sections for redistribution, so if a single input section contains
1376more than @var{count} relocations one output section will contain that
a854a4a7 1377many relocations. @var{count} defaults to a value of 32768.
252b5132
RH
1378
1379@kindex --stats
1380@item --stats
1381Compute and display statistics about the operation of the linker, such
1382as execution time and memory usage.
1383
1384@kindex --traditional-format
1385@cindex traditional format
1386@item --traditional-format
ff5dcc92
SC
1387For some targets, the output of @command{ld} is different in some ways from
1388the output of some existing linker. This switch requests @command{ld} to
252b5132
RH
1389use the traditional format instead.
1390
1391@cindex dbx
ff5dcc92 1392For example, on SunOS, @command{ld} combines duplicate entries in the
252b5132
RH
1393symbol string table. This can reduce the size of an output file with
1394full debugging information by over 30 percent. Unfortunately, the SunOS
1395@code{dbx} program can not read the resulting program (@code{gdb} has no
ff5dcc92 1396trouble). The @samp{--traditional-format} switch tells @command{ld} to not
252b5132
RH
1397combine duplicate entries.
1398
176355da
NC
1399@kindex --section-start @var{sectionname}=@var{org}
1400@item --section-start @var{sectionname}=@var{org}
1401Locate a section in the output file at the absolute
1402address given by @var{org}. You may use this option as many
1403times as necessary to locate multiple sections in the command
1404line.
1405@var{org} must be a single hexadecimal integer;
1406for compatibility with other linkers, you may omit the leading
1407@samp{0x} usually associated with hexadecimal values. @emph{Note:} there
1408should be no white space between @var{sectionname}, the equals
1409sign (``@key{=}''), and @var{org}.
1410
252b5132
RH
1411@kindex -Tbss @var{org}
1412@kindex -Tdata @var{org}
1413@kindex -Ttext @var{org}
1414@cindex segment origins, cmd line
1415@item -Tbss @var{org}
1416@itemx -Tdata @var{org}
1417@itemx -Ttext @var{org}
1418Use @var{org} as the starting address for---respectively---the
1419@code{bss}, @code{data}, or the @code{text} segment of the output file.
1420@var{org} must be a single hexadecimal integer;
1421for compatibility with other linkers, you may omit the leading
1422@samp{0x} usually associated with hexadecimal values.
1423
1424@kindex --verbose
1425@cindex verbose
1426@item --dll-verbose
308b1ffd 1427@itemx --verbose
ff5dcc92 1428Display the version number for @command{ld} and list the linker emulations
252b5132 1429supported. Display which input files can and cannot be opened. Display
b9a8de1e 1430the linker script being used by the linker.
252b5132
RH
1431
1432@kindex --version-script=@var{version-scriptfile}
1433@cindex version script, symbol versions
1434@itemx --version-script=@var{version-scriptfile}
1435Specify the name of a version script to the linker. This is typically
1436used when creating shared libraries to specify additional information
1437about the version heirarchy for the library being created. This option
1438is only meaningful on ELF platforms which support shared libraries.
1439@xref{VERSION}.
1440
7ce691ae 1441@kindex --warn-common
252b5132
RH
1442@cindex warnings, on combining symbols
1443@cindex combining symbols, warnings on
1444@item --warn-common
1445Warn when a common symbol is combined with another common symbol or with
1446a symbol definition. Unix linkers allow this somewhat sloppy practice,
1447but linkers on some other operating systems do not. This option allows
1448you to find potential problems from combining global symbols.
1449Unfortunately, some C libraries use this practice, so you may get some
1450warnings about symbols in the libraries as well as in your programs.
1451
1452There are three kinds of global symbols, illustrated here by C examples:
1453
1454@table @samp
1455@item int i = 1;
1456A definition, which goes in the initialized data section of the output
1457file.
1458
1459@item extern int i;
1460An undefined reference, which does not allocate space.
1461There must be either a definition or a common symbol for the
1462variable somewhere.
1463
1464@item int i;
1465A common symbol. If there are only (one or more) common symbols for a
1466variable, it goes in the uninitialized data area of the output file.
1467The linker merges multiple common symbols for the same variable into a
1468single symbol. If they are of different sizes, it picks the largest
1469size. The linker turns a common symbol into a declaration, if there is
1470a definition of the same variable.
1471@end table
1472
1473The @samp{--warn-common} option can produce five kinds of warnings.
1474Each warning consists of a pair of lines: the first describes the symbol
1475just encountered, and the second describes the previous symbol
1476encountered with the same name. One or both of the two symbols will be
1477a common symbol.
1478
1479@enumerate
1480@item
1481Turning a common symbol into a reference, because there is already a
1482definition for the symbol.
1483@smallexample
1484@var{file}(@var{section}): warning: common of `@var{symbol}'
1485 overridden by definition
1486@var{file}(@var{section}): warning: defined here
1487@end smallexample
1488
1489@item
1490Turning a common symbol into a reference, because a later definition for
1491the symbol is encountered. This is the same as the previous case,
1492except that the symbols are encountered in a different order.
1493@smallexample
1494@var{file}(@var{section}): warning: definition of `@var{symbol}'
1495 overriding common
1496@var{file}(@var{section}): warning: common is here
1497@end smallexample
1498
1499@item
1500Merging a common symbol with a previous same-sized common symbol.
1501@smallexample
1502@var{file}(@var{section}): warning: multiple common
1503 of `@var{symbol}'
1504@var{file}(@var{section}): warning: previous common is here
1505@end smallexample
1506
1507@item
1508Merging a common symbol with a previous larger common symbol.
1509@smallexample
1510@var{file}(@var{section}): warning: common of `@var{symbol}'
1511 overridden by larger common
1512@var{file}(@var{section}): warning: larger common is here
1513@end smallexample
1514
1515@item
1516Merging a common symbol with a previous smaller common symbol. This is
1517the same as the previous case, except that the symbols are
1518encountered in a different order.
1519@smallexample
1520@var{file}(@var{section}): warning: common of `@var{symbol}'
1521 overriding smaller common
1522@var{file}(@var{section}): warning: smaller common is here
1523@end smallexample
1524@end enumerate
1525
1526@kindex --warn-constructors
1527@item --warn-constructors
1528Warn if any global constructors are used. This is only useful for a few
1529object file formats. For formats like COFF or ELF, the linker can not
1530detect the use of global constructors.
1531
1532@kindex --warn-multiple-gp
1533@item --warn-multiple-gp
1534Warn if multiple global pointer values are required in the output file.
1535This is only meaningful for certain processors, such as the Alpha.
1536Specifically, some processors put large-valued constants in a special
1537section. A special register (the global pointer) points into the middle
1538of this section, so that constants can be loaded efficiently via a
1539base-register relative addressing mode. Since the offset in
1540base-register relative mode is fixed and relatively small (e.g., 16
1541bits), this limits the maximum size of the constant pool. Thus, in
1542large programs, it is often necessary to use multiple global pointer
1543values in order to be able to address all possible constants. This
1544option causes a warning to be issued whenever this case occurs.
1545
1546@kindex --warn-once
1547@cindex warnings, on undefined symbols
1548@cindex undefined symbols, warnings on
1549@item --warn-once
1550Only warn once for each undefined symbol, rather than once per module
1551which refers to it.
1552
1553@kindex --warn-section-align
1554@cindex warnings, on section alignment
1555@cindex section alignment, warnings on
1556@item --warn-section-align
1557Warn if the address of an output section is changed because of
1558alignment. Typically, the alignment will be set by an input section.
1559The address will only be changed if it not explicitly specified; that
1560is, if the @code{SECTIONS} command does not specify a start address for
1561the section (@pxref{SECTIONS}).
1562
1563@kindex --whole-archive
1564@cindex including an entire archive
1565@item --whole-archive
1566For each archive mentioned on the command line after the
ff5dcc92 1567@option{--whole-archive} option, include every object file in the archive
252b5132
RH
1568in the link, rather than searching the archive for the required object
1569files. This is normally used to turn an archive file into a shared
1570library, forcing every object to be included in the resulting shared
1571library. This option may be used more than once.
1572
7ec229ce 1573Two notes when using this option from gcc: First, gcc doesn't know
ff5dcc92
SC
1574about this option, so you have to use @option{-Wl,-whole-archive}.
1575Second, don't forget to use @option{-Wl,-no-whole-archive} after your
7ec229ce
DD
1576list of archives, because gcc will add its own list of archives to
1577your link and you may not want this flag to affect those as well.
1578
252b5132
RH
1579@kindex --wrap
1580@item --wrap @var{symbol}
1581Use a wrapper function for @var{symbol}. Any undefined reference to
1582@var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any
1583undefined reference to @code{__real_@var{symbol}} will be resolved to
1584@var{symbol}.
1585
1586This can be used to provide a wrapper for a system function. The
1587wrapper function should be called @code{__wrap_@var{symbol}}. If it
1588wishes to call the system function, it should call
1589@code{__real_@var{symbol}}.
1590
1591Here is a trivial example:
1592
1593@smallexample
1594void *
1595__wrap_malloc (int c)
1596@{
1597 printf ("malloc called with %ld\n", c);
1598 return __real_malloc (c);
1599@}
1600@end smallexample
1601
ff5dcc92 1602If you link other code with this file using @option{--wrap malloc}, then
252b5132
RH
1603all calls to @code{malloc} will call the function @code{__wrap_malloc}
1604instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will
1605call the real @code{malloc} function.
1606
1607You may wish to provide a @code{__real_malloc} function as well, so that
ff5dcc92 1608links without the @option{--wrap} option will succeed. If you do this,
252b5132
RH
1609you should not put the definition of @code{__real_malloc} in the same
1610file as @code{__wrap_malloc}; if you do, the assembler may resolve the
1611call before the linker has a chance to wrap it to @code{malloc}.
1612
6c1439be
L
1613@kindex --enable-new-dtags
1614@kindex --disable-new-dtags
1615@item --enable-new-dtags
1616@itemx --disable-new-dtags
1617This linker can create the new dynamic tags in ELF. But the older ELF
1618systems may not understand them. If you specify
ff5dcc92
SC
1619@option{--enable-new-dtags}, the dynamic tags will be created as needed.
1620If you specify @option{--disable-new-dtags}, no new dynamic tags will be
6c1439be
L
1621created. By default, the new dynamic tags are not created. Note that
1622those options are only available for ELF systems.
1623
252b5132
RH
1624@end table
1625
0285c67d
NC
1626@c man end
1627
252b5132
RH
1628@subsection Options specific to i386 PE targets
1629
0285c67d
NC
1630@c man begin OPTIONS
1631
ff5dcc92 1632The i386 PE linker supports the @option{-shared} option, which causes
252b5132
RH
1633the output to be a dynamically linked library (DLL) instead of a
1634normal executable. You should name the output @code{*.dll} when you
1635use this option. In addition, the linker fully supports the standard
1636@code{*.def} files, which may be specified on the linker command line
1637like an object file (in fact, it should precede archives it exports
1638symbols from, to ensure that they get linked in, just like a normal
1639object file).
1640
1641In addition to the options common to all targets, the i386 PE linker
1642support additional command line options that are specific to the i386
1643PE target. Options that take values may be separated from their
1644values by either a space or an equals sign.
1645
ff5dcc92 1646@table @gcctabopt
252b5132
RH
1647
1648@kindex --add-stdcall-alias
1649@item --add-stdcall-alias
1650If given, symbols with a stdcall suffix (@@@var{nn}) will be exported
1651as-is and also with the suffix stripped.
1652
1653@kindex --base-file
1654@item --base-file @var{file}
1655Use @var{file} as the name of a file in which to save the base
1656addresses of all the relocations needed for generating DLLs with
1657@file{dlltool}.
1658
1659@kindex --dll
1660@item --dll
1661Create a DLL instead of a regular executable. You may also use
ff5dcc92 1662@option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
252b5132
RH
1663file.
1664
1665@kindex --enable-stdcall-fixup
1666@kindex --disable-stdcall-fixup
1667@item --enable-stdcall-fixup
1668@itemx --disable-stdcall-fixup
1669If the link finds a symbol that it cannot resolve, it will attempt to
1670do "fuzzy linking" by looking for another defined symbol that differs
1671only in the format of the symbol name (cdecl vs stdcall) and will
1672resolve that symbol by linking to the match. For example, the
1673undefined symbol @code{_foo} might be linked to the function
1674@code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
1675to the function @code{_bar}. When the linker does this, it prints a
1676warning, since it normally should have failed to link, but sometimes
1677import libraries generated from third-party dlls may need this feature
ff5dcc92 1678to be usable. If you specify @option{--enable-stdcall-fixup}, this
252b5132 1679feature is fully enabled and warnings are not printed. If you specify
ff5dcc92 1680@option{--disable-stdcall-fixup}, this feature is disabled and such
252b5132
RH
1681mismatches are considered to be errors.
1682
1683@cindex DLLs, creating
1684@kindex --export-all-symbols
1685@item --export-all-symbols
1686If given, all global symbols in the objects used to build a DLL will
1687be exported by the DLL. Note that this is the default if there
1688otherwise wouldn't be any exported symbols. When symbols are
1689explicitly exported via DEF files or implicitly exported via function
1690attributes, the default is to not export anything else unless this
1691option is given. Note that the symbols @code{DllMain@@12},
b044cda1
CW
1692@code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
1693@code{impure_ptr} will not be automatically
1694exported. Also, symbols imported from other DLLs will not be
1695re-exported, nor will symbols specifying the DLL's internal layout
1696such as those beginning with @code{_head_} or ending with
1697@code{_iname}. In addition, no symbols from @code{libgcc},
1698@code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
1699Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will
1700not be exported, to help with C++ DLLs. Finally, there is an
1701extensive list of cygwin-private symbols that are not exported
1702(obviously, this applies on when building DLLs for cygwin targets).
1703These cygwin-excludes are: @code{_cygwin_dll_entry@@12},
1704@code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
1705@code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
1706@code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
1707@code{cygwin_premain3}, and @code{environ}.
252b5132
RH
1708
1709@kindex --exclude-symbols
1d0a3c9c 1710@item --exclude-symbols @var{symbol},@var{symbol},...
252b5132
RH
1711Specifies a list of symbols which should not be automatically
1712exported. The symbol names may be delimited by commas or colons.
1713
70b0be79
CF
1714@kindex --exclude-libs
1715@item --exclude-libs @var{lib},@var{lib},...
1716Specifies a list of archive libraries from which symbols should not be automatically
1717exported. The library names may be delimited by commas or colons. Specifying
1718@code{--exclude-libs ALL} excludes symbols in all archive libraries from
1719automatic export. Symbols explicitly listed in a .def file are still exported,
1720regardless of this option.
1721
252b5132
RH
1722@kindex --file-alignment
1723@item --file-alignment
1724Specify the file alignment. Sections in the file will always begin at
1725file offsets which are multiples of this number. This defaults to
1726512.
1727
1728@cindex heap size
1729@kindex --heap
1730@item --heap @var{reserve}
1731@itemx --heap @var{reserve},@var{commit}
1732Specify the amount of memory to reserve (and optionally commit) to be
1733used as heap for this program. The default is 1Mb reserved, 4K
1734committed.
1735
1736@cindex image base
1737@kindex --image-base
1738@item --image-base @var{value}
1739Use @var{value} as the base address of your program or dll. This is
1740the lowest memory location that will be used when your program or dll
1741is loaded. To reduce the need to relocate and improve performance of
1742your dlls, each should have a unique base address and not overlap any
1743other dlls. The default is 0x400000 for executables, and 0x10000000
1744for dlls.
1745
1746@kindex --kill-at
1747@item --kill-at
1748If given, the stdcall suffixes (@@@var{nn}) will be stripped from
1749symbols before they are exported.
1750
1751@kindex --major-image-version
1752@item --major-image-version @var{value}
1753Sets the major number of the "image version". Defaults to 1.
1754
1755@kindex --major-os-version
1756@item --major-os-version @var{value}
1757Sets the major number of the "os version". Defaults to 4.
1758
1759@kindex --major-subsystem-version
1760@item --major-subsystem-version @var{value}
1761Sets the major number of the "subsystem version". Defaults to 4.
1762
1763@kindex --minor-image-version
1764@item --minor-image-version @var{value}
1765Sets the minor number of the "image version". Defaults to 0.
1766
1767@kindex --minor-os-version
1768@item --minor-os-version @var{value}
1769Sets the minor number of the "os version". Defaults to 0.
1770
1771@kindex --minor-subsystem-version
1772@item --minor-subsystem-version @var{value}
1773Sets the minor number of the "subsystem version". Defaults to 0.
1774
1775@cindex DEF files, creating
1776@cindex DLLs, creating
1777@kindex --output-def
1778@item --output-def @var{file}
1779The linker will create the file @var{file} which will contain a DEF
1780file corresponding to the DLL the linker is generating. This DEF file
1781(which should be called @code{*.def}) may be used to create an import
1782library with @code{dlltool} or may be used as a reference to
1783automatically or implicitly exported symbols.
1784
b044cda1
CW
1785@cindex DLLs, creating
1786@kindex --out-implib
1787@item --out-implib @var{file}
1788The linker will create the file @var{file} which will contain an
1789import lib corresponding to the DLL the linker is generating. This
1790import lib (which should be called @code{*.dll.a} or @code{*.a}
1791may be used to link clients against the generated DLL; this behavior
1792makes it possible to skip a separate @code{dlltool} import library
1793creation step.
1794
1795@kindex --enable-auto-image-base
1796@item --enable-auto-image-base
1797Automatically choose the image base for DLLs, unless one is specified
1798using the @code{--image-base} argument. By using a hash generated
1799from the dllname to create unique image bases for each DLL, in-memory
1800collisions and relocations which can delay program execution are
1801avoided.
1802
1803@kindex --disable-auto-image-base
1804@item --disable-auto-image-base
1805Do not automatically generate a unique image base. If there is no
1806user-specified image base (@code{--image-base}) then use the platform
1807default.
1808
1809@cindex DLLs, linking to
1810@kindex --dll-search-prefix
1811@item --dll-search-prefix @var{string}
489d0400 1812When linking dynamically to a dll without an import library,
b044cda1
CW
1813search for @code{<string><basename>.dll} in preference to
1814@code{lib<basename>.dll}. This behavior allows easy distinction
1815between DLLs built for the various "subplatforms": native, cygwin,
1816uwin, pw, etc. For instance, cygwin DLLs typically use
1817@code{--dll-search-prefix=cyg}.
1818
1819@kindex --enable-auto-import
1820@item --enable-auto-import
0d888aac 1821Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
b044cda1 1822DATA imports from DLLs, and create the necessary thunking symbols when
2ca22b03
NC
1823building the import libraries with those DATA exports. This generally
1824will 'just work' -- but sometimes you may see this message:
0d888aac
CW
1825
1826"variable '<var>' can't be auto-imported. Please read the
1827documentation for ld's @code{--enable-auto-import} for details."
1828
1829This message occurs when some (sub)expression accesses an address
1830ultimately given by the sum of two constants (Win32 import tables only
1831allow one). Instances where this may occur include accesses to member
1832fields of struct variables imported from a DLL, as well as using a
2f8d8971
NC
1833constant index into an array variable imported from a DLL. Any
1834multiword variable (arrays, structs, long long, etc) may trigger
1835this error condition. However, regardless of the exact data type
1836of the offending exported variable, ld will always detect it, issue
1837the warning, and exit.
1838
1839There are several ways to address this difficulty, regardless of the
1840data type of the exported variable:
0d888aac 1841
2fa9fc65
NC
1842One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
1843of adjusting references in your client code for runtime environment, so
1844this method works only when runtime environtment supports this feature.
1845
1846A second solution is to force one of the 'constants' to be a variable --
0d888aac
CW
1847that is, unknown and un-optimizable at compile time. For arrays,
1848there are two possibilities: a) make the indexee (the array's address)
1849a variable, or b) make the 'constant' index a variable. Thus:
1850
1851@example
1852extern type extern_array[];
1853extern_array[1] -->
1854 @{ volatile type *t=extern_array; t[1] @}
1855@end example
1856
1857or
1858
1859@example
1860extern type extern_array[];
1861extern_array[1] -->
1862 @{ volatile int t=1; extern_array[t] @}
1863@end example
1864
2f8d8971
NC
1865For structs (and most other multiword data types) the only option
1866is to make the struct itself (or the long long, or the ...) variable:
0d888aac
CW
1867
1868@example
1869extern struct s extern_struct;
1870extern_struct.field -->
1871 @{ volatile struct s *t=&extern_struct; t->field @}
1872@end example
1873
c406afaf
NC
1874or
1875
1876@example
1877extern long long extern_ll;
1878extern_ll -->
1879 @{ volatile long long * local_ll=&extern_ll; *local_ll @}
1880@end example
1881
2fa9fc65 1882A third method of dealing with this difficulty is to abandon
0d888aac
CW
1883'auto-import' for the offending symbol and mark it with
1884@code{__declspec(dllimport)}. However, in practice that
1885requires using compile-time #defines to indicate whether you are
1886building a DLL, building client code that will link to the DLL, or
1887merely building/linking to a static library. In making the choice
1888between the various methods of resolving the 'direct address with
1889constant offset' problem, you should consider typical real-world usage:
1890
1891Original:
1892@example
1893--foo.h
1894extern int arr[];
1895--foo.c
1896#include "foo.h"
1897void main(int argc, char **argv)@{
1898 printf("%d\n",arr[1]);
1899@}
1900@end example
1901
1902Solution 1:
1903@example
1904--foo.h
1905extern int arr[];
1906--foo.c
1907#include "foo.h"
1908void main(int argc, char **argv)@{
1909 /* This workaround is for win32 and cygwin; do not "optimize" */
1910 volatile int *parr = arr;
1911 printf("%d\n",parr[1]);
1912@}
1913@end example
1914
1915Solution 2:
1916@example
1917--foo.h
1918/* Note: auto-export is assumed (no __declspec(dllexport)) */
1919#if (defined(_WIN32) || defined(__CYGWIN__)) && \
1920 !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
1921#define FOO_IMPORT __declspec(dllimport)
1922#else
1923#define FOO_IMPORT
1924#endif
1925extern FOO_IMPORT int arr[];
1926--foo.c
1927#include "foo.h"
1928void main(int argc, char **argv)@{
1929 printf("%d\n",arr[1]);
1930@}
1931@end example
1932
2fa9fc65 1933A fourth way to avoid this problem is to re-code your
0d888aac
CW
1934library to use a functional interface rather than a data interface
1935for the offending variables (e.g. set_foo() and get_foo() accessor
1936functions).
b044cda1
CW
1937
1938@kindex --disable-auto-import
1939@item --disable-auto-import
1940Do not attempt to do sophisticalted linking of @code{_symbol} to
1941@code{__imp__symbol} for DATA imports from DLLs.
1942
2fa9fc65
NC
1943@kindex --enable-runtime-pseudo-reloc
1944@item --enable-runtime-pseudo-reloc
1945If your code contains expressions described in --enable-auto-import section,
1946that is, DATA imports from DLL with non-zero offset, this switch will create
1947a vector of 'runtime pseudo relocations' which can be used by runtime
1948environment to adjust references to such data in your client code.
1949
1950@kindex --disable-runtime-pseudo-reloc
1951@item --disable-runtime-pseudo-reloc
1952Do not create pseudo relocations for non-zero offset DATA imports from
1953DLLs. This is the default.
1954
b044cda1
CW
1955@kindex --enable-extra-pe-debug
1956@item --enable-extra-pe-debug
1957Show additional debug info related to auto-import symbol thunking.
1958
252b5132
RH
1959@kindex --section-alignment
1960@item --section-alignment
1961Sets the section alignment. Sections in memory will always begin at
1962addresses which are a multiple of this number. Defaults to 0x1000.
1963
1964@cindex stack size
1965@kindex --stack
1966@item --stack @var{reserve}
1967@itemx --stack @var{reserve},@var{commit}
1968Specify the amount of memory to reserve (and optionally commit) to be
559e4713 1969used as stack for this program. The default is 2Mb reserved, 4K
252b5132
RH
1970committed.
1971
1972@kindex --subsystem
1973@item --subsystem @var{which}
1974@itemx --subsystem @var{which}:@var{major}
1975@itemx --subsystem @var{which}:@var{major}.@var{minor}
1976Specifies the subsystem under which your program will execute. The
1977legal values for @var{which} are @code{native}, @code{windows},
1978@code{console}, and @code{posix}. You may optionally set the
1979subsystem version also.
1980
1981@end table
1982
0285c67d
NC
1983@c man end
1984
252b5132
RH
1985@ifset UsesEnvVars
1986@node Environment
1987@section Environment Variables
1988
0285c67d
NC
1989@c man begin ENVIRONMENT
1990
ff5dcc92 1991You can change the behavior of @command{ld} with the environment variables
252b5132
RH
1992@code{GNUTARGET}, @code{LDEMULATION}, and @code{COLLECT_NO_DEMANGLE}.
1993
1994@kindex GNUTARGET
1995@cindex default input format
1996@code{GNUTARGET} determines the input-file object format if you don't
1997use @samp{-b} (or its synonym @samp{--format}). Its value should be one
1998of the BFD names for an input format (@pxref{BFD}). If there is no
ff5dcc92 1999@code{GNUTARGET} in the environment, @command{ld} uses the natural format
252b5132
RH
2000of the target. If @code{GNUTARGET} is set to @code{default} then BFD
2001attempts to discover the input format by examining binary input files;
2002this method often succeeds, but there are potential ambiguities, since
2003there is no method of ensuring that the magic number used to specify
2004object-file formats is unique. However, the configuration procedure for
2005BFD on each system places the conventional format for that system first
2006in the search-list, so ambiguities are resolved in favor of convention.
2007
2008@kindex LDEMULATION
2009@cindex default emulation
2010@cindex emulation, default
2011@code{LDEMULATION} determines the default emulation if you don't use the
2012@samp{-m} option. The emulation can affect various aspects of linker
2013behaviour, particularly the default linker script. You can list the
2014available emulations with the @samp{--verbose} or @samp{-V} options. If
2015the @samp{-m} option is not used, and the @code{LDEMULATION} environment
2016variable is not defined, the default emulation depends upon how the
2017linker was configured.
252b5132
RH
2018
2019@kindex COLLECT_NO_DEMANGLE
2020@cindex demangling, default
2021Normally, the linker will default to demangling symbols. However, if
2022@code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
2023default to not demangling symbols. This environment variable is used in
2024a similar fashion by the @code{gcc} linker wrapper program. The default
2025may be overridden by the @samp{--demangle} and @samp{--no-demangle}
2026options.
2027
0285c67d
NC
2028@c man end
2029@end ifset
2030
252b5132
RH
2031@node Scripts
2032@chapter Linker Scripts
2033
2034@cindex scripts
2035@cindex linker scripts
2036@cindex command files
2037Every link is controlled by a @dfn{linker script}. This script is
2038written in the linker command language.
2039
2040The main purpose of the linker script is to describe how the sections in
2041the input files should be mapped into the output file, and to control
2042the memory layout of the output file. Most linker scripts do nothing
2043more than this. However, when necessary, the linker script can also
2044direct the linker to perform many other operations, using the commands
2045described below.
2046
2047The linker always uses a linker script. If you do not supply one
2048yourself, the linker will use a default script that is compiled into the
2049linker executable. You can use the @samp{--verbose} command line option
2050to display the default linker script. Certain command line options,
2051such as @samp{-r} or @samp{-N}, will affect the default linker script.
2052
2053You may supply your own linker script by using the @samp{-T} command
2054line option. When you do this, your linker script will replace the
2055default linker script.
2056
2057You may also use linker scripts implicitly by naming them as input files
2058to the linker, as though they were files to be linked. @xref{Implicit
2059Linker Scripts}.
2060
2061@menu
2062* Basic Script Concepts:: Basic Linker Script Concepts
2063* Script Format:: Linker Script Format
2064* Simple Example:: Simple Linker Script Example
2065* Simple Commands:: Simple Linker Script Commands
2066* Assignments:: Assigning Values to Symbols
2067* SECTIONS:: SECTIONS Command
2068* MEMORY:: MEMORY Command
2069* PHDRS:: PHDRS Command
2070* VERSION:: VERSION Command
2071* Expressions:: Expressions in Linker Scripts
2072* Implicit Linker Scripts:: Implicit Linker Scripts
2073@end menu
2074
2075@node Basic Script Concepts
2076@section Basic Linker Script Concepts
2077@cindex linker script concepts
2078We need to define some basic concepts and vocabulary in order to
2079describe the linker script language.
2080
2081The linker combines input files into a single output file. The output
2082file and each input file are in a special data format known as an
2083@dfn{object file format}. Each file is called an @dfn{object file}.
2084The output file is often called an @dfn{executable}, but for our
2085purposes we will also call it an object file. Each object file has,
2086among other things, a list of @dfn{sections}. We sometimes refer to a
2087section in an input file as an @dfn{input section}; similarly, a section
2088in the output file is an @dfn{output section}.
2089
2090Each section in an object file has a name and a size. Most sections
2091also have an associated block of data, known as the @dfn{section
2092contents}. A section may be marked as @dfn{loadable}, which mean that
2093the contents should be loaded into memory when the output file is run.
2094A section with no contents may be @dfn{allocatable}, which means that an
2095area in memory should be set aside, but nothing in particular should be
2096loaded there (in some cases this memory must be zeroed out). A section
2097which is neither loadable nor allocatable typically contains some sort
2098of debugging information.
2099
2100Every loadable or allocatable output section has two addresses. The
2101first is the @dfn{VMA}, or virtual memory address. This is the address
2102the section will have when the output file is run. The second is the
2103@dfn{LMA}, or load memory address. This is the address at which the
2104section will be loaded. In most cases the two addresses will be the
2105same. An example of when they might be different is when a data section
2106is loaded into ROM, and then copied into RAM when the program starts up
2107(this technique is often used to initialize global variables in a ROM
2108based system). In this case the ROM address would be the LMA, and the
2109RAM address would be the VMA.
2110
2111You can see the sections in an object file by using the @code{objdump}
2112program with the @samp{-h} option.
2113
2114Every object file also has a list of @dfn{symbols}, known as the
2115@dfn{symbol table}. A symbol may be defined or undefined. Each symbol
2116has a name, and each defined symbol has an address, among other
2117information. If you compile a C or C++ program into an object file, you
2118will get a defined symbol for every defined function and global or
2119static variable. Every undefined function or global variable which is
2120referenced in the input file will become an undefined symbol.
2121
2122You can see the symbols in an object file by using the @code{nm}
2123program, or by using the @code{objdump} program with the @samp{-t}
2124option.
2125
2126@node Script Format
2127@section Linker Script Format
2128@cindex linker script format
2129Linker scripts are text files.
2130
2131You write a linker script as a series of commands. Each command is
2132either a keyword, possibly followed by arguments, or an assignment to a
2133symbol. You may separate commands using semicolons. Whitespace is
2134generally ignored.
2135
2136Strings such as file or format names can normally be entered directly.
2137If the file name contains a character such as a comma which would
2138otherwise serve to separate file names, you may put the file name in
2139double quotes. There is no way to use a double quote character in a
2140file name.
2141
2142You may include comments in linker scripts just as in C, delimited by
2143@samp{/*} and @samp{*/}. As in C, comments are syntactically equivalent
2144to whitespace.
2145
2146@node Simple Example
2147@section Simple Linker Script Example
2148@cindex linker script example
2149@cindex example of linker script
2150Many linker scripts are fairly simple.
2151
2152The simplest possible linker script has just one command:
2153@samp{SECTIONS}. You use the @samp{SECTIONS} command to describe the
2154memory layout of the output file.
2155
2156The @samp{SECTIONS} command is a powerful command. Here we will
2157describe a simple use of it. Let's assume your program consists only of
2158code, initialized data, and uninitialized data. These will be in the
2159@samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
2160Let's assume further that these are the only sections which appear in
2161your input files.
2162
2163For this example, let's say that the code should be loaded at address
21640x10000, and that the data should start at address 0x8000000. Here is a
2165linker script which will do that:
2166@smallexample
2167SECTIONS
2168@{
2169 . = 0x10000;
2170 .text : @{ *(.text) @}
2171 . = 0x8000000;
2172 .data : @{ *(.data) @}
2173 .bss : @{ *(.bss) @}
2174@}
2175@end smallexample
2176
2177You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
2178followed by a series of symbol assignments and output section
2179descriptions enclosed in curly braces.
2180
252b5132
RH
2181The first line inside the @samp{SECTIONS} command of the above example
2182sets the value of the special symbol @samp{.}, which is the location
2183counter. If you do not specify the address of an output section in some
2184other way (other ways are described later), the address is set from the
2185current value of the location counter. The location counter is then
2186incremented by the size of the output section. At the start of the
2187@samp{SECTIONS} command, the location counter has the value @samp{0}.
2188
2189The second line defines an output section, @samp{.text}. The colon is
2190required syntax which may be ignored for now. Within the curly braces
2191after the output section name, you list the names of the input sections
2192which should be placed into this output section. The @samp{*} is a
2193wildcard which matches any file name. The expression @samp{*(.text)}
2194means all @samp{.text} input sections in all input files.
2195
2196Since the location counter is @samp{0x10000} when the output section
2197@samp{.text} is defined, the linker will set the address of the
2198@samp{.text} section in the output file to be @samp{0x10000}.
2199
2200The remaining lines define the @samp{.data} and @samp{.bss} sections in
2201the output file. The linker will place the @samp{.data} output section
2202at address @samp{0x8000000}. After the linker places the @samp{.data}
2203output section, the value of the location counter will be
2204@samp{0x8000000} plus the size of the @samp{.data} output section. The
2205effect is that the linker will place the @samp{.bss} output section
2206immediately after the @samp{.data} output section in memory
2207
2208The linker will ensure that each output section has the required
2209alignment, by increasing the location counter if necessary. In this
2210example, the specified addresses for the @samp{.text} and @samp{.data}
2211sections will probably satisfy any alignment constraints, but the linker
2212may have to create a small gap between the @samp{.data} and @samp{.bss}
2213sections.
2214
2215That's it! That's a simple and complete linker script.
2216
2217@node Simple Commands
2218@section Simple Linker Script Commands
2219@cindex linker script simple commands
2220In this section we describe the simple linker script commands.
2221
2222@menu
2223* Entry Point:: Setting the entry point
2224* File Commands:: Commands dealing with files
2225@ifclear SingleFormat
2226* Format Commands:: Commands dealing with object file formats
2227@end ifclear
2228
2229* Miscellaneous Commands:: Other linker script commands
2230@end menu
2231
2232@node Entry Point
2233@subsection Setting the entry point
2234@kindex ENTRY(@var{symbol})
2235@cindex start of execution
2236@cindex first instruction
2237@cindex entry point
2238The first instruction to execute in a program is called the @dfn{entry
2239point}. You can use the @code{ENTRY} linker script command to set the
2240entry point. The argument is a symbol name:
2241@smallexample
2242ENTRY(@var{symbol})
2243@end smallexample
2244
2245There are several ways to set the entry point. The linker will set the
2246entry point by trying each of the following methods in order, and
2247stopping when one of them succeeds:
2248@itemize @bullet
a1ab1d2a 2249@item
252b5132 2250the @samp{-e} @var{entry} command-line option;
a1ab1d2a 2251@item
252b5132 2252the @code{ENTRY(@var{symbol})} command in a linker script;
a1ab1d2a 2253@item
252b5132 2254the value of the symbol @code{start}, if defined;
a1ab1d2a 2255@item
252b5132 2256the address of the first byte of the @samp{.text} section, if present;
a1ab1d2a 2257@item
252b5132
RH
2258The address @code{0}.
2259@end itemize
2260
2261@node File Commands
2262@subsection Commands dealing with files
2263@cindex linker script file commands
2264Several linker script commands deal with files.
2265
2266@table @code
2267@item INCLUDE @var{filename}
2268@kindex INCLUDE @var{filename}
2269@cindex including a linker script
2270Include the linker script @var{filename} at this point. The file will
2271be searched for in the current directory, and in any directory specified
ff5dcc92 2272with the @option{-L} option. You can nest calls to @code{INCLUDE} up to
252b5132
RH
227310 levels deep.
2274
2275@item INPUT(@var{file}, @var{file}, @dots{})
2276@itemx INPUT(@var{file} @var{file} @dots{})
2277@kindex INPUT(@var{files})
2278@cindex input files in linker scripts
2279@cindex input object files in linker scripts
2280@cindex linker script input object files
2281The @code{INPUT} command directs the linker to include the named files
2282in the link, as though they were named on the command line.
2283
2284For example, if you always want to include @file{subr.o} any time you do
2285a link, but you can't be bothered to put it on every link command line,
2286then you can put @samp{INPUT (subr.o)} in your linker script.
2287
2288In fact, if you like, you can list all of your input files in the linker
2289script, and then invoke the linker with nothing but a @samp{-T} option.
2290
2291The linker will first try to open the file in the current directory. If
2292it is not found, the linker will search through the archive library
2293search path. See the description of @samp{-L} in @ref{Options,,Command
2294Line Options}.
2295
ff5dcc92 2296If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
252b5132
RH
2297name to @code{lib@var{file}.a}, as with the command line argument
2298@samp{-l}.
2299
2300When you use the @code{INPUT} command in an implicit linker script, the
2301files will be included in the link at the point at which the linker
2302script file is included. This can affect archive searching.
2303
2304@item GROUP(@var{file}, @var{file}, @dots{})
2305@itemx GROUP(@var{file} @var{file} @dots{})
2306@kindex GROUP(@var{files})
2307@cindex grouping input files
2308The @code{GROUP} command is like @code{INPUT}, except that the named
2309files should all be archives, and they are searched repeatedly until no
2310new undefined references are created. See the description of @samp{-(}
2311in @ref{Options,,Command Line Options}.
2312
2313@item OUTPUT(@var{filename})
2314@kindex OUTPUT(@var{filename})
2315@cindex output file name in linker scripot
2316The @code{OUTPUT} command names the output file. Using
2317@code{OUTPUT(@var{filename})} in the linker script is exactly like using
2318@samp{-o @var{filename}} on the command line (@pxref{Options,,Command
2319Line Options}). If both are used, the command line option takes
2320precedence.
2321
2322You can use the @code{OUTPUT} command to define a default name for the
2323output file other than the usual default of @file{a.out}.
2324
2325@item SEARCH_DIR(@var{path})
2326@kindex SEARCH_DIR(@var{path})
2327@cindex library search path in linker script
2328@cindex archive search path in linker script
2329@cindex search path in linker script
2330The @code{SEARCH_DIR} command adds @var{path} to the list of paths where
ff5dcc92 2331@command{ld} looks for archive libraries. Using
252b5132
RH
2332@code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
2333on the command line (@pxref{Options,,Command Line Options}). If both
2334are used, then the linker will search both paths. Paths specified using
2335the command line option are searched first.
2336
2337@item STARTUP(@var{filename})
2338@kindex STARTUP(@var{filename})
2339@cindex first input file
2340The @code{STARTUP} command is just like the @code{INPUT} command, except
2341that @var{filename} will become the first input file to be linked, as
2342though it were specified first on the command line. This may be useful
2343when using a system in which the entry point is always the start of the
2344first file.
2345@end table
2346
2347@ifclear SingleFormat
2348@node Format Commands
2349@subsection Commands dealing with object file formats
2350A couple of linker script commands deal with object file formats.
2351
2352@table @code
2353@item OUTPUT_FORMAT(@var{bfdname})
2354@itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
2355@kindex OUTPUT_FORMAT(@var{bfdname})
2356@cindex output file format in linker script
2357The @code{OUTPUT_FORMAT} command names the BFD format to use for the
2358output file (@pxref{BFD}). Using @code{OUTPUT_FORMAT(@var{bfdname})} is
024531e2 2359exactly like using @samp{--oformat @var{bfdname}} on the command line
252b5132
RH
2360(@pxref{Options,,Command Line Options}). If both are used, the command
2361line option takes precedence.
2362
2363You can use @code{OUTPUT_FORMAT} with three arguments to use different
2364formats based on the @samp{-EB} and @samp{-EL} command line options.
2365This permits the linker script to set the output format based on the
2366desired endianness.
2367
2368If neither @samp{-EB} nor @samp{-EL} are used, then the output format
2369will be the first argument, @var{default}. If @samp{-EB} is used, the
2370output format will be the second argument, @var{big}. If @samp{-EL} is
2371used, the output format will be the third argument, @var{little}.
2372
2373For example, the default linker script for the MIPS ELF target uses this
2374command:
2375@smallexample
2376OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
2377@end smallexample
2378This says that the default format for the output file is
2379@samp{elf32-bigmips}, but if the user uses the @samp{-EL} command line
2380option, the output file will be created in the @samp{elf32-littlemips}
2381format.
2382
2383@item TARGET(@var{bfdname})
2384@kindex TARGET(@var{bfdname})
2385@cindex input file format in linker script
2386The @code{TARGET} command names the BFD format to use when reading input
2387files. It affects subsequent @code{INPUT} and @code{GROUP} commands.
2388This command is like using @samp{-b @var{bfdname}} on the command line
2389(@pxref{Options,,Command Line Options}). If the @code{TARGET} command
2390is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
2391command is also used to set the format for the output file. @xref{BFD}.
2392@end table
2393@end ifclear
2394
2395@node Miscellaneous Commands
2396@subsection Other linker script commands
2397There are a few other linker scripts commands.
2398
2399@table @code
2400@item ASSERT(@var{exp}, @var{message})
2401@kindex ASSERT
2402@cindex assertion in linker script
2403Ensure that @var{exp} is non-zero. If it is zero, then exit the linker
2404with an error code, and print @var{message}.
2405
2406@item EXTERN(@var{symbol} @var{symbol} @dots{})
2407@kindex EXTERN
2408@cindex undefined symbol in linker script
2409Force @var{symbol} to be entered in the output file as an undefined
2410symbol. Doing this may, for example, trigger linking of additional
2411modules from standard libraries. You may list several @var{symbol}s for
2412each @code{EXTERN}, and you may use @code{EXTERN} multiple times. This
2413command has the same effect as the @samp{-u} command-line option.
2414
2415@item FORCE_COMMON_ALLOCATION
2416@kindex FORCE_COMMON_ALLOCATION
2417@cindex common allocation in linker script
2418This command has the same effect as the @samp{-d} command-line option:
ff5dcc92 2419to make @command{ld} assign space to common symbols even if a relocatable
252b5132
RH
2420output file is specified (@samp{-r}).
2421
4818e05f
AM
2422@item INHIBIT_COMMON_ALLOCATION
2423@kindex INHIBIT_COMMON_ALLOCATION
2424@cindex common allocation in linker script
2425This command has the same effect as the @samp{--no-define-common}
2426command-line option: to make @code{ld} omit the assignment of addresses
2427to common symbols even for a non-relocatable output file.
2428
252b5132
RH
2429@item NOCROSSREFS(@var{section} @var{section} @dots{})
2430@kindex NOCROSSREFS(@var{sections})
2431@cindex cross references
ff5dcc92 2432This command may be used to tell @command{ld} to issue an error about any
252b5132
RH
2433references among certain output sections.
2434
2435In certain types of programs, particularly on embedded systems when
2436using overlays, when one section is loaded into memory, another section
2437will not be. Any direct references between the two sections would be
2438errors. For example, it would be an error if code in one section called
2439a function defined in the other section.
2440
2441The @code{NOCROSSREFS} command takes a list of output section names. If
ff5dcc92 2442@command{ld} detects any cross references between the sections, it reports
252b5132
RH
2443an error and returns a non-zero exit status. Note that the
2444@code{NOCROSSREFS} command uses output section names, not input section
2445names.
2446
2447@ifclear SingleFormat
2448@item OUTPUT_ARCH(@var{bfdarch})
2449@kindex OUTPUT_ARCH(@var{bfdarch})
2450@cindex machine architecture
2451@cindex architecture
2452Specify a particular output machine architecture. The argument is one
2453of the names used by the BFD library (@pxref{BFD}). You can see the
2454architecture of an object file by using the @code{objdump} program with
2455the @samp{-f} option.
2456@end ifclear
2457@end table
2458
2459@node Assignments
2460@section Assigning Values to Symbols
2461@cindex assignment in scripts
2462@cindex symbol definition, scripts
2463@cindex variables, defining
2464You may assign a value to a symbol in a linker script. This will define
2465the symbol as a global symbol.
2466
2467@menu
2468* Simple Assignments:: Simple Assignments
2469* PROVIDE:: PROVIDE
2470@end menu
2471
2472@node Simple Assignments
2473@subsection Simple Assignments
2474
2475You may assign to a symbol using any of the C assignment operators:
2476
2477@table @code
2478@item @var{symbol} = @var{expression} ;
2479@itemx @var{symbol} += @var{expression} ;
2480@itemx @var{symbol} -= @var{expression} ;
2481@itemx @var{symbol} *= @var{expression} ;
2482@itemx @var{symbol} /= @var{expression} ;
2483@itemx @var{symbol} <<= @var{expression} ;
2484@itemx @var{symbol} >>= @var{expression} ;
2485@itemx @var{symbol} &= @var{expression} ;
2486@itemx @var{symbol} |= @var{expression} ;
2487@end table
2488
2489The first case will define @var{symbol} to the value of
2490@var{expression}. In the other cases, @var{symbol} must already be
2491defined, and the value will be adjusted accordingly.
2492
2493The special symbol name @samp{.} indicates the location counter. You
2494may only use this within a @code{SECTIONS} command.
2495
2496The semicolon after @var{expression} is required.
2497
2498Expressions are defined below; see @ref{Expressions}.
2499
2500You may write symbol assignments as commands in their own right, or as
2501statements within a @code{SECTIONS} command, or as part of an output
2502section description in a @code{SECTIONS} command.
2503
2504The section of the symbol will be set from the section of the
2505expression; for more information, see @ref{Expression Section}.
2506
2507Here is an example showing the three different places that symbol
2508assignments may be used:
2509
2510@smallexample
2511floating_point = 0;
2512SECTIONS
2513@{
2514 .text :
2515 @{
2516 *(.text)
2517 _etext = .;
2518 @}
156e34dd 2519 _bdata = (. + 3) & ~ 3;
252b5132
RH
2520 .data : @{ *(.data) @}
2521@}
2522@end smallexample
2523@noindent
2524In this example, the symbol @samp{floating_point} will be defined as
2525zero. The symbol @samp{_etext} will be defined as the address following
2526the last @samp{.text} input section. The symbol @samp{_bdata} will be
2527defined as the address following the @samp{.text} output section aligned
2528upward to a 4 byte boundary.
2529
2530@node PROVIDE
2531@subsection PROVIDE
2532@cindex PROVIDE
2533In some cases, it is desirable for a linker script to define a symbol
2534only if it is referenced and is not defined by any object included in
2535the link. For example, traditional linkers defined the symbol
2536@samp{etext}. However, ANSI C requires that the user be able to use
2537@samp{etext} as a function name without encountering an error. The
2538@code{PROVIDE} keyword may be used to define a symbol, such as
2539@samp{etext}, only if it is referenced but not defined. The syntax is
2540@code{PROVIDE(@var{symbol} = @var{expression})}.
2541
2542Here is an example of using @code{PROVIDE} to define @samp{etext}:
2543@smallexample
2544SECTIONS
2545@{
2546 .text :
2547 @{
2548 *(.text)
2549 _etext = .;
2550 PROVIDE(etext = .);
2551 @}
2552@}
2553@end smallexample
2554
2555In this example, if the program defines @samp{_etext} (with a leading
2556underscore), the linker will give a multiple definition error. If, on
2557the other hand, the program defines @samp{etext} (with no leading
2558underscore), the linker will silently use the definition in the program.
2559If the program references @samp{etext} but does not define it, the
2560linker will use the definition in the linker script.
2561
2562@node SECTIONS
2563@section SECTIONS command
2564@kindex SECTIONS
2565The @code{SECTIONS} command tells the linker how to map input sections
2566into output sections, and how to place the output sections in memory.
2567
2568The format of the @code{SECTIONS} command is:
2569@smallexample
2570SECTIONS
2571@{
2572 @var{sections-command}
2573 @var{sections-command}
2574 @dots{}
2575@}
2576@end smallexample
2577
2578Each @var{sections-command} may of be one of the following:
2579
2580@itemize @bullet
2581@item
2582an @code{ENTRY} command (@pxref{Entry Point,,Entry command})
2583@item
2584a symbol assignment (@pxref{Assignments})
2585@item
2586an output section description
2587@item
2588an overlay description
2589@end itemize
2590
2591The @code{ENTRY} command and symbol assignments are permitted inside the
2592@code{SECTIONS} command for convenience in using the location counter in
2593those commands. This can also make the linker script easier to
2594understand because you can use those commands at meaningful points in
2595the layout of the output file.
2596
2597Output section descriptions and overlay descriptions are described
2598below.
2599
2600If you do not use a @code{SECTIONS} command in your linker script, the
2601linker will place each input section into an identically named output
2602section in the order that the sections are first encountered in the
2603input files. If all input sections are present in the first file, for
2604example, the order of sections in the output file will match the order
2605in the first input file. The first section will be at address zero.
2606
2607@menu
2608* Output Section Description:: Output section description
2609* Output Section Name:: Output section name
2610* Output Section Address:: Output section address
2611* Input Section:: Input section description
2612* Output Section Data:: Output section data
2613* Output Section Keywords:: Output section keywords
2614* Output Section Discarding:: Output section discarding
2615* Output Section Attributes:: Output section attributes
2616* Overlay Description:: Overlay description
2617@end menu
2618
2619@node Output Section Description
2620@subsection Output section description
2621The full description of an output section looks like this:
2622@smallexample
a1ab1d2a 2623@group
252b5132
RH
2624@var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})]
2625 @{
2626 @var{output-section-command}
2627 @var{output-section-command}
2628 @dots{}
562d3460 2629 @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
252b5132
RH
2630@end group
2631@end smallexample
2632
2633Most output sections do not use most of the optional section attributes.
2634
2635The whitespace around @var{section} is required, so that the section
2636name is unambiguous. The colon and the curly braces are also required.
2637The line breaks and other white space are optional.
2638
2639Each @var{output-section-command} may be one of the following:
2640
2641@itemize @bullet
2642@item
2643a symbol assignment (@pxref{Assignments})
2644@item
2645an input section description (@pxref{Input Section})
2646@item
2647data values to include directly (@pxref{Output Section Data})
2648@item
2649a special output section keyword (@pxref{Output Section Keywords})
2650@end itemize
2651
2652@node Output Section Name
2653@subsection Output section name
2654@cindex name, section
2655@cindex section name
2656The name of the output section is @var{section}. @var{section} must
2657meet the constraints of your output format. In formats which only
2658support a limited number of sections, such as @code{a.out}, the name
2659must be one of the names supported by the format (@code{a.out}, for
2660example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
2661output format supports any number of sections, but with numbers and not
2662names (as is the case for Oasys), the name should be supplied as a
2663quoted numeric string. A section name may consist of any sequence of
2664characters, but a name which contains any unusual characters such as
2665commas must be quoted.
2666
2667The output section name @samp{/DISCARD/} is special; @ref{Output Section
2668Discarding}.
2669
2670@node Output Section Address
2671@subsection Output section address
2672@cindex address, section
2673@cindex section address
2674The @var{address} is an expression for the VMA (the virtual memory
2675address) of the output section. If you do not provide @var{address},
2676the linker will set it based on @var{region} if present, or otherwise
2677based on the current value of the location counter.
2678
2679If you provide @var{address}, the address of the output section will be
2680set to precisely that. If you provide neither @var{address} nor
2681@var{region}, then the address of the output section will be set to the
2682current value of the location counter aligned to the alignment
2683requirements of the output section. The alignment requirement of the
2684output section is the strictest alignment of any input section contained
2685within the output section.
2686
2687For example,
2688@smallexample
2689.text . : @{ *(.text) @}
2690@end smallexample
2691@noindent
2692and
2693@smallexample
2694.text : @{ *(.text) @}
2695@end smallexample
2696@noindent
2697are subtly different. The first will set the address of the
2698@samp{.text} output section to the current value of the location
2699counter. The second will set it to the current value of the location
2700counter aligned to the strictest alignment of a @samp{.text} input
2701section.
2702
2703The @var{address} may be an arbitrary expression; @ref{Expressions}.
2704For example, if you want to align the section on a 0x10 byte boundary,
2705so that the lowest four bits of the section address are zero, you could
2706do something like this:
2707@smallexample
2708.text ALIGN(0x10) : @{ *(.text) @}
2709@end smallexample
2710@noindent
2711This works because @code{ALIGN} returns the current location counter
2712aligned upward to the specified value.
2713
2714Specifying @var{address} for a section will change the value of the
2715location counter.
2716
2717@node Input Section
2718@subsection Input section description
2719@cindex input sections
2720@cindex mapping input sections to output sections
2721The most common output section command is an input section description.
2722
2723The input section description is the most basic linker script operation.
2724You use output sections to tell the linker how to lay out your program
2725in memory. You use input section descriptions to tell the linker how to
2726map the input files into your memory layout.
2727
2728@menu
2729* Input Section Basics:: Input section basics
2730* Input Section Wildcards:: Input section wildcard patterns
2731* Input Section Common:: Input section for common symbols
2732* Input Section Keep:: Input section and garbage collection
2733* Input Section Example:: Input section example
2734@end menu
2735
2736@node Input Section Basics
2737@subsubsection Input section basics
2738@cindex input section basics
2739An input section description consists of a file name optionally followed
2740by a list of section names in parentheses.
2741
2742The file name and the section name may be wildcard patterns, which we
2743describe further below (@pxref{Input Section Wildcards}).
2744
2745The most common input section description is to include all input
2746sections with a particular name in the output section. For example, to
2747include all input @samp{.text} sections, you would write:
2748@smallexample
2749*(.text)
2750@end smallexample
2751@noindent
18625d54
CM
2752Here the @samp{*} is a wildcard which matches any file name. To exclude a list
2753of files from matching the file name wildcard, EXCLUDE_FILE may be used to
2754match all files except the ones specified in the EXCLUDE_FILE list. For
2755example:
252b5132 2756@smallexample
765b7cbe 2757(*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors))
252b5132 2758@end smallexample
765b7cbe
JB
2759will cause all .ctors sections from all files except @file{crtend.o} and
2760@file{otherfile.o} to be included.
252b5132
RH
2761
2762There are two ways to include more than one section:
2763@smallexample
2764*(.text .rdata)
2765*(.text) *(.rdata)
2766@end smallexample
2767@noindent
2768The difference between these is the order in which the @samp{.text} and
2769@samp{.rdata} input sections will appear in the output section. In the
b6bf44ba
AM
2770first example, they will be intermingled, appearing in the same order as
2771they are found in the linker input. In the second example, all
252b5132
RH
2772@samp{.text} input sections will appear first, followed by all
2773@samp{.rdata} input sections.
2774
2775You can specify a file name to include sections from a particular file.
2776You would do this if one or more of your files contain special data that
2777needs to be at a particular location in memory. For example:
2778@smallexample
2779data.o(.data)
2780@end smallexample
2781
2782If you use a file name without a list of sections, then all sections in
2783the input file will be included in the output section. This is not
2784commonly done, but it may by useful on occasion. For example:
2785@smallexample
2786data.o
2787@end smallexample
2788
2789When you use a file name which does not contain any wild card
2790characters, the linker will first see if you also specified the file
2791name on the linker command line or in an @code{INPUT} command. If you
2792did not, the linker will attempt to open the file as an input file, as
2793though it appeared on the command line. Note that this differs from an
2794@code{INPUT} command, because the linker will not search for the file in
2795the archive search path.
2796
2797@node Input Section Wildcards
2798@subsubsection Input section wildcard patterns
2799@cindex input section wildcards
2800@cindex wildcard file name patterns
2801@cindex file name wildcard patterns
2802@cindex section name wildcard patterns
2803In an input section description, either the file name or the section
2804name or both may be wildcard patterns.
2805
2806The file name of @samp{*} seen in many examples is a simple wildcard
2807pattern for the file name.
2808
2809The wildcard patterns are like those used by the Unix shell.
2810
2811@table @samp
2812@item *
2813matches any number of characters
2814@item ?
2815matches any single character
2816@item [@var{chars}]
2817matches a single instance of any of the @var{chars}; the @samp{-}
2818character may be used to specify a range of characters, as in
2819@samp{[a-z]} to match any lower case letter
2820@item \
2821quotes the following character
2822@end table
2823
2824When a file name is matched with a wildcard, the wildcard characters
2825will not match a @samp{/} character (used to separate directory names on
2826Unix). A pattern consisting of a single @samp{*} character is an
2827exception; it will always match any file name, whether it contains a
2828@samp{/} or not. In a section name, the wildcard characters will match
2829a @samp{/} character.
2830
2831File name wildcard patterns only match files which are explicitly
2832specified on the command line or in an @code{INPUT} command. The linker
2833does not search directories to expand wildcards.
2834
2835If a file name matches more than one wildcard pattern, or if a file name
2836appears explicitly and is also matched by a wildcard pattern, the linker
2837will use the first match in the linker script. For example, this
2838sequence of input section descriptions is probably in error, because the
2839@file{data.o} rule will not be used:
2840@smallexample
2841.data : @{ *(.data) @}
2842.data1 : @{ data.o(.data) @}
2843@end smallexample
2844
2845@cindex SORT
2846Normally, the linker will place files and sections matched by wildcards
2847in the order in which they are seen during the link. You can change
2848this by using the @code{SORT} keyword, which appears before a wildcard
2849pattern in parentheses (e.g., @code{SORT(.text*)}). When the
2850@code{SORT} keyword is used, the linker will sort the files or sections
2851into ascending order by name before placing them in the output file.
2852
2853If you ever get confused about where input sections are going, use the
2854@samp{-M} linker option to generate a map file. The map file shows
2855precisely how input sections are mapped to output sections.
2856
2857This example shows how wildcard patterns might be used to partition
2858files. This linker script directs the linker to place all @samp{.text}
2859sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
2860The linker will place the @samp{.data} section from all files beginning
2861with an upper case character in @samp{.DATA}; for all other files, the
2862linker will place the @samp{.data} section in @samp{.data}.
2863@smallexample
2864@group
2865SECTIONS @{
2866 .text : @{ *(.text) @}
2867 .DATA : @{ [A-Z]*(.data) @}
2868 .data : @{ *(.data) @}
2869 .bss : @{ *(.bss) @}
2870@}
2871@end group
2872@end smallexample
2873
2874@node Input Section Common
2875@subsubsection Input section for common symbols
2876@cindex common symbol placement
2877@cindex uninitialized data placement
2878A special notation is needed for common symbols, because in many object
2879file formats common symbols do not have a particular input section. The
2880linker treats common symbols as though they are in an input section
2881named @samp{COMMON}.
2882
2883You may use file names with the @samp{COMMON} section just as with any
2884other input sections. You can use this to place common symbols from a
2885particular input file in one section while common symbols from other
2886input files are placed in another section.
2887
2888In most cases, common symbols in input files will be placed in the
2889@samp{.bss} section in the output file. For example:
2890@smallexample
2891.bss @{ *(.bss) *(COMMON) @}
2892@end smallexample
2893
2894@cindex scommon section
2895@cindex small common symbols
2896Some object file formats have more than one type of common symbol. For
2897example, the MIPS ELF object file format distinguishes standard common
2898symbols and small common symbols. In this case, the linker will use a
2899different special section name for other types of common symbols. In
2900the case of MIPS ELF, the linker uses @samp{COMMON} for standard common
2901symbols and @samp{.scommon} for small common symbols. This permits you
2902to map the different types of common symbols into memory at different
2903locations.
2904
2905@cindex [COMMON]
2906You will sometimes see @samp{[COMMON]} in old linker scripts. This
2907notation is now considered obsolete. It is equivalent to
2908@samp{*(COMMON)}.
2909
2910@node Input Section Keep
2911@subsubsection Input section and garbage collection
2912@cindex KEEP
2913@cindex garbage collection
2914When link-time garbage collection is in use (@samp{--gc-sections}),
a1ab1d2a 2915it is often useful to mark sections that should not be eliminated.
252b5132
RH
2916This is accomplished by surrounding an input section's wildcard entry
2917with @code{KEEP()}, as in @code{KEEP(*(.init))} or
2918@code{KEEP(SORT(*)(.ctors))}.
2919
2920@node Input Section Example
2921@subsubsection Input section example
2922The following example is a complete linker script. It tells the linker
2923to read all of the sections from file @file{all.o} and place them at the
2924start of output section @samp{outputa} which starts at location
2925@samp{0x10000}. All of section @samp{.input1} from file @file{foo.o}
2926follows immediately, in the same output section. All of section
2927@samp{.input2} from @file{foo.o} goes into output section
2928@samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
2929All of the remaining @samp{.input1} and @samp{.input2} sections from any
2930files are written to output section @samp{outputc}.
2931
2932@smallexample
2933@group
2934SECTIONS @{
2935 outputa 0x10000 :
2936 @{
2937 all.o
2938 foo.o (.input1)
2939 @}
2940 outputb :
2941 @{
2942 foo.o (.input2)
2943 foo1.o (.input1)
2944 @}
2945 outputc :
2946 @{
2947 *(.input1)
2948 *(.input2)
2949 @}
2950@}
2951@end group
a1ab1d2a 2952@end smallexample
252b5132
RH
2953
2954@node Output Section Data
2955@subsection Output section data
2956@cindex data
2957@cindex section data
2958@cindex output section data
2959@kindex BYTE(@var{expression})
2960@kindex SHORT(@var{expression})
2961@kindex LONG(@var{expression})
2962@kindex QUAD(@var{expression})
2963@kindex SQUAD(@var{expression})
2964You can include explicit bytes of data in an output section by using
2965@code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
2966an output section command. Each keyword is followed by an expression in
2967parentheses providing the value to store (@pxref{Expressions}). The
2968value of the expression is stored at the current value of the location
2969counter.
2970
2971The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
2972store one, two, four, and eight bytes (respectively). After storing the
2973bytes, the location counter is incremented by the number of bytes
2974stored.
2975
2976For example, this will store the byte 1 followed by the four byte value
2977of the symbol @samp{addr}:
2978@smallexample
2979BYTE(1)
2980LONG(addr)
2981@end smallexample
2982
2983When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
2984same; they both store an 8 byte, or 64 bit, value. When both host and
2985target are 32 bits, an expression is computed as 32 bits. In this case
2986@code{QUAD} stores a 32 bit value zero extended to 64 bits, and
2987@code{SQUAD} stores a 32 bit value sign extended to 64 bits.
2988
2989If the object file format of the output file has an explicit endianness,
2990which is the normal case, the value will be stored in that endianness.
2991When the object file format does not have an explicit endianness, as is
2992true of, for example, S-records, the value will be stored in the
2993endianness of the first input object file.
2994
2b5fc1f5
NC
2995Note - these commands only work inside a section description and not
2996between them, so the following will produce an error from the linker:
2997@smallexample
2998SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
2999@end smallexample
3000whereas this will work:
3001@smallexample
3002SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
3003@end smallexample
3004
252b5132
RH
3005@kindex FILL(@var{expression})
3006@cindex holes, filling
3007@cindex unspecified memory
3008You may use the @code{FILL} command to set the fill pattern for the
3009current section. It is followed by an expression in parentheses. Any
3010otherwise unspecified regions of memory within the section (for example,
3011gaps left due to the required alignment of input sections) are filled
a139d329 3012with the value of the expression, repeated as
252b5132
RH
3013necessary. A @code{FILL} statement covers memory locations after the
3014point at which it occurs in the section definition; by including more
3015than one @code{FILL} statement, you can have different fill patterns in
3016different parts of an output section.
3017
3018This example shows how to fill unspecified regions of memory with the
563e308f 3019value @samp{0x90}:
252b5132 3020@smallexample
563e308f 3021FILL(0x90909090)
252b5132
RH
3022@end smallexample
3023
3024The @code{FILL} command is similar to the @samp{=@var{fillexp}} output
9673c93c 3025section attribute, but it only affects the
252b5132
RH
3026part of the section following the @code{FILL} command, rather than the
3027entire section. If both are used, the @code{FILL} command takes
9673c93c 3028precedence. @xref{Output Section Fill}, for details on the fill
a139d329 3029expression.
252b5132
RH
3030
3031@node Output Section Keywords
3032@subsection Output section keywords
3033There are a couple of keywords which can appear as output section
3034commands.
3035
3036@table @code
3037@kindex CREATE_OBJECT_SYMBOLS
3038@cindex input filename symbols
3039@cindex filename symbols
3040@item CREATE_OBJECT_SYMBOLS
3041The command tells the linker to create a symbol for each input file.
3042The name of each symbol will be the name of the corresponding input
3043file. The section of each symbol will be the output section in which
3044the @code{CREATE_OBJECT_SYMBOLS} command appears.
3045
3046This is conventional for the a.out object file format. It is not
3047normally used for any other object file format.
3048
3049@kindex CONSTRUCTORS
3050@cindex C++ constructors, arranging in link
3051@cindex constructors, arranging in link
3052@item CONSTRUCTORS
3053When linking using the a.out object file format, the linker uses an
3054unusual set construct to support C++ global constructors and
3055destructors. When linking object file formats which do not support
3056arbitrary sections, such as ECOFF and XCOFF, the linker will
3057automatically recognize C++ global constructors and destructors by name.
3058For these object file formats, the @code{CONSTRUCTORS} command tells the
3059linker to place constructor information in the output section where the
3060@code{CONSTRUCTORS} command appears. The @code{CONSTRUCTORS} command is
3061ignored for other object file formats.
3062
3063The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
3064constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end. The
3065first word in the list is the number of entries, followed by the address
3066of each constructor or destructor, followed by a zero word. The
3067compiler must arrange to actually run the code. For these object file
3068formats @sc{gnu} C++ normally calls constructors from a subroutine
3069@code{__main}; a call to @code{__main} is automatically inserted into
3070the startup code for @code{main}. @sc{gnu} C++ normally runs
3071destructors either by using @code{atexit}, or directly from the function
3072@code{exit}.
3073
3074For object file formats such as @code{COFF} or @code{ELF} which support
3075arbitrary section names, @sc{gnu} C++ will normally arrange to put the
3076addresses of global constructors and destructors into the @code{.ctors}
3077and @code{.dtors} sections. Placing the following sequence into your
3078linker script will build the sort of table which the @sc{gnu} C++
3079runtime code expects to see.
3080
3081@smallexample
3082 __CTOR_LIST__ = .;
3083 LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
3084 *(.ctors)
3085 LONG(0)
3086 __CTOR_END__ = .;
3087 __DTOR_LIST__ = .;
3088 LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
3089 *(.dtors)
3090 LONG(0)
3091 __DTOR_END__ = .;
3092@end smallexample
3093
3094If you are using the @sc{gnu} C++ support for initialization priority,
3095which provides some control over the order in which global constructors
3096are run, you must sort the constructors at link time to ensure that they
3097are executed in the correct order. When using the @code{CONSTRUCTORS}
3098command, use @samp{SORT(CONSTRUCTORS)} instead. When using the
3099@code{.ctors} and @code{.dtors} sections, use @samp{*(SORT(.ctors))} and
3100@samp{*(SORT(.dtors))} instead of just @samp{*(.ctors)} and
3101@samp{*(.dtors)}.
3102
3103Normally the compiler and linker will handle these issues automatically,
3104and you will not need to concern yourself with them. However, you may
3105need to consider this if you are using C++ and writing your own linker
3106scripts.
3107
3108@end table
3109
3110@node Output Section Discarding
3111@subsection Output section discarding
3112@cindex discarding sections
3113@cindex sections, discarding
3114@cindex removing sections
3115The linker will not create output section which do not have any
3116contents. This is for convenience when referring to input sections that
3117may or may not be present in any of the input files. For example:
3118@smallexample
3119.foo @{ *(.foo) @}
3120@end smallexample
3121@noindent
3122will only create a @samp{.foo} section in the output file if there is a
3123@samp{.foo} section in at least one input file.
3124
3125If you use anything other than an input section description as an output
3126section command, such as a symbol assignment, then the output section
3127will always be created, even if there are no matching input sections.
3128
3129@cindex /DISCARD/
3130The special output section name @samp{/DISCARD/} may be used to discard
3131input sections. Any input sections which are assigned to an output
3132section named @samp{/DISCARD/} are not included in the output file.
3133
3134@node Output Section Attributes
3135@subsection Output section attributes
3136@cindex output section attributes
3137We showed above that the full description of an output section looked
3138like this:
3139@smallexample
a1ab1d2a 3140@group
252b5132
RH
3141@var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})]
3142 @{
3143 @var{output-section-command}
3144 @var{output-section-command}
3145 @dots{}
562d3460 3146 @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
252b5132
RH
3147@end group
3148@end smallexample
3149We've already described @var{section}, @var{address}, and
3150@var{output-section-command}. In this section we will describe the
3151remaining section attributes.
3152
a1ab1d2a 3153@menu
252b5132
RH
3154* Output Section Type:: Output section type
3155* Output Section LMA:: Output section LMA
3156* Output Section Region:: Output section region
3157* Output Section Phdr:: Output section phdr
3158* Output Section Fill:: Output section fill
3159@end menu
3160
3161@node Output Section Type
3162@subsubsection Output section type
3163Each output section may have a type. The type is a keyword in
3164parentheses. The following types are defined:
3165
3166@table @code
3167@item NOLOAD
3168The section should be marked as not loadable, so that it will not be
3169loaded into memory when the program is run.
3170@item DSECT
3171@itemx COPY
3172@itemx INFO
3173@itemx OVERLAY
3174These type names are supported for backward compatibility, and are
3175rarely used. They all have the same effect: the section should be
3176marked as not allocatable, so that no memory is allocated for the
3177section when the program is run.
3178@end table
3179
3180@kindex NOLOAD
3181@cindex prevent unnecessary loading
3182@cindex loading, preventing
3183The linker normally sets the attributes of an output section based on
3184the input sections which map into it. You can override this by using
3185the section type. For example, in the script sample below, the
3186@samp{ROM} section is addressed at memory location @samp{0} and does not
3187need to be loaded when the program is run. The contents of the
3188@samp{ROM} section will appear in the linker output file as usual.
3189@smallexample
3190@group
3191SECTIONS @{
3192 ROM 0 (NOLOAD) : @{ @dots{} @}
3193 @dots{}
3194@}
3195@end group
3196@end smallexample
3197
3198@node Output Section LMA
3199@subsubsection Output section LMA
562d3460 3200@kindex AT>@var{lma_region}
252b5132
RH
3201@kindex AT(@var{lma})
3202@cindex load address
3203@cindex section load address
3204Every section has a virtual address (VMA) and a load address (LMA); see
3205@ref{Basic Script Concepts}. The address expression which may appear in
3206an output section description sets the VMA (@pxref{Output Section
3207Address}).
3208
3209The linker will normally set the LMA equal to the VMA. You can change
3210that by using the @code{AT} keyword. The expression @var{lma} that
562d3460
TW
3211follows the @code{AT} keyword specifies the load address of the
3212section. Alternatively, with @samp{AT>@var{lma_region}} expression,
3213you may specify a memory region for the section's load address. @xref{MEMORY}.
252b5132
RH
3214
3215@cindex ROM initialized data
3216@cindex initialized data in ROM
3217This feature is designed to make it easy to build a ROM image. For
3218example, the following linker script creates three output sections: one
3219called @samp{.text}, which starts at @code{0x1000}, one called
3220@samp{.mdata}, which is loaded at the end of the @samp{.text} section
3221even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
3222uninitialized data at address @code{0x3000}. The symbol @code{_data} is
3223defined with the value @code{0x2000}, which shows that the location
3224counter holds the VMA value, not the LMA value.
3225
3226@smallexample
3227@group
3228SECTIONS
3229 @{
3230 .text 0x1000 : @{ *(.text) _etext = . ; @}
a1ab1d2a 3231 .mdata 0x2000 :
252b5132
RH
3232 AT ( ADDR (.text) + SIZEOF (.text) )
3233 @{ _data = . ; *(.data); _edata = . ; @}
3234 .bss 0x3000 :
3235 @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@}
3236@}
3237@end group
3238@end smallexample
3239
3240The run-time initialization code for use with a program generated with
3241this linker script would include something like the following, to copy
3242the initialized data from the ROM image to its runtime address. Notice
3243how this code takes advantage of the symbols defined by the linker
3244script.
3245
3246@smallexample
3247@group
3248extern char _etext, _data, _edata, _bstart, _bend;
3249char *src = &_etext;
3250char *dst = &_data;
3251
3252/* ROM has data at end of text; copy it. */
3253while (dst < &_edata) @{
3254 *dst++ = *src++;
3255@}
3256
3257/* Zero bss */
3258for (dst = &_bstart; dst< &_bend; dst++)
3259 *dst = 0;
3260@end group
3261@end smallexample
3262
3263@node Output Section Region
3264@subsubsection Output section region
3265@kindex >@var{region}
3266@cindex section, assigning to memory region
3267@cindex memory regions and sections
3268You can assign a section to a previously defined region of memory by
3269using @samp{>@var{region}}. @xref{MEMORY}.
3270
3271Here is a simple example:
3272@smallexample
3273@group
3274MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
3275SECTIONS @{ ROM : @{ *(.text) @} >rom @}
3276@end group
3277@end smallexample
3278
3279@node Output Section Phdr
3280@subsubsection Output section phdr
3281@kindex :@var{phdr}
3282@cindex section, assigning to program header
3283@cindex program headers and sections
3284You can assign a section to a previously defined program segment by
3285using @samp{:@var{phdr}}. @xref{PHDRS}. If a section is assigned to
3286one or more segments, then all subsequent allocated sections will be
3287assigned to those segments as well, unless they use an explicitly
3288@code{:@var{phdr}} modifier. You can use @code{:NONE} to tell the
3289linker to not put the section in any segment at all.
3290
3291Here is a simple example:
3292@smallexample
3293@group
3294PHDRS @{ text PT_LOAD ; @}
3295SECTIONS @{ .text : @{ *(.text) @} :text @}
3296@end group
3297@end smallexample
3298
3299@node Output Section Fill
3300@subsubsection Output section fill
3301@kindex =@var{fillexp}
3302@cindex section fill pattern
3303@cindex fill pattern, entire section
3304You can set the fill pattern for an entire section by using
3305@samp{=@var{fillexp}}. @var{fillexp} is an expression
3306(@pxref{Expressions}). Any otherwise unspecified regions of memory
3307within the output section (for example, gaps left due to the required
a139d329
AM
3308alignment of input sections) will be filled with the value, repeated as
3309necessary. If the fill expression is a simple hex number, ie. a string
9673c93c 3310of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
a139d329
AM
3311an arbitrarily long sequence of hex digits can be used to specify the
3312fill pattern; Leading zeros become part of the pattern too. For all
9673c93c 3313other cases, including extra parentheses or a unary @code{+}, the fill
a139d329
AM
3314pattern is the four least significant bytes of the value of the
3315expression. In all cases, the number is big-endian.
252b5132
RH
3316
3317You can also change the fill value with a @code{FILL} command in the
9673c93c 3318output section commands; (@pxref{Output Section Data}).
252b5132
RH
3319
3320Here is a simple example:
3321@smallexample
3322@group
563e308f 3323SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
252b5132
RH
3324@end group
3325@end smallexample
3326
3327@node Overlay Description
3328@subsection Overlay description
3329@kindex OVERLAY
3330@cindex overlays
3331An overlay description provides an easy way to describe sections which
3332are to be loaded as part of a single memory image but are to be run at
3333the same memory address. At run time, some sort of overlay manager will
3334copy the overlaid sections in and out of the runtime memory address as
3335required, perhaps by simply manipulating addressing bits. This approach
3336can be useful, for example, when a certain region of memory is faster
3337than another.
3338
3339Overlays are described using the @code{OVERLAY} command. The
3340@code{OVERLAY} command is used within a @code{SECTIONS} command, like an
3341output section description. The full syntax of the @code{OVERLAY}
3342command is as follows:
3343@smallexample
3344@group
3345OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
3346 @{
3347 @var{secname1}
3348 @{
3349 @var{output-section-command}
3350 @var{output-section-command}
3351 @dots{}
3352 @} [:@var{phdr}@dots{}] [=@var{fill}]
3353 @var{secname2}
3354 @{
3355 @var{output-section-command}
3356 @var{output-section-command}
3357 @dots{}
3358 @} [:@var{phdr}@dots{}] [=@var{fill}]
3359 @dots{}
3360 @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}]
3361@end group
3362@end smallexample
3363
3364Everything is optional except @code{OVERLAY} (a keyword), and each
3365section must have a name (@var{secname1} and @var{secname2} above). The
3366section definitions within the @code{OVERLAY} construct are identical to
3367those within the general @code{SECTIONS} contruct (@pxref{SECTIONS}),
3368except that no addresses and no memory regions may be defined for
3369sections within an @code{OVERLAY}.
3370
3371The sections are all defined with the same starting address. The load
3372addresses of the sections are arranged such that they are consecutive in
3373memory starting at the load address used for the @code{OVERLAY} as a
3374whole (as with normal section definitions, the load address is optional,
3375and defaults to the start address; the start address is also optional,
3376and defaults to the current value of the location counter).
3377
3378If the @code{NOCROSSREFS} keyword is used, and there any references
3379among the sections, the linker will report an error. Since the sections
3380all run at the same address, it normally does not make sense for one
3381section to refer directly to another. @xref{Miscellaneous Commands,
3382NOCROSSREFS}.
3383
3384For each section within the @code{OVERLAY}, the linker automatically
3385defines two symbols. The symbol @code{__load_start_@var{secname}} is
3386defined as the starting load address of the section. The symbol
3387@code{__load_stop_@var{secname}} is defined as the final load address of
3388the section. Any characters within @var{secname} which are not legal
3389within C identifiers are removed. C (or assembler) code may use these
3390symbols to move the overlaid sections around as necessary.
3391
3392At the end of the overlay, the value of the location counter is set to
3393the start address of the overlay plus the size of the largest section.
3394
3395Here is an example. Remember that this would appear inside a
3396@code{SECTIONS} construct.
3397@smallexample
3398@group
3399 OVERLAY 0x1000 : AT (0x4000)
3400 @{
3401 .text0 @{ o1/*.o(.text) @}
3402 .text1 @{ o2/*.o(.text) @}
3403 @}
3404@end group
3405@end smallexample
3406@noindent
3407This will define both @samp{.text0} and @samp{.text1} to start at
3408address 0x1000. @samp{.text0} will be loaded at address 0x4000, and
3409@samp{.text1} will be loaded immediately after @samp{.text0}. The
3410following symbols will be defined: @code{__load_start_text0},
3411@code{__load_stop_text0}, @code{__load_start_text1},
3412@code{__load_stop_text1}.
3413
3414C code to copy overlay @code{.text1} into the overlay area might look
3415like the following.
3416
3417@smallexample
3418@group
3419 extern char __load_start_text1, __load_stop_text1;
3420 memcpy ((char *) 0x1000, &__load_start_text1,
3421 &__load_stop_text1 - &__load_start_text1);
3422@end group
3423@end smallexample
3424
3425Note that the @code{OVERLAY} command is just syntactic sugar, since
3426everything it does can be done using the more basic commands. The above
3427example could have been written identically as follows.
3428
3429@smallexample
3430@group
3431 .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
3432 __load_start_text0 = LOADADDR (.text0);
3433 __load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0);
3434 .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
3435 __load_start_text1 = LOADADDR (.text1);
3436 __load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1);
3437 . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
3438@end group
3439@end smallexample
3440
3441@node MEMORY
3442@section MEMORY command
3443@kindex MEMORY
3444@cindex memory regions
3445@cindex regions of memory
3446@cindex allocating memory
3447@cindex discontinuous memory
3448The linker's default configuration permits allocation of all available
3449memory. You can override this by using the @code{MEMORY} command.
3450
3451The @code{MEMORY} command describes the location and size of blocks of
3452memory in the target. You can use it to describe which memory regions
3453may be used by the linker, and which memory regions it must avoid. You
3454can then assign sections to particular memory regions. The linker will
3455set section addresses based on the memory regions, and will warn about
3456regions that become too full. The linker will not shuffle sections
3457around to fit into the available regions.
3458
3459A linker script may contain at most one use of the @code{MEMORY}
3460command. However, you can define as many blocks of memory within it as
3461you wish. The syntax is:
3462@smallexample
3463@group
a1ab1d2a 3464MEMORY
252b5132
RH
3465 @{
3466 @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
3467 @dots{}
3468 @}
3469@end group
3470@end smallexample
3471
3472The @var{name} is a name used in the linker script to refer to the
3473region. The region name has no meaning outside of the linker script.
3474Region names are stored in a separate name space, and will not conflict
3475with symbol names, file names, or section names. Each memory region
3476must have a distinct name.
3477
3478@cindex memory region attributes
3479The @var{attr} string is an optional list of attributes that specify
3480whether to use a particular memory region for an input section which is
3481not explicitly mapped in the linker script. As described in
3482@ref{SECTIONS}, if you do not specify an output section for some input
3483section, the linker will create an output section with the same name as
3484the input section. If you define region attributes, the linker will use
3485them to select the memory region for the output section that it creates.
3486
3487The @var{attr} string must consist only of the following characters:
3488@table @samp
3489@item R
3490Read-only section
3491@item W
3492Read/write section
3493@item X
3494Executable section
3495@item A
3496Allocatable section
3497@item I
3498Initialized section
3499@item L
3500Same as @samp{I}
3501@item !
3502Invert the sense of any of the preceding attributes
3503@end table
3504
3505If a unmapped section matches any of the listed attributes other than
3506@samp{!}, it will be placed in the memory region. The @samp{!}
3507attribute reverses this test, so that an unmapped section will be placed
3508in the memory region only if it does not match any of the listed
3509attributes.
3510
3511@kindex ORIGIN =
3512@kindex o =
3513@kindex org =
3514The @var{origin} is an expression for the start address of the memory
3515region. The expression must evaluate to a constant before memory
3516allocation is performed, which means that you may not use any section
3517relative symbols. The keyword @code{ORIGIN} may be abbreviated to
3518@code{org} or @code{o} (but not, for example, @code{ORG}).
3519
3520@kindex LENGTH =
3521@kindex len =
3522@kindex l =
3523The @var{len} is an expression for the size in bytes of the memory
3524region. As with the @var{origin} expression, the expression must
3525evaluate to a constant before memory allocation is performed. The
3526keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
3527
3528In the following example, we specify that there are two memory regions
3529available for allocation: one starting at @samp{0} for 256 kilobytes,
3530and the other starting at @samp{0x40000000} for four megabytes. The
3531linker will place into the @samp{rom} memory region every section which
3532is not explicitly mapped into a memory region, and is either read-only
3533or executable. The linker will place other sections which are not
3534explicitly mapped into a memory region into the @samp{ram} memory
3535region.
3536
3537@smallexample
3538@group
a1ab1d2a 3539MEMORY
252b5132
RH
3540 @{
3541 rom (rx) : ORIGIN = 0, LENGTH = 256K
3542 ram (!rx) : org = 0x40000000, l = 4M
3543 @}
3544@end group
3545@end smallexample
3546
3547Once you define a memory region, you can direct the linker to place
3548specific output sections into that memory region by using the
3549@samp{>@var{region}} output section attribute. For example, if you have
3550a memory region named @samp{mem}, you would use @samp{>mem} in the
3551output section definition. @xref{Output Section Region}. If no address
3552was specified for the output section, the linker will set the address to
3553the next available address within the memory region. If the combined
3554output sections directed to a memory region are too large for the
3555region, the linker will issue an error message.
3556
3557@node PHDRS
3558@section PHDRS Command
3559@kindex PHDRS
3560@cindex program headers
3561@cindex ELF program headers
3562@cindex program segments
3563@cindex segments, ELF
3564The ELF object file format uses @dfn{program headers}, also knows as
3565@dfn{segments}. The program headers describe how the program should be
3566loaded into memory. You can print them out by using the @code{objdump}
3567program with the @samp{-p} option.
3568
3569When you run an ELF program on a native ELF system, the system loader
3570reads the program headers in order to figure out how to load the
3571program. This will only work if the program headers are set correctly.
3572This manual does not describe the details of how the system loader
3573interprets program headers; for more information, see the ELF ABI.
3574
3575The linker will create reasonable program headers by default. However,
3576in some cases, you may need to specify the program headers more
3577precisely. You may use the @code{PHDRS} command for this purpose. When
3578the linker sees the @code{PHDRS} command in the linker script, it will
3579not create any program headers other than the ones specified.
3580
3581The linker only pays attention to the @code{PHDRS} command when
3582generating an ELF output file. In other cases, the linker will simply
3583ignore @code{PHDRS}.
3584
3585This is the syntax of the @code{PHDRS} command. The words @code{PHDRS},
3586@code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
3587
3588@smallexample
3589@group
3590PHDRS
3591@{
3592 @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
3593 [ FLAGS ( @var{flags} ) ] ;
3594@}
3595@end group
3596@end smallexample
3597
3598The @var{name} is used only for reference in the @code{SECTIONS} command
3599of the linker script. It is not put into the output file. Program
3600header names are stored in a separate name space, and will not conflict
3601with symbol names, file names, or section names. Each program header
3602must have a distinct name.
3603
3604Certain program header types describe segments of memory which the
3605system loader will load from the file. In the linker script, you
3606specify the contents of these segments by placing allocatable output
3607sections in the segments. You use the @samp{:@var{phdr}} output section
3608attribute to place a section in a particular segment. @xref{Output
3609Section Phdr}.
3610
3611It is normal to put certain sections in more than one segment. This
3612merely implies that one segment of memory contains another. You may
3613repeat @samp{:@var{phdr}}, using it once for each segment which should
3614contain the section.
3615
3616If you place a section in one or more segments using @samp{:@var{phdr}},
3617then the linker will place all subsequent allocatable sections which do
3618not specify @samp{:@var{phdr}} in the same segments. This is for
3619convenience, since generally a whole set of contiguous sections will be
3620placed in a single segment. You can use @code{:NONE} to override the
3621default segment and tell the linker to not put the section in any
3622segment at all.
3623
3624@kindex FILEHDR
3625@kindex PHDRS
3626You may use the @code{FILEHDR} and @code{PHDRS} keywords appear after
3627the program header type to further describe the contents of the segment.
3628The @code{FILEHDR} keyword means that the segment should include the ELF
3629file header. The @code{PHDRS} keyword means that the segment should
3630include the ELF program headers themselves.
3631
3632The @var{type} may be one of the following. The numbers indicate the
3633value of the keyword.
3634
3635@table @asis
3636@item @code{PT_NULL} (0)
3637Indicates an unused program header.
3638
3639@item @code{PT_LOAD} (1)
3640Indicates that this program header describes a segment to be loaded from
3641the file.
3642
3643@item @code{PT_DYNAMIC} (2)
3644Indicates a segment where dynamic linking information can be found.
3645
3646@item @code{PT_INTERP} (3)
3647Indicates a segment where the name of the program interpreter may be
3648found.
3649
3650@item @code{PT_NOTE} (4)
3651Indicates a segment holding note information.
3652
3653@item @code{PT_SHLIB} (5)
3654A reserved program header type, defined but not specified by the ELF
3655ABI.
3656
3657@item @code{PT_PHDR} (6)
3658Indicates a segment where the program headers may be found.
3659
3660@item @var{expression}
3661An expression giving the numeric type of the program header. This may
3662be used for types not defined above.
3663@end table
3664
3665You can specify that a segment should be loaded at a particular address
3666in memory by using an @code{AT} expression. This is identical to the
3667@code{AT} command used as an output section attribute (@pxref{Output
3668Section LMA}). The @code{AT} command for a program header overrides the
3669output section attribute.
3670
3671The linker will normally set the segment flags based on the sections
3672which comprise the segment. You may use the @code{FLAGS} keyword to
3673explicitly specify the segment flags. The value of @var{flags} must be
3674an integer. It is used to set the @code{p_flags} field of the program
3675header.
3676
3677Here is an example of @code{PHDRS}. This shows a typical set of program
3678headers used on a native ELF system.
3679
3680@example
3681@group
3682PHDRS
3683@{
3684 headers PT_PHDR PHDRS ;
3685 interp PT_INTERP ;
3686 text PT_LOAD FILEHDR PHDRS ;
3687 data PT_LOAD ;
3688 dynamic PT_DYNAMIC ;
3689@}
3690
3691SECTIONS
3692@{
3693 . = SIZEOF_HEADERS;
3694 .interp : @{ *(.interp) @} :text :interp
3695 .text : @{ *(.text) @} :text
3696 .rodata : @{ *(.rodata) @} /* defaults to :text */
3697 @dots{}
3698 . = . + 0x1000; /* move to a new page in memory */
3699 .data : @{ *(.data) @} :data
3700 .dynamic : @{ *(.dynamic) @} :data :dynamic
3701 @dots{}
3702@}
3703@end group
3704@end example
3705
3706@node VERSION
3707@section VERSION Command
3708@kindex VERSION @{script text@}
3709@cindex symbol versions
3710@cindex version script
3711@cindex versions of symbols
3712The linker supports symbol versions when using ELF. Symbol versions are
3713only useful when using shared libraries. The dynamic linker can use
3714symbol versions to select a specific version of a function when it runs
3715a program that may have been linked against an earlier version of the
3716shared library.
3717
3718You can include a version script directly in the main linker script, or
3719you can supply the version script as an implicit linker script. You can
3720also use the @samp{--version-script} linker option.
3721
3722The syntax of the @code{VERSION} command is simply
3723@smallexample
3724VERSION @{ version-script-commands @}
3725@end smallexample
3726
3727The format of the version script commands is identical to that used by
3728Sun's linker in Solaris 2.5. The version script defines a tree of
3729version nodes. You specify the node names and interdependencies in the
3730version script. You can specify which symbols are bound to which
3731version nodes, and you can reduce a specified set of symbols to local
3732scope so that they are not globally visible outside of the shared
3733library.
3734
3735The easiest way to demonstrate the version script language is with a few
3736examples.
3737
3738@smallexample
3739VERS_1.1 @{
3740 global:
3741 foo1;
3742 local:
a1ab1d2a
UD
3743 old*;
3744 original*;
3745 new*;
252b5132
RH
3746@};
3747
3748VERS_1.2 @{
3749 foo2;
3750@} VERS_1.1;
3751
3752VERS_2.0 @{
3753 bar1; bar2;
3754@} VERS_1.2;
3755@end smallexample
3756
3757This example version script defines three version nodes. The first
3758version node defined is @samp{VERS_1.1}; it has no other dependencies.
3759The script binds the symbol @samp{foo1} to @samp{VERS_1.1}. It reduces
3760a number of symbols to local scope so that they are not visible outside
313e35ee
AM
3761of the shared library; this is done using wildcard patterns, so that any
3762symbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
3763is matched. The wildcard patterns available are the same as those used
3764in the shell when matching filenames (also known as ``globbing'').
252b5132
RH
3765
3766Next, the version script defines node @samp{VERS_1.2}. This node
3767depends upon @samp{VERS_1.1}. The script binds the symbol @samp{foo2}
3768to the version node @samp{VERS_1.2}.
3769
3770Finally, the version script defines node @samp{VERS_2.0}. This node
3771depends upon @samp{VERS_1.2}. The scripts binds the symbols @samp{bar1}
3772and @samp{bar2} are bound to the version node @samp{VERS_2.0}.
3773
3774When the linker finds a symbol defined in a library which is not
3775specifically bound to a version node, it will effectively bind it to an
3776unspecified base version of the library. You can bind all otherwise
a981ed6f 3777unspecified symbols to a given version node by using @samp{global: *;}
252b5132
RH
3778somewhere in the version script.
3779
3780The names of the version nodes have no specific meaning other than what
3781they might suggest to the person reading them. The @samp{2.0} version
3782could just as well have appeared in between @samp{1.1} and @samp{1.2}.
3783However, this would be a confusing way to write a version script.
3784
6b9b879a
JJ
3785Node name can be omited, provided it is the only version node
3786in the version script. Such version script doesn't assign any versions to
3787symbols, only selects which symbols will be globally visible out and which
3788won't.
3789
3790@smallexample
7c9c73be 3791@{ global: foo; bar; local: *; @};
9d201f2f 3792@end smallexample
6b9b879a 3793
252b5132
RH
3794When you link an application against a shared library that has versioned
3795symbols, the application itself knows which version of each symbol it
3796requires, and it also knows which version nodes it needs from each
3797shared library it is linked against. Thus at runtime, the dynamic
3798loader can make a quick check to make sure that the libraries you have
3799linked against do in fact supply all of the version nodes that the
3800application will need to resolve all of the dynamic symbols. In this
3801way it is possible for the dynamic linker to know with certainty that
3802all external symbols that it needs will be resolvable without having to
3803search for each symbol reference.
3804
3805The symbol versioning is in effect a much more sophisticated way of
3806doing minor version checking that SunOS does. The fundamental problem
3807that is being addressed here is that typically references to external
3808functions are bound on an as-needed basis, and are not all bound when
3809the application starts up. If a shared library is out of date, a
3810required interface may be missing; when the application tries to use
3811that interface, it may suddenly and unexpectedly fail. With symbol
3812versioning, the user will get a warning when they start their program if
3813the libraries being used with the application are too old.
3814
3815There are several GNU extensions to Sun's versioning approach. The
3816first of these is the ability to bind a symbol to a version node in the
3817source file where the symbol is defined instead of in the versioning
3818script. This was done mainly to reduce the burden on the library
3819maintainer. You can do this by putting something like:
3820@smallexample
3821__asm__(".symver original_foo,foo@@VERS_1.1");
3822@end smallexample
3823@noindent
3824in the C source file. This renames the function @samp{original_foo} to
3825be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
3826The @samp{local:} directive can be used to prevent the symbol
96a94295
L
3827@samp{original_foo} from being exported. A @samp{.symver} directive
3828takes precedence over a version script.
252b5132
RH
3829
3830The second GNU extension is to allow multiple versions of the same
3831function to appear in a given shared library. In this way you can make
3832an incompatible change to an interface without increasing the major
3833version number of the shared library, while still allowing applications
3834linked against the old interface to continue to function.
3835
3836To do this, you must use multiple @samp{.symver} directives in the
3837source file. Here is an example:
3838
3839@smallexample
3840__asm__(".symver original_foo,foo@@");
3841__asm__(".symver old_foo,foo@@VERS_1.1");
3842__asm__(".symver old_foo1,foo@@VERS_1.2");
3843__asm__(".symver new_foo,foo@@@@VERS_2.0");
3844@end smallexample
3845
3846In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
3847unspecified base version of the symbol. The source file that contains this
3848example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
3849@samp{old_foo1}, and @samp{new_foo}.
3850
3851When you have multiple definitions of a given symbol, there needs to be
3852some way to specify a default version to which external references to
3853this symbol will be bound. You can do this with the
3854@samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. You can only
3855declare one version of a symbol as the default in this manner; otherwise
3856you would effectively have multiple definitions of the same symbol.
3857
3858If you wish to bind a reference to a specific version of the symbol
3859within the shared library, you can use the aliases of convenience
3860(i.e. @samp{old_foo}), or you can use the @samp{.symver} directive to
3861specifically bind to an external version of the function in question.
3862
cb840a31
L
3863You can also specify the language in the version script:
3864
3865@smallexample
3866VERSION extern "lang" @{ version-script-commands @}
3867@end smallexample
3868
3869The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
3870The linker will iterate over the list of symbols at the link time and
3871demangle them according to @samp{lang} before matching them to the
3872patterns specified in @samp{version-script-commands}.
3873
252b5132
RH
3874@node Expressions
3875@section Expressions in Linker Scripts
3876@cindex expressions
3877@cindex arithmetic
3878The syntax for expressions in the linker script language is identical to
3879that of C expressions. All expressions are evaluated as integers. All
3880expressions are evaluated in the same size, which is 32 bits if both the
3881host and target are 32 bits, and is otherwise 64 bits.
3882
3883You can use and set symbol values in expressions.
3884
3885The linker defines several special purpose builtin functions for use in
3886expressions.
3887
3888@menu
3889* Constants:: Constants
3890* Symbols:: Symbol Names
3891* Location Counter:: The Location Counter
3892* Operators:: Operators
3893* Evaluation:: Evaluation
3894* Expression Section:: The Section of an Expression
3895* Builtin Functions:: Builtin Functions
3896@end menu
3897
3898@node Constants
3899@subsection Constants
3900@cindex integer notation
3901@cindex constants in linker scripts
3902All constants are integers.
3903
3904As in C, the linker considers an integer beginning with @samp{0} to be
3905octal, and an integer beginning with @samp{0x} or @samp{0X} to be
3906hexadecimal. The linker considers other integers to be decimal.
3907
3908@cindex scaled integers
3909@cindex K and M integer suffixes
3910@cindex M and K integer suffixes
3911@cindex suffixes for integers
3912@cindex integer suffixes
3913In addition, you can use the suffixes @code{K} and @code{M} to scale a
3914constant by
3915@c TEXI2ROFF-KILL
3916@ifinfo
3917@c END TEXI2ROFF-KILL
3918@code{1024} or @code{1024*1024}
3919@c TEXI2ROFF-KILL
3920@end ifinfo
3921@tex
3922${\rm 1024}$ or ${\rm 1024}^2$
3923@end tex
3924@c END TEXI2ROFF-KILL
3925respectively. For example, the following all refer to the same quantity:
3926@smallexample
3927 _fourk_1 = 4K;
3928 _fourk_2 = 4096;
3929 _fourk_3 = 0x1000;
3930@end smallexample
3931
3932@node Symbols
3933@subsection Symbol Names
3934@cindex symbol names
3935@cindex names
3936@cindex quoted symbol names
3937@kindex "
3938Unless quoted, symbol names start with a letter, underscore, or period
3939and may include letters, digits, underscores, periods, and hyphens.
3940Unquoted symbol names must not conflict with any keywords. You can
3941specify a symbol which contains odd characters or has the same name as a
3942keyword by surrounding the symbol name in double quotes:
3943@smallexample
3944 "SECTION" = 9;
3945 "with a space" = "also with a space" + 10;
3946@end smallexample
3947
3948Since symbols can contain many non-alphabetic characters, it is safest
3949to delimit symbols with spaces. For example, @samp{A-B} is one symbol,
3950whereas @samp{A - B} is an expression involving subtraction.
3951
3952@node Location Counter
3953@subsection The Location Counter
3954@kindex .
3955@cindex dot
3956@cindex location counter
3957@cindex current output location
3958The special linker variable @dfn{dot} @samp{.} always contains the
3959current output location counter. Since the @code{.} always refers to a
3960location in an output section, it may only appear in an expression
3961within a @code{SECTIONS} command. The @code{.} symbol may appear
3962anywhere that an ordinary symbol is allowed in an expression.
3963
3964@cindex holes
3965Assigning a value to @code{.} will cause the location counter to be
3966moved. This may be used to create holes in the output section. The
3967location counter may never be moved backwards.
3968
3969@smallexample
3970SECTIONS
3971@{
3972 output :
3973 @{
3974 file1(.text)
3975 . = . + 1000;
3976 file2(.text)
3977 . += 1000;
3978 file3(.text)
563e308f 3979 @} = 0x12345678;
252b5132
RH
3980@}
3981@end smallexample
3982@noindent
3983In the previous example, the @samp{.text} section from @file{file1} is
3984located at the beginning of the output section @samp{output}. It is
3985followed by a 1000 byte gap. Then the @samp{.text} section from
3986@file{file2} appears, also with a 1000 byte gap following before the
563e308f 3987@samp{.text} section from @file{file3}. The notation @samp{= 0x12345678}
252b5132
RH
3988specifies what data to write in the gaps (@pxref{Output Section Fill}).
3989
5c6bbab8
NC
3990@cindex dot inside sections
3991Note: @code{.} actually refers to the byte offset from the start of the
3992current containing object. Normally this is the @code{SECTIONS}
69da35b5 3993statement, whose start address is 0, hence @code{.} can be used as an
5c6bbab8
NC
3994absolute address. If @code{.} is used inside a section description
3995however, it refers to the byte offset from the start of that section,
3996not an absolute address. Thus in a script like this:
3997
3998@smallexample
3999SECTIONS
4000@{
4001 . = 0x100
4002 .text: @{
4003 *(.text)
4004 . = 0x200
4005 @}
4006 . = 0x500
4007 .data: @{
4008 *(.data)
4009 . += 0x600
4010 @}
4011@}
4012@end smallexample
4013
4014The @samp{.text} section will be assigned a starting address of 0x100
4015and a size of exactly 0x200 bytes, even if there is not enough data in
4016the @samp{.text} input sections to fill this area. (If there is too
4017much data, an error will be produced because this would be an attempt to
4018move @code{.} backwards). The @samp{.data} section will start at 0x500
4019and it will have an extra 0x600 bytes worth of space after the end of
4020the values from the @samp{.data} input sections and before the end of
4021the @samp{.data} output section itself.
4022
252b5132
RH
4023@need 2000
4024@node Operators
4025@subsection Operators
4026@cindex operators for arithmetic
4027@cindex arithmetic operators
4028@cindex precedence in expressions
4029The linker recognizes the standard C set of arithmetic operators, with
4030the standard bindings and precedence levels:
4031@c TEXI2ROFF-KILL
4032@ifinfo
4033@c END TEXI2ROFF-KILL
4034@smallexample
4035precedence associativity Operators Notes
4036(highest)
40371 left ! - ~ (1)
40382 left * / %
40393 left + -
40404 left >> <<
40415 left == != > < <= >=
40426 left &
40437 left |
40448 left &&
40459 left ||
404610 right ? :
404711 right &= += -= *= /= (2)
4048(lowest)
4049@end smallexample
4050Notes:
a1ab1d2a 4051(1) Prefix operators
252b5132
RH
4052(2) @xref{Assignments}.
4053@c TEXI2ROFF-KILL
4054@end ifinfo
4055@tex
4056\vskip \baselineskip
4057%"lispnarrowing" is the extra indent used generally for smallexample
4058\hskip\lispnarrowing\vbox{\offinterlineskip
4059\hrule
4060\halign
4061{\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
4062height2pt&\omit&&\omit&&\omit&\cr
4063&Precedence&& Associativity &&{\rm Operators}&\cr
4064height2pt&\omit&&\omit&&\omit&\cr
4065\noalign{\hrule}
4066height2pt&\omit&&\omit&&\omit&\cr
4067&highest&&&&&\cr
4068% '176 is tilde, '~' in tt font
a1ab1d2a 4069&1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
252b5132
RH
4070&2&&left&&* / \%&\cr
4071&3&&left&&+ -&\cr
4072&4&&left&&>> <<&\cr
4073&5&&left&&== != > < <= >=&\cr
4074&6&&left&&\&&\cr
4075&7&&left&&|&\cr
4076&8&&left&&{\&\&}&\cr
4077&9&&left&&||&\cr
4078&10&&right&&? :&\cr
4079&11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr
4080&lowest&&&&&\cr
4081height2pt&\omit&&\omit&&\omit&\cr}
4082\hrule}
4083@end tex
4084@iftex
4085{
4086@obeylines@parskip=0pt@parindent=0pt
4087@dag@quad Prefix operators.
4088@ddag@quad @xref{Assignments}.
4089}
4090@end iftex
4091@c END TEXI2ROFF-KILL
4092
4093@node Evaluation
4094@subsection Evaluation
4095@cindex lazy evaluation
4096@cindex expression evaluation order
4097The linker evaluates expressions lazily. It only computes the value of
4098an expression when absolutely necessary.
4099
4100The linker needs some information, such as the value of the start
4101address of the first section, and the origins and lengths of memory
4102regions, in order to do any linking at all. These values are computed
4103as soon as possible when the linker reads in the linker script.
4104
4105However, other values (such as symbol values) are not known or needed
4106until after storage allocation. Such values are evaluated later, when
4107other information (such as the sizes of output sections) is available
4108for use in the symbol assignment expression.
4109
4110The sizes of sections cannot be known until after allocation, so
4111assignments dependent upon these are not performed until after
4112allocation.
4113
4114Some expressions, such as those depending upon the location counter
4115@samp{.}, must be evaluated during section allocation.
4116
4117If the result of an expression is required, but the value is not
4118available, then an error results. For example, a script like the
4119following
4120@smallexample
4121@group
4122SECTIONS
4123 @{
a1ab1d2a 4124 .text 9+this_isnt_constant :
252b5132
RH
4125 @{ *(.text) @}
4126 @}
4127@end group
4128@end smallexample
4129@noindent
4130will cause the error message @samp{non constant expression for initial
4131address}.
4132
4133@node Expression Section
4134@subsection The Section of an Expression
4135@cindex expression sections
4136@cindex absolute expressions
4137@cindex relative expressions
4138@cindex absolute and relocatable symbols
4139@cindex relocatable and absolute symbols
4140@cindex symbols, relocatable and absolute
4141When the linker evaluates an expression, the result is either absolute
4142or relative to some section. A relative expression is expressed as a
4143fixed offset from the base of a section.
4144
4145The position of the expression within the linker script determines
4146whether it is absolute or relative. An expression which appears within
4147an output section definition is relative to the base of the output
4148section. An expression which appears elsewhere will be absolute.
4149
4150A symbol set to a relative expression will be relocatable if you request
4151relocatable output using the @samp{-r} option. That means that a
4152further link operation may change the value of the symbol. The symbol's
4153section will be the section of the relative expression.
4154
4155A symbol set to an absolute expression will retain the same value
4156through any further link operation. The symbol will be absolute, and
4157will not have any particular associated section.
4158
4159You can use the builtin function @code{ABSOLUTE} to force an expression
4160to be absolute when it would otherwise be relative. For example, to
4161create an absolute symbol set to the address of the end of the output
4162section @samp{.data}:
4163@smallexample
4164SECTIONS
4165 @{
4166 .data : @{ *(.data) _edata = ABSOLUTE(.); @}
4167 @}
4168@end smallexample
4169@noindent
4170If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
4171@samp{.data} section.
4172
4173@node Builtin Functions
4174@subsection Builtin Functions
4175@cindex functions in expressions
4176The linker script language includes a number of builtin functions for
4177use in linker script expressions.
4178
4179@table @code
4180@item ABSOLUTE(@var{exp})
4181@kindex ABSOLUTE(@var{exp})
4182@cindex expression, absolute
4183Return the absolute (non-relocatable, as opposed to non-negative) value
4184of the expression @var{exp}. Primarily useful to assign an absolute
4185value to a symbol within a section definition, where symbol values are
4186normally section relative. @xref{Expression Section}.
4187
4188@item ADDR(@var{section})
4189@kindex ADDR(@var{section})
4190@cindex section address in expression
4191Return the absolute address (the VMA) of the named @var{section}. Your
4192script must previously have defined the location of that section. In
4193the following example, @code{symbol_1} and @code{symbol_2} are assigned
4194identical values:
4195@smallexample
4196@group
4197SECTIONS @{ @dots{}
4198 .output1 :
a1ab1d2a 4199 @{
252b5132
RH
4200 start_of_output_1 = ABSOLUTE(.);
4201 @dots{}
4202 @}
4203 .output :
4204 @{
4205 symbol_1 = ADDR(.output1);
4206 symbol_2 = start_of_output_1;
4207 @}
4208@dots{} @}
4209@end group
4210@end smallexample
4211
4212@item ALIGN(@var{exp})
4213@kindex ALIGN(@var{exp})
4214@cindex round up location counter
4215@cindex align location counter
4216Return the location counter (@code{.}) aligned to the next @var{exp}
3c6706bb 4217boundary.
252b5132
RH
4218@code{ALIGN} doesn't change the value of the location counter---it just
4219does arithmetic on it. Here is an example which aligns the output
4220@code{.data} section to the next @code{0x2000} byte boundary after the
4221preceding section and sets a variable within the section to the next
4222@code{0x8000} boundary after the input sections:
4223@smallexample
4224@group
4225SECTIONS @{ @dots{}
4226 .data ALIGN(0x2000): @{
4227 *(.data)
4228 variable = ALIGN(0x8000);
4229 @}
4230@dots{} @}
4231@end group
4232@end smallexample
4233@noindent
4234The first use of @code{ALIGN} in this example specifies the location of
4235a section because it is used as the optional @var{address} attribute of
4236a section definition (@pxref{Output Section Address}). The second use
4237of @code{ALIGN} is used to defines the value of a symbol.
4238
4239The builtin function @code{NEXT} is closely related to @code{ALIGN}.
4240
4241@item BLOCK(@var{exp})
4242@kindex BLOCK(@var{exp})
4243This is a synonym for @code{ALIGN}, for compatibility with older linker
4244scripts. It is most often seen when setting the address of an output
4245section.
4246
2d20f7bf
JJ
4247@item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
4248@kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
4249This is equivalent to either
4250@smallexample
4251(ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
4252@end smallexample
4253or
4254@smallexample
4255(ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - @var{commonpagesize})))
4256@end smallexample
4257@noindent
4258depending on whether the latter uses fewer @var{commonpagesize} sized pages
4259for the data segment (area between the result of this expression and
4260@code{DATA_SEGMENT_END}) than the former or not.
4261If the latter form is used, it means @var{commonpagesize} bytes of runtime
4262memory will be saved at the expense of up to @var{commonpagesize} wasted
4263bytes in the on-disk file.
4264
4265This expression can only be used directly in @code{SECTIONS} commands, not in
4266any output section descriptions and only once in the linker script.
4267@var{commonpagesize} should be less or equal to @var{maxpagesize} and should
4268be the system page size the object wants to be optimized for (while still
4269working on system page sizes up to @var{maxpagesize}).
4270
4271@noindent
4272Example:
4273@smallexample
4274 . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
4275@end smallexample
4276
4277@item DATA_SEGMENT_END(@var{exp})
4278@kindex DATA_SEGMENT_END(@var{exp})
4279This defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
4280evaluation purposes.
4281
4282@smallexample
4283 . = DATA_SEGMENT_END(.);
4284@end smallexample
4285
252b5132
RH
4286@item DEFINED(@var{symbol})
4287@kindex DEFINED(@var{symbol})
4288@cindex symbol defaults
4289Return 1 if @var{symbol} is in the linker global symbol table and is
4290defined, otherwise return 0. You can use this function to provide
4291default values for symbols. For example, the following script fragment
4292shows how to set a global symbol @samp{begin} to the first location in
4293the @samp{.text} section---but if a symbol called @samp{begin} already
4294existed, its value is preserved:
4295
4296@smallexample
4297@group
4298SECTIONS @{ @dots{}
4299 .text : @{
4300 begin = DEFINED(begin) ? begin : . ;
4301 @dots{}
4302 @}
4303 @dots{}
4304@}
4305@end group
4306@end smallexample
4307
4308@item LOADADDR(@var{section})
4309@kindex LOADADDR(@var{section})
4310@cindex section load address in expression
4311Return the absolute LMA of the named @var{section}. This is normally
4312the same as @code{ADDR}, but it may be different if the @code{AT}
4313attribute is used in the output section definition (@pxref{Output
4314Section LMA}).
4315
4316@kindex MAX
4317@item MAX(@var{exp1}, @var{exp2})
4318Returns the maximum of @var{exp1} and @var{exp2}.
4319
4320@kindex MIN
4321@item MIN(@var{exp1}, @var{exp2})
4322Returns the minimum of @var{exp1} and @var{exp2}.
4323
4324@item NEXT(@var{exp})
4325@kindex NEXT(@var{exp})
4326@cindex unallocated address, next
4327Return the next unallocated address that is a multiple of @var{exp}.
4328This function is closely related to @code{ALIGN(@var{exp})}; unless you
4329use the @code{MEMORY} command to define discontinuous memory for the
4330output file, the two functions are equivalent.
4331
4332@item SIZEOF(@var{section})
4333@kindex SIZEOF(@var{section})
4334@cindex section size
4335Return the size in bytes of the named @var{section}, if that section has
4336been allocated. If the section has not been allocated when this is
4337evaluated, the linker will report an error. In the following example,
4338@code{symbol_1} and @code{symbol_2} are assigned identical values:
4339@smallexample
4340@group
4341SECTIONS@{ @dots{}
4342 .output @{
4343 .start = . ;
4344 @dots{}
4345 .end = . ;
4346 @}
4347 symbol_1 = .end - .start ;
4348 symbol_2 = SIZEOF(.output);
4349@dots{} @}
4350@end group
4351@end smallexample
4352
4353@item SIZEOF_HEADERS
4354@itemx sizeof_headers
4355@kindex SIZEOF_HEADERS
4356@cindex header size
4357Return the size in bytes of the output file's headers. This is
4358information which appears at the start of the output file. You can use
4359this number when setting the start address of the first section, if you
4360choose, to facilitate paging.
4361
4362@cindex not enough room for program headers
4363@cindex program headers, not enough room
4364When producing an ELF output file, if the linker script uses the
4365@code{SIZEOF_HEADERS} builtin function, the linker must compute the
4366number of program headers before it has determined all the section
4367addresses and sizes. If the linker later discovers that it needs
4368additional program headers, it will report an error @samp{not enough
4369room for program headers}. To avoid this error, you must avoid using
4370the @code{SIZEOF_HEADERS} function, or you must rework your linker
4371script to avoid forcing the linker to use additional program headers, or
4372you must define the program headers yourself using the @code{PHDRS}
4373command (@pxref{PHDRS}).
4374@end table
4375
4376@node Implicit Linker Scripts
4377@section Implicit Linker Scripts
4378@cindex implicit linker scripts
4379If you specify a linker input file which the linker can not recognize as
4380an object file or an archive file, it will try to read the file as a
4381linker script. If the file can not be parsed as a linker script, the
4382linker will report an error.
4383
4384An implicit linker script will not replace the default linker script.
4385
4386Typically an implicit linker script would contain only symbol
4387assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
4388commands.
4389
4390Any input files read because of an implicit linker script will be read
4391at the position in the command line where the implicit linker script was
4392read. This can affect archive searching.
4393
4394@ifset GENERIC
4395@node Machine Dependent
4396@chapter Machine Dependent Features
4397
4398@cindex machine dependencies
ff5dcc92
SC
4399@command{ld} has additional features on some platforms; the following
4400sections describe them. Machines where @command{ld} has no additional
252b5132
RH
4401functionality are not listed.
4402
4403@menu
4404* H8/300:: @code{ld} and the H8/300
4405* i960:: @code{ld} and the Intel 960 family
4406* ARM:: @code{ld} and the ARM family
47d89dba 4407* HPPA ELF32:: @code{ld} and HPPA 32-bit ELF
3c3bdf30
NC
4408@ifset MMIX
4409* MMIX:: @code{ld} and MMIX
4410@end ifset
2469cfa2
NC
4411@ifset MSP430
4412* MSP430:: @code{ld} and MSP430
4413@end ifset
74459f0e 4414@ifset TICOFF
ff5dcc92 4415* TI COFF:: @command{ld} and TI COFF
74459f0e 4416@end ifset
2ca22b03
NC
4417@ifset WIN32
4418* WIN32:: @command{ld} and WIN32 (cygwin/mingw)
4419@end ifset
252b5132
RH
4420@end menu
4421@end ifset
4422
4423@c FIXME! This could use @raisesections/@lowersections, but there seems to be a conflict
4424@c between those and node-defaulting.
4425@ifset H8300
4426@ifclear GENERIC
4427@raisesections
4428@end ifclear
4429
4430@node H8/300
ff5dcc92 4431@section @command{ld} and the H8/300
252b5132
RH
4432
4433@cindex H8/300 support
ff5dcc92 4434For the H8/300, @command{ld} can perform these global optimizations when
252b5132
RH
4435you specify the @samp{--relax} command-line option.
4436
4437@table @emph
4438@cindex relaxing on H8/300
4439@item relaxing address modes
ff5dcc92 4440@command{ld} finds all @code{jsr} and @code{jmp} instructions whose
252b5132
RH
4441targets are within eight bits, and turns them into eight-bit
4442program-counter relative @code{bsr} and @code{bra} instructions,
4443respectively.
4444
4445@cindex synthesizing on H8/300
4446@item synthesizing instructions
4447@c FIXME: specifically mov.b, or any mov instructions really?
ff5dcc92 4448@command{ld} finds all @code{mov.b} instructions which use the
252b5132
RH
4449sixteen-bit absolute address form, but refer to the top
4450page of memory, and changes them to use the eight-bit address form.
4451(That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
4452@samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
4453top page of memory).
4454@end table
4455
4456@ifclear GENERIC
4457@lowersections
4458@end ifclear
4459@end ifset
4460
2ca22b03
NC
4461@ifset WIN32
4462@ifclear GENERIC
4463@raisesections
4464@end ifclear
4465
4466@node WIN32
4467@section @command{ld} and WIN32 (cygwin/mingw)
4468
4469This section describes some of the win32 specific @command{ld} issues.
dc8465bf
NC
4470See @ref{Options,,Command Line Options} for detailed decription of the
4471command line options mentioned here.
2ca22b03
NC
4472
4473@table @emph
4474@cindex import libraries
4475@item import libraries
69da35b5 4476The standard Windows linker creates and uses so-called import
2ca22b03 4477libraries, which contains information for linking to dll's. They are
69da35b5
NC
4478regular static archives and are handled as any other static
4479archive. The cygwin and mingw ports of @command{ld} have specific
2ca22b03
NC
4480support for creating such libraries provided with the
4481@samp{--out-implib} command line option.
4482
dc8465bf
NC
4483@item exporting DLL symbols
4484@cindex exporting DLL symbols
4485The cygwin/mingw @command{ld} has several ways to export symbols for dll's.
4486
4487@table @emph
4488@item using auto-export functionality
4489@cindex using auto-export functionality
4490By default @command{ld} exports symbols with the auto-export functionality,
4491which is controlled by the following command line options:
4492
0a5d968e
NC
4493@itemize
4494@item --export-all-symbols [This is the default]
4495@item --exclude-symbols
4496@item --exclude-libs
4497@end itemize
4498
4499If, however, @samp{--export-all-symbols} is not given explicitly on the
4500command line, then the default auto-export behavior will be @emph{disabled}
4501if either of the following are true:
4502
4503@itemize
4504@item A DEF file is used.
4505@item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
4506@end itemize
dc8465bf
NC
4507
4508@item using a DEF file
4509@cindex using a DEF file
4510Another way of exporting symbols is using a DEF file. A DEF file is
4511an ASCII file containing definitions of symbols which should be
4512exported when a dll is created. Usually it is named @samp{<dll
4513name>.def} and is added as any other object file to the linker's
0a5d968e 4514command line. The file's name must end in @samp{.def} or @samp{.DEF}.
dc8465bf
NC
4515
4516@example
4517gcc -o <output> <objectfiles> <dll name>.def
4518@end example
4519
0a5d968e
NC
4520Using a DEF file turns off the normal auto-export behavior, unless the
4521@samp{--export-all-symbols} option is also used.
4522
dc8465bf
NC
4523Here is an example of a DEF file for a shared library called @samp{xyz.dll}:
4524
4525@example
4526LIBRARY "xyz.dll" BASE=0x10000000
4527
4528EXPORTS
4529foo
4530bar
4531_bar = bar
4532@end example
4533
4534This example defines a base address and three symbols. The third
4535symbol is an alias for the second. For the complete format
4536specification see ld/deffilep.y in the binutils sources.
4537
4538@cindex creating a DEF file
4539While linking a shared dll, @command{ld} is able to create a DEF file
4540with the @samp{--output-def <file>} command line option.
0a5d968e
NC
4541
4542@item Using decorations
4543@cindex Using decorations
4544Another way of marking symbols for export is to modify the source code
4545itself, so that when building the DLL each symbol to be exported is
4546declared as:
4547
4548@example
4549__declspec(dllexport) int a_variable
4550__declspec(dllexport) void a_function(int with_args)
4551@end example
4552
4553All such symbols will be exported from the DLL. If, however,
4554any of the object files in the DLL contain symbols decorated in
4555this way, then the normal auto-export behavior is disabled, unless
4556the @samp{--export-all-symbols} option is also used.
4557
4558Note that object files that wish to access these symbols must @emph{not}
4559decorate them with dllexport. Instead, they should use dllimport,
4560instead:
4561
4562@example
4563__declspec(dllimport) int a_variable
4564__declspec(dllimport) void a_function(int with_args)
4565@end example
4566
4567This complicates the structure of library header files, because
4568when included by the library itself the header must declare the
4569variables and functions as dllexport, but when included by client
4570code the header must declare them as dllimport. There are a number
4571of idioms that are typically used to do this; often client code can
4572omit the __declspec() declaration completely. See
4573@samp{--enable-auto-import} and @samp{automatic data imports} for more
4574imformation.
dc8465bf
NC
4575@end table
4576
2ca22b03
NC
4577@cindex automatic data imports
4578@item automatic data imports
4579The standard Windows dll format supports data imports from dlls only
69da35b5 4580by adding special decorations (dllimport/dllexport), which let the
2ca22b03 4581compiler produce specific assembler instructions to deal with this
69da35b5
NC
4582issue. This increases the effort necessary to port existing Un*x
4583code to these platforms, especially for large
2ca22b03 4584c++ libraries and applications. The auto-import feature, which was
69da35b5
NC
4585initially provided by Paul Sokolovsky, allows one to omit the
4586decorations to archieve a behavior that conforms to that on POSIX/Un*x
4587platforms. This feature is enabled with the @samp{--enable-auto-import}
4588command-line option, although it is enabled by default on cygwin/mingw.
4589The @samp{--enable-auto-import} option itself now serves mainly to
4590suppress any warnings that are ordinarily emitted when linked objects
4591trigger the feature's use.
4592
4593auto-import of variables does not always work flawlessly without
4594additional assistance. Sometimes, you will see this message
4595
4596"variable '<var>' can't be auto-imported. Please read the
4597documentation for ld's @code{--enable-auto-import} for details."
4598
4599The @samp{--enable-auto-import} documentation explains why this error
4600occurs, and several methods that can be used to overcome this difficulty.
4601One of these methods is the @emph{runtime pseudo-relocs} feature, described
4602below.
4603
4604@cindex runtime pseudo-relocation
4605For complex variables imported from DLLs (such as structs or classes),
4606object files typically contain a base address for the variable and an
4607offset (@emph{addend}) within the variable--to specify a particular
4608field or public member, for instance. Unfortunately, the runtime loader used
4609in win32 environments is incapable of fixing these references at runtime
4610without the additional information supplied by dllimport/dllexport decorations.
4611The standard auto-import feature described above is unable to resolve these
4612references.
4613
4614The @samp{--enable-runtime-pseudo-relocs} switch allows these references to
4615be resolved without error, while leaving the task of adjusting the references
4616themselves (with their non-zero addends) to specialized code provided by the
4617runtime environment. Recent versions of the cygwin and mingw environments and
4618compilers provide this runtime support; older versions do not. However, the
4619support is only necessary on the developer's platform; the compiled result will
4620run without error on an older system.
4621
4622@samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
4623enabled as needed.
2ca22b03
NC
4624
4625@cindex direct linking to a dll
4626@item direct linking to a dll
4627The cygwin/mingw ports of @command{ld} support the direct linking,
4628including data symbols, to a dll without the usage of any import
69da35b5
NC
4629libraries. This is much faster and uses much less memory than does the
4630traditional import library method, expecially when linking large
4631libraries or applications. When @command{ld} creates an import lib, each
4632function or variable exported from the dll is stored in its own bfd, even
4633though a single bfd could contain many exports. The overhead involved in
4634storing, loading, and processing so many bfd's is quite large, and explains the
4635tremendous time, memory, and storage needed to link against particularly
4636large or complex libraries when using import libs.
4637
4638Linking directly to a dll uses no extra command-line switches other than
4639@samp{-L} and @samp{-l}, because @command{ld} already searches for a number
4640of names to match each library. All that is needed from the developer's
4641perspective is an understanding of this search, in order to force ld to
4642select the dll instead of an import library.
4643
2ca22b03 4644
69da35b5
NC
4645For instance, when ld is called with the argument @samp{-lxxx} it will attempt
4646to find, in the first directory of its search path,
2ca22b03
NC
4647
4648@example
4649libxxx.dll.a
4650xxx.dll.a
4651libxxx.a
69da35b5 4652cygxxx.dll (*)
2ca22b03
NC
4653libxxx.dll
4654xxx.dll
4655@end example
4656
69da35b5
NC
4657before moving on to the next directory in the search path.
4658
4659(*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
4660where @samp{<prefix>} is set by the @command{ld} option
4661@samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
4662file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
4663@samp{cygxxx.dll}.
4664
4665Other win32-based unix environments, such as mingw or pw32, may use other
4666@samp{<prefix>}es, although at present only cygwin makes use of this feature. It
4667was originally intended to help avoid name conflicts among dll's built for the
4668various win32/un*x environments, so that (for example) two versions of a zlib dll
4669could coexist on the same machine.
4670
2ca22b03
NC
4671The generic cygwin/mingw path layout uses a @samp{bin} directory for
4672applications and dll's and a @samp{lib} directory for the import
69da35b5 4673libraries (using cygwin nomenclature):
2ca22b03
NC
4674
4675@example
4676bin/
4677 cygxxx.dll
4678lib/
4679 libxxx.dll.a (in case of dll's)
4680 libxxx.a (in case of static archive)
4681@end example
4682
69da35b5
NC
4683Linking directly to a dll without using the import library can be
4684done two ways:
2ca22b03
NC
4685
46861. Use the dll directly by adding the @samp{bin} path to the link line
4687@example
4688gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx
4689@end example
4690
69da35b5
NC
4691However, as the dll's often have version numbers appended to their names
4692(@samp{cygncurses-5.dll}) this will often fail, unless one specifies
4693@samp{-L../bin -lncurses-5} to include the version. Import libs are generally
4694not versioned, and do not have this difficulty.
4695
2ca22b03
NC
46962. Create a symbolic link from the dll to a file in the @samp{lib}
4697directory according to the above mentioned search pattern. This
4698should be used to avoid unwanted changes in the tools needed for
4699making the app/dll.
4700
4701@example
4702ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
4703@end example
4704
4705Then you can link without any make environment changes.
4706
4707@example
4708gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx
4709@end example
69da35b5
NC
4710
4711This technique also avoids the version number problems, because the following is
4712perfectly legal
4713
4714@example
4715bin/
4716 cygxxx-5.dll
4717lib/
4718 libxxx.dll.a -> ../bin/cygxxx-5.dll
4719@end example
4720
dc8465bf 4721Linking directly to a dll without using an import lib will work
69da35b5
NC
4722even when auto-import features are exercised, and even when
4723@samp{--enable-runtime-pseudo-relocs} is used.
4724
4725Given the improvements in speed and memory usage, one might justifiably
dc8465bf 4726wonder why import libraries are used at all. There are two reasons:
69da35b5
NC
4727
47281. Until recently, the link-directly-to-dll functionality did @emph{not}
4729work with auto-imported data.
4730
dc8465bf
NC
47312. Sometimes it is necessary to include pure static objects within the
4732import library (which otherwise contains only bfd's for indirection
4733symbols that point to the exports of a dll). Again, the import lib
4734for the cygwin kernel makes use of this ability, and it is not
4735possible to do this without an import lib.
69da35b5
NC
4736
4737So, import libs are not going away. But the ability to replace
4738true import libs with a simple symbolic link to (or a copy of)
4739a dll, in most cases, is a useful addition to the suite of tools
4740binutils makes available to the win32 developer. Given the
4741massive improvements in memory requirements during linking, storage
4742requirements, and linking speed, we expect that many developers
4743will soon begin to use this feature whenever possible.
dc8465bf
NC
4744
4745@item symbol aliasing
4746@table @emph
4747@item adding additional names
4748Sometimes, it is useful to export symbols with additional names.
4749A symbol @samp{foo} will be exported as @samp{foo}, but it can also be
4750exported as @samp{_foo} by using special directives in the DEF file
4751when creating the dll. This will affect also the optional created
4752import library. Consider the following DEF file:
4753
4754@example
4755LIBRARY "xyz.dll" BASE=0x61000000
4756
4757EXPORTS
4758foo
4759_foo = foo
4760@end example
4761
4762The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
4763
4764Another method for creating a symbol alias is to create it in the
4765source code using the "weak" attribute:
4766
4767@example
4768void foo () @{ /* Do something. */; @}
4769void _foo () __attribute__ ((weak, alias ("foo")));
4770@end example
4771
4772See the gcc manual for more information about attributes and weak
4773symbols.
4774
4775@item renaming symbols
4776Sometimes it is useful to rename exports. For instance, the cygwin
4777kernel does this regularly. A symbol @samp{_foo} can be exported as
4778@samp{foo} but not as @samp{_foo} by using special directives in the
4779DEF file. (This will also affect the import library, if it is
4780created). In the following example:
4781
4782@example
4783LIBRARY "xyz.dll" BASE=0x61000000
4784
4785EXPORTS
4786_foo = foo
4787@end example
4788
4789The line @samp{_foo = foo} maps the exported symbol @samp{foo} to
4790@samp{_foo}.
4791@end table
4792
0a5d968e
NC
4793Note: using a DEF file disables the default auto-export behavior,
4794unless the @samp{--export-all-symbols} command line option is used.
4795If, however, you are trying to rename symbols, then you should list
4796@emph{all} desired exports in the DEF file, including the symbols
4797that are not being renamed, and do @emph{not} use the
4798@samp{--export-all-symbols} option. If you list only the
4799renamed symbols in the DEF file, and use @samp{--export-all-symbols}
4800to handle the other symbols, then the both the new names @emph{and}
4801the original names for the the renamed symbols will be exported.
4802In effect, you'd be aliasing those symbols, not renaming them,
4803which is probably not what you wanted.
2ca22b03
NC
4804@end table
4805
4806@ifclear GENERIC
4807@lowersections
4808@end ifclear
4809@end ifset
4810
252b5132
RH
4811@ifclear GENERIC
4812@ifset Hitachi
4813@c This stuff is pointless to say unless you're especially concerned
4814@c with Hitachi chips; don't enable it for generic case, please.
4815@node Hitachi
ff5dcc92 4816@chapter @command{ld} and other Hitachi chips
252b5132 4817
ff5dcc92 4818@command{ld} also supports the H8/300H, the H8/500, and the Hitachi SH. No
252b5132
RH
4819special features, commands, or command-line options are required for
4820these chips.
4821@end ifset
4822@end ifclear
4823
4824@ifset I960
4825@ifclear GENERIC
4826@raisesections
4827@end ifclear
4828
4829@node i960
ff5dcc92 4830@section @command{ld} and the Intel 960 family
252b5132
RH
4831
4832@cindex i960 support
4833
4834You can use the @samp{-A@var{architecture}} command line option to
4835specify one of the two-letter names identifying members of the 960
4836family; the option specifies the desired output target, and warns of any
4837incompatible instructions in the input files. It also modifies the
4838linker's search strategy for archive libraries, to support the use of
4839libraries specific to each particular architecture, by including in the
4840search loop names suffixed with the string identifying the architecture.
4841
ff5dcc92 4842For example, if your @command{ld} command line included @w{@samp{-ACA}} as
252b5132
RH
4843well as @w{@samp{-ltry}}, the linker would look (in its built-in search
4844paths, and in any paths you specify with @samp{-L}) for a library with
4845the names
4846
4847@smallexample
4848@group
4849try
4850libtry.a
4851tryca
4852libtryca.a
4853@end group
4854@end smallexample
4855
4856@noindent
4857The first two possibilities would be considered in any event; the last
4858two are due to the use of @w{@samp{-ACA}}.
4859
4860You can meaningfully use @samp{-A} more than once on a command line, since
4861the 960 architecture family allows combination of target architectures; each
4862use will add another pair of name variants to search for when @w{@samp{-l}}
4863specifies a library.
4864
ff5dcc92 4865@cindex @option{--relax} on i960
252b5132 4866@cindex relaxing on i960
ff5dcc92
SC
4867@command{ld} supports the @samp{--relax} option for the i960 family. If
4868you specify @samp{--relax}, @command{ld} finds all @code{balx} and
252b5132
RH
4869@code{calx} instructions whose targets are within 24 bits, and turns
4870them into 24-bit program-counter relative @code{bal} and @code{cal}
ff5dcc92 4871instructions, respectively. @command{ld} also turns @code{cal}
252b5132
RH
4872instructions into @code{bal} instructions when it determines that the
4873target subroutine is a leaf routine (that is, the target subroutine does
4874not itself call any subroutines).
4875
4876@ifclear GENERIC
4877@lowersections
4878@end ifclear
4879@end ifset
4880
4881@ifclear GENERIC
4882@raisesections
4883@end ifclear
4884
4885@node ARM
ff5dcc92 4886@section @command{ld}'s support for interworking between ARM and Thumb code
252b5132
RH
4887
4888@cindex ARM interworking support
6f798e5c 4889@kindex --support-old-code
ff5dcc92 4890For the ARM, @command{ld} will generate code stubs to allow functions calls
252b5132
RH
4891betweem ARM and Thumb code. These stubs only work with code that has
4892been compiled and assembled with the @samp{-mthumb-interwork} command
4893line option. If it is necessary to link with old ARM object files or
4894libraries, which have not been compiled with the -mthumb-interwork
4895option then the @samp{--support-old-code} command line switch should be
4896given to the linker. This will make it generate larger stub functions
4897which will work with non-interworking aware ARM code. Note, however,
4898the linker does not support generating stubs for function calls to
4899non-interworking aware Thumb code.
4900
6f798e5c
NC
4901@cindex thumb entry point
4902@cindex entry point, thumb
4903@kindex --thumb-entry=@var{entry}
4904The @samp{--thumb-entry} switch is a duplicate of the generic
a1ab1d2a 4905@samp{--entry} switch, in that it sets the program's starting address.
6f798e5c
NC
4906But it also sets the bottom bit of the address, so that it can be
4907branched to using a BX instruction, and the program will start
4908executing in Thumb mode straight away.
4909
47d89dba 4910@node HPPA ELF32
ff5dcc92 4911@section @command{ld} and HPPA 32-bit ELF support
47d89dba
AM
4912@cindex HPPA multiple sub-space stubs
4913@kindex --multi-subspace
ff5dcc92 4914When generating a shared library, @command{ld} will by default generate
47d89dba 4915import stubs suitable for use with a single sub-space application.
ff5dcc92 4916The @samp{--multi-subspace} switch causes @command{ld} to generate export
47d89dba
AM
4917stubs, and different (larger) import stubs suitable for use with
4918multiple sub-spaces.
4919
4920@cindex HPPA stub grouping
4921@kindex --stub-group-size=@var{N}
ff5dcc92 4922Long branch stubs and import/export stubs are placed by @command{ld} in
47d89dba
AM
4923stub sections located between groups of input sections.
4924@samp{--stub-group-size} specifies the maximum size of a group of input
4925sections handled by one stub section. Since branch offsets are signed,
4926a stub section may serve two groups of input sections, one group before
4927the stub section, and one group after it. However, when using
4928conditional branches that require stubs, it may be better (for branch
4929prediction) that stub sections only serve one group of input sections.
4930A negative value for @samp{N} chooses this scheme, ensuring that
4931branches to stubs always use a negative offset. Two special values of
4932@samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
ff5dcc92 4933@command{ld} to automatically size input section groups for the branch types
47d89dba
AM
4934detected, with the same behaviour regarding stub placement as other
4935positive or negative values of @samp{N} respectively.
4936
4937Note that @samp{--stub-group-size} does not split input sections. A
4938single input section larger than the group size specified will of course
4939create a larger group (of one section). If input sections are too
4940large, it may not be possible for a branch to reach its stub.
4941
3c3bdf30
NC
4942@ifset MMIX
4943@node MMIX
4944@section @code{ld} and MMIX
4945For MMIX, there is choice of generating @code{ELF} object files or
4946@code{mmo} object files when linking. The simulator @code{mmix}
4947understands the @code{mmo} format. The binutils @code{objcopy} utility
4948can translate between the two formats.
4949
4950There is one special section, the @samp{.MMIX.reg_contents} section.
4951Contents in this section is assumed to correspond to that of global
4952registers, and symbols referring to it are translated to special symbols,
4953equal to registers. In a final link, the start address of the
4954@samp{.MMIX.reg_contents} section corresponds to the first allocated
4955global register multiplied by 8. Register @code{$255} is not included in
4956this section; it is always set to the program entry, which is at the
4957symbol @code{Main} for @code{mmo} files.
4958
4959Symbols with the prefix @code{__.MMIX.start.}, for example
4960@code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special;
4961there must be only one each, even if they are local. The default linker
4962script uses these to set the default start address of a section.
4963
4964Initial and trailing multiples of zero-valued 32-bit words in a section,
4965are left out from an mmo file.
4966@end ifset
4967
2469cfa2
NC
4968@ifset MSP430
4969@node MSP430
4970@section @code{ld} and MSP430
4971For the MSP430 it is possible to select the MPU architecture. The flag @samp{-m [mpu type]}
4972will select an appropriate linker script for selected MPU type. (To get a list of known MPUs
4973just pass @samp{-m help} option to the linker).
4974
4975@cindex MSP430 extra sections
4976The linker will recognize some extra sections which are MSP430 specific:
4977
4978@table @code
4979@item @samp{.vectors}
4980Defines a portion of ROM where interrupt vectors located.
4981
4982@item @samp{.bootloader}
4983Defines the bootloader portion of the ROM (if applicable). Any code
4984in this section will be uploaded to the MPU.
4985
4986@item @samp{.infomem}
4987Defines an information memory section (if applicable). Any code in
4988this section will be uploaded to the MPU.
4989
4990@item @samp{.infomemnobits}
4991This is the same as the @samp{.infomem} section except that any code
4992in this section will not be uploaded to the MPU.
4993
4994@item @samp{.noinit}
4995Denotes a portion of RAM located above @samp{.bss} section.
4996
4997The last two sections are used by gcc.
4998@end table
4999@end ifset
5000
74459f0e
TW
5001@ifset TICOFF
5002@node TI COFF
ff5dcc92 5003@section @command{ld}'s support for various TI COFF versions
74459f0e
TW
5004@cindex TI COFF versions
5005@kindex --format=@var{version}
5006The @samp{--format} switch allows selection of one of the various
5007TI COFF versions. The latest of this writing is 2; versions 0 and 1 are
5008also supported. The TI COFF versions also vary in header byte-order
ff5dcc92 5009format; @command{ld} will read any version or byte order, but the output
74459f0e
TW
5010header format depends on the default specified by the specific target.
5011@end ifset
5012
252b5132
RH
5013@ifclear GENERIC
5014@lowersections
5015@end ifclear
5016
5017@ifclear SingleFormat
5018@node BFD
5019@chapter BFD
5020
5021@cindex back end
5022@cindex object file management
5023@cindex object formats available
5024@kindex objdump -i
5025The linker accesses object and archive files using the BFD libraries.
5026These libraries allow the linker to use the same routines to operate on
5027object files whatever the object file format. A different object file
5028format can be supported simply by creating a new BFD back end and adding
5029it to the library. To conserve runtime memory, however, the linker and
5030associated tools are usually configured to support only a subset of the
5031object file formats available. You can use @code{objdump -i}
5032(@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
5033list all the formats available for your configuration.
5034
5035@cindex BFD requirements
5036@cindex requirements for BFD
5037As with most implementations, BFD is a compromise between
5038several conflicting requirements. The major factor influencing
5039BFD design was efficiency: any time used converting between
5040formats is time which would not have been spent had BFD not
5041been involved. This is partly offset by abstraction payback; since
5042BFD simplifies applications and back ends, more time and care
5043may be spent optimizing algorithms for a greater speed.
5044
5045One minor artifact of the BFD solution which you should bear in
5046mind is the potential for information loss. There are two places where
5047useful information can be lost using the BFD mechanism: during
5048conversion and during output. @xref{BFD information loss}.
5049
5050@menu
5051* BFD outline:: How it works: an outline of BFD
5052@end menu
5053
5054@node BFD outline
5055@section How it works: an outline of BFD
5056@cindex opening object files
5057@include bfdsumm.texi
5058@end ifclear
5059
5060@node Reporting Bugs
5061@chapter Reporting Bugs
ff5dcc92
SC
5062@cindex bugs in @command{ld}
5063@cindex reporting bugs in @command{ld}
252b5132 5064
ff5dcc92 5065Your bug reports play an essential role in making @command{ld} reliable.
252b5132
RH
5066
5067Reporting a bug may help you by bringing a solution to your problem, or
5068it may not. But in any case the principal function of a bug report is
ff5dcc92 5069to help the entire community by making the next version of @command{ld}
252b5132 5070work better. Bug reports are your contribution to the maintenance of
ff5dcc92 5071@command{ld}.
252b5132
RH
5072
5073In order for a bug report to serve its purpose, you must include the
5074information that enables us to fix the bug.
5075
5076@menu
5077* Bug Criteria:: Have you found a bug?
5078* Bug Reporting:: How to report bugs
5079@end menu
5080
5081@node Bug Criteria
5082@section Have you found a bug?
5083@cindex bug criteria
5084
5085If you are not sure whether you have found a bug, here are some guidelines:
5086
5087@itemize @bullet
5088@cindex fatal signal
5089@cindex linker crash
5090@cindex crash of linker
5091@item
5092If the linker gets a fatal signal, for any input whatever, that is a
ff5dcc92 5093@command{ld} bug. Reliable linkers never crash.
252b5132
RH
5094
5095@cindex error on valid input
5096@item
ff5dcc92 5097If @command{ld} produces an error message for valid input, that is a bug.
252b5132
RH
5098
5099@cindex invalid input
5100@item
ff5dcc92 5101If @command{ld} does not produce an error message for invalid input, that
252b5132
RH
5102may be a bug. In the general case, the linker can not verify that
5103object files are correct.
5104
5105@item
5106If you are an experienced user of linkers, your suggestions for
ff5dcc92 5107improvement of @command{ld} are welcome in any case.
252b5132
RH
5108@end itemize
5109
5110@node Bug Reporting
5111@section How to report bugs
5112@cindex bug reports
ff5dcc92 5113@cindex @command{ld} bugs, reporting
252b5132
RH
5114
5115A number of companies and individuals offer support for @sc{gnu}
ff5dcc92 5116products. If you obtained @command{ld} from a support organization, we
252b5132
RH
5117recommend you contact that organization first.
5118
5119You can find contact information for many support companies and
5120individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
5121distribution.
5122
ff5dcc92 5123Otherwise, send bug reports for @command{ld} to
d7ed7ca6 5124@samp{bug-binutils@@gnu.org}.
252b5132
RH
5125
5126The fundamental principle of reporting bugs usefully is this:
5127@strong{report all the facts}. If you are not sure whether to state a
5128fact or leave it out, state it!
5129
5130Often people omit facts because they think they know what causes the
5131problem and assume that some details do not matter. Thus, you might
b553b183
NC
5132assume that the name of a symbol you use in an example does not
5133matter. Well, probably it does not, but one cannot be sure. Perhaps
5134the bug is a stray memory reference which happens to fetch from the
5135location where that name is stored in memory; perhaps, if the name
5136were different, the contents of that location would fool the linker
5137into doing the right thing despite the bug. Play it safe and give a
5138specific, complete example. That is the easiest thing for you to do,
5139and the most helpful.
5140
5141Keep in mind that the purpose of a bug report is to enable us to fix
5142the bug if it is new to us. Therefore, always write your bug reports
5143on the assumption that the bug has not been reported previously.
252b5132
RH
5144
5145Sometimes people give a few sketchy facts and ask, ``Does this ring a
5146bell?'' Those bug reports are useless, and we urge everyone to
5147@emph{refuse to respond to them} except to chide the sender to report
5148bugs properly.
5149
5150To enable us to fix the bug, you should include all these things:
5151
5152@itemize @bullet
5153@item
ff5dcc92 5154The version of @command{ld}. @command{ld} announces it if you start it with
252b5132
RH
5155the @samp{--version} argument.
5156
5157Without this, we will not know whether there is any point in looking for
ff5dcc92 5158the bug in the current version of @command{ld}.
252b5132
RH
5159
5160@item
ff5dcc92 5161Any patches you may have applied to the @command{ld} source, including any
252b5132
RH
5162patches made to the @code{BFD} library.
5163
5164@item
5165The type of machine you are using, and the operating system name and
5166version number.
5167
5168@item
ff5dcc92 5169What compiler (and its version) was used to compile @command{ld}---e.g.
252b5132
RH
5170``@code{gcc-2.7}''.
5171
5172@item
5173The command arguments you gave the linker to link your example and
5174observe the bug. To guarantee you will not omit something important,
5175list them all. A copy of the Makefile (or the output from make) is
5176sufficient.
5177
5178If we were to try to guess the arguments, we would probably guess wrong
5179and then we might not encounter the bug.
5180
5181@item
5182A complete input file, or set of input files, that will reproduce the
b553b183
NC
5183bug. It is generally most helpful to send the actual object files
5184provided that they are reasonably small. Say no more than 10K. For
5185bigger files you can either make them available by FTP or HTTP or else
5186state that you are willing to send the object file(s) to whomever
5187requests them. (Note - your email will be going to a mailing list, so
5188we do not want to clog it up with large attachments). But small
5189attachments are best.
252b5132
RH
5190
5191If the source files were assembled using @code{gas} or compiled using
5192@code{gcc}, then it may be OK to send the source files rather than the
5193object files. In this case, be sure to say exactly what version of
5194@code{gas} or @code{gcc} was used to produce the object files. Also say
5195how @code{gas} or @code{gcc} were configured.
5196
5197@item
5198A description of what behavior you observe that you believe is
5199incorrect. For example, ``It gets a fatal signal.''
5200
ff5dcc92 5201Of course, if the bug is that @command{ld} gets a fatal signal, then we
252b5132
RH
5202will certainly notice it. But if the bug is incorrect output, we might
5203not notice unless it is glaringly wrong. You might as well not give us
5204a chance to make a mistake.
5205
5206Even if the problem you experience is a fatal signal, you should still
5207say so explicitly. Suppose something strange is going on, such as, your
ff5dcc92 5208copy of @command{ld} is out of synch, or you have encountered a bug in the
252b5132
RH
5209C library on your system. (This has happened!) Your copy might crash
5210and ours would not. If you told us to expect a crash, then when ours
5211fails to crash, we would know that the bug was not happening for us. If
5212you had not told us to expect a crash, then we would not be able to draw
5213any conclusion from our observations.
5214
5215@item
ff5dcc92 5216If you wish to suggest changes to the @command{ld} source, send us context
252b5132
RH
5217diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
5218@samp{-p} option. Always send diffs from the old file to the new file.
ff5dcc92 5219If you even discuss something in the @command{ld} source, refer to it by
252b5132
RH
5220context, not by line number.
5221
5222The line numbers in our development sources will not match those in your
5223sources. Your line numbers would convey no useful information to us.
5224@end itemize
5225
5226Here are some things that are not necessary:
5227
5228@itemize @bullet
5229@item
5230A description of the envelope of the bug.
5231
5232Often people who encounter a bug spend a lot of time investigating
5233which changes to the input file will make the bug go away and which
5234changes will not affect it.
5235
5236This is often time consuming and not very useful, because the way we
5237will find the bug is by running a single example under the debugger
5238with breakpoints, not by pure deduction from a series of examples.
5239We recommend that you save your time for something else.
5240
5241Of course, if you can find a simpler example to report @emph{instead}
5242of the original one, that is a convenience for us. Errors in the
5243output will be easier to spot, running under the debugger will take
5244less time, and so on.
5245
5246However, simplification is not vital; if you do not want to do this,
5247report the bug anyway and send us the entire test case you used.
5248
5249@item
5250A patch for the bug.
5251
5252A patch for the bug does help us if it is a good one. But do not omit
5253the necessary information, such as the test case, on the assumption that
5254a patch is all we need. We might see problems with your patch and decide
5255to fix the problem another way, or we might not understand it at all.
5256
ff5dcc92 5257Sometimes with a program as complicated as @command{ld} it is very hard to
252b5132
RH
5258construct an example that will make the program follow a certain path
5259through the code. If you do not send us the example, we will not be
5260able to construct one, so we will not be able to verify that the bug is
5261fixed.
5262
5263And if we cannot understand what bug you are trying to fix, or why your
5264patch should be an improvement, we will not install it. A test case will
5265help us to understand.
5266
5267@item
5268A guess about what the bug is or what it depends on.
5269
5270Such guesses are usually wrong. Even we cannot guess right about such
5271things without first using the debugger to find the facts.
5272@end itemize
5273
5274@node MRI
5275@appendix MRI Compatible Script Files
5276@cindex MRI compatibility
ff5dcc92
SC
5277To aid users making the transition to @sc{gnu} @command{ld} from the MRI
5278linker, @command{ld} can use MRI compatible linker scripts as an
252b5132
RH
5279alternative to the more general-purpose linker scripting language
5280described in @ref{Scripts}. MRI compatible linker scripts have a much
5281simpler command set than the scripting language otherwise used with
ff5dcc92 5282@command{ld}. @sc{gnu} @command{ld} supports the most commonly used MRI
252b5132
RH
5283linker commands; these commands are described here.
5284
5285In general, MRI scripts aren't of much use with the @code{a.out} object
5286file format, since it only has three sections and MRI scripts lack some
5287features to make use of them.
5288
5289You can specify a file containing an MRI-compatible script using the
5290@samp{-c} command-line option.
5291
5292Each command in an MRI-compatible script occupies its own line; each
5293command line starts with the keyword that identifies the command (though
5294blank lines are also allowed for punctuation). If a line of an
ff5dcc92 5295MRI-compatible script begins with an unrecognized keyword, @command{ld}
252b5132
RH
5296issues a warning message, but continues processing the script.
5297
5298Lines beginning with @samp{*} are comments.
5299
5300You can write these commands using all upper-case letters, or all
5301lower case; for example, @samp{chip} is the same as @samp{CHIP}.
5302The following list shows only the upper-case form of each command.
5303
5304@table @code
5305@cindex @code{ABSOLUTE} (MRI)
5306@item ABSOLUTE @var{secname}
5307@itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
ff5dcc92 5308Normally, @command{ld} includes in the output file all sections from all
252b5132
RH
5309the input files. However, in an MRI-compatible script, you can use the
5310@code{ABSOLUTE} command to restrict the sections that will be present in
5311your output program. If the @code{ABSOLUTE} command is used at all in a
5312script, then only the sections named explicitly in @code{ABSOLUTE}
5313commands will appear in the linker output. You can still use other
5314input sections (whatever you select on the command line, or using
5315@code{LOAD}) to resolve addresses in the output file.
5316
5317@cindex @code{ALIAS} (MRI)
5318@item ALIAS @var{out-secname}, @var{in-secname}
5319Use this command to place the data from input section @var{in-secname}
5320in a section called @var{out-secname} in the linker output file.
5321
5322@var{in-secname} may be an integer.
5323
5324@cindex @code{ALIGN} (MRI)
5325@item ALIGN @var{secname} = @var{expression}
5326Align the section called @var{secname} to @var{expression}. The
5327@var{expression} should be a power of two.
5328
5329@cindex @code{BASE} (MRI)
5330@item BASE @var{expression}
5331Use the value of @var{expression} as the lowest address (other than
5332absolute addresses) in the output file.
5333
5334@cindex @code{CHIP} (MRI)
5335@item CHIP @var{expression}
5336@itemx CHIP @var{expression}, @var{expression}
5337This command does nothing; it is accepted only for compatibility.
5338
5339@cindex @code{END} (MRI)
5340@item END
5341This command does nothing whatever; it's only accepted for compatibility.
5342
5343@cindex @code{FORMAT} (MRI)
5344@item FORMAT @var{output-format}
5345Similar to the @code{OUTPUT_FORMAT} command in the more general linker
a1ab1d2a 5346language, but restricted to one of these output formats:
252b5132
RH
5347
5348@enumerate
a1ab1d2a 5349@item
252b5132
RH
5350S-records, if @var{output-format} is @samp{S}
5351
5352@item
5353IEEE, if @var{output-format} is @samp{IEEE}
5354
5355@item
5356COFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is
5357@samp{COFF}
5358@end enumerate
5359
5360@cindex @code{LIST} (MRI)
5361@item LIST @var{anything}@dots{}
5362Print (to the standard output file) a link map, as produced by the
ff5dcc92 5363@command{ld} command-line option @samp{-M}.
252b5132
RH
5364
5365The keyword @code{LIST} may be followed by anything on the
5366same line, with no change in its effect.
5367
5368@cindex @code{LOAD} (MRI)
5369@item LOAD @var{filename}
5370@itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
5371Include one or more object file @var{filename} in the link; this has the
ff5dcc92 5372same effect as specifying @var{filename} directly on the @command{ld}
252b5132
RH
5373command line.
5374
5375@cindex @code{NAME} (MRI)
5376@item NAME @var{output-name}
ff5dcc92 5377@var{output-name} is the name for the program produced by @command{ld}; the
252b5132
RH
5378MRI-compatible command @code{NAME} is equivalent to the command-line
5379option @samp{-o} or the general script language command @code{OUTPUT}.
5380
5381@cindex @code{ORDER} (MRI)
5382@item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
5383@itemx ORDER @var{secname} @var{secname} @var{secname}
ff5dcc92 5384Normally, @command{ld} orders the sections in its output file in the
252b5132
RH
5385order in which they first appear in the input files. In an MRI-compatible
5386script, you can override this ordering with the @code{ORDER} command. The
5387sections you list with @code{ORDER} will appear first in your output
5388file, in the order specified.
5389
5390@cindex @code{PUBLIC} (MRI)
5391@item PUBLIC @var{name}=@var{expression}
5392@itemx PUBLIC @var{name},@var{expression}
5393@itemx PUBLIC @var{name} @var{expression}
5394Supply a value (@var{expression}) for external symbol
5395@var{name} used in the linker input files.
5396
5397@cindex @code{SECT} (MRI)
5398@item SECT @var{secname}, @var{expression}
5399@itemx SECT @var{secname}=@var{expression}
5400@itemx SECT @var{secname} @var{expression}
5401You can use any of these three forms of the @code{SECT} command to
5402specify the start address (@var{expression}) for section @var{secname}.
5403If you have more than one @code{SECT} statement for the same
5404@var{secname}, only the @emph{first} sets the start address.
5405@end table
5406
704c465c
NC
5407@node GNU Free Documentation License
5408@appendix GNU Free Documentation License
5409@cindex GNU Free Documentation License
5410
5411 GNU Free Documentation License
a1ab1d2a 5412
704c465c
NC
5413 Version 1.1, March 2000
5414
5415 Copyright (C) 2000 Free Software Foundation, Inc.
5416 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a1ab1d2a 5417
704c465c
NC
5418 Everyone is permitted to copy and distribute verbatim copies
5419 of this license document, but changing it is not allowed.
5420
5421
54220. PREAMBLE
5423
5424The purpose of this License is to make a manual, textbook, or other
5425written document "free" in the sense of freedom: to assure everyone
5426the effective freedom to copy and redistribute it, with or without
5427modifying it, either commercially or noncommercially. Secondarily,
5428this License preserves for the author and publisher a way to get
5429credit for their work, while not being considered responsible for
5430modifications made by others.
5431
5432This License is a kind of "copyleft", which means that derivative
5433works of the document must themselves be free in the same sense. It
5434complements the GNU General Public License, which is a copyleft
5435license designed for free software.
5436
5437We have designed this License in order to use it for manuals for free
5438software, because free software needs free documentation: a free
5439program should come with manuals providing the same freedoms that the
5440software does. But this License is not limited to software manuals;
5441it can be used for any textual work, regardless of subject matter or
5442whether it is published as a printed book. We recommend this License
5443principally for works whose purpose is instruction or reference.
5444
5445
54461. APPLICABILITY AND DEFINITIONS
5447
5448This License applies to any manual or other work that contains a
5449notice placed by the copyright holder saying it can be distributed
5450under the terms of this License. The "Document", below, refers to any
5451such manual or work. Any member of the public is a licensee, and is
5452addressed as "you".
5453
5454A "Modified Version" of the Document means any work containing the
5455Document or a portion of it, either copied verbatim, or with
5456modifications and/or translated into another language.
5457
5458A "Secondary Section" is a named appendix or a front-matter section of
5459the Document that deals exclusively with the relationship of the
5460publishers or authors of the Document to the Document's overall subject
5461(or to related matters) and contains nothing that could fall directly
5462within that overall subject. (For example, if the Document is in part a
5463textbook of mathematics, a Secondary Section may not explain any
5464mathematics.) The relationship could be a matter of historical
5465connection with the subject or with related matters, or of legal,
5466commercial, philosophical, ethical or political position regarding
5467them.
5468
5469The "Invariant Sections" are certain Secondary Sections whose titles
5470are designated, as being those of Invariant Sections, in the notice
5471that says that the Document is released under this License.
5472
5473The "Cover Texts" are certain short passages of text that are listed,
5474as Front-Cover Texts or Back-Cover Texts, in the notice that says that
5475the Document is released under this License.
5476
5477A "Transparent" copy of the Document means a machine-readable copy,
5478represented in a format whose specification is available to the
5479general public, whose contents can be viewed and edited directly and
5480straightforwardly with generic text editors or (for images composed of
5481pixels) generic paint programs or (for drawings) some widely available
5482drawing editor, and that is suitable for input to text formatters or
5483for automatic translation to a variety of formats suitable for input
5484to text formatters. A copy made in an otherwise Transparent file
5485format whose markup has been designed to thwart or discourage
5486subsequent modification by readers is not Transparent. A copy that is
5487not "Transparent" is called "Opaque".
5488
5489Examples of suitable formats for Transparent copies include plain
5490ASCII without markup, Texinfo input format, LaTeX input format, SGML
5491or XML using a publicly available DTD, and standard-conforming simple
5492HTML designed for human modification. Opaque formats include
5493PostScript, PDF, proprietary formats that can be read and edited only
5494by proprietary word processors, SGML or XML for which the DTD and/or
5495processing tools are not generally available, and the
5496machine-generated HTML produced by some word processors for output
5497purposes only.
5498
5499The "Title Page" means, for a printed book, the title page itself,
5500plus such following pages as are needed to hold, legibly, the material
5501this License requires to appear in the title page. For works in
5502formats which do not have any title page as such, "Title Page" means
5503the text near the most prominent appearance of the work's title,
5504preceding the beginning of the body of the text.
5505
5506
55072. VERBATIM COPYING
5508
5509You may copy and distribute the Document in any medium, either
5510commercially or noncommercially, provided that this License, the
5511copyright notices, and the license notice saying this License applies
5512to the Document are reproduced in all copies, and that you add no other
5513conditions whatsoever to those of this License. You may not use
5514technical measures to obstruct or control the reading or further
5515copying of the copies you make or distribute. However, you may accept
5516compensation in exchange for copies. If you distribute a large enough
5517number of copies you must also follow the conditions in section 3.
5518
5519You may also lend copies, under the same conditions stated above, and
5520you may publicly display copies.
5521
5522
55233. COPYING IN QUANTITY
5524
5525If you publish printed copies of the Document numbering more than 100,
5526and the Document's license notice requires Cover Texts, you must enclose
5527the copies in covers that carry, clearly and legibly, all these Cover
5528Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
5529the back cover. Both covers must also clearly and legibly identify
5530you as the publisher of these copies. The front cover must present
5531the full title with all words of the title equally prominent and
5532visible. You may add other material on the covers in addition.
5533Copying with changes limited to the covers, as long as they preserve
5534the title of the Document and satisfy these conditions, can be treated
5535as verbatim copying in other respects.
5536
5537If the required texts for either cover are too voluminous to fit
5538legibly, you should put the first ones listed (as many as fit
5539reasonably) on the actual cover, and continue the rest onto adjacent
5540pages.
5541
5542If you publish or distribute Opaque copies of the Document numbering
5543more than 100, you must either include a machine-readable Transparent
5544copy along with each Opaque copy, or state in or with each Opaque copy
5545a publicly-accessible computer-network location containing a complete
5546Transparent copy of the Document, free of added material, which the
5547general network-using public has access to download anonymously at no
5548charge using public-standard network protocols. If you use the latter
5549option, you must take reasonably prudent steps, when you begin
5550distribution of Opaque copies in quantity, to ensure that this
5551Transparent copy will remain thus accessible at the stated location
5552until at least one year after the last time you distribute an Opaque
5553copy (directly or through your agents or retailers) of that edition to
5554the public.
5555
5556It is requested, but not required, that you contact the authors of the
5557Document well before redistributing any large number of copies, to give
5558them a chance to provide you with an updated version of the Document.
5559
5560
55614. MODIFICATIONS
5562
5563You may copy and distribute a Modified Version of the Document under
5564the conditions of sections 2 and 3 above, provided that you release
5565the Modified Version under precisely this License, with the Modified
5566Version filling the role of the Document, thus licensing distribution
5567and modification of the Modified Version to whoever possesses a copy
5568of it. In addition, you must do these things in the Modified Version:
5569
5570A. Use in the Title Page (and on the covers, if any) a title distinct
5571 from that of the Document, and from those of previous versions
5572 (which should, if there were any, be listed in the History section
5573 of the Document). You may use the same title as a previous version
5574 if the original publisher of that version gives permission.
5575B. List on the Title Page, as authors, one or more persons or entities
5576 responsible for authorship of the modifications in the Modified
5577 Version, together with at least five of the principal authors of the
5578 Document (all of its principal authors, if it has less than five).
5579C. State on the Title page the name of the publisher of the
5580 Modified Version, as the publisher.
5581D. Preserve all the copyright notices of the Document.
5582E. Add an appropriate copyright notice for your modifications
5583 adjacent to the other copyright notices.
5584F. Include, immediately after the copyright notices, a license notice
5585 giving the public permission to use the Modified Version under the
5586 terms of this License, in the form shown in the Addendum below.
5587G. Preserve in that license notice the full lists of Invariant Sections
5588 and required Cover Texts given in the Document's license notice.
5589H. Include an unaltered copy of this License.
5590I. Preserve the section entitled "History", and its title, and add to
5591 it an item stating at least the title, year, new authors, and
5592 publisher of the Modified Version as given on the Title Page. If
5593 there is no section entitled "History" in the Document, create one
5594 stating the title, year, authors, and publisher of the Document as
5595 given on its Title Page, then add an item describing the Modified
5596 Version as stated in the previous sentence.
5597J. Preserve the network location, if any, given in the Document for
5598 public access to a Transparent copy of the Document, and likewise
5599 the network locations given in the Document for previous versions
5600 it was based on. These may be placed in the "History" section.
5601 You may omit a network location for a work that was published at
5602 least four years before the Document itself, or if the original
5603 publisher of the version it refers to gives permission.
5604K. In any section entitled "Acknowledgements" or "Dedications",
5605 preserve the section's title, and preserve in the section all the
5606 substance and tone of each of the contributor acknowledgements
5607 and/or dedications given therein.
5608L. Preserve all the Invariant Sections of the Document,
5609 unaltered in their text and in their titles. Section numbers
5610 or the equivalent are not considered part of the section titles.
5611M. Delete any section entitled "Endorsements". Such a section
5612 may not be included in the Modified Version.
5613N. Do not retitle any existing section as "Endorsements"
5614 or to conflict in title with any Invariant Section.
5615
5616If the Modified Version includes new front-matter sections or
5617appendices that qualify as Secondary Sections and contain no material
5618copied from the Document, you may at your option designate some or all
5619of these sections as invariant. To do this, add their titles to the
5620list of Invariant Sections in the Modified Version's license notice.
5621These titles must be distinct from any other section titles.
5622
5623You may add a section entitled "Endorsements", provided it contains
5624nothing but endorsements of your Modified Version by various
5625parties--for example, statements of peer review or that the text has
5626been approved by an organization as the authoritative definition of a
5627standard.
5628
5629You may add a passage of up to five words as a Front-Cover Text, and a
5630passage of up to 25 words as a Back-Cover Text, to the end of the list
5631of Cover Texts in the Modified Version. Only one passage of
5632Front-Cover Text and one of Back-Cover Text may be added by (or
5633through arrangements made by) any one entity. If the Document already
5634includes a cover text for the same cover, previously added by you or
5635by arrangement made by the same entity you are acting on behalf of,
5636you may not add another; but you may replace the old one, on explicit
5637permission from the previous publisher that added the old one.
5638
5639The author(s) and publisher(s) of the Document do not by this License
5640give permission to use their names for publicity for or to assert or
5641imply endorsement of any Modified Version.
5642
5643
56445. COMBINING DOCUMENTS
5645
5646You may combine the Document with other documents released under this
5647License, under the terms defined in section 4 above for modified
5648versions, provided that you include in the combination all of the
5649Invariant Sections of all of the original documents, unmodified, and
5650list them all as Invariant Sections of your combined work in its
5651license notice.
5652
5653The combined work need only contain one copy of this License, and
5654multiple identical Invariant Sections may be replaced with a single
5655copy. If there are multiple Invariant Sections with the same name but
5656different contents, make the title of each such section unique by
5657adding at the end of it, in parentheses, the name of the original
5658author or publisher of that section if known, or else a unique number.
5659Make the same adjustment to the section titles in the list of
5660Invariant Sections in the license notice of the combined work.
5661
5662In the combination, you must combine any sections entitled "History"
5663in the various original documents, forming one section entitled
5664"History"; likewise combine any sections entitled "Acknowledgements",
5665and any sections entitled "Dedications". You must delete all sections
5666entitled "Endorsements."
5667
5668
56696. COLLECTIONS OF DOCUMENTS
5670
5671You may make a collection consisting of the Document and other documents
5672released under this License, and replace the individual copies of this
5673License in the various documents with a single copy that is included in
5674the collection, provided that you follow the rules of this License for
5675verbatim copying of each of the documents in all other respects.
5676
5677You may extract a single document from such a collection, and distribute
5678it individually under this License, provided you insert a copy of this
5679License into the extracted document, and follow this License in all
5680other respects regarding verbatim copying of that document.
5681
5682
56837. AGGREGATION WITH INDEPENDENT WORKS
5684
5685A compilation of the Document or its derivatives with other separate
5686and independent documents or works, in or on a volume of a storage or
5687distribution medium, does not as a whole count as a Modified Version
5688of the Document, provided no compilation copyright is claimed for the
5689compilation. Such a compilation is called an "aggregate", and this
5690License does not apply to the other self-contained works thus compiled
5691with the Document, on account of their being thus compiled, if they
5692are not themselves derivative works of the Document.
5693
5694If the Cover Text requirement of section 3 is applicable to these
5695copies of the Document, then if the Document is less than one quarter
5696of the entire aggregate, the Document's Cover Texts may be placed on
5697covers that surround only the Document within the aggregate.
5698Otherwise they must appear on covers around the whole aggregate.
5699
5700
57018. TRANSLATION
5702
5703Translation is considered a kind of modification, so you may
5704distribute translations of the Document under the terms of section 4.
5705Replacing Invariant Sections with translations requires special
5706permission from their copyright holders, but you may include
5707translations of some or all Invariant Sections in addition to the
5708original versions of these Invariant Sections. You may include a
5709translation of this License provided that you also include the
5710original English version of this License. In case of a disagreement
5711between the translation and the original English version of this
5712License, the original English version will prevail.
5713
5714
57159. TERMINATION
5716
5717You may not copy, modify, sublicense, or distribute the Document except
5718as expressly provided for under this License. Any other attempt to
5719copy, modify, sublicense or distribute the Document is void, and will
5720automatically terminate your rights under this License. However,
5721parties who have received copies, or rights, from you under this
5722License will not have their licenses terminated so long as such
5723parties remain in full compliance.
5724
5725
572610. FUTURE REVISIONS OF THIS LICENSE
5727
5728The Free Software Foundation may publish new, revised versions
5729of the GNU Free Documentation License from time to time. Such new
5730versions will be similar in spirit to the present version, but may
5731differ in detail to address new problems or concerns. See
5732http://www.gnu.org/copyleft/.
5733
5734Each version of the License is given a distinguishing version number.
5735If the Document specifies that a particular numbered version of this
5736License "or any later version" applies to it, you have the option of
5737following the terms and conditions either of that specified version or
5738of any later version that has been published (not as a draft) by the
5739Free Software Foundation. If the Document does not specify a version
5740number of this License, you may choose any version ever published (not
5741as a draft) by the Free Software Foundation.
5742
5743
5744ADDENDUM: How to use this License for your documents
5745
5746To use this License in a document you have written, include a copy of
5747the License in the document and put the following copyright and
5748license notices just after the title page:
5749
5750@smallexample
5751 Copyright (c) YEAR YOUR NAME.
5752 Permission is granted to copy, distribute and/or modify this document
5753 under the terms of the GNU Free Documentation License, Version 1.1
5754 or any later version published by the Free Software Foundation;
5755 with the Invariant Sections being LIST THEIR TITLES, with the
5756 Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
5757 A copy of the license is included in the section entitled "GNU
5758 Free Documentation License".
5759@end smallexample
5760
5761If you have no Invariant Sections, write "with no Invariant Sections"
5762instead of saying which ones are invariant. If you have no
5763Front-Cover Texts, write "no Front-Cover Texts" instead of
5764"Front-Cover Texts being LIST"; likewise for Back-Cover Texts.
5765
5766If your document contains nontrivial examples of program code, we
5767recommend releasing these examples in parallel under your choice of
5768free software license, such as the GNU General Public License,
5769to permit their use in free software.
5770
252b5132
RH
5771@node Index
5772@unnumbered Index
5773
5774@printindex cp
5775
5776@tex
5777% I think something like @colophon should be in texinfo. In the
5778% meantime:
5779\long\def\colophon{\hbox to0pt{}\vfill
5780\centerline{The body of this manual is set in}
5781\centerline{\fontname\tenrm,}
5782\centerline{with headings in {\bf\fontname\tenbf}}
5783\centerline{and examples in {\tt\fontname\tentt}.}
5784\centerline{{\it\fontname\tenit\/} and}
5785\centerline{{\sl\fontname\tensl\/}}
5786\centerline{are used for emphasis.}\vfill}
5787\page\colophon
5788% Blame: doc@cygnus.com, 28mar91.
5789@end tex
5790
5791
5792@contents
5793@bye