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