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