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