1 This is ../../src/ld/ld.info, produced by makeinfo version 4.2 from
2 ../../src/ld/ld.texinfo.
5 * Ld: (ld). The GNU linker.
8 This file documents the GNU linker LD version 2.16.91.
10 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001,
11 2002, 2003, 2004 Free Software Foundation, Inc.
14 File: ld.info, Node: Top, Next: Overview, Up: (dir)
19 This file documents the GNU linker ld version 2.16.91.
21 This document is distributed under the terms of the GNU Free
22 Documentation License. A copy of the license is included in the
23 section entitled "GNU Free Documentation License".
28 * Invocation:: Invocation
29 * Scripts:: Linker Scripts
31 * Machine Dependent:: Machine Dependent Features
35 * Reporting Bugs:: Reporting Bugs
36 * MRI:: MRI Compatible Script Files
37 * GNU Free Documentation License:: GNU Free Documentation License
41 File: ld.info, Node: Overview, Next: Invocation, Prev: Top, Up: Top
46 `ld' combines a number of object and archive files, relocates their
47 data and ties up symbol references. Usually the last step in compiling
48 a program is to run `ld'.
50 `ld' accepts Linker Command Language files written in a superset of
51 AT&T's Link Editor Command Language syntax, to provide explicit and
52 total control over the linking process.
54 This version of `ld' uses the general purpose BFD libraries to
55 operate on object files. This allows `ld' to read, combine, and write
56 object files in many different formats--for example, COFF or `a.out'.
57 Different formats may be linked together to produce any available kind
58 of object file. *Note BFD::, for more information.
60 Aside from its flexibility, the GNU linker is more helpful than other
61 linkers in providing diagnostic information. Many linkers abandon
62 execution immediately upon encountering an error; whenever possible,
63 `ld' continues executing, allowing you to identify other errors (or, in
64 some cases, to get an output file in spite of the error).
67 File: ld.info, Node: Invocation, Next: Scripts, Prev: Overview, Up: Top
72 The GNU linker `ld' is meant to cover a broad range of situations,
73 and to be as compatible as possible with other linkers. As a result,
74 you have many choices to control its behavior.
78 * Options:: Command Line Options
79 * Environment:: Environment Variables
82 File: ld.info, Node: Options, Next: Environment, Up: Invocation
87 The linker supports a plethora of command-line options, but in actual
88 practice few of them are used in any particular context. For instance,
89 a frequent use of `ld' is to link standard Unix object files on a
90 standard, supported Unix system. On such a system, to link a file
93 ld -o OUTPUT /lib/crt0.o hello.o -lc
95 This tells `ld' to produce a file called OUTPUT as the result of
96 linking the file `/lib/crt0.o' with `hello.o' and the library `libc.a',
97 which will come from the standard search directories. (See the
98 discussion of the `-l' option below.)
100 Some of the command-line options to `ld' may be specified at any
101 point in the command line. However, options which refer to files, such
102 as `-l' or `-T', cause the file to be read at the point at which the
103 option appears in the command line, relative to the object files and
104 other file options. Repeating non-file options with a different
105 argument will either have no further effect, or override prior
106 occurrences (those further to the left on the command line) of that
107 option. Options which may be meaningfully specified more than once are
108 noted in the descriptions below.
110 Non-option arguments are object files or archives which are to be
111 linked together. They may follow, precede, or be mixed in with
112 command-line options, except that an object file argument may not be
113 placed between an option and its argument.
115 Usually the linker is invoked with at least one object file, but you
116 can specify other forms of binary input files using `-l', `-R', and the
117 script command language. If _no_ binary input files at all are
118 specified, the linker does not produce any output, and issues the
119 message `No input files'.
121 If the linker cannot recognize the format of an object file, it will
122 assume that it is a linker script. A script specified in this way
123 augments the main linker script used for the link (either the default
124 linker script or the one specified by using `-T'). This feature
125 permits the linker to link against a file which appears to be an object
126 or an archive, but actually merely defines some symbol values, or uses
127 `INPUT' or `GROUP' to load other objects. Note that specifying a
128 script in this way merely augments the main linker script; use the `-T'
129 option to replace the default linker script entirely. *Note Scripts::.
131 For options whose names are a single letter, option arguments must
132 either follow the option letter without intervening whitespace, or be
133 given as separate arguments immediately following the option that
136 For options whose names are multiple letters, either one dash or two
137 can precede the option name; for example, `-trace-symbol' and
138 `--trace-symbol' are equivalent. Note--there is one exception to this
139 rule. Multiple letter options that start with a lower case 'o' can
140 only be preceeded by two dashes. This is to reduce confusion with the
141 `-o' option. So for example `-omagic' sets the output file name to
142 `magic' whereas `--omagic' sets the NMAGIC flag on the output.
144 Arguments to multiple-letter options must either be separated from
145 the option name by an equals sign, or be given as separate arguments
146 immediately following the option that requires them. For example,
147 `--trace-symbol foo' and `--trace-symbol=foo' are equivalent. Unique
148 abbreviations of the names of multiple-letter options are accepted.
150 Note--if the linker is being invoked indirectly, via a compiler
151 driver (e.g. `gcc') then all the linker command line options should be
152 prefixed by `-Wl,' (or whatever is appropriate for the particular
153 compiler driver) like this:
155 gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
157 This is important, because otherwise the compiler driver program may
158 silently drop the linker options, resulting in a bad link.
160 Here is a table of the generic command line switches accepted by the
164 Read command-line options from FILE. The options read are
165 inserted in place of the original @FILE option. If FILE does not
166 exist, or cannot be read, then the option will be treated
167 literally, and not removed.
169 Options in FILE are separated by whitespace. A whitespace
170 character may be included in an option by surrounding the entire
171 option in either single or double quotes. Any character
172 (including a backslash) may be included by prefixing the character
173 to be included with a backslash. The FILE may itself contain
174 additional @FILE options; any such options will be processed
178 This option is supported for HP/UX compatibility. The KEYWORD
179 argument must be one of the strings `archive', `shared', or
180 `default'. `-aarchive' is functionally equivalent to `-Bstatic',
181 and the other two keywords are functionally equivalent to
182 `-Bdynamic'. This option may be used any number of times.
185 `--architecture=ARCHITECTURE'
186 In the current release of `ld', this option is useful only for the
187 Intel 960 family of architectures. In that `ld' configuration, the
188 ARCHITECTURE argument identifies the particular architecture in
189 the 960 family, enabling some safeguards and modifying the
190 archive-library search path. *Note `ld' and the Intel 960 family:
193 Future releases of `ld' may support similar functionality for
194 other architecture families.
197 `--format=INPUT-FORMAT'
198 `ld' may be configured to support more than one kind of object
199 file. If your `ld' is configured this way, you can use the `-b'
200 option to specify the binary format for input object files that
201 follow this option on the command line. Even when `ld' is
202 configured to support alternative object formats, you don't
203 usually need to specify this, as `ld' should be configured to
204 expect as a default input format the most usual format on each
205 machine. INPUT-FORMAT is a text string, the name of a particular
206 format supported by the BFD libraries. (You can list the
207 available binary formats with `objdump -i'.) *Note BFD::.
209 You may want to use this option if you are linking files with an
210 unusual binary format. You can also use `-b' to switch formats
211 explicitly (when linking object files of different formats), by
212 including `-b INPUT-FORMAT' before each group of object files in a
215 The default format is taken from the environment variable
216 `GNUTARGET'. *Note Environment::. You can also define the input
217 format from a script, using the command `TARGET'; see *Note Format
221 `--mri-script=MRI-COMMANDFILE'
222 For compatibility with linkers produced by MRI, `ld' accepts script
223 files written in an alternate, restricted command language,
224 described in *Note MRI Compatible Script Files: MRI. Introduce
225 MRI script files with the option `-c'; use the `-T' option to run
226 linker scripts written in the general-purpose `ld' scripting
227 language. If MRI-CMDFILE does not exist, `ld' looks for it in the
228 directories specified by any `-L' options.
233 These three options are equivalent; multiple forms are supported
234 for compatibility with other linkers. They assign space to common
235 symbols even if a relocatable output file is specified (with
236 `-r'). The script command `FORCE_COMMON_ALLOCATION' has the same
237 effect. *Note Miscellaneous Commands::.
241 Use ENTRY as the explicit symbol for beginning execution of your
242 program, rather than the default entry point. If there is no
243 symbol named ENTRY, the linker will try to parse ENTRY as a number,
244 and use that as the entry address (the number will be interpreted
245 in base 10; you may use a leading `0x' for base 16, or a leading
246 `0' for base 8). *Note Entry Point::, for a discussion of defaults
247 and other ways of specifying the entry point.
249 `--exclude-libs LIB,LIB,...'
250 Specifies a list of archive libraries from which symbols should
251 not be automatically exported. The library names may be delimited
252 by commas or colons. Specifying `--exclude-libs ALL' excludes
253 symbols in all archive libraries from automatic export. This
254 option is available only for the i386 PE targeted port of the
255 linker and for ELF targeted ports. For i386 PE, symbols
256 explicitly listed in a .def file are still exported, regardless of
257 this option. For ELF targeted ports, symbols affected by this
258 option will be treated as hidden.
262 When creating a dynamically linked executable, add all symbols to
263 the dynamic symbol table. The dynamic symbol table is the set of
264 symbols which are visible from dynamic objects at run time.
266 If you do not use this option, the dynamic symbol table will
267 normally contain only those symbols which are referenced by some
268 dynamic object mentioned in the link.
270 If you use `dlopen' to load a dynamic object which needs to refer
271 back to the symbols defined by the program, rather than some other
272 dynamic object, then you will probably need to use this option when
273 linking the program itself.
275 You can also use the version script to control what symbols should
276 be added to the dynamic symbol table if the output format supports
277 it. See the description of `--version-script' in *Note VERSION::.
280 Link big-endian objects. This affects the default output format.
283 Link little-endian objects. This affects the default output
288 When creating an ELF shared object, set the internal DT_AUXILIARY
289 field to the specified name. This tells the dynamic linker that
290 the symbol table of the shared object should be used as an
291 auxiliary filter on the symbol table of the shared object NAME.
293 If you later link a program against this filter object, then, when
294 you run the program, the dynamic linker will see the DT_AUXILIARY
295 field. If the dynamic linker resolves any symbols from the filter
296 object, it will first check whether there is a definition in the
297 shared object NAME. If there is one, it will be used instead of
298 the definition in the filter object. The shared object NAME need
299 not exist. Thus the shared object NAME may be used to provide an
300 alternative implementation of certain functions, perhaps for
301 debugging or for machine specific performance.
303 This option may be specified more than once. The DT_AUXILIARY
304 entries will be created in the order in which they appear on the
309 When creating an ELF shared object, set the internal DT_FILTER
310 field to the specified name. This tells the dynamic linker that
311 the symbol table of the shared object which is being created
312 should be used as a filter on the symbol table of the shared
315 If you later link a program against this filter object, then, when
316 you run the program, the dynamic linker will see the DT_FILTER
317 field. The dynamic linker will resolve symbols according to the
318 symbol table of the filter object as usual, but it will actually
319 link to the definitions found in the shared object NAME. Thus the
320 filter object can be used to select a subset of the symbols
321 provided by the object NAME.
323 Some older linkers used the `-F' option throughout a compilation
324 toolchain for specifying object-file format for both input and
325 output object files. The GNU linker uses other mechanisms for
326 this purpose: the `-b', `--format', `--oformat' options, the
327 `TARGET' command in linker scripts, and the `GNUTARGET'
328 environment variable. The GNU linker will ignore the `-F' option
329 when not creating an ELF shared object.
332 When creating an ELF executable or shared object, call NAME when
333 the executable or shared object is unloaded, by setting DT_FINI to
334 the address of the function. By default, the linker uses `_fini'
335 as the function to call.
338 Ignored. Provided for compatibility with other tools.
342 Set the maximum size of objects to be optimized using the GP
343 register to SIZE. This is only meaningful for object file formats
344 such as MIPS ECOFF which supports putting large and small objects
345 into different sections. This is ignored for other object file
350 When creating an ELF shared object, set the internal DT_SONAME
351 field to the specified name. When an executable is linked with a
352 shared object which has a DT_SONAME field, then when the
353 executable is run the dynamic linker will attempt to load the
354 shared object specified by the DT_SONAME field rather than the
355 using the file name given to the linker.
358 Perform an incremental link (same as option `-r').
361 When creating an ELF executable or shared object, call NAME when
362 the executable or shared object is loaded, by setting DT_INIT to
363 the address of the function. By default, the linker uses `_init'
364 as the function to call.
368 Add archive file ARCHIVE to the list of files to link. This
369 option may be used any number of times. `ld' will search its
370 path-list for occurrences of `libARCHIVE.a' for every ARCHIVE
373 On systems which support shared libraries, `ld' may also search for
374 libraries with extensions other than `.a'. Specifically, on ELF
375 and SunOS systems, `ld' will search a directory for a library with
376 an extension of `.so' before searching for one with an extension of
377 `.a'. By convention, a `.so' extension indicates a shared library.
379 The linker will search an archive only once, at the location where
380 it is specified on the command line. If the archive defines a
381 symbol which was undefined in some object which appeared before
382 the archive on the command line, the linker will include the
383 appropriate file(s) from the archive. However, an undefined
384 symbol in an object appearing later on the command line will not
385 cause the linker to search the archive again.
387 See the `-(' option for a way to force the linker to search
388 archives multiple times.
390 You may list the same archive multiple times on the command line.
392 This type of archive searching is standard for Unix linkers.
393 However, if you are using `ld' on AIX, note that it is different
394 from the behaviour of the AIX linker.
397 `--library-path=SEARCHDIR'
398 Add path SEARCHDIR to the list of paths that `ld' will search for
399 archive libraries and `ld' control scripts. You may use this
400 option any number of times. The directories are searched in the
401 order in which they are specified on the command line.
402 Directories specified on the command line are searched before the
403 default directories. All `-L' options apply to all `-l' options,
404 regardless of the order in which the options appear.
406 If SEARCHDIR begins with `=', then the `=' will be replaced by the
407 "sysroot prefix", a path specified when the linker is configured.
409 The default set of paths searched (without being specified with
410 `-L') depends on which emulation mode `ld' is using, and in some
411 cases also on how it was configured. *Note Environment::.
413 The paths can also be specified in a link script with the
414 `SEARCH_DIR' command. Directories specified this way are searched
415 at the point in which the linker script appears in the command
419 Emulate the EMULATION linker. You can list the available
420 emulations with the `--verbose' or `-V' options.
422 If the `-m' option is not used, the emulation is taken from the
423 `LDEMULATION' environment variable, if that is defined.
425 Otherwise, the default emulation depends upon how the linker was
430 Print a link map to the standard output. A link map provides
431 information about the link, including the following:
433 * Where object files are mapped into memory.
435 * How common symbols are allocated.
437 * All archive members included in the link, with a mention of
438 the symbol which caused the archive member to be brought in.
440 * The values assigned to symbols.
442 Note - symbols whose values are computed by an expression
443 which involves a reference to a previous value of the same
444 symbol may not have correct result displayed in the link map.
445 This is because the linker discards intermediate results and
446 only retains the final value of an expression. Under such
447 circumstances the linker will display the final value
448 enclosed by square brackets. Thus for example a linker
455 will produce the following output in the link map if the `-M'
459 [0x0000000c] foo = (foo * 0x4)
460 [0x0000000c] foo = (foo + 0x8)
462 See *Note Expressions:: for more information about
463 expressions in linker scripts.
467 Turn off page alignment of sections, and mark the output as
468 `NMAGIC' if possible.
472 Set the text and data sections to be readable and writable. Also,
473 do not page-align the data segment, and disable linking against
474 shared libraries. If the output format supports Unix style magic
475 numbers, mark the output as `OMAGIC'. Note: Although a writable
476 text section is allowed for PE-COFF targets, it does not conform
477 to the format specification published by Microsoft.
480 This option negates most of the effects of the `-N' option. It
481 sets the text section to be read-only, and forces the data segment
482 to be page-aligned. Note - this option does not enable linking
483 against shared libraries. Use `-Bdynamic' for this.
487 Use OUTPUT as the name for the program produced by `ld'; if this
488 option is not specified, the name `a.out' is used by default. The
489 script command `OUTPUT' can also specify the output file name.
492 If LEVEL is a numeric values greater than zero `ld' optimizes the
493 output. This might take significantly longer and therefore
494 probably should only be enabled for the final binary.
498 Leave relocation sections and contents in fully linked
499 exececutables. Post link analysis and optimization tools may need
500 this information in order to perform correct modifications of
501 executables. This results in larger executables.
503 This option is currently only supported on ELF platforms.
507 Generate relocatable output--i.e., generate an output file that
508 can in turn serve as input to `ld'. This is often called "partial
509 linking". As a side effect, in environments that support standard
510 Unix magic numbers, this option also sets the output file's magic
511 number to `OMAGIC'. If this option is not specified, an absolute
512 file is produced. When linking C++ programs, this option _will
513 not_ resolve references to constructors; to do that, use `-Ur'.
515 When an input file does not have the same format as the output
516 file, partial linking is only supported if that input file does
517 not contain any relocations. Different output formats can have
518 further restrictions; for example some `a.out'-based formats do
519 not support partial linking with input files in other formats at
522 This option does the same thing as `-i'.
525 `--just-symbols=FILENAME'
526 Read symbol names and their addresses from FILENAME, but do not
527 relocate it or include it in the output. This allows your output
528 file to refer symbolically to absolute locations of memory defined
529 in other programs. You may use this option more than once.
531 For compatibility with other ELF linkers, if the `-R' option is
532 followed by a directory name, rather than a file name, it is
533 treated as the `-rpath' option.
537 Omit all symbol information from the output file.
541 Omit debugger symbol information (but not all symbols) from the
546 Print the names of the input files as `ld' processes them.
549 `--script=SCRIPTFILE'
550 Use SCRIPTFILE as the linker script. This script replaces `ld''s
551 default linker script (rather than adding to it), so COMMANDFILE
552 must specify everything necessary to describe the output file.
553 *Note Scripts::. If SCRIPTFILE does not exist in the current
554 directory, `ld' looks for it in the directories specified by any
555 preceding `-L' options. Multiple `-T' options accumulate.
559 Force SYMBOL to be entered in the output file as an undefined
560 symbol. Doing this may, for example, trigger linking of additional
561 modules from standard libraries. `-u' may be repeated with
562 different option arguments to enter additional undefined symbols.
563 This option is equivalent to the `EXTERN' linker script command.
566 For anything other than C++ programs, this option is equivalent to
567 `-r': it generates relocatable output--i.e., an output file that
568 can in turn serve as input to `ld'. When linking C++ programs,
569 `-Ur' _does_ resolve references to constructors, unlike `-r'. It
570 does not work to use `-Ur' on files that were themselves linked
571 with `-Ur'; once the constructor table has been built, it cannot
572 be added to. Use `-Ur' only for the last partial link, and `-r'
576 Creates a separate output section for every input section matching
577 SECTION, or if the optional wildcard SECTION argument is missing,
578 for every orphan input section. An orphan section is one not
579 specifically mentioned in a linker script. You may use this option
580 multiple times on the command line; It prevents the normal
581 merging of input sections with the same name, overriding output
582 section assignments in a linker script.
587 Display the version number for `ld'. The `-V' option also lists
588 the supported emulations.
592 Delete all local symbols.
596 Delete all temporary local symbols. For most targets, this is all
597 local symbols whose names begin with `L'.
600 `--trace-symbol=SYMBOL'
601 Print the name of each linked file in which SYMBOL appears. This
602 option may be given any number of times. On many systems it is
603 necessary to prepend an underscore.
605 This option is useful when you have an undefined symbol in your
606 link but don't know where the reference is coming from.
609 Add PATH to the default library search path. This option exists
610 for Solaris compatibility.
613 The recognized keywords are:
615 Combines multiple reloc sections and sorts them to make
616 dynamic symbol lookup caching possible.
619 Disallows undefined symbols in object files. Undefined
620 symbols in shared libraries are still allowed.
623 Marks the object as requiring executable stack.
626 This option is only meaningful when building a shared object.
627 It marks the object so that its runtime initialization will
628 occur before the runtime initialization of any other objects
629 brought into the process at the same time. Similarly the
630 runtime finalization of the object will occur after the
631 runtime finalization of any other objects.
634 Marks the object that its symbol table interposes before all
635 symbols but the primary executable.
638 Marks the object that its filters be processed immediately at
642 Allows multiple definitions.
645 Disables multiple reloc sections combining.
648 Disables production of copy relocs.
651 Marks the object that the search for dependencies of this
652 object will ignore any default library search paths.
655 Marks the object shouldn't be unloaded at runtime.
658 Marks the object not available to `dlopen'.
661 Marks the object can not be dumped by `dldump'.
664 Marks the object as not requiring executable stack.
667 Don't create an ELF `PT_GNU_RELRO' segment header in the
671 When generating an executable or shared library, mark it to
672 tell the dynamic linker to resolve all symbols when the
673 program is started, or when the shared library is linked to
674 using dlopen, instead of deferring function call resolution
675 to the point when the function is first called.
678 Marks the object may contain $ORIGIN.
681 Create an ELF `PT_GNU_RELRO' segment header in the object.
683 Other keywords are ignored for Solaris compatibility.
686 `--start-group ARCHIVES --end-group'
687 The ARCHIVES should be a list of archive files. They may be
688 either explicit file names, or `-l' options.
690 The specified archives are searched repeatedly until no new
691 undefined references are created. Normally, an archive is
692 searched only once in the order that it is specified on the
693 command line. If a symbol in that archive is needed to resolve an
694 undefined symbol referred to by an object in an archive that
695 appears later on the command line, the linker would not be able to
696 resolve that reference. By grouping the archives, they all be
697 searched repeatedly until all possible references are resolved.
699 Using this option has a significant performance cost. It is best
700 to use it only when there are unavoidable circular references
701 between two or more archives.
703 `--accept-unknown-input-arch'
704 `--no-accept-unknown-input-arch'
705 Tells the linker to accept input files whose architecture cannot be
706 recognised. The assumption is that the user knows what they are
707 doing and deliberately wants to link in these unknown input files.
708 This was the default behaviour of the linker, before release
709 2.14. The default behaviour from release 2.14 onwards is to
710 reject such input files, and so the `--accept-unknown-input-arch'
711 option has been added to restore the old behaviour.
715 This option affects ELF DT_NEEDED tags for dynamic libraries
716 mentioned on the command line after the `--as-needed' option.
717 Normally, the linker will add a DT_NEEDED tag for each dynamic
718 library mentioned on the command line, regardless of whether the
719 library is actually needed. `--as-needed' causes DT_NEEDED tags
720 to only be emitted for libraries that satisfy some symbol
721 reference from regular objects which is undefined at the point
722 that the library was linked. `--no-as-needed' restores the
727 This option affects the treatment of dynamic libraries from ELF
728 DT_NEEDED tags in dynamic libraries mentioned on the command line
729 after the `--no-add-needed' option. Normally, the linker will add
730 a DT_NEEDED tag for each dynamic library from DT_NEEDED tags.
731 `--no-add-needed' causes DT_NEEDED tags will never be emitted for
732 those libraries from DT_NEEDED tags. `--add-needed' restores the
736 This option is ignored for SunOS compatibility.
741 Link against dynamic libraries. This is only meaningful on
742 platforms for which shared libraries are supported. This option
743 is normally the default on such platforms. The different variants
744 of this option are for compatibility with various systems. You
745 may use this option multiple times on the command line: it affects
746 library searching for `-l' options which follow it.
749 Set the `DF_1_GROUP' flag in the `DT_FLAGS_1' entry in the dynamic
750 section. This causes the runtime linker to handle lookups in this
751 object and its dependencies to be performed only inside the group.
752 `--unresolved-symbols=report-all' is implied. This option is only
753 meaningful on ELF platforms which support shared libraries.
759 Do not link against shared libraries. This is only meaningful on
760 platforms for which shared libraries are supported. The different
761 variants of this option are for compatibility with various
762 systems. You may use this option multiple times on the command
763 line: it affects library searching for `-l' options which follow
764 it. This option also implies `--unresolved-symbols=report-all'.
765 This option can be used with `-shared'. Doing so means that a
766 shared library is being created but that all of the library's
767 external references must be resolved by pulling in entries from
771 When creating a shared library, bind references to global symbols
772 to the definition within the shared library, if any. Normally, it
773 is possible for a program linked against a shared library to
774 override the definition within the shared library. This option is
775 only meaningful on ELF platforms which support shared libraries.
778 `--no-check-sections'
779 Asks the linker _not_ to check section addresses after they have
780 been assigned to see if there any overlaps. Normally the linker
781 will perform this check, and if it finds any overlaps it will
782 produce suitable error messages. The linker does know about, and
783 does make allowances for sections in overlays. The default
784 behaviour can be restored by using the command line switch
788 Output a cross reference table. If a linker map file is being
789 generated, the cross reference table is printed to the map file.
790 Otherwise, it is printed on the standard output.
792 The format of the table is intentionally simple, so that it may be
793 easily processed by a script if necessary. The symbols are
794 printed out, sorted by name. For each symbol, a list of file
795 names is given. If the symbol is defined, the first file listed
796 is the location of the definition. The remaining files contain
797 references to the symbol.
800 This option inhibits the assignment of addresses to common symbols.
801 The script command `INHIBIT_COMMON_ALLOCATION' has the same effect.
802 *Note Miscellaneous Commands::.
804 The `--no-define-common' option allows decoupling the decision to
805 assign addresses to Common symbols from the choice of the output
806 file type; otherwise a non-Relocatable output type forces
807 assigning addresses to Common symbols. Using `--no-define-common'
808 allows Common symbols that are referenced from a shared library to
809 be assigned addresses only in the main program. This eliminates
810 the unused duplicate space in the shared library, and also
811 prevents any possible confusion over resolving to the wrong
812 duplicate when there are many dynamic modules with specialized
813 search paths for runtime symbol resolution.
815 `--defsym SYMBOL=EXPRESSION'
816 Create a global symbol in the output file, containing the absolute
817 address given by EXPRESSION. You may use this option as many
818 times as necessary to define multiple symbols in the command line.
819 A limited form of arithmetic is supported for the EXPRESSION in
820 this context: you may give a hexadecimal constant or the name of
821 an existing symbol, or use `+' and `-' to add or subtract
822 hexadecimal constants or symbols. If you need more elaborate
823 expressions, consider using the linker command language from a
824 script (*note Assignment: Symbol Definitions: Assignments.).
825 _Note:_ there should be no white space between SYMBOL, the equals
826 sign ("<=>"), and EXPRESSION.
830 These options control whether to demangle symbol names in error
831 messages and other output. When the linker is told to demangle,
832 it tries to present symbol names in a readable fashion: it strips
833 leading underscores if they are used by the object file format,
834 and converts C++ mangled symbol names into user readable names.
835 Different compilers have different mangling styles. The optional
836 demangling style argument can be used to choose an appropriate
837 demangling style for your compiler. The linker will demangle by
838 default unless the environment variable `COLLECT_NO_DEMANGLE' is
839 set. These options may be used to override the default.
841 `--dynamic-linker FILE'
842 Set the name of the dynamic linker. This is only meaningful when
843 generating dynamically linked ELF executables. The default dynamic
844 linker is normally correct; don't use this unless you know what
848 Treat all warnings as errors.
851 Make sure that an output file has a .exe suffix.
853 If a successfully built fully linked output file does not have a
854 `.exe' or `.dll' suffix, this option forces the linker to copy the
855 output file to one of the same name with a `.exe' suffix. This
856 option is useful when using unmodified Unix makefiles on a
857 Microsoft Windows host, since some versions of Windows won't run
858 an image unless it ends in a `.exe' suffix.
862 Enable garbage collection of unused input sections. It is ignored
863 on targets that do not support this option. This option is not
864 compatible with `-r'. The default behaviour (of not performing
865 this garbage collection) can be restored by specifying
866 `--no-gc-sections' on the command line.
869 Print a summary of the command-line options on the standard output
873 Print a summary of all target specific options on the standard
877 Print a link map to the file MAPFILE. See the description of the
881 `ld' normally optimizes for speed over memory usage by caching the
882 symbol tables of input files in memory. This option tells `ld' to
883 instead optimize for memory usage, by rereading the symbol tables
884 as necessary. This may be required if `ld' runs out of memory
885 space while linking a large executable.
889 Report unresolved symbol references from regular object files.
890 This is done even if the linker is creating a non-symbolic shared
891 library. The switch `--[no-]allow-shlib-undefined' controls the
892 behaviour for reporting unresolved references found in shared
893 libraries being linked in.
895 `--allow-multiple-definition'
897 Normally when a symbol is defined multiple times, the linker will
898 report a fatal error. These options allow multiple definitions and
899 the first definition will be used.
901 `--allow-shlib-undefined'
902 `--no-allow-shlib-undefined'
903 Allows (the default) or disallows undefined symbols in shared
904 libraries. This switch is similar to `--no-undefined' except that
905 it determines the behaviour when the undefined symbols are in a
906 shared library rather than a regular object file. It does not
907 affect how undefined symbols in regular object files are handled.
909 The reason that `--allow-shlib-undefined' is the default is that
910 the shared library being specified at link time may not be the
911 same as the one that is available at load time, so the symbols
912 might actually be resolvable at load time. Plus there are some
913 systems, (eg BeOS) where undefined symbols in shared libraries is
914 normal. (The kernel patches them at load time to select which
915 function is most appropriate for the current architecture. This
916 is used for example to dynamically select an appropriate memset
917 function). Apparently it is also normal for HPPA shared libraries
918 to have undefined symbols.
920 `--no-undefined-version'
921 Normally when a symbol has an undefined version, the linker will
922 ignore it. This option disallows symbols with undefined version
923 and a fatal error will be issued instead.
926 Create and use a default symbol version (the soname) for
927 unversioned exported symbols.
929 `--default-imported-symver'
930 Create and use a default symbol version (the soname) for
931 unversioned imported symbols.
934 Normally `ld' will give an error if you try to link together input
935 files that are mismatched for some reason, perhaps because they
936 have been compiled for different processors or for different
937 endiannesses. This option tells `ld' that it should silently
938 permit such possible errors. This option should only be used with
939 care, in cases when you have taken some special action that
940 ensures that the linker errors are inappropriate.
943 Turn off the effect of the `--whole-archive' option for subsequent
947 Retain the executable output file whenever it is still usable.
948 Normally, the linker will not produce an output file if it
949 encounters errors during the link process; it exits without
950 writing an output file when it issues any error whatsoever.
953 Only search library directories explicitly specified on the
954 command line. Library directories specified in linker scripts
955 (including linker scripts specified on the command line) are
958 `--oformat OUTPUT-FORMAT'
959 `ld' may be configured to support more than one kind of object
960 file. If your `ld' is configured this way, you can use the
961 `--oformat' option to specify the binary format for the output
962 object file. Even when `ld' is configured to support alternative
963 object formats, you don't usually need to specify this, as `ld'
964 should be configured to produce as a default output format the most
965 usual format on each machine. OUTPUT-FORMAT is a text string, the
966 name of a particular format supported by the BFD libraries. (You
967 can list the available binary formats with `objdump -i'.) The
968 script command `OUTPUT_FORMAT' can also specify the output format,
969 but this option overrides it. *Note BFD::.
973 Create a position independent executable. This is currently only
974 supported on ELF platforms. Position independent executables are
975 similar to shared libraries in that they are relocated by the
976 dynamic linker to the virtual address the OS chooses for them
977 (which can vary between invocations). Like normal dynamically
978 linked executables they can be executed and symbols defined in the
979 executable cannot be overridden by shared libraries.
982 This option is ignored for Linux compatibility.
985 This option is ignored for SVR4 compatibility.
988 An option with machine dependent effects. This option is only
989 supported on a few targets. *Note `ld' and the H8/300: H8/300.
990 *Note `ld' and the Intel 960 family: i960. *Note `ld' and Xtensa
993 On some platforms, the `--relax' option performs global
994 optimizations that become possible when the linker resolves
995 addressing in the program, such as relaxing address modes and
996 synthesizing new instructions in the output object file.
998 On some platforms these link time global optimizations may make
999 symbolic debugging of the resulting executable impossible. This
1000 is known to be the case for the Matsushita MN10200 and MN10300
1001 family of processors.
1003 On platforms where this is not supported, `--relax' is accepted,
1006 `--retain-symbols-file FILENAME'
1007 Retain _only_ the symbols listed in the file FILENAME, discarding
1008 all others. FILENAME is simply a flat file, with one symbol name
1009 per line. This option is especially useful in environments (such
1010 as VxWorks) where a large global symbol table is accumulated
1011 gradually, to conserve run-time memory.
1013 `--retain-symbols-file' does _not_ discard undefined symbols, or
1014 symbols needed for relocations.
1016 You may only specify `--retain-symbols-file' once in the command
1017 line. It overrides `-s' and `-S'.
1020 Add a directory to the runtime library search path. This is used
1021 when linking an ELF executable with shared objects. All `-rpath'
1022 arguments are concatenated and passed to the runtime linker, which
1023 uses them to locate shared objects at runtime. The `-rpath'
1024 option is also used when locating shared objects which are needed
1025 by shared objects explicitly included in the link; see the
1026 description of the `-rpath-link' option. If `-rpath' is not used
1027 when linking an ELF executable, the contents of the environment
1028 variable `LD_RUN_PATH' will be used if it is defined.
1030 The `-rpath' option may also be used on SunOS. By default, on
1031 SunOS, the linker will form a runtime search patch out of all the
1032 `-L' options it is given. If a `-rpath' option is used, the
1033 runtime search path will be formed exclusively using the `-rpath'
1034 options, ignoring the `-L' options. This can be useful when using
1035 gcc, which adds many `-L' options which may be on NFS mounted
1038 For compatibility with other ELF linkers, if the `-R' option is
1039 followed by a directory name, rather than a file name, it is
1040 treated as the `-rpath' option.
1043 When using ELF or SunOS, one shared library may require another.
1044 This happens when an `ld -shared' link includes a shared library
1045 as one of the input files.
1047 When the linker encounters such a dependency when doing a
1048 non-shared, non-relocatable link, it will automatically try to
1049 locate the required shared library and include it in the link, if
1050 it is not included explicitly. In such a case, the `-rpath-link'
1051 option specifies the first set of directories to search. The
1052 `-rpath-link' option may specify a sequence of directory names
1053 either by specifying a list of names separated by colons, or by
1054 appearing multiple times.
1056 This option should be used with caution as it overrides the search
1057 path that may have been hard compiled into a shared library. In
1058 such a case it is possible to use unintentionally a different
1059 search path than the runtime linker would do.
1061 The linker uses the following search paths to locate required
1063 1. Any directories specified by `-rpath-link' options.
1065 2. Any directories specified by `-rpath' options. The difference
1066 between `-rpath' and `-rpath-link' is that directories
1067 specified by `-rpath' options are included in the executable
1068 and used at runtime, whereas the `-rpath-link' option is only
1069 effective at link time. It is for the native linker only.
1071 3. On an ELF system, if the `-rpath' and `rpath-link' options
1072 were not used, search the contents of the environment variable
1073 `LD_RUN_PATH'. It is for the native linker only.
1075 4. On SunOS, if the `-rpath' option was not used, search any
1076 directories specified using `-L' options.
1078 5. For a native linker, the contents of the environment variable
1081 6. For a native ELF linker, the directories in `DT_RUNPATH' or
1082 `DT_RPATH' of a shared library are searched for shared
1083 libraries needed by it. The `DT_RPATH' entries are ignored if
1084 `DT_RUNPATH' entries exist.
1086 7. The default directories, normally `/lib' and `/usr/lib'.
1088 8. For a native linker on an ELF system, if the file
1089 `/etc/ld.so.conf' exists, the list of directories found in
1092 If the required shared library is not found, the linker will issue
1093 a warning and continue with the link.
1097 Create a shared library. This is currently only supported on ELF,
1098 XCOFF and SunOS platforms. On SunOS, the linker will
1099 automatically create a shared library if the `-e' option is not
1100 used and there are undefined symbols in the link.
1103 This option tells `ld' to sort the common symbols by size when it
1104 places them in the appropriate output sections. First come all
1105 the one byte symbols, then all the two byte, then all the four
1106 byte, and then everything else. This is to prevent gaps between
1107 symbols due to alignment constraints.
1109 `--sort-section name'
1110 This option will apply `SORT_BY_NAME' to all wildcard section
1111 patterns in the linker script.
1113 `--sort-section alignment'
1114 This option will apply `SORT_BY_ALIGNMENT' to all wildcard section
1115 patterns in the linker script.
1117 `--split-by-file [SIZE]'
1118 Similar to `--split-by-reloc' but creates a new output section for
1119 each input file when SIZE is reached. SIZE defaults to a size of
1122 `--split-by-reloc [COUNT]'
1123 Tries to creates extra sections in the output file so that no
1124 single output section in the file contains more than COUNT
1125 relocations. This is useful when generating huge relocatable
1126 files for downloading into certain real time kernels with the COFF
1127 object file format; since COFF cannot represent more than 65535
1128 relocations in a single section. Note that this will fail to work
1129 with object file formats which do not support arbitrary sections.
1130 The linker will not split up individual input sections for
1131 redistribution, so if a single input section contains more than
1132 COUNT relocations one output section will contain that many
1133 relocations. COUNT defaults to a value of 32768.
1136 Compute and display statistics about the operation of the linker,
1137 such as execution time and memory usage.
1139 `--sysroot=DIRECTORY'
1140 Use DIRECTORY as the location of the sysroot, overriding the
1141 configure-time default. This option is only supported by linkers
1142 that were configured using `--with-sysroot'.
1144 `--traditional-format'
1145 For some targets, the output of `ld' is different in some ways from
1146 the output of some existing linker. This switch requests `ld' to
1147 use the traditional format instead.
1149 For example, on SunOS, `ld' combines duplicate entries in the
1150 symbol string table. This can reduce the size of an output file
1151 with full debugging information by over 30 percent.
1152 Unfortunately, the SunOS `dbx' program can not read the resulting
1153 program (`gdb' has no trouble). The `--traditional-format' switch
1154 tells `ld' to not combine duplicate entries.
1156 `--section-start SECTIONNAME=ORG'
1157 Locate a section in the output file at the absolute address given
1158 by ORG. You may use this option as many times as necessary to
1159 locate multiple sections in the command line. ORG must be a
1160 single hexadecimal integer; for compatibility with other linkers,
1161 you may omit the leading `0x' usually associated with hexadecimal
1162 values. _Note:_ there should be no white space between
1163 SECTIONNAME, the equals sign ("<=>"), and ORG.
1168 Same as -section-start, with `.bss', `.data' or `.text' as the
1171 `--unresolved-symbols=METHOD'
1172 Determine how to handle unresolved symbols. There are four
1173 possible values for `method':
1176 Do not report any unresolved symbols.
1179 Report all unresolved symbols. This is the default.
1181 `ignore-in-object-files'
1182 Report unresolved symbols that are contained in shared
1183 libraries, but ignore them if they come from regular object
1186 `ignore-in-shared-libs'
1187 Report unresolved symbols that come from regular object
1188 files, but ignore them if they come from shared libraries.
1189 This can be useful when creating a dynamic binary and it is
1190 known that all the shared libraries that it should be
1191 referencing are included on the linker's command line.
1193 The behaviour for shared libraries on their own can also be
1194 controlled by the `--[no-]allow-shlib-undefined' option.
1196 Normally the linker will generate an error message for each
1197 reported unresolved symbol but the option
1198 `--warn-unresolved-symbols' can change this to a warning.
1202 Display the version number for `ld' and list the linker emulations
1203 supported. Display which input files can and cannot be opened.
1204 Display the linker script being used by the linker.
1206 `--version-script=VERSION-SCRIPTFILE'
1207 Specify the name of a version script to the linker. This is
1208 typically used when creating shared libraries to specify
1209 additional information about the version hierarchy for the library
1210 being created. This option is only meaningful on ELF platforms
1211 which support shared libraries. *Note VERSION::.
1214 Warn when a common symbol is combined with another common symbol
1215 or with a symbol definition. Unix linkers allow this somewhat
1216 sloppy practise, but linkers on some other operating systems do
1217 not. This option allows you to find potential problems from
1218 combining global symbols. Unfortunately, some C libraries use
1219 this practise, so you may get some warnings about symbols in the
1220 libraries as well as in your programs.
1222 There are three kinds of global symbols, illustrated here by C
1226 A definition, which goes in the initialized data section of
1230 An undefined reference, which does not allocate space. There
1231 must be either a definition or a common symbol for the
1235 A common symbol. If there are only (one or more) common
1236 symbols for a variable, it goes in the uninitialized data
1237 area of the output file. The linker merges multiple common
1238 symbols for the same variable into a single symbol. If they
1239 are of different sizes, it picks the largest size. The
1240 linker turns a common symbol into a declaration, if there is
1241 a definition of the same variable.
1243 The `--warn-common' option can produce five kinds of warnings.
1244 Each warning consists of a pair of lines: the first describes the
1245 symbol just encountered, and the second describes the previous
1246 symbol encountered with the same name. One or both of the two
1247 symbols will be a common symbol.
1249 1. Turning a common symbol into a reference, because there is
1250 already a definition for the symbol.
1251 FILE(SECTION): warning: common of `SYMBOL'
1252 overridden by definition
1253 FILE(SECTION): warning: defined here
1255 2. Turning a common symbol into a reference, because a later
1256 definition for the symbol is encountered. This is the same
1257 as the previous case, except that the symbols are encountered
1258 in a different order.
1259 FILE(SECTION): warning: definition of `SYMBOL'
1261 FILE(SECTION): warning: common is here
1263 3. Merging a common symbol with a previous same-sized common
1265 FILE(SECTION): warning: multiple common
1267 FILE(SECTION): warning: previous common is here
1269 4. Merging a common symbol with a previous larger common symbol.
1270 FILE(SECTION): warning: common of `SYMBOL'
1271 overridden by larger common
1272 FILE(SECTION): warning: larger common is here
1274 5. Merging a common symbol with a previous smaller common
1275 symbol. This is the same as the previous case, except that
1276 the symbols are encountered in a different order.
1277 FILE(SECTION): warning: common of `SYMBOL'
1278 overriding smaller common
1279 FILE(SECTION): warning: smaller common is here
1281 `--warn-constructors'
1282 Warn if any global constructors are used. This is only useful for
1283 a few object file formats. For formats like COFF or ELF, the
1284 linker can not detect the use of global constructors.
1286 `--warn-multiple-gp'
1287 Warn if multiple global pointer values are required in the output
1288 file. This is only meaningful for certain processors, such as the
1289 Alpha. Specifically, some processors put large-valued constants
1290 in a special section. A special register (the global pointer)
1291 points into the middle of this section, so that constants can be
1292 loaded efficiently via a base-register relative addressing mode.
1293 Since the offset in base-register relative mode is fixed and
1294 relatively small (e.g., 16 bits), this limits the maximum size of
1295 the constant pool. Thus, in large programs, it is often necessary
1296 to use multiple global pointer values in order to be able to
1297 address all possible constants. This option causes a warning to
1298 be issued whenever this case occurs.
1301 Only warn once for each undefined symbol, rather than once per
1302 module which refers to it.
1304 `--warn-section-align'
1305 Warn if the address of an output section is changed because of
1306 alignment. Typically, the alignment will be set by an input
1307 section. The address will only be changed if it not explicitly
1308 specified; that is, if the `SECTIONS' command does not specify a
1309 start address for the section (*note SECTIONS::).
1311 `--warn-shared-textrel'
1312 Warn if the linker adds a DT_TEXTREL to a shared object.
1314 `--warn-unresolved-symbols'
1315 If the linker is going to report an unresolved symbol (see the
1316 option `--unresolved-symbols') it will normally generate an error.
1317 This option makes it generate a warning instead.
1319 `--error-unresolved-symbols'
1320 This restores the linker's default behaviour of generating errors
1321 when it is reporting unresolved symbols.
1324 For each archive mentioned on the command line after the
1325 `--whole-archive' option, include every object file in the archive
1326 in the link, rather than searching the archive for the required
1327 object files. This is normally used to turn an archive file into
1328 a shared library, forcing every object to be included in the
1329 resulting shared library. This option may be used more than once.
1331 Two notes when using this option from gcc: First, gcc doesn't know
1332 about this option, so you have to use `-Wl,-whole-archive'.
1333 Second, don't forget to use `-Wl,-no-whole-archive' after your
1334 list of archives, because gcc will add its own list of archives to
1335 your link and you may not want this flag to affect those as well.
1338 Use a wrapper function for SYMBOL. Any undefined reference to
1339 SYMBOL will be resolved to `__wrap_SYMBOL'. Any undefined
1340 reference to `__real_SYMBOL' will be resolved to SYMBOL.
1342 This can be used to provide a wrapper for a system function. The
1343 wrapper function should be called `__wrap_SYMBOL'. If it wishes
1344 to call the system function, it should call `__real_SYMBOL'.
1346 Here is a trivial example:
1349 __wrap_malloc (size_t c)
1351 printf ("malloc called with %zu\n", c);
1352 return __real_malloc (c);
1355 If you link other code with this file using `--wrap malloc', then
1356 all calls to `malloc' will call the function `__wrap_malloc'
1357 instead. The call to `__real_malloc' in `__wrap_malloc' will call
1358 the real `malloc' function.
1360 You may wish to provide a `__real_malloc' function as well, so that
1361 links without the `--wrap' option will succeed. If you do this,
1362 you should not put the definition of `__real_malloc' in the same
1363 file as `__wrap_malloc'; if you do, the assembler may resolve the
1364 call before the linker has a chance to wrap it to `malloc'.
1367 Request creation of `.eh_frame_hdr' section and ELF
1368 `PT_GNU_EH_FRAME' segment header.
1370 `--enable-new-dtags'
1371 `--disable-new-dtags'
1372 This linker can create the new dynamic tags in ELF. But the older
1373 ELF systems may not understand them. If you specify
1374 `--enable-new-dtags', the dynamic tags will be created as needed.
1375 If you specify `--disable-new-dtags', no new dynamic tags will be
1376 created. By default, the new dynamic tags are not created. Note
1377 that those options are only available for ELF systems.
1379 `--hash-size=NUMBER'
1380 Set the default size of the linker's hash tables to a prime number
1381 close to NUMBER. Increasing this value can reduce the length of
1382 time it takes the linker to perform its tasks, at the expense of
1383 increasing the linker's memory requirements. Similarly reducing
1384 this value can reduce the memory requirements at the expense of
1387 `--reduce-memory-overheads'
1388 This option reduces memory requirements at ld runtime, at the
1389 expense of linking speed. This was introduced to select the old
1390 O(n^2) algorithm for link map file generation, rather than the new
1391 O(n) algorithm which uses about 40% more memory for symbol storage.
1393 Another effect of the switch is to set the default hash table size
1394 to 1021, which again saves memory at the cost of lengthening the
1395 linker's run time. This is not done however if the `--hash-size'
1396 switch has been used.
1398 The `--reduce-memory-overheads' switch may be also be used to
1399 enable other tradeoffs in future versions of the linker.
1401 Options Specific to i386 PE Targets
1402 -----------------------------------
1404 The i386 PE linker supports the `-shared' option, which causes the
1405 output to be a dynamically linked library (DLL) instead of a normal
1406 executable. You should name the output `*.dll' when you use this
1407 option. In addition, the linker fully supports the standard `*.def'
1408 files, which may be specified on the linker command line like an object
1409 file (in fact, it should precede archives it exports symbols from, to
1410 ensure that they get linked in, just like a normal object file).
1412 The `-shared' option creates a relocatable DLL. To convert a
1413 relocatable DLL to a non-relocatable one, strip the `.reloc' section
1416 strip -R .reloc FOO.DLL
1418 In addition to the options common to all targets, the i386 PE linker
1419 support additional command line options that are specific to the i386
1420 PE target. Options that take values may be separated from their values
1421 by either a space or an equals sign.
1423 `--add-stdcall-alias'
1424 If given, symbols with a stdcall suffix (@NN) will be exported
1425 as-is and also with the suffix stripped. [This option is specific
1426 to the i386 PE targeted port of the linker]
1429 Use FILE as the name of a file in which to save the base addresses
1430 of all the relocations needed for generating DLLs with `dlltool'.
1431 [This is an i386 PE specific option]
1434 Create a DLL instead of a regular executable. You may also use
1435 `-shared' or specify a `LIBRARY' in a given `.def' file. [This
1436 option is specific to the i386 PE targeted port of the linker]
1438 `--enable-stdcall-fixup'
1439 `--disable-stdcall-fixup'
1440 If the link finds a symbol that it cannot resolve, it will attempt
1441 to do "fuzzy linking" by looking for another defined symbol that
1442 differs only in the format of the symbol name (cdecl vs stdcall)
1443 and will resolve that symbol by linking to the match. For
1444 example, the undefined symbol `_foo' might be linked to the
1445 function `_foo@12', or the undefined symbol `_bar@16' might be
1446 linked to the function `_bar'. When the linker does this, it
1447 prints a warning, since it normally should have failed to link,
1448 but sometimes import libraries generated from third-party dlls may
1449 need this feature to be usable. If you specify
1450 `--enable-stdcall-fixup', this feature is fully enabled and
1451 warnings are not printed. If you specify
1452 `--disable-stdcall-fixup', this feature is disabled and such
1453 mismatches are considered to be errors. [This option is specific
1454 to the i386 PE targeted port of the linker]
1456 `--export-all-symbols'
1457 If given, all global symbols in the objects used to build a DLL
1458 will be exported by the DLL. Note that this is the default if
1459 there otherwise wouldn't be any exported symbols. When symbols are
1460 explicitly exported via DEF files or implicitly exported via
1461 function attributes, the default is to not export anything else
1462 unless this option is given. Note that the symbols `DllMain@12',
1463 `DllEntryPoint@0', `DllMainCRTStartup@12', and `impure_ptr' will
1464 not be automatically exported. Also, symbols imported from other
1465 DLLs will not be re-exported, nor will symbols specifying the
1466 DLL's internal layout such as those beginning with `_head_' or
1467 ending with `_iname'. In addition, no symbols from `libgcc',
1468 `libstd++', `libmingw32', or `crtX.o' will be exported. Symbols
1469 whose names begin with `__rtti_' or `__builtin_' will not be
1470 exported, to help with C++ DLLs. Finally, there is an extensive
1471 list of cygwin-private symbols that are not exported (obviously,
1472 this applies on when building DLLs for cygwin targets). These
1473 cygwin-excludes are: `_cygwin_dll_entry@12',
1474 `_cygwin_crt0_common@8', `_cygwin_noncygwin_dll_entry@12',
1475 `_fmode', `_impure_ptr', `cygwin_attach_dll', `cygwin_premain0',
1476 `cygwin_premain1', `cygwin_premain2', `cygwin_premain3', and
1477 `environ'. [This option is specific to the i386 PE targeted port
1480 `--exclude-symbols SYMBOL,SYMBOL,...'
1481 Specifies a list of symbols which should not be automatically
1482 exported. The symbol names may be delimited by commas or colons.
1483 [This option is specific to the i386 PE targeted port of the
1487 Specify the file alignment. Sections in the file will always
1488 begin at file offsets which are multiples of this number. This
1489 defaults to 512. [This option is specific to the i386 PE targeted
1493 `--heap RESERVE,COMMIT'
1494 Specify the amount of memory to reserve (and optionally commit) to
1495 be used as heap for this program. The default is 1Mb reserved, 4K
1496 committed. [This option is specific to the i386 PE targeted port
1499 `--image-base VALUE'
1500 Use VALUE as the base address of your program or dll. This is the
1501 lowest memory location that will be used when your program or dll
1502 is loaded. To reduce the need to relocate and improve performance
1503 of your dlls, each should have a unique base address and not
1504 overlap any other dlls. The default is 0x400000 for executables,
1505 and 0x10000000 for dlls. [This option is specific to the i386 PE
1506 targeted port of the linker]
1509 If given, the stdcall suffixes (@NN) will be stripped from symbols
1510 before they are exported. [This option is specific to the i386 PE
1511 targeted port of the linker]
1513 `--large-address-aware'
1514 If given, the appropriate bit in the "Charateristics" field of the
1515 COFF header is set to indicate that this executable supports
1516 virtual addresses greater than 2 gigabytes. This should be used
1517 in conjuction with the /3GB or /USERVA=VALUE megabytes switch in
1518 the "[operating systems]" section of the BOOT.INI. Otherwise,
1519 this bit has no effect. [This option is specific to PE targeted
1520 ports of the linker]
1522 `--major-image-version VALUE'
1523 Sets the major number of the "image version". Defaults to 1.
1524 [This option is specific to the i386 PE targeted port of the
1527 `--major-os-version VALUE'
1528 Sets the major number of the "os version". Defaults to 4. [This
1529 option is specific to the i386 PE targeted port of the linker]
1531 `--major-subsystem-version VALUE'
1532 Sets the major number of the "subsystem version". Defaults to 4.
1533 [This option is specific to the i386 PE targeted port of the
1536 `--minor-image-version VALUE'
1537 Sets the minor number of the "image version". Defaults to 0.
1538 [This option is specific to the i386 PE targeted port of the
1541 `--minor-os-version VALUE'
1542 Sets the minor number of the "os version". Defaults to 0. [This
1543 option is specific to the i386 PE targeted port of the linker]
1545 `--minor-subsystem-version VALUE'
1546 Sets the minor number of the "subsystem version". Defaults to 0.
1547 [This option is specific to the i386 PE targeted port of the
1551 The linker will create the file FILE which will contain a DEF file
1552 corresponding to the DLL the linker is generating. This DEF file
1553 (which should be called `*.def') may be used to create an import
1554 library with `dlltool' or may be used as a reference to
1555 automatically or implicitly exported symbols. [This option is
1556 specific to the i386 PE targeted port of the linker]
1559 The linker will create the file FILE which will contain an import
1560 lib corresponding to the DLL the linker is generating. This import
1561 lib (which should be called `*.dll.a' or `*.a' may be used to link
1562 clients against the generated DLL; this behaviour makes it
1563 possible to skip a separate `dlltool' import library creation step.
1564 [This option is specific to the i386 PE targeted port of the
1567 `--enable-auto-image-base'
1568 Automatically choose the image base for DLLs, unless one is
1569 specified using the `--image-base' argument. By using a hash
1570 generated from the dllname to create unique image bases for each
1571 DLL, in-memory collisions and relocations which can delay program
1572 execution are avoided. [This option is specific to the i386 PE
1573 targeted port of the linker]
1575 `--disable-auto-image-base'
1576 Do not automatically generate a unique image base. If there is no
1577 user-specified image base (`--image-base') then use the platform
1578 default. [This option is specific to the i386 PE targeted port of
1581 `--dll-search-prefix STRING'
1582 When linking dynamically to a dll without an import library,
1583 search for `<string><basename>.dll' in preference to
1584 `lib<basename>.dll'. This behaviour allows easy distinction
1585 between DLLs built for the various "subplatforms": native, cygwin,
1586 uwin, pw, etc. For instance, cygwin DLLs typically use
1587 `--dll-search-prefix=cyg'. [This option is specific to the i386
1588 PE targeted port of the linker]
1590 `--enable-auto-import'
1591 Do sophisticated linking of `_symbol' to `__imp__symbol' for DATA
1592 imports from DLLs, and create the necessary thunking symbols when
1593 building the import libraries with those DATA exports. Note: Use
1594 of the 'auto-import' extension will cause the text section of the
1595 image file to be made writable. This does not conform to the
1596 PE-COFF format specification published by Microsoft.
1598 Using 'auto-import' generally will 'just work' - but sometimes you
1599 may see this message:
1601 "variable '<var>' can't be auto-imported. Please read the
1602 documentation for ld's `--enable-auto-import' for details."
1604 This message occurs when some (sub)expression accesses an address
1605 ultimately given by the sum of two constants (Win32 import tables
1606 only allow one). Instances where this may occur include accesses
1607 to member fields of struct variables imported from a DLL, as well
1608 as using a constant index into an array variable imported from a
1609 DLL. Any multiword variable (arrays, structs, long long, etc) may
1610 trigger this error condition. However, regardless of the exact
1611 data type of the offending exported variable, ld will always
1612 detect it, issue the warning, and exit.
1614 There are several ways to address this difficulty, regardless of
1615 the data type of the exported variable:
1617 One way is to use -enable-runtime-pseudo-reloc switch. This leaves
1618 the task of adjusting references in your client code for runtime
1619 environment, so this method works only when runtime environment
1620 supports this feature.
1622 A second solution is to force one of the 'constants' to be a
1623 variable - that is, unknown and un-optimizable at compile time.
1624 For arrays, there are two possibilities: a) make the indexee (the
1625 array's address) a variable, or b) make the 'constant' index a
1628 extern type extern_array[];
1630 { volatile type *t=extern_array; t[1] }
1634 extern type extern_array[];
1636 { volatile int t=1; extern_array[t] }
1638 For structs (and most other multiword data types) the only option
1639 is to make the struct itself (or the long long, or the ...)
1642 extern struct s extern_struct;
1643 extern_struct.field -->
1644 { volatile struct s *t=&extern_struct; t->field }
1648 extern long long extern_ll;
1650 { volatile long long * local_ll=&extern_ll; *local_ll }
1652 A third method of dealing with this difficulty is to abandon
1653 'auto-import' for the offending symbol and mark it with
1654 `__declspec(dllimport)'. However, in practise that requires using
1655 compile-time #defines to indicate whether you are building a DLL,
1656 building client code that will link to the DLL, or merely
1657 building/linking to a static library. In making the choice
1658 between the various methods of resolving the 'direct address with
1659 constant offset' problem, you should consider typical real-world
1667 void main(int argc, char **argv){
1668 printf("%d\n",arr[1]);
1676 void main(int argc, char **argv){
1677 /* This workaround is for win32 and cygwin; do not "optimize" */
1678 volatile int *parr = arr;
1679 printf("%d\n",parr[1]);
1684 /* Note: auto-export is assumed (no __declspec(dllexport)) */
1685 #if (defined(_WIN32) || defined(__CYGWIN__)) && \
1686 !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
1687 #define FOO_IMPORT __declspec(dllimport)
1691 extern FOO_IMPORT int arr[];
1694 void main(int argc, char **argv){
1695 printf("%d\n",arr[1]);
1698 A fourth way to avoid this problem is to re-code your library to
1699 use a functional interface rather than a data interface for the
1700 offending variables (e.g. set_foo() and get_foo() accessor
1701 functions). [This option is specific to the i386 PE targeted port
1704 `--disable-auto-import'
1705 Do not attempt to do sophisticated linking of `_symbol' to
1706 `__imp__symbol' for DATA imports from DLLs. [This option is
1707 specific to the i386 PE targeted port of the linker]
1709 `--enable-runtime-pseudo-reloc'
1710 If your code contains expressions described in -enable-auto-import
1711 section, that is, DATA imports from DLL with non-zero offset, this
1712 switch will create a vector of 'runtime pseudo relocations' which
1713 can be used by runtime environment to adjust references to such
1714 data in your client code. [This option is specific to the i386 PE
1715 targeted port of the linker]
1717 `--disable-runtime-pseudo-reloc'
1718 Do not create pseudo relocations for non-zero offset DATA imports
1719 from DLLs. This is the default. [This option is specific to the
1720 i386 PE targeted port of the linker]
1722 `--enable-extra-pe-debug'
1723 Show additional debug info related to auto-import symbol thunking.
1724 [This option is specific to the i386 PE targeted port of the
1727 `--section-alignment'
1728 Sets the section alignment. Sections in memory will always begin
1729 at addresses which are a multiple of this number. Defaults to
1730 0x1000. [This option is specific to the i386 PE targeted port of
1734 `--stack RESERVE,COMMIT'
1735 Specify the amount of memory to reserve (and optionally commit) to
1736 be used as stack for this program. The default is 2Mb reserved, 4K
1737 committed. [This option is specific to the i386 PE targeted port
1741 `--subsystem WHICH:MAJOR'
1742 `--subsystem WHICH:MAJOR.MINOR'
1743 Specifies the subsystem under which your program will execute. The
1744 legal values for WHICH are `native', `windows', `console',
1745 `posix', and `xbox'. You may optionally set the subsystem version
1746 also. Numeric values are also accepted for WHICH. [This option
1747 is specific to the i386 PE targeted port of the linker]
1750 File: ld.info, Node: Environment, Prev: Options, Up: Invocation
1752 Environment Variables
1753 =====================
1755 You can change the behaviour of `ld' with the environment variables
1756 `GNUTARGET', `LDEMULATION' and `COLLECT_NO_DEMANGLE'.
1758 `GNUTARGET' determines the input-file object format if you don't use
1759 `-b' (or its synonym `--format'). Its value should be one of the BFD
1760 names for an input format (*note BFD::). If there is no `GNUTARGET' in
1761 the environment, `ld' uses the natural format of the target. If
1762 `GNUTARGET' is set to `default' then BFD attempts to discover the input
1763 format by examining binary input files; this method often succeeds, but
1764 there are potential ambiguities, since there is no method of ensuring
1765 that the magic number used to specify object-file formats is unique.
1766 However, the configuration procedure for BFD on each system places the
1767 conventional format for that system first in the search-list, so
1768 ambiguities are resolved in favor of convention.
1770 `LDEMULATION' determines the default emulation if you don't use the
1771 `-m' option. The emulation can affect various aspects of linker
1772 behaviour, particularly the default linker script. You can list the
1773 available emulations with the `--verbose' or `-V' options. If the `-m'
1774 option is not used, and the `LDEMULATION' environment variable is not
1775 defined, the default emulation depends upon how the linker was
1778 Normally, the linker will default to demangling symbols. However, if
1779 `COLLECT_NO_DEMANGLE' is set in the environment, then it will default
1780 to not demangling symbols. This environment variable is used in a
1781 similar fashion by the `gcc' linker wrapper program. The default may
1782 be overridden by the `--demangle' and `--no-demangle' options.
1785 File: ld.info, Node: Scripts, Next: Machine Dependent, Prev: Invocation, Up: Top
1790 Every link is controlled by a "linker script". This script is
1791 written in the linker command language.
1793 The main purpose of the linker script is to describe how the
1794 sections in the input files should be mapped into the output file, and
1795 to control the memory layout of the output file. Most linker scripts
1796 do nothing more than this. However, when necessary, the linker script
1797 can also direct the linker to perform many other operations, using the
1798 commands described below.
1800 The linker always uses a linker script. If you do not supply one
1801 yourself, the linker will use a default script that is compiled into the
1802 linker executable. You can use the `--verbose' command line option to
1803 display the default linker script. Certain command line options, such
1804 as `-r' or `-N', will affect the default linker script.
1806 You may supply your own linker script by using the `-T' command line
1807 option. When you do this, your linker script will replace the default
1810 You may also use linker scripts implicitly by naming them as input
1811 files to the linker, as though they were files to be linked. *Note
1812 Implicit Linker Scripts::.
1816 * Basic Script Concepts:: Basic Linker Script Concepts
1817 * Script Format:: Linker Script Format
1818 * Simple Example:: Simple Linker Script Example
1819 * Simple Commands:: Simple Linker Script Commands
1820 * Assignments:: Assigning Values to Symbols
1821 * SECTIONS:: SECTIONS Command
1822 * MEMORY:: MEMORY Command
1823 * PHDRS:: PHDRS Command
1824 * VERSION:: VERSION Command
1825 * Expressions:: Expressions in Linker Scripts
1826 * Implicit Linker Scripts:: Implicit Linker Scripts
1829 File: ld.info, Node: Basic Script Concepts, Next: Script Format, Up: Scripts
1831 Basic Linker Script Concepts
1832 ============================
1834 We need to define some basic concepts and vocabulary in order to
1835 describe the linker script language.
1837 The linker combines input files into a single output file. The
1838 output file and each input file are in a special data format known as an
1839 "object file format". Each file is called an "object file". The
1840 output file is often called an "executable", but for our purposes we
1841 will also call it an object file. Each object file has, among other
1842 things, a list of "sections". We sometimes refer to a section in an
1843 input file as an "input section"; similarly, a section in the output
1844 file is an "output section".
1846 Each section in an object file has a name and a size. Most sections
1847 also have an associated block of data, known as the "section contents".
1848 A section may be marked as "loadable", which mean that the contents
1849 should be loaded into memory when the output file is run. A section
1850 with no contents may be "allocatable", which means that an area in
1851 memory should be set aside, but nothing in particular should be loaded
1852 there (in some cases this memory must be zeroed out). A section which
1853 is neither loadable nor allocatable typically contains some sort of
1854 debugging information.
1856 Every loadable or allocatable output section has two addresses. The
1857 first is the "VMA", or virtual memory address. This is the address the
1858 section will have when the output file is run. The second is the
1859 "LMA", or load memory address. This is the address at which the
1860 section will be loaded. In most cases the two addresses will be the
1861 same. An example of when they might be different is when a data section
1862 is loaded into ROM, and then copied into RAM when the program starts up
1863 (this technique is often used to initialize global variables in a ROM
1864 based system). In this case the ROM address would be the LMA, and the
1865 RAM address would be the VMA.
1867 You can see the sections in an object file by using the `objdump'
1868 program with the `-h' option.
1870 Every object file also has a list of "symbols", known as the "symbol
1871 table". A symbol may be defined or undefined. Each symbol has a name,
1872 and each defined symbol has an address, among other information. If
1873 you compile a C or C++ program into an object file, you will get a
1874 defined symbol for every defined function and global or static
1875 variable. Every undefined function or global variable which is
1876 referenced in the input file will become an undefined symbol.
1878 You can see the symbols in an object file by using the `nm' program,
1879 or by using the `objdump' program with the `-t' option.
1882 File: ld.info, Node: Script Format, Next: Simple Example, Prev: Basic Script Concepts, Up: Scripts
1884 Linker Script Format
1885 ====================
1887 Linker scripts are text files.
1889 You write a linker script as a series of commands. Each command is
1890 either a keyword, possibly followed by arguments, or an assignment to a
1891 symbol. You may separate commands using semicolons. Whitespace is
1894 Strings such as file or format names can normally be entered
1895 directly. If the file name contains a character such as a comma which
1896 would otherwise serve to separate file names, you may put the file name
1897 in double quotes. There is no way to use a double quote character in a
1900 You may include comments in linker scripts just as in C, delimited by
1901 `/*' and `*/'. As in C, comments are syntactically equivalent to
1905 File: ld.info, Node: Simple Example, Next: Simple Commands, Prev: Script Format, Up: Scripts
1907 Simple Linker Script Example
1908 ============================
1910 Many linker scripts are fairly simple.
1912 The simplest possible linker script has just one command:
1913 `SECTIONS'. You use the `SECTIONS' command to describe the memory
1914 layout of the output file.
1916 The `SECTIONS' command is a powerful command. Here we will describe
1917 a simple use of it. Let's assume your program consists only of code,
1918 initialized data, and uninitialized data. These will be in the
1919 `.text', `.data', and `.bss' sections, respectively. Let's assume
1920 further that these are the only sections which appear in your input
1923 For this example, let's say that the code should be loaded at address
1924 0x10000, and that the data should start at address 0x8000000. Here is a
1925 linker script which will do that:
1929 .text : { *(.text) }
1931 .data : { *(.data) }
1935 You write the `SECTIONS' command as the keyword `SECTIONS', followed
1936 by a series of symbol assignments and output section descriptions
1937 enclosed in curly braces.
1939 The first line inside the `SECTIONS' command of the above example
1940 sets the value of the special symbol `.', which is the location
1941 counter. If you do not specify the address of an output section in some
1942 other way (other ways are described later), the address is set from the
1943 current value of the location counter. The location counter is then
1944 incremented by the size of the output section. At the start of the
1945 `SECTIONS' command, the location counter has the value `0'.
1947 The second line defines an output section, `.text'. The colon is
1948 required syntax which may be ignored for now. Within the curly braces
1949 after the output section name, you list the names of the input sections
1950 which should be placed into this output section. The `*' is a wildcard
1951 which matches any file name. The expression `*(.text)' means all
1952 `.text' input sections in all input files.
1954 Since the location counter is `0x10000' when the output section
1955 `.text' is defined, the linker will set the address of the `.text'
1956 section in the output file to be `0x10000'.
1958 The remaining lines define the `.data' and `.bss' sections in the
1959 output file. The linker will place the `.data' output section at
1960 address `0x8000000'. After the linker places the `.data' output
1961 section, the value of the location counter will be `0x8000000' plus the
1962 size of the `.data' output section. The effect is that the linker will
1963 place the `.bss' output section immediately after the `.data' output
1966 The linker will ensure that each output section has the required
1967 alignment, by increasing the location counter if necessary. In this
1968 example, the specified addresses for the `.text' and `.data' sections
1969 will probably satisfy any alignment constraints, but the linker may
1970 have to create a small gap between the `.data' and `.bss' sections.
1972 That's it! That's a simple and complete linker script.
1975 File: ld.info, Node: Simple Commands, Next: Assignments, Prev: Simple Example, Up: Scripts
1977 Simple Linker Script Commands
1978 =============================
1980 In this section we describe the simple linker script commands.
1984 * Entry Point:: Setting the entry point
1985 * File Commands:: Commands dealing with files
1987 * Format Commands:: Commands dealing with object file formats
1989 * Miscellaneous Commands:: Other linker script commands
1992 File: ld.info, Node: Entry Point, Next: File Commands, Up: Simple Commands
1994 Setting the Entry Point
1995 -----------------------
1997 The first instruction to execute in a program is called the "entry
1998 point". You can use the `ENTRY' linker script command to set the entry
1999 point. The argument is a symbol name:
2002 There are several ways to set the entry point. The linker will set
2003 the entry point by trying each of the following methods in order, and
2004 stopping when one of them succeeds:
2005 * the `-e' ENTRY command-line option;
2007 * the `ENTRY(SYMBOL)' command in a linker script;
2009 * the value of the symbol `start', if defined;
2011 * the address of the first byte of the `.text' section, if present;
2016 File: ld.info, Node: File Commands, Next: Format Commands, Prev: Entry Point, Up: Simple Commands
2018 Commands Dealing with Files
2019 ---------------------------
2021 Several linker script commands deal with files.
2024 Include the linker script FILENAME at this point. The file will
2025 be searched for in the current directory, and in any directory
2026 specified with the `-L' option. You can nest calls to `INCLUDE'
2027 up to 10 levels deep.
2029 `INPUT(FILE, FILE, ...)'
2030 `INPUT(FILE FILE ...)'
2031 The `INPUT' command directs the linker to include the named files
2032 in the link, as though they were named on the command line.
2034 For example, if you always want to include `subr.o' any time you do
2035 a link, but you can't be bothered to put it on every link command
2036 line, then you can put `INPUT (subr.o)' in your linker script.
2038 In fact, if you like, you can list all of your input files in the
2039 linker script, and then invoke the linker with nothing but a `-T'
2042 In case a "sysroot prefix" is configured, and the filename starts
2043 with the `/' character, and the script being processed was located
2044 inside the "sysroot prefix", the filename will be looked for in
2045 the "sysroot prefix". Otherwise, the linker will try to open the
2046 file in the current directory. If it is not found, the linker
2047 will search through the archive library search path. See the
2048 description of `-L' in *Note Command Line Options: Options.
2050 If you use `INPUT (-lFILE)', `ld' will transform the name to
2051 `libFILE.a', as with the command line argument `-l'.
2053 When you use the `INPUT' command in an implicit linker script, the
2054 files will be included in the link at the point at which the linker
2055 script file is included. This can affect archive searching.
2057 `GROUP(FILE, FILE, ...)'
2058 `GROUP(FILE FILE ...)'
2059 The `GROUP' command is like `INPUT', except that the named files
2060 should all be archives, and they are searched repeatedly until no
2061 new undefined references are created. See the description of `-('
2062 in *Note Command Line Options: Options.
2064 `AS_NEEDED(FILE, FILE, ...)'
2065 `AS_NEEDED(FILE FILE ...)'
2066 This construct can appear only inside of the `INPUT' or `GROUP'
2067 commands, among other filenames. The files listed will be handled
2068 as if they appear directly in the `INPUT' or `GROUP' commands,
2069 with the exception of ELF shared libraries, that will be added only
2070 when they are actually needed. This construct essentially enables
2071 `--as-needed' option for all the files listed inside of it and
2072 restores previous `--as-needed' resp. `--no-as-needed' setting
2076 The `OUTPUT' command names the output file. Using
2077 `OUTPUT(FILENAME)' in the linker script is exactly like using `-o
2078 FILENAME' on the command line (*note Command Line Options:
2079 Options.). If both are used, the command line option takes
2082 You can use the `OUTPUT' command to define a default name for the
2083 output file other than the usual default of `a.out'.
2086 The `SEARCH_DIR' command adds PATH to the list of paths where `ld'
2087 looks for archive libraries. Using `SEARCH_DIR(PATH)' is exactly
2088 like using `-L PATH' on the command line (*note Command Line
2089 Options: Options.). If both are used, then the linker will search
2090 both paths. Paths specified using the command line option are
2094 The `STARTUP' command is just like the `INPUT' command, except
2095 that FILENAME will become the first input file to be linked, as
2096 though it were specified first on the command line. This may be
2097 useful when using a system in which the entry point is always the
2098 start of the first file.
2101 File: ld.info, Node: Format Commands, Next: Miscellaneous Commands, Prev: File Commands, Up: Simple Commands
2103 Commands Dealing with Object File Formats
2104 -----------------------------------------
2106 A couple of linker script commands deal with object file formats.
2108 `OUTPUT_FORMAT(BFDNAME)'
2109 `OUTPUT_FORMAT(DEFAULT, BIG, LITTLE)'
2110 The `OUTPUT_FORMAT' command names the BFD format to use for the
2111 output file (*note BFD::). Using `OUTPUT_FORMAT(BFDNAME)' is
2112 exactly like using `--oformat BFDNAME' on the command line (*note
2113 Command Line Options: Options.). If both are used, the command
2114 line option takes precedence.
2116 You can use `OUTPUT_FORMAT' with three arguments to use different
2117 formats based on the `-EB' and `-EL' command line options. This
2118 permits the linker script to set the output format based on the
2121 If neither `-EB' nor `-EL' are used, then the output format will
2122 be the first argument, DEFAULT. If `-EB' is used, the output
2123 format will be the second argument, BIG. If `-EL' is used, the
2124 output format will be the third argument, LITTLE.
2126 For example, the default linker script for the MIPS ELF target
2128 OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
2129 This says that the default format for the output file is
2130 `elf32-bigmips', but if the user uses the `-EL' command line
2131 option, the output file will be created in the `elf32-littlemips'
2135 The `TARGET' command names the BFD format to use when reading input
2136 files. It affects subsequent `INPUT' and `GROUP' commands. This
2137 command is like using `-b BFDNAME' on the command line (*note
2138 Command Line Options: Options.). If the `TARGET' command is used
2139 but `OUTPUT_FORMAT' is not, then the last `TARGET' command is also
2140 used to set the format for the output file. *Note BFD::.
2143 File: ld.info, Node: Miscellaneous Commands, Prev: Format Commands, Up: Simple Commands
2145 Other Linker Script Commands
2146 ----------------------------
2148 There are a few other linker scripts commands.
2150 `ASSERT(EXP, MESSAGE)'
2151 Ensure that EXP is non-zero. If it is zero, then exit the linker
2152 with an error code, and print MESSAGE.
2154 `EXTERN(SYMBOL SYMBOL ...)'
2155 Force SYMBOL to be entered in the output file as an undefined
2156 symbol. Doing this may, for example, trigger linking of additional
2157 modules from standard libraries. You may list several SYMBOLs for
2158 each `EXTERN', and you may use `EXTERN' multiple times. This
2159 command has the same effect as the `-u' command-line option.
2161 `FORCE_COMMON_ALLOCATION'
2162 This command has the same effect as the `-d' command-line option:
2163 to make `ld' assign space to common symbols even if a relocatable
2164 output file is specified (`-r').
2166 `INHIBIT_COMMON_ALLOCATION'
2167 This command has the same effect as the `--no-define-common'
2168 command-line option: to make `ld' omit the assignment of addresses
2169 to common symbols even for a non-relocatable output file.
2171 `NOCROSSREFS(SECTION SECTION ...)'
2172 This command may be used to tell `ld' to issue an error about any
2173 references among certain output sections.
2175 In certain types of programs, particularly on embedded systems when
2176 using overlays, when one section is loaded into memory, another
2177 section will not be. Any direct references between the two
2178 sections would be errors. For example, it would be an error if
2179 code in one section called a function defined in the other section.
2181 The `NOCROSSREFS' command takes a list of output section names. If
2182 `ld' detects any cross references between the sections, it reports
2183 an error and returns a non-zero exit status. Note that the
2184 `NOCROSSREFS' command uses output section names, not input section
2187 `OUTPUT_ARCH(BFDARCH)'
2188 Specify a particular output machine architecture. The argument is
2189 one of the names used by the BFD library (*note BFD::). You can
2190 see the architecture of an object file by using the `objdump'
2191 program with the `-f' option.
2194 File: ld.info, Node: Assignments, Next: SECTIONS, Prev: Simple Commands, Up: Scripts
2196 Assigning Values to Symbols
2197 ===========================
2199 You may assign a value to a symbol in a linker script. This will
2200 define the symbol and place it into the symbol table with a global
2205 * Simple Assignments:: Simple Assignments
2207 * PROVIDE_HIDDEN:: PROVIDE_HIDDEN
2208 * Source Code Reference:: How to use a linker script defined symbol in source code
2211 File: ld.info, Node: Simple Assignments, Next: PROVIDE, Up: Assignments
2216 You may assign to a symbol using any of the C assignment operators:
2218 `SYMBOL = EXPRESSION ;'
2219 `SYMBOL += EXPRESSION ;'
2220 `SYMBOL -= EXPRESSION ;'
2221 `SYMBOL *= EXPRESSION ;'
2222 `SYMBOL /= EXPRESSION ;'
2223 `SYMBOL <<= EXPRESSION ;'
2224 `SYMBOL >>= EXPRESSION ;'
2225 `SYMBOL &= EXPRESSION ;'
2226 `SYMBOL |= EXPRESSION ;'
2227 The first case will define SYMBOL to the value of EXPRESSION. In
2228 the other cases, SYMBOL must already be defined, and the value will be
2229 adjusted accordingly.
2231 The special symbol name `.' indicates the location counter. You may
2232 only use this within a `SECTIONS' command. *Note Location Counter::.
2234 The semicolon after EXPRESSION is required.
2236 Expressions are defined below; see *Note Expressions::.
2238 You may write symbol assignments as commands in their own right, or
2239 as statements within a `SECTIONS' command, or as part of an output
2240 section description in a `SECTIONS' command.
2242 The section of the symbol will be set from the section of the
2243 expression; for more information, see *Note Expression Section::.
2245 Here is an example showing the three different places that symbol
2246 assignments may be used:
2256 _bdata = (. + 3) & ~ 3;
2257 .data : { *(.data) }
2260 In this example, the symbol `floating_point' will be defined as zero.
2261 The symbol `_etext' will be defined as the address following the last
2262 `.text' input section. The symbol `_bdata' will be defined as the
2263 address following the `.text' output section aligned upward to a 4 byte
2267 File: ld.info, Node: PROVIDE, Next: PROVIDE_HIDDEN, Prev: Simple Assignments, Up: Assignments
2272 In some cases, it is desirable for a linker script to define a symbol
2273 only if it is referenced and is not defined by any object included in
2274 the link. For example, traditional linkers defined the symbol `etext'.
2275 However, ANSI C requires that the user be able to use `etext' as a
2276 function name without encountering an error. The `PROVIDE' keyword may
2277 be used to define a symbol, such as `etext', only if it is referenced
2278 but not defined. The syntax is `PROVIDE(SYMBOL = EXPRESSION)'.
2280 Here is an example of using `PROVIDE' to define `etext':
2291 In this example, if the program defines `_etext' (with a leading
2292 underscore), the linker will give a multiple definition error. If, on
2293 the other hand, the program defines `etext' (with no leading
2294 underscore), the linker will silently use the definition in the program.
2295 If the program references `etext' but does not define it, the linker
2296 will use the definition in the linker script.
2299 File: ld.info, Node: PROVIDE_HIDDEN, Next: Source Code Reference, Prev: PROVIDE, Up: Assignments
2304 Similar to `PROVIDE'. For ELF targeted ports, the symbol will be
2305 hidden and won't be exported.
2308 File: ld.info, Node: Source Code Reference, Prev: PROVIDE_HIDDEN, Up: Assignments
2310 Source Code Reference
2311 ---------------------
2313 Accessing a linker script defined variable from source code is not
2314 intuitive. In particular a linker script symbol is not equivalent to a
2315 variable declaration in a high level language, it is instead a symbol
2316 that does not have a value.
2318 Before going further, it is important to note that compilers often
2319 transform names in the source code into different names when they are
2320 stored in the symbol table. For example, Fortran compilers commonly
2321 prepend or append an underscore, and C++ performs extensive `name
2322 mangling'. Therefore there might be a discrepancy between the name of
2323 a variable as it is used in source code and the name of the same
2324 variable as it is defined in a linker script. For example in C a
2325 linker script variable might be referred to as:
2329 But in the linker script it might be defined as:
2333 In the remaining examples however it is assumed that no name
2334 transformation has taken place.
2336 When a symbol is declared in a high level language such as C, two
2337 things happen. The first is that the compiler reserves enough space in
2338 the program's memory to hold the _value_ of the symbol. The second is
2339 that the compiler creates an entry in the program's symbol table which
2340 holds the symbol's _address_. ie the symbol table contains the address
2341 of the block of memory holding the symbol's value. So for example the
2342 following C declaration, at file scope:
2346 creates a entry called `foo' in the symbol table. This entry holds
2347 the address of an `int' sized block of memory where the number 1000 is
2350 When a program references a symbol the compiler generates code that
2351 first accesses the symbol table to find the address of the symbol's
2352 memory block and then code to read the value from that memory block.
2357 looks up the symbol `foo' in the symbol table, gets the address
2358 associated with this symbol and then writes the value 1 into that
2363 looks up the symbol `foo' in the symbol table, gets it address and
2364 then copies this address into the block of memory associated with the
2367 Linker scripts symbol declarations, by contrast, create an entry in
2368 the symbol table but do not assign any memory to them. Thus they are
2369 an address without a value. So for example the linker script
2374 creates an entry in the symbol table called `foo' which holds the
2375 address of memory location 1000, but nothing special is stored at
2376 address 1000. This means that you cannot access the _value_ of a
2377 linker script defined symbol - it has no value - all you can do is
2378 access the _address_ of a linker script defined symbol.
2380 Hence when you are using a linker script defined symbol in source
2381 code you should always take the address of the symbol, and never
2382 attempt to use its value. For example suppose you want to copy the
2383 contents of a section of memory called .ROM into a section called
2384 .FLASH and the linker script contains these declarations:
2386 start_of_ROM = .ROM;
2387 end_of_ROM = .ROM + sizeof (.ROM) - 1;
2388 start_of_FLASH = .FLASH;
2390 Then the C source code to perform the copy would be:
2392 extern char start_of_ROM, end_of_ROM, start_of_FLASH;
2394 memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
2396 Note the use of the `&' operators. These are correct.
2399 File: ld.info, Node: SECTIONS, Next: MEMORY, Prev: Assignments, Up: Scripts
2404 The `SECTIONS' command tells the linker how to map input sections
2405 into output sections, and how to place the output sections in memory.
2407 The format of the `SECTIONS' command is:
2415 Each SECTIONS-COMMAND may of be one of the following:
2417 * an `ENTRY' command (*note Entry command: Entry Point.)
2419 * a symbol assignment (*note Assignments::)
2421 * an output section description
2423 * an overlay description
2425 The `ENTRY' command and symbol assignments are permitted inside the
2426 `SECTIONS' command for convenience in using the location counter in
2427 those commands. This can also make the linker script easier to
2428 understand because you can use those commands at meaningful points in
2429 the layout of the output file.
2431 Output section descriptions and overlay descriptions are described
2434 If you do not use a `SECTIONS' command in your linker script, the
2435 linker will place each input section into an identically named output
2436 section in the order that the sections are first encountered in the
2437 input files. If all input sections are present in the first file, for
2438 example, the order of sections in the output file will match the order
2439 in the first input file. The first section will be at address zero.
2443 * Output Section Description:: Output section description
2444 * Output Section Name:: Output section name
2445 * Output Section Address:: Output section address
2446 * Input Section:: Input section description
2447 * Output Section Data:: Output section data
2448 * Output Section Keywords:: Output section keywords
2449 * Output Section Discarding:: Output section discarding
2450 * Output Section Attributes:: Output section attributes
2451 * Overlay Description:: Overlay description
2454 File: ld.info, Node: Output Section Description, Next: Output Section Name, Up: SECTIONS
2456 Output Section Description
2457 --------------------------
2459 The full description of an output section looks like this:
2460 SECTION [ADDRESS] [(TYPE)] :
2461 [AT(LMA)] [ALIGN(SECTION_ALIGN)] [SUBALIGN(SUBSECTION_ALIGN)]
2463 OUTPUT-SECTION-COMMAND
2464 OUTPUT-SECTION-COMMAND
2466 } [>REGION] [AT>LMA_REGION] [:PHDR :PHDR ...] [=FILLEXP]
2468 Most output sections do not use most of the optional section
2471 The whitespace around SECTION is required, so that the section name
2472 is unambiguous. The colon and the curly braces are also required. The
2473 line breaks and other white space are optional.
2475 Each OUTPUT-SECTION-COMMAND may be one of the following:
2477 * a symbol assignment (*note Assignments::)
2479 * an input section description (*note Input Section::)
2481 * data values to include directly (*note Output Section Data::)
2483 * a special output section keyword (*note Output Section Keywords::)
2486 File: ld.info, Node: Output Section Name, Next: Output Section Address, Prev: Output Section Description, Up: SECTIONS
2491 The name of the output section is SECTION. SECTION must meet the
2492 constraints of your output format. In formats which only support a
2493 limited number of sections, such as `a.out', the name must be one of
2494 the names supported by the format (`a.out', for example, allows only
2495 `.text', `.data' or `.bss'). If the output format supports any number
2496 of sections, but with numbers and not names (as is the case for Oasys),
2497 the name should be supplied as a quoted numeric string. A section name
2498 may consist of any sequence of characters, but a name which contains
2499 any unusual characters such as commas must be quoted.
2501 The output section name `/DISCARD/' is special; *Note Output Section
2505 File: ld.info, Node: Output Section Address, Next: Input Section, Prev: Output Section Name, Up: SECTIONS
2507 Output Section Address
2508 ----------------------
2510 The ADDRESS is an expression for the VMA (the virtual memory
2511 address) of the output section. If you do not provide ADDRESS, the
2512 linker will set it based on REGION if present, or otherwise based on
2513 the current value of the location counter.
2515 If you provide ADDRESS, the address of the output section will be
2516 set to precisely that. If you provide neither ADDRESS nor REGION, then
2517 the address of the output section will be set to the current value of
2518 the location counter aligned to the alignment requirements of the
2519 output section. The alignment requirement of the output section is the
2520 strictest alignment of any input section contained within the output
2524 .text . : { *(.text) }
2527 .text : { *(.text) }
2529 are subtly different. The first will set the address of the `.text'
2530 output section to the current value of the location counter. The
2531 second will set it to the current value of the location counter aligned
2532 to the strictest alignment of a `.text' input section.
2534 The ADDRESS may be an arbitrary expression; *Note Expressions::.
2535 For example, if you want to align the section on a 0x10 byte boundary,
2536 so that the lowest four bits of the section address are zero, you could
2537 do something like this:
2538 .text ALIGN(0x10) : { *(.text) }
2540 This works because `ALIGN' returns the current location counter aligned
2541 upward to the specified value.
2543 Specifying ADDRESS for a section will change the value of the
2547 File: ld.info, Node: Input Section, Next: Output Section Data, Prev: Output Section Address, Up: SECTIONS
2549 Input Section Description
2550 -------------------------
2552 The most common output section command is an input section
2555 The input section description is the most basic linker script
2556 operation. You use output sections to tell the linker how to lay out
2557 your program in memory. You use input section descriptions to tell the
2558 linker how to map the input files into your memory layout.
2562 * Input Section Basics:: Input section basics
2563 * Input Section Wildcards:: Input section wildcard patterns
2564 * Input Section Common:: Input section for common symbols
2565 * Input Section Keep:: Input section and garbage collection
2566 * Input Section Example:: Input section example
2569 File: ld.info, Node: Input Section Basics, Next: Input Section Wildcards, Up: Input Section
2571 Input Section Basics
2572 ....................
2574 An input section description consists of a file name optionally
2575 followed by a list of section names in parentheses.
2577 The file name and the section name may be wildcard patterns, which we
2578 describe further below (*note Input Section Wildcards::).
2580 The most common input section description is to include all input
2581 sections with a particular name in the output section. For example, to
2582 include all input `.text' sections, you would write:
2585 Here the `*' is a wildcard which matches any file name. To exclude a
2586 list of files from matching the file name wildcard, EXCLUDE_FILE may be
2587 used to match all files except the ones specified in the EXCLUDE_FILE
2589 (*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors))
2590 will cause all .ctors sections from all files except `crtend.o' and
2591 `otherfile.o' to be included.
2593 There are two ways to include more than one section:
2597 The difference between these is the order in which the `.text' and
2598 `.rdata' input sections will appear in the output section. In the
2599 first example, they will be intermingled, appearing in the same order as
2600 they are found in the linker input. In the second example, all `.text'
2601 input sections will appear first, followed by all `.rdata' input
2604 You can specify a file name to include sections from a particular
2605 file. You would do this if one or more of your files contain special
2606 data that needs to be at a particular location in memory. For example:
2609 If you use a file name without a list of sections, then all sections
2610 in the input file will be included in the output section. This is not
2611 commonly done, but it may by useful on occasion. For example:
2614 When you use a file name which does not contain any wild card
2615 characters, the linker will first see if you also specified the file
2616 name on the linker command line or in an `INPUT' command. If you did
2617 not, the linker will attempt to open the file as an input file, as
2618 though it appeared on the command line. Note that this differs from an
2619 `INPUT' command, because the linker will not search for the file in the
2620 archive search path.
2623 File: ld.info, Node: Input Section Wildcards, Next: Input Section Common, Prev: Input Section Basics, Up: Input Section
2625 Input Section Wildcard Patterns
2626 ...............................
2628 In an input section description, either the file name or the section
2629 name or both may be wildcard patterns.
2631 The file name of `*' seen in many examples is a simple wildcard
2632 pattern for the file name.
2634 The wildcard patterns are like those used by the Unix shell.
2637 matches any number of characters
2640 matches any single character
2643 matches a single instance of any of the CHARS; the `-' character
2644 may be used to specify a range of characters, as in `[a-z]' to
2645 match any lower case letter
2648 quotes the following character
2650 When a file name is matched with a wildcard, the wildcard characters
2651 will not match a `/' character (used to separate directory names on
2652 Unix). A pattern consisting of a single `*' character is an exception;
2653 it will always match any file name, whether it contains a `/' or not.
2654 In a section name, the wildcard characters will match a `/' character.
2656 File name wildcard patterns only match files which are explicitly
2657 specified on the command line or in an `INPUT' command. The linker
2658 does not search directories to expand wildcards.
2660 If a file name matches more than one wildcard pattern, or if a file
2661 name appears explicitly and is also matched by a wildcard pattern, the
2662 linker will use the first match in the linker script. For example, this
2663 sequence of input section descriptions is probably in error, because the
2664 `data.o' rule will not be used:
2665 .data : { *(.data) }
2666 .data1 : { data.o(.data) }
2668 Normally, the linker will place files and sections matched by
2669 wildcards in the order in which they are seen during the link. You can
2670 change this by using the `SORT_BY_NAME' keyword, which appears before a
2671 wildcard pattern in parentheses (e.g., `SORT_BY_NAME(.text*)'). When
2672 the `SORT_BY_NAME' keyword is used, the linker will sort the files or
2673 sections into ascending order by name before placing them in the output
2676 `SORT_BY_ALIGNMENT' is very similar to `SORT_BY_NAME'. The
2677 difference is `SORT_BY_ALIGNMENT' will sort sections into ascending
2678 order by alignment before placing them in the output file.
2680 `SORT' is an alias for `SORT_BY_NAME'.
2682 When there are nested section sorting commands in linker script,
2683 there can be at most 1 level of nesting for section sorting commands.
2685 1. `SORT_BY_NAME' (`SORT_BY_ALIGNMENT' (wildcard section pattern)).
2686 It will sort the input sections by name first, then by alignment
2687 if 2 sections have the same name.
2689 2. `SORT_BY_ALIGNMENT' (`SORT_BY_NAME' (wildcard section pattern)).
2690 It will sort the input sections by alignment first, then by name
2691 if 2 sections have the same alignment.
2693 3. `SORT_BY_NAME' (`SORT_BY_NAME' (wildcard section pattern)) is
2694 treated the same as `SORT_BY_NAME' (wildcard section pattern).
2696 4. `SORT_BY_ALIGNMENT' (`SORT_BY_ALIGNMENT' (wildcard section
2697 pattern)) is treated the same as `SORT_BY_ALIGNMENT' (wildcard
2700 5. All other nested section sorting commands are invalid.
2702 When both command line section sorting option and linker script
2703 section sorting command are used, section sorting command always takes
2704 precedence over the command line option.
2706 If the section sorting command in linker script isn't nested, the
2707 command line option will make the section sorting command to be treated
2708 as nested sorting command.
2710 1. `SORT_BY_NAME' (wildcard section pattern ) with `--sort-sections
2711 alignment' is equivalent to `SORT_BY_NAME' (`SORT_BY_ALIGNMENT'
2712 (wildcard section pattern)).
2714 2. `SORT_BY_ALIGNMENT' (wildcard section pattern) with
2715 `--sort-section name' is equivalent to `SORT_BY_ALIGNMENT'
2716 (`SORT_BY_NAME' (wildcard section pattern)).
2718 If the section sorting command in linker script is nested, the
2719 command line option will be ignored.
2721 If you ever get confused about where input sections are going, use
2722 the `-M' linker option to generate a map file. The map file shows
2723 precisely how input sections are mapped to output sections.
2725 This example shows how wildcard patterns might be used to partition
2726 files. This linker script directs the linker to place all `.text'
2727 sections in `.text' and all `.bss' sections in `.bss'. The linker will
2728 place the `.data' section from all files beginning with an upper case
2729 character in `.DATA'; for all other files, the linker will place the
2730 `.data' section in `.data'.
2732 .text : { *(.text) }
2733 .DATA : { [A-Z]*(.data) }
2734 .data : { *(.data) }
2739 File: ld.info, Node: Input Section Common, Next: Input Section Keep, Prev: Input Section Wildcards, Up: Input Section
2741 Input Section for Common Symbols
2742 ................................
2744 A special notation is needed for common symbols, because in many
2745 object file formats common symbols do not have a particular input
2746 section. The linker treats common symbols as though they are in an
2747 input section named `COMMON'.
2749 You may use file names with the `COMMON' section just as with any
2750 other input sections. You can use this to place common symbols from a
2751 particular input file in one section while common symbols from other
2752 input files are placed in another section.
2754 In most cases, common symbols in input files will be placed in the
2755 `.bss' section in the output file. For example:
2756 .bss { *(.bss) *(COMMON) }
2758 Some object file formats have more than one type of common symbol.
2759 For example, the MIPS ELF object file format distinguishes standard
2760 common symbols and small common symbols. In this case, the linker will
2761 use a different special section name for other types of common symbols.
2762 In the case of MIPS ELF, the linker uses `COMMON' for standard common
2763 symbols and `.scommon' for small common symbols. This permits you to
2764 map the different types of common symbols into memory at different
2767 You will sometimes see `[COMMON]' in old linker scripts. This
2768 notation is now considered obsolete. It is equivalent to `*(COMMON)'.
2771 File: ld.info, Node: Input Section Keep, Next: Input Section Example, Prev: Input Section Common, Up: Input Section
2773 Input Section and Garbage Collection
2774 ....................................
2776 When link-time garbage collection is in use (`--gc-sections'), it is
2777 often useful to mark sections that should not be eliminated. This is
2778 accomplished by surrounding an input section's wildcard entry with
2779 `KEEP()', as in `KEEP(*(.init))' or `KEEP(SORT_BY_NAME(*)(.ctors))'.
2782 File: ld.info, Node: Input Section Example, Prev: Input Section Keep, Up: Input Section
2784 Input Section Example
2785 .....................
2787 The following example is a complete linker script. It tells the
2788 linker to read all of the sections from file `all.o' and place them at
2789 the start of output section `outputa' which starts at location
2790 `0x10000'. All of section `.input1' from file `foo.o' follows
2791 immediately, in the same output section. All of section `.input2' from
2792 `foo.o' goes into output section `outputb', followed by section
2793 `.input1' from `foo1.o'. All of the remaining `.input1' and `.input2'
2794 sections from any files are written to output section `outputc'.
2815 File: ld.info, Node: Output Section Data, Next: Output Section Keywords, Prev: Input Section, Up: SECTIONS
2820 You can include explicit bytes of data in an output section by using
2821 `BYTE', `SHORT', `LONG', `QUAD', or `SQUAD' as an output section
2822 command. Each keyword is followed by an expression in parentheses
2823 providing the value to store (*note Expressions::). The value of the
2824 expression is stored at the current value of the location counter.
2826 The `BYTE', `SHORT', `LONG', and `QUAD' commands store one, two,
2827 four, and eight bytes (respectively). After storing the bytes, the
2828 location counter is incremented by the number of bytes stored.
2830 For example, this will store the byte 1 followed by the four byte
2831 value of the symbol `addr':
2835 When using a 64 bit host or target, `QUAD' and `SQUAD' are the same;
2836 they both store an 8 byte, or 64 bit, value. When both host and target
2837 are 32 bits, an expression is computed as 32 bits. In this case `QUAD'
2838 stores a 32 bit value zero extended to 64 bits, and `SQUAD' stores a 32
2839 bit value sign extended to 64 bits.
2841 If the object file format of the output file has an explicit
2842 endianness, which is the normal case, the value will be stored in that
2843 endianness. When the object file format does not have an explicit
2844 endianness, as is true of, for example, S-records, the value will be
2845 stored in the endianness of the first input object file.
2847 Note--these commands only work inside a section description and not
2848 between them, so the following will produce an error from the linker:
2849 SECTIONS { .text : { *(.text) } LONG(1) .data : { *(.data) } }
2850 whereas this will work:
2851 SECTIONS { .text : { *(.text) ; LONG(1) } .data : { *(.data) } }
2853 You may use the `FILL' command to set the fill pattern for the
2854 current section. It is followed by an expression in parentheses. Any
2855 otherwise unspecified regions of memory within the section (for example,
2856 gaps left due to the required alignment of input sections) are filled
2857 with the value of the expression, repeated as necessary. A `FILL'
2858 statement covers memory locations after the point at which it occurs in
2859 the section definition; by including more than one `FILL' statement,
2860 you can have different fill patterns in different parts of an output
2863 This example shows how to fill unspecified regions of memory with the
2867 The `FILL' command is similar to the `=FILLEXP' output section
2868 attribute, but it only affects the part of the section following the
2869 `FILL' command, rather than the entire section. If both are used, the
2870 `FILL' command takes precedence. *Note Output Section Fill::, for
2871 details on the fill expression.
2874 File: ld.info, Node: Output Section Keywords, Next: Output Section Discarding, Prev: Output Section Data, Up: SECTIONS
2876 Output Section Keywords
2877 -----------------------
2879 There are a couple of keywords which can appear as output section
2882 `CREATE_OBJECT_SYMBOLS'
2883 The command tells the linker to create a symbol for each input
2884 file. The name of each symbol will be the name of the
2885 corresponding input file. The section of each symbol will be the
2886 output section in which the `CREATE_OBJECT_SYMBOLS' command
2889 This is conventional for the a.out object file format. It is not
2890 normally used for any other object file format.
2893 When linking using the a.out object file format, the linker uses an
2894 unusual set construct to support C++ global constructors and
2895 destructors. When linking object file formats which do not support
2896 arbitrary sections, such as ECOFF and XCOFF, the linker will
2897 automatically recognize C++ global constructors and destructors by
2898 name. For these object file formats, the `CONSTRUCTORS' command
2899 tells the linker to place constructor information in the output
2900 section where the `CONSTRUCTORS' command appears. The
2901 `CONSTRUCTORS' command is ignored for other object file formats.
2903 The symbol `__CTOR_LIST__' marks the start of the global
2904 constructors, and the symbol `__CTOR_END__' marks the end.
2905 Similarly, `__DTOR_LIST__' and `__DTOR_END__' mark the start and
2906 end of the global destructors. The first word in the list is the
2907 number of entries, followed by the address of each constructor or
2908 destructor, followed by a zero word. The compiler must arrange to
2909 actually run the code. For these object file formats GNU C++
2910 normally calls constructors from a subroutine `__main'; a call to
2911 `__main' is automatically inserted into the startup code for
2912 `main'. GNU C++ normally runs destructors either by using
2913 `atexit', or directly from the function `exit'.
2915 For object file formats such as `COFF' or `ELF' which support
2916 arbitrary section names, GNU C++ will normally arrange to put the
2917 addresses of global constructors and destructors into the `.ctors'
2918 and `.dtors' sections. Placing the following sequence into your
2919 linker script will build the sort of table which the GNU C++
2920 runtime code expects to see.
2923 LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
2928 LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
2933 If you are using the GNU C++ support for initialization priority,
2934 which provides some control over the order in which global
2935 constructors are run, you must sort the constructors at link time
2936 to ensure that they are executed in the correct order. When using
2937 the `CONSTRUCTORS' command, use `SORT_BY_NAME(CONSTRUCTORS)'
2938 instead. When using the `.ctors' and `.dtors' sections, use
2939 `*(SORT_BY_NAME(.ctors))' and `*(SORT_BY_NAME(.dtors))' instead of
2940 just `*(.ctors)' and `*(.dtors)'.
2942 Normally the compiler and linker will handle these issues
2943 automatically, and you will not need to concern yourself with
2944 them. However, you may need to consider this if you are using C++
2945 and writing your own linker scripts.
2948 File: ld.info, Node: Output Section Discarding, Next: Output Section Attributes, Prev: Output Section Keywords, Up: SECTIONS
2950 Output Section Discarding
2951 -------------------------
2953 The linker will not create output section which do not have any
2954 contents. This is for convenience when referring to input sections that
2955 may or may not be present in any of the input files. For example:
2958 will only create a `.foo' section in the output file if there is a
2959 `.foo' section in at least one input file.
2961 If you use anything other than an input section description as an
2962 output section command, such as a symbol assignment, then the output
2963 section will always be created, even if there are no matching input
2966 The special output section name `/DISCARD/' may be used to discard
2967 input sections. Any input sections which are assigned to an output
2968 section named `/DISCARD/' are not included in the output file.
2971 File: ld.info, Node: Output Section Attributes, Next: Overlay Description, Prev: Output Section Discarding, Up: SECTIONS
2973 Output Section Attributes
2974 -------------------------
2976 We showed above that the full description of an output section looked
2978 SECTION [ADDRESS] [(TYPE)] :
2979 [AT(LMA)] [ALIGN(SECTION_ALIGN)] [SUBALIGN(SUBSECTION_ALIGN)]
2981 OUTPUT-SECTION-COMMAND
2982 OUTPUT-SECTION-COMMAND
2984 } [>REGION] [AT>LMA_REGION] [:PHDR :PHDR ...] [=FILLEXP]
2985 We've already described SECTION, ADDRESS, and
2986 OUTPUT-SECTION-COMMAND. In this section we will describe the remaining
2991 * Output Section Type:: Output section type
2992 * Output Section LMA:: Output section LMA
2993 * Forced Output Alignment:: Forced Output Alignment
2994 * Forced Input Alignment:: Forced Input Alignment
2995 * Output Section Region:: Output section region
2996 * Output Section Phdr:: Output section phdr
2997 * Output Section Fill:: Output section fill
3000 File: ld.info, Node: Output Section Type, Next: Output Section LMA, Up: Output Section Attributes
3005 Each output section may have a type. The type is a keyword in
3006 parentheses. The following types are defined:
3009 The section should be marked as not loadable, so that it will not
3010 be loaded into memory when the program is run.
3016 These type names are supported for backward compatibility, and are
3017 rarely used. They all have the same effect: the section should be
3018 marked as not allocatable, so that no memory is allocated for the
3019 section when the program is run.
3021 The linker normally sets the attributes of an output section based on
3022 the input sections which map into it. You can override this by using
3023 the section type. For example, in the script sample below, the `ROM'
3024 section is addressed at memory location `0' and does not need to be
3025 loaded when the program is run. The contents of the `ROM' section will
3026 appear in the linker output file as usual.
3028 ROM 0 (NOLOAD) : { ... }
3033 File: ld.info, Node: Output Section LMA, Next: Forced Output Alignment, Prev: Output Section Type, Up: Output Section Attributes
3038 Every section has a virtual address (VMA) and a load address (LMA);
3039 see *Note Basic Script Concepts::. The address expression which may
3040 appear in an output section description sets the VMA (*note Output
3043 The linker will normally set the LMA equal to the VMA. You can
3044 change that by using the `AT' keyword. The expression LMA that follows
3045 the `AT' keyword specifies the load address of the section.
3047 Alternatively, with `AT>LMA_REGION' expression, you may specify a
3048 memory region for the section's load address. *Note MEMORY::. Note
3049 that if the section has not had a VMA assigned to it then the linker
3050 will use the LMA_REGION as the VMA region as well. *Note Output
3053 This feature is designed to make it easy to build a ROM image. For
3054 example, the following linker script creates three output sections: one
3055 called `.text', which starts at `0x1000', one called `.mdata', which is
3056 loaded at the end of the `.text' section even though its VMA is
3057 `0x2000', and one called `.bss' to hold uninitialized data at address
3058 `0x3000'. The symbol `_data' is defined with the value `0x2000', which
3059 shows that the location counter holds the VMA value, not the LMA value.
3063 .text 0x1000 : { *(.text) _etext = . ; }
3065 AT ( ADDR (.text) + SIZEOF (.text) )
3066 { _data = . ; *(.data); _edata = . ; }
3068 { _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;}
3071 The run-time initialization code for use with a program generated
3072 with this linker script would include something like the following, to
3073 copy the initialized data from the ROM image to its runtime address.
3074 Notice how this code takes advantage of the symbols defined by the
3077 extern char _etext, _data, _edata, _bstart, _bend;
3078 char *src = &_etext;
3081 /* ROM has data at end of text; copy it. */
3082 while (dst < &_edata) {
3087 for (dst = &_bstart; dst< &_bend; dst++)
3091 File: ld.info, Node: Forced Output Alignment, Next: Forced Input Alignment, Prev: Output Section LMA, Up: Output Section Attributes
3093 Forced Output Alignment
3094 .......................
3096 You can increase an output section's alignment by using ALIGN.
3099 File: ld.info, Node: Forced Input Alignment, Next: Output Section Region, Prev: Forced Output Alignment, Up: Output Section Attributes
3101 Forced Input Alignment
3102 ......................
3104 You can force input section alignment within an output section by
3105 using SUBALIGN. The value specified overrides any alignment given by
3106 input sections, whether larger or smaller.
3109 File: ld.info, Node: Output Section Region, Next: Output Section Phdr, Prev: Forced Input Alignment, Up: Output Section Attributes
3111 Output Section Region
3112 .....................
3114 You can assign a section to a previously defined region of memory by
3115 using `>REGION'. *Note MEMORY::.
3117 Here is a simple example:
3118 MEMORY { rom : ORIGIN = 0x1000, LENGTH = 0x1000 }
3119 SECTIONS { ROM : { *(.text) } >rom }
3122 File: ld.info, Node: Output Section Phdr, Next: Output Section Fill, Prev: Output Section Region, Up: Output Section Attributes
3127 You can assign a section to a previously defined program segment by
3128 using `:PHDR'. *Note PHDRS::. If a section is assigned to one or more
3129 segments, then all subsequent allocated sections will be assigned to
3130 those segments as well, unless they use an explicitly `:PHDR' modifier.
3131 You can use `:NONE' to tell the linker to not put the section in any
3134 Here is a simple example:
3135 PHDRS { text PT_LOAD ; }
3136 SECTIONS { .text : { *(.text) } :text }
3139 File: ld.info, Node: Output Section Fill, Prev: Output Section Phdr, Up: Output Section Attributes
3144 You can set the fill pattern for an entire section by using
3145 `=FILLEXP'. FILLEXP is an expression (*note Expressions::). Any
3146 otherwise unspecified regions of memory within the output section (for
3147 example, gaps left due to the required alignment of input sections)
3148 will be filled with the value, repeated as necessary. If the fill
3149 expression is a simple hex number, ie. a string of hex digit starting
3150 with `0x' and without a trailing `k' or `M', then an arbitrarily long
3151 sequence of hex digits can be used to specify the fill pattern;
3152 Leading zeros become part of the pattern too. For all other cases,
3153 including extra parentheses or a unary `+', the fill pattern is the
3154 four least significant bytes of the value of the expression. In all
3155 cases, the number is big-endian.
3157 You can also change the fill value with a `FILL' command in the
3158 output section commands; (*note Output Section Data::).
3160 Here is a simple example:
3161 SECTIONS { .text : { *(.text) } =0x90909090 }
3164 File: ld.info, Node: Overlay Description, Prev: Output Section Attributes, Up: SECTIONS
3169 An overlay description provides an easy way to describe sections
3170 which are to be loaded as part of a single memory image but are to be
3171 run at the same memory address. At run time, some sort of overlay
3172 manager will copy the overlaid sections in and out of the runtime
3173 memory address as required, perhaps by simply manipulating addressing
3174 bits. This approach can be useful, for example, when a certain region
3175 of memory is faster than another.
3177 Overlays are described using the `OVERLAY' command. The `OVERLAY'
3178 command is used within a `SECTIONS' command, like an output section
3179 description. The full syntax of the `OVERLAY' command is as follows:
3180 OVERLAY [START] : [NOCROSSREFS] [AT ( LDADDR )]
3184 OUTPUT-SECTION-COMMAND
3185 OUTPUT-SECTION-COMMAND
3187 } [:PHDR...] [=FILL]
3190 OUTPUT-SECTION-COMMAND
3191 OUTPUT-SECTION-COMMAND
3193 } [:PHDR...] [=FILL]
3195 } [>REGION] [:PHDR...] [=FILL]
3197 Everything is optional except `OVERLAY' (a keyword), and each
3198 section must have a name (SECNAME1 and SECNAME2 above). The section
3199 definitions within the `OVERLAY' construct are identical to those
3200 within the general `SECTIONS' contruct (*note SECTIONS::), except that
3201 no addresses and no memory regions may be defined for sections within
3204 The sections are all defined with the same starting address. The
3205 load addresses of the sections are arranged such that they are
3206 consecutive in memory starting at the load address used for the
3207 `OVERLAY' as a whole (as with normal section definitions, the load
3208 address is optional, and defaults to the start address; the start
3209 address is also optional, and defaults to the current value of the
3212 If the `NOCROSSREFS' keyword is used, and there any references among
3213 the sections, the linker will report an error. Since the sections all
3214 run at the same address, it normally does not make sense for one
3215 section to refer directly to another. *Note NOCROSSREFS: Miscellaneous
3218 For each section within the `OVERLAY', the linker automatically
3219 defines two symbols. The symbol `__load_start_SECNAME' is defined as
3220 the starting load address of the section. The symbol
3221 `__load_stop_SECNAME' is defined as the final load address of the
3222 section. Any characters within SECNAME which are not legal within C
3223 identifiers are removed. C (or assembler) code may use these symbols
3224 to move the overlaid sections around as necessary.
3226 At the end of the overlay, the value of the location counter is set
3227 to the start address of the overlay plus the size of the largest
3230 Here is an example. Remember that this would appear inside a
3231 `SECTIONS' construct.
3232 OVERLAY 0x1000 : AT (0x4000)
3234 .text0 { o1/*.o(.text) }
3235 .text1 { o2/*.o(.text) }
3238 This will define both `.text0' and `.text1' to start at address 0x1000.
3239 `.text0' will be loaded at address 0x4000, and `.text1' will be loaded
3240 immediately after `.text0'. The following symbols will be defined:
3241 `__load_start_text0', `__load_stop_text0', `__load_start_text1',
3242 `__load_stop_text1'.
3244 C code to copy overlay `.text1' into the overlay area might look
3247 extern char __load_start_text1, __load_stop_text1;
3248 memcpy ((char *) 0x1000, &__load_start_text1,
3249 &__load_stop_text1 - &__load_start_text1);
3251 Note that the `OVERLAY' command is just syntactic sugar, since
3252 everything it does can be done using the more basic commands. The above
3253 example could have been written identically as follows.
3255 .text0 0x1000 : AT (0x4000) { o1/*.o(.text) }
3256 __load_start_text0 = LOADADDR (.text0);
3257 __load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0);
3258 .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) }
3259 __load_start_text1 = LOADADDR (.text1);
3260 __load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1);
3261 . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
3264 File: ld.info, Node: MEMORY, Next: PHDRS, Prev: SECTIONS, Up: Scripts
3269 The linker's default configuration permits allocation of all
3270 available memory. You can override this by using the `MEMORY' command.
3272 The `MEMORY' command describes the location and size of blocks of
3273 memory in the target. You can use it to describe which memory regions
3274 may be used by the linker, and which memory regions it must avoid. You
3275 can then assign sections to particular memory regions. The linker will
3276 set section addresses based on the memory regions, and will warn about
3277 regions that become too full. The linker will not shuffle sections
3278 around to fit into the available regions.
3280 A linker script may contain at most one use of the `MEMORY' command.
3281 However, you can define as many blocks of memory within it as you
3282 wish. The syntax is:
3285 NAME [(ATTR)] : ORIGIN = ORIGIN, LENGTH = LEN
3289 The NAME is a name used in the linker script to refer to the region.
3290 The region name has no meaning outside of the linker script. Region
3291 names are stored in a separate name space, and will not conflict with
3292 symbol names, file names, or section names. Each memory region must
3293 have a distinct name.
3295 The ATTR string is an optional list of attributes that specify
3296 whether to use a particular memory region for an input section which is
3297 not explicitly mapped in the linker script. As described in *Note
3298 SECTIONS::, if you do not specify an output section for some input
3299 section, the linker will create an output section with the same name as
3300 the input section. If you define region attributes, the linker will use
3301 them to select the memory region for the output section that it creates.
3303 The ATTR string must consist only of the following characters:
3323 Invert the sense of any of the preceding attributes
3325 If a unmapped section matches any of the listed attributes other than
3326 `!', it will be placed in the memory region. The `!' attribute
3327 reverses this test, so that an unmapped section will be placed in the
3328 memory region only if it does not match any of the listed attributes.
3330 The ORIGIN is an numerical expression for the start address of the
3331 memory region. The expression must evaluate to a constant and it
3332 cannot involve any symbols. The keyword `ORIGIN' may be abbreviated to
3333 `org' or `o' (but not, for example, `ORG').
3335 The LEN is an expression for the size in bytes of the memory region.
3336 As with the ORIGIN expression, the expression must be numerical only
3337 and must evaluate to a constant. The keyword `LENGTH' may be
3338 abbreviated to `len' or `l'.
3340 In the following example, we specify that there are two memory
3341 regions available for allocation: one starting at `0' for 256 kilobytes,
3342 and the other starting at `0x40000000' for four megabytes. The linker
3343 will place into the `rom' memory region every section which is not
3344 explicitly mapped into a memory region, and is either read-only or
3345 executable. The linker will place other sections which are not
3346 explicitly mapped into a memory region into the `ram' memory region.
3350 rom (rx) : ORIGIN = 0, LENGTH = 256K
3351 ram (!rx) : org = 0x40000000, l = 4M
3354 Once you define a memory region, you can direct the linker to place
3355 specific output sections into that memory region by using the `>REGION'
3356 output section attribute. For example, if you have a memory region
3357 named `mem', you would use `>mem' in the output section definition.
3358 *Note Output Section Region::. If no address was specified for the
3359 output section, the linker will set the address to the next available
3360 address within the memory region. If the combined output sections
3361 directed to a memory region are too large for the region, the linker
3362 will issue an error message.
3364 It is possible to access the origin and length of a memory in an
3365 expression via the `ORIGIN(MEMORY)' and `LENGTH(MEMORY)' functions:
3367 _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
3370 File: ld.info, Node: PHDRS, Next: VERSION, Prev: MEMORY, Up: Scripts
3375 The ELF object file format uses "program headers", also knows as
3376 "segments". The program headers describe how the program should be
3377 loaded into memory. You can print them out by using the `objdump'
3378 program with the `-p' option.
3380 When you run an ELF program on a native ELF system, the system loader
3381 reads the program headers in order to figure out how to load the
3382 program. This will only work if the program headers are set correctly.
3383 This manual does not describe the details of how the system loader
3384 interprets program headers; for more information, see the ELF ABI.
3386 The linker will create reasonable program headers by default.
3387 However, in some cases, you may need to specify the program headers more
3388 precisely. You may use the `PHDRS' command for this purpose. When the
3389 linker sees the `PHDRS' command in the linker script, it will not
3390 create any program headers other than the ones specified.
3392 The linker only pays attention to the `PHDRS' command when
3393 generating an ELF output file. In other cases, the linker will simply
3396 This is the syntax of the `PHDRS' command. The words `PHDRS',
3397 `FILEHDR', `AT', and `FLAGS' are keywords.
3401 NAME TYPE [ FILEHDR ] [ PHDRS ] [ AT ( ADDRESS ) ]
3402 [ FLAGS ( FLAGS ) ] ;
3405 The NAME is used only for reference in the `SECTIONS' command of the
3406 linker script. It is not put into the output file. Program header
3407 names are stored in a separate name space, and will not conflict with
3408 symbol names, file names, or section names. Each program header must
3409 have a distinct name.
3411 Certain program header types describe segments of memory which the
3412 system loader will load from the file. In the linker script, you
3413 specify the contents of these segments by placing allocatable output
3414 sections in the segments. You use the `:PHDR' output section attribute
3415 to place a section in a particular segment. *Note Output Section
3418 It is normal to put certain sections in more than one segment. This
3419 merely implies that one segment of memory contains another. You may
3420 repeat `:PHDR', using it once for each segment which should contain the
3423 If you place a section in one or more segments using `:PHDR', then
3424 the linker will place all subsequent allocatable sections which do not
3425 specify `:PHDR' in the same segments. This is for convenience, since
3426 generally a whole set of contiguous sections will be placed in a single
3427 segment. You can use `:NONE' to override the default segment and tell
3428 the linker to not put the section in any segment at all.
3430 You may use the `FILEHDR' and `PHDRS' keywords appear after the
3431 program header type to further describe the contents of the segment.
3432 The `FILEHDR' keyword means that the segment should include the ELF
3433 file header. The `PHDRS' keyword means that the segment should include
3434 the ELF program headers themselves.
3436 The TYPE may be one of the following. The numbers indicate the
3437 value of the keyword.
3440 Indicates an unused program header.
3443 Indicates that this program header describes a segment to be
3444 loaded from the file.
3447 Indicates a segment where dynamic linking information can be found.
3450 Indicates a segment where the name of the program interpreter may
3454 Indicates a segment holding note information.
3457 A reserved program header type, defined but not specified by the
3461 Indicates a segment where the program headers may be found.
3464 An expression giving the numeric type of the program header. This
3465 may be used for types not defined above.
3467 You can specify that a segment should be loaded at a particular
3468 address in memory by using an `AT' expression. This is identical to the
3469 `AT' command used as an output section attribute (*note Output Section
3470 LMA::). The `AT' command for a program header overrides the output
3473 The linker will normally set the segment flags based on the sections
3474 which comprise the segment. You may use the `FLAGS' keyword to
3475 explicitly specify the segment flags. The value of FLAGS must be an
3476 integer. It is used to set the `p_flags' field of the program header.
3478 Here is an example of `PHDRS'. This shows a typical set of program
3479 headers used on a native ELF system.
3483 headers PT_PHDR PHDRS ;
3485 text PT_LOAD FILEHDR PHDRS ;
3487 dynamic PT_DYNAMIC ;
3493 .interp : { *(.interp) } :text :interp
3494 .text : { *(.text) } :text
3495 .rodata : { *(.rodata) } /* defaults to :text */
3497 . = . + 0x1000; /* move to a new page in memory */
3498 .data : { *(.data) } :data
3499 .dynamic : { *(.dynamic) } :data :dynamic
3504 File: ld.info, Node: VERSION, Next: Expressions, Prev: PHDRS, Up: Scripts
3509 The linker supports symbol versions when using ELF. Symbol versions
3510 are only useful when using shared libraries. The dynamic linker can use
3511 symbol versions to select a specific version of a function when it runs
3512 a program that may have been linked against an earlier version of the
3515 You can include a version script directly in the main linker script,
3516 or you can supply the version script as an implicit linker script. You
3517 can also use the `--version-script' linker option.
3519 The syntax of the `VERSION' command is simply
3520 VERSION { version-script-commands }
3522 The format of the version script commands is identical to that used
3523 by Sun's linker in Solaris 2.5. The version script defines a tree of
3524 version nodes. You specify the node names and interdependencies in the
3525 version script. You can specify which symbols are bound to which
3526 version nodes, and you can reduce a specified set of symbols to local
3527 scope so that they are not globally visible outside of the shared
3530 The easiest way to demonstrate the version script language is with a
3550 "int f(int, double)";
3554 This example version script defines three version nodes. The first
3555 version node defined is `VERS_1.1'; it has no other dependencies. The
3556 script binds the symbol `foo1' to `VERS_1.1'. It reduces a number of
3557 symbols to local scope so that they are not visible outside of the
3558 shared library; this is done using wildcard patterns, so that any
3559 symbol whose name begins with `old', `original', or `new' is matched.
3560 The wildcard patterns available are the same as those used in the shell
3561 when matching filenames (also known as "globbing"). However, if you
3562 specify the symbol name inside double quotes, then the name is treated
3563 as literal, rather than as a glob pattern.
3565 Next, the version script defines node `VERS_1.2'. This node depends
3566 upon `VERS_1.1'. The script binds the symbol `foo2' to the version
3569 Finally, the version script defines node `VERS_2.0'. This node
3570 depends upon `VERS_1.2'. The scripts binds the symbols `bar1' and
3571 `bar2' are bound to the version node `VERS_2.0'.
3573 When the linker finds a symbol defined in a library which is not
3574 specifically bound to a version node, it will effectively bind it to an
3575 unspecified base version of the library. You can bind all otherwise
3576 unspecified symbols to a given version node by using `global: *;'
3577 somewhere in the version script.
3579 The names of the version nodes have no specific meaning other than
3580 what they might suggest to the person reading them. The `2.0' version
3581 could just as well have appeared in between `1.1' and `1.2'. However,
3582 this would be a confusing way to write a version script.
3584 Node name can be omited, provided it is the only version node in the
3585 version script. Such version script doesn't assign any versions to
3586 symbols, only selects which symbols will be globally visible out and
3589 { global: foo; bar; local: *; };
3591 When you link an application against a shared library that has
3592 versioned symbols, the application itself knows which version of each
3593 symbol it requires, and it also knows which version nodes it needs from
3594 each shared library it is linked against. Thus at runtime, the dynamic
3595 loader can make a quick check to make sure that the libraries you have
3596 linked against do in fact supply all of the version nodes that the
3597 application will need to resolve all of the dynamic symbols. In this
3598 way it is possible for the dynamic linker to know with certainty that
3599 all external symbols that it needs will be resolvable without having to
3600 search for each symbol reference.
3602 The symbol versioning is in effect a much more sophisticated way of
3603 doing minor version checking that SunOS does. The fundamental problem
3604 that is being addressed here is that typically references to external
3605 functions are bound on an as-needed basis, and are not all bound when
3606 the application starts up. If a shared library is out of date, a
3607 required interface may be missing; when the application tries to use
3608 that interface, it may suddenly and unexpectedly fail. With symbol
3609 versioning, the user will get a warning when they start their program if
3610 the libraries being used with the application are too old.
3612 There are several GNU extensions to Sun's versioning approach. The
3613 first of these is the ability to bind a symbol to a version node in the
3614 source file where the symbol is defined instead of in the versioning
3615 script. This was done mainly to reduce the burden on the library
3616 maintainer. You can do this by putting something like:
3617 __asm__(".symver original_foo,foo@VERS_1.1");
3619 in the C source file. This renames the function `original_foo' to be
3620 an alias for `foo' bound to the version node `VERS_1.1'. The `local:'
3621 directive can be used to prevent the symbol `original_foo' from being
3622 exported. A `.symver' directive takes precedence over a version script.
3624 The second GNU extension is to allow multiple versions of the same
3625 function to appear in a given shared library. In this way you can make
3626 an incompatible change to an interface without increasing the major
3627 version number of the shared library, while still allowing applications
3628 linked against the old interface to continue to function.
3630 To do this, you must use multiple `.symver' directives in the source
3631 file. Here is an example:
3633 __asm__(".symver original_foo,foo@");
3634 __asm__(".symver old_foo,foo@VERS_1.1");
3635 __asm__(".symver old_foo1,foo@VERS_1.2");
3636 __asm__(".symver new_foo,foo@@VERS_2.0");
3638 In this example, `foo@' represents the symbol `foo' bound to the
3639 unspecified base version of the symbol. The source file that contains
3640 this example would define 4 C functions: `original_foo', `old_foo',
3641 `old_foo1', and `new_foo'.
3643 When you have multiple definitions of a given symbol, there needs to
3644 be some way to specify a default version to which external references to
3645 this symbol will be bound. You can do this with the `foo@@VERS_2.0'
3646 type of `.symver' directive. You can only declare one version of a
3647 symbol as the default in this manner; otherwise you would effectively
3648 have multiple definitions of the same symbol.
3650 If you wish to bind a reference to a specific version of the symbol
3651 within the shared library, you can use the aliases of convenience
3652 (i.e., `old_foo'), or you can use the `.symver' directive to
3653 specifically bind to an external version of the function in question.
3655 You can also specify the language in the version script:
3657 VERSION extern "lang" { version-script-commands }
3659 The supported `lang's are `C', `C++', and `Java'. The linker will
3660 iterate over the list of symbols at the link time and demangle them
3661 according to `lang' before matching them to the patterns specified in
3662 `version-script-commands'.
3664 Demangled names may contains spaces and other special characters. As
3665 described above, you can use a glob pattern to match demangled names,
3666 or you can use a double-quoted string to match the string exactly. In
3667 the latter case, be aware that minor differences (such as differing
3668 whitespace) between the version script and the demangler output will
3669 cause a mismatch. As the exact string generated by the demangler might
3670 change in the future, even if the mangled name does not, you should
3671 check that all of your version directives are behaving as you expect
3675 File: ld.info, Node: Expressions, Next: Implicit Linker Scripts, Prev: VERSION, Up: Scripts
3677 Expressions in Linker Scripts
3678 =============================
3680 The syntax for expressions in the linker script language is
3681 identical to that of C expressions. All expressions are evaluated as
3682 integers. All expressions are evaluated in the same size, which is 32
3683 bits if both the host and target are 32 bits, and is otherwise 64 bits.
3685 You can use and set symbol values in expressions.
3687 The linker defines several special purpose builtin functions for use
3692 * Constants:: Constants
3693 * Symbols:: Symbol Names
3694 * Orphan Sections:: Orphan Sections
3695 * Location Counter:: The Location Counter
3696 * Operators:: Operators
3697 * Evaluation:: Evaluation
3698 * Expression Section:: The Section of an Expression
3699 * Builtin Functions:: Builtin Functions
3702 File: ld.info, Node: Constants, Next: Symbols, Up: Expressions
3707 All constants are integers.
3709 As in C, the linker considers an integer beginning with `0' to be
3710 octal, and an integer beginning with `0x' or `0X' to be hexadecimal.
3711 The linker considers other integers to be decimal.
3713 In addition, you can use the suffixes `K' and `M' to scale a
3714 constant by `1024' or `1024*1024' respectively. For example, the
3715 following all refer to the same quantity:
3721 File: ld.info, Node: Symbols, Next: Orphan Sections, Prev: Constants, Up: Expressions
3726 Unless quoted, symbol names start with a letter, underscore, or
3727 period and may include letters, digits, underscores, periods, and
3728 hyphens. Unquoted symbol names must not conflict with any keywords.
3729 You can specify a symbol which contains odd characters or has the same
3730 name as a keyword by surrounding the symbol name in double quotes:
3732 "with a space" = "also with a space" + 10;
3734 Since symbols can contain many non-alphabetic characters, it is
3735 safest to delimit symbols with spaces. For example, `A-B' is one
3736 symbol, whereas `A - B' is an expression involving subtraction.
3739 File: ld.info, Node: Orphan Sections, Next: Location Counter, Prev: Symbols, Up: Expressions
3744 Orphan sections are sections present in the input files which are
3745 not explicitly placed into the output file by the linker script. The
3746 linker will still copy these sections into the output file, but it has
3747 to guess as to where they should be placed. The linker uses a simple
3748 heuristic to do this. It attempts to place orphan sections after
3749 non-orphan sections of the same attribute, such as code vs data,
3750 loadable vs non-loadable, etc. If there is not enough room to do this
3751 then it places at the end of the file.
3753 For ELF targets, the attribute of the section includes section type
3754 as well as section flag.
3757 File: ld.info, Node: Location Counter, Next: Operators, Prev: Orphan Sections, Up: Expressions
3759 The Location Counter
3760 --------------------
3762 The special linker variable "dot" `.' always contains the current
3763 output location counter. Since the `.' always refers to a location in
3764 an output section, it may only appear in an expression within a
3765 `SECTIONS' command. The `.' symbol may appear anywhere that an
3766 ordinary symbol is allowed in an expression.
3768 Assigning a value to `.' will cause the location counter to be
3769 moved. This may be used to create holes in the output section. The
3770 location counter may never be moved backwards.
3784 In the previous example, the `.text' section from `file1' is located at
3785 the beginning of the output section `output'. It is followed by a 1000
3786 byte gap. Then the `.text' section from `file2' appears, also with a
3787 1000 byte gap following before the `.text' section from `file3'. The
3788 notation `= 0x12345678' specifies what data to write in the gaps (*note
3789 Output Section Fill::).
3791 Note: `.' actually refers to the byte offset from the start of the
3792 current containing object. Normally this is the `SECTIONS' statement,
3793 whose start address is 0, hence `.' can be used as an absolute address.
3794 If `.' is used inside a section description however, it refers to the
3795 byte offset from the start of that section, not an absolute address.
3796 Thus in a script like this:
3812 The `.text' section will be assigned a starting address of 0x100 and
3813 a size of exactly 0x200 bytes, even if there is not enough data in the
3814 `.text' input sections to fill this area. (If there is too much data,
3815 an error will be produced because this would be an attempt to move `.'
3816 backwards). The `.data' section will start at 0x500 and it will have
3817 an extra 0x600 bytes worth of space after the end of the values from
3818 the `.data' input sections and before the end of the `.data' output
3821 Setting symbols to the value of the location counter outside of an
3822 output section statement can result in unexpected values if the linker
3823 needs to place orphan sections. For example, given the following:
3836 If the linker needs to place some input section, e.g. `.rodata', not
3837 mentioned in the script, it might choose to place that section between
3838 `.text' and `.data'. You might think the linker should place `.rodata'
3839 on the blank line in the above script, but blank lines are of no
3840 particular significance to the linker. As well, the linker doesn't
3841 associate the above symbol names with their sections. Instead, it
3842 assumes that all assignments or other statements belong to the previous
3843 output section, except for the special case of an assignment to `.'.
3844 I.e., the linker will place the orphan `.rodata' section as if the
3845 script was written as follows:
3854 .rodata: { *(.rodata) }
3859 This may or may not be the script author's intention for the value of
3860 `start_of_data'. One way to influence the orphan section placement is
3861 to assign the location counter to itself, as the linker assumes that an
3862 assignment to `.' is setting the start address of a following output
3863 section and thus should be grouped with that section. So you could
3878 Now, the orphan `.rodata' section will be placed between
3879 `end_of_text' and `start_of_data'.
3882 File: ld.info, Node: Operators, Next: Evaluation, Prev: Location Counter, Up: Expressions
3887 The linker recognizes the standard C set of arithmetic operators,
3888 with the standard bindings and precedence levels:
3889 precedence associativity Operators Notes
3895 5 left == != > < <= >=
3901 11 right &= += -= *= /= (2)
3903 Notes: (1) Prefix operators (2) *Note Assignments::.
3906 File: ld.info, Node: Evaluation, Next: Expression Section, Prev: Operators, Up: Expressions
3911 The linker evaluates expressions lazily. It only computes the value
3912 of an expression when absolutely necessary.
3914 The linker needs some information, such as the value of the start
3915 address of the first section, and the origins and lengths of memory
3916 regions, in order to do any linking at all. These values are computed
3917 as soon as possible when the linker reads in the linker script.
3919 However, other values (such as symbol values) are not known or needed
3920 until after storage allocation. Such values are evaluated later, when
3921 other information (such as the sizes of output sections) is available
3922 for use in the symbol assignment expression.
3924 The sizes of sections cannot be known until after allocation, so
3925 assignments dependent upon these are not performed until after
3928 Some expressions, such as those depending upon the location counter
3929 `.', must be evaluated during section allocation.
3931 If the result of an expression is required, but the value is not
3932 available, then an error results. For example, a script like the
3936 .text 9+this_isnt_constant :
3940 will cause the error message `non constant expression for initial
3944 File: ld.info, Node: Expression Section, Next: Builtin Functions, Prev: Evaluation, Up: Expressions
3946 The Section of an Expression
3947 ----------------------------
3949 When the linker evaluates an expression, the result is either
3950 absolute or relative to some section. A relative expression is
3951 expressed as a fixed offset from the base of a section.
3953 The position of the expression within the linker script determines
3954 whether it is absolute or relative. An expression which appears within
3955 an output section definition is relative to the base of the output
3956 section. An expression which appears elsewhere will be absolute.
3958 A symbol set to a relative expression will be relocatable if you
3959 request relocatable output using the `-r' option. That means that a
3960 further link operation may change the value of the symbol. The symbol's
3961 section will be the section of the relative expression.
3963 A symbol set to an absolute expression will retain the same value
3964 through any further link operation. The symbol will be absolute, and
3965 will not have any particular associated section.
3967 You can use the builtin function `ABSOLUTE' to force an expression
3968 to be absolute when it would otherwise be relative. For example, to
3969 create an absolute symbol set to the address of the end of the output
3973 .data : { *(.data) _edata = ABSOLUTE(.); }
3976 If `ABSOLUTE' were not used, `_edata' would be relative to the `.data'
3980 File: ld.info, Node: Builtin Functions, Prev: Expression Section, Up: Expressions
3985 The linker script language includes a number of builtin functions for
3986 use in linker script expressions.
3989 Return the absolute (non-relocatable, as opposed to non-negative)
3990 value of the expression EXP. Primarily useful to assign an
3991 absolute value to a symbol within a section definition, where
3992 symbol values are normally section relative. *Note Expression
3996 Return the absolute address (the VMA) of the named SECTION. Your
3997 script must previously have defined the location of that section.
3998 In the following example, `symbol_1' and `symbol_2' are assigned
4003 start_of_output_1 = ABSOLUTE(.);
4008 symbol_1 = ADDR(.output1);
4009 symbol_2 = start_of_output_1;
4015 Return the location counter (`.') or arbitrary expression aligned
4016 to the next ALIGN boundary. The single operand `ALIGN' doesn't
4017 change the value of the location counter--it just does arithmetic
4018 on it. The two operand `ALIGN' allows an arbitrary expression to
4019 be aligned upwards (`ALIGN(ALIGN)' is equivalent to `ALIGN(.,
4022 Here is an example which aligns the output `.data' section to the
4023 next `0x2000' byte boundary after the preceding section and sets a
4024 variable within the section to the next `0x8000' boundary after the
4027 .data ALIGN(0x2000): {
4029 variable = ALIGN(0x8000);
4033 The first use of `ALIGN' in this example specifies the location of
4034 a section because it is used as the optional ADDRESS attribute of
4035 a section definition (*note Output Section Address::). The second
4036 use of `ALIGN' is used to defines the value of a symbol.
4038 The builtin function `NEXT' is closely related to `ALIGN'.
4041 This is a synonym for `ALIGN', for compatibility with older linker
4042 scripts. It is most often seen when setting the address of an
4045 `DATA_SEGMENT_ALIGN(MAXPAGESIZE, COMMONPAGESIZE)'
4046 This is equivalent to either
4047 (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - 1)))
4049 (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - COMMONPAGESIZE)))
4051 depending on whether the latter uses fewer COMMONPAGESIZE sized
4052 pages for the data segment (area between the result of this
4053 expression and `DATA_SEGMENT_END') than the former or not. If the
4054 latter form is used, it means COMMONPAGESIZE bytes of runtime
4055 memory will be saved at the expense of up to COMMONPAGESIZE wasted
4056 bytes in the on-disk file.
4058 This expression can only be used directly in `SECTIONS' commands,
4059 not in any output section descriptions and only once in the linker
4060 script. COMMONPAGESIZE should be less or equal to MAXPAGESIZE and
4061 should be the system page size the object wants to be optimized
4062 for (while still working on system page sizes up to MAXPAGESIZE).
4065 . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
4067 `DATA_SEGMENT_END(EXP)'
4068 This defines the end of data segment for `DATA_SEGMENT_ALIGN'
4069 evaluation purposes.
4071 . = DATA_SEGMENT_END(.);
4073 `DATA_SEGMENT_RELRO_END(OFFSET, EXP)'
4074 This defines the end of the `PT_GNU_RELRO' segment when `-z relro'
4075 option is used. Second argument is returned. When `-z relro'
4076 option is not present, `DATA_SEGMENT_RELRO_END' does nothing,
4077 otherwise `DATA_SEGMENT_ALIGN' is padded so that EXP + OFFSET is
4078 aligned to the most commonly used page boundary for particular
4079 target. If present in the linker script, it must always come in
4080 between `DATA_SEGMENT_ALIGN' and `DATA_SEGMENT_END'.
4082 . = DATA_SEGMENT_RELRO_END(24, .);
4085 Return 1 if SYMBOL is in the linker global symbol table and is
4086 defined before the statement using DEFINED in the script, otherwise
4087 return 0. You can use this function to provide default values for
4088 symbols. For example, the following script fragment shows how to
4089 set a global symbol `begin' to the first location in the `.text'
4090 section--but if a symbol called `begin' already existed, its value
4095 begin = DEFINED(begin) ? begin : . ;
4102 Return the length of the memory region named MEMORY.
4105 Return the absolute LMA of the named SECTION. This is normally
4106 the same as `ADDR', but it may be different if the `AT' attribute
4107 is used in the output section definition (*note Output Section
4111 Returns the maximum of EXP1 and EXP2.
4114 Returns the minimum of EXP1 and EXP2.
4117 Return the next unallocated address that is a multiple of EXP.
4118 This function is closely related to `ALIGN(EXP)'; unless you use
4119 the `MEMORY' command to define discontinuous memory for the output
4120 file, the two functions are equivalent.
4123 Return the origin of the memory region named MEMORY.
4125 `SEGMENT_START(SEGMENT, DEFAULT)'
4126 Return the base address of the named SEGMENT. If an explicit
4127 value has been given for this segment (with a command-line `-T'
4128 option) that value will be returned; otherwise the value will be
4129 DEFAULT. At present, the `-T' command-line option can only be
4130 used to set the base address for the "text", "data", and "bss"
4131 sections, but you use `SEGMENT_START' with any segment name.
4134 Return the size in bytes of the named SECTION, if that section has
4135 been allocated. If the section has not been allocated when this is
4136 evaluated, the linker will report an error. In the following
4137 example, `symbol_1' and `symbol_2' are assigned identical values:
4144 symbol_1 = .end - .start ;
4145 symbol_2 = SIZEOF(.output);
4150 Return the size in bytes of the output file's headers. This is
4151 information which appears at the start of the output file. You
4152 can use this number when setting the start address of the first
4153 section, if you choose, to facilitate paging.
4155 When producing an ELF output file, if the linker script uses the
4156 `SIZEOF_HEADERS' builtin function, the linker must compute the
4157 number of program headers before it has determined all the section
4158 addresses and sizes. If the linker later discovers that it needs
4159 additional program headers, it will report an error `not enough
4160 room for program headers'. To avoid this error, you must avoid
4161 using the `SIZEOF_HEADERS' function, or you must rework your linker
4162 script to avoid forcing the linker to use additional program
4163 headers, or you must define the program headers yourself using the
4164 `PHDRS' command (*note PHDRS::).
4167 File: ld.info, Node: Implicit Linker Scripts, Prev: Expressions, Up: Scripts
4169 Implicit Linker Scripts
4170 =======================
4172 If you specify a linker input file which the linker can not
4173 recognize as an object file or an archive file, it will try to read the
4174 file as a linker script. If the file can not be parsed as a linker
4175 script, the linker will report an error.
4177 An implicit linker script will not replace the default linker script.
4179 Typically an implicit linker script would contain only symbol
4180 assignments, or the `INPUT', `GROUP', or `VERSION' commands.
4182 Any input files read because of an implicit linker script will be
4183 read at the position in the command line where the implicit linker
4184 script was read. This can affect archive searching.
4187 File: ld.info, Node: Machine Dependent, Next: BFD, Prev: Scripts, Up: Top
4189 Machine Dependent Features
4190 **************************
4192 `ld' has additional features on some platforms; the following
4193 sections describe them. Machines where `ld' has no additional
4194 functionality are not listed.
4199 * H8/300:: `ld' and the H8/300
4201 * i960:: `ld' and the Intel 960 family
4203 * ARM:: `ld' and the ARM family
4205 * HPPA ELF32:: `ld' and HPPA 32-bit ELF
4207 * MMIX:: `ld' and MMIX
4209 * MSP430:: `ld' and MSP430
4211 * TI COFF:: `ld' and TI COFF
4213 * WIN32:: `ld' and WIN32 (cygwin/mingw)
4215 * Xtensa:: `ld' and Xtensa Processors
4218 File: ld.info, Node: H8/300, Next: i960, Up: Machine Dependent
4223 For the H8/300, `ld' can perform these global optimizations when you
4224 specify the `--relax' command-line option.
4226 _relaxing address modes_
4227 `ld' finds all `jsr' and `jmp' instructions whose targets are
4228 within eight bits, and turns them into eight-bit program-counter
4229 relative `bsr' and `bra' instructions, respectively.
4231 _synthesizing instructions_
4232 `ld' finds all `mov.b' instructions which use the sixteen-bit
4233 absolute address form, but refer to the top page of memory, and
4234 changes them to use the eight-bit address form. (That is: the
4235 linker turns `mov.b `@'AA:16' into `mov.b `@'AA:8' whenever the
4236 address AA is in the top page of memory).
4238 _bit manipulation instructions_
4239 `ld' finds all bit manipulation instructions like `band, bclr,
4240 biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst,
4241 bxor' which use 32 bit and 16 bit absolute address form, but refer
4242 to the top page of memory, and changes them to use the 8 bit
4243 address form. (That is: the linker turns `bset #xx:3,`@'AA:32'
4244 into `bset #xx:3,`@'AA:8' whenever the address AA is in the top
4247 _system control instructions_
4248 `ld' finds all `ldc.w, stc.w' instrcutions which use the 32 bit
4249 absolute address form, but refer to the top page of memory, and
4250 changes them to use 16 bit address form. (That is: the linker
4251 turns `ldc.w `@'AA:32,ccr' into `ldc.w `@'AA:16,ccr' whenever the
4252 address AA is in the top page of memory).
4255 File: ld.info, Node: i960, Next: ARM, Prev: H8/300, Up: Machine Dependent
4257 `ld' and the Intel 960 Family
4258 =============================
4260 You can use the `-AARCHITECTURE' command line option to specify one
4261 of the two-letter names identifying members of the 960 family; the
4262 option specifies the desired output target, and warns of any
4263 incompatible instructions in the input files. It also modifies the
4264 linker's search strategy for archive libraries, to support the use of
4265 libraries specific to each particular architecture, by including in the
4266 search loop names suffixed with the string identifying the architecture.
4268 For example, if your `ld' command line included `-ACA' as well as
4269 `-ltry', the linker would look (in its built-in search paths, and in
4270 any paths you specify with `-L') for a library with the names
4277 The first two possibilities would be considered in any event; the last
4278 two are due to the use of `-ACA'.
4280 You can meaningfully use `-A' more than once on a command line, since
4281 the 960 architecture family allows combination of target architectures;
4282 each use will add another pair of name variants to search for when `-l'
4283 specifies a library.
4285 `ld' supports the `--relax' option for the i960 family. If you
4286 specify `--relax', `ld' finds all `balx' and `calx' instructions whose
4287 targets are within 24 bits, and turns them into 24-bit program-counter
4288 relative `bal' and `cal' instructions, respectively. `ld' also turns
4289 `cal' instructions into `bal' instructions when it determines that the
4290 target subroutine is a leaf routine (that is, the target subroutine does
4291 not itself call any subroutines).
4294 File: ld.info, Node: ARM, Next: HPPA ELF32, Prev: i960, Up: Machine Dependent
4296 `ld' and the ARM family
4297 =======================
4299 For the ARM, `ld' will generate code stubs to allow functions calls
4300 betweem ARM and Thumb code. These stubs only work with code that has
4301 been compiled and assembled with the `-mthumb-interwork' command line
4302 option. If it is necessary to link with old ARM object files or
4303 libraries, which have not been compiled with the -mthumb-interwork
4304 option then the `--support-old-code' command line switch should be
4305 given to the linker. This will make it generate larger stub functions
4306 which will work with non-interworking aware ARM code. Note, however,
4307 the linker does not support generating stubs for function calls to
4308 non-interworking aware Thumb code.
4310 The `--thumb-entry' switch is a duplicate of the generic `--entry'
4311 switch, in that it sets the program's starting address. But it also
4312 sets the bottom bit of the address, so that it can be branched to using
4313 a BX instruction, and the program will start executing in Thumb mode
4316 The `--be8' switch instructs `ld' to generate BE8 format
4317 executables. This option is only valid when linking big-endian objects.
4318 The resulting image will contain big-endian data and little-endian code.
4320 The `R_ARM_TARGET1' relocation is typically used for entries in the
4321 `.init_array' section. It is interpreted as either `R_ARM_REL32' or
4322 `R_ARM_ABS32', depending on the target. The `--target1-rel' and
4323 `--target1-abs' switches override the default.
4325 The `--target2=type' switch overrides the default definition of the
4326 `R_ARM_TARGET2' relocation. Valid values for `type', their meanings,
4327 and target defaults are as follows:
4329 `R_ARM_REL32' (arm*-*-elf, arm*-*-eabi)
4332 `R_ARM_ABS32' (arm*-*-symbianelf)
4335 `R_ARM_GOT_PREL' (arm*-*-linux, arm*-*-*bsd)
4337 The `R_ARM_V4BX' relocation (defined by the ARM AAELF specification)
4338 enables objects compiled for the ARMv4 architecture to be
4339 interworking-safe when linked with other objects compiled for ARMv4t,
4340 but also allows pure ARMv4 binaries to be built from the same ARMv4
4343 In the latter case, the switch `--fix-v4bx' must be passed to the
4344 linker, which causes v4t `BX rM' instructions to be rewritten as `MOV
4345 PC,rM', since v4 processors do not have a `BX' instruction.
4347 In the former case, the switch should not be used, and `R_ARM_V4BX'
4348 relocations are ignored.
4350 The `--use-blx' switch enables the linker to use ARM/Thumb BLX
4351 instructions (available on ARMv5t and above) in various situations.
4352 Currently it is used to perform calls via the PLT from Thumb code using
4353 BLX rather than using BX and a mode-switching stub before each PLT
4354 entry. This should lead to such calls executing slightly faster.
4356 This option is enabled implicitly for SymbianOS, so there is no need
4357 to specify it if you are using that target.
4360 File: ld.info, Node: HPPA ELF32, Next: MMIX, Prev: ARM, Up: Machine Dependent
4362 `ld' and HPPA 32-bit ELF Support
4363 ================================
4365 When generating a shared library, `ld' will by default generate
4366 import stubs suitable for use with a single sub-space application. The
4367 `--multi-subspace' switch causes `ld' to generate export stubs, and
4368 different (larger) import stubs suitable for use with multiple
4371 Long branch stubs and import/export stubs are placed by `ld' in stub
4372 sections located between groups of input sections. `--stub-group-size'
4373 specifies the maximum size of a group of input sections handled by one
4374 stub section. Since branch offsets are signed, a stub section may
4375 serve two groups of input sections, one group before the stub section,
4376 and one group after it. However, when using conditional branches that
4377 require stubs, it may be better (for branch prediction) that stub
4378 sections only serve one group of input sections. A negative value for
4379 `N' chooses this scheme, ensuring that branches to stubs always use a
4380 negative offset. Two special values of `N' are recognized, `1' and
4381 `-1'. These both instruct `ld' to automatically size input section
4382 groups for the branch types detected, with the same behaviour regarding
4383 stub placement as other positive or negative values of `N' respectively.
4385 Note that `--stub-group-size' does not split input sections. A
4386 single input section larger than the group size specified will of course
4387 create a larger group (of one section). If input sections are too
4388 large, it may not be possible for a branch to reach its stub.
4391 File: ld.info, Node: MMIX, Next: MSP430, Prev: HPPA ELF32, Up: Machine Dependent
4396 For MMIX, there is a choice of generating `ELF' object files or
4397 `mmo' object files when linking. The simulator `mmix' understands the
4398 `mmo' format. The binutils `objcopy' utility can translate between the
4401 There is one special section, the `.MMIX.reg_contents' section.
4402 Contents in this section is assumed to correspond to that of global
4403 registers, and symbols referring to it are translated to special
4404 symbols, equal to registers. In a final link, the start address of the
4405 `.MMIX.reg_contents' section corresponds to the first allocated global
4406 register multiplied by 8. Register `$255' is not included in this
4407 section; it is always set to the program entry, which is at the symbol
4408 `Main' for `mmo' files.
4410 Symbols with the prefix `__.MMIX.start.', for example
4411 `__.MMIX.start..text' and `__.MMIX.start..data' are special; there must
4412 be only one each, even if they are local. The default linker script
4413 uses these to set the default start address of a section.
4415 Initial and trailing multiples of zero-valued 32-bit words in a
4416 section, are left out from an mmo file.
4419 File: ld.info, Node: MSP430, Next: TI COFF, Prev: MMIX, Up: Machine Dependent
4424 For the MSP430 it is possible to select the MPU architecture. The
4425 flag `-m [mpu type]' will select an appropriate linker script for
4426 selected MPU type. (To get a list of known MPUs just pass `-m help'
4427 option to the linker).
4429 The linker will recognize some extra sections which are MSP430
4433 Defines a portion of ROM where interrupt vectors located.
4436 Defines the bootloader portion of the ROM (if applicable). Any
4437 code in this section will be uploaded to the MPU.
4440 Defines an information memory section (if applicable). Any code in
4441 this section will be uploaded to the MPU.
4444 This is the same as the `.infomem' section except that any code in
4445 this section will not be uploaded to the MPU.
4448 Denotes a portion of RAM located above `.bss' section.
4450 The last two sections are used by gcc.
4453 File: ld.info, Node: TI COFF, Next: WIN32, Prev: MSP430, Up: Machine Dependent
4455 `ld''s Support for Various TI COFF Versions
4456 ===========================================
4458 The `--format' switch allows selection of one of the various TI COFF
4459 versions. The latest of this writing is 2; versions 0 and 1 are also
4460 supported. The TI COFF versions also vary in header byte-order format;
4461 `ld' will read any version or byte order, but the output header format
4462 depends on the default specified by the specific target.
4465 File: ld.info, Node: WIN32, Next: Xtensa, Prev: TI COFF, Up: Machine Dependent
4467 `ld' and WIN32 (cygwin/mingw)
4468 =============================
4470 This section describes some of the win32 specific `ld' issues. See
4471 *Note Command Line Options: Options for detailed decription of the
4472 command line options mentioned here.
4475 The standard Windows linker creates and uses so-called import
4476 libraries, which contains information for linking to dll's. They
4477 are regular static archives and are handled as any other static
4478 archive. The cygwin and mingw ports of `ld' have specific support
4479 for creating such libraries provided with the `--out-implib'
4480 command line option.
4482 _exporting DLL symbols_
4483 The cygwin/mingw `ld' has several ways to export symbols for dll's.
4485 _using auto-export functionality_
4486 By default `ld' exports symbols with the auto-export
4487 functionality, which is controlled by the following command
4490 * -export-all-symbols [This is the default]
4496 If, however, `--export-all-symbols' is not given explicitly
4497 on the command line, then the default auto-export behavior
4498 will be _disabled_ if either of the following are true:
4500 * A DEF file is used.
4502 * Any symbol in any object file was marked with the
4503 __declspec(dllexport) attribute.
4506 Another way of exporting symbols is using a DEF file. A DEF
4507 file is an ASCII file containing definitions of symbols which
4508 should be exported when a dll is created. Usually it is
4509 named `<dll name>.def' and is added as any other object file
4510 to the linker's command line. The file's name must end in
4513 gcc -o <output> <objectfiles> <dll name>.def
4515 Using a DEF file turns off the normal auto-export behavior,
4516 unless the `--export-all-symbols' option is also used.
4518 Here is an example of a DEF file for a shared library called
4521 LIBRARY "xyz.dll" BASE=0x10000000
4528 This example defines a base address and three symbols. The
4529 third symbol is an alias for the second. For the complete
4530 format specification see ld/deffilep.y in the binutils
4533 While linking a shared dll, `ld' is able to create a DEF file
4534 with the `--output-def <file>' command line option.
4537 Another way of marking symbols for export is to modify the
4538 source code itself, so that when building the DLL each symbol
4539 to be exported is declared as:
4541 __declspec(dllexport) int a_variable
4542 __declspec(dllexport) void a_function(int with_args)
4544 All such symbols will be exported from the DLL. If, however,
4545 any of the object files in the DLL contain symbols decorated
4546 in this way, then the normal auto-export behavior is
4547 disabled, unless the `--export-all-symbols' option is also
4550 Note that object files that wish to access these symbols must
4551 _not_ decorate them with dllexport. Instead, they should use
4554 __declspec(dllimport) int a_variable
4555 __declspec(dllimport) void a_function(int with_args)
4557 This complicates the structure of library header files,
4558 because when included by the library itself the header must
4559 declare the variables and functions as dllexport, but when
4560 included by client code the header must declare them as
4561 dllimport. There are a number of idioms that are typically
4562 used to do this; often client code can omit the __declspec()
4563 declaration completely. See `--enable-auto-import' and
4564 `automatic data imports' for more imformation.
4566 _automatic data imports_
4567 The standard Windows dll format supports data imports from dlls
4568 only by adding special decorations (dllimport/dllexport), which
4569 let the compiler produce specific assembler instructions to deal
4570 with this issue. This increases the effort necessary to port
4571 existing Un*x code to these platforms, especially for large c++
4572 libraries and applications. The auto-import feature, which was
4573 initially provided by Paul Sokolovsky, allows one to omit the
4574 decorations to archieve a behavior that conforms to that on
4575 POSIX/Un*x platforms. This feature is enabled with the
4576 `--enable-auto-import' command-line option, although it is enabled
4577 by default on cygwin/mingw. The `--enable-auto-import' option
4578 itself now serves mainly to suppress any warnings that are
4579 ordinarily emitted when linked objects trigger the feature's use.
4581 auto-import of variables does not always work flawlessly without
4582 additional assistance. Sometimes, you will see this message
4584 "variable '<var>' can't be auto-imported. Please read the
4585 documentation for ld's `--enable-auto-import' for details."
4587 The `--enable-auto-import' documentation explains why this error
4588 occurs, and several methods that can be used to overcome this
4589 difficulty. One of these methods is the _runtime pseudo-relocs_
4590 feature, described below.
4592 For complex variables imported from DLLs (such as structs or
4593 classes), object files typically contain a base address for the
4594 variable and an offset (_addend_) within the variable-to specify a
4595 particular field or public member, for instance. Unfortunately,
4596 the runtime loader used in win32 environments is incapable of
4597 fixing these references at runtime without the additional
4598 information supplied by dllimport/dllexport decorations. The
4599 standard auto-import feature described above is unable to resolve
4602 The `--enable-runtime-pseudo-relocs' switch allows these
4603 references to be resolved without error, while leaving the task of
4604 adjusting the references themselves (with their non-zero addends)
4605 to specialized code provided by the runtime environment. Recent
4606 versions of the cygwin and mingw environments and compilers
4607 provide this runtime support; older versions do not. However, the
4608 support is only necessary on the developer's platform; the
4609 compiled result will run without error on an older system.
4611 `--enable-runtime-pseudo-relocs' is not the default; it must be
4612 explicitly enabled as needed.
4614 _direct linking to a dll_
4615 The cygwin/mingw ports of `ld' support the direct linking,
4616 including data symbols, to a dll without the usage of any import
4617 libraries. This is much faster and uses much less memory than
4618 does the traditional import library method, expecially when
4619 linking large libraries or applications. When `ld' creates an
4620 import lib, each function or variable exported from the dll is
4621 stored in its own bfd, even though a single bfd could contain many
4622 exports. The overhead involved in storing, loading, and
4623 processing so many bfd's is quite large, and explains the
4624 tremendous time, memory, and storage needed to link against
4625 particularly large or complex libraries when using import libs.
4627 Linking directly to a dll uses no extra command-line switches
4628 other than `-L' and `-l', because `ld' already searches for a
4629 number of names to match each library. All that is needed from
4630 the developer's perspective is an understanding of this search, in
4631 order to force ld to select the dll instead of an import library.
4633 For instance, when ld is called with the argument `-lxxx' it will
4634 attempt to find, in the first directory of its search path,
4643 before moving on to the next directory in the search path.
4645 (*) Actually, this is not `cygxxx.dll' but in fact is
4646 `<prefix>xxx.dll', where `<prefix>' is set by the `ld' option
4647 `--dll-search-prefix=<prefix>'. In the case of cygwin, the
4648 standard gcc spec file includes `--dll-search-prefix=cyg', so in
4649 effect we actually search for `cygxxx.dll'.
4651 Other win32-based unix environments, such as mingw or pw32, may
4652 use other `<prefix>'es, although at present only cygwin makes use
4653 of this feature. It was originally intended to help avoid name
4654 conflicts among dll's built for the various win32/un*x
4655 environments, so that (for example) two versions of a zlib dll
4656 could coexist on the same machine.
4658 The generic cygwin/mingw path layout uses a `bin' directory for
4659 applications and dll's and a `lib' directory for the import
4660 libraries (using cygwin nomenclature):
4665 libxxx.dll.a (in case of dll's)
4666 libxxx.a (in case of static archive)
4668 Linking directly to a dll without using the import library can be
4671 1. Use the dll directly by adding the `bin' path to the link line
4672 gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx
4674 However, as the dll's often have version numbers appended to their
4675 names (`cygncurses-5.dll') this will often fail, unless one
4676 specifies `-L../bin -lncurses-5' to include the version. Import
4677 libs are generally not versioned, and do not have this difficulty.
4679 2. Create a symbolic link from the dll to a file in the `lib'
4680 directory according to the above mentioned search pattern. This
4681 should be used to avoid unwanted changes in the tools needed for
4684 ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
4686 Then you can link without any make environment changes.
4688 gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx
4690 This technique also avoids the version number problems, because
4691 the following is perfectly legal
4696 libxxx.dll.a -> ../bin/cygxxx-5.dll
4698 Linking directly to a dll without using an import lib will work
4699 even when auto-import features are exercised, and even when
4700 `--enable-runtime-pseudo-relocs' is used.
4702 Given the improvements in speed and memory usage, one might
4703 justifiably wonder why import libraries are used at all. There
4706 1. Until recently, the link-directly-to-dll functionality did _not_
4707 work with auto-imported data.
4709 2. Sometimes it is necessary to include pure static objects within
4710 the import library (which otherwise contains only bfd's for
4711 indirection symbols that point to the exports of a dll). Again,
4712 the import lib for the cygwin kernel makes use of this ability,
4713 and it is not possible to do this without an import lib.
4715 So, import libs are not going away. But the ability to replace
4716 true import libs with a simple symbolic link to (or a copy of) a
4717 dll, in most cases, is a useful addition to the suite of tools
4718 binutils makes available to the win32 developer. Given the
4719 massive improvements in memory requirements during linking, storage
4720 requirements, and linking speed, we expect that many developers
4721 will soon begin to use this feature whenever possible.
4725 _adding additional names_
4726 Sometimes, it is useful to export symbols with additional
4727 names. A symbol `foo' will be exported as `foo', but it can
4728 also be exported as `_foo' by using special directives in the
4729 DEF file when creating the dll. This will affect also the
4730 optional created import library. Consider the following DEF
4733 LIBRARY "xyz.dll" BASE=0x61000000
4739 The line `_foo = foo' maps the symbol `foo' to `_foo'.
4741 Another method for creating a symbol alias is to create it in
4742 the source code using the "weak" attribute:
4744 void foo () { /* Do something. */; }
4745 void _foo () __attribute__ ((weak, alias ("foo")));
4747 See the gcc manual for more information about attributes and
4751 Sometimes it is useful to rename exports. For instance, the
4752 cygwin kernel does this regularly. A symbol `_foo' can be
4753 exported as `foo' but not as `_foo' by using special
4754 directives in the DEF file. (This will also affect the import
4755 library, if it is created). In the following example:
4757 LIBRARY "xyz.dll" BASE=0x61000000
4762 The line `_foo = foo' maps the exported symbol `foo' to
4765 Note: using a DEF file disables the default auto-export behavior,
4766 unless the `--export-all-symbols' command line option is used.
4767 If, however, you are trying to rename symbols, then you should list
4768 _all_ desired exports in the DEF file, including the symbols that
4769 are not being renamed, and do _not_ use the `--export-all-symbols'
4770 option. If you list only the renamed symbols in the DEF file, and
4771 use `--export-all-symbols' to handle the other symbols, then the
4772 both the new names _and_ the original names for the renamed
4773 symbols will be exported. In effect, you'd be aliasing those
4774 symbols, not renaming them, which is probably not what you wanted.
4777 The Windows object format, PE, specifies a form of weak symbols
4778 called weak externals. When a weak symbol is linked and the
4779 symbol is not defined, the weak symbol becomes an alias for some
4780 other symbol. There are three variants of weak externals:
4781 * Definition is searched for in objects and libraries,
4782 historically called lazy externals.
4784 * Definition is searched for only in other objects, not in
4785 libraries. This form is not presently implemented.
4787 * No search; the symbol is an alias. This form is not presently
4789 As a GNU extension, weak symbols that do not specify an alternate
4790 symbol are supported. If the symbol is undefined when linking,
4791 the symbol uses a default value.
4794 File: ld.info, Node: Xtensa, Prev: WIN32, Up: Machine Dependent
4796 `ld' and Xtensa Processors
4797 ==========================
4799 The default `ld' behavior for Xtensa processors is to interpret
4800 `SECTIONS' commands so that lists of explicitly named sections in a
4801 specification with a wildcard file will be interleaved when necessary to
4802 keep literal pools within the range of PC-relative load offsets. For
4803 example, with the command:
4812 `ld' may interleave some of the `.literal' and `.text' sections from
4813 different object files to ensure that the literal pools are within the
4814 range of PC-relative load offsets. A valid interleaving might place
4815 the `.literal' sections from an initial group of files followed by the
4816 `.text' sections of that group of files. Then, the `.literal' sections
4817 from the rest of the files and the `.text' sections from the rest of
4818 the files would follow.
4820 Relaxation is enabled by default for the Xtensa version of `ld' and
4821 provides two important link-time optimizations. The first optimization
4822 is to combine identical literal values to reduce code size. A redundant
4823 literal will be removed and all the `L32R' instructions that use it
4824 will be changed to reference an identical literal, as long as the
4825 location of the replacement literal is within the offset range of all
4826 the `L32R' instructions. The second optimization is to remove
4827 unnecessary overhead from assembler-generated "longcall" sequences of
4828 `L32R'/`CALLXN' when the target functions are within range of direct
4829 `CALLN' instructions.
4831 For each of these cases where an indirect call sequence can be
4832 optimized to a direct call, the linker will change the `CALLXN'
4833 instruction to a `CALLN' instruction, remove the `L32R' instruction,
4834 and remove the literal referenced by the `L32R' instruction if it is
4835 not used for anything else. Removing the `L32R' instruction always
4836 reduces code size but can potentially hurt performance by changing the
4837 alignment of subsequent branch targets. By default, the linker will
4838 always preserve alignments, either by switching some instructions
4839 between 24-bit encodings and the equivalent density instructions or by
4840 inserting a no-op in place of the `L32R' instruction that was removed.
4841 If code size is more important than performance, the `--size-opt'
4842 option can be used to prevent the linker from widening density
4843 instructions or inserting no-ops, except in a few cases where no-ops
4844 are required for correctness.
4846 The following Xtensa-specific command-line options can be used to
4850 Since the Xtensa version of `ld' enables the `--relax' option by
4851 default, the `--no-relax' option is provided to disable relaxation.
4854 When optimizing indirect calls to direct calls, optimize for code
4855 size more than performance. With this option, the linker will not
4856 insert no-ops or widen density instructions to preserve branch
4857 target alignment. There may still be some cases where no-ops are
4858 required to preserve the correctness of the code.
4861 File: ld.info, Node: BFD, Next: Reporting Bugs, Prev: Machine Dependent, Up: Top
4866 The linker accesses object and archive files using the BFD libraries.
4867 These libraries allow the linker to use the same routines to operate on
4868 object files whatever the object file format. A different object file
4869 format can be supported simply by creating a new BFD back end and adding
4870 it to the library. To conserve runtime memory, however, the linker and
4871 associated tools are usually configured to support only a subset of the
4872 object file formats available. You can use `objdump -i' (*note
4873 objdump: (binutils.info)objdump.) to list all the formats available for
4876 As with most implementations, BFD is a compromise between several
4877 conflicting requirements. The major factor influencing BFD design was
4878 efficiency: any time used converting between formats is time which
4879 would not have been spent had BFD not been involved. This is partly
4880 offset by abstraction payback; since BFD simplifies applications and
4881 back ends, more time and care may be spent optimizing algorithms for a
4884 One minor artifact of the BFD solution which you should bear in mind
4885 is the potential for information loss. There are two places where
4886 useful information can be lost using the BFD mechanism: during
4887 conversion and during output. *Note BFD information loss::.
4891 * BFD outline:: How it works: an outline of BFD
4894 File: ld.info, Node: BFD outline, Up: BFD
4896 How It Works: An Outline of BFD
4897 ===============================
4899 When an object file is opened, BFD subroutines automatically
4900 determine the format of the input object file. They then build a
4901 descriptor in memory with pointers to routines that will be used to
4902 access elements of the object file's data structures.
4904 As different information from the object files is required, BFD
4905 reads from different sections of the file and processes them. For
4906 example, a very common operation for the linker is processing symbol
4907 tables. Each BFD back end provides a routine for converting between
4908 the object file's representation of symbols and an internal canonical
4909 format. When the linker asks for the symbol table of an object file, it
4910 calls through a memory pointer to the routine from the relevant BFD
4911 back end which reads and converts the table into a canonical form. The
4912 linker then operates upon the canonical form. When the link is finished
4913 and the linker writes the output file's symbol table, another BFD back
4914 end routine is called to take the newly created symbol table and
4915 convert it into the chosen output format.
4919 * BFD information loss:: Information Loss
4920 * Canonical format:: The BFD canonical object-file format
4923 File: ld.info, Node: BFD information loss, Next: Canonical format, Up: BFD outline
4928 _Information can be lost during output._ The output formats
4929 supported by BFD do not provide identical facilities, and information
4930 which can be described in one form has nowhere to go in another format.
4931 One example of this is alignment information in `b.out'. There is
4932 nowhere in an `a.out' format file to store alignment information on the
4933 contained data, so when a file is linked from `b.out' and an `a.out'
4934 image is produced, alignment information will not propagate to the
4935 output file. (The linker will still use the alignment information
4936 internally, so the link is performed correctly).
4938 Another example is COFF section names. COFF files may contain an
4939 unlimited number of sections, each one with a textual section name. If
4940 the target of the link is a format which does not have many sections
4941 (e.g., `a.out') or has sections without names (e.g., the Oasys format),
4942 the link cannot be done simply. You can circumvent this problem by
4943 describing the desired input-to-output section mapping with the linker
4946 _Information can be lost during canonicalization._ The BFD internal
4947 canonical form of the external formats is not exhaustive; there are
4948 structures in input formats for which there is no direct representation
4949 internally. This means that the BFD back ends cannot maintain all
4950 possible data richness through the transformation between external to
4951 internal and back to external formats.
4953 This limitation is only a problem when an application reads one
4954 format and writes another. Each BFD back end is responsible for
4955 maintaining as much data as possible, and the internal BFD canonical
4956 form has structures which are opaque to the BFD core, and exported only
4957 to the back ends. When a file is read in one format, the canonical form
4958 is generated for BFD and the application. At the same time, the back
4959 end saves away any information which may otherwise be lost. If the data
4960 is then written back in the same format, the back end routine will be
4961 able to use the canonical form provided by the BFD core as well as the
4962 information it prepared earlier. Since there is a great deal of
4963 commonality between back ends, there is no information lost when
4964 linking or copying big endian COFF to little endian COFF, or `a.out' to
4965 `b.out'. When a mixture of formats is linked, the information is only
4966 lost from the files whose format differs from the destination.
4969 File: ld.info, Node: Canonical format, Prev: BFD information loss, Up: BFD outline
4971 The BFD canonical object-file format
4972 ------------------------------------
4974 The greatest potential for loss of information occurs when there is
4975 the least overlap between the information provided by the source
4976 format, that stored by the canonical format, and that needed by the
4977 destination format. A brief description of the canonical form may help
4978 you understand which kinds of data you can count on preserving across
4982 Information stored on a per-file basis includes target machine
4983 architecture, particular implementation format type, a demand
4984 pageable bit, and a write protected bit. Information like Unix
4985 magic numbers is not stored here--only the magic numbers' meaning,
4986 so a `ZMAGIC' file would have both the demand pageable bit and the
4987 write protected text bit set. The byte order of the target is
4988 stored on a per-file basis, so that big- and little-endian object
4989 files may be used with one another.
4992 Each section in the input file contains the name of the section,
4993 the section's original address in the object file, size and
4994 alignment information, various flags, and pointers into other BFD
4998 Each symbol contains a pointer to the information for the object
4999 file which originally defined it, its name, its value, and various
5000 flag bits. When a BFD back end reads in a symbol table, it
5001 relocates all symbols to make them relative to the base of the
5002 section where they were defined. Doing this ensures that each
5003 symbol points to its containing section. Each symbol also has a
5004 varying amount of hidden private data for the BFD back end. Since
5005 the symbol points to the original file, the private data format
5006 for that symbol is accessible. `ld' can operate on a collection
5007 of symbols of wildly different formats without problems.
5009 Normal global and simple local symbols are maintained on output,
5010 so an output file (no matter its format) will retain symbols
5011 pointing to functions and to global, static, and common variables.
5012 Some symbol information is not worth retaining; in `a.out', type
5013 information is stored in the symbol table as long symbol names.
5014 This information would be useless to most COFF debuggers; the
5015 linker has command line switches to allow users to throw it away.
5017 There is one word of type information within the symbol, so if the
5018 format supports symbol type information within symbols (for
5019 example, COFF, IEEE, Oasys) and the type is simple enough to fit
5020 within one word (nearly everything but aggregates), the
5021 information will be preserved.
5024 Each canonical BFD relocation record contains a pointer to the
5025 symbol to relocate to, the offset of the data to relocate, the
5026 section the data is in, and a pointer to a relocation type
5027 descriptor. Relocation is performed by passing messages through
5028 the relocation type descriptor and the symbol pointer. Therefore,
5029 relocations can be performed on output data using a relocation
5030 method that is only available in one of the input formats. For
5031 instance, Oasys provides a byte relocation format. A relocation
5032 record requesting this relocation type would point indirectly to a
5033 routine to perform this, so the relocation may be performed on a
5034 byte being written to a 68k COFF file, even though 68k COFF has no
5035 such relocation type.
5038 Object formats can contain, for debugging purposes, some form of
5039 mapping between symbols, source line numbers, and addresses in the
5040 output file. These addresses have to be relocated along with the
5041 symbol information. Each symbol with an associated list of line
5042 number records points to the first record of the list. The head
5043 of a line number list consists of a pointer to the symbol, which
5044 allows finding out the address of the function whose line number
5045 is being described. The rest of the list is made up of pairs:
5046 offsets into the section and line numbers. Any format which can
5047 simply derive this information can pass it successfully between
5048 formats (COFF, IEEE and Oasys).
5051 File: ld.info, Node: Reporting Bugs, Next: MRI, Prev: BFD, Up: Top
5056 Your bug reports play an essential role in making `ld' reliable.
5058 Reporting a bug may help you by bringing a solution to your problem,
5059 or it may not. But in any case the principal function of a bug report
5060 is to help the entire community by making the next version of `ld' work
5061 better. Bug reports are your contribution to the maintenance of `ld'.
5063 In order for a bug report to serve its purpose, you must include the
5064 information that enables us to fix the bug.
5068 * Bug Criteria:: Have you found a bug?
5069 * Bug Reporting:: How to report bugs
5072 File: ld.info, Node: Bug Criteria, Next: Bug Reporting, Up: Reporting Bugs
5074 Have You Found a Bug?
5075 =====================
5077 If you are not sure whether you have found a bug, here are some
5080 * If the linker gets a fatal signal, for any input whatever, that is
5081 a `ld' bug. Reliable linkers never crash.
5083 * If `ld' produces an error message for valid input, that is a bug.
5085 * If `ld' does not produce an error message for invalid input, that
5086 may be a bug. In the general case, the linker can not verify that
5087 object files are correct.
5089 * If you are an experienced user of linkers, your suggestions for
5090 improvement of `ld' are welcome in any case.
5093 File: ld.info, Node: Bug Reporting, Prev: Bug Criteria, Up: Reporting Bugs
5098 A number of companies and individuals offer support for GNU
5099 products. If you obtained `ld' from a support organization, we
5100 recommend you contact that organization first.
5102 You can find contact information for many support companies and
5103 individuals in the file `etc/SERVICE' in the GNU Emacs distribution.
5105 Otherwise, send bug reports for `ld' to `bug-binutils@gnu.org'.
5107 The fundamental principle of reporting bugs usefully is this:
5108 *report all the facts*. If you are not sure whether to state a fact or
5109 leave it out, state it!
5111 Often people omit facts because they think they know what causes the
5112 problem and assume that some details do not matter. Thus, you might
5113 assume that the name of a symbol you use in an example does not matter.
5114 Well, probably it does not, but one cannot be sure. Perhaps the bug
5115 is a stray memory reference which happens to fetch from the location
5116 where that name is stored in memory; perhaps, if the name were
5117 different, the contents of that location would fool the linker into
5118 doing the right thing despite the bug. Play it safe and give a
5119 specific, complete example. That is the easiest thing for you to do,
5120 and the most helpful.
5122 Keep in mind that the purpose of a bug report is to enable us to fix
5123 the bug if it is new to us. Therefore, always write your bug reports
5124 on the assumption that the bug has not been reported previously.
5126 Sometimes people give a few sketchy facts and ask, "Does this ring a
5127 bell?" This cannot help us fix a bug, so it is basically useless. We
5128 respond by asking for enough details to enable us to investigate. You
5129 might as well expedite matters by sending them to begin with.
5131 To enable us to fix the bug, you should include all these things:
5133 * The version of `ld'. `ld' announces it if you start it with the
5134 `--version' argument.
5136 Without this, we will not know whether there is any point in
5137 looking for the bug in the current version of `ld'.
5139 * Any patches you may have applied to the `ld' source, including any
5140 patches made to the `BFD' library.
5142 * The type of machine you are using, and the operating system name
5145 * What compiler (and its version) was used to compile `ld'--e.g.
5148 * The command arguments you gave the linker to link your example and
5149 observe the bug. To guarantee you will not omit something
5150 important, list them all. A copy of the Makefile (or the output
5151 from make) is sufficient.
5153 If we were to try to guess the arguments, we would probably guess
5154 wrong and then we might not encounter the bug.
5156 * A complete input file, or set of input files, that will reproduce
5157 the bug. It is generally most helpful to send the actual object
5158 files provided that they are reasonably small. Say no more than
5159 10K. For bigger files you can either make them available by FTP
5160 or HTTP or else state that you are willing to send the object
5161 file(s) to whomever requests them. (Note - your email will be
5162 going to a mailing list, so we do not want to clog it up with
5163 large attachments). But small attachments are best.
5165 If the source files were assembled using `gas' or compiled using
5166 `gcc', then it may be OK to send the source files rather than the
5167 object files. In this case, be sure to say exactly what version of
5168 `gas' or `gcc' was used to produce the object files. Also say how
5169 `gas' or `gcc' were configured.
5171 * A description of what behavior you observe that you believe is
5172 incorrect. For example, "It gets a fatal signal."
5174 Of course, if the bug is that `ld' gets a fatal signal, then we
5175 will certainly notice it. But if the bug is incorrect output, we
5176 might not notice unless it is glaringly wrong. You might as well
5177 not give us a chance to make a mistake.
5179 Even if the problem you experience is a fatal signal, you should
5180 still say so explicitly. Suppose something strange is going on,
5181 such as, your copy of `ld' is out of synch, or you have
5182 encountered a bug in the C library on your system. (This has
5183 happened!) Your copy might crash and ours would not. If you told
5184 us to expect a crash, then when ours fails to crash, we would know
5185 that the bug was not happening for us. If you had not told us to
5186 expect a crash, then we would not be able to draw any conclusion
5187 from our observations.
5189 * If you wish to suggest changes to the `ld' source, send us context
5190 diffs, as generated by `diff' with the `-u', `-c', or `-p' option.
5191 Always send diffs from the old file to the new file. If you even
5192 discuss something in the `ld' source, refer to it by context, not
5195 The line numbers in our development sources will not match those
5196 in your sources. Your line numbers would convey no useful
5199 Here are some things that are not necessary:
5201 * A description of the envelope of the bug.
5203 Often people who encounter a bug spend a lot of time investigating
5204 which changes to the input file will make the bug go away and which
5205 changes will not affect it.
5207 This is often time consuming and not very useful, because the way
5208 we will find the bug is by running a single example under the
5209 debugger with breakpoints, not by pure deduction from a series of
5210 examples. We recommend that you save your time for something else.
5212 Of course, if you can find a simpler example to report _instead_
5213 of the original one, that is a convenience for us. Errors in the
5214 output will be easier to spot, running under the debugger will take
5215 less time, and so on.
5217 However, simplification is not vital; if you do not want to do
5218 this, report the bug anyway and send us the entire test case you
5221 * A patch for the bug.
5223 A patch for the bug does help us if it is a good one. But do not
5224 omit the necessary information, such as the test case, on the
5225 assumption that a patch is all we need. We might see problems
5226 with your patch and decide to fix the problem another way, or we
5227 might not understand it at all.
5229 Sometimes with a program as complicated as `ld' it is very hard to
5230 construct an example that will make the program follow a certain
5231 path through the code. If you do not send us the example, we will
5232 not be able to construct one, so we will not be able to verify
5233 that the bug is fixed.
5235 And if we cannot understand what bug you are trying to fix, or why
5236 your patch should be an improvement, we will not install it. A
5237 test case will help us to understand.
5239 * A guess about what the bug is or what it depends on.
5241 Such guesses are usually wrong. Even we cannot guess right about
5242 such things without first using the debugger to find the facts.
5245 File: ld.info, Node: MRI, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
5247 MRI Compatible Script Files
5248 ***************************
5250 To aid users making the transition to GNU `ld' from the MRI linker,
5251 `ld' can use MRI compatible linker scripts as an alternative to the
5252 more general-purpose linker scripting language described in *Note
5253 Scripts::. MRI compatible linker scripts have a much simpler command
5254 set than the scripting language otherwise used with `ld'. GNU `ld'
5255 supports the most commonly used MRI linker commands; these commands are
5258 In general, MRI scripts aren't of much use with the `a.out' object
5259 file format, since it only has three sections and MRI scripts lack some
5260 features to make use of them.
5262 You can specify a file containing an MRI-compatible script using the
5263 `-c' command-line option.
5265 Each command in an MRI-compatible script occupies its own line; each
5266 command line starts with the keyword that identifies the command (though
5267 blank lines are also allowed for punctuation). If a line of an
5268 MRI-compatible script begins with an unrecognized keyword, `ld' issues
5269 a warning message, but continues processing the script.
5271 Lines beginning with `*' are comments.
5273 You can write these commands using all upper-case letters, or all
5274 lower case; for example, `chip' is the same as `CHIP'. The following
5275 list shows only the upper-case form of each command.
5278 `ABSOLUTE SECNAME, SECNAME, ... SECNAME'
5279 Normally, `ld' includes in the output file all sections from all
5280 the input files. However, in an MRI-compatible script, you can
5281 use the `ABSOLUTE' command to restrict the sections that will be
5282 present in your output program. If the `ABSOLUTE' command is used
5283 at all in a script, then only the sections named explicitly in
5284 `ABSOLUTE' commands will appear in the linker output. You can
5285 still use other input sections (whatever you select on the command
5286 line, or using `LOAD') to resolve addresses in the output file.
5288 `ALIAS OUT-SECNAME, IN-SECNAME'
5289 Use this command to place the data from input section IN-SECNAME
5290 in a section called OUT-SECNAME in the linker output file.
5292 IN-SECNAME may be an integer.
5294 `ALIGN SECNAME = EXPRESSION'
5295 Align the section called SECNAME to EXPRESSION. The EXPRESSION
5296 should be a power of two.
5299 Use the value of EXPRESSION as the lowest address (other than
5300 absolute addresses) in the output file.
5303 `CHIP EXPRESSION, EXPRESSION'
5304 This command does nothing; it is accepted only for compatibility.
5307 This command does nothing whatever; it's only accepted for
5310 `FORMAT OUTPUT-FORMAT'
5311 Similar to the `OUTPUT_FORMAT' command in the more general linker
5312 language, but restricted to one of these output formats:
5314 1. S-records, if OUTPUT-FORMAT is `S'
5316 2. IEEE, if OUTPUT-FORMAT is `IEEE'
5318 3. COFF (the `coff-m68k' variant in BFD), if OUTPUT-FORMAT is
5322 Print (to the standard output file) a link map, as produced by the
5323 `ld' command-line option `-M'.
5325 The keyword `LIST' may be followed by anything on the same line,
5326 with no change in its effect.
5329 `LOAD FILENAME, FILENAME, ... FILENAME'
5330 Include one or more object file FILENAME in the link; this has the
5331 same effect as specifying FILENAME directly on the `ld' command
5335 OUTPUT-NAME is the name for the program produced by `ld'; the
5336 MRI-compatible command `NAME' is equivalent to the command-line
5337 option `-o' or the general script language command `OUTPUT'.
5339 `ORDER SECNAME, SECNAME, ... SECNAME'
5340 `ORDER SECNAME SECNAME SECNAME'
5341 Normally, `ld' orders the sections in its output file in the order
5342 in which they first appear in the input files. In an
5343 MRI-compatible script, you can override this ordering with the
5344 `ORDER' command. The sections you list with `ORDER' will appear
5345 first in your output file, in the order specified.
5347 `PUBLIC NAME=EXPRESSION'
5348 `PUBLIC NAME,EXPRESSION'
5349 `PUBLIC NAME EXPRESSION'
5350 Supply a value (EXPRESSION) for external symbol NAME used in the
5353 `SECT SECNAME, EXPRESSION'
5354 `SECT SECNAME=EXPRESSION'
5355 `SECT SECNAME EXPRESSION'
5356 You can use any of these three forms of the `SECT' command to
5357 specify the start address (EXPRESSION) for section SECNAME. If
5358 you have more than one `SECT' statement for the same SECNAME, only
5359 the _first_ sets the start address.
5362 File: ld.info, Node: GNU Free Documentation License, Next: Index, Prev: MRI, Up: Top
5364 GNU Free Documentation License
5365 ******************************
5367 Version 1.1, March 2000
5368 Copyright (C) 2000, 2003 Free Software Foundation, Inc.
5369 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5371 Everyone is permitted to copy and distribute verbatim copies
5372 of this license document, but changing it is not allowed.
5377 The purpose of this License is to make a manual, textbook, or other
5378 written document "free" in the sense of freedom: to assure everyone
5379 the effective freedom to copy and redistribute it, with or without
5380 modifying it, either commercially or noncommercially. Secondarily,
5381 this License preserves for the author and publisher a way to get
5382 credit for their work, while not being considered responsible for
5383 modifications made by others.
5385 This License is a kind of "copyleft", which means that derivative
5386 works of the document must themselves be free in the same sense.
5387 It complements the GNU General Public License, which is a copyleft
5388 license designed for free software.
5390 We have designed this License in order to use it for manuals for
5391 free software, because free software needs free documentation: a
5392 free program should come with manuals providing the same freedoms
5393 that the software does. But this License is not limited to
5394 software manuals; it can be used for any textual work, regardless
5395 of subject matter or whether it is published as a printed book.
5396 We recommend this License principally for works whose purpose is
5397 instruction or reference.
5400 1. APPLICABILITY AND DEFINITIONS
5402 This License applies to any manual or other work that contains a
5403 notice placed by the copyright holder saying it can be distributed
5404 under the terms of this License. The "Document", below, refers to
5405 any such manual or work. Any member of the public is a licensee,
5406 and is addressed as "you."
5408 A "Modified Version" of the Document means any work containing the
5409 Document or a portion of it, either copied verbatim, or with
5410 modifications and/or translated into another language.
5412 A "Secondary Section" is a named appendix or a front-matter
5413 section of the Document that deals exclusively with the
5414 relationship of the publishers or authors of the Document to the
5415 Document's overall subject (or to related matters) and contains
5416 nothing that could fall directly within that overall subject.
5417 (For example, if the Document is in part a textbook of
5418 mathematics, a Secondary Section may not explain any mathematics.)
5419 The relationship could be a matter of historical connection with
5420 the subject or with related matters, or of legal, commercial,
5421 philosophical, ethical or political position regarding them.
5423 The "Invariant Sections" are certain Secondary Sections whose
5424 titles are designated, as being those of Invariant Sections, in
5425 the notice that says that the Document is released under this
5428 The "Cover Texts" are certain short passages of text that are
5429 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
5430 that says that the Document is released under this License.
5432 A "Transparent" copy of the Document means a machine-readable copy,
5433 represented in a format whose specification is available to the
5434 general public, whose contents can be viewed and edited directly
5435 and straightforwardly with generic text editors or (for images
5436 composed of pixels) generic paint programs or (for drawings) some
5437 widely available drawing editor, and that is suitable for input to
5438 text formatters or for automatic translation to a variety of
5439 formats suitable for input to text formatters. A copy made in an
5440 otherwise Transparent file format whose markup has been designed
5441 to thwart or discourage subsequent modification by readers is not
5442 Transparent. A copy that is not "Transparent" is called "Opaque."
5444 Examples of suitable formats for Transparent copies include plain
5445 ASCII without markup, Texinfo input format, LaTeX input format,
5446 SGML or XML using a publicly available DTD, and
5447 standard-conforming simple HTML designed for human modification.
5448 Opaque formats include PostScript, PDF, proprietary formats that
5449 can be read and edited only by proprietary word processors, SGML
5450 or XML for which the DTD and/or processing tools are not generally
5451 available, and the machine-generated HTML produced by some word
5452 processors for output purposes only.
5454 The "Title Page" means, for a printed book, the title page itself,
5455 plus such following pages as are needed to hold, legibly, the
5456 material this License requires to appear in the title page. For
5457 works in formats which do not have any title page as such, "Title
5458 Page" means the text near the most prominent appearance of the
5459 work's title, preceding the beginning of the body of the text.
5463 You may copy and distribute the Document in any medium, either
5464 commercially or noncommercially, provided that this License, the
5465 copyright notices, and the license notice saying this License
5466 applies to the Document are reproduced in all copies, and that you
5467 add no other conditions whatsoever to those of this License. You
5468 may not use technical measures to obstruct or control the reading
5469 or further copying of the copies you make or distribute. However,
5470 you may accept compensation in exchange for copies. If you
5471 distribute a large enough number of copies you must also follow
5472 the conditions in section 3.
5474 You may also lend copies, under the same conditions stated above,
5475 and you may publicly display copies.
5477 3. COPYING IN QUANTITY
5479 If you publish printed copies of the Document numbering more than
5480 100, and the Document's license notice requires Cover Texts, you
5481 must enclose the copies in covers that carry, clearly and legibly,
5482 all these Cover Texts: Front-Cover Texts on the front cover, and
5483 Back-Cover Texts on the back cover. Both covers must also clearly
5484 and legibly identify you as the publisher of these copies. The
5485 front cover must present the full title with all words of the
5486 title equally prominent and visible. You may add other material
5487 on the covers in addition. Copying with changes limited to the
5488 covers, as long as they preserve the title of the Document and
5489 satisfy these conditions, can be treated as verbatim copying in
5492 If the required texts for either cover are too voluminous to fit
5493 legibly, you should put the first ones listed (as many as fit
5494 reasonably) on the actual cover, and continue the rest onto
5497 If you publish or distribute Opaque copies of the Document
5498 numbering more than 100, you must either include a
5499 machine-readable Transparent copy along with each Opaque copy, or
5500 state in or with each Opaque copy a publicly-accessible
5501 computer-network location containing a complete Transparent copy
5502 of the Document, free of added material, which the general
5503 network-using public has access to download anonymously at no
5504 charge using public-standard network protocols. If you use the
5505 latter option, you must take reasonably prudent steps, when you
5506 begin distribution of Opaque copies in quantity, to ensure that
5507 this Transparent copy will remain thus accessible at the stated
5508 location until at least one year after the last time you
5509 distribute an Opaque copy (directly or through your agents or
5510 retailers) of that edition to the public.
5512 It is requested, but not required, that you contact the authors of
5513 the Document well before redistributing any large number of
5514 copies, to give them a chance to provide you with an updated
5515 version of the Document.
5519 You may copy and distribute a Modified Version of the Document
5520 under the conditions of sections 2 and 3 above, provided that you
5521 release the Modified Version under precisely this License, with
5522 the Modified Version filling the role of the Document, thus
5523 licensing distribution and modification of the Modified Version to
5524 whoever possesses a copy of it. In addition, you must do these
5525 things in the Modified Version:
5527 A. Use in the Title Page (and on the covers, if any) a title
5528 distinct from that of the Document, and from those of previous
5529 versions (which should, if there were any, be listed in the
5530 History section of the Document). You may use the same title
5531 as a previous version if the original publisher of that version
5533 B. List on the Title Page, as authors, one or more persons or
5534 entities responsible for authorship of the modifications in the
5535 Modified Version, together with at least five of the principal
5536 authors of the Document (all of its principal authors, if it
5537 has less than five).
5538 C. State on the Title page the name of the publisher of the
5539 Modified Version, as the publisher.
5540 D. Preserve all the copyright notices of the Document.
5541 E. Add an appropriate copyright notice for your modifications
5542 adjacent to the other copyright notices.
5543 F. Include, immediately after the copyright notices, a license
5544 notice giving the public permission to use the Modified Version
5545 under the terms of this License, in the form shown in the
5547 G. Preserve in that license notice the full lists of Invariant
5548 Sections and required Cover Texts given in the Document's
5550 H. Include an unaltered copy of this License.
5551 I. Preserve the section entitled "History", and its title, and add
5552 to it an item stating at least the title, year, new authors, and
5553 publisher of the Modified Version as given on the Title Page.
5554 If there is no section entitled "History" in the Document,
5555 create one stating the title, year, authors, and publisher of
5556 the Document as given on its Title Page, then add an item
5557 describing the Modified Version as stated in the previous
5559 J. Preserve the network location, if any, given in the Document for
5560 public access to a Transparent copy of the Document, and
5561 likewise the network locations given in the Document for
5562 previous versions it was based on. These may be placed in the
5563 "History" section. You may omit a network location for a work
5564 that was published at least four years before the Document
5565 itself, or if the original publisher of the version it refers
5566 to gives permission.
5567 K. In any section entitled "Acknowledgements" or "Dedications",
5568 preserve the section's title, and preserve in the section all the
5569 substance and tone of each of the contributor acknowledgements
5570 and/or dedications given therein.
5571 L. Preserve all the Invariant Sections of the Document,
5572 unaltered in their text and in their titles. Section numbers
5573 or the equivalent are not considered part of the section titles.
5574 M. Delete any section entitled "Endorsements." Such a section
5575 may not be included in the Modified Version.
5576 N. Do not retitle any existing section as "Endorsements" or to
5577 conflict in title with any Invariant Section.
5579 If the Modified Version includes new front-matter sections or
5580 appendices that qualify as Secondary Sections and contain no
5581 material copied from the Document, you may at your option
5582 designate some or all of these sections as invariant. To do this,
5583 add their titles to the list of Invariant Sections in the Modified
5584 Version's license notice. These titles must be distinct from any
5585 other section titles.
5587 You may add a section entitled "Endorsements", provided it contains
5588 nothing but endorsements of your Modified Version by various
5589 parties-for example, statements of peer review or that the text has
5590 been approved by an organization as the authoritative definition
5593 You may add a passage of up to five words as a Front-Cover Text,
5594 and a passage of up to 25 words as a Back-Cover Text, to the end
5595 of the list of Cover Texts in the Modified Version. Only one
5596 passage of Front-Cover Text and one of Back-Cover Text may be
5597 added by (or through arrangements made by) any one entity. If the
5598 Document already includes a cover text for the same cover,
5599 previously added by you or by arrangement made by the same entity
5600 you are acting on behalf of, you may not add another; but you may
5601 replace the old one, on explicit permission from the previous
5602 publisher that added the old one.
5604 The author(s) and publisher(s) of the Document do not by this
5605 License give permission to use their names for publicity for or to
5606 assert or imply endorsement of any Modified Version.
5608 5. COMBINING DOCUMENTS
5610 You may combine the Document with other documents released under
5611 this License, under the terms defined in section 4 above for
5612 modified versions, provided that you include in the combination
5613 all of the Invariant Sections of all of the original documents,
5614 unmodified, and list them all as Invariant Sections of your
5615 combined work in its license notice.
5617 The combined work need only contain one copy of this License, and
5618 multiple identical Invariant Sections may be replaced with a single
5619 copy. If there are multiple Invariant Sections with the same name
5620 but different contents, make the title of each such section unique
5621 by adding at the end of it, in parentheses, the name of the
5622 original author or publisher of that section if known, or else a
5623 unique number. Make the same adjustment to the section titles in
5624 the list of Invariant Sections in the license notice of the
5627 In the combination, you must combine any sections entitled
5628 "History" in the various original documents, forming one section
5629 entitled "History"; likewise combine any sections entitled
5630 "Acknowledgements", and any sections entitled "Dedications." You
5631 must delete all sections entitled "Endorsements."
5633 6. COLLECTIONS OF DOCUMENTS
5635 You may make a collection consisting of the Document and other
5636 documents released under this License, and replace the individual
5637 copies of this License in the various documents with a single copy
5638 that is included in the collection, provided that you follow the
5639 rules of this License for verbatim copying of each of the
5640 documents in all other respects.
5642 You may extract a single document from such a collection, and
5643 distribute it individually under this License, provided you insert
5644 a copy of this License into the extracted document, and follow
5645 this License in all other respects regarding verbatim copying of
5648 7. AGGREGATION WITH INDEPENDENT WORKS
5650 A compilation of the Document or its derivatives with other
5651 separate and independent documents or works, in or on a volume of
5652 a storage or distribution medium, does not as a whole count as a
5653 Modified Version of the Document, provided no compilation
5654 copyright is claimed for the compilation. Such a compilation is
5655 called an "aggregate", and this License does not apply to the
5656 other self-contained works thus compiled with the Document, on
5657 account of their being thus compiled, if they are not themselves
5658 derivative works of the Document.
5660 If the Cover Text requirement of section 3 is applicable to these
5661 copies of the Document, then if the Document is less than one
5662 quarter of the entire aggregate, the Document's Cover Texts may be
5663 placed on covers that surround only the Document within the
5664 aggregate. Otherwise they must appear on covers around the whole
5669 Translation is considered a kind of modification, so you may
5670 distribute translations of the Document under the terms of section
5671 4. Replacing Invariant Sections with translations requires special
5672 permission from their copyright holders, but you may include
5673 translations of some or all Invariant Sections in addition to the
5674 original versions of these Invariant Sections. You may include a
5675 translation of this License provided that you also include the
5676 original English version of this License. In case of a
5677 disagreement between the translation and the original English
5678 version of this License, the original English version will prevail.
5682 You may not copy, modify, sublicense, or distribute the Document
5683 except as expressly provided for under this License. Any other
5684 attempt to copy, modify, sublicense or distribute the Document is
5685 void, and will automatically terminate your rights under this
5686 License. However, parties who have received copies, or rights,
5687 from you under this License will not have their licenses
5688 terminated so long as such parties remain in full compliance.
5690 10. FUTURE REVISIONS OF THIS LICENSE
5692 The Free Software Foundation may publish new, revised versions of
5693 the GNU Free Documentation License from time to time. Such new
5694 versions will be similar in spirit to the present version, but may
5695 differ in detail to address new problems or concerns. See
5696 http://www.gnu.org/copyleft/.
5698 Each version of the License is given a distinguishing version
5699 number. If the Document specifies that a particular numbered
5700 version of this License "or any later version" applies to it, you
5701 have the option of following the terms and conditions either of
5702 that specified version or of any later version that has been
5703 published (not as a draft) by the Free Software Foundation. If
5704 the Document does not specify a version number of this License,
5705 you may choose any version ever published (not as a draft) by the
5706 Free Software Foundation.
5709 ADDENDUM: How to use this License for your documents
5710 ====================================================
5712 To use this License in a document you have written, include a copy of
5713 the License in the document and put the following copyright and license
5714 notices just after the title page:
5716 Copyright (C) YEAR YOUR NAME.
5717 Permission is granted to copy, distribute and/or modify this document
5718 under the terms of the GNU Free Documentation License, Version 1.1
5719 or any later version published by the Free Software Foundation;
5720 with the Invariant Sections being LIST THEIR TITLES, with the
5721 Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
5722 A copy of the license is included in the section entitled "GNU
5723 Free Documentation License."
5725 If you have no Invariant Sections, write "with no Invariant Sections"
5726 instead of saying which ones are invariant. If you have no Front-Cover
5727 Texts, write "no Front-Cover Texts" instead of "Front-Cover Texts being
5728 LIST"; likewise for Back-Cover Texts.
5730 If your document contains nontrivial examples of program code, we
5731 recommend releasing these examples in parallel under your choice of
5732 free software license, such as the GNU General Public License, to
5733 permit their use in free software.
5736 File: ld.info, Node: Index, Prev: GNU Free Documentation License, Up: Top
5745 * --accept-unknown-input-arch: Options.
5746 * --add-needed: Options.
5747 * --add-stdcall-alias: Options.
5748 * --allow-multiple-definition: Options.
5749 * --allow-shlib-undefined: Options.
5750 * --architecture=ARCH: Options.
5751 * --as-needed: Options.
5752 * --auxiliary: Options.
5753 * --base-file: Options.
5755 * --check-sections: Options.
5757 * --default-imported-symver: Options.
5758 * --default-symver: Options.
5759 * --defsym SYMBOL=EXP: Options.
5760 * --demangle[=STYLE]: Options.
5761 * --disable-auto-image-base: Options.
5762 * --disable-auto-import: Options.
5763 * --disable-new-dtags: Options.
5764 * --disable-runtime-pseudo-reloc: Options.
5765 * --disable-stdcall-fixup: Options.
5766 * --discard-all: Options.
5767 * --discard-locals: Options.
5769 * --dll-search-prefix: Options.
5770 * --dynamic-linker FILE: Options.
5771 * --eh-frame-hdr: Options.
5772 * --emit-relocs: Options.
5773 * --enable-auto-image-base: Options.
5774 * --enable-auto-import: Options.
5775 * --enable-extra-pe-debug: Options.
5776 * --enable-new-dtags: Options.
5777 * --enable-runtime-pseudo-reloc: Options.
5778 * --enable-stdcall-fixup: Options.
5779 * --entry=ENTRY: Options.
5780 * --error-unresolved-symbols: Options.
5781 * --exclude-libs: Options.
5782 * --exclude-symbols: Options.
5783 * --export-all-symbols: Options.
5784 * --export-dynamic: Options.
5785 * --fatal-warnings: Options.
5786 * --file-alignment: Options.
5787 * --filter: Options.
5789 * --force-exe-suffix: Options.
5790 * --format=FORMAT: Options.
5791 * --format=VERSION: TI COFF.
5792 * --gc-sections: Options.
5793 * --gpsize: Options.
5794 * --hash-size=NUMBER: Options.
5797 * --image-base: Options.
5798 * --just-symbols=FILE: Options.
5799 * --kill-at: Options.
5800 * --large-address-aware: Options.
5801 * --library-path=DIR: Options.
5802 * --library=ARCHIVE: Options.
5803 * --major-image-version: Options.
5804 * --major-os-version: Options.
5805 * --major-subsystem-version: Options.
5806 * --minor-image-version: Options.
5807 * --minor-os-version: Options.
5808 * --minor-subsystem-version: Options.
5809 * --mri-script=MRI-CMDFILE: Options.
5810 * --multi-subspace: HPPA ELF32.
5811 * --nmagic: Options.
5812 * --no-accept-unknown-input-arch: Options.
5813 * --no-add-needed: Options.
5814 * --no-allow-shlib-undefined: Options.
5815 * --no-as-needed: Options.
5816 * --no-check-sections: Options.
5817 * --no-define-common: Options.
5818 * --no-demangle: Options.
5819 * --no-gc-sections: Options.
5820 * --no-keep-memory: Options.
5821 * --no-omagic: Options.
5822 * --no-relax: Xtensa.
5823 * --no-undefined: Options.
5824 * --no-undefined-version: Options.
5825 * --no-warn-mismatch: Options.
5826 * --no-whole-archive: Options.
5827 * --noinhibit-exec: Options.
5828 * --oformat: Options.
5829 * --omagic: Options.
5830 * --out-implib: Options.
5831 * --output-def: Options.
5832 * --output=OUTPUT: Options.
5833 * --pic-executable: Options.
5834 * --print-map: Options.
5835 * --reduce-memory-overheads: Options.
5837 * --relax on i960: i960.
5838 * --relax on Xtensa: Xtensa.
5839 * --relocatable: Options.
5840 * --script=SCRIPT: Options.
5841 * --section-alignment: Options.
5842 * --section-start SECTIONNAME=ORG: Options.
5843 * --sort-common: Options.
5844 * --sort-section alignment: Options.
5845 * --sort-section name: Options.
5846 * --split-by-file: Options.
5847 * --split-by-reloc: Options.
5850 * --strip-all: Options.
5851 * --strip-debug: Options.
5852 * --stub-group-size=N: HPPA ELF32.
5853 * --subsystem: Options.
5854 * --support-old-code: ARM.
5855 * --sysroot: Options.
5856 * --target-help: Options.
5857 * --target1-abs: ARM.
5858 * --target1-rel: ARM.
5859 * --target2=TYPE: ARM.
5860 * --thumb-entry=ENTRY: ARM.
5862 * --trace-symbol=SYMBOL: Options.
5863 * --traditional-format: Options.
5864 * --undefined=SYMBOL: Options.
5865 * --unique[=SECTION]: Options.
5866 * --unresolved-symbols: Options.
5868 * --verbose: Options.
5869 * --version: Options.
5870 * --version-script=VERSION-SCRIPTFILE: Options.
5871 * --warn-common: Options.
5872 * --warn-constructors: Options.
5873 * --warn-multiple-gp: Options.
5874 * --warn-once: Options.
5875 * --warn-section-align: Options.
5876 * --warn-shared-textrel: Options.
5877 * --warn-unresolved-symbols: Options.
5878 * --whole-archive: Options.
5881 * -aKEYWORD: Options.
5882 * -assert KEYWORD: Options.
5883 * -b FORMAT: Options.
5884 * -Bdynamic: Options.
5886 * -Bshareable: Options.
5887 * -Bstatic: Options.
5888 * -Bsymbolic: Options.
5889 * -c MRI-CMDFILE: Options.
5890 * -call_shared: Options.
5897 * -e ENTRY: Options.
5909 * -lARCHIVE: Options.
5912 * -m EMULATION: Options.
5916 * -non_shared: Options.
5917 * -nostdlib: Options.
5918 * -O LEVEL: Options.
5919 * -o OUTPUT: Options.
5927 * -rpath-link: Options.
5931 * -soname=NAME: Options.
5934 * -T SCRIPT: Options.
5935 * -Tbss ORG: Options.
5936 * -Tdata ORG: Options.
5937 * -Ttext ORG: Options.
5938 * -u SYMBOL: Options.
5945 * -y SYMBOL: Options.
5947 * -z KEYWORD: Options.
5948 * -z muldefs: Options.
5949 * .: Location Counter.
5950 * /DISCARD/: Output Section Discarding.
5951 * :PHDR: Output Section Phdr.
5952 * =FILLEXP: Output Section Fill.
5953 * >REGION: Output Section Region.
5954 * [COMMON]: Input Section Common.
5955 * ABSOLUTE (MRI): MRI.
5956 * absolute and relocatable symbols: Expression Section.
5957 * absolute expressions: Expression Section.
5958 * ABSOLUTE(EXP): Builtin Functions.
5959 * ADDR(SECTION): Builtin Functions.
5960 * address, section: Output Section Address.
5963 * align expression: Builtin Functions.
5964 * align location counter: Builtin Functions.
5965 * ALIGN(ALIGN): Builtin Functions.
5966 * ALIGN(EXP,ALIGN): Builtin Functions.
5967 * ALIGN(SECTION_ALIGN): Forced Output Alignment.
5968 * allocating memory: MEMORY.
5969 * architecture: Miscellaneous Commands.
5970 * architectures: Options.
5971 * archive files, from cmd line: Options.
5972 * archive search path in linker script: File Commands.
5973 * arithmetic: Expressions.
5974 * arithmetic operators: Operators.
5975 * ARM interworking support: ARM.
5976 * AS_NEEDED(FILES): File Commands.
5977 * ASSERT: Miscellaneous Commands.
5978 * assertion in linker script: Miscellaneous Commands.
5979 * assignment in scripts: Assignments.
5980 * AT(LMA): Output Section LMA.
5981 * AT>LMA_REGION: Output Section LMA.
5982 * automatic data imports: WIN32.
5986 * BFD canonical format: Canonical format.
5987 * BFD requirements: BFD.
5988 * big-endian objects: Options.
5989 * binary input format: Options.
5990 * BLOCK(EXP): Builtin Functions.
5991 * bug criteria: Bug Criteria.
5992 * bug reports: Bug Reporting.
5993 * bugs in ld: Reporting Bugs.
5994 * BYTE(EXPRESSION): Output Section Data.
5995 * C++ constructors, arranging in link: Output Section Keywords.
5997 * COLLECT_NO_DEMANGLE: Environment.
5998 * combining symbols, warnings on: Options.
5999 * command files: Scripts.
6000 * command line: Options.
6001 * common allocation: Options.
6002 * common allocation in linker script: Miscellaneous Commands.
6003 * common symbol placement: Input Section Common.
6004 * compatibility, MRI: Options.
6005 * constants in linker scripts: Constants.
6006 * CONSTRUCTORS: Output Section Keywords.
6007 * constructors: Options.
6008 * constructors, arranging in link: Output Section Keywords.
6009 * crash of linker: Bug Criteria.
6010 * CREATE_OBJECT_SYMBOLS: Output Section Keywords.
6011 * creating a DEF file: WIN32.
6012 * cross reference table: Options.
6013 * cross references: Miscellaneous Commands.
6014 * current output location: Location Counter.
6015 * data: Output Section Data.
6016 * DATA_SEGMENT_ALIGN(MAXPAGESIZE, COMMONPAGESIZE): Builtin Functions.
6017 * DATA_SEGMENT_END(EXP): Builtin Functions.
6018 * DATA_SEGMENT_RELRO_END(OFFSET, EXP): Builtin Functions.
6020 * DEF files, creating: Options.
6021 * default emulation: Environment.
6022 * default input format: Environment.
6023 * DEFINED(SYMBOL): Builtin Functions.
6024 * deleting local symbols: Options.
6025 * demangling, default: Environment.
6026 * demangling, from command line: Options.
6027 * direct linking to a dll: WIN32.
6028 * discarding sections: Output Section Discarding.
6029 * discontinuous memory: MEMORY.
6030 * DLLs, creating: Options.
6031 * DLLs, linking to: Options.
6032 * dot: Location Counter.
6033 * dot inside sections: Location Counter.
6034 * dot outside sections: Location Counter.
6035 * dynamic linker, from command line: Options.
6036 * dynamic symbol table: Options.
6037 * ELF program headers: PHDRS.
6038 * emulation: Options.
6039 * emulation, default: Environment.
6041 * endianness: Options.
6042 * entry point: Entry Point.
6043 * entry point, from command line: Options.
6044 * entry point, thumb: ARM.
6045 * ENTRY(SYMBOL): Entry Point.
6046 * error on valid input: Bug Criteria.
6047 * example of linker script: Simple Example.
6048 * exporting DLL symbols: WIN32.
6049 * expression evaluation order: Evaluation.
6050 * expression sections: Expression Section.
6051 * expression, absolute: Builtin Functions.
6052 * expressions: Expressions.
6053 * EXTERN: Miscellaneous Commands.
6054 * fatal signal: Bug Criteria.
6055 * file name wildcard patterns: Input Section Wildcards.
6057 * filename symbols: Output Section Keywords.
6058 * fill pattern, entire section: Output Section Fill.
6059 * FILL(EXPRESSION): Output Section Data.
6060 * finalization function: Options.
6061 * first input file: File Commands.
6062 * first instruction: Entry Point.
6064 * FORCE_COMMON_ALLOCATION: Miscellaneous Commands.
6065 * forcing input section alignment: Forced Input Alignment.
6066 * forcing output section alignment: Forced Output Alignment.
6067 * FORMAT (MRI): MRI.
6068 * functions in expressions: Builtin Functions.
6069 * garbage collection <1>: Options.
6070 * garbage collection: Input Section Keep.
6071 * generating optimized output: Options.
6072 * GNU linker: Overview.
6073 * GNUTARGET: Environment.
6074 * GROUP(FILES): File Commands.
6075 * grouping input files: File Commands.
6076 * groups of archives: Options.
6077 * H8/300 support: H8/300.
6078 * header size: Builtin Functions.
6079 * heap size: Options.
6081 * holes: Location Counter.
6082 * holes, filling: Output Section Data.
6083 * HPPA multiple sub-space stubs: HPPA ELF32.
6084 * HPPA stub grouping: HPPA ELF32.
6085 * i960 support: i960.
6086 * image base: Options.
6087 * implicit linker scripts: Implicit Linker Scripts.
6088 * import libraries: WIN32.
6089 * INCLUDE FILENAME: File Commands.
6090 * including a linker script: File Commands.
6091 * including an entire archive: Options.
6092 * incremental link: Options.
6093 * INHIBIT_COMMON_ALLOCATION: Miscellaneous Commands.
6094 * initialization function: Options.
6095 * initialized data in ROM: Output Section LMA.
6096 * input file format in linker script: Format Commands.
6097 * input filename symbols: Output Section Keywords.
6098 * input files in linker scripts: File Commands.
6099 * input files, displaying: Options.
6100 * input format: Options.
6101 * input object files in linker scripts: File Commands.
6102 * input section alignment: Forced Input Alignment.
6103 * input section basics: Input Section Basics.
6104 * input section wildcards: Input Section Wildcards.
6105 * input sections: Input Section.
6106 * INPUT(FILES): File Commands.
6107 * integer notation: Constants.
6108 * integer suffixes: Constants.
6109 * internal object-file format: Canonical format.
6110 * invalid input: Bug Criteria.
6111 * K and M integer suffixes: Constants.
6112 * KEEP: Input Section Keep.
6114 * L, deleting symbols beginning: Options.
6115 * lazy evaluation: Evaluation.
6116 * ld bugs, reporting: Bug Reporting.
6117 * LDEMULATION: Environment.
6120 * LENGTH(MEMORY): Builtin Functions.
6121 * library search path in linker script: File Commands.
6122 * link map: Options.
6123 * link-time runtime library search path: Options.
6124 * linker crash: Bug Criteria.
6125 * linker script concepts: Basic Script Concepts.
6126 * linker script example: Simple Example.
6127 * linker script file commands: File Commands.
6128 * linker script format: Script Format.
6129 * linker script input object files: File Commands.
6130 * linker script simple commands: Simple Commands.
6131 * linker scripts: Scripts.
6133 * little-endian objects: Options.
6135 * load address: Output Section LMA.
6136 * LOADADDR(SECTION): Builtin Functions.
6137 * loading, preventing: Output Section Type.
6138 * local symbols, deleting: Options.
6139 * location counter: Location Counter.
6140 * LONG(EXPRESSION): Output Section Data.
6141 * M and K integer suffixes: Constants.
6142 * machine architecture: Miscellaneous Commands.
6143 * machine dependencies: Machine Dependent.
6144 * mapping input sections to output sections: Input Section.
6145 * MAX: Builtin Functions.
6147 * memory region attributes: MEMORY.
6148 * memory regions: MEMORY.
6149 * memory regions and sections: Output Section Region.
6150 * memory usage: Options.
6151 * MIN: Builtin Functions.
6152 * MRI compatibility: MRI.
6153 * MSP430 extra sections: MSP430.
6155 * name, section: Output Section Name.
6157 * naming the output file: Options.
6158 * NEXT(EXP): Builtin Functions.
6160 * NOCROSSREFS(SECTIONS): Miscellaneous Commands.
6161 * NOLOAD: Output Section Type.
6162 * not enough room for program headers: Builtin Functions.
6165 * object file management: BFD.
6166 * object files: Options.
6167 * object formats available: BFD.
6168 * object size: Options.
6170 * opening object files: BFD outline.
6171 * operators for arithmetic: Operators.
6176 * ORIGIN(MEMORY): Builtin Functions.
6177 * orphan: Orphan Sections.
6178 * output file after errors: Options.
6179 * output file format in linker script: Format Commands.
6180 * output file name in linker scripot: File Commands.
6181 * output section alignment: Forced Output Alignment.
6182 * output section attributes: Output Section Attributes.
6183 * output section data: Output Section Data.
6184 * OUTPUT(FILENAME): File Commands.
6185 * OUTPUT_ARCH(BFDARCH): Miscellaneous Commands.
6186 * OUTPUT_FORMAT(BFDNAME): Format Commands.
6187 * OVERLAY: Overlay Description.
6188 * overlays: Overlay Description.
6189 * partial link: Options.
6191 * position independent executables: Options.
6192 * precedence in expressions: Operators.
6193 * prevent unnecessary loading: Output Section Type.
6194 * program headers: PHDRS.
6195 * program headers and sections: Output Section Phdr.
6196 * program headers, not enough room: Builtin Functions.
6197 * program segments: PHDRS.
6199 * PROVIDE_HIDDEN: PROVIDE_HIDDEN.
6200 * PUBLIC (MRI): MRI.
6201 * QUAD(EXPRESSION): Output Section Data.
6202 * quoted symbol names: Symbols.
6203 * read-only text: Options.
6204 * read/write from cmd line: Options.
6205 * regions of memory: MEMORY.
6206 * relative expressions: Expression Section.
6207 * relaxing addressing modes: Options.
6208 * relaxing on H8/300: H8/300.
6209 * relaxing on i960: i960.
6210 * relaxing on Xtensa: Xtensa.
6211 * relocatable and absolute symbols: Expression Section.
6212 * relocatable output: Options.
6213 * removing sections: Output Section Discarding.
6214 * reporting bugs in ld: Reporting Bugs.
6215 * requirements for BFD: BFD.
6216 * retain relocations in final executable: Options.
6217 * retaining specified symbols: Options.
6218 * ROM initialized data: Output Section LMA.
6219 * round up expression: Builtin Functions.
6220 * round up location counter: Builtin Functions.
6221 * runtime library name: Options.
6222 * runtime library search path: Options.
6223 * runtime pseudo-relocation: WIN32.
6224 * scaled integers: Constants.
6225 * scommon section: Input Section Common.
6226 * script files: Options.
6228 * search directory, from cmd line: Options.
6229 * search path in linker script: File Commands.
6230 * SEARCH_DIR(PATH): File Commands.
6232 * section address: Output Section Address.
6233 * section address in expression: Builtin Functions.
6234 * section alignment, warnings on: Options.
6235 * section data: Output Section Data.
6236 * section fill pattern: Output Section Fill.
6237 * section load address: Output Section LMA.
6238 * section load address in expression: Builtin Functions.
6239 * section name: Output Section Name.
6240 * section name wildcard patterns: Input Section Wildcards.
6241 * section size: Builtin Functions.
6242 * section, assigning to memory region: Output Section Region.
6243 * section, assigning to program header: Output Section Phdr.
6244 * SECTIONS: SECTIONS.
6245 * sections, discarding: Output Section Discarding.
6246 * segment origins, cmd line: Options.
6247 * SEGMENT_START(SEGMENT, DEFAULT): Builtin Functions.
6248 * segments, ELF: PHDRS.
6249 * shared libraries: Options.
6250 * SHORT(EXPRESSION): Output Section Data.
6251 * SIZEOF(SECTION): Builtin Functions.
6252 * SIZEOF_HEADERS: Builtin Functions.
6253 * small common symbols: Input Section Common.
6254 * SORT: Input Section Wildcards.
6255 * SORT_BY_ALIGNMENT: Input Section Wildcards.
6256 * SORT_BY_NAME: Input Section Wildcards.
6257 * SQUAD(EXPRESSION): Output Section Data.
6258 * stack size: Options.
6259 * standard Unix system: Options.
6260 * start of execution: Entry Point.
6261 * STARTUP(FILENAME): File Commands.
6262 * strip all symbols: Options.
6263 * strip debugger symbols: Options.
6264 * stripping all but some symbols: Options.
6265 * SUBALIGN(SUBSECTION_ALIGN): Forced Input Alignment.
6266 * suffixes for integers: Constants.
6267 * symbol defaults: Builtin Functions.
6268 * symbol definition, scripts: Assignments.
6269 * symbol names: Symbols.
6270 * symbol tracing: Options.
6271 * symbol versions: VERSION.
6272 * symbol-only input: Options.
6273 * symbols, from command line: Options.
6274 * symbols, relocatable and absolute: Expression Section.
6275 * symbols, retaining selectively: Options.
6276 * synthesizing linker: Options.
6277 * synthesizing on H8/300: H8/300.
6278 * TARGET(BFDNAME): Format Commands.
6281 * thumb entry point: ARM.
6282 * TI COFF versions: TI COFF.
6283 * traditional format: Options.
6284 * unallocated address, next: Builtin Functions.
6285 * undefined symbol: Options.
6286 * undefined symbol in linker script: Miscellaneous Commands.
6287 * undefined symbols, warnings on: Options.
6288 * uninitialized data placement: Input Section Common.
6289 * unspecified memory: Output Section Data.
6292 * using a DEF file: WIN32.
6293 * using auto-export functionality: WIN32.
6294 * Using decorations: WIN32.
6295 * variables, defining: Assignments.
6298 * version script: VERSION.
6299 * version script, symbol versions: Options.
6300 * VERSION {script text}: VERSION.
6301 * versions of symbols: VERSION.
6302 * warnings, on combining symbols: Options.
6303 * warnings, on section alignment: Options.
6304 * warnings, on undefined symbols: Options.
6305 * weak externals: WIN32.
6306 * what is this?: Overview.
6307 * wildcard file name patterns: Input Section Wildcards.
6308 * Xtensa options: Xtensa.
6309 * Xtensa processors: Xtensa.