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