3 @c Copyright (C) 1991-2024 Free Software Foundation, Inc.
6 @include configdoc.texi
7 @c (configdoc.texi is generated by the Makefile)
13 @macro gcctabopt{body}
19 @c Configure for the generation of man pages
47 @dircategory Software development
49 * Ld: (ld). The GNU linker.
54 This file documents the @sc{gnu} linker LD
55 @ifset VERSION_PACKAGE
56 @value{VERSION_PACKAGE}
58 version @value{VERSION}.
60 Copyright @copyright{} 1991-2024 Free Software Foundation, Inc.
62 Permission is granted to copy, distribute and/or modify this document
63 under the terms of the GNU Free Documentation License, Version 1.3
64 or any later version published by the Free Software Foundation;
65 with no Invariant Sections, with no Front-Cover Texts, and with no
66 Back-Cover Texts. A copy of the license is included in the
67 section entitled ``GNU Free Documentation License''.
71 @setchapternewpage odd
72 @settitle The GNU linker
77 @ifset VERSION_PACKAGE
78 @subtitle @value{VERSION_PACKAGE}
80 @subtitle Version @value{VERSION}
81 @author Steve Chamberlain
82 @author Ian Lance Taylor
87 \hfill Red Hat Inc\par
88 \hfill nickc\@redhat.com, doc\@redhat.com\par
89 \hfill {\it The GNU linker}\par
90 \hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
92 \global\parindent=0pt % Steve likes it this way.
95 @vskip 0pt plus 1filll
96 @c man begin COPYRIGHT
97 Copyright @copyright{} 1991-2024 Free Software Foundation, Inc.
99 Permission is granted to copy, distribute and/or modify this document
100 under the terms of the GNU Free Documentation License, Version 1.3
101 or any later version published by the Free Software Foundation;
102 with no Invariant Sections, with no Front-Cover Texts, and with no
103 Back-Cover Texts. A copy of the license is included in the
104 section entitled ``GNU Free Documentation License''.
110 @c FIXME: Talk about importance of *order* of args, cmds to linker!
115 This file documents the @sc{gnu} linker ld
116 @ifset VERSION_PACKAGE
117 @value{VERSION_PACKAGE}
119 version @value{VERSION}.
121 This document is distributed under the terms of the GNU Free
122 Documentation License version 1.3. A copy of the license is included
123 in the section entitled ``GNU Free Documentation License''.
126 * Overview:: Overview
127 * Invocation:: Invocation
128 * Scripts:: Linker Scripts
129 * Plugins:: Linker Plugins
130 * Special Sections:: Special Sections
132 * Machine Dependent:: Machine Dependent Features
136 * H8/300:: ld and the H8/300
139 * Renesas:: ld and other Renesas micros
142 * ARM:: ld and the ARM family
145 * M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families
148 * HPPA ELF32:: ld and HPPA 32-bit ELF
151 * M68K:: ld and Motorola 68K family
154 * MIPS:: ld and MIPS family
157 * PowerPC ELF32:: ld and PowerPC 32-bit ELF Support
160 * PowerPC64 ELF64:: ld and PowerPC64 64-bit ELF Support
163 * S/390 ELF:: ld and S/390 ELF Support
166 * SPU ELF:: ld and SPU ELF Support
169 * TI COFF:: ld and the TI COFF
172 * Win32:: ld and WIN32 (cygwin/mingw)
175 * Xtensa:: ld and Xtensa Processors
178 @ifclear SingleFormat
181 @c Following blank line required for remaining bug in makeinfo conds/menus
183 * Reporting Bugs:: Reporting Bugs
184 * MRI:: MRI Compatible Script Files
185 * GNU Free Documentation License:: GNU Free Documentation License
186 * LD Index:: LD Index
193 @cindex @sc{gnu} linker
194 @cindex what is this?
197 @c man begin SYNOPSIS
198 ld [@b{options}] @var{objfile} @dots{}
202 ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
203 the Info entries for @file{binutils} and
208 @c man begin DESCRIPTION
210 @command{ld} combines a number of object and archive files, relocates
211 their data and ties up symbol references. Usually the last step in
212 compiling a program is to run @command{ld}.
214 @command{ld} accepts Linker Command Language files written in
215 a superset of AT&T's Link Editor Command Language syntax,
216 to provide explicit and total control over the linking process.
220 This man page does not describe the command language; see the
221 @command{ld} entry in @code{info} for full details on the command
222 language and on other aspects of the GNU linker.
225 @ifclear SingleFormat
226 This version of @command{ld} uses the general purpose BFD libraries
227 to operate on object files. This allows @command{ld} to read, combine, and
228 write object files in many different formats---for example, COFF or
229 @code{a.out}. Different formats may be linked together to produce any
230 available kind of object file. @xref{BFD}, for more information.
233 Aside from its flexibility, the @sc{gnu} linker is more helpful than other
234 linkers in providing diagnostic information. Many linkers abandon
235 execution immediately upon encountering an error; whenever possible,
236 @command{ld} continues executing, allowing you to identify other errors
237 (or, in some cases, to get an output file in spite of the error).
244 @c man begin DESCRIPTION
246 The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
247 and to be as compatible as possible with other linkers. As a result,
248 you have many choices to control its behavior.
254 * Options:: Command-line Options
255 * Environment:: Environment Variables
259 @section Command-line Options
267 The linker supports a plethora of command-line options, but in actual
268 practice few of them are used in any particular context.
269 @cindex standard Unix system
270 For instance, a frequent use of @command{ld} is to link standard Unix
271 object files on a standard, supported Unix system. On such a system, to
272 link a file @code{hello.o}:
275 ld -o @var{output} /lib/crt0.o hello.o -lc
278 This tells @command{ld} to produce a file called @var{output} as the
279 result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
280 the library @code{libc.a}, which will come from the standard search
281 directories. (See the discussion of the @samp{-l} option below.)
283 Some of the command-line options to @command{ld} may be specified at any
284 point in the command line. However, options which refer to files, such
285 as @samp{-l} or @samp{-T}, cause the file to be read at the point at
286 which the option appears in the command line, relative to the object
287 files and other file options. Repeating non-file options with a
288 different argument will either have no further effect, or override prior
289 occurrences (those further to the left on the command line) of that
290 option. Options which may be meaningfully specified more than once are
291 noted in the descriptions below.
294 Non-option arguments are object files or archives which are to be linked
295 together. They may follow, precede, or be mixed in with command-line
296 options, except that an object file argument may not be placed between
297 an option and its argument.
299 Usually the linker is invoked with at least one object file, but you can
300 specify other forms of binary input files using @samp{-l}, @samp{-R},
301 and the script command language. If @emph{no} binary input files at all
302 are specified, the linker does not produce any output, and issues the
303 message @samp{No input files}.
305 @anchor{unrecognised-input-files}
306 If the linker cannot recognize the format of an object file, it will
307 assume that it is a linker script. A script specified in this way
308 augments the main linker script used for the link (either the default
309 linker script or the one specified by using @samp{-T}). This feature
310 permits the linker to link against a file which appears to be an object
311 or an archive, but actually merely defines some symbol values, or uses
312 @code{INPUT} or @code{GROUP} to load other objects. Specifying a
313 script in this way merely augments the main linker script, with the
314 extra commands placed after the main script; use the @samp{-T} option
315 to replace the default linker script entirely, but note the effect of
316 the @code{INSERT} command. @xref{Scripts}.
318 For options whose names are a single letter,
319 option arguments must either follow the option letter without intervening
320 whitespace, or be given as separate arguments immediately following the
321 option that requires them.
323 For options whose names are multiple letters, either one dash or two can
324 precede the option name; for example, @samp{-trace-symbol} and
325 @samp{--trace-symbol} are equivalent. Note---there is one exception to
326 this rule. Multiple letter options that start with a lower case 'o' can
327 only be preceded by two dashes. This is to reduce confusion with the
328 @samp{-o} option. So for example @samp{-omagic} sets the output file
329 name to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the
332 Arguments to multiple-letter options must either be separated from the
333 option name by an equals sign, or be given as separate arguments
334 immediately following the option that requires them. For example,
335 @samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent.
336 Unique abbreviations of the names of multiple-letter options are
339 Note---if the linker is being invoked indirectly, via a compiler driver
340 (e.g. @samp{gcc}) then all the linker command-line options should be
341 prefixed by @samp{-Wl,} (or whatever is appropriate for the particular
342 compiler driver) like this:
345 gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
348 This is important, because otherwise the compiler driver program may
349 silently drop the linker options, resulting in a bad link. Confusion
350 may also arise when passing options that require values through a
351 driver, as the use of a space between option and argument acts as
352 a separator, and causes the driver to pass only the option to the linker
353 and the argument to the compiler. In this case, it is simplest to use
354 the joined forms of both single- and multiple-letter options, such as:
357 gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
360 Here is a table of the generic command-line switches accepted by the GNU
364 @include at-file.texi
366 @kindex -a @var{keyword}
367 @item -a @var{keyword}
368 This option is supported for HP/UX compatibility. The @var{keyword}
369 argument must be one of the strings @samp{archive}, @samp{shared}, or
370 @samp{default}. @samp{-aarchive} is functionally equivalent to
371 @samp{-Bstatic}, and the other two keywords are functionally equivalent
372 to @samp{-Bdynamic}. This option may be used any number of times.
374 @kindex --audit @var{AUDITLIB}
375 @item --audit @var{AUDITLIB}
376 Adds @var{AUDITLIB} to the @code{DT_AUDIT} entry of the dynamic section.
377 @var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
378 specified in the library. If specified multiple times @code{DT_AUDIT}
379 will contain a colon separated list of audit interfaces to use. If the linker
380 finds an object with an audit entry while searching for shared libraries,
381 it will add a corresponding @code{DT_DEPAUDIT} entry in the output file.
382 This option is only meaningful on ELF platforms supporting the rtld-audit
385 @ifclear SingleFormat
386 @cindex binary input format
387 @kindex -b @var{format}
388 @kindex --format=@var{format}
391 @item -b @var{input-format}
392 @itemx --format=@var{input-format}
393 @command{ld} may be configured to support more than one kind of object
394 file. If your @command{ld} is configured this way, you can use the
395 @samp{-b} option to specify the binary format for input object files
396 that follow this option on the command line. Even when @command{ld} is
397 configured to support alternative object formats, you don't usually need
398 to specify this, as @command{ld} should be configured to expect as a
399 default input format the most usual format on each machine.
400 @var{input-format} is a text string, the name of a particular format
401 supported by the BFD libraries. (You can list the available binary
402 formats with @samp{objdump -i}.)
405 You may want to use this option if you are linking files with an unusual
406 binary format. You can also use @samp{-b} to switch formats explicitly (when
407 linking object files of different formats), by including
408 @samp{-b @var{input-format}} before each group of object files in a
411 The default format is taken from the environment variable
416 You can also define the input format from a script, using the command
419 see @ref{Format Commands}.
423 @kindex -c @var{MRI-cmdfile}
424 @kindex --mri-script=@var{MRI-cmdfile}
425 @cindex compatibility, MRI
426 @item -c @var{MRI-commandfile}
427 @itemx --mri-script=@var{MRI-commandfile}
428 For compatibility with linkers produced by MRI, @command{ld} accepts script
429 files written in an alternate, restricted command language, described in
431 @ref{MRI,,MRI Compatible Script Files}.
434 the MRI Compatible Script Files section of GNU ld documentation.
436 Introduce MRI script files with
437 the option @samp{-c}; use the @samp{-T} option to run linker
438 scripts written in the general-purpose @command{ld} scripting language.
439 If @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories
440 specified by any @samp{-L} options.
442 @cindex common allocation
449 These three options are equivalent; multiple forms are supported for
450 compatibility with other linkers. They assign space to common symbols
451 even if a relocatable output file is specified (with @samp{-r}). The
452 script command @code{FORCE_COMMON_ALLOCATION} has the same effect.
453 @xref{Miscellaneous Commands}.
455 @kindex --depaudit @var{AUDITLIB}
456 @kindex -P @var{AUDITLIB}
457 @item --depaudit @var{AUDITLIB}
458 @itemx -P @var{AUDITLIB}
459 Adds @var{AUDITLIB} to the @code{DT_DEPAUDIT} entry of the dynamic section.
460 @var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
461 specified in the library. If specified multiple times @code{DT_DEPAUDIT}
462 will contain a colon separated list of audit interfaces to use. This
463 option is only meaningful on ELF platforms supporting the rtld-audit interface.
464 The -P option is provided for Solaris compatibility.
466 @kindex --enable-linker-version
467 @item --enable-linker-version
468 Enables the @code{LINKER_VERSION} linker script directive, described
469 in @ref{Output Section Data}. If this directive is used in a linker
470 script and this option has been enabled then a string containing the
471 linker version will be inserted at the current point.
473 Note - this location of this option on the linker command line is
474 significant. It will only affect linker scripts that come after it on
475 the command line, or which are built into the linker.
477 @kindex --disable-linker-version
478 @item --disable-linker-version
479 Disables the @code{LINKER_VERSION} linker script directive, so that it
480 does not insert a version string. This is the default.
482 @kindex --enable-non-contiguous-regions
483 @item --enable-non-contiguous-regions
484 This option avoids generating an error if an input section does not
485 fit a matching output section. The linker tries to allocate the input
486 section to subseque nt matching output sections, and generates an
487 error only if no output section is large enough. This is useful when
488 several non-contiguous memory regions are available and the input
489 section does not require a particular one. The order in which input
490 sections are evaluated does not change, for instance:
494 MEM1 (rwx) : ORIGIN = 0x1000, LENGTH = 0x14
495 MEM2 (rwx) : ORIGIN = 0x1000, LENGTH = 0x40
496 MEM3 (rwx) : ORIGIN = 0x2000, LENGTH = 0x40
499 mem1 : @{ *(.data.*); @} > MEM1
500 mem2 : @{ *(.data.*); @} > MEM2
501 mem3 : @{ *(.data.*); @} > MEM3
509 results in .data.1 affected to mem1, and .data.2 and .data.3
510 affected to mem2, even though .data.3 would fit in mem3.
513 This option is incompatible with INSERT statements because it changes
514 the way input sections are mapped to output sections.
516 @kindex --enable-non-contiguous-regions-warnings
517 @item --enable-non-contiguous-regions-warnings
518 This option enables warnings when
519 @code{--enable-non-contiguous-regions} allows possibly unexpected
520 matches in sections mapping, potentially leading to silently
521 discarding a section instead of failing because it does not fit any
524 @cindex entry point, from command line
525 @kindex -e @var{entry}
526 @kindex --entry=@var{entry}
528 @itemx --entry=@var{entry}
529 Use @var{entry} as the explicit symbol for beginning execution of your
530 program, rather than the default entry point. If there is no symbol
531 named @var{entry}, the linker will try to parse @var{entry} as a number,
532 and use that as the entry address (the number will be interpreted in
533 base 10; you may use a leading @samp{0x} for base 16, or a leading
534 @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults
535 and other ways of specifying the entry point.
537 @kindex --exclude-libs
538 @item --exclude-libs @var{lib},@var{lib},...
539 Specifies a list of archive libraries from which symbols should not be automatically
540 exported. The library names may be delimited by commas or colons. Specifying
541 @code{--exclude-libs ALL} excludes symbols in all archive libraries from
542 automatic export. This option is available only for the i386 PE targeted
543 port of the linker and for ELF targeted ports. For i386 PE, symbols
544 explicitly listed in a .def file are still exported, regardless of this
545 option. For ELF targeted ports, symbols affected by this option will
546 be treated as hidden.
548 @kindex --exclude-modules-for-implib
549 @item --exclude-modules-for-implib @var{module},@var{module},...
550 Specifies a list of object files or archive members, from which symbols
551 should not be automatically exported, but which should be copied wholesale
552 into the import library being generated during the link. The module names
553 may be delimited by commas or colons, and must match exactly the filenames
554 used by @command{ld} to open the files; for archive members, this is simply
555 the member name, but for object files the name listed must include and
556 match precisely any path used to specify the input file on the linker's
557 command-line. This option is available only for the i386 PE targeted port
558 of the linker. Symbols explicitly listed in a .def file are still exported,
559 regardless of this option.
561 @cindex dynamic symbol table
563 @kindex --export-dynamic
564 @kindex --no-export-dynamic
566 @itemx --export-dynamic
567 @itemx --no-export-dynamic
568 When creating a dynamically linked executable, using the @option{-E}
569 option or the @option{--export-dynamic} option causes the linker to add
570 all symbols to the dynamic symbol table. The dynamic symbol table is the
571 set of symbols which are visible from dynamic objects at run time.
573 If you do not use either of these options (or use the
574 @option{--no-export-dynamic} option to restore the default behavior), the
575 dynamic symbol table will normally contain only those symbols which are
576 referenced by some dynamic object mentioned in the link.
578 If you use @code{dlopen} to load a dynamic object which needs to refer
579 back to the symbols defined by the program, rather than some other
580 dynamic object, then you will probably need to use this option when
581 linking the program itself.
583 You can also use the dynamic list to control what symbols should
584 be added to the dynamic symbol table if the output format supports it.
585 See the description of @samp{--dynamic-list}.
587 Note that this option is specific to ELF targeted ports. PE targets
588 support a similar function to export all symbols from a DLL or EXE; see
589 the description of @samp{--export-all-symbols} below.
591 @kindex --export-dynamic-symbol=@var{glob}
592 @cindex export dynamic symbol
593 @item --export-dynamic-symbol=@var{glob}
594 When creating a dynamically linked executable, symbols matching
595 @var{glob} will be added to the dynamic symbol table. When creating a
596 shared library, references to symbols matching @var{glob} will not be
597 bound to the definitions within the shared library. This option is a
598 no-op when creating a shared library and @samp{-Bsymbolic} or
599 @samp{--dynamic-list} are not specified. This option is only meaningful
600 on ELF platforms which support shared libraries.
602 @kindex --export-dynamic-symbol-list=@var{file}
603 @cindex export dynamic symbol list
604 @item --export-dynamic-symbol-list=@var{file}
605 Specify a @samp{--export-dynamic-symbol} for each pattern in the file.
606 The format of the file is the same as the version node without
607 scope and node name. See @ref{VERSION} for more information.
609 @ifclear SingleFormat
610 @cindex big-endian objects
614 Link big-endian objects. This affects the default output format.
616 @cindex little-endian objects
619 Link little-endian objects. This affects the default output format.
622 @kindex -f @var{name}
623 @kindex --auxiliary=@var{name}
625 @itemx --auxiliary=@var{name}
626 When creating an ELF shared object, set the internal DT_AUXILIARY field
627 to the specified name. This tells the dynamic linker that the symbol
628 table of the shared object should be used as an auxiliary filter on the
629 symbol table of the shared object @var{name}.
631 If you later link a program against this filter object, then, when you
632 run the program, the dynamic linker will see the DT_AUXILIARY field. If
633 the dynamic linker resolves any symbols from the filter object, it will
634 first check whether there is a definition in the shared object
635 @var{name}. If there is one, it will be used instead of the definition
636 in the filter object. The shared object @var{name} need not exist.
637 Thus the shared object @var{name} may be used to provide an alternative
638 implementation of certain functions, perhaps for debugging or for
639 machine-specific performance.
641 This option may be specified more than once. The DT_AUXILIARY entries
642 will be created in the order in which they appear on the command line.
644 @kindex -F @var{name}
645 @kindex --filter=@var{name}
647 @itemx --filter=@var{name}
648 When creating an ELF shared object, set the internal DT_FILTER field to
649 the specified name. This tells the dynamic linker that the symbol table
650 of the shared object which is being created should be used as a filter
651 on the symbol table of the shared object @var{name}.
653 If you later link a program against this filter object, then, when you
654 run the program, the dynamic linker will see the DT_FILTER field. The
655 dynamic linker will resolve symbols according to the symbol table of the
656 filter object as usual, but it will actually link to the definitions
657 found in the shared object @var{name}. Thus the filter object can be
658 used to select a subset of the symbols provided by the object
661 Some older linkers used the @option{-F} option throughout a compilation
662 toolchain for specifying object-file format for both input and output
664 @ifclear SingleFormat
665 The @sc{gnu} linker uses other mechanisms for this purpose: the
666 @option{-b}, @option{--format}, @option{--oformat} options, the
667 @code{TARGET} command in linker scripts, and the @code{GNUTARGET}
668 environment variable.
670 The @sc{gnu} linker will ignore the @option{-F} option when not
671 creating an ELF shared object.
673 @cindex finalization function
674 @kindex -fini=@var{name}
675 @item -fini=@var{name}
676 When creating an ELF executable or shared object, call NAME when the
677 executable or shared object is unloaded, by setting DT_FINI to the
678 address of the function. By default, the linker uses @code{_fini} as
679 the function to call.
683 Ignored. Provided for compatibility with other tools.
685 @kindex -G @var{value}
686 @kindex --gpsize=@var{value}
689 @itemx --gpsize=@var{value}
690 Set the maximum size of objects to be optimized using the GP register to
691 @var{size}. This is only meaningful for object file formats such as
692 MIPS ELF that support putting large and small objects into different
693 sections. This is ignored for other object file formats.
695 @cindex runtime library name
696 @kindex -h @var{name}
697 @kindex -soname=@var{name}
699 @itemx -soname=@var{name}
700 When creating an ELF shared object, set the internal DT_SONAME field to
701 the specified name. When an executable is linked with a shared object
702 which has a DT_SONAME field, then when the executable is run the dynamic
703 linker will attempt to load the shared object specified by the DT_SONAME
704 field rather than using the file name given to the linker.
707 @cindex incremental link
709 Perform an incremental link (same as option @samp{-r}).
711 @cindex initialization function
712 @kindex -init=@var{name}
713 @item -init=@var{name}
714 When creating an ELF executable or shared object, call NAME when the
715 executable or shared object is loaded, by setting DT_INIT to the address
716 of the function. By default, the linker uses @code{_init} as the
719 @cindex archive files, from cmd line
720 @kindex -l @var{namespec}
721 @kindex --library=@var{namespec}
722 @item -l @var{namespec}
723 @itemx --library=@var{namespec}
724 Add the archive or object file specified by @var{namespec} to the
725 list of files to link. This option may be used any number of times.
726 If @var{namespec} is of the form @file{:@var{filename}}, @command{ld}
727 will search the library path for a file called @var{filename}, otherwise it
728 will search the library path for a file called @file{lib@var{namespec}.a}.
730 On systems which support shared libraries, @command{ld} may also search for
731 files other than @file{lib@var{namespec}.a}. Specifically, on ELF
732 and SunOS systems, @command{ld} will search a directory for a library
733 called @file{lib@var{namespec}.so} before searching for one called
734 @file{lib@var{namespec}.a}. (By convention, a @code{.so} extension
735 indicates a shared library.) Note that this behavior does not apply
736 to @file{:@var{filename}}, which always specifies a file called
739 The linker will search an archive only once, at the location where it is
740 specified on the command line. If the archive defines a symbol which
741 was undefined in some object which appeared before the archive on the
742 command line, the linker will include the appropriate file(s) from the
743 archive. However, an undefined symbol in an object appearing later on
744 the command line will not cause the linker to search the archive again.
746 See the @option{-(} option for a way to force the linker to search
747 archives multiple times.
749 You may list the same archive multiple times on the command line.
752 This type of archive searching is standard for Unix linkers. However,
753 if you are using @command{ld} on AIX, note that it is different from the
754 behaviour of the AIX linker.
757 @cindex search directory, from cmd line
759 @kindex --library-path=@var{dir}
760 @item -L @var{searchdir}
761 @itemx --library-path=@var{searchdir}
763 Add path @var{searchdir} to the list of paths that @command{ld} will search
764 for archive libraries and @command{ld} control scripts. You may use this
765 option any number of times. The directories are searched in the order
766 in which they are specified on the command line. Directories specified
767 on the command line are searched before the default directories. All
768 @option{-L} options apply to all @option{-l} options, regardless of the
769 order in which the options appear. @option{-L} options do not affect
770 how @command{ld} searches for a linker script unless @option{-T}
773 If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
774 prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
775 @samp{--sysroot} option, or specified when the linker is configured.
778 The default set of paths searched (without being specified with
779 @samp{-L}) depends on which emulation mode @command{ld} is using, and in
780 some cases also on how it was configured. @xref{Environment}.
783 The paths can also be specified in a link script with the
784 @code{SEARCH_DIR} command. Directories specified this way are searched
785 at the point in which the linker script appears in the command line.
788 @kindex -m @var{emulation}
789 @item -m @var{emulation}
790 Emulate the @var{emulation} linker. You can list the available
791 emulations with the @samp{--verbose} or @samp{-V} options.
793 If the @samp{-m} option is not used, the emulation is taken from the
794 @code{LDEMULATION} environment variable, if that is defined.
796 Otherwise, the default emulation depends upon how the linker was
799 @cindex remapping inputs
800 @kindex --remap-inputs=@file{pattern}=@file{filename}
801 @kindex --remap-inputs-file=@file{file}
802 @item --remap-inputs=@file{pattern}=@file{filename}
803 @itemx --remap-inputs-file=@file{file}
804 These options allow the names of input files to be changed before the
805 linker attempts to open them. The option
806 @option{--remap-inputs=foo.o=bar.o} will cause any attempt to load a
807 file called @file{foo.o} to instead try to load a file called
808 @file{bar.o}. Wildcard patterns are permitted in the first filename,
809 so @option{--remap-inputs=foo*.o=bar.o} will rename any input file that
810 matches @file{foo*.o} to @file{bar.o}.
812 An alternative form of the option
813 @option{--remap-inputs-file=filename} allows the remappings to be read
814 from a file. Each line in the file can contain a single remapping.
815 Blank lines are ignored. Anything from a hash character (@samp{#}) to
816 the end of a line is considered to be a comment and is also ignored.
817 The mapping pattern can be separated from the filename by whitespace
818 or an equals (@samp{=}) character.
820 The options can be specified multiple times. Their contents
821 accumulate. The remappings will be processed in the order in which
822 they occur on the command line, and if they come from a file, in the
823 order in which they occur in the file. If a match is made, no further
824 checking for that filename will be performed.
826 If the replacement filename is @file{/dev/null} or just @file{NUL}
827 then the remapping will actually cause the input file to be ignored.
828 This can be a convenient way to experiment with removing input files
829 from a complicated build environment.
831 Note that this option is position dependent and only affects filenames
832 that come after it on the command line. Thus:
835 ld foo.o --remap-inputs=foo.o=bar.o
838 Will have no effect, whereas:
841 ld --remap-inputs=foo.o=bar.o foo.o
844 Will rename the input file @file{foo.o} to @file{bar.o}.
846 Note - these options also affect files referenced by @emph{INPUT}
847 statements in linker scripts. But since linker scripts are processed
848 after the entire command line is read, the position of the remap
849 options on the command line is not significant.
851 If the @option{verbose} option is enabled then any mappings that match
852 will be reported, although again the @option{verbose} option needs to
853 be enabled on the command line @emph{before} the remaped filenames
856 If the @option{-Map} or @option{--print-map} options are enabled then
857 the remapping list will be included in the map output.
864 Print a link map to the standard output. A link map provides
865 information about the link, including the following:
869 Where object files are mapped into memory.
871 How common symbols are allocated.
873 All archive members included in the link, with a mention of the symbol
874 which caused the archive member to be brought in.
876 The values assigned to symbols.
878 Note - symbols whose values are computed by an expression which
879 involves a reference to a previous value of the same symbol may not
880 have correct result displayed in the link map. This is because the
881 linker discards intermediate results and only retains the final value
882 of an expression. Under such circumstances the linker will display
883 the final value enclosed by square brackets. Thus for example a
884 linker script containing:
892 will produce the following output in the link map if the @option{-M}
897 [0x0000000c] foo = (foo * 0x4)
898 [0x0000000c] foo = (foo + 0x8)
901 See @ref{Expressions} for more information about expressions in linker
905 How GNU properties are merged.
907 When the linker merges input .note.gnu.property sections into one output
908 .note.gnu.property section, some properties are removed or updated.
909 These actions are reported in the link map. For example:
912 Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
915 This indicates that property 0xc0000002 is removed from output when
916 merging properties in @file{foo.o}, whose property 0xc0000002 value
917 is 0x1, and @file{bar.o}, which doesn't have property 0xc0000002.
920 Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
923 This indicates that property 0xc0010001 value is updated to 0x1 in output
924 when merging properties in @file{foo.o}, whose 0xc0010001 property value
925 is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1.
928 On some ELF targets, a list of fixups inserted by @option{--relax}
931 foo.o: Adjusting branch at 0x00000008 towards "far" in section .text
934 This indicates that the branch at 0x00000008 in foo.o, targeting
935 the symbol "far" in section .text, has been replaced by a trampoline.
939 @cindex link map discarded
940 @kindex --print-map-discarded
941 @kindex --no-print-map-discarded
942 @item --print-map-discarded
943 @itemx --no-print-map-discarded
944 Print (or do not print) the list of discarded and garbage collected sections
945 in the link map. Enabled by default.
947 @kindex --print-map-locals
948 @kindex --no-print-map-locals
949 @item --print-map-locals
950 @itemx --no-print-map-locals
951 Print (or do not print) local symbols in the link map. Local symbols
952 will have the text @samp{(local)} printed before their name, and will
953 be listed after all of the global symbols in a given section.
954 Temporary local symbols (typically those that start with @samp{.L})
955 will not be included in the output. Disabled by default.
958 @cindex read-only text
963 Turn off page alignment of sections, and disable linking against shared
964 libraries. If the output format supports Unix style magic numbers,
965 mark the output as @code{NMAGIC}.
969 @cindex read/write from cmd line
973 Set the text and data sections to be readable and writable. Also, do
974 not page-align the data segment, and disable linking against shared
975 libraries. If the output format supports Unix style magic numbers,
976 mark the output as @code{OMAGIC}. Note: Although a writable text section
977 is allowed for PE-COFF targets, it does not conform to the format
978 specification published by Microsoft.
983 This option negates most of the effects of the @option{-N} option. It
984 sets the text section to be read-only, and forces the data segment to
985 be page-aligned. Note - this option does not enable linking against
986 shared libraries. Use @option{-Bdynamic} for this.
988 @kindex -o @var{output}
989 @kindex --output=@var{output}
990 @cindex naming the output file
991 @item -o @var{output}
992 @itemx --output=@var{output}
993 Use @var{output} as the name for the program produced by @command{ld}; if this
994 option is not specified, the name @file{a.out} is used by default. The
995 script command @code{OUTPUT} can also specify the output file name.
997 Note - the linker will delete the output file before it starts to
998 write to it. It will do this even if it turns out that the link
999 cannot be completed due to errors.
1001 Note - the linker will check to make sure that the output file name
1002 does not match the name of any of the input files, but that is all.
1003 In particular it will not complain if the output file might overwrite
1004 a source file or some other important file. Therefore in build
1005 systems it is recommended to use the @option{-o} option as the last
1006 option on the linker command line. For example consider:
1009 ld -o $(EXE) $(OBJS)
1010 ld $(OBJS) -o $(EXE)
1013 If the @samp{EXE} variable is not defined for some reason, the first
1014 version of the linker command could end up deleting one of the object
1015 files (the first one in the @samp{OBJS} list) whereas the second
1016 version of the linker command will generate an error message and not
1019 @kindex --dependency-file=@var{depfile}
1020 @cindex dependency file
1021 @item --dependency-file=@var{depfile}
1022 Write a @dfn{dependency file} to @var{depfile}. This file contains a rule
1023 suitable for @code{make} describing the output file and all the input files
1024 that were read to produce it. The output is similar to the compiler's
1025 output with @samp{-M -MP} (@pxref{Preprocessor Options,, Options
1026 Controlling the Preprocessor, gcc.info, Using the GNU Compiler
1027 Collection}). Note that there is no option like the compiler's @samp{-MM},
1028 to exclude ``system files'' (which is not a well-specified concept in the
1029 linker, unlike ``system headers'' in the compiler). So the output from
1030 @samp{--dependency-file} is always specific to the exact state of the
1031 installation where it was produced, and should not be copied into
1032 distributed makefiles without careful editing.
1034 @kindex -O @var{level}
1035 @cindex generating optimized output
1036 @item -O @var{level}
1037 If @var{level} is a numeric values greater than zero @command{ld} optimizes
1038 the output. This might take significantly longer and therefore probably
1039 should only be enabled for the final binary. At the moment this
1040 option only affects ELF shared library generation. Future releases of
1041 the linker may make more use of this option. Also currently there is
1042 no difference in the linker's behaviour for different non-zero values
1043 of this option. Again this may change with future releases.
1045 @kindex -plugin @var{name}
1046 @item -plugin @var{name}
1047 Involve a plugin in the linking process. The @var{name} parameter is
1048 the absolute filename of the plugin. Usually this parameter is
1049 automatically added by the complier, when using link time
1050 optimization, but users can also add their own plugins if they so
1053 Note that the location of the compiler originated plugins is different
1054 from the place where the @command{ar}, @command{nm} and
1055 @command{ranlib} programs search for their plugins. In order for
1056 those commands to make use of a compiler based plugin it must first be
1057 copied into the @file{$@{libdir@}/bfd-plugins} directory. All gcc
1058 based linker plugins are backward compatible, so it is sufficient to
1059 just copy in the newest one.
1061 @kindex --push-state
1062 @cindex push state governing input file handling
1064 The @option{--push-state} allows one to preserve the current state of the
1065 flags which govern the input file handling so that they can all be
1066 restored with one corresponding @option{--pop-state} option.
1068 The option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
1069 @option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
1070 @option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
1071 @option{--no-whole-archive}, @option{-r}, @option{-Ur},
1072 @option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
1073 @option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
1075 One target for this option are specifications for @file{pkg-config}. When
1076 used with the @option{--libs} option all possibly needed libraries are
1077 listed and then possibly linked with all the time. It is better to return
1078 something as follows:
1081 -Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
1085 @cindex pop state governing input file handling
1087 Undoes the effect of --push-state, restores the previous values of the
1088 flags governing input file handling.
1091 @kindex --emit-relocs
1092 @cindex retain relocations in final executable
1094 @itemx --emit-relocs
1095 Leave relocation sections and contents in fully linked executables.
1096 Post link analysis and optimization tools may need this information in
1097 order to perform correct modifications of executables. This results
1098 in larger executables.
1100 This option is currently only supported on ELF platforms.
1102 @kindex --force-dynamic
1103 @cindex forcing the creation of dynamic sections
1104 @item --force-dynamic
1105 Force the output file to have dynamic sections. This option is specific
1108 @cindex partial link
1109 @cindex relocatable output
1111 @kindex --relocatable
1113 @itemx --relocatable
1114 Generate relocatable output---i.e., generate an output file that can in
1115 turn serve as input to @command{ld}. This is often called @dfn{partial
1116 linking}. As a side effect, in environments that support standard Unix
1117 magic numbers, this option also sets the output file's magic number to
1119 @c ; see @option{-N}.
1120 If this option is not specified, an absolute file is produced. When
1121 linking C++ programs, this option @emph{will not} resolve references to
1122 constructors; to do that, use @samp{-Ur}.
1124 When an input file does not have the same format as the output file,
1125 partial linking is only supported if that input file does not contain any
1126 relocations. Different output formats can have further restrictions; for
1127 example some @code{a.out}-based formats do not support partial linking
1128 with input files in other formats at all.
1130 This option does the same thing as @samp{-i}.
1132 @kindex -R @var{file}
1133 @kindex --just-symbols=@var{file}
1134 @cindex symbol-only input
1135 @item -R @var{filename}
1136 @itemx --just-symbols=@var{filename}
1137 Read symbol names and their addresses from @var{filename}, but do not
1138 relocate it or include it in the output. This allows your output file
1139 to refer symbolically to absolute locations of memory defined in other
1140 programs. You may use this option more than once.
1142 For compatibility with other ELF linkers, if the @option{-R} option is
1143 followed by a directory name, rather than a file name, it is treated as
1144 the @option{-rpath} option.
1147 @itemx --no-rosegment
1148 Attempt to ensure that only a single read-only, non-code segment is
1149 created. Only useful when used in conjunction with the @option{-z
1150 separate-code} option. The resulting binaries should be smaller than
1151 if @option{-z separate-code} is used on its own. Without this option,
1152 or if @option{--no-rosegment} is specified, the @option{-z separate-code}
1153 option will create two read-only segments, one before the code segment
1156 The name of the options are misleading, but they have been chosen in
1157 order for the linker to be compatible with the LLD and GOLD linkers.
1159 Thse options are only supported by ELF targets.
1163 @cindex strip all symbols
1166 Omit all symbol information from the output file.
1169 @kindex --strip-debug
1170 @cindex strip debugger symbols
1172 @itemx --strip-debug
1173 Omit debugger symbol information (but not all symbols) from the output file.
1175 @kindex --strip-discarded
1176 @kindex --no-strip-discarded
1177 @item --strip-discarded
1178 @itemx --no-strip-discarded
1179 Omit (or do not omit) global symbols defined in discarded sections.
1182 @kindex -plugin-save-temps
1183 @item -plugin-save-temps
1184 Store the plugin ``temporary'' intermediate files permanently.
1188 @cindex input files, displaying
1191 Print the names of the input files as @command{ld} processes them. If
1192 @samp{-t} is given twice then members within archives are also printed.
1193 @samp{-t} output is useful to generate a list of all the object files
1194 and scripts involved in linking, for example, when packaging files for
1195 a linker bug report.
1197 @kindex -T @var{script}
1198 @kindex --script=@var{script}
1199 @cindex script files
1200 @item -T @var{scriptfile}
1201 @itemx --script=@var{scriptfile}
1202 Use @var{scriptfile} as the linker script. This script replaces
1203 @command{ld}'s default linker script (rather than adding to it),
1204 unless the script contains @code{INSERT}, so @var{commandfile} must
1205 specify everything necessary to describe the output file.
1208 If @var{scriptfile} does not exist in the current directory, @code{ld}
1209 looks for it in the directories specified by any preceding @samp{-L}
1212 Command line options that appear before the @option{-T} option can
1213 affect the script, but command line options that appear after it do
1216 Multiple @samp{-T} options will accumulate if they are augmenting the
1217 current script, otherwise the last, non-augmenting, @option{-T} option
1220 There are other ways of specifying linker scripts. See
1221 @xref{--default-script}, @xref{--section-ordering-file}, and
1222 @xref{unrecognised-input-files}.
1224 @kindex -dT @var{script}
1225 @kindex --default-script=@var{script}
1226 @cindex script files
1227 @item -dT @var{scriptfile}
1228 @itemx --default-script=@var{scriptfile}
1229 @anchor{--default-script}
1230 Use @var{scriptfile} as the default linker script. @xref{Scripts}.
1232 This option is similar to the @option{--script} option except that
1233 processing of the script is delayed until after the rest of the
1234 command line has been processed. This allows options placed after the
1235 @option{--default-script} option on the command line to affect the
1236 behaviour of the linker script, which can be important when the linker
1237 command line cannot be directly controlled by the user. (eg because
1238 the command line is being constructed by another tool, such as
1241 @kindex -u @var{symbol}
1242 @kindex --undefined=@var{symbol}
1243 @cindex undefined symbol
1244 @item -u @var{symbol}
1245 @itemx --undefined=@var{symbol}
1246 Force @var{symbol} to be entered in the output file as an undefined
1247 symbol. Doing this may, for example, trigger linking of additional
1248 modules from standard libraries. @samp{-u} may be repeated with
1249 different option arguments to enter additional undefined symbols. This
1250 option is equivalent to the @code{EXTERN} linker script command.
1252 If this option is being used to force additional modules to be pulled
1253 into the link, and if it is an error for the symbol to remain
1254 undefined, then the option @option{--require-defined} should be used
1257 @kindex --require-defined=@var{symbol}
1258 @cindex symbols, require defined
1259 @cindex defined symbol
1260 @item --require-defined=@var{symbol}
1261 Require that @var{symbol} is defined in the output file. This option
1262 is the same as option @option{--undefined} except that if @var{symbol}
1263 is not defined in the output file then the linker will issue an error
1264 and exit. The same effect can be achieved in a linker script by using
1265 @code{EXTERN}, @code{ASSERT} and @code{DEFINED} together. This option
1266 can be used multiple times to require additional symbols.
1269 @cindex constructors
1272 For programs that do not use constructors or destructors, or for ELF
1273 based systems this option is equivalent to @option{-r}: it generates
1274 relocatable output---i.e., an output file that can in turn serve as
1275 input to @command{ld}. For other binaries however the @option{-Ur}
1276 option is similar to @option{-r} but it also resolves references to
1277 constructors and destructors.
1279 For those systems where @option{-r} and @option{-Ur} behave
1280 differently, it does not work to use @option{-Ur} on files that were
1281 themselves linked with @option{-Ur}; once the constructor table has
1282 been built, it cannot be added to. Use @option{-Ur} only for the last
1283 partial link, and @option{-r} for the others.
1285 @kindex --orphan-handling=@var{MODE}
1286 @cindex orphan sections
1287 @cindex sections, orphan
1288 @item --orphan-handling=@var{MODE}
1289 Control how orphan sections are handled. An orphan section is one not
1290 specifically mentioned in a linker script. @xref{Orphan Sections}.
1292 @var{MODE} can have any of the following values:
1296 Orphan sections are placed into a suitable output section following
1297 the strategy described in @ref{Orphan Sections}. The option
1298 @samp{--unique} also affects how sections are placed.
1301 All orphan sections are discarded, by placing them in the
1302 @samp{/DISCARD/} section (@pxref{Output Section Discarding}).
1305 The linker will place the orphan section as for @code{place} and also
1309 The linker will exit with an error if any orphan section is found.
1312 The default if @samp{--orphan-handling} is not given is @code{place}.
1314 @kindex --unique[=@var{SECTION}]
1315 @item --unique[=@var{SECTION}]
1316 Creates a separate output section for every input section matching
1317 @var{SECTION}, or if the optional wildcard @var{SECTION} argument is
1318 missing, for every orphan input section. An orphan section is one not
1319 specifically mentioned in a linker script. You may use this option
1320 multiple times on the command line; It prevents the normal merging of
1321 input sections with the same name, overriding output section assignments
1331 Display the version number for @command{ld}. The @option{-V} option also
1332 lists the supported emulations. See also the description of the
1333 @option{--enable-linker-version} in @ref{Options,,Command-line Options}
1334 which can be used to insert the linker version string into a binary.
1337 @kindex --discard-all
1338 @cindex deleting local symbols
1340 @itemx --discard-all
1341 Delete all local symbols.
1344 @kindex --discard-locals
1345 @cindex local symbols, deleting
1347 @itemx --discard-locals
1348 Delete all temporary local symbols. (These symbols start with
1349 system-specific local label prefixes, typically @samp{.L} for ELF systems
1350 or @samp{L} for traditional a.out systems.)
1352 @kindex -y @var{symbol}
1353 @kindex --trace-symbol=@var{symbol}
1354 @cindex symbol tracing
1355 @item -y @var{symbol}
1356 @itemx --trace-symbol=@var{symbol}
1357 Print the name of each linked file in which @var{symbol} appears. This
1358 option may be given any number of times. On many systems it is necessary
1359 to prepend an underscore.
1361 This option is useful when you have an undefined symbol in your link but
1362 don't know where the reference is coming from.
1364 @kindex -Y @var{path}
1366 Add @var{path} to the default library search path. This option exists
1367 for Solaris compatibility.
1369 @kindex -z @var{keyword}
1370 @item -z @var{keyword}
1371 The recognized keywords are:
1374 @item call-nop=prefix-addr
1375 @itemx call-nop=suffix-nop
1376 @itemx call-nop=prefix-@var{byte}
1377 @itemx call-nop=suffix-@var{byte}
1378 Specify the 1-byte @code{NOP} padding when transforming indirect call
1379 to a locally defined function, foo, via its GOT slot.
1380 @option{call-nop=prefix-addr} generates @code{0x67 call foo}.
1381 @option{call-nop=suffix-nop} generates @code{call foo 0x90}.
1382 @option{call-nop=prefix-@var{byte}} generates @code{@var{byte} call foo}.
1383 @option{call-nop=suffix-@var{byte}} generates @code{call foo @var{byte}}.
1384 Supported for i386 and x86_64.
1386 @item cet-report=none
1387 @itemx cet-report=warning
1388 @itemx cet-report=error
1389 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT and
1390 GNU_PROPERTY_X86_FEATURE_1_SHSTK properties in input .note.gnu.property
1391 section. @option{cet-report=none}, which is the default, will make the
1392 linker not report missing properties in input files.
1393 @option{cet-report=warning} will make the linker issue a warning for
1394 missing properties in input files. @option{cet-report=error} will make
1395 the linker issue an error for missing properties in input files.
1396 Note that @option{ibt} will turn off the missing
1397 GNU_PROPERTY_X86_FEATURE_1_IBT property report and @option{shstk} will
1398 turn off the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property report.
1399 Supported for Linux/i386 and Linux/x86_64.
1403 Combine multiple dynamic relocation sections and sort to improve
1404 dynamic symbol lookup caching. Do not do this if @samp{nocombreloc}.
1408 Generate common symbols with STT_COMMON type during a relocatable
1409 link. Use STT_OBJECT type if @samp{nocommon}.
1411 @item common-page-size=@var{value}
1412 Set the page size most commonly used to @var{value}. Memory image
1413 layout will be optimized to minimize memory pages if the system is
1414 using pages of this size.
1417 Report unresolved symbol references from regular object files. This
1418 is done even if the linker is creating a non-symbolic shared library.
1419 This option is the inverse of @samp{-z undefs}.
1421 @item dynamic-undefined-weak
1422 @itemx nodynamic-undefined-weak
1423 Make undefined weak symbols dynamic when building a dynamic object,
1424 if they are referenced from a regular object file and not forced local
1425 by symbol visibility or versioning. Do not make them dynamic if
1426 @samp{nodynamic-undefined-weak}. If neither option is given, a target
1427 may default to either option being in force, or make some other
1428 selection of undefined weak symbols dynamic. Not all targets support
1432 Marks the object as requiring executable stack.
1435 This option is only meaningful when building a shared object. It makes
1436 the symbols defined by this shared object available for symbol resolution
1437 of subsequently loaded libraries.
1440 This option is only meaningful when building a dynamic executable.
1441 This option marks the executable as requiring global auditing by
1442 setting the @code{DF_1_GLOBAUDIT} bit in the @code{DT_FLAGS_1} dynamic
1443 tag. Global auditing requires that any auditing library defined via
1444 the @option{--depaudit} or @option{-P} command-line options be run for
1445 all dynamic objects loaded by the application.
1448 Generate Intel Indirect Branch Tracking (IBT) enabled PLT entries.
1449 Supported for Linux/i386 and Linux/x86_64.
1452 Generate GNU_PROPERTY_X86_FEATURE_1_IBT in .note.gnu.property section
1453 to indicate compatibility with IBT. This also implies @option{ibtplt}.
1454 Supported for Linux/i386 and Linux/x86_64.
1456 @item indirect-extern-access
1457 @itemx noindirect-extern-access
1458 Generate GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS in
1459 .note.gnu.property section to indicate that object file requires
1460 canonical function pointers and cannot be used with copy relocation.
1461 This option also implies @option{noextern-protected-data} and
1462 @option{nocopyreloc}. Supported for i386 and x86-64.
1464 @option{noindirect-extern-access} removes
1465 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS from .note.gnu.property
1469 This option is only meaningful when building a shared object.
1470 It marks the object so that its runtime initialization will occur
1471 before the runtime initialization of any other objects brought into
1472 the process at the same time. Similarly the runtime finalization of
1473 the object will occur after the runtime finalization of any other
1477 Specify that the dynamic loader should modify its symbol search order
1478 so that symbols in this shared library interpose all other shared
1479 libraries not so marked.
1483 When generating a shared library or other dynamically loadable ELF
1484 object mark it as one that should (by default) only ever be loaded once,
1485 and only in the main namespace (when using @code{dlmopen}). This is
1486 primarily used to mark fundamental libraries such as libc, libpthread et
1487 al which do not usually function correctly unless they are the sole instances
1488 of themselves. This behaviour can be overridden by the @code{dlmopen} caller
1489 and does not apply to certain loading mechanisms (such as audit libraries).
1492 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U48 in .note.gnu.property section
1493 to indicate compatibility with Intel LAM_U48. Supported for Linux/x86_64.
1496 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U57 in .note.gnu.property section
1497 to indicate compatibility with Intel LAM_U57. Supported for Linux/x86_64.
1499 @item lam-u48-report=none
1500 @itemx lam-u48-report=warning
1501 @itemx lam-u48-report=error
1502 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48
1503 property in input .note.gnu.property section.
1504 @option{lam-u48-report=none}, which is the default, will make the
1505 linker not report missing properties in input files.
1506 @option{lam-u48-report=warning} will make the linker issue a warning for
1507 missing properties in input files. @option{lam-u48-report=error} will
1508 make the linker issue an error for missing properties in input files.
1509 Supported for Linux/x86_64.
1511 @item lam-u57-report=none
1512 @itemx lam-u57-report=warning
1513 @itemx lam-u57-report=error
1514 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U57
1515 property in input .note.gnu.property section.
1516 @option{lam-u57-report=none}, which is the default, will make the
1517 linker not report missing properties in input files.
1518 @option{lam-u57-report=warning} will make the linker issue a warning for
1519 missing properties in input files. @option{lam-u57-report=error} will
1520 make the linker issue an error for missing properties in input files.
1521 Supported for Linux/x86_64.
1523 @item lam-report=none
1524 @itemx lam-report=warning
1525 @itemx lam-report=error
1526 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
1527 GNU_PROPERTY_X86_FEATURE_1_LAM_U57 properties in input .note.gnu.property
1528 section. @option{lam-report=none}, which is the default, will make the
1529 linker not report missing properties in input files.
1530 @option{lam-report=warning} will make the linker issue a warning for
1531 missing properties in input files. @option{lam-report=error} will make
1532 the linker issue an error for missing properties in input files.
1533 Supported for Linux/x86_64.
1536 When generating an executable or shared library, mark it to tell the
1537 dynamic linker to defer function call resolution to the point when
1538 the function is called (lazy binding), rather than at load time.
1539 Lazy binding is the default.
1542 Specify that the object's filters be processed immediately at runtime.
1544 @item max-page-size=@var{value}
1545 Set the maximum memory page size supported to @var{value}.
1549 Mark PLT entries with dynamic tags, DT_X86_64_PLT, DT_X86_64_PLTSZ and
1550 DT_X86_64_PLTENT. Since this option stores a non-zero value in the
1551 r_addend field of R_X86_64_JUMP_SLOT relocations, the resulting
1552 executables and shared libraries are incompatible with dynamic linkers,
1553 such as those in older versions of glibc without the change to ignore
1554 r_addend in R_X86_64_GLOB_DAT and R_X86_64_JUMP_SLOT relocations, which
1555 don't ignore the r_addend field of R_X86_64_JUMP_SLOT relocations.
1556 Supported for x86_64.
1559 Allow multiple definitions.
1562 Disable linker generated .dynbss variables used in place of variables
1563 defined in shared libraries. May result in dynamic text relocations.
1566 Specify that the dynamic loader search for dependencies of this object
1567 should ignore any default library search paths.
1570 Specify that the object shouldn't be unloaded at runtime.
1573 Specify that the object is not available to @code{dlopen}.
1576 Specify that the object can not be dumped by @code{dldump}.
1579 Marks the object as not requiring executable stack.
1581 @item noextern-protected-data
1582 Don't treat protected data symbols as external when building a shared
1583 library. This option overrides the linker backend default. It can be
1584 used to work around incorrect relocations against protected data symbols
1585 generated by compiler. Updates on protected data symbols by another
1586 module aren't visible to the resulting shared library. Supported for
1589 @item noreloc-overflow
1590 Disable relocation overflow check. This can be used to disable
1591 relocation overflow check if there will be no dynamic relocation
1592 overflow at run-time. Supported for x86_64.
1595 When generating an executable or shared library, mark it to tell the
1596 dynamic linker to resolve all symbols when the program is started, or
1597 when the shared library is loaded by dlopen, instead of deferring
1598 function call resolution to the point when the function is first
1602 Specify that the object requires @samp{$ORIGIN} handling in paths.
1604 @item pack-relative-relocs
1605 @itemx nopack-relative-relocs
1606 Generate compact relative relocation in position-independent executable
1607 and shared library. It adds @code{DT_RELR}, @code{DT_RELRSZ} and
1608 @code{DT_RELRENT} entries to the dynamic section. It is ignored when
1609 building position-dependent executable and relocatable output.
1610 @option{nopack-relative-relocs} is the default, which disables compact
1611 relative relocation. When linked against the GNU C Library, a
1612 GLIBC_ABI_DT_RELR symbol version dependency on the shared C Library is
1613 added to the output. Supported for i386 and x86-64.
1617 Create an ELF @code{PT_GNU_RELRO} segment header in the object. This
1618 specifies a memory segment that should be made read-only after
1619 relocation, if supported. Specifying @samp{common-page-size} smaller
1620 than the system page size will render this protection ineffective.
1621 Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
1623 @item report-relative-reloc
1624 Report dynamic relative relocations generated by linker. Supported for
1625 Linux/i386 and Linux/x86_64.
1628 @itemx nosectionheader
1629 Generate section header. Don't generate section header if
1630 @samp{nosectionheader} is used. @option{sectionheader} is the default.
1633 @itemx noseparate-code
1634 Create separate code @code{PT_LOAD} segment header in the object. This
1635 specifies a memory segment that should contain only instructions and must
1636 be in wholly disjoint pages from any other data. Don't create separate
1637 code @code{PT_LOAD} segment if @samp{noseparate-code} is used.
1640 Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
1641 to indicate compatibility with Intel Shadow Stack. Supported for
1642 Linux/i386 and Linux/x86_64.
1644 @item stack-size=@var{value}
1645 Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
1646 Specifying zero will override any default non-zero sized
1647 @code{PT_GNU_STACK} segment creation.
1650 @itemx nostart-stop-gc
1651 @cindex start-stop-gc
1652 When @samp{--gc-sections} is in effect, a reference from a retained
1653 section to @code{__start_SECNAME} or @code{__stop_SECNAME} causes all
1654 input sections named @code{SECNAME} to also be retained, if
1655 @code{SECNAME} is representable as a C identifier and either
1656 @code{__start_SECNAME} or @code{__stop_SECNAME} is synthesized by the
1657 linker. @samp{-z start-stop-gc} disables this effect, allowing
1658 sections to be garbage collected as if the special synthesized symbols
1659 were not defined. @samp{-z start-stop-gc} has no effect on a
1660 definition of @code{__start_SECNAME} or @code{__stop_SECNAME} in an
1661 object file or linker script. Such a definition will prevent the
1662 linker providing a synthesized @code{__start_SECNAME} or
1663 @code{__stop_SECNAME} respectively, and therefore the special
1664 treatment by garbage collection for those references.
1666 @item start-stop-visibility=@var{value}
1668 @cindex ELF symbol visibility
1669 Specify the ELF symbol visibility for synthesized
1670 @code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input
1671 Section Example}). @var{value} must be exactly @samp{default},
1672 @samp{internal}, @samp{hidden}, or @samp{protected}. If no @samp{-z
1673 start-stop-visibility} option is given, @samp{protected} is used for
1674 compatibility with historical practice. However, it's highly
1675 recommended to use @samp{-z start-stop-visibility=hidden} in new
1676 programs and shared libraries so that these symbols are not exported
1677 between shared objects, which is not usually what's intended.
1682 Report an error if DT_TEXTREL is set, i.e., if the position-independent
1683 or shared object has dynamic relocations in read-only sections. Don't
1684 report an error if @samp{notext} or @samp{textoff}.
1687 Do not report unresolved symbol references from regular object files,
1688 either when creating an executable, or when creating a shared library.
1689 This option is the inverse of @samp{-z defs}.
1692 @itemx nounique-symbol
1693 Avoid duplicated local symbol names in the symbol string table. Append
1694 ".@code{number}" to duplicated local symbol names if @samp{unique-symbol}
1695 is used. @option{nounique-symbol} is the default.
1697 @item x86-64-baseline
1701 Specify the x86-64 ISA level needed in .note.gnu.property section.
1702 @option{x86-64-baseline} generates @code{GNU_PROPERTY_X86_ISA_1_BASELINE}.
1703 @option{x86-64-v2} generates @code{GNU_PROPERTY_X86_ISA_1_V2}.
1704 @option{x86-64-v3} generates @code{GNU_PROPERTY_X86_ISA_1_V3}.
1705 @option{x86-64-v4} generates @code{GNU_PROPERTY_X86_ISA_1_V4}.
1706 Supported for Linux/i386 and Linux/x86_64.
1708 @item isa-level-report=none
1709 @itemx isa-level-report=all
1710 @itemx isa-level-report=needed
1711 @itemx isa-level-report=used
1712 Specify how to report x86-64 ISA levels in input relocatable files.
1713 @option{isa-level-report=none}, which is the default, will make the
1714 linker not report x86-64 ISA levels in input files.
1715 @option{isa-level-report=all} will make the linker report needed and
1716 used x86-64 ISA levels in input files.
1717 @option{isa-level-report=needed} will make the linker report needed
1718 x86-64 ISA levels in input files.
1719 @option{isa-level-report=used} will make the linker report used
1720 x86-64 ISA levels in input files.
1721 Supported for Linux/i386 and Linux/x86_64.
1725 Other keywords are ignored for Solaris compatibility.
1728 @cindex groups of archives
1729 @item -( @var{archives} -)
1730 @itemx --start-group @var{archives} --end-group
1731 The @var{archives} should be a list of archive files. They may be
1732 either explicit file names, or @samp{-l} options.
1734 The specified archives are searched repeatedly until no new undefined
1735 references are created. Normally, an archive is searched only once in
1736 the order that it is specified on the command line. If a symbol in that
1737 archive is needed to resolve an undefined symbol referred to by an
1738 object in an archive that appears later on the command line, the linker
1739 would not be able to resolve that reference. By grouping the archives,
1740 they will all be searched repeatedly until all possible references are
1743 Using this option has a significant performance cost. It is best to use
1744 it only when there are unavoidable circular references between two or
1747 @kindex --accept-unknown-input-arch
1748 @kindex --no-accept-unknown-input-arch
1749 @item --accept-unknown-input-arch
1750 @itemx --no-accept-unknown-input-arch
1751 Tells the linker to accept input files whose architecture cannot be
1752 recognised. The assumption is that the user knows what they are doing
1753 and deliberately wants to link in these unknown input files. This was
1754 the default behaviour of the linker, before release 2.14. The default
1755 behaviour from release 2.14 onwards is to reject such input files, and
1756 so the @samp{--accept-unknown-input-arch} option has been added to
1757 restore the old behaviour.
1760 @kindex --no-as-needed
1762 @itemx --no-as-needed
1763 This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
1764 on the command line after the @option{--as-needed} option. Normally
1765 the linker will add a DT_NEEDED tag for each dynamic library mentioned
1766 on the command line, regardless of whether the library is actually
1767 needed or not. @option{--as-needed} causes a DT_NEEDED tag to only be
1768 emitted for a library that @emph{at that point in the link} satisfies a
1769 non-weak undefined symbol reference from a regular object file or, if
1770 the library is not found in the DT_NEEDED lists of other needed libraries, a
1771 non-weak undefined symbol reference from another needed dynamic library.
1772 Object files or libraries appearing on the command line @emph{after}
1773 the library in question do not affect whether the library is seen as
1774 needed. This is similar to the rules for extraction of object files
1775 from archives. @option{--no-as-needed} restores the default behaviour.
1777 Note: On Linux based systems the @option{--as-needed} option also has
1778 an affect on the behaviour of the @option{--rpath} and
1779 @option{--rpath-link} options. See the description of
1780 @option{--rpath-link} for more details.
1782 @kindex --add-needed
1783 @kindex --no-add-needed
1785 @itemx --no-add-needed
1786 These two options have been deprecated because of the similarity of
1787 their names to the @option{--as-needed} and @option{--no-as-needed}
1788 options. They have been replaced by @option{--copy-dt-needed-entries}
1789 and @option{--no-copy-dt-needed-entries}.
1791 @kindex -assert @var{keyword}
1792 @item -assert @var{keyword}
1793 This option is ignored for SunOS compatibility.
1797 @kindex -call_shared
1801 Link against dynamic libraries. This is only meaningful on platforms
1802 for which shared libraries are supported. This option is normally the
1803 default on such platforms. The different variants of this option are
1804 for compatibility with various systems. You may use this option
1805 multiple times on the command line: it affects library searching for
1806 @option{-l} options which follow it.
1810 Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
1811 section. This causes the runtime linker to handle lookups in this
1812 object and its dependencies to be performed only inside the group.
1813 @option{--unresolved-symbols=report-all} is implied. This option is
1814 only meaningful on ELF platforms which support shared libraries.
1824 Do not link against shared libraries. This is only meaningful on
1825 platforms for which shared libraries are supported. The different
1826 variants of this option are for compatibility with various systems. You
1827 may use this option multiple times on the command line: it affects
1828 library searching for @option{-l} options which follow it. This
1829 option also implies @option{--unresolved-symbols=report-all}. This
1830 option can be used with @option{-shared}. Doing so means that a
1831 shared library is being created but that all of the library's external
1832 references must be resolved by pulling in entries from static
1837 When creating a shared library, bind references to global symbols to the
1838 definition within the shared library, if any. Normally, it is possible
1839 for a program linked against a shared library to override the definition
1840 within the shared library. This option is only meaningful on ELF
1841 platforms which support shared libraries.
1843 @kindex -Bsymbolic-functions
1844 @item -Bsymbolic-functions
1845 When creating a shared library, bind references to global function
1846 symbols to the definition within the shared library, if any.
1847 This option is only meaningful on ELF platforms which support shared
1850 @kindex -Bno-symbolic
1852 This option can cancel previously specified @samp{-Bsymbolic} and
1853 @samp{-Bsymbolic-functions}.
1855 @kindex --dynamic-list=@var{dynamic-list-file}
1856 @item --dynamic-list=@var{dynamic-list-file}
1857 Specify the name of a dynamic list file to the linker. This is
1858 typically used when creating shared libraries to specify a list of
1859 global symbols whose references shouldn't be bound to the definition
1860 within the shared library, or creating dynamically linked executables
1861 to specify a list of symbols which should be added to the symbol table
1862 in the executable. This option is only meaningful on ELF platforms
1863 which support shared libraries.
1865 The format of the dynamic list is the same as the version node without
1866 scope and node name. See @ref{VERSION} for more information.
1868 @kindex --dynamic-list-data
1869 @item --dynamic-list-data
1870 Include all global data symbols to the dynamic list.
1872 @kindex --dynamic-list-cpp-new
1873 @item --dynamic-list-cpp-new
1874 Provide the builtin dynamic list for C++ operator new and delete. It
1875 is mainly useful for building shared libstdc++.
1877 @kindex --dynamic-list-cpp-typeinfo
1878 @item --dynamic-list-cpp-typeinfo
1879 Provide the builtin dynamic list for C++ runtime type identification.
1881 @kindex --check-sections
1882 @kindex --no-check-sections
1883 @item --check-sections
1884 @itemx --no-check-sections
1885 Asks the linker @emph{not} to check section addresses after they have
1886 been assigned to see if there are any overlaps. Normally the linker will
1887 perform this check, and if it finds any overlaps it will produce
1888 suitable error messages. The linker does know about, and does make
1889 allowances for sections in overlays. The default behaviour can be
1890 restored by using the command-line switch @option{--check-sections}.
1891 Section overlap is not usually checked for relocatable links. You can
1892 force checking in that case by using the @option{--check-sections}
1895 @kindex --copy-dt-needed-entries
1896 @kindex --no-copy-dt-needed-entries
1897 @item --copy-dt-needed-entries
1898 @itemx --no-copy-dt-needed-entries
1899 This option affects the treatment of dynamic libraries referred to
1900 by DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
1901 command line. Normally the linker won't add a DT_NEEDED tag to the
1902 output binary for each library mentioned in a DT_NEEDED tag in an
1903 input dynamic library. With @option{--copy-dt-needed-entries}
1904 specified on the command line however any dynamic libraries that
1905 follow it will have their DT_NEEDED entries added. The default
1906 behaviour can be restored with @option{--no-copy-dt-needed-entries}.
1908 This option also has an effect on the resolution of symbols in dynamic
1909 libraries. With @option{--copy-dt-needed-entries} dynamic libraries
1910 mentioned on the command line will be recursively searched, following
1911 their DT_NEEDED tags to other libraries, in order to resolve symbols
1912 required by the output binary. With the default setting however
1913 the searching of dynamic libraries that follow it will stop with the
1914 dynamic library itself. No DT_NEEDED links will be traversed to resolve
1917 @cindex cross reference table
1920 Output a cross reference table. If a linker map file is being
1921 generated, the cross reference table is printed to the map file.
1922 Otherwise, it is printed on the standard output.
1924 The format of the table is intentionally simple, so that it may be
1925 easily processed by a script if necessary. The symbols are printed out,
1926 sorted by name. For each symbol, a list of file names is given. If the
1927 symbol is defined, the first file listed is the location of the
1928 definition. If the symbol is defined as a common value then any files
1929 where this happens appear next. Finally any files that reference the
1932 @cindex ctf variables
1933 @kindex --ctf-variables
1934 @kindex --no-ctf-variables
1935 @item --ctf-variables
1936 @item --no-ctf-variables
1937 The CTF debuginfo format supports a section which encodes the names and
1938 types of variables found in the program which do not appear in any symbol
1939 table. These variables clearly cannot be looked up by address by
1940 conventional debuggers, so the space used for their types and names is
1941 usually wasted: the types are usually small but the names are often not.
1942 @option{--ctf-variables} causes the generation of such a section.
1943 The default behaviour can be restored with @option{--no-ctf-variables}.
1945 @cindex ctf type sharing
1946 @kindex --ctf-share-types
1947 @item --ctf-share-types=@var{method}
1948 Adjust the method used to share types between translation units in CTF.
1951 @item share-unconflicted
1952 Put all types that do not have ambiguous definitions into the shared dictionary,
1953 where debuggers can easily access them, even if they only occur in one
1954 translation unit. This is the default.
1956 @item share-duplicated
1957 Put only types that occur in multiple translation units into the shared
1958 dictionary: types with only one definition go into per-translation-unit
1959 dictionaries. Types with ambiguous definitions in multiple translation units
1960 always go into per-translation-unit dictionaries. This tends to make the CTF
1961 larger, but may reduce the amount of CTF in the shared dictionary. For very
1962 large projects this may speed up opening the CTF and save memory in the CTF
1963 consumer at runtime.
1966 @cindex common allocation
1967 @kindex --no-define-common
1968 @item --no-define-common
1969 This option inhibits the assignment of addresses to common symbols.
1970 The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
1971 @xref{Miscellaneous Commands}.
1973 The @samp{--no-define-common} option allows decoupling
1974 the decision to assign addresses to Common symbols from the choice
1975 of the output file type; otherwise a non-Relocatable output type
1976 forces assigning addresses to Common symbols.
1977 Using @samp{--no-define-common} allows Common symbols that are referenced
1978 from a shared library to be assigned addresses only in the main program.
1979 This eliminates the unused duplicate space in the shared library,
1980 and also prevents any possible confusion over resolving to the wrong
1981 duplicate when there are many dynamic modules with specialized search
1982 paths for runtime symbol resolution.
1984 @cindex group allocation in linker script
1985 @cindex section groups
1987 @kindex --force-group-allocation
1988 @item --force-group-allocation
1989 This option causes the linker to place section group members like
1990 normal input sections, and to delete the section groups. This is the
1991 default behaviour for a final link but this option can be used to
1992 change the behaviour of a relocatable link (@samp{-r}). The script
1993 command @code{FORCE_GROUP_ALLOCATION} has the same
1994 effect. @xref{Miscellaneous Commands}.
1996 @cindex symbols, from command line
1997 @kindex --defsym=@var{symbol}=@var{exp}
1998 @item --defsym=@var{symbol}=@var{expression}
1999 Create a global symbol in the output file, containing the absolute
2000 address given by @var{expression}. You may use this option as many
2001 times as necessary to define multiple symbols in the command line. A
2002 limited form of arithmetic is supported for the @var{expression} in this
2003 context: you may give a hexadecimal constant or the name of an existing
2004 symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
2005 constants or symbols. If you need more elaborate expressions, consider
2006 using the linker command language from a script (@pxref{Assignments}).
2007 @emph{Note:} there should be no white space between @var{symbol}, the
2008 equals sign (``@key{=}''), and @var{expression}.
2010 The linker processes @samp{--defsym} arguments and @samp{-T} arguments
2011 in order, placing @samp{--defsym} before @samp{-T} will define the
2012 symbol before the linker script from @samp{-T} is processed, while
2013 placing @samp{--defsym} after @samp{-T} will define the symbol after
2014 the linker script has been processed. This difference has
2015 consequences for expressions within the linker script that use the
2016 @samp{--defsym} symbols, which order is correct will depend on what
2017 you are trying to achieve.
2019 @cindex demangling, from command line
2020 @kindex --demangle[=@var{style}]
2021 @kindex --no-demangle
2022 @item --demangle[=@var{style}]
2023 @itemx --no-demangle
2024 These options control whether to demangle symbol names in error messages
2025 and other output. When the linker is told to demangle, it tries to
2026 present symbol names in a readable fashion: it strips leading
2027 underscores if they are used by the object file format, and converts C++
2028 mangled symbol names into user readable names. Different compilers have
2029 different mangling styles. The optional demangling style argument can be used
2030 to choose an appropriate demangling style for your compiler. The linker will
2031 demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
2032 is set. These options may be used to override the default.
2034 @cindex dynamic linker, from command line
2035 @kindex -I@var{file}
2036 @kindex --dynamic-linker=@var{file}
2038 @itemx --dynamic-linker=@var{file}
2039 Set the name of the dynamic linker. This is only meaningful when
2040 generating dynamically linked ELF executables. The default dynamic
2041 linker is normally correct; don't use this unless you know what you are
2044 @kindex --no-dynamic-linker
2045 @item --no-dynamic-linker
2046 When producing an executable file, omit the request for a dynamic
2047 linker to be used at load-time. This is only meaningful for ELF
2048 executables that contain dynamic relocations, and usually requires
2049 entry point code that is capable of processing these relocations.
2051 @kindex --embedded-relocs
2052 @item --embedded-relocs
2053 This option is similar to the @option{--emit-relocs} option except
2054 that the relocs are stored in a target-specific section. This option
2055 is only supported by the @samp{BFIN}, @samp{CR16} and @emph{M68K}
2058 @kindex --disable-multiple-abs-defs
2059 @item --disable-multiple-abs-defs
2060 Do not allow multiple definitions with symbols included
2061 in filename invoked by -R or --just-symbols
2063 @kindex --fatal-warnings
2064 @kindex --no-fatal-warnings
2065 @item --fatal-warnings
2066 @itemx --no-fatal-warnings
2067 Treat all warnings as errors. The default behaviour can be restored
2068 with the option @option{--no-fatal-warnings}.
2071 @kindex --no-warnings
2073 @itemx --no-warnings
2074 Do not display any warning or error messages. This overrides
2075 @option{--fatal-warnings} if it has been enabled. This option can be
2076 used when it is known that the output binary will not work, but there
2077 is still a need to create it.
2079 @kindex --force-exe-suffix
2080 @item --force-exe-suffix
2081 Make sure that an output file has a .exe suffix.
2083 If a successfully built fully linked output file does not have a
2084 @code{.exe} or @code{.dll} suffix, this option forces the linker to copy
2085 the output file to one of the same name with a @code{.exe} suffix. This
2086 option is useful when using unmodified Unix makefiles on a Microsoft
2087 Windows host, since some versions of Windows won't run an image unless
2088 it ends in a @code{.exe} suffix.
2090 @kindex --gc-sections
2091 @kindex --no-gc-sections
2092 @cindex garbage collection
2094 @itemx --no-gc-sections
2095 Enable garbage collection of unused input sections. It is ignored on
2096 targets that do not support this option. The default behaviour (of not
2097 performing this garbage collection) can be restored by specifying
2098 @samp{--no-gc-sections} on the command line. Note that garbage
2099 collection for COFF and PE format targets is supported, but the
2100 implementation is currently considered to be experimental.
2102 @samp{--gc-sections} decides which input sections are used by
2103 examining symbols and relocations. The section containing the entry
2104 symbol and all sections containing symbols undefined on the
2105 command-line will be kept, as will sections containing symbols
2106 referenced by dynamic objects. Note that when building shared
2107 libraries, the linker must assume that any visible symbol is
2108 referenced. Once this initial set of sections has been determined,
2109 the linker recursively marks as used any section referenced by their
2110 relocations. See @samp{--entry}, @samp{--undefined}, and
2111 @samp{--gc-keep-exported}.
2113 This option can be set when doing a partial link (enabled with option
2114 @samp{-r}). In this case the root of symbols kept must be explicitly
2115 specified either by one of the options @samp{--entry},
2116 @samp{--undefined}, or @samp{--gc-keep-exported} or by a @code{ENTRY}
2117 command in the linker script.
2119 As a GNU extension, ELF input sections marked with the
2120 @code{SHF_GNU_RETAIN} flag will not be garbage collected.
2122 @kindex --print-gc-sections
2123 @kindex --no-print-gc-sections
2124 @cindex garbage collection
2125 @item --print-gc-sections
2126 @itemx --no-print-gc-sections
2127 List all sections removed by garbage collection. The listing is
2128 printed on stderr. This option is only effective if garbage
2129 collection has been enabled via the @samp{--gc-sections}) option. The
2130 default behaviour (of not listing the sections that are removed) can
2131 be restored by specifying @samp{--no-print-gc-sections} on the command
2134 @kindex --gc-keep-exported
2135 @cindex garbage collection
2136 @item --gc-keep-exported
2137 When @samp{--gc-sections} is enabled, this option prevents garbage
2138 collection of unused input sections that contain global symbols having
2139 default or protected visibility. This option is intended to be used for
2140 executables where unreferenced sections would otherwise be garbage
2141 collected regardless of the external visibility of contained symbols.
2142 Note that this option has no effect when linking shared objects since
2143 it is already the default behaviour. This option is only supported for
2146 @kindex --print-output-format
2147 @cindex output format
2148 @item --print-output-format
2149 Print the name of the default output format (perhaps influenced by
2150 other command-line options). This is the string that would appear
2151 in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
2153 @kindex --print-memory-usage
2154 @cindex memory usage
2155 @item --print-memory-usage
2156 Print used size, total size and used size of memory regions created with
2157 the @ref{MEMORY} command. This is useful on embedded targets to have a
2158 quick view of amount of free memory. The format of the output has one
2159 headline and one line per region. It is both human readable and easily
2160 parsable by tools. Here is an example of an output:
2163 Memory region Used Size Region Size %age Used
2164 ROM: 256 KB 1 MB 25.00%
2165 RAM: 32 B 2 GB 0.00%
2172 Print a summary of the command-line options on the standard output and exit.
2174 @kindex --target-help
2176 Print a summary of all target-specific options on the standard output and exit.
2178 @kindex -Map=@var{mapfile}
2179 @item -Map=@var{mapfile}
2180 Print a link map to the file @var{mapfile}. See the description of the
2181 @option{-M} option, above. If @var{mapfile} is just the character
2182 @code{-} then the map will be written to stdout.
2184 Specifying a directory as @var{mapfile} causes the linker map to be
2185 written as a file inside the directory. Normally name of the file
2186 inside the directory is computed as the basename of the @var{output}
2187 file with @code{.map} appended. If however the special character
2188 @code{%} is used then this will be replaced by the full path of the
2189 output file. Additionally if there are any characters after the
2190 @var{%} symbol then @code{.map} will no longer be appended.
2193 -o foo.exe -Map=bar [Creates ./bar]
2194 -o ../dir/foo.exe -Map=bar [Creates ./bar]
2195 -o foo.exe -Map=../dir [Creates ../dir/foo.exe.map]
2196 -o ../dir2/foo.exe -Map=../dir [Creates ../dir/foo.exe.map]
2197 -o foo.exe -Map=% [Creates ./foo.exe.map]
2198 -o ../dir/foo.exe -Map=% [Creates ../dir/foo.exe.map]
2199 -o foo.exe -Map=%.bar [Creates ./foo.exe.bar]
2200 -o ../dir/foo.exe -Map=%.bar [Creates ../dir/foo.exe.bar]
2201 -o ../dir2/foo.exe -Map=../dir/% [Creates ../dir/../dir2/foo.exe.map]
2202 -o ../dir2/foo.exe -Map=../dir/%.bar [Creates ../dir/../dir2/foo.exe.bar]
2205 It is an error to specify more than one @code{%} character.
2207 If the map file already exists then it will be overwritten by this
2210 @cindex memory usage
2211 @kindex --no-keep-memory
2212 @item --no-keep-memory
2213 @command{ld} normally optimizes for speed over memory usage by caching the
2214 symbol tables of input files in memory. This option tells @command{ld} to
2215 instead optimize for memory usage, by rereading the symbol tables as
2216 necessary. This may be required if @command{ld} runs out of memory space
2217 while linking a large executable.
2219 @kindex --no-undefined
2222 @item --no-undefined
2224 Report unresolved symbol references from regular object files. This
2225 is done even if the linker is creating a non-symbolic shared library.
2226 The switch @option{--[no-]allow-shlib-undefined} controls the
2227 behaviour for reporting unresolved references found in shared
2228 libraries being linked in.
2230 The effects of this option can be reverted by using @code{-z undefs}.
2232 @kindex --allow-multiple-definition
2234 @item --allow-multiple-definition
2236 Normally when a symbol is defined multiple times, the linker will
2237 report a fatal error. These options allow multiple definitions and the
2238 first definition will be used.
2240 @kindex --allow-shlib-undefined
2241 @kindex --no-allow-shlib-undefined
2242 @item --allow-shlib-undefined
2243 @itemx --no-allow-shlib-undefined
2244 Allows or disallows undefined symbols in shared libraries.
2245 This switch is similar to @option{--no-undefined} except that it
2246 determines the behaviour when the undefined symbols are in a
2247 shared library rather than a regular object file. It does not affect
2248 how undefined symbols in regular object files are handled.
2250 The default behaviour is to report errors for any undefined symbols
2251 referenced in shared libraries if the linker is being used to create
2252 an executable, but to allow them if the linker is being used to create
2255 The reasons for allowing undefined symbol references in shared
2256 libraries specified at link time are that:
2260 A shared library specified at link time may not be the same as the one
2261 that is available at load time, so the symbol might actually be
2262 resolvable at load time.
2264 There are some operating systems, eg BeOS and HPPA, where undefined
2265 symbols in shared libraries are normal.
2267 The BeOS kernel for example patches shared libraries at load time to
2268 select whichever function is most appropriate for the current
2269 architecture. This is used, for example, to dynamically select an
2270 appropriate memset function.
2273 @kindex --error-handling-script=@var{scriptname}
2274 @item --error-handling-script=@var{scriptname}
2275 If this option is provided then the linker will invoke
2276 @var{scriptname} whenever an error is encountered. Currently however
2277 only two kinds of error are supported: missing symbols and missing
2278 libraries. Two arguments will be passed to script: the keyword
2279 ``undefined-symbol'' or `missing-lib'' and the @var{name} of the
2280 undefined symbol or missing library. The intention is that the script
2281 will provide suggestions to the user as to where the symbol or library
2282 might be found. After the script has finished then the normal linker
2283 error message will be displayed.
2285 The availability of this option is controlled by a configure time
2286 switch, so it may not be present in specific implementations.
2288 @kindex --no-undefined-version
2289 @item --no-undefined-version
2290 Normally when a symbol has an undefined version, the linker will ignore
2291 it. This option disallows symbols with undefined version and a fatal error
2292 will be issued instead.
2294 @kindex --default-symver
2295 @item --default-symver
2296 Create and use a default symbol version (the soname) for unversioned
2299 @kindex --default-imported-symver
2300 @item --default-imported-symver
2301 Create and use a default symbol version (the soname) for unversioned
2304 @kindex --no-warn-mismatch
2305 @item --no-warn-mismatch
2306 Normally @command{ld} will give an error if you try to link together input
2307 files that are mismatched for some reason, perhaps because they have
2308 been compiled for different processors or for different endiannesses.
2309 This option tells @command{ld} that it should silently permit such possible
2310 errors. This option should only be used with care, in cases when you
2311 have taken some special action that ensures that the linker errors are
2314 @kindex --no-warn-search-mismatch
2315 @item --no-warn-search-mismatch
2316 Normally @command{ld} will give a warning if it finds an incompatible
2317 library during a library search. This option silences the warning.
2319 @kindex --no-whole-archive
2320 @item --no-whole-archive
2321 Turn off the effect of the @option{--whole-archive} option for subsequent
2324 @cindex output file after errors
2325 @kindex --noinhibit-exec
2326 @item --noinhibit-exec
2327 Retain the executable output file whenever it is still usable.
2328 Normally, the linker will not produce an output file if it encounters
2329 errors during the link process; it exits without writing an output file
2330 when it issues any error whatsoever.
2334 Only search library directories explicitly specified on the
2335 command line. Library directories specified in linker scripts
2336 (including linker scripts specified on the command line) are ignored.
2338 @ifclear SingleFormat
2339 @kindex --oformat=@var{output-format}
2340 @item --oformat=@var{output-format}
2341 @command{ld} may be configured to support more than one kind of object
2342 file. If your @command{ld} is configured this way, you can use the
2343 @samp{--oformat} option to specify the binary format for the output
2344 object file. Even when @command{ld} is configured to support alternative
2345 object formats, you don't usually need to specify this, as @command{ld}
2346 should be configured to produce as a default output format the most
2347 usual format on each machine. @var{output-format} is a text string, the
2348 name of a particular format supported by the BFD libraries. (You can
2349 list the available binary formats with @samp{objdump -i}.) The script
2350 command @code{OUTPUT_FORMAT} can also specify the output format, but
2351 this option overrides it. @xref{BFD}.
2354 @kindex --out-implib
2355 @item --out-implib @var{file}
2356 Create an import library in @var{file} corresponding to the executable
2357 the linker is generating (eg. a DLL or ELF program). This import
2358 library (which should be called @code{*.dll.a} or @code{*.a} for DLLs)
2359 may be used to link clients against the generated executable; this
2360 behaviour makes it possible to skip a separate import library creation
2361 step (eg. @code{dlltool} for DLLs). This option is only available for
2362 the i386 PE and ELF targetted ports of the linker.
2365 @kindex --pic-executable
2367 @itemx --pic-executable
2368 @cindex position independent executables
2369 Create a position independent executable. This is currently only
2370 supported on ELF platforms. Position independent executables are
2371 relocated by the dynamic linker to the virtual address the OS chooses
2372 for them, which can vary between invocations. They are marked ET_DYN
2373 in the ELF file header, but differ from shared libraries in a number
2374 of ways. In particular, defined symbols in a PIE by default can not
2375 be overridden by another object as they can be in a shared library.
2379 @cindex position dependent executables
2380 Create a position dependent executable. This is the default.
2384 This option is ignored for Linux compatibility.
2388 This option is ignored for SVR4 compatibility.
2391 @cindex synthesizing linker
2392 @cindex relaxing addressing modes
2396 An option with machine dependent effects.
2398 This option is only supported on a few targets.
2401 @xref{H8/300,,@command{ld} and the H8/300}.
2404 @xref{Xtensa,, @command{ld} and Xtensa Processors}.
2407 @xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
2410 @xref{Nios II,,@command{ld} and the Altera Nios II}.
2413 @xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}.
2416 On some platforms the @option{--relax} option performs target specific,
2417 global optimizations that become possible when the linker resolves
2418 addressing in the program, such as relaxing address modes,
2419 synthesizing new instructions, selecting shorter version of current
2420 instructions, and combining constant values.
2422 On some platforms these link time global optimizations may make symbolic
2423 debugging of the resulting executable impossible.
2425 This is known to be the case for the Matsushita MN10200 and MN10300
2426 family of processors.
2429 On platforms where the feature is supported, the option
2430 @option{--no-relax} will disable it.
2432 On platforms where the feature is not supported, both @option{--relax}
2433 and @option{--no-relax} are accepted, but ignored.
2435 @cindex retaining specified symbols
2436 @cindex stripping all but some symbols
2437 @cindex symbols, retaining selectively
2438 @kindex --retain-symbols-file=@var{filename}
2439 @item --retain-symbols-file=@var{filename}
2440 Retain @emph{only} the symbols listed in the file @var{filename},
2441 discarding all others. @var{filename} is simply a flat file, with one
2442 symbol name per line. This option is especially useful in environments
2446 where a large global symbol table is accumulated gradually, to conserve
2449 @samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
2450 or symbols needed for relocations.
2452 You may only specify @samp{--retain-symbols-file} once in the command
2453 line. It overrides @samp{-s} and @samp{-S}.
2456 @item -rpath=@var{dir}
2457 @cindex runtime library search path
2458 @kindex -rpath=@var{dir}
2459 Add a directory to the runtime library search path. This is used when
2460 linking an ELF executable with shared objects. All @option{-rpath}
2461 arguments are concatenated and passed to the runtime linker, which uses
2462 them to locate shared objects at runtime.
2464 The @option{-rpath} option is also used when locating shared objects which
2465 are needed by shared objects explicitly included in the link; see the
2466 description of the @option{-rpath-link} option. Searching @option{-rpath}
2467 in this way is only supported by native linkers and cross linkers which
2468 have been configured with the @option{--with-sysroot} option.
2470 If @option{-rpath} is not used when linking an ELF executable, the
2471 contents of the environment variable @code{LD_RUN_PATH} will be used if it
2474 The @option{-rpath} option may also be used on SunOS. By default, on
2475 SunOS, the linker will form a runtime search path out of all the
2476 @option{-L} options it is given. If a @option{-rpath} option is used, the
2477 runtime search path will be formed exclusively using the @option{-rpath}
2478 options, ignoring the @option{-L} options. This can be useful when using
2479 gcc, which adds many @option{-L} options which may be on NFS mounted
2482 For compatibility with other ELF linkers, if the @option{-R} option is
2483 followed by a directory name, rather than a file name, it is treated as
2484 the @option{-rpath} option.
2488 @cindex link-time runtime library search path
2489 @kindex -rpath-link=@var{dir}
2490 @item -rpath-link=@var{dir}
2491 When using ELF or SunOS, one shared library may require another. This
2492 happens when an @code{ld -shared} link includes a shared library as one
2495 When the linker encounters such a dependency when doing a non-shared,
2496 non-relocatable link, it will automatically try to locate the required
2497 shared library and include it in the link, if it is not included
2498 explicitly. In such a case, several directories are searched as
2499 described below. The @option{-rpath-link} option specifies the first
2500 set of directories to search. This option may specify a sequence of
2501 directory names either by providing a list of names separated by
2502 colons, or by appearing multiple times.
2504 The tokens @var{$ORIGIN} and @var{$LIB} can appear in these search
2505 directories. They will be replaced by the full path to the directory
2506 containing the program or shared object in the case of @var{$ORIGIN}
2507 and either @samp{lib} - for 32-bit binaries - or @samp{lib64} - for
2508 64-bit binaries - in the case of @var{$LIB}.
2510 The alternative form of these tokens - @var{$@{ORIGIN@}} and
2511 @var{$@{LIB@}} can also be used. The token @var{$PLATFORM} is not
2514 The @option{--rpath-link} option should be used with caution as it
2515 overrides the search path that may have been hard compiled into a
2516 shared library. In such a case it is possible to unintentionally use
2517 a different search path than the runtime linker would have used.
2519 When additional shared libraries are required, the linker will search
2520 directories in the order listed below in order to find them. Note
2521 however that this only applies to additional libraries needed to
2522 satisfy already included shared libraries. It does @emph{not}
2523 apply to libraries that are included via the @option{-l} command line
2524 option. Searches for @option{-l} libraries are only conducted in
2525 directories specified by the @option{-L} option (@pxref{-L}).
2529 Any directories specified by @option{-rpath-link} options.
2531 Any directories specified by @option{-rpath} options. The difference
2532 between @option{-rpath} and @option{-rpath-link} is that directories
2533 specified by @option{-rpath} options are included in the executable and
2534 used at runtime, whereas the @option{-rpath-link} option is only effective
2535 at link time. Searching @option{-rpath} in this way is only supported
2536 by native linkers and cross linkers which have been configured with
2537 the @option{--with-sysroot} option.
2539 On an ELF system, for native linkers, if the @option{-rpath} and
2540 @option{-rpath-link} options were not used, search the contents of the
2541 environment variable @code{LD_RUN_PATH}.
2543 On SunOS, if the @option{-rpath} option was not used, search any
2544 directories specified using @option{-L} options.
2546 For a native linker, search the contents of the environment
2547 variable @code{LD_LIBRARY_PATH}.
2549 For a native ELF linker, the directories in @code{DT_RUNPATH} or
2550 @code{DT_RPATH} of a shared library are searched for shared
2551 libraries needed by it. The @code{DT_RPATH} entries are ignored if
2552 @code{DT_RUNPATH} entries exist.
2554 For a linker for a Linux system, if the file @file{/etc/ld.so.conf}
2555 exists, the list of directories found in that file. Note: the path
2556 to this file is prefixed with the @code{sysroot} value, if that is
2557 defined, and then any @code{prefix} string if the linker was
2558 configured with the @command{--prefix=<path>} option.
2560 For a native linker on a FreeBSD system, any directories specified by
2561 the @code{_PATH_ELF_HINTS} macro defined in the @file{elf-hints.h}
2564 Any directories specified by a @code{SEARCH_DIR} command in a
2565 linker script given on the command line, including scripts specified
2566 by @option{-T} (but not @option{-dT}).
2568 The default directories, normally @file{/lib} and @file{/usr/lib}.
2570 Any directories specified by a plugin LDPT_SET_EXTRA_LIBRARY_PATH.
2572 Any directories specified by a @code{SEARCH_DIR} command in a default
2576 Note however on Linux based systems there is an additional caveat: If
2577 the @option{--as-needed} option is active @emph{and} a shared library
2578 is located which would normally satisfy the search @emph{and} this
2579 library does not have DT_NEEDED tag for @file{libc.so}
2580 @emph{and} there is a shared library later on in the set of search
2581 directories which also satisfies the search @emph{and}
2582 this second shared library does have a DT_NEEDED tag for
2583 @file{libc.so} @emph{then} the second library will be selected instead
2586 If the required shared library is not found, the linker will issue a
2587 warning and continue with the link.
2591 @kindex --section-ordering-file
2592 @item --section-ordering-file=@var{script}
2593 @anchor{--section-ordering-file}
2594 This option is used to augment the current linker script with
2595 additional mapping of input sections to output sections. This file
2596 must use the same syntax for @code{SECTIONS} as is used in normal
2597 linker scripts, but it should not do anything other than place input
2598 sections into output sections. @pxref{SECTIONS}
2600 A second constraint on the section ordering script is that it can only
2601 reference output sections that are already defined by whichever linker
2602 script is currently in use. (Ie the default linker script or a script
2603 specified on the command line). The benefit of the section ordering
2604 script however is that the input sections are mapped to the start of
2605 the output sections, so that they can ensure the ordering of sections
2606 in the output section. For example, imagine that the default linker
2607 script looks like this:
2611 .text : @{ *(.text.hot) ; *(.text .text.*) @}
2612 .data : @{ *(.data.big) ; *(.data .data.*) @}
2616 Then if a section ordering file like this is used:
2619 .text : @{ *(.text.first) ; *(.text.z*) @}
2620 .data : @{ foo.o(.data.first) ; *(.data.small) @}
2623 This would be equivalent to a linker script like this:
2627 .text : @{ *(.text.first) ; *(.text.z*) ; *(.text.hot) ; *(.text .text.*) @}
2628 .data : @{ foo.o(.data.first) ; *(.data.small) ; *(.data.big) ; *(.data .data.*) @}
2632 The advantage of the section ordering file is that it can be used to
2633 order those sections that matter to the user without having to worry
2634 about any other sections, or memory regions, or anything else.
2640 @cindex shared libraries
2641 Create a shared library. This is currently only supported on ELF, XCOFF
2642 and SunOS platforms. On SunOS, the linker will automatically create a
2643 shared library if the @option{-e} option is not used and there are
2644 undefined symbols in the link.
2646 @kindex --sort-common
2648 @itemx --sort-common=ascending
2649 @itemx --sort-common=descending
2650 This option tells @command{ld} to sort the common symbols by alignment in
2651 ascending or descending order when it places them in the appropriate output
2652 sections. The symbol alignments considered are sixteen-byte or larger,
2653 eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
2654 between symbols due to alignment constraints. If no sorting order is
2655 specified, then descending order is assumed.
2657 @kindex --sort-section=name
2658 @item --sort-section=name
2659 This option will apply @code{SORT_BY_NAME} to all wildcard section
2660 patterns in the linker script.
2662 @kindex --sort-section=alignment
2663 @item --sort-section=alignment
2664 This option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
2665 patterns in the linker script.
2667 @kindex --spare-dynamic-tags
2668 @item --spare-dynamic-tags=@var{count}
2669 This option specifies the number of empty slots to leave in the
2670 .dynamic section of ELF shared objects. Empty slots may be needed by
2671 post processing tools, such as the prelinker. The default is 5.
2673 @kindex --split-by-file
2674 @item --split-by-file[=@var{size}]
2675 Similar to @option{--split-by-reloc} but creates a new output section for
2676 each input file when @var{size} is reached. @var{size} defaults to a
2677 size of 1 if not given.
2679 @kindex --split-by-reloc
2680 @item --split-by-reloc[=@var{count}]
2681 Tries to creates extra sections in the output file so that no single
2682 output section in the file contains more than @var{count} relocations.
2683 This is useful when generating huge relocatable files for downloading into
2684 certain real time kernels with the COFF object file format; since COFF
2685 cannot represent more than 65535 relocations in a single section. Note
2686 that this will fail to work with object file formats which do not
2687 support arbitrary sections. The linker will not split up individual
2688 input sections for redistribution, so if a single input section contains
2689 more than @var{count} relocations one output section will contain that
2690 many relocations. @var{count} defaults to a value of 32768.
2694 Compute and display statistics about the operation of the linker, such
2695 as execution time and memory usage.
2697 @kindex --sysroot=@var{directory}
2698 @item --sysroot=@var{directory}
2699 Use @var{directory} as the location of the sysroot, overriding the
2700 configure-time default. This option is only supported by linkers
2701 that were configured using @option{--with-sysroot}.
2705 This is used by COFF/PE based targets to create a task-linked object
2706 file where all of the global symbols have been converted to statics.
2708 @kindex --traditional-format
2709 @cindex traditional format
2710 @item --traditional-format
2711 For some targets, the output of @command{ld} is different in some ways from
2712 the output of some existing linker. This switch requests @command{ld} to
2713 use the traditional format instead.
2716 For example, on SunOS, @command{ld} combines duplicate entries in the
2717 symbol string table. This can reduce the size of an output file with
2718 full debugging information by over 30 percent. Unfortunately, the SunOS
2719 @code{dbx} program can not read the resulting program (@code{gdb} has no
2720 trouble). The @samp{--traditional-format} switch tells @command{ld} to not
2721 combine duplicate entries.
2723 @kindex --section-start=@var{sectionname}=@var{org}
2724 @item --section-start=@var{sectionname}=@var{org}
2725 Locate a section in the output file at the absolute
2726 address given by @var{org}. You may use this option as many
2727 times as necessary to locate multiple sections in the command
2729 @var{org} must be a single hexadecimal integer;
2730 for compatibility with other linkers, you may omit the leading
2731 @samp{0x} usually associated with hexadecimal values. @emph{Note:} there
2732 should be no white space between @var{sectionname}, the equals
2733 sign (``@key{=}''), and @var{org}.
2735 @kindex -Tbss=@var{org}
2736 @kindex -Tdata=@var{org}
2737 @kindex -Ttext=@var{org}
2738 @cindex segment origins, cmd line
2739 @item -Tbss=@var{org}
2740 @itemx -Tdata=@var{org}
2741 @itemx -Ttext=@var{org}
2742 Same as @option{--section-start}, with @code{.bss}, @code{.data} or
2743 @code{.text} as the @var{sectionname}.
2745 @kindex -Ttext-segment=@var{org}
2746 @item -Ttext-segment=@var{org}
2747 @cindex text segment origin, cmd line
2748 When creating an ELF executable, it will set the address of the first
2749 byte of the text segment. Note that when @option{-pie} is used with
2750 @option{-Ttext-segment=@var{org}}, the output executable is marked
2751 ET_EXEC so that the address of the first byte of the text segment will
2752 be guaranteed to be @var{org} at run time.
2754 @kindex -Trodata-segment=@var{org}
2755 @item -Trodata-segment=@var{org}
2756 @cindex rodata segment origin, cmd line
2757 When creating an ELF executable or shared object for a target where
2758 the read-only data is in its own segment separate from the executable
2759 text, it will set the address of the first byte of the read-only data segment.
2761 @kindex -Tldata-segment=@var{org}
2762 @item -Tldata-segment=@var{org}
2763 @cindex ldata segment origin, cmd line
2764 When creating an ELF executable or shared object for x86-64 medium memory
2765 model, it will set the address of the first byte of the ldata segment.
2767 @kindex --unresolved-symbols
2768 @item --unresolved-symbols=@var{method}
2769 Determine how to handle unresolved symbols. There are four possible
2770 values for @samp{method}:
2774 Do not report any unresolved symbols.
2777 Report all unresolved symbols. This is the default.
2779 @item ignore-in-object-files
2780 Report unresolved symbols that are contained in shared libraries, but
2781 ignore them if they come from regular object files.
2783 @item ignore-in-shared-libs
2784 Report unresolved symbols that come from regular object files, but
2785 ignore them if they come from shared libraries. This can be useful
2786 when creating a dynamic binary and it is known that all the shared
2787 libraries that it should be referencing are included on the linker's
2791 The behaviour for shared libraries on their own can also be controlled
2792 by the @option{--[no-]allow-shlib-undefined} option.
2794 Normally the linker will generate an error message for each reported
2795 unresolved symbol but the option @option{--warn-unresolved-symbols}
2796 can change this to a warning.
2798 @kindex --verbose[=@var{NUMBER}]
2799 @cindex verbose[=@var{NUMBER}]
2801 @itemx --verbose[=@var{NUMBER}]
2802 Display the version number for @command{ld} and list the linker emulations
2803 supported. Display which input files can and cannot be opened. Display
2804 the linker script being used by the linker. If the optional @var{NUMBER}
2805 argument > 1, plugin symbol status will also be displayed.
2807 @kindex --version-script=@var{version-scriptfile}
2808 @cindex version script, symbol versions
2809 @item --version-script=@var{version-scriptfile}
2810 Specify the name of a version script to the linker. This is typically
2811 used when creating shared libraries to specify additional information
2812 about the version hierarchy for the library being created. This option
2813 is only fully supported on ELF platforms which support shared libraries;
2814 see @ref{VERSION}. It is partially supported on PE platforms, which can
2815 use version scripts to filter symbol visibility in auto-export mode: any
2816 symbols marked @samp{local} in the version script will not be exported.
2819 @kindex --warn-common
2820 @cindex warnings, on combining symbols
2821 @cindex combining symbols, warnings on
2823 Warn when a common symbol is combined with another common symbol or with
2824 a symbol definition. Unix linkers allow this somewhat sloppy practice,
2825 but linkers on some other operating systems do not. This option allows
2826 you to find potential problems from combining global symbols.
2827 Unfortunately, some C libraries use this practice, so you may get some
2828 warnings about symbols in the libraries as well as in your programs.
2830 There are three kinds of global symbols, illustrated here by C examples:
2834 A definition, which goes in the initialized data section of the output
2838 An undefined reference, which does not allocate space.
2839 There must be either a definition or a common symbol for the
2843 A common symbol. If there are only (one or more) common symbols for a
2844 variable, it goes in the uninitialized data area of the output file.
2845 The linker merges multiple common symbols for the same variable into a
2846 single symbol. If they are of different sizes, it picks the largest
2847 size. The linker turns a common symbol into a declaration, if there is
2848 a definition of the same variable.
2851 The @samp{--warn-common} option can produce five kinds of warnings.
2852 Each warning consists of a pair of lines: the first describes the symbol
2853 just encountered, and the second describes the previous symbol
2854 encountered with the same name. One or both of the two symbols will be
2859 Turning a common symbol into a reference, because there is already a
2860 definition for the symbol.
2862 @var{file}(@var{section}): warning: common of `@var{symbol}'
2863 overridden by definition
2864 @var{file}(@var{section}): warning: defined here
2868 Turning a common symbol into a reference, because a later definition for
2869 the symbol is encountered. This is the same as the previous case,
2870 except that the symbols are encountered in a different order.
2872 @var{file}(@var{section}): warning: definition of `@var{symbol}'
2874 @var{file}(@var{section}): warning: common is here
2878 Merging a common symbol with a previous same-sized common symbol.
2880 @var{file}(@var{section}): warning: multiple common
2882 @var{file}(@var{section}): warning: previous common is here
2886 Merging a common symbol with a previous larger common symbol.
2888 @var{file}(@var{section}): warning: common of `@var{symbol}'
2889 overridden by larger common
2890 @var{file}(@var{section}): warning: larger common is here
2894 Merging a common symbol with a previous smaller common symbol. This is
2895 the same as the previous case, except that the symbols are
2896 encountered in a different order.
2898 @var{file}(@var{section}): warning: common of `@var{symbol}'
2899 overriding smaller common
2900 @var{file}(@var{section}): warning: smaller common is here
2904 @kindex --warn-constructors
2905 @item --warn-constructors
2906 Warn if any global constructors are used. This is only useful for a few
2907 object file formats. For formats like COFF or ELF, the linker can not
2908 detect the use of global constructors.
2910 @kindex --warn-execstack
2911 @cindex warnings, on executable stack
2912 @cindex executable stack, warnings on
2913 @item --warn-execstack
2914 @itemx --warn-execstack-objects
2915 @itemx --no-warn-execstack
2916 On ELF platforms the linker may generate warning messages if it is
2917 asked to create an output file that contains an executable stack.
2918 There are three possible states:
2921 Do not generate any warnings.
2923 Always generate warnings, even if the executable stack is requested
2924 via the @option{-z execstack} command line option.
2926 Only generate a warning if an object file requests an executable
2927 stack, but not if the @option{-z execstack} option is used.
2930 The default state depends upon how the linker was configured when it
2931 was built. The @option{--no-warn-execstack} option always puts the
2932 linker into the no-warnings state. The @option{--warn-execstack}
2933 option puts the linker into the warn-always state. The
2934 @option{--warn-execstack-objects} option puts the linker into the
2935 warn-for-object-files-only state.
2937 Note: ELF format input files can specify that they need an executable
2938 stack by having a @var{.note.GNU-stack} section with the executable
2939 bit set in its section flags. They can specify that they do not need
2940 an executable stack by having the same section, but without the
2941 executable flag bit set. If an input file does not have a
2942 @var{.note.GNU-stack} section then the default behaviour is target
2943 specific. For some targets, then absence of such a section implies
2944 that an executable stack @emph{is} required. This is often a problem
2945 for hand crafted assembler files.
2947 @kindex --error-execstack
2948 @item --error-execstack
2949 @itemx --no-error-execstack
2950 If the linker is going to generate a warning message about an
2951 executable stack then the @option{--error-execstack} option will
2952 instead change that warning into an error. Note - this option does
2953 not change the linker's execstack warning generation state. Use
2954 @option{--warn-execstack} or @option{--warn-execstack-objects} to set
2955 a specific warning state.
2957 The @option{--no-error-execstack} option will restore the default
2958 behaviour of generating warning messages.
2960 @kindex --warn-multiple-gp
2961 @item --warn-multiple-gp
2962 Warn if multiple global pointer values are required in the output file.
2963 This is only meaningful for certain processors, such as the Alpha.
2964 Specifically, some processors put large-valued constants in a special
2965 section. A special register (the global pointer) points into the middle
2966 of this section, so that constants can be loaded efficiently via a
2967 base-register relative addressing mode. Since the offset in
2968 base-register relative mode is fixed and relatively small (e.g., 16
2969 bits), this limits the maximum size of the constant pool. Thus, in
2970 large programs, it is often necessary to use multiple global pointer
2971 values in order to be able to address all possible constants. This
2972 option causes a warning to be issued whenever this case occurs.
2975 @cindex warnings, on undefined symbols
2976 @cindex undefined symbols, warnings on
2978 Only warn once for each undefined symbol, rather than once per module
2981 @kindex --warn-rwx-segments
2982 @cindex warnings, on writeable and exectuable segments
2983 @cindex executable segments, warnings on
2984 @item --warn-rwx-segments
2985 @itemx --no-warn-rwx-segments
2986 Warn if the linker creates a loadable, non-zero sized segment that has
2987 all three of the read, write and execute permission flags set. Such a
2988 segment represents a potential security vulnerability. In addition
2989 warnings will be generated if a thread local storage segment is
2990 created with the execute permission flag set, regardless of whether or
2991 not it has the read and/or write flags set.
2993 These warnings are enabled by default. They can be disabled via the
2994 @option{--no-warn-rwx-segments} option and re-enabled via the
2995 @option{--warn-rwx-segments} option.
2997 @kindex --error-rwx-segments
2998 @item --error-rwx-segments
2999 @itemx --no-error-rwx-segments
3000 If the linker is going to generate a warning message about an
3001 executable, writeable segment, or an executable TLS segment, then the
3002 @option{--error-rwx-segments} option will turn this warning into an
3003 error instead. The @option{--no-error-rwx-segments} option will
3004 restore the default behaviour of just generating a warning message.
3006 Note - the @option{--error-rwx-segments} option does not by itself
3007 turn on warnings about these segments. These warnings are either
3008 enabled by default, if the linker was configured that way, or via the
3009 @option{--warn-rwx-segments} command line option.
3011 @kindex --warn-section-align
3012 @cindex warnings, on section alignment
3013 @cindex section alignment, warnings on
3014 @item --warn-section-align
3015 Warn if the address of an output section is changed because of
3016 alignment. Typically, the alignment will be set by an input section.
3017 The address will only be changed if it not explicitly specified; that
3018 is, if the @code{SECTIONS} command does not specify a start address for
3019 the section (@pxref{SECTIONS}).
3021 @kindex --warn-textrel
3022 @item --warn-textrel
3023 Warn if the linker adds DT_TEXTREL to a position-independent executable
3026 @kindex --warn-alternate-em
3027 @item --warn-alternate-em
3028 Warn if an object has alternate ELF machine code.
3030 @kindex --warn-unresolved-symbols
3031 @item --warn-unresolved-symbols
3032 If the linker is going to report an unresolved symbol (see the option
3033 @option{--unresolved-symbols}) it will normally generate an error.
3034 This option makes it generate a warning instead.
3036 @kindex --error-unresolved-symbols
3037 @item --error-unresolved-symbols
3038 This restores the linker's default behaviour of generating errors when
3039 it is reporting unresolved symbols.
3041 @kindex --whole-archive
3042 @cindex including an entire archive
3043 @item --whole-archive
3044 For each archive mentioned on the command line after the
3045 @option{--whole-archive} option, include every object file in the archive
3046 in the link, rather than searching the archive for the required object
3047 files. This is normally used to turn an archive file into a shared
3048 library, forcing every object to be included in the resulting shared
3049 library. This option may be used more than once.
3051 Two notes when using this option from gcc: First, gcc doesn't know
3052 about this option, so you have to use @option{-Wl,-whole-archive}.
3053 Second, don't forget to use @option{-Wl,-no-whole-archive} after your
3054 list of archives, because gcc will add its own list of archives to
3055 your link and you may not want this flag to affect those as well.
3057 @kindex --wrap=@var{symbol}
3058 @item --wrap=@var{symbol}
3059 Use a wrapper function for @var{symbol}. Any undefined reference to
3060 @var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any
3061 undefined reference to @code{__real_@var{symbol}} will be resolved to
3064 This can be used to provide a wrapper for a system function. The
3065 wrapper function should be called @code{__wrap_@var{symbol}}. If it
3066 wishes to call the system function, it should call
3067 @code{__real_@var{symbol}}.
3069 Here is a trivial example:
3073 __wrap_malloc (size_t c)
3075 printf ("malloc called with %zu\n", c);
3076 return __real_malloc (c);
3080 If you link other code with this file using @option{--wrap malloc}, then
3081 all calls to @code{malloc} will call the function @code{__wrap_malloc}
3082 instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will
3083 call the real @code{malloc} function.
3085 You may wish to provide a @code{__real_malloc} function as well, so that
3086 links without the @option{--wrap} option will succeed. If you do this,
3087 you should not put the definition of @code{__real_malloc} in the same
3088 file as @code{__wrap_malloc}; if you do, the assembler may resolve the
3089 call before the linker has a chance to wrap it to @code{malloc}.
3091 Only undefined references are replaced by the linker. So, translation unit
3092 internal references to @var{symbol} are not resolved to
3093 @code{__wrap_@var{symbol}}. In the next example, the call to @code{f} in
3094 @code{g} is not resolved to @code{__wrap_f}.
3110 @kindex --eh-frame-hdr
3111 @kindex --no-eh-frame-hdr
3112 @item --eh-frame-hdr
3113 @itemx --no-eh-frame-hdr
3114 Request (@option{--eh-frame-hdr}) or suppress
3115 (@option{--no-eh-frame-hdr}) the creation of @code{.eh_frame_hdr}
3116 section and ELF @code{PT_GNU_EH_FRAME} segment header.
3118 @kindex --ld-generated-unwind-info
3119 @item --no-ld-generated-unwind-info
3120 Request creation of @code{.eh_frame} unwind info for linker
3121 generated code sections like PLT. This option is on by default
3122 if linker generated unwind info is supported. This option also
3123 controls the generation of @code{.sframe} stack trace info for linker
3124 generated code sections like PLT.
3126 @kindex --enable-new-dtags
3127 @kindex --disable-new-dtags
3128 @item --enable-new-dtags
3129 @itemx --disable-new-dtags
3130 This linker can create the new dynamic tags in ELF. But the older ELF
3131 systems may not understand them. If you specify
3132 @option{--enable-new-dtags}, the new dynamic tags will be created as needed
3133 and older dynamic tags will be omitted.
3134 If you specify @option{--disable-new-dtags}, no new dynamic tags will be
3135 created. By default, the new dynamic tags are not created. Note that
3136 those options are only available for ELF systems.
3138 @kindex --hash-size=@var{number}
3139 @item --hash-size=@var{number}
3140 Set the default size of the linker's hash tables to a prime number
3141 close to @var{number}. Increasing this value can reduce the length of
3142 time it takes the linker to perform its tasks, at the expense of
3143 increasing the linker's memory requirements. Similarly reducing this
3144 value can reduce the memory requirements at the expense of speed.
3146 @kindex --hash-style=@var{style}
3147 @item --hash-style=@var{style}
3148 Set the type of linker's hash table(s). @var{style} can be either
3149 @code{sysv} for classic ELF @code{.hash} section, @code{gnu} for
3150 new style GNU @code{.gnu.hash} section or @code{both} for both
3151 the classic ELF @code{.hash} and new style GNU @code{.gnu.hash}
3152 hash tables. The default depends upon how the linker was configured,
3153 but for most Linux based systems it will be @code{both}.
3155 @kindex --compress-debug-sections=none
3156 @kindex --compress-debug-sections=zlib
3157 @kindex --compress-debug-sections=zlib-gnu
3158 @kindex --compress-debug-sections=zlib-gabi
3159 @kindex --compress-debug-sections=zstd
3160 @item --compress-debug-sections=none
3161 @itemx --compress-debug-sections=zlib
3162 @itemx --compress-debug-sections=zlib-gnu
3163 @itemx --compress-debug-sections=zlib-gabi
3164 @itemx --compress-debug-sections=zstd
3165 On ELF platforms, these options control how DWARF debug sections are
3166 compressed using zlib.
3168 @option{--compress-debug-sections=none} doesn't compress DWARF debug
3169 sections. @option{--compress-debug-sections=zlib-gnu} compresses
3170 DWARF debug sections and renames them to begin with @samp{.zdebug}
3171 instead of @samp{.debug}. @option{--compress-debug-sections=zlib-gabi}
3172 also compresses DWARF debug sections, but rather than renaming them it
3173 sets the SHF_COMPRESSED flag in the sections' headers.
3175 The @option{--compress-debug-sections=zlib} option is an alias for
3176 @option{--compress-debug-sections=zlib-gabi}.
3178 @option{--compress-debug-sections=zstd} compresses DWARF debug sections using
3181 Note that this option overrides any compression in input debug
3182 sections, so if a binary is linked with @option{--compress-debug-sections=none}
3183 for example, then any compressed debug sections in input files will be
3184 uncompressed before they are copied into the output binary.
3186 The default compression behaviour varies depending upon the target
3187 involved and the configure options used to build the toolchain. The
3188 default can be determined by examining the output from the linker's
3189 @option{--help} option.
3191 @kindex --reduce-memory-overheads
3192 @item --reduce-memory-overheads
3193 This option reduces memory requirements at ld runtime, at the expense of
3194 linking speed. This was introduced to select the old O(n^2) algorithm
3195 for link map file generation, rather than the new O(n) algorithm which uses
3196 about 40% more memory for symbol storage.
3198 Another effect of the switch is to set the default hash table size to
3199 1021, which again saves memory at the cost of lengthening the linker's
3200 run time. This is not done however if the @option{--hash-size} switch
3203 The @option{--reduce-memory-overheads} switch may be also be used to
3204 enable other tradeoffs in future versions of the linker.
3206 @kindex --max-cache-size=@var{size}
3207 @item --max-cache-size=@var{size}
3208 @command{ld} normally caches the relocation information and symbol tables
3209 of input files in memory with the unlimited size. This option sets the
3210 maximum cache size to @var{size}.
3213 @kindex --build-id=@var{style}
3215 @itemx --build-id=@var{style}
3216 Request the creation of a @code{.note.gnu.build-id} ELF note section
3217 or a @code{.buildid} COFF section. The contents of the note are
3218 unique bits identifying this linked file. @var{style} can be
3219 @code{uuid} to use 128 random bits, @code{sha1} to use a 160-bit
3220 @sc{SHA1} hash on the normative parts of the output contents,
3221 @code{md5} to use a 128-bit @sc{MD5} hash on the normative parts of
3222 the output contents, or @code{0x@var{hexstring}} to use a chosen bit
3223 string specified as an even number of hexadecimal digits (@code{-} and
3224 @code{:} characters between digit pairs are ignored). If @var{style}
3225 is omitted, @code{sha1} is used.
3227 The @code{md5} and @code{sha1} styles produces an identifier
3228 that is always the same in an identical output file, but will be
3229 unique among all nonidentical output files. It is not intended
3230 to be compared as a checksum for the file's contents. A linked
3231 file may be changed later by other tools, but the build ID bit
3232 string identifying the original linked file does not change.
3234 Passing @code{none} for @var{style} disables the setting from any
3235 @code{--build-id} options earlier on the command line.
3237 @kindex --package-metadata=@var{JSON}
3238 @item --package-metadata=@var{JSON}
3239 Request the creation of a @code{.note.package} ELF note section. The
3240 contents of the note are in JSON format, as per the package metadata
3241 specification. For more information see:
3242 https://systemd.io/ELF_PACKAGE_METADATA/
3243 If the JSON argument is missing/empty then this will disable the
3244 creation of the metadata note, if one had been enabled by an earlier
3245 occurrence of the --package-metadata option.
3246 If the linker has been built with libjansson, then the JSON string
3252 @subsection Options Specific to i386 PE Targets
3254 @c man begin OPTIONS
3256 The i386 PE linker supports the @option{-shared} option, which causes
3257 the output to be a dynamically linked library (DLL) instead of a
3258 normal executable. You should name the output @code{*.dll} when you
3259 use this option. In addition, the linker fully supports the standard
3260 @code{*.def} files, which may be specified on the linker command line
3261 like an object file (in fact, it should precede archives it exports
3262 symbols from, to ensure that they get linked in, just like a normal
3265 In addition to the options common to all targets, the i386 PE linker
3266 support additional command-line options that are specific to the i386
3267 PE target. Options that take values may be separated from their
3268 values by either a space or an equals sign.
3272 @kindex --add-stdcall-alias
3273 @item --add-stdcall-alias
3274 If given, symbols with a stdcall suffix (@@@var{nn}) will be exported
3275 as-is and also with the suffix stripped.
3276 [This option is specific to the i386 PE targeted port of the linker]
3279 @item --base-file @var{file}
3280 Use @var{file} as the name of a file in which to save the base
3281 addresses of all the relocations needed for generating DLLs with
3283 [This is an i386 PE specific option]
3287 Create a DLL instead of a regular executable. You may also use
3288 @option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
3290 [This option is specific to the i386 PE targeted port of the linker]
3292 @kindex --enable-long-section-names
3293 @kindex --disable-long-section-names
3294 @item --enable-long-section-names
3295 @itemx --disable-long-section-names
3296 The PE variants of the COFF object format add an extension that permits
3297 the use of section names longer than eight characters, the normal limit
3298 for COFF. By default, these names are only allowed in object files, as
3299 fully-linked executable images do not carry the COFF string table required
3300 to support the longer names. As a GNU extension, it is possible to
3301 allow their use in executable images as well, or to (probably pointlessly!)
3302 disallow it in object files, by using these two options. Executable images
3303 generated with these long section names are slightly non-standard, carrying
3304 as they do a string table, and may generate confusing output when examined
3305 with non-GNU PE-aware tools, such as file viewers and dumpers. However,
3306 GDB relies on the use of PE long section names to find Dwarf-2 debug
3307 information sections in an executable image at runtime, and so if neither
3308 option is specified on the command-line, @command{ld} will enable long
3309 section names, overriding the default and technically correct behaviour,
3310 when it finds the presence of debug information while linking an executable
3311 image and not stripping symbols.
3312 [This option is valid for all PE targeted ports of the linker]
3314 @kindex --enable-stdcall-fixup
3315 @kindex --disable-stdcall-fixup
3316 @item --enable-stdcall-fixup
3317 @itemx --disable-stdcall-fixup
3318 If the link finds a symbol that it cannot resolve, it will attempt to
3319 do ``fuzzy linking'' by looking for another defined symbol that differs
3320 only in the format of the symbol name (cdecl vs stdcall) and will
3321 resolve that symbol by linking to the match. For example, the
3322 undefined symbol @code{_foo} might be linked to the function
3323 @code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
3324 to the function @code{_bar}. When the linker does this, it prints a
3325 warning, since it normally should have failed to link, but sometimes
3326 import libraries generated from third-party dlls may need this feature
3327 to be usable. If you specify @option{--enable-stdcall-fixup}, this
3328 feature is fully enabled and warnings are not printed. If you specify
3329 @option{--disable-stdcall-fixup}, this feature is disabled and such
3330 mismatches are considered to be errors.
3331 [This option is specific to the i386 PE targeted port of the linker]
3333 @kindex --leading-underscore
3334 @kindex --no-leading-underscore
3335 @item --leading-underscore
3336 @itemx --no-leading-underscore
3337 For most targets default symbol-prefix is an underscore and is defined
3338 in target's description. By this option it is possible to
3339 disable/enable the default underscore symbol-prefix.
3341 @cindex DLLs, creating
3342 @kindex --export-all-symbols
3343 @item --export-all-symbols
3344 If given, all global symbols in the objects used to build a DLL will
3345 be exported by the DLL. Note that this is the default if there
3346 otherwise wouldn't be any exported symbols. When symbols are
3347 explicitly exported via DEF files or implicitly exported via function
3348 attributes, the default is to not export anything else unless this
3349 option is given. Note that the symbols @code{DllMain@@12},
3350 @code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
3351 @code{impure_ptr} will not be automatically
3352 exported. Also, symbols imported from other DLLs will not be
3353 re-exported, nor will symbols specifying the DLL's internal layout
3354 such as those beginning with @code{_head_} or ending with
3355 @code{_iname}. In addition, no symbols from @code{libgcc},
3356 @code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
3357 Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will
3358 not be exported, to help with C++ DLLs. Finally, there is an
3359 extensive list of cygwin-private symbols that are not exported
3360 (obviously, this applies on when building DLLs for cygwin targets).
3361 These cygwin-excludes are: @code{_cygwin_dll_entry@@12},
3362 @code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
3363 @code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
3364 @code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
3365 @code{cygwin_premain3}, and @code{environ}.
3366 [This option is specific to the i386 PE targeted port of the linker]
3368 @kindex --exclude-symbols
3369 @item --exclude-symbols @var{symbol},@var{symbol},...
3370 Specifies a list of symbols which should not be automatically
3371 exported. The symbol names may be delimited by commas or colons.
3372 [This option is specific to the i386 PE targeted port of the linker]
3374 @kindex --exclude-all-symbols
3375 @item --exclude-all-symbols
3376 Specifies no symbols should be automatically exported.
3377 [This option is specific to the i386 PE targeted port of the linker]
3379 @kindex --file-alignment
3380 @item --file-alignment
3381 Specify the file alignment. Sections in the file will always begin at
3382 file offsets which are multiples of this number. This defaults to
3384 [This option is specific to the i386 PE targeted port of the linker]
3388 @item --heap @var{reserve}
3389 @itemx --heap @var{reserve},@var{commit}
3390 Specify the number of bytes of memory to reserve (and optionally commit)
3391 to be used as heap for this program. The default is 1MB reserved, 4K
3393 [This option is specific to the i386 PE targeted port of the linker]
3396 @kindex --image-base
3397 @item --image-base @var{value}
3398 Use @var{value} as the base address of your program or dll. This is
3399 the lowest memory location that will be used when your program or dll
3400 is loaded. To reduce the need to relocate and improve performance of
3401 your dlls, each should have a unique base address and not overlap any
3402 other dlls. The default is 0x400000 for executables, and 0x10000000
3404 [This option is specific to the i386 PE targeted port of the linker]
3408 If given, the stdcall suffixes (@@@var{nn}) will be stripped from
3409 symbols before they are exported.
3410 [This option is specific to the i386 PE targeted port of the linker]
3412 @kindex --large-address-aware
3413 @item --large-address-aware
3414 If given, the appropriate bit in the ``Characteristics'' field of the COFF
3415 header is set to indicate that this executable supports virtual addresses
3416 greater than 2 gigabytes. This should be used in conjunction with the /3GB
3417 or /USERVA=@var{value} megabytes switch in the ``[operating systems]''
3418 section of the BOOT.INI. Otherwise, this bit has no effect.
3419 [This option is specific to PE targeted ports of the linker]
3421 @kindex --disable-large-address-aware
3422 @item --disable-large-address-aware
3423 Reverts the effect of a previous @samp{--large-address-aware} option.
3424 This is useful if @samp{--large-address-aware} is always set by the compiler
3425 driver (e.g. Cygwin gcc) and the executable does not support virtual
3426 addresses greater than 2 gigabytes.
3427 [This option is specific to PE targeted ports of the linker]
3429 @kindex --major-image-version
3430 @item --major-image-version @var{value}
3431 Sets the major number of the ``image version''. Defaults to 1.
3432 [This option is specific to the i386 PE targeted port of the linker]
3434 @kindex --major-os-version
3435 @item --major-os-version @var{value}
3436 Sets the major number of the ``os version''. Defaults to 4.
3437 [This option is specific to the i386 PE targeted port of the linker]
3439 @kindex --major-subsystem-version
3440 @item --major-subsystem-version @var{value}
3441 Sets the major number of the ``subsystem version''. Defaults to 4.
3442 [This option is specific to the i386 PE targeted port of the linker]
3444 @kindex --minor-image-version
3445 @item --minor-image-version @var{value}
3446 Sets the minor number of the ``image version''. Defaults to 0.
3447 [This option is specific to the i386 PE targeted port of the linker]
3449 @kindex --minor-os-version
3450 @item --minor-os-version @var{value}
3451 Sets the minor number of the ``os version''. Defaults to 0.
3452 [This option is specific to the i386 PE targeted port of the linker]
3454 @kindex --minor-subsystem-version
3455 @item --minor-subsystem-version @var{value}
3456 Sets the minor number of the ``subsystem version''. Defaults to 0.
3457 [This option is specific to the i386 PE targeted port of the linker]
3459 @cindex DEF files, creating
3460 @cindex DLLs, creating
3461 @kindex --output-def
3462 @item --output-def @var{file}
3463 The linker will create the file @var{file} which will contain a DEF
3464 file corresponding to the DLL the linker is generating. This DEF file
3465 (which should be called @code{*.def}) may be used to create an import
3466 library with @code{dlltool} or may be used as a reference to
3467 automatically or implicitly exported symbols.
3468 [This option is specific to the i386 PE targeted port of the linker]
3470 @cindex DLLs, creating
3471 @kindex --enable-auto-image-base
3472 @item --enable-auto-image-base
3473 @itemx --enable-auto-image-base=@var{value}
3474 Automatically choose the image base for DLLs, optionally starting with base
3475 @var{value}, unless one is specified using the @code{--image-base} argument.
3476 By using a hash generated from the dllname to create unique image bases
3477 for each DLL, in-memory collisions and relocations which can delay program
3478 execution are avoided.
3479 [This option is specific to the i386 PE targeted port of the linker]
3481 @kindex --disable-auto-image-base
3482 @item --disable-auto-image-base
3483 Do not automatically generate a unique image base. If there is no
3484 user-specified image base (@code{--image-base}) then use the platform
3486 [This option is specific to the i386 PE targeted port of the linker]
3488 @cindex DLLs, linking to
3489 @kindex --dll-search-prefix
3490 @item --dll-search-prefix @var{string}
3491 When linking dynamically to a dll without an import library,
3492 search for @code{<string><basename>.dll} in preference to
3493 @code{lib<basename>.dll}. This behaviour allows easy distinction
3494 between DLLs built for the various "subplatforms": native, cygwin,
3495 uwin, pw, etc. For instance, cygwin DLLs typically use
3496 @code{--dll-search-prefix=cyg}.
3497 [This option is specific to the i386 PE targeted port of the linker]
3499 @kindex --enable-auto-import
3500 @item --enable-auto-import
3501 Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
3502 DATA imports from DLLs, thus making it possible to bypass the dllimport
3503 mechanism on the user side and to reference unmangled symbol names.
3504 [This option is specific to the i386 PE targeted port of the linker]
3506 The following remarks pertain to the original implementation of the
3507 feature and are obsolete nowadays for Cygwin and MinGW targets.
3509 Note: Use of the 'auto-import' extension will cause the text section
3510 of the image file to be made writable. This does not conform to the
3511 PE-COFF format specification published by Microsoft.
3513 Note - use of the 'auto-import' extension will also cause read only
3514 data which would normally be placed into the .rdata section to be
3515 placed into the .data section instead. This is in order to work
3516 around a problem with consts that is described here:
3517 http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
3519 Using 'auto-import' generally will 'just work' -- but sometimes you may
3522 "variable '<var>' can't be auto-imported. Please read the
3523 documentation for ld's @code{--enable-auto-import} for details."
3525 This message occurs when some (sub)expression accesses an address
3526 ultimately given by the sum of two constants (Win32 import tables only
3527 allow one). Instances where this may occur include accesses to member
3528 fields of struct variables imported from a DLL, as well as using a
3529 constant index into an array variable imported from a DLL. Any
3530 multiword variable (arrays, structs, long long, etc) may trigger
3531 this error condition. However, regardless of the exact data type
3532 of the offending exported variable, ld will always detect it, issue
3533 the warning, and exit.
3535 There are several ways to address this difficulty, regardless of the
3536 data type of the exported variable:
3538 One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
3539 of adjusting references in your client code for runtime environment, so
3540 this method works only when runtime environment supports this feature.
3542 A second solution is to force one of the 'constants' to be a variable --
3543 that is, unknown and un-optimizable at compile time. For arrays,
3544 there are two possibilities: a) make the indexee (the array's address)
3545 a variable, or b) make the 'constant' index a variable. Thus:
3548 extern type extern_array[];
3550 @{ volatile type *t=extern_array; t[1] @}
3556 extern type extern_array[];
3558 @{ volatile int t=1; extern_array[t] @}
3561 For structs (and most other multiword data types) the only option
3562 is to make the struct itself (or the long long, or the ...) variable:
3565 extern struct s extern_struct;
3566 extern_struct.field -->
3567 @{ volatile struct s *t=&extern_struct; t->field @}
3573 extern long long extern_ll;
3575 @{ volatile long long * local_ll=&extern_ll; *local_ll @}
3578 A third method of dealing with this difficulty is to abandon
3579 'auto-import' for the offending symbol and mark it with
3580 @code{__declspec(dllimport)}. However, in practice that
3581 requires using compile-time #defines to indicate whether you are
3582 building a DLL, building client code that will link to the DLL, or
3583 merely building/linking to a static library. In making the choice
3584 between the various methods of resolving the 'direct address with
3585 constant offset' problem, you should consider typical real-world usage:
3593 void main(int argc, char **argv)@{
3594 printf("%d\n",arr[1]);
3604 void main(int argc, char **argv)@{
3605 /* This workaround is for win32 and cygwin; do not "optimize" */
3606 volatile int *parr = arr;
3607 printf("%d\n",parr[1]);
3614 /* Note: auto-export is assumed (no __declspec(dllexport)) */
3615 #if (defined(_WIN32) || defined(__CYGWIN__)) && \
3616 !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
3617 #define FOO_IMPORT __declspec(dllimport)
3621 extern FOO_IMPORT int arr[];
3624 void main(int argc, char **argv)@{
3625 printf("%d\n",arr[1]);
3629 A fourth way to avoid this problem is to re-code your
3630 library to use a functional interface rather than a data interface
3631 for the offending variables (e.g. set_foo() and get_foo() accessor
3634 @kindex --disable-auto-import
3635 @item --disable-auto-import
3636 Do not attempt to do sophisticated linking of @code{_symbol} to
3637 @code{__imp__symbol} for DATA imports from DLLs.
3638 [This option is specific to the i386 PE targeted port of the linker]
3640 @kindex --enable-runtime-pseudo-reloc
3641 @item --enable-runtime-pseudo-reloc
3642 If your code contains expressions described in --enable-auto-import section,
3643 that is, DATA imports from DLL with non-zero offset, this switch will create
3644 a vector of 'runtime pseudo relocations' which can be used by runtime
3645 environment to adjust references to such data in your client code.
3646 [This option is specific to the i386 PE targeted port of the linker]
3648 @kindex --disable-runtime-pseudo-reloc
3649 @item --disable-runtime-pseudo-reloc
3650 Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
3651 [This option is specific to the i386 PE targeted port of the linker]
3653 @kindex --enable-extra-pe-debug
3654 @item --enable-extra-pe-debug
3655 Show additional debug info related to auto-import symbol thunking.
3656 [This option is specific to the i386 PE targeted port of the linker]
3658 @kindex --section-alignment
3659 @item --section-alignment
3660 Sets the section alignment. Sections in memory will always begin at
3661 addresses which are a multiple of this number. Defaults to 0x1000.
3662 [This option is specific to the i386 PE targeted port of the linker]
3666 @item --stack @var{reserve}
3667 @itemx --stack @var{reserve},@var{commit}
3668 Specify the number of bytes of memory to reserve (and optionally commit)
3669 to be used as stack for this program. The default is 2MB reserved, 4K
3671 [This option is specific to the i386 PE targeted port of the linker]
3674 @item --subsystem @var{which}
3675 @itemx --subsystem @var{which}:@var{major}
3676 @itemx --subsystem @var{which}:@var{major}.@var{minor}
3677 Specifies the subsystem under which your program will execute. The
3678 legal values for @var{which} are @code{native}, @code{windows},
3679 @code{console}, @code{posix}, and @code{xbox}. You may optionally set
3680 the subsystem version also. Numeric values are also accepted for
3682 [This option is specific to the i386 PE targeted port of the linker]
3684 The following options set flags in the @code{DllCharacteristics} field
3685 of the PE file header:
3686 [These options are specific to PE targeted ports of the linker]
3688 @kindex --high-entropy-va
3689 @item --high-entropy-va
3690 @itemx --disable-high-entropy-va
3691 Image is compatible with 64-bit address space layout randomization
3692 (ASLR). This option is enabled by default for 64-bit PE images.
3694 This option also implies @option{--dynamicbase} and
3695 @option{--enable-reloc-section}.
3697 @kindex --dynamicbase
3699 @itemx --disable-dynamicbase
3700 The image base address may be relocated using address space layout
3701 randomization (ASLR). This feature was introduced with MS Windows
3702 Vista for i386 PE targets. This option is enabled by default but
3703 can be disabled via the @option{--disable-dynamicbase} option.
3704 This option also implies @option{--enable-reloc-section}.
3706 @kindex --forceinteg
3708 @itemx --disable-forceinteg
3709 Code integrity checks are enforced. This option is disabled by
3714 @item --disable-nxcompat
3715 The image is compatible with the Data Execution Prevention.
3716 This feature was introduced with MS Windows XP SP2 for i386 PE
3717 targets. The option is enabled by default.
3719 @kindex --no-isolation
3720 @item --no-isolation
3721 @itemx --disable-no-isolation
3722 Although the image understands isolation, do not isolate the image.
3723 This option is disabled by default.
3727 @itemx --disable-no-seh
3728 The image does not use SEH. No SE handler may be called from
3729 this image. This option is disabled by default.
3733 @itemx --disable-no-bind
3734 Do not bind this image. This option is disabled by default.
3738 @itemx --disable-wdmdriver
3739 The driver uses the MS Windows Driver Model. This option is disabled
3744 @itemx --disable-tsaware
3745 The image is Terminal Server aware. This option is disabled by
3748 @kindex --insert-timestamp
3749 @item --insert-timestamp
3750 @itemx --no-insert-timestamp
3751 Insert a real timestamp into the image. This is the default behaviour
3752 as it matches legacy code and it means that the image will work with
3753 other, proprietary tools. The problem with this default is that it
3754 will result in slightly different images being produced each time the
3755 same sources are linked. The option @option{--no-insert-timestamp}
3756 can be used to insert a zero value for the timestamp, this ensuring
3757 that binaries produced from identical sources will compare
3760 If @option{--insert-timestamp} is active then the time inserted is
3761 either the time that the linking takes place or, if the
3762 @code{SOURCE_DATE_EPOCH} environment variable is defined, the number
3763 of seconds since Unix epoch as specified by that variable.
3765 @kindex --enable-reloc-section
3766 @item --enable-reloc-section
3767 @itemx --disable-reloc-section
3768 Create the base relocation table, which is necessary if the image
3769 is loaded at a different image base than specified in the PE header.
3770 This option is enabled by default.
3776 @subsection Options specific to C6X uClinux targets
3778 @c man begin OPTIONS
3780 The C6X uClinux target uses a binary format called DSBT to support shared
3781 libraries. Each shared library in the system needs to have a unique index;
3782 all executables use an index of 0.
3787 @item --dsbt-size @var{size}
3788 This option sets the number of entries in the DSBT of the current executable
3789 or shared library to @var{size}. The default is to create a table with 64
3792 @kindex --dsbt-index
3793 @item --dsbt-index @var{index}
3794 This option sets the DSBT index of the current executable or shared library
3795 to @var{index}. The default is 0, which is appropriate for generating
3796 executables. If a shared library is generated with a DSBT index of 0, the
3797 @code{R_C6000_DSBT_INDEX} relocs are copied into the output file.
3799 @kindex --no-merge-exidx-entries
3800 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent
3801 exidx entries in frame unwind info.
3809 @subsection Options specific to C-SKY targets
3811 @c man begin OPTIONS
3815 @kindex --branch-stub on C-SKY
3817 This option enables linker branch relaxation by inserting branch stub
3818 sections when needed to extend the range of branches. This option is
3819 usually not required since C-SKY supports branch and call instructions that
3820 can access the full memory range and branch relaxation is normally handled by
3821 the compiler or assembler.
3823 @kindex --stub-group-size on C-SKY
3824 @item --stub-group-size=@var{N}
3825 This option allows finer control of linker branch stub creation.
3826 It sets the maximum size of a group of input sections that can
3827 be handled by one stub section. A negative value of @var{N} locates
3828 stub sections after their branches, while a positive value allows stub
3829 sections to appear either before or after the branches. Values of
3830 @samp{1} or @samp{-1} indicate that the
3831 linker should choose suitable defaults.
3839 @subsection Options specific to Motorola 68HC11 and 68HC12 targets
3841 @c man begin OPTIONS
3843 The 68HC11 and 68HC12 linkers support specific options to control the
3844 memory bank switching mapping and trampoline code generation.
3848 @kindex --no-trampoline
3849 @item --no-trampoline
3850 This option disables the generation of trampoline. By default a trampoline
3851 is generated for each far function which is called using a @code{jsr}
3852 instruction (this happens when a pointer to a far function is taken).
3854 @kindex --bank-window
3855 @item --bank-window @var{name}
3856 This option indicates to the linker the name of the memory region in
3857 the @samp{MEMORY} specification that describes the memory bank window.
3858 The definition of such region is then used by the linker to compute
3859 paging and addresses within the memory window.
3867 @subsection Options specific to Motorola 68K target
3869 @c man begin OPTIONS
3871 The following options are supported to control handling of GOT generation
3872 when linking for 68K targets.
3877 @item --got=@var{type}
3878 This option tells the linker which GOT generation scheme to use.
3879 @var{type} should be one of @samp{single}, @samp{negative},
3880 @samp{multigot} or @samp{target}. For more information refer to the
3881 Info entry for @file{ld}.
3889 @subsection Options specific to MIPS targets
3891 @c man begin OPTIONS
3893 The following options are supported to control microMIPS instruction
3894 generation and branch relocation checks for ISA mode transitions when
3895 linking for MIPS targets.
3903 These options control the choice of microMIPS instructions used in code
3904 generated by the linker, such as that in the PLT or lazy binding stubs,
3905 or in relaxation. If @samp{--insn32} is used, then the linker only uses
3906 32-bit instruction encodings. By default or if @samp{--no-insn32} is
3907 used, all instruction encodings are used, including 16-bit ones where
3910 @kindex --ignore-branch-isa
3911 @item --ignore-branch-isa
3912 @kindex --no-ignore-branch-isa
3913 @itemx --no-ignore-branch-isa
3914 These options control branch relocation checks for invalid ISA mode
3915 transitions. If @samp{--ignore-branch-isa} is used, then the linker
3916 accepts any branch relocations and any ISA mode transition required
3917 is lost in relocation calculation, except for some cases of @code{BAL}
3918 instructions which meet relaxation conditions and are converted to
3919 equivalent @code{JALX} instructions as the associated relocation is
3920 calculated. By default or if @samp{--no-ignore-branch-isa} is used
3921 a check is made causing the loss of an ISA mode transition to produce
3924 @kindex --compact-branches
3925 @item --compact-branches
3926 @kindex --no-compact-branches
3927 @itemx --no-compact-branches
3928 These options control the generation of compact instructions by the linker
3929 in the PLT entries for MIPS R6.
3938 @subsection Options specific to PDP11 targets
3940 @c man begin OPTIONS
3942 For the pdp11-aout target, three variants of the output format can be
3943 produced as selected by the following options. The default variant
3944 for pdp11-aout is the @samp{--omagic} option, whereas for other
3945 targets @samp{--nmagic} is the default. The @samp{--imagic} option is
3946 defined only for the pdp11-aout target, while the others are described
3947 here as they apply to the pdp11-aout target.
3956 Mark the output as @code{OMAGIC} (0407) in the @file{a.out} header to
3957 indicate that the text segment is not to be write-protected and
3958 shared. Since the text and data sections are both readable and
3959 writable, the data section is allocated immediately contiguous after
3960 the text segment. This is the oldest format for PDP11 executable
3961 programs and is the default for @command{ld} on PDP11 Unix systems
3962 from the beginning through 2.11BSD.
3969 Mark the output as @code{NMAGIC} (0410) in the @file{a.out} header to
3970 indicate that when the output file is executed, the text portion will
3971 be read-only and shareable among all processes executing the same
3972 file. This involves moving the data areas up to the first possible 8K
3973 byte page boundary following the end of the text. This option creates
3974 a @emph{pure executable} format.
3981 Mark the output as @code{IMAGIC} (0411) in the @file{a.out} header to
3982 indicate that when the output file is executed, the program text and
3983 data areas will be loaded into separate address spaces using the split
3984 instruction and data space feature of the memory management unit in
3985 larger models of the PDP11. This doubles the address space available
3986 to the program. The text segment is again pure, write-protected, and
3987 shareable. The only difference in the output format between this
3988 option and the others, besides the magic number, is that both the text
3989 and data sections start at location 0. The @samp{-z} option selected
3990 this format in 2.11BSD. This option creates a @emph{separate
3996 Equivalent to @samp{--nmagic} for pdp11-aout.
4005 @section Environment Variables
4007 @c man begin ENVIRONMENT
4009 You can change the behaviour of @command{ld} with the environment variables
4010 @ifclear SingleFormat
4013 @code{LDEMULATION} and @code{COLLECT_NO_DEMANGLE}.
4015 @ifclear SingleFormat
4017 @cindex default input format
4018 @code{GNUTARGET} determines the input-file object format if you don't
4019 use @samp{-b} (or its synonym @samp{--format}). Its value should be one
4020 of the BFD names for an input format (@pxref{BFD}). If there is no
4021 @code{GNUTARGET} in the environment, @command{ld} uses the natural format
4022 of the target. If @code{GNUTARGET} is set to @code{default} then BFD
4023 attempts to discover the input format by examining binary input files;
4024 this method often succeeds, but there are potential ambiguities, since
4025 there is no method of ensuring that the magic number used to specify
4026 object-file formats is unique. However, the configuration procedure for
4027 BFD on each system places the conventional format for that system first
4028 in the search-list, so ambiguities are resolved in favor of convention.
4032 @cindex default emulation
4033 @cindex emulation, default
4034 @code{LDEMULATION} determines the default emulation if you don't use the
4035 @samp{-m} option. The emulation can affect various aspects of linker
4036 behaviour, particularly the default linker script. You can list the
4037 available emulations with the @samp{--verbose} or @samp{-V} options. If
4038 the @samp{-m} option is not used, and the @code{LDEMULATION} environment
4039 variable is not defined, the default emulation depends upon how the
4040 linker was configured.
4042 @kindex COLLECT_NO_DEMANGLE
4043 @cindex demangling, default
4044 Normally, the linker will default to demangling symbols. However, if
4045 @code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
4046 default to not demangling symbols. This environment variable is used in
4047 a similar fashion by the @code{gcc} linker wrapper program. The default
4048 may be overridden by the @samp{--demangle} and @samp{--no-demangle}
4055 @chapter Linker Scripts
4058 @cindex linker scripts
4059 @cindex command files
4060 Every link is controlled by a @dfn{linker script}. This script is
4061 written in the linker command language.
4063 The main purpose of the linker script is to describe how the sections in
4064 the input files should be mapped into the output file, and to control
4065 the memory layout of the output file. Most linker scripts do nothing
4066 more than this. However, when necessary, the linker script can also
4067 direct the linker to perform many other operations, using the commands
4070 The linker always uses a linker script. If you do not supply one
4071 yourself, the linker will use a default script that is compiled into the
4072 linker executable. You can use the @samp{--verbose} command-line option
4073 to display the default linker script. Certain command-line options,
4074 such as @samp{-r} or @samp{-N}, will affect the default linker script.
4076 You may supply your own linker script by using the @samp{-T} command
4077 line option. When you do this, your linker script will replace the
4078 default linker script.
4080 You may also use linker scripts implicitly by naming them as input files
4081 to the linker, as though they were files to be linked. @xref{Implicit
4085 * Basic Script Concepts:: Basic Linker Script Concepts
4086 * Script Format:: Linker Script Format
4087 * Simple Example:: Simple Linker Script Example
4088 * Simple Commands:: Simple Linker Script Commands
4089 * Assignments:: Assigning Values to Symbols
4090 * SECTIONS:: SECTIONS Command
4091 * MEMORY:: MEMORY Command
4092 * PHDRS:: PHDRS Command
4093 * VERSION:: VERSION Command
4094 * Expressions:: Expressions in Linker Scripts
4095 * Implicit Linker Scripts:: Implicit Linker Scripts
4098 @node Basic Script Concepts
4099 @section Basic Linker Script Concepts
4100 @cindex linker script concepts
4101 We need to define some basic concepts and vocabulary in order to
4102 describe the linker script language.
4104 The linker combines input files into a single output file. The output
4105 file and each input file are in a special data format known as an
4106 @dfn{object file format}. Each file is called an @dfn{object file}.
4107 The output file is often called an @dfn{executable}, but for our
4108 purposes we will also call it an object file. Each object file has,
4109 among other things, a list of @dfn{sections}. We sometimes refer to a
4110 section in an input file as an @dfn{input section}; similarly, a section
4111 in the output file is an @dfn{output section}.
4113 Each section in an object file has a name and a size. Most sections
4114 also have an associated block of data, known as the @dfn{section
4115 contents}. A section may be marked as @dfn{loadable}, which means that
4116 the contents should be loaded into memory when the output file is run.
4117 A section with no contents may be @dfn{allocatable}, which means that an
4118 area in memory should be set aside, but nothing in particular should be
4119 loaded there (in some cases this memory must be zeroed out). A section
4120 which is neither loadable nor allocatable typically contains some sort
4121 of debugging information.
4123 Every loadable or allocatable output section has two addresses. The
4124 first is the @dfn{VMA}, or virtual memory address. This is the address
4125 the section will have when the output file is run. The second is the
4126 @dfn{LMA}, or load memory address. This is the address at which the
4127 section will be loaded. In most cases the two addresses will be the
4128 same. An example of when they might be different is when a data section
4129 is loaded into ROM, and then copied into RAM when the program starts up
4130 (this technique is often used to initialize global variables in a ROM
4131 based system). In this case the ROM address would be the LMA, and the
4132 RAM address would be the VMA.
4134 You can see the sections in an object file by using the @code{objdump}
4135 program with the @samp{-h} option.
4137 Every object file also has a list of @dfn{symbols}, known as the
4138 @dfn{symbol table}. A symbol may be defined or undefined. Each symbol
4139 has a name, and each defined symbol has an address, among other
4140 information. If you compile a C or C++ program into an object file, you
4141 will get a defined symbol for every defined function and global or
4142 static variable. Every undefined function or global variable which is
4143 referenced in the input file will become an undefined symbol.
4145 You can see the symbols in an object file by using the @code{nm}
4146 program, or by using the @code{objdump} program with the @samp{-t}
4150 @section Linker Script Format
4151 @cindex linker script format
4152 Linker scripts are text files.
4154 You write a linker script as a series of commands. Each command is
4155 either a keyword, possibly followed by arguments, or an assignment to a
4156 symbol. You may separate commands using semicolons. Whitespace is
4159 Strings such as file or format names can normally be entered directly.
4160 If the file name contains a character such as a comma which would
4161 otherwise serve to separate file names, you may put the file name in
4162 double quotes. There is no way to use a double quote character in a
4165 You may include comments in linker scripts just as in C, delimited by
4166 @samp{/*} and @samp{*/}. As in C, comments are syntactically equivalent
4169 @node Simple Example
4170 @section Simple Linker Script Example
4171 @cindex linker script example
4172 @cindex example of linker script
4173 Many linker scripts are fairly simple.
4175 The simplest possible linker script has just one command:
4176 @samp{SECTIONS}. You use the @samp{SECTIONS} command to describe the
4177 memory layout of the output file.
4179 The @samp{SECTIONS} command is a powerful command. Here we will
4180 describe a simple use of it. Let's assume your program consists only of
4181 code, initialized data, and uninitialized data. These will be in the
4182 @samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
4183 Let's assume further that these are the only sections which appear in
4186 For this example, let's say that the code should be loaded at address
4187 0x10000, and that the data should start at address 0x8000000. Here is a
4188 linker script which will do that:
4193 .text : @{ *(.text) @}
4195 .data : @{ *(.data) @}
4196 .bss : @{ *(.bss) @}
4200 You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
4201 followed by a series of symbol assignments and output section
4202 descriptions enclosed in curly braces.
4204 The first line inside the @samp{SECTIONS} command of the above example
4205 sets the value of the special symbol @samp{.}, which is the location
4206 counter. If you do not specify the address of an output section in some
4207 other way (other ways are described later), the address is set from the
4208 current value of the location counter. The location counter is then
4209 incremented by the size of the output section. At the start of the
4210 @samp{SECTIONS} command, the location counter has the value @samp{0}.
4212 The second line defines an output section, @samp{.text}. The colon is
4213 required syntax which may be ignored for now. Within the curly braces
4214 after the output section name, you list the names of the input sections
4215 which should be placed into this output section. The @samp{*} is a
4216 wildcard which matches any file name. The expression @samp{*(.text)}
4217 means all @samp{.text} input sections in all input files.
4219 Since the location counter is @samp{0x10000} when the output section
4220 @samp{.text} is defined, the linker will set the address of the
4221 @samp{.text} section in the output file to be @samp{0x10000}.
4223 The remaining lines define the @samp{.data} and @samp{.bss} sections in
4224 the output file. The linker will place the @samp{.data} output section
4225 at address @samp{0x8000000}. After the linker places the @samp{.data}
4226 output section, the value of the location counter will be
4227 @samp{0x8000000} plus the size of the @samp{.data} output section. The
4228 effect is that the linker will place the @samp{.bss} output section
4229 immediately after the @samp{.data} output section in memory.
4231 The linker will ensure that each output section has the required
4232 alignment, by increasing the location counter if necessary. In this
4233 example, the specified addresses for the @samp{.text} and @samp{.data}
4234 sections will probably satisfy any alignment constraints, but the linker
4235 may have to create a small gap between the @samp{.data} and @samp{.bss}
4238 That's it! That's a simple and complete linker script.
4240 @node Simple Commands
4241 @section Simple Linker Script Commands
4242 @cindex linker script simple commands
4243 In this section we describe the simple linker script commands.
4246 * Entry Point:: Setting the entry point
4247 * File Commands:: Commands dealing with files
4248 @ifclear SingleFormat
4249 * Format Commands:: Commands dealing with object file formats
4252 * REGION_ALIAS:: Assign alias names to memory regions
4253 * Miscellaneous Commands:: Other linker script commands
4257 @subsection Setting the Entry Point
4258 @kindex ENTRY(@var{symbol})
4259 @cindex start of execution
4260 @cindex first instruction
4262 The first instruction to execute in a program is called the @dfn{entry
4263 point}. You can use the @code{ENTRY} linker script command to set the
4264 entry point. The argument is a symbol name:
4269 There are several ways to set the entry point. The linker will set the
4270 entry point by trying each of the following methods in order, and
4271 stopping when one of them succeeds:
4274 the @samp{-e} @var{entry} command-line option;
4276 the @code{ENTRY(@var{symbol})} command in a linker script;
4278 the value of a target-specific symbol, if it is defined; For many
4279 targets this is @code{start}, but PE- and BeOS-based systems for example
4280 check a list of possible entry symbols, matching the first one found.
4282 the address of the first byte of the code section, if present and an
4283 executable is being created - the code section is usually
4284 @samp{.text}, but can be something else;
4286 The address @code{0}.
4290 @subsection Commands Dealing with Files
4291 @cindex linker script file commands
4292 Several linker script commands deal with files.
4295 @item INCLUDE @var{filename}
4296 @kindex INCLUDE @var{filename}
4297 @cindex including a linker script
4298 Include the linker script @var{filename} at this point. The file will
4299 be searched for in the current directory, and in any directory specified
4300 with the @option{-L} option. You can nest calls to @code{INCLUDE} up to
4303 You can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or
4304 @code{SECTIONS} commands, or in output section descriptions.
4306 @item INPUT(@var{file}, @var{file}, @dots{})
4307 @itemx INPUT(@var{file} @var{file} @dots{})
4308 @kindex INPUT(@var{files})
4309 @cindex input files in linker scripts
4310 @cindex input object files in linker scripts
4311 @cindex linker script input object files
4312 The @code{INPUT} command directs the linker to include the named files
4313 in the link, as though they were named on the command line.
4315 For example, if you always want to include @file{subr.o} any time you do
4316 a link, but you can't be bothered to put it on every link command line,
4317 then you can put @samp{INPUT (subr.o)} in your linker script.
4319 In fact, if you like, you can list all of your input files in the linker
4320 script, and then invoke the linker with nothing but a @samp{-T} option.
4322 In case a @dfn{sysroot prefix} is configured, and the filename starts
4323 with the @samp{/} character, and the script being processed was
4324 located inside the @dfn{sysroot prefix}, the filename will be looked
4325 for in the @dfn{sysroot prefix}. The @dfn{sysroot prefix} can also be forced by specifying
4326 @code{=} as the first character in the filename path, or prefixing the
4327 filename path with @code{$SYSROOT}. See also the description of
4328 @samp{-L} in @ref{Options,,Command-line Options}.
4330 If a @dfn{sysroot prefix} is not used then the linker will try to open
4331 the file in the directory containing the linker script. If it is not
4332 found the linker will then search the current directory. If it is still
4333 not found the linker will search through the archive library search
4336 If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
4337 name to @code{lib@var{file}.a}, as with the command-line argument
4340 When you use the @code{INPUT} command in an implicit linker script, the
4341 files will be included in the link at the point at which the linker
4342 script file is included. This can affect archive searching.
4344 @item GROUP(@var{file}, @var{file}, @dots{})
4345 @itemx GROUP(@var{file} @var{file} @dots{})
4346 @kindex GROUP(@var{files})
4347 @cindex grouping input files
4348 The @code{GROUP} command is like @code{INPUT}, except that the named
4349 files should all be archives, and they are searched repeatedly until no
4350 new undefined references are created. See the description of @samp{-(}
4351 in @ref{Options,,Command-line Options}.
4353 @item AS_NEEDED(@var{file}, @var{file}, @dots{})
4354 @itemx AS_NEEDED(@var{file} @var{file} @dots{})
4355 @kindex AS_NEEDED(@var{files})
4356 This construct can appear only inside of the @code{INPUT} or @code{GROUP}
4357 commands, among other filenames. The files listed will be handled
4358 as if they appear directly in the @code{INPUT} or @code{GROUP} commands,
4359 with the exception of ELF shared libraries, that will be added only
4360 when they are actually needed. This construct essentially enables
4361 @option{--as-needed} option for all the files listed inside of it
4362 and restores previous @option{--as-needed} resp. @option{--no-as-needed}
4365 @item OUTPUT(@var{filename})
4366 @kindex OUTPUT(@var{filename})
4367 @cindex output file name in linker script
4368 The @code{OUTPUT} command names the output file. Using
4369 @code{OUTPUT(@var{filename})} in the linker script is exactly like using
4370 @samp{-o @var{filename}} on the command line (@pxref{Options,,Command
4371 Line Options}). If both are used, the command-line option takes
4374 You can use the @code{OUTPUT} command to define a default name for the
4375 output file other than the usual default of @file{a.out}.
4377 @item SEARCH_DIR(@var{path})
4378 @kindex SEARCH_DIR(@var{path})
4379 @cindex library search path in linker script
4380 @cindex archive search path in linker script
4381 @cindex search path in linker script
4382 The @code{SEARCH_DIR} command adds @var{path} to the list of paths where
4383 @command{ld} looks for archive libraries. Using
4384 @code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
4385 on the command line (@pxref{Options,,Command-line Options}). If both
4386 are used, then the linker will search both paths. Paths specified using
4387 the command-line option are searched first.
4389 @item STARTUP(@var{filename})
4390 @kindex STARTUP(@var{filename})
4391 @cindex first input file
4392 The @code{STARTUP} command is just like the @code{INPUT} command, except
4393 that @var{filename} will become the first input file to be linked, as
4394 though it were specified first on the command line. This may be useful
4395 when using a system in which the entry point is always the start of the
4399 @ifclear SingleFormat
4400 @node Format Commands
4401 @subsection Commands Dealing with Object File Formats
4402 A couple of linker script commands deal with object file formats.
4405 @item OUTPUT_FORMAT(@var{bfdname})
4406 @itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
4407 @kindex OUTPUT_FORMAT(@var{bfdname})
4408 @cindex output file format in linker script
4409 The @code{OUTPUT_FORMAT} command names the BFD format to use for the
4410 output file (@pxref{BFD}). Using @code{OUTPUT_FORMAT(@var{bfdname})} is
4411 exactly like using @samp{--oformat @var{bfdname}} on the command line
4412 (@pxref{Options,,Command-line Options}). If both are used, the command
4413 line option takes precedence.
4415 You can use @code{OUTPUT_FORMAT} with three arguments to use different
4416 formats based on the @samp{-EB} and @samp{-EL} command-line options.
4417 This permits the linker script to set the output format based on the
4420 If neither @samp{-EB} nor @samp{-EL} are used, then the output format
4421 will be the first argument, @var{default}. If @samp{-EB} is used, the
4422 output format will be the second argument, @var{big}. If @samp{-EL} is
4423 used, the output format will be the third argument, @var{little}.
4425 For example, the default linker script for the MIPS ELF target uses this
4428 OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
4430 This says that the default format for the output file is
4431 @samp{elf32-bigmips}, but if the user uses the @samp{-EL} command-line
4432 option, the output file will be created in the @samp{elf32-littlemips}
4435 @item TARGET(@var{bfdname})
4436 @kindex TARGET(@var{bfdname})
4437 @cindex input file format in linker script
4438 The @code{TARGET} command names the BFD format to use when reading input
4439 files. It affects subsequent @code{INPUT} and @code{GROUP} commands.
4440 This command is like using @samp{-b @var{bfdname}} on the command line
4441 (@pxref{Options,,Command-line Options}). If the @code{TARGET} command
4442 is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
4443 command is also used to set the format for the output file. @xref{BFD}.
4448 @subsection Assign alias names to memory regions
4449 @kindex REGION_ALIAS(@var{alias}, @var{region})
4450 @cindex region alias
4451 @cindex region names
4453 Alias names can be added to existing memory regions created with the
4454 @ref{MEMORY} command. Each name corresponds to at most one memory region.
4457 REGION_ALIAS(@var{alias}, @var{region})
4460 The @code{REGION_ALIAS} function creates an alias name @var{alias} for the
4461 memory region @var{region}. This allows a flexible mapping of output sections
4462 to memory regions. An example follows.
4464 Suppose we have an application for embedded systems which come with various
4465 memory storage devices. All have a general purpose, volatile memory @code{RAM}
4466 that allows code execution or data storage. Some may have a read-only,
4467 non-volatile memory @code{ROM} that allows code execution and read-only data
4468 access. The last variant is a read-only, non-volatile memory @code{ROM2} with
4469 read-only data access and no code execution capability. We have four output
4474 @code{.text} program code;
4476 @code{.rodata} read-only data;
4478 @code{.data} read-write initialized data;
4480 @code{.bss} read-write zero initialized data.
4483 The goal is to provide a linker command file that contains a system independent
4484 part defining the output sections and a system dependent part mapping the
4485 output sections to the memory regions available on the system. Our embedded
4486 systems come with three different memory setups @code{A}, @code{B} and
4488 @multitable @columnfractions .25 .25 .25 .25
4489 @item Section @tab Variant A @tab Variant B @tab Variant C
4490 @item .text @tab RAM @tab ROM @tab ROM
4491 @item .rodata @tab RAM @tab ROM @tab ROM2
4492 @item .data @tab RAM @tab RAM/ROM @tab RAM/ROM2
4493 @item .bss @tab RAM @tab RAM @tab RAM
4495 The notation @code{RAM/ROM} or @code{RAM/ROM2} means that this section is
4496 loaded into region @code{ROM} or @code{ROM2} respectively. Please note that
4497 the load address of the @code{.data} section starts in all three variants at
4498 the end of the @code{.rodata} section.
4500 The base linker script that deals with the output sections follows. It
4501 includes the system dependent @code{linkcmds.memory} file that describes the
4504 INCLUDE linkcmds.memory
4517 .data : AT (rodata_end)
4522 data_size = SIZEOF(.data);
4523 data_load_start = LOADADDR(.data);
4531 Now we need three different @code{linkcmds.memory} files to define memory
4532 regions and alias names. The content of @code{linkcmds.memory} for the three
4533 variants @code{A}, @code{B} and @code{C}:
4536 Here everything goes into the @code{RAM}.
4540 RAM : ORIGIN = 0, LENGTH = 4M
4543 REGION_ALIAS("REGION_TEXT", RAM);
4544 REGION_ALIAS("REGION_RODATA", RAM);
4545 REGION_ALIAS("REGION_DATA", RAM);
4546 REGION_ALIAS("REGION_BSS", RAM);
4549 Program code and read-only data go into the @code{ROM}. Read-write data goes
4550 into the @code{RAM}. An image of the initialized data is loaded into the
4551 @code{ROM} and will be copied during system start into the @code{RAM}.
4555 ROM : ORIGIN = 0, LENGTH = 3M
4556 RAM : ORIGIN = 0x10000000, LENGTH = 1M
4559 REGION_ALIAS("REGION_TEXT", ROM);
4560 REGION_ALIAS("REGION_RODATA", ROM);
4561 REGION_ALIAS("REGION_DATA", RAM);
4562 REGION_ALIAS("REGION_BSS", RAM);
4565 Program code goes into the @code{ROM}. Read-only data goes into the
4566 @code{ROM2}. Read-write data goes into the @code{RAM}. An image of the
4567 initialized data is loaded into the @code{ROM2} and will be copied during
4568 system start into the @code{RAM}.
4572 ROM : ORIGIN = 0, LENGTH = 2M
4573 ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
4574 RAM : ORIGIN = 0x20000000, LENGTH = 1M
4577 REGION_ALIAS("REGION_TEXT", ROM);
4578 REGION_ALIAS("REGION_RODATA", ROM2);
4579 REGION_ALIAS("REGION_DATA", RAM);
4580 REGION_ALIAS("REGION_BSS", RAM);
4584 It is possible to write a common system initialization routine to copy the
4585 @code{.data} section from @code{ROM} or @code{ROM2} into the @code{RAM} if
4590 extern char data_start [];
4591 extern char data_size [];
4592 extern char data_load_start [];
4594 void copy_data(void)
4596 if (data_start != data_load_start)
4598 memcpy(data_start, data_load_start, (size_t) data_size);
4603 @node Miscellaneous Commands
4604 @subsection Other Linker Script Commands
4605 There are a few other linker scripts commands.
4608 @item ASSERT(@var{exp}, @var{message})
4610 @cindex assertion in linker script
4611 Ensure that @var{exp} is non-zero. If it is zero, then exit the linker
4612 with an error code, and print @var{message}.
4614 Note that assertions are checked before the final stages of linking
4615 take place. This means that expressions involving symbols PROVIDEd
4616 inside section definitions will fail if the user has not set values
4617 for those symbols. The only exception to this rule is PROVIDEd
4618 symbols that just reference dot. Thus an assertion like this:
4623 PROVIDE (__stack = .);
4624 PROVIDE (__stack_size = 0x100);
4625 ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4629 will fail if @code{__stack_size} is not defined elsewhere. Symbols
4630 PROVIDEd outside of section definitions are evaluated earlier, so they
4631 can be used inside ASSERTions. Thus:
4634 PROVIDE (__stack_size = 0x100);
4637 PROVIDE (__stack = .);
4638 ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4644 @item EXTERN(@var{symbol} @var{symbol} @dots{})
4646 @cindex undefined symbol in linker script
4647 Force @var{symbol} to be entered in the output file as an undefined
4648 symbol. Doing this may, for example, trigger linking of additional
4649 modules from standard libraries. You may list several @var{symbol}s for
4650 each @code{EXTERN}, and you may use @code{EXTERN} multiple times. This
4651 command has the same effect as the @samp{-u} command-line option.
4653 @item FORCE_COMMON_ALLOCATION
4654 @kindex FORCE_COMMON_ALLOCATION
4655 @cindex common allocation in linker script
4656 This command has the same effect as the @samp{-d} command-line option:
4657 to make @command{ld} assign space to common symbols even if a relocatable
4658 output file is specified (@samp{-r}).
4660 @item INHIBIT_COMMON_ALLOCATION
4661 @kindex INHIBIT_COMMON_ALLOCATION
4662 @cindex common allocation in linker script
4663 This command has the same effect as the @samp{--no-define-common}
4664 command-line option: to make @code{ld} omit the assignment of addresses
4665 to common symbols even for a non-relocatable output file.
4667 @item FORCE_GROUP_ALLOCATION
4668 @kindex FORCE_GROUP_ALLOCATION
4669 @cindex group allocation in linker script
4670 @cindex section groups
4672 This command has the same effect as the
4673 @samp{--force-group-allocation} command-line option: to make
4674 @command{ld} place section group members like normal input sections,
4675 and to delete the section groups even if a relocatable output file is
4676 specified (@samp{-r}).
4678 @item INSERT [ AFTER | BEFORE ] @var{output_section}
4680 @cindex insert user script into default script
4681 This command is typically used in a script specified by @samp{-T} to
4682 augment the default @code{SECTIONS} with, for example, overlays. It
4683 inserts all prior linker script statements after (or before)
4684 @var{output_section}, and also causes @samp{-T} to not override the
4685 default linker script. The exact insertion point is as for orphan
4686 sections. @xref{Location Counter}. The insertion happens after the
4687 linker has mapped input sections to output sections. Prior to the
4688 insertion, since @samp{-T} scripts are parsed before the default
4689 linker script, statements in the @samp{-T} script occur before the
4690 default linker script statements in the internal linker representation
4691 of the script. In particular, input section assignments will be made
4692 to @samp{-T} output sections before those in the default script. Here
4693 is an example of how a @samp{-T} script using @code{INSERT} might look:
4700 .ov1 @{ ov1*(.text) @}
4701 .ov2 @{ ov2*(.text) @}
4707 Note that when @samp{-T} is used twice, once to override the default
4708 script and once to augment that script using @code{INSERT} the order
4709 of parsing and section assignments apply as for the default script.
4710 The script with @code{INSERT} should be specified @emph{first} on the
4713 @item NOCROSSREFS(@var{section} @var{section} @dots{})
4714 @kindex NOCROSSREFS(@var{sections})
4715 @cindex cross references
4716 This command may be used to tell @command{ld} to issue an error about any
4717 references among certain output sections.
4719 In certain types of programs, particularly on embedded systems when
4720 using overlays, when one section is loaded into memory, another section
4721 will not be. Any direct references between the two sections would be
4722 errors. For example, it would be an error if code in one section called
4723 a function defined in the other section.
4725 The @code{NOCROSSREFS} command takes a list of output section names. If
4726 @command{ld} detects any cross references between the sections, it reports
4727 an error and returns a non-zero exit status. Note that the
4728 @code{NOCROSSREFS} command uses output section names, not input section
4731 @item NOCROSSREFS_TO(@var{tosection} @var{fromsection} @dots{})
4732 @kindex NOCROSSREFS_TO(@var{tosection} @var{fromsections})
4733 @cindex cross references
4734 This command may be used to tell @command{ld} to issue an error about any
4735 references to one section from a list of other sections.
4737 The @code{NOCROSSREFS} command is useful when ensuring that two or more
4738 output sections are entirely independent but there are situations where
4739 a one-way dependency is needed. For example, in a multi-core application
4740 there may be shared code that can be called from each core but for safety
4741 must never call back.
4743 The @code{NOCROSSREFS_TO} command takes a list of output section names.
4744 The first section can not be referenced from any of the other sections.
4745 If @command{ld} detects any references to the first section from any of
4746 the other sections, it reports an error and returns a non-zero exit
4747 status. Note that the @code{NOCROSSREFS_TO} command uses output section
4748 names, not input section names.
4750 @ifclear SingleFormat
4751 @item OUTPUT_ARCH(@var{bfdarch})
4752 @kindex OUTPUT_ARCH(@var{bfdarch})
4753 @cindex machine architecture
4754 @cindex architecture
4755 Specify a particular output machine architecture. The argument is one
4756 of the names used by the BFD library (@pxref{BFD}). You can see the
4757 architecture of an object file by using the @code{objdump} program with
4758 the @samp{-f} option.
4761 @item LD_FEATURE(@var{string})
4762 @kindex LD_FEATURE(@var{string})
4763 This command may be used to modify @command{ld} behavior. If
4764 @var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
4765 in a script are simply treated as numbers everywhere.
4766 @xref{Expression Section}.
4770 @section Assigning Values to Symbols
4771 @cindex assignment in scripts
4772 @cindex symbol definition, scripts
4773 @cindex variables, defining
4774 You may assign a value to a symbol in a linker script. This will define
4775 the symbol and place it into the symbol table with a global scope.
4778 * Simple Assignments:: Simple Assignments
4781 * PROVIDE_HIDDEN:: PROVIDE_HIDDEN
4782 * Source Code Reference:: How to use a linker script defined symbol in source code
4785 @node Simple Assignments
4786 @subsection Simple Assignments
4788 You may assign to a symbol using any of the C assignment operators:
4791 @item @var{symbol} = @var{expression} ;
4792 @itemx @var{symbol} += @var{expression} ;
4793 @itemx @var{symbol} -= @var{expression} ;
4794 @itemx @var{symbol} *= @var{expression} ;
4795 @itemx @var{symbol} /= @var{expression} ;
4796 @itemx @var{symbol} <<= @var{expression} ;
4797 @itemx @var{symbol} >>= @var{expression} ;
4798 @itemx @var{symbol} &= @var{expression} ;
4799 @itemx @var{symbol} |= @var{expression} ;
4802 The first case will define @var{symbol} to the value of
4803 @var{expression}. In the other cases, @var{symbol} must already be
4804 defined, and the value will be adjusted accordingly.
4806 The special symbol name @samp{.} indicates the location counter. You
4807 may only use this within a @code{SECTIONS} command. @xref{Location Counter}.
4809 The semicolon after @var{expression} is required.
4811 Expressions are defined below; see @ref{Expressions}.
4813 You may write symbol assignments as commands in their own right, or as
4814 statements within a @code{SECTIONS} command, or as part of an output
4815 section description in a @code{SECTIONS} command.
4817 The section of the symbol will be set from the section of the
4818 expression; for more information, see @ref{Expression Section}.
4820 Here is an example showing the three different places that symbol
4821 assignments may be used:
4832 _bdata = (. + 3) & ~ 3;
4833 .data : @{ *(.data) @}
4837 In this example, the symbol @samp{floating_point} will be defined as
4838 zero. The symbol @samp{_etext} will be defined as the address following
4839 the last @samp{.text} input section. The symbol @samp{_bdata} will be
4840 defined as the address following the @samp{.text} output section aligned
4841 upward to a 4 byte boundary.
4846 For ELF targeted ports, define a symbol that will be hidden and won't be
4847 exported. The syntax is @code{HIDDEN(@var{symbol} = @var{expression})}.
4849 Here is the example from @ref{Simple Assignments}, rewritten to use
4853 HIDDEN(floating_point = 0);
4861 HIDDEN(_bdata = (. + 3) & ~ 3);
4862 .data : @{ *(.data) @}
4866 In this case none of the three symbols will be visible outside this module.
4871 In some cases, it is desirable for a linker script to define a symbol
4872 only if it is referenced and is not defined by any object included in
4873 the link. For example, traditional linkers defined the symbol
4874 @samp{etext}. However, ANSI C requires that the user be able to use
4875 @samp{etext} as a function name without encountering an error. The
4876 @code{PROVIDE} keyword may be used to define a symbol, such as
4877 @samp{etext}, only if it is referenced but not defined. The syntax is
4878 @code{PROVIDE(@var{symbol} = @var{expression})}.
4880 Here is an example of using @code{PROVIDE} to define @samp{etext}:
4893 In this example, if the program defines @samp{_etext} (with a leading
4894 underscore), the linker will give a multiple definition diagnostic. If,
4895 on the other hand, the program defines @samp{etext} (with no leading
4896 underscore), the linker will silently use the definition in the program.
4897 If the program references @samp{etext} but does not define it, the
4898 linker will use the definition in the linker script.
4900 Note - the @code{PROVIDE} directive considers a common symbol to be
4901 defined, even though such a symbol could be combined with the symbol
4902 that the @code{PROVIDE} would create. This is particularly important
4903 when considering constructor and destructor list symbols such as
4904 @samp{__CTOR_LIST__} as these are often defined as common symbols.
4906 @node PROVIDE_HIDDEN
4907 @subsection PROVIDE_HIDDEN
4908 @cindex PROVIDE_HIDDEN
4909 Similar to @code{PROVIDE}. For ELF targeted ports, the symbol will be
4910 hidden and won't be exported.
4912 @node Source Code Reference
4913 @subsection Source Code Reference
4915 Accessing a linker script defined variable from source code is not
4916 intuitive. In particular a linker script symbol is not equivalent to
4917 a variable declaration in a high level language, it is instead a
4918 symbol that does not have a value.
4920 Before going further, it is important to note that compilers often
4921 transform names in the source code into different names when they are
4922 stored in the symbol table. For example, Fortran compilers commonly
4923 prepend or append an underscore, and C++ performs extensive @samp{name
4924 mangling}. Therefore there might be a discrepancy between the name
4925 of a variable as it is used in source code and the name of the same
4926 variable as it is defined in a linker script. For example in C a
4927 linker script variable might be referred to as:
4933 But in the linker script it might be defined as:
4939 In the remaining examples however it is assumed that no name
4940 transformation has taken place.
4942 When a symbol is declared in a high level language such as C, two
4943 things happen. The first is that the compiler reserves enough space
4944 in the program's memory to hold the @emph{value} of the symbol. The
4945 second is that the compiler creates an entry in the program's symbol
4946 table which holds the symbol's @emph{address}. ie the symbol table
4947 contains the address of the block of memory holding the symbol's
4948 value. So for example the following C declaration, at file scope:
4954 creates an entry called @samp{foo} in the symbol table. This entry
4955 holds the address of an @samp{int} sized block of memory where the
4956 number 1000 is initially stored.
4958 When a program references a symbol the compiler generates code that
4959 first accesses the symbol table to find the address of the symbol's
4960 memory block and then code to read the value from that memory block.
4967 looks up the symbol @samp{foo} in the symbol table, gets the address
4968 associated with this symbol and then writes the value 1 into that
4975 looks up the symbol @samp{foo} in the symbol table, gets its address
4976 and then copies this address into the block of memory associated with
4977 the variable @samp{a}.
4979 Linker scripts symbol declarations, by contrast, create an entry in
4980 the symbol table but do not assign any memory to them. Thus they are
4981 an address without a value. So for example the linker script definition:
4987 creates an entry in the symbol table called @samp{foo} which holds
4988 the address of memory location 1000, but nothing special is stored at
4989 address 1000. This means that you cannot access the @emph{value} of a
4990 linker script defined symbol - it has no value - all you can do is
4991 access the @emph{address} of a linker script defined symbol.
4993 Hence when you are using a linker script defined symbol in source code
4994 you should always take the address of the symbol, and never attempt to
4995 use its value. For example suppose you want to copy the contents of a
4996 section of memory called .ROM into a section called .FLASH and the
4997 linker script contains these declarations:
5001 start_of_ROM = .ROM;
5002 end_of_ROM = .ROM + sizeof (.ROM);
5003 start_of_FLASH = .FLASH;
5007 Then the C source code to perform the copy would be:
5011 extern char start_of_ROM, end_of_ROM, start_of_FLASH;
5013 memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
5017 Note the use of the @samp{&} operators. These are correct.
5018 Alternatively the symbols can be treated as the names of vectors or
5019 arrays and then the code will again work as expected:
5023 extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
5025 memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
5029 Note how using this method does not require the use of @samp{&}
5033 @section SECTIONS Command
5035 The @code{SECTIONS} command tells the linker how to map input sections
5036 into output sections, and how to place the output sections in memory.
5038 The format of the @code{SECTIONS} command is:
5042 @var{sections-command}
5043 @var{sections-command}
5048 Each @var{sections-command} may of be one of the following:
5052 an @code{ENTRY} command (@pxref{Entry Point,,Entry command})
5054 a symbol assignment (@pxref{Assignments})
5056 an output section description
5058 an overlay description
5061 The @code{ENTRY} command and symbol assignments are permitted inside the
5062 @code{SECTIONS} command for convenience in using the location counter in
5063 those commands. This can also make the linker script easier to
5064 understand because you can use those commands at meaningful points in
5065 the layout of the output file.
5067 Output section descriptions and overlay descriptions are described
5070 If you do not use a @code{SECTIONS} command in your linker script, the
5071 linker will place each input section into an identically named output
5072 section in the order that the sections are first encountered in the
5073 input files. If all input sections are present in the first file, for
5074 example, the order of sections in the output file will match the order
5075 in the first input file. The first section will be at address zero.
5078 * Output Section Description:: Output section description
5079 * Output Section Name:: Output section name
5080 * Output Section Address:: Output section address
5081 * Input Section:: Input section description
5082 * Output Section Data:: Output section data
5083 * Output Section Keywords:: Output section keywords
5084 * Output Section Discarding:: Output section discarding
5085 * Output Section Attributes:: Output section attributes
5086 * Overlay Description:: Overlay description
5089 @node Output Section Description
5090 @subsection Output Section Description
5091 The full description of an output section looks like this:
5094 @var{section} [@var{address}] [(@var{type})] :
5096 [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
5097 [SUBALIGN(@var{subsection_align})]
5100 @var{output-section-command}
5101 @var{output-section-command}
5103 @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] [,]
5107 Most output sections do not use most of the optional section attributes.
5109 The whitespace around @var{section} is required, so that the section
5110 name is unambiguous. The colon and the curly braces are also required.
5111 The comma at the end may be required if a @var{fillexp} is used and
5112 the next @var{sections-command} looks like a continuation of the expression.
5113 The line breaks and other white space are optional.
5115 Each @var{output-section-command} may be one of the following:
5119 a symbol assignment (@pxref{Assignments})
5121 an input section description (@pxref{Input Section})
5123 data values to include directly (@pxref{Output Section Data})
5125 a special output section keyword (@pxref{Output Section Keywords})
5128 @node Output Section Name
5129 @subsection Output Section Name
5130 @cindex name, section
5131 @cindex section name
5132 The name of the output section is @var{section}. @var{section} must
5133 meet the constraints of your output format. In formats which only
5134 support a limited number of sections, such as @code{a.out}, the name
5135 must be one of the names supported by the format (@code{a.out}, for
5136 example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
5137 output format supports any number of sections, but with numbers and not
5138 names (as is the case for Oasys), the name should be supplied as a
5139 quoted numeric string. A section name may consist of any sequence of
5140 characters, but a name which contains any unusual characters such as
5141 commas must be quoted.
5143 The output section name @samp{/DISCARD/} is special; @ref{Output Section
5146 @node Output Section Address
5147 @subsection Output Section Address
5148 @cindex address, section
5149 @cindex section address
5150 The @var{address} is an expression for the VMA (the virtual memory
5151 address) of the output section. This address is optional, but if it
5152 is provided then the output address will be set exactly as specified.
5154 If the output address is not specified then one will be chosen for the
5155 section, based on the heuristic below. This address will be adjusted
5156 to fit the alignment requirement of the output section. The
5157 alignment requirement is the strictest alignment of any input section
5158 contained within the output section.
5160 The output section address heuristic is as follows:
5164 If an output memory @var{region} is set for the section then it
5165 is added to this region and its address will be the next free address
5169 If the MEMORY command has been used to create a list of memory
5170 regions then the first region which has attributes compatible with the
5171 section is selected to contain it. The section's output address will
5172 be the next free address in that region; @ref{MEMORY}.
5175 If no memory regions were specified, or none match the section then
5176 the output address will be based on the current value of the location
5184 .text . : @{ *(.text) @}
5191 .text : @{ *(.text) @}
5195 are subtly different. The first will set the address of the
5196 @samp{.text} output section to the current value of the location
5197 counter. The second will set it to the current value of the location
5198 counter aligned to the strictest alignment of any of the @samp{.text}
5201 The @var{address} may be an arbitrary expression; @ref{Expressions}.
5202 For example, if you want to align the section on a 0x10 byte boundary,
5203 so that the lowest four bits of the section address are zero, you could
5204 do something like this:
5206 .text ALIGN(0x10) : @{ *(.text) @}
5209 This works because @code{ALIGN} returns the current location counter
5210 aligned upward to the specified value.
5212 Specifying @var{address} for a section will change the value of the
5213 location counter, provided that the section is non-empty. (Empty
5214 sections are ignored).
5217 @subsection Input Section Description
5218 @cindex input sections
5219 @cindex mapping input sections to output sections
5220 The most common output section command is an input section description.
5222 The input section description is the most basic linker script operation.
5223 You use output sections to tell the linker how to lay out your program
5224 in memory. You use input section descriptions to tell the linker how to
5225 map the input files into your memory layout.
5228 * Input Section Basics:: Input section basics
5229 * Input Section Wildcards:: Input section wildcard patterns
5230 * Input Section Common:: Input section for common symbols
5231 * Input Section Keep:: Input section and garbage collection
5232 * Input Section Example:: Input section example
5235 @node Input Section Basics
5236 @subsubsection Input Section Basics
5237 @cindex input section basics
5238 An input section description consists of a file name optionally followed
5239 by a list of section names in parentheses.
5241 The file name and the section name may be wildcard patterns, which we
5242 describe further below (@pxref{Input Section Wildcards}).
5244 The most common input section description is to include all input
5245 sections with a particular name in the output section. For example, to
5246 include all input @samp{.text} sections, you would write:
5251 Here the @samp{*} is a wildcard which matches any file name. To exclude a list
5252 @cindex EXCLUDE_FILE
5253 of files from matching the file name wildcard, EXCLUDE_FILE may be used to
5254 match all files except the ones specified in the EXCLUDE_FILE list. For
5257 EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
5260 will cause all .ctors sections from all files except @file{crtend.o}
5261 and @file{otherfile.o} to be included. The EXCLUDE_FILE can also be
5262 placed inside the section list, for example:
5264 *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
5267 The result of this is identically to the previous example. Supporting
5268 two syntaxes for EXCLUDE_FILE is useful if the section list contains
5269 more than one section, as described below.
5271 There are two ways to include more than one section:
5277 The difference between these is the order in which the @samp{.text} and
5278 @samp{.rdata} input sections will appear in the output section. In the
5279 first example, they will be intermingled, appearing in the same order as
5280 they are found in the linker input. In the second example, all
5281 @samp{.text} input sections will appear first, followed by all
5282 @samp{.rdata} input sections.
5284 When using EXCLUDE_FILE with more than one section, if the exclusion
5285 is within the section list then the exclusion only applies to the
5286 immediately following section, for example:
5288 *(EXCLUDE_FILE (*somefile.o) .text .rdata)
5291 will cause all @samp{.text} sections from all files except
5292 @file{somefile.o} to be included, while all @samp{.rdata} sections
5293 from all files, including @file{somefile.o}, will be included. To
5294 exclude the @samp{.rdata} sections from @file{somefile.o} the example
5295 could be modified to:
5297 *(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
5300 Alternatively, placing the EXCLUDE_FILE outside of the section list,
5301 before the input file selection, will cause the exclusion to apply for
5302 all sections. Thus the previous example can be rewritten as:
5304 EXCLUDE_FILE (*somefile.o) *(.text .rdata)
5307 You can specify a file name to include sections from a particular file.
5308 You would do this if one or more of your files contain special data that
5309 needs to be at a particular location in memory. For example:
5314 To refine the sections that are included based on the section flags
5315 of an input section, INPUT_SECTION_FLAGS may be used.
5317 Here is a simple example for using Section header flags for ELF sections:
5322 .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @}
5323 .text2 : @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @}
5328 In this example, the output section @samp{.text} will be comprised of any
5329 input section matching the name *(.text) whose section header flags
5330 @code{SHF_MERGE} and @code{SHF_STRINGS} are set. The output section
5331 @samp{.text2} will be comprised of any input section matching the name *(.text)
5332 whose section header flag @code{SHF_WRITE} is clear.
5334 You can also specify files within archives by writing a pattern
5335 matching the archive, a colon, then the pattern matching the file,
5336 with no whitespace around the colon.
5340 matches file within archive
5342 matches the whole archive
5344 matches file but not one in an archive
5347 Either one or both of @samp{archive} and @samp{file} can contain shell
5348 wildcards. On DOS based file systems, the linker will assume that a
5349 single letter followed by a colon is a drive specifier, so
5350 @samp{c:myfile.o} is a simple file specification, not @samp{myfile.o}
5351 within an archive called @samp{c}. @samp{archive:file} filespecs may
5352 also be used within an @code{EXCLUDE_FILE} list, but may not appear in
5353 other linker script contexts. For instance, you cannot extract a file
5354 from an archive by using @samp{archive:file} in an @code{INPUT}
5357 If you use a file name without a list of sections, then all sections in
5358 the input file will be included in the output section. This is not
5359 commonly done, but it may by useful on occasion. For example:
5364 When you use a file name which is not an @samp{archive:file} specifier
5365 and does not contain any wild card
5366 characters, the linker will first see if you also specified the file
5367 name on the linker command line or in an @code{INPUT} command. If you
5368 did not, the linker will attempt to open the file as an input file, as
5369 though it appeared on the command line. Note that this differs from an
5370 @code{INPUT} command, because the linker will not search for the file in
5371 the archive search path.
5373 @node Input Section Wildcards
5374 @subsubsection Input Section Wildcard Patterns
5375 @cindex input section wildcards
5376 @cindex wildcard file name patterns
5377 @cindex file name wildcard patterns
5378 @cindex section name wildcard patterns
5379 In an input section description, either the file name or the section
5380 name or both may be wildcard patterns.
5382 The file name of @samp{*} seen in many examples is a simple wildcard
5383 pattern for the file name.
5385 The wildcard patterns are like those used by the Unix shell.
5389 matches any number of characters
5391 matches any single character
5393 matches a single instance of any of the @var{chars}; the @samp{-}
5394 character may be used to specify a range of characters, as in
5395 @samp{[a-z]} to match any lower case letter
5397 quotes the following character
5400 File name wildcard patterns only match files which are explicitly
5401 specified on the command line or in an @code{INPUT} command. The linker
5402 does not search directories to expand wildcards.
5404 If a file name matches more than one wildcard pattern, or if a file name
5405 appears explicitly and is also matched by a wildcard pattern, the linker
5406 will use the first match in the linker script. For example, this
5407 sequence of input section descriptions is probably in error, because the
5408 @file{data.o} rule will not be used:
5410 .data : @{ *(.data) @}
5411 .data1 : @{ data.o(.data) @}
5414 @cindex SORT_BY_NAME
5415 Normally, the linker will place files and sections matched by wildcards
5416 in the order in which they are seen during the link. You can change
5417 this by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
5418 pattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}). When the
5419 @code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
5420 into ascending order by name before placing them in the output file.
5422 @cindex SORT_BY_ALIGNMENT
5423 @code{SORT_BY_ALIGNMENT} is similar to @code{SORT_BY_NAME}.
5424 @code{SORT_BY_ALIGNMENT} will sort sections into descending order of
5425 alignment before placing them in the output file. Placing larger
5426 alignments before smaller alignments can reduce the amount of padding
5429 @cindex SORT_BY_INIT_PRIORITY
5430 @code{SORT_BY_INIT_PRIORITY} is also similar to @code{SORT_BY_NAME}.
5431 @code{SORT_BY_INIT_PRIORITY} will sort sections into ascending
5432 numerical order of the GCC init_priority attribute encoded in the
5433 section name before placing them in the output file. In
5434 @code{.init_array.NNNNN} and @code{.fini_array.NNNNN}, @code{NNNNN} is
5435 the init_priority. In @code{.ctors.NNNNN} and @code{.dtors.NNNNN},
5436 @code{NNNNN} is 65535 minus the init_priority.
5439 @code{SORT} is an alias for @code{SORT_BY_NAME}.
5442 @code{REVERSE} indicates that the sorting should be reversed. If used
5443 on its own then @code{REVERSE} implies @code{SORT_BY_NAME}, otherwise
5444 it reverses the enclosed @code{SORT..} command. Note - reverse
5445 sorting of alignment is not currently supported.
5447 Note - the sorting commands only accept a single wildcard pattern. So
5448 for example the following will not work:
5450 *(REVERSE(.text* .init*))
5452 To resolve this problem list the patterns individually, like this:
5458 Note - you can put the @code{EXCLUDE_FILE} command inside a sorting
5459 command, but not the other way around. So for example:
5461 *(SORT_BY_NAME(EXCLUDE_FILE(foo) .text*))
5465 *(EXCLUDE_FILE(foo) SORT_BY_NAME(.text*))
5470 When there are nested section sorting commands in linker script, there
5471 can be at most 1 level of nesting for section sorting commands.
5475 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5476 It will sort the input sections by name first, then by alignment if two
5477 sections have the same name.
5479 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5480 It will sort the input sections by alignment first, then by name if two
5481 sections have the same alignment.
5483 @code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is
5484 treated the same as @code{SORT_BY_NAME} (wildcard section pattern).
5486 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
5487 is treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
5489 @code{SORT_BY_NAME} (@code{REVERSE} (wildcard section pattern))
5490 reverse sorts by name.
5492 @code{REVERSE} (@code{SORT_BY_NAME} (wildcard section pattern))
5493 reverse sorts by name.
5495 @code{SORT_BY_INIT_PRIORITY} (@code{REVERSE} (wildcard section pattern))
5496 reverse sorts by init priority.
5498 All other nested section sorting commands are invalid.
5501 When both command-line section sorting option and linker script
5502 section sorting command are used, section sorting command always
5503 takes precedence over the command-line option.
5505 If the section sorting command in linker script isn't nested, the
5506 command-line option will make the section sorting command to be
5507 treated as nested sorting command.
5511 @code{SORT_BY_NAME} (wildcard section pattern ) with
5512 @option{--sort-sections alignment} is equivalent to
5513 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5515 @code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
5516 @option{--sort-section name} is equivalent to
5517 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5520 If the section sorting command in linker script is nested, the
5521 command-line option will be ignored.
5524 @code{SORT_NONE} disables section sorting by ignoring the command-line
5525 section sorting option.
5527 If you ever get confused about where input sections are going, use the
5528 @samp{-M} linker option to generate a map file. The map file shows
5529 precisely how input sections are mapped to output sections.
5531 This example shows how wildcard patterns might be used to partition
5532 files. This linker script directs the linker to place all @samp{.text}
5533 sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
5534 The linker will place the @samp{.data} section from all files beginning
5535 with an upper case character in @samp{.DATA}; for all other files, the
5536 linker will place the @samp{.data} section in @samp{.data}.
5540 .text : @{ *(.text) @}
5541 .DATA : @{ [A-Z]*(.data) @}
5542 .data : @{ *(.data) @}
5543 .bss : @{ *(.bss) @}
5548 @node Input Section Common
5549 @subsubsection Input Section for Common Symbols
5550 @cindex common symbol placement
5551 @cindex uninitialized data placement
5552 A special notation is needed for common symbols, because in many object
5553 file formats common symbols do not have a particular input section. The
5554 linker treats common symbols as though they are in an input section
5555 named @samp{COMMON}.
5557 You may use file names with the @samp{COMMON} section just as with any
5558 other input sections. You can use this to place common symbols from a
5559 particular input file in one section while common symbols from other
5560 input files are placed in another section.
5562 In most cases, common symbols in input files will be placed in the
5563 @samp{.bss} section in the output file. For example:
5565 .bss @{ *(.bss) *(COMMON) @}
5568 @cindex scommon section
5569 @cindex small common symbols
5570 Some object file formats have more than one type of common symbol. For
5571 example, the MIPS ELF object file format distinguishes standard common
5572 symbols and small common symbols. In this case, the linker will use a
5573 different special section name for other types of common symbols. In
5574 the case of MIPS ELF, the linker uses @samp{COMMON} for standard common
5575 symbols and @samp{.scommon} for small common symbols. This permits you
5576 to map the different types of common symbols into memory at different
5580 You will sometimes see @samp{[COMMON]} in old linker scripts. This
5581 notation is now considered obsolete. It is equivalent to
5584 @node Input Section Keep
5585 @subsubsection Input Section and Garbage Collection
5587 @cindex garbage collection
5588 When link-time garbage collection is in use (@samp{--gc-sections}),
5589 it is often useful to mark sections that should not be eliminated.
5590 This is accomplished by surrounding an input section's wildcard entry
5591 with @code{KEEP()}, as in @code{KEEP(*(.init))} or
5592 @code{KEEP(SORT_BY_NAME(*)(.ctors))}.
5594 @node Input Section Example
5595 @subsubsection Input Section Example
5596 The following example is a complete linker script. It tells the linker
5597 to read all of the sections from file @file{all.o} and place them at the
5598 start of output section @samp{outputa} which starts at location
5599 @samp{0x10000}. All of section @samp{.input1} from file @file{foo.o}
5600 follows immediately, in the same output section. All of section
5601 @samp{.input2} from @file{foo.o} goes into output section
5602 @samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
5603 All of the remaining @samp{.input1} and @samp{.input2} sections from any
5604 files are written to output section @samp{outputc}.
5632 If an output section's name is the same as the input section's name
5633 and is representable as a C identifier, then the linker will
5634 automatically @pxref{PROVIDE} two symbols: __start_SECNAME and
5635 __stop_SECNAME, where SECNAME is the name of the section. These
5636 indicate the start address and end address of the output section
5637 respectively. Note: most section names are not representable as
5638 C identifiers because they contain a @samp{.} character.
5640 @node Output Section Data
5641 @subsection Output Section Data
5643 @cindex section data
5644 @cindex output section data
5645 @kindex ASCIZ ``@var{string}''
5646 @kindex BYTE(@var{expression})
5647 @kindex SHORT(@var{expression})
5648 @kindex LONG(@var{expression})
5649 @kindex QUAD(@var{expression})
5650 @kindex SQUAD(@var{expression})
5651 You can include explicit bytes of data in an output section by using
5652 @code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
5653 an output section command. Each keyword is followed by an expression in
5654 parentheses providing the value to store (@pxref{Expressions}). The
5655 value of the expression is stored at the current value of the location
5658 The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
5659 store one, two, four, and eight bytes (respectively). After storing the
5660 bytes, the location counter is incremented by the number of bytes
5663 For example, this will store the byte 1 followed by the four byte value
5664 of the symbol @samp{addr}:
5670 When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
5671 same; they both store an 8 byte, or 64 bit, value. When both host and
5672 target are 32 bits, an expression is computed as 32 bits. In this case
5673 @code{QUAD} stores a 32 bit value zero extended to 64 bits, and
5674 @code{SQUAD} stores a 32 bit value sign extended to 64 bits.
5676 If the object file format of the output file has an explicit endianness,
5677 which is the normal case, the value will be stored in that endianness.
5678 When the object file format does not have an explicit endianness, as is
5679 true of, for example, S-records, the value will be stored in the
5680 endianness of the first input object file.
5682 You can include a zero-terminated string in an output section by using
5683 @code{ASCIZ}. The keyword is followed by a string which is stored at
5684 the current value of the location counter adding a zero byte at the
5685 end. If the string includes spaces it must be enclosed in double
5686 quotes. The string may contain '\n', '\r', '\t' and octal numbers.
5687 Hex numbers are not supported.
5689 For example, this string of 16 characters will create a 17 byte area
5691 ASCIZ "This is 16 bytes"
5694 Note---these commands only work inside a section description and not
5695 between them, so the following will produce an error from the linker:
5697 SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
5699 whereas this will work:
5701 SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
5704 @kindex FILL(@var{expression})
5705 @cindex holes, filling
5706 @cindex unspecified memory
5707 You may use the @code{FILL} command to set the fill pattern for the
5708 current section. It is followed by an expression in parentheses. Any
5709 otherwise unspecified regions of memory within the section (for example,
5710 gaps left due to the required alignment of input sections) are filled
5711 with the value of the expression, repeated as
5712 necessary. A @code{FILL} statement covers memory locations after the
5713 point at which it occurs in the section definition; by including more
5714 than one @code{FILL} statement, you can have different fill patterns in
5715 different parts of an output section.
5717 This example shows how to fill unspecified regions of memory with the
5723 The @code{FILL} command is similar to the @samp{=@var{fillexp}} output
5724 section attribute, but it only affects the
5725 part of the section following the @code{FILL} command, rather than the
5726 entire section. If both are used, the @code{FILL} command takes
5727 precedence. @xref{Output Section Fill}, for details on the fill
5730 Note - normally the value of @code{expression} is zero extended to 4
5731 bytes when used to fill gaps. Thus @samp{FILL(144)} will fill a
5732 region with repeats of the pattern @samp{0 0 0 144}. The value is
5733 treated as a big-endian number, so for example
5734 @samp{FILL(22 * 256 + 23)} will fill the region with repeats of the
5735 pattern @samp{0 0 22 23}. If the expression results in a value with
5736 more than 4 significant bytes only the least 4 bytes of the value will
5739 The above rules do not apply when the @code{expression} is a simple
5740 hexadecimal number. In this case zero extension is not performed and
5741 all bytes are significant. So @samp{FILL(0x90)} will fill a region with
5742 repeats of @samp{0x90} with no zero bytes, and @samp{FILL(0x9192)}
5743 will fill the region with repeats of @samp{0x91 0x92}. Zero bytes
5744 in a hexadecimal expression are significant even at the start, so
5745 @samp{FILL(0x0090)} will fill a region with repeats of @samp{0x00 0x90}.
5747 Hexadecimal numbers can be longer than 4 bytes, and all of the bytes
5748 are significant, so @samp{FILL(0x123456789a)} will fill a region with
5749 repeats of the 5 byte sequence @samp{0x12 0x34 0x56 0x78 0x9a}.
5750 Excess bytes in a hexadecimal value beyond the size of a region will
5751 be silently ignored.
5753 The above only applies to hexadecimal numbers specified as
5754 @samp{0x[0-9][a-f][A-F]}. Hexadecimal numbers specified with a
5755 @samp{$} prefix, or a @samp{h}, @samp{H}, @samp{x} or @samp{X} suffix
5756 will follow the normal fill value rules. This also applies to
5757 expressions that involve hexadecimal numbers, and hexadecimal numbers
5758 that have a magnitude suffix.
5760 @kindex LINKER_VERSION
5761 @cindex LINKER_VERSION
5762 The @code{LINKER_VERSION} command inserts a string containing the
5763 version of the linker at the current point. Note - by default this
5764 directive is disabled and will do nothing. It only becomes active if
5765 the @option{--enable-linker-version} command line option is used.
5767 Built-in linker scripts for ELF based targets already include this
5768 directive in their @samp{.comment} section.
5770 @node Output Section Keywords
5771 @subsection Output Section Keywords
5772 There are a couple of keywords which can appear as output section
5776 @kindex CREATE_OBJECT_SYMBOLS
5777 @cindex input filename symbols
5778 @cindex filename symbols
5779 @item CREATE_OBJECT_SYMBOLS
5780 The command tells the linker to create a symbol for each input file.
5781 The name of each symbol will be the name of the corresponding input
5782 file. The section of each symbol will be the output section in which
5783 the @code{CREATE_OBJECT_SYMBOLS} command appears.
5785 This is conventional for the a.out object file format. It is not
5786 normally used for any other object file format.
5788 @kindex CONSTRUCTORS
5789 @cindex C++ constructors, arranging in link
5790 @cindex constructors, arranging in link
5792 When linking using the a.out object file format, the linker uses an
5793 unusual set construct to support C++ global constructors and
5794 destructors. When linking object file formats which do not support
5795 arbitrary sections, such as ECOFF and XCOFF, the linker will
5796 automatically recognize C++ global constructors and destructors by name.
5797 For these object file formats, the @code{CONSTRUCTORS} command tells the
5798 linker to place constructor information in the output section where the
5799 @code{CONSTRUCTORS} command appears. The @code{CONSTRUCTORS} command is
5800 ignored for other object file formats.
5802 The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
5803 constructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
5804 Similarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
5805 the start and end of the global destructors. The
5806 first word in the list is the number of entries, followed by the address
5807 of each constructor or destructor, followed by a zero word. The
5808 compiler must arrange to actually run the code. For these object file
5809 formats @sc{gnu} C++ normally calls constructors from a subroutine
5810 @code{__main}; a call to @code{__main} is automatically inserted into
5811 the startup code for @code{main}. @sc{gnu} C++ normally runs
5812 destructors either by using @code{atexit}, or directly from the function
5815 For object file formats such as @code{COFF} or @code{ELF} which support
5816 arbitrary section names, @sc{gnu} C++ will normally arrange to put the
5817 addresses of global constructors and destructors into the @code{.ctors}
5818 and @code{.dtors} sections. Placing the following sequence into your
5819 linker script will build the sort of table which the @sc{gnu} C++
5820 runtime code expects to see.
5824 LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
5829 LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
5835 If you are using the @sc{gnu} C++ support for initialization priority,
5836 which provides some control over the order in which global constructors
5837 are run, you must sort the constructors at link time to ensure that they
5838 are executed in the correct order. When using the @code{CONSTRUCTORS}
5839 command, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead. When using the
5840 @code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
5841 @samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
5844 Normally the compiler and linker will handle these issues automatically,
5845 and you will not need to concern yourself with them. However, you may
5846 need to consider this if you are using C++ and writing your own linker
5851 @node Output Section Discarding
5852 @subsection Output Section Discarding
5853 @cindex discarding sections
5854 @cindex sections, discarding
5855 @cindex removing sections
5856 The linker will not normally create output sections with no contents.
5857 This is for convenience when referring to input sections that may or
5858 may not be present in any of the input files. For example:
5860 .foo : @{ *(.foo) @}
5863 will only create a @samp{.foo} section in the output file if there is a
5864 @samp{.foo} section in at least one input file, and if the input
5865 sections are not all empty. Other link script directives that allocate
5866 space in an output section will also create the output section. So
5867 too will assignments to dot even if the assignment does not create
5868 space, except for @samp{. = 0}, @samp{. = . + 0}, @samp{. = sym},
5869 @samp{. = . + sym} and @samp{. = ALIGN (. != 0, expr, 1)} when
5870 @samp{sym} is an absolute symbol of value 0 defined in the script.
5871 This allows you to force output of an empty section with @samp{. = .}.
5873 The linker will ignore address assignments (@pxref{Output Section Address})
5874 on discarded output sections, except when the linker script defines
5875 symbols in the output section. In that case the linker will obey
5876 the address assignments, possibly advancing dot even though the
5877 section is discarded.
5880 The special output section name @samp{/DISCARD/} may be used to discard
5881 input sections. Any input sections which are assigned to an output
5882 section named @samp{/DISCARD/} are not included in the output file.
5884 This can be used to discard input sections marked with the ELF flag
5885 @code{SHF_GNU_RETAIN}, which would otherwise have been saved from linker
5888 Note, sections that match the @samp{/DISCARD/} output section will be
5889 discarded even if they are in an ELF section group which has other
5890 members which are not being discarded. This is deliberate.
5891 Discarding takes precedence over grouping.
5893 @node Output Section Attributes
5894 @subsection Output Section Attributes
5895 @cindex output section attributes
5896 We showed above that the full description of an output section looked
5901 @var{section} [@var{address}] [(@var{type})] :
5903 [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
5904 [SUBALIGN(@var{subsection_align})]
5907 @var{output-section-command}
5908 @var{output-section-command}
5910 @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
5914 We've already described @var{section}, @var{address}, and
5915 @var{output-section-command}. In this section we will describe the
5916 remaining section attributes.
5919 * Output Section Type:: Output section type
5920 * Output Section LMA:: Output section LMA
5921 * Forced Output Alignment:: Forced Output Alignment
5922 * Forced Input Alignment:: Forced Input Alignment
5923 * Output Section Constraint:: Output section constraint
5924 * Output Section Region:: Output section region
5925 * Output Section Phdr:: Output section phdr
5926 * Output Section Fill:: Output section fill
5929 @node Output Section Type
5930 @subsubsection Output Section Type
5931 Each output section may have a type. The type is a keyword in
5932 parentheses. The following types are defined:
5937 The section should be marked as not loadable, so that it will not be
5938 loaded into memory when the program is run.
5941 The section should be marked as read-only.
5947 These type names are supported for backward compatibility, and are
5948 rarely used. They all have the same effect: the section should be
5949 marked as not allocatable, so that no memory is allocated for the
5950 section when the program is run.
5952 @item TYPE = @var{type}
5953 Set the section type to the integer @var{type}. When generating an ELF
5954 output file, type names @code{SHT_PROGBITS}, @code{SHT_STRTAB},
5955 @code{SHT_NOTE}, @code{SHT_NOBITS}, @code{SHT_INIT_ARRAY},
5956 @code{SHT_FINI_ARRAY}, and @code{SHT_PREINIT_ARRAY} are also allowed
5957 for @var{type}. It is the user's responsibility to ensure that any
5958 special requirements of the section type are met.
5960 Note - the TYPE only is used if some or all of the contents of the
5961 section do not have an implicit type of their own. So for example:
5963 .foo . TYPE = SHT_PROGBITS @{ *(.bar) @}
5965 will set the type of section @samp{.foo} to the type of the section
5966 @samp{.bar} in the input files, which may not be the SHT_PROGBITS
5969 .foo . TYPE = SHT_PROGBITS @{ BYTE(1) @}
5971 will set the type of @samp{.foo} to SHT_PROGBBITS. If it is necessary
5972 to override the type of incoming sections and force the output section
5973 type then an extra piece of untyped data will be needed:
5975 .foo . TYPE = SHT_PROGBITS @{ BYTE(1); *(.bar) @}
5978 @item READONLY ( TYPE = @var{type} )
5979 This form of the syntax combines the @var{READONLY} type with the
5980 type specified by @var{type}.
5985 @cindex prevent unnecessary loading
5986 @cindex loading, preventing
5987 The linker normally sets the attributes of an output section based on
5988 the input sections which map into it. You can override this by using
5989 the section type. For example, in the script sample below, the
5990 @samp{ROM} section is addressed at memory location @samp{0} and does not
5991 need to be loaded when the program is run.
5995 ROM 0 (NOLOAD) : @{ @dots{} @}
6001 @node Output Section LMA
6002 @subsubsection Output Section LMA
6003 @kindex AT>@var{lma_region}
6004 @kindex AT(@var{lma})
6005 @cindex load address
6006 @cindex section load address
6007 Every section has a virtual address (VMA) and a load address (LMA); see
6008 @ref{Basic Script Concepts}. The virtual address is specified by the
6009 @pxref{Output Section Address} described earlier. The load address is
6010 specified by the @code{AT} or @code{AT>} keywords. Specifying a load
6011 address is optional.
6013 The @code{AT} keyword takes an expression as an argument. This
6014 specifies the exact load address of the section. The @code{AT>} keyword
6015 takes the name of a memory region as an argument. @xref{MEMORY}. The
6016 load address of the section is set to the next free address in the
6017 region, aligned to the section's alignment requirements.
6019 If neither @code{AT} nor @code{AT>} is specified for an allocatable
6020 section, the linker will use the following heuristic to determine the
6025 If the section has a specific VMA address, then this is used as
6026 the LMA address as well.
6029 If the section is not allocatable then its LMA is set to its VMA.
6032 Otherwise if a memory region can be found that is compatible
6033 with the current section, and this region contains at least one
6034 section, then the LMA is set so the difference between the
6035 VMA and LMA is the same as the difference between the VMA and LMA of
6036 the last section in the located region.
6039 If no memory regions have been declared then a default region
6040 that covers the entire address space is used in the previous step.
6043 If no suitable region could be found, or there was no previous
6044 section then the LMA is set equal to the VMA.
6047 @cindex ROM initialized data
6048 @cindex initialized data in ROM
6049 This feature is designed to make it easy to build a ROM image. For
6050 example, the following linker script creates three output sections: one
6051 called @samp{.text}, which starts at @code{0x1000}, one called
6052 @samp{.mdata}, which is loaded at the end of the @samp{.text} section
6053 even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
6054 uninitialized data at address @code{0x3000}. The symbol @code{_data} is
6055 defined with the value @code{0x2000}, which shows that the location
6056 counter holds the VMA value, not the LMA value.
6062 .text 0x1000 : @{ *(.text) _etext = . ; @}
6064 AT ( ADDR (.text) + SIZEOF (.text) )
6065 @{ _data = . ; *(.data); _edata = . ; @}
6067 @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@}
6072 The run-time initialization code for use with a program generated with
6073 this linker script would include something like the following, to copy
6074 the initialized data from the ROM image to its runtime address. Notice
6075 how this code takes advantage of the symbols defined by the linker
6080 extern char _etext, _data, _edata, _bstart, _bend;
6081 char *src = &_etext;
6084 /* ROM has data at end of text; copy it. */
6085 while (dst < &_edata)
6089 for (dst = &_bstart; dst< &_bend; dst++)
6094 @node Forced Output Alignment
6095 @subsubsection Forced Output Alignment
6096 @kindex ALIGN(@var{section_align})
6097 @cindex forcing output section alignment
6098 @cindex output section alignment
6099 You can increase an output section's alignment by using ALIGN. As an
6100 alternative you can enforce that the difference between the VMA and LMA remains
6101 intact throughout this output section with the ALIGN_WITH_INPUT attribute.
6103 @node Forced Input Alignment
6104 @subsubsection Forced Input Alignment
6105 @kindex SUBALIGN(@var{subsection_align})
6106 @cindex forcing input section alignment
6107 @cindex input section alignment
6108 You can force input section alignment within an output section by using
6109 SUBALIGN. The value specified overrides any alignment given by input
6110 sections, whether larger or smaller.
6112 @node Output Section Constraint
6113 @subsubsection Output Section Constraint
6116 @cindex constraints on output sections
6117 You can specify that an output section should only be created if all
6118 of its input sections are read-only or all of its input sections are
6119 read-write by using the keyword @code{ONLY_IF_RO} and
6120 @code{ONLY_IF_RW} respectively.
6122 @node Output Section Region
6123 @subsubsection Output Section Region
6124 @kindex >@var{region}
6125 @cindex section, assigning to memory region
6126 @cindex memory regions and sections
6127 You can assign a section to a previously defined region of memory by
6128 using @samp{>@var{region}}. @xref{MEMORY}.
6130 Here is a simple example:
6133 MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
6134 SECTIONS @{ ROM : @{ *(.text) @} >rom @}
6138 @node Output Section Phdr
6139 @subsubsection Output Section Phdr
6141 @cindex section, assigning to program header
6142 @cindex program headers and sections
6143 You can assign a section to a previously defined program segment by
6144 using @samp{:@var{phdr}}. @xref{PHDRS}. If a section is assigned to
6145 one or more segments, then all subsequent allocated sections will be
6146 assigned to those segments as well, unless they use an explicitly
6147 @code{:@var{phdr}} modifier. You can use @code{:NONE} to tell the
6148 linker to not put the section in any segment at all.
6150 Here is a simple example:
6153 PHDRS @{ text PT_LOAD ; @}
6154 SECTIONS @{ .text : @{ *(.text) @} :text @}
6158 @node Output Section Fill
6159 @subsubsection Output Section Fill
6160 @kindex =@var{fillexp}
6161 @cindex section fill pattern
6162 @cindex fill pattern, entire section
6163 You can set the fill pattern for an entire section by using
6164 @samp{=@var{fillexp}}. @var{fillexp} is an expression
6165 (@pxref{Expressions}). Any otherwise unspecified regions of memory
6166 within the output section (for example, gaps left due to the required
6167 alignment of input sections) will be filled with the value, repeated as
6168 necessary. If the fill expression is a simple hex number, ie. a string
6169 of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
6170 an arbitrarily long sequence of hex digits can be used to specify the
6171 fill pattern; Leading zeros become part of the pattern too. For all
6172 other cases, including extra parentheses or a unary @code{+}, the fill
6173 pattern is the four least significant bytes of the value of the
6174 expression. If the value is less than four bytes in size then it will
6175 be zero extended to four bytes. In all cases, the number is big-endian.
6178 Fill Value Fill Pattern
6184 You can also change the fill value with a @code{FILL} command in the
6185 output section commands; (@pxref{Output Section Data}).
6187 Here is a simple example:
6190 SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
6194 @node Overlay Description
6195 @subsection Overlay Description
6198 An overlay description provides an easy way to describe sections which
6199 are to be loaded as part of a single memory image but are to be run at
6200 the same memory address. At run time, some sort of overlay manager will
6201 copy the overlaid sections in and out of the runtime memory address as
6202 required, perhaps by simply manipulating addressing bits. This approach
6203 can be useful, for example, when a certain region of memory is faster
6206 Overlays are described using the @code{OVERLAY} command. The
6207 @code{OVERLAY} command is used within a @code{SECTIONS} command, like an
6208 output section description. The full syntax of the @code{OVERLAY}
6209 command is as follows:
6212 OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
6216 @var{output-section-command}
6217 @var{output-section-command}
6219 @} [:@var{phdr}@dots{}] [=@var{fill}]
6222 @var{output-section-command}
6223 @var{output-section-command}
6225 @} [:@var{phdr}@dots{}] [=@var{fill}]
6227 @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] [,]
6231 Everything is optional except @code{OVERLAY} (a keyword), and each
6232 section must have a name (@var{secname1} and @var{secname2} above). The
6233 section definitions within the @code{OVERLAY} construct are identical to
6234 those within the general @code{SECTIONS} construct (@pxref{SECTIONS}),
6235 except that no addresses and no memory regions may be defined for
6236 sections within an @code{OVERLAY}.
6238 The comma at the end may be required if a @var{fill} is used and
6239 the next @var{sections-command} looks like a continuation of the expression.
6241 The sections are all defined with the same starting address. The load
6242 addresses of the sections are arranged such that they are consecutive in
6243 memory starting at the load address used for the @code{OVERLAY} as a
6244 whole (as with normal section definitions, the load address is optional,
6245 and defaults to the start address; the start address is also optional,
6246 and defaults to the current value of the location counter).
6248 If the @code{NOCROSSREFS} keyword is used, and there are any
6249 references among the sections, the linker will report an error. Since
6250 the sections all run at the same address, it normally does not make
6251 sense for one section to refer directly to another.
6252 @xref{Miscellaneous Commands, NOCROSSREFS}.
6254 For each section within the @code{OVERLAY}, the linker automatically
6255 provides two symbols. The symbol @code{__load_start_@var{secname}} is
6256 defined as the starting load address of the section. The symbol
6257 @code{__load_stop_@var{secname}} is defined as the final load address of
6258 the section. Any characters within @var{secname} which are not legal
6259 within C identifiers are removed. C (or assembler) code may use these
6260 symbols to move the overlaid sections around as necessary.
6262 At the end of the overlay, the value of the location counter is set to
6263 the start address of the overlay plus the size of the largest section.
6265 Here is an example. Remember that this would appear inside a
6266 @code{SECTIONS} construct.
6269 OVERLAY 0x1000 : AT (0x4000)
6271 .text0 @{ o1/*.o(.text) @}
6272 .text1 @{ o2/*.o(.text) @}
6277 This will define both @samp{.text0} and @samp{.text1} to start at
6278 address 0x1000. @samp{.text0} will be loaded at address 0x4000, and
6279 @samp{.text1} will be loaded immediately after @samp{.text0}. The
6280 following symbols will be defined if referenced: @code{__load_start_text0},
6281 @code{__load_stop_text0}, @code{__load_start_text1},
6282 @code{__load_stop_text1}.
6284 C code to copy overlay @code{.text1} into the overlay area might look
6289 extern char __load_start_text1, __load_stop_text1;
6290 memcpy ((char *) 0x1000, &__load_start_text1,
6291 &__load_stop_text1 - &__load_start_text1);
6295 Note that the @code{OVERLAY} command is just syntactic sugar, since
6296 everything it does can be done using the more basic commands. The above
6297 example could have been written identically as follows.
6301 .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
6302 PROVIDE (__load_start_text0 = LOADADDR (.text0));
6303 PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
6304 .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
6305 PROVIDE (__load_start_text1 = LOADADDR (.text1));
6306 PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
6307 . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
6312 @section MEMORY Command
6314 @cindex memory regions
6315 @cindex regions of memory
6316 @cindex allocating memory
6317 @cindex discontinuous memory
6318 The linker's default configuration permits allocation of all available
6319 memory. You can override this by using the @code{MEMORY} command.
6321 The @code{MEMORY} command describes the location and size of blocks of
6322 memory in the target. You can use it to describe which memory regions
6323 may be used by the linker, and which memory regions it must avoid. You
6324 can then assign sections to particular memory regions. The linker will
6325 set section addresses based on the memory regions, and will warn about
6326 regions that become too full. The linker will not shuffle sections
6327 around to fit into the available regions.
6329 A linker script may contain many uses of the @code{MEMORY} command,
6330 however, all memory blocks defined are treated as if they were
6331 specified inside a single @code{MEMORY} command. The syntax for
6337 @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
6343 The @var{name} is a name used in the linker script to refer to the
6344 region. The region name has no meaning outside of the linker script.
6345 Region names are stored in a separate name space, and will not conflict
6346 with symbol names, file names, or section names. Each memory region
6347 must have a distinct name within the @code{MEMORY} command. However you can
6348 add later alias names to existing memory regions with the @ref{REGION_ALIAS}
6351 @cindex memory region attributes
6352 The @var{attr} string is an optional list of attributes that specify
6353 whether to use a particular memory region for an input section which is
6354 not explicitly mapped in the linker script. As described in
6355 @ref{SECTIONS}, if you do not specify an output section for some input
6356 section, the linker will create an output section with the same name as
6357 the input section. If you define region attributes, the linker will use
6358 them to select the memory region for the output section that it creates.
6360 The @var{attr} string must consist only of the following characters:
6375 Invert the sense of any of the attributes that follow
6378 If an unmapped section matches any of the listed attributes other than
6379 @samp{!}, it will be placed in the memory region. The @samp{!}
6380 attribute reverses the test for the characters that follow, so that an
6381 unmapped section will be placed in the memory region only if it does
6382 not match any of the attributes listed afterwards. Thus an attribute
6383 string of @samp{RW!X} will match any unmapped section that has either
6384 or both of the @samp{R} and @samp{W} attributes, but only as long as
6385 the section does not also have the @samp{X} attribute.
6390 The @var{origin} is an numerical expression for the start address of
6391 the memory region. The expression must evaluate to a constant and it
6392 cannot involve any symbols. The keyword @code{ORIGIN} may be
6393 abbreviated to @code{org} or @code{o} (but not, for example,
6399 The @var{len} is an expression for the size in bytes of the memory
6400 region. As with the @var{origin} expression, the expression must
6401 be numerical only and must evaluate to a constant. The keyword
6402 @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
6404 In the following example, we specify that there are two memory regions
6405 available for allocation: one starting at @samp{0} for 256 kilobytes,
6406 and the other starting at @samp{0x40000000} for four megabytes. The
6407 linker will place into the @samp{rom} memory region every section which
6408 is not explicitly mapped into a memory region, and is either read-only
6409 or executable. The linker will place other sections which are not
6410 explicitly mapped into a memory region into the @samp{ram} memory
6417 rom (rx) : ORIGIN = 0, LENGTH = 256K
6418 ram (!rx) : org = 0x40000000, l = 4M
6423 Once you define a memory region, you can direct the linker to place
6424 specific output sections into that memory region by using the
6425 @samp{>@var{region}} output section attribute. For example, if you have
6426 a memory region named @samp{mem}, you would use @samp{>mem} in the
6427 output section definition. @xref{Output Section Region}. If no address
6428 was specified for the output section, the linker will set the address to
6429 the next available address within the memory region. If the combined
6430 output sections directed to a memory region are too large for the
6431 region, the linker will issue an error message.
6433 It is possible to access the origin and length of a memory in an
6434 expression via the @code{ORIGIN(@var{memory})} and
6435 @code{LENGTH(@var{memory})} functions:
6439 _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
6444 @section PHDRS Command
6446 @cindex program headers
6447 @cindex ELF program headers
6448 @cindex program segments
6449 @cindex segments, ELF
6450 The ELF object file format uses @dfn{program headers}, also knows as
6451 @dfn{segments}. The program headers describe how the program should be
6452 loaded into memory. You can print them out by using the @code{objdump}
6453 program with the @samp{-p} option.
6455 When you run an ELF program on a native ELF system, the system loader
6456 reads the program headers in order to figure out how to load the
6457 program. This will only work if the program headers are set correctly.
6458 This manual does not describe the details of how the system loader
6459 interprets program headers; for more information, see the ELF ABI.
6461 The linker will create reasonable program headers by default. However,
6462 in some cases, you may need to specify the program headers more
6463 precisely. You may use the @code{PHDRS} command for this purpose. When
6464 the linker sees the @code{PHDRS} command in the linker script, it will
6465 not create any program headers other than the ones specified.
6467 The linker only pays attention to the @code{PHDRS} command when
6468 generating an ELF output file. In other cases, the linker will simply
6469 ignore @code{PHDRS}.
6471 This is the syntax of the @code{PHDRS} command. The words @code{PHDRS},
6472 @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
6478 @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
6479 [ FLAGS ( @var{flags} ) ] ;
6484 The @var{name} is used only for reference in the @code{SECTIONS} command
6485 of the linker script. It is not put into the output file. Program
6486 header names are stored in a separate name space, and will not conflict
6487 with symbol names, file names, or section names. Each program header
6488 must have a distinct name. The headers are processed in order and it
6489 is usual for them to map to sections in ascending load address order.
6491 Certain program header types describe segments of memory which the
6492 system loader will load from the file. In the linker script, you
6493 specify the contents of these segments by placing allocatable output
6494 sections in the segments. You use the @samp{:@var{phdr}} output section
6495 attribute to place a section in a particular segment. @xref{Output
6498 It is normal to put certain sections in more than one segment. This
6499 merely implies that one segment of memory contains another. You may
6500 repeat @samp{:@var{phdr}}, using it once for each segment which should
6501 contain the section.
6503 If you place a section in one or more segments using @samp{:@var{phdr}},
6504 then the linker will place all subsequent allocatable sections which do
6505 not specify @samp{:@var{phdr}} in the same segments. This is for
6506 convenience, since generally a whole set of contiguous sections will be
6507 placed in a single segment. You can use @code{:NONE} to override the
6508 default segment and tell the linker to not put the section in any
6513 You may use the @code{FILEHDR} and @code{PHDRS} keywords after
6514 the program header type to further describe the contents of the segment.
6515 The @code{FILEHDR} keyword means that the segment should include the ELF
6516 file header. The @code{PHDRS} keyword means that the segment should
6517 include the ELF program headers themselves. If applied to a loadable
6518 segment (@code{PT_LOAD}), all prior loadable segments must have one of
6521 The @var{type} may be one of the following. The numbers indicate the
6522 value of the keyword.
6525 @item @code{PT_NULL} (0)
6526 Indicates an unused program header.
6528 @item @code{PT_LOAD} (1)
6529 Indicates that this program header describes a segment to be loaded from
6532 @item @code{PT_DYNAMIC} (2)
6533 Indicates a segment where dynamic linking information can be found.
6535 @item @code{PT_INTERP} (3)
6536 Indicates a segment where the name of the program interpreter may be
6539 @item @code{PT_NOTE} (4)
6540 Indicates a segment holding note information.
6542 @item @code{PT_SHLIB} (5)
6543 A reserved program header type, defined but not specified by the ELF
6546 @item @code{PT_PHDR} (6)
6547 Indicates a segment where the program headers may be found.
6549 @item @code{PT_TLS} (7)
6550 Indicates a segment containing thread local storage.
6552 @item @var{expression}
6553 An expression giving the numeric type of the program header. This may
6554 be used for types not defined above.
6557 You can specify that a segment should be loaded at a particular address
6558 in memory by using an @code{AT} expression. This is identical to the
6559 @code{AT} command used as an output section attribute (@pxref{Output
6560 Section LMA}). The @code{AT} command for a program header overrides the
6561 output section attribute.
6563 The linker will normally set the segment flags based on the sections
6564 which comprise the segment. You may use the @code{FLAGS} keyword to
6565 explicitly specify the segment flags. The value of @var{flags} must be
6566 an integer. It is used to set the @code{p_flags} field of the program
6569 Here is an example of @code{PHDRS}. This shows a typical set of program
6570 headers used on a native ELF system.
6576 headers PT_PHDR PHDRS ;
6578 text PT_LOAD FILEHDR PHDRS ;
6580 dynamic PT_DYNAMIC ;
6586 .interp : @{ *(.interp) @} :text :interp
6587 .text : @{ *(.text) @} :text
6588 .rodata : @{ *(.rodata) @} /* defaults to :text */
6590 . = . + 0x1000; /* move to a new page in memory */
6591 .data : @{ *(.data) @} :data
6592 .dynamic : @{ *(.dynamic) @} :data :dynamic
6599 @section VERSION Command
6600 @kindex VERSION @{script text@}
6601 @cindex symbol versions
6602 @cindex version script
6603 @cindex versions of symbols
6604 The linker supports symbol versions when using ELF. Symbol versions are
6605 only useful when using shared libraries. The dynamic linker can use
6606 symbol versions to select a specific version of a function when it runs
6607 a program that may have been linked against an earlier version of the
6610 You can include a version script directly in the main linker script, or
6611 you can supply the version script as an implicit linker script. You can
6612 also use the @samp{--version-script} linker option.
6614 The syntax of the @code{VERSION} command is simply
6616 VERSION @{ version-script-commands @}
6619 The format of the version script commands is identical to that used by
6620 Sun's linker in Solaris 2.5. The version script defines a tree of
6621 version nodes. You specify the node names and interdependencies in the
6622 version script. You can specify which symbols are bound to which
6623 version nodes, and you can reduce a specified set of symbols to local
6624 scope so that they are not globally visible outside of the shared
6627 The easiest way to demonstrate the version script language is with a few
6653 This example version script defines three version nodes. The first
6654 version node defined is @samp{VERS_1.1}; it has no other dependencies.
6655 The script binds the symbol @samp{foo1} to @samp{VERS_1.1}. It reduces
6656 a number of symbols to local scope so that they are not visible outside
6657 of the shared library; this is done using wildcard patterns, so that any
6658 symbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
6659 is matched. The wildcard patterns available are the same as those used
6660 in the shell when matching filenames (also known as ``globbing'').
6661 However, if you specify the symbol name inside double quotes, then the
6662 name is treated as literal, rather than as a glob pattern.
6664 Next, the version script defines node @samp{VERS_1.2}. This node
6665 depends upon @samp{VERS_1.1}. The script binds the symbol @samp{foo2}
6666 to the version node @samp{VERS_1.2}.
6668 Finally, the version script defines node @samp{VERS_2.0}. This node
6669 depends upon @samp{VERS_1.2}. The scripts binds the symbols @samp{bar1}
6670 and @samp{bar2} are bound to the version node @samp{VERS_2.0}.
6672 When the linker finds a symbol defined in a library which is not
6673 specifically bound to a version node, it will effectively bind it to an
6674 unspecified base version of the library. You can bind all otherwise
6675 unspecified symbols to a given version node by using @samp{global: *;}
6676 somewhere in the version script. Note that it's slightly crazy to use
6677 wildcards in a global spec except on the last version node. Global
6678 wildcards elsewhere run the risk of accidentally adding symbols to the
6679 set exported for an old version. That's wrong since older versions
6680 ought to have a fixed set of symbols.
6682 The names of the version nodes have no specific meaning other than what
6683 they might suggest to the person reading them. The @samp{2.0} version
6684 could just as well have appeared in between @samp{1.1} and @samp{1.2}.
6685 However, this would be a confusing way to write a version script.
6687 Node name can be omitted, provided it is the only version node
6688 in the version script. Such version script doesn't assign any versions to
6689 symbols, only selects which symbols will be globally visible out and which
6693 @{ global: foo; bar; local: *; @};
6696 When you link an application against a shared library that has versioned
6697 symbols, the application itself knows which version of each symbol it
6698 requires, and it also knows which version nodes it needs from each
6699 shared library it is linked against. Thus at runtime, the dynamic
6700 loader can make a quick check to make sure that the libraries you have
6701 linked against do in fact supply all of the version nodes that the
6702 application will need to resolve all of the dynamic symbols. In this
6703 way it is possible for the dynamic linker to know with certainty that
6704 all external symbols that it needs will be resolvable without having to
6705 search for each symbol reference.
6707 The symbol versioning is in effect a much more sophisticated way of
6708 doing minor version checking that SunOS does. The fundamental problem
6709 that is being addressed here is that typically references to external
6710 functions are bound on an as-needed basis, and are not all bound when
6711 the application starts up. If a shared library is out of date, a
6712 required interface may be missing; when the application tries to use
6713 that interface, it may suddenly and unexpectedly fail. With symbol
6714 versioning, the user will get a warning when they start their program if
6715 the libraries being used with the application are too old.
6717 There are several GNU extensions to Sun's versioning approach. The
6718 first of these is the ability to bind a symbol to a version node in the
6719 source file where the symbol is defined instead of in the versioning
6720 script. This was done mainly to reduce the burden on the library
6721 maintainer. You can do this by putting something like:
6723 __asm__(".symver original_foo,foo@@VERS_1.1");
6726 in the C source file. This renames the function @samp{original_foo} to
6727 be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
6728 The @samp{local:} directive can be used to prevent the symbol
6729 @samp{original_foo} from being exported. A @samp{.symver} directive
6730 takes precedence over a version script.
6732 The second GNU extension is to allow multiple versions of the same
6733 function to appear in a given shared library. In this way you can make
6734 an incompatible change to an interface without increasing the major
6735 version number of the shared library, while still allowing applications
6736 linked against the old interface to continue to function.
6738 To do this, you must use multiple @samp{.symver} directives in the
6739 source file. Here is an example:
6742 __asm__(".symver original_foo,foo@@");
6743 __asm__(".symver old_foo,foo@@VERS_1.1");
6744 __asm__(".symver old_foo1,foo@@VERS_1.2");
6745 __asm__(".symver new_foo,foo@@@@VERS_2.0");
6748 In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
6749 unspecified base version of the symbol. The source file that contains this
6750 example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
6751 @samp{old_foo1}, and @samp{new_foo}.
6753 When you have multiple definitions of a given symbol, there needs to be
6754 some way to specify a default version to which external references to
6755 this symbol will be bound. You can do this with the
6756 @samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. You can only
6757 declare one version of a symbol as the default in this manner; otherwise
6758 you would effectively have multiple definitions of the same symbol.
6760 If you wish to bind a reference to a specific version of the symbol
6761 within the shared library, you can use the aliases of convenience
6762 (i.e., @samp{old_foo}), or you can use the @samp{.symver} directive to
6763 specifically bind to an external version of the function in question.
6765 You can also specify the language in the version script:
6768 VERSION extern "lang" @{ version-script-commands @}
6771 The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
6772 The linker will iterate over the list of symbols at the link time and
6773 demangle them according to @samp{lang} before matching them to the
6774 patterns specified in @samp{version-script-commands}. The default
6775 @samp{lang} is @samp{C}.
6777 Demangled names may contains spaces and other special characters. As
6778 described above, you can use a glob pattern to match demangled names,
6779 or you can use a double-quoted string to match the string exactly. In
6780 the latter case, be aware that minor differences (such as differing
6781 whitespace) between the version script and the demangler output will
6782 cause a mismatch. As the exact string generated by the demangler
6783 might change in the future, even if the mangled name does not, you
6784 should check that all of your version directives are behaving as you
6785 expect when you upgrade.
6788 @section Expressions in Linker Scripts
6791 The syntax for expressions in the linker script language is identical to
6792 that of C expressions, except that whitespace is required in some
6793 places to resolve syntactic ambiguities. All expressions are
6794 evaluated as integers. All expressions are evaluated in the same
6795 size, which is 32 bits if both the host and target are 32 bits, and is
6798 You can use and set symbol values in expressions.
6800 The linker defines several special purpose builtin functions for use in
6804 * Constants:: Constants
6805 * Symbolic Constants:: Symbolic constants
6806 * Symbols:: Symbol Names
6807 * Orphan Sections:: Orphan Sections
6808 * Location Counter:: The Location Counter
6809 * Operators:: Operators
6810 * Evaluation:: Evaluation
6811 * Expression Section:: The Section of an Expression
6812 * Builtin Functions:: Builtin Functions
6816 @subsection Constants
6817 @cindex integer notation
6818 @cindex constants in linker scripts
6819 All constants are integers.
6821 As in C, the linker considers an integer beginning with @samp{0} to be
6822 octal, and an integer beginning with @samp{0x} or @samp{0X} to be
6823 hexadecimal. Alternatively the linker accepts suffixes of @samp{h} or
6824 @samp{H} for hexadecimal, @samp{o} or @samp{O} for octal, @samp{b} or
6825 @samp{B} for binary and @samp{d} or @samp{D} for decimal. Any integer
6826 value without a prefix or a suffix is considered to be decimal.
6828 @cindex scaled integers
6829 @cindex K and M integer suffixes
6830 @cindex M and K integer suffixes
6831 @cindex suffixes for integers
6832 @cindex integer suffixes
6833 In addition, you can use the suffixes @code{K} and @code{M} to scale a
6837 @c END TEXI2ROFF-KILL
6838 @code{1024} or @code{1024*1024}
6842 ${\rm 1024}$ or ${\rm 1024}^2$
6844 @c END TEXI2ROFF-KILL
6845 respectively. For example, the following
6846 all refer to the same quantity:
6855 Note - the @code{K} and @code{M} suffixes cannot be used in
6856 conjunction with the base suffixes mentioned above.
6858 @node Symbolic Constants
6859 @subsection Symbolic Constants
6860 @cindex symbolic constants
6862 It is possible to refer to target-specific constants via the use of
6863 the @code{CONSTANT(@var{name})} operator, where @var{name} is one of:
6868 The target's maximum page size.
6870 @item COMMONPAGESIZE
6871 @kindex COMMONPAGESIZE
6872 The target's default page size.
6878 .text ALIGN (CONSTANT (MAXPAGESIZE)) : @{ *(.text) @}
6881 will create a text section aligned to the largest page boundary
6882 supported by the target.
6885 @subsection Symbol Names
6886 @cindex symbol names
6888 @cindex quoted symbol names
6890 Unless quoted, symbol names start with a letter, underscore, or period
6891 and may include letters, digits, underscores, periods, and hyphens.
6892 Unquoted symbol names must not conflict with any keywords. You can
6893 specify a symbol which contains odd characters or has the same name as a
6894 keyword by surrounding the symbol name in double quotes:
6897 "with a space" = "also with a space" + 10;
6900 Since symbols can contain many non-alphabetic characters, it is safest
6901 to delimit symbols with spaces. For example, @samp{A-B} is one symbol,
6902 whereas @samp{A - B} is an expression involving subtraction.
6904 @node Orphan Sections
6905 @subsection Orphan Sections
6907 Orphan sections are sections present in the input files which
6908 are not explicitly placed into the output file by the linker
6909 script. The linker will still copy these sections into the
6910 output file by either finding, or creating a suitable output section
6911 in which to place the orphaned input section.
6913 If the name of an orphaned input section exactly matches the name of
6914 an existing output section, then the orphaned input section will be
6915 placed at the end of that output section.
6917 If there is no output section with a matching name then new output
6918 sections will be created. Each new output section will have the same
6919 name as the orphan section placed within it. If there are multiple
6920 orphan sections with the same name, these will all be combined into
6921 one new output section.
6923 If new output sections are created to hold orphaned input sections,
6924 then the linker must decide where to place these new output sections
6925 in relation to existing output sections. On most modern targets, the
6926 linker attempts to place orphan sections after sections of the same
6927 attribute, such as code vs data, loadable vs non-loadable, etc. If no
6928 sections with matching attributes are found, or your target lacks this
6929 support, the orphan section is placed at the end of the file.
6931 The command-line options @samp{--orphan-handling} and @samp{--unique}
6932 (@pxref{Options,,Command-line Options}) can be used to control which
6933 output sections an orphan is placed in.
6935 @node Location Counter
6936 @subsection The Location Counter
6939 @cindex location counter
6940 @cindex current output location
6941 The special linker variable @dfn{dot} @samp{.} always contains the
6942 current output location counter. Since the @code{.} always refers to a
6943 location in an output section, it may only appear in an expression
6944 within a @code{SECTIONS} command. The @code{.} symbol may appear
6945 anywhere that an ordinary symbol is allowed in an expression.
6948 Assigning a value to @code{.} will cause the location counter to be
6949 moved. This may be used to create holes in the output section. The
6950 location counter may not be moved backwards inside an output section,
6951 and may not be moved backwards outside of an output section if so
6952 doing creates areas with overlapping LMAs.
6968 In the previous example, the @samp{.text} section from @file{file1} is
6969 located at the beginning of the output section @samp{output}. It is
6970 followed by a 1000 byte gap. Then the @samp{.text} section from
6971 @file{file2} appears, also with a 1000 byte gap following before the
6972 @samp{.text} section from @file{file3}. The notation @samp{= 0x12345678}
6973 specifies what data to write in the gaps (@pxref{Output Section Fill}).
6975 @cindex dot inside sections
6976 Note: @code{.} actually refers to the byte offset from the start of the
6977 current containing object. Normally this is the @code{SECTIONS}
6978 statement, whose start address is 0, hence @code{.} can be used as an
6979 absolute address. If @code{.} is used inside a section description
6980 however, it refers to the byte offset from the start of that section,
6981 not an absolute address. Thus in a script like this:
6999 The @samp{.text} section will be assigned a starting address of 0x100
7000 and a size of exactly 0x200 bytes, even if there is not enough data in
7001 the @samp{.text} input sections to fill this area. (If there is too
7002 much data, an error will be produced because this would be an attempt to
7003 move @code{.} backwards). The @samp{.data} section will start at 0x500
7004 and it will have an extra 0x600 bytes worth of space after the end of
7005 the values from the @samp{.data} input sections and before the end of
7006 the @samp{.data} output section itself.
7008 @cindex dot outside sections
7009 Setting symbols to the value of the location counter outside of an
7010 output section statement can result in unexpected values if the linker
7011 needs to place orphan sections. For example, given the following:
7017 .text: @{ *(.text) @}
7021 .data: @{ *(.data) @}
7026 If the linker needs to place some input section, e.g. @code{.rodata},
7027 not mentioned in the script, it might choose to place that section
7028 between @code{.text} and @code{.data}. You might think the linker
7029 should place @code{.rodata} on the blank line in the above script, but
7030 blank lines are of no particular significance to the linker. As well,
7031 the linker doesn't associate the above symbol names with their
7032 sections. Instead, it assumes that all assignments or other
7033 statements belong to the previous output section, except for the
7034 special case of an assignment to @code{.}. I.e., the linker will
7035 place the orphan @code{.rodata} section as if the script was written
7042 .text: @{ *(.text) @}
7046 .rodata: @{ *(.rodata) @}
7047 .data: @{ *(.data) @}
7052 This may or may not be the script author's intention for the value of
7053 @code{start_of_data}. One way to influence the orphan section
7054 placement is to assign the location counter to itself, as the linker
7055 assumes that an assignment to @code{.} is setting the start address of
7056 a following output section and thus should be grouped with that
7057 section. So you could write:
7063 .text: @{ *(.text) @}
7068 .data: @{ *(.data) @}
7073 Now, the orphan @code{.rodata} section will be placed between
7074 @code{end_of_text} and @code{start_of_data}.
7078 @subsection Operators
7079 @cindex operators for arithmetic
7080 @cindex arithmetic operators
7081 @cindex precedence in expressions
7082 The linker recognizes the standard C set of arithmetic operators, with
7083 the standard bindings and precedence levels:
7086 @c END TEXI2ROFF-KILL
7088 precedence associativity Operators Notes
7102 13 right += -= *= /= <<= >>= &= |= ^= (2)
7106 (1) Prefix operators
7107 (2) @xref{Assignments}.
7111 \vskip \baselineskip
7112 %"lispnarrowing" is the extra indent used generally for smallexample
7113 \hskip\lispnarrowing\vbox{\offinterlineskip
7116 {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
7117 height2pt&\omit&&\omit&&\omit&\cr
7118 &Precedence&& Associativity &&{\rm Operators}&\cr
7119 height2pt&\omit&&\omit&&\omit&\cr
7121 height2pt&\omit&&\omit&&\omit&\cr
7123 % '176 is tilde, '~' in tt font
7124 &1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
7125 &2&&left&&* / \%&\cr
7128 &5&&left&& > < <= >=&\cr
7133 &10&&left&&{\&\&}&\cr
7136 &13&&right&&\qquad += -= *= /= <<= >>= \&= |= \^{}=\qquad\ddag&\cr
7138 height2pt&\omit&&\omit&&\omit&\cr}
7143 @obeylines@parskip=0pt@parindent=0pt
7144 @dag@quad Prefix operators.
7145 @ddag@quad @xref{Assignments}.
7148 @c END TEXI2ROFF-KILL
7151 @subsection Evaluation
7152 @cindex lazy evaluation
7153 @cindex expression evaluation order
7154 The linker evaluates expressions lazily. It only computes the value of
7155 an expression when absolutely necessary.
7157 The linker needs some information, such as the value of the start
7158 address of the first section, and the origins and lengths of memory
7159 regions, in order to do any linking at all. These values are computed
7160 as soon as possible when the linker reads in the linker script.
7162 However, other values (such as symbol values) are not known or needed
7163 until after storage allocation. Such values are evaluated later, when
7164 other information (such as the sizes of output sections) is available
7165 for use in the symbol assignment expression.
7167 The sizes of sections cannot be known until after allocation, so
7168 assignments dependent upon these are not performed until after
7171 Some expressions, such as those depending upon the location counter
7172 @samp{.}, must be evaluated during section allocation.
7174 If the result of an expression is required, but the value is not
7175 available, then an error results. For example, a script like the
7181 .text 9+this_isnt_constant :
7187 will cause the error message @samp{non constant expression for initial
7190 @node Expression Section
7191 @subsection The Section of an Expression
7192 @cindex expression sections
7193 @cindex absolute expressions
7194 @cindex relative expressions
7195 @cindex absolute and relocatable symbols
7196 @cindex relocatable and absolute symbols
7197 @cindex symbols, relocatable and absolute
7198 Addresses and symbols may be section relative, or absolute. A section
7199 relative symbol is relocatable. If you request relocatable output
7200 using the @samp{-r} option, a further link operation may change the
7201 value of a section relative symbol. On the other hand, an absolute
7202 symbol will retain the same value throughout any further link
7205 Some terms in linker expressions are addresses. This is true of
7206 section relative symbols and for builtin functions that return an
7207 address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
7208 @code{SEGMENT_START}. Other terms are simply numbers, or are builtin
7209 functions that return a non-address value, such as @code{LENGTH}.
7210 One complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
7211 (@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
7212 differently depending on their location, for compatibility with older
7213 versions of @code{ld}. Expressions appearing outside an output
7214 section definition treat all numbers as absolute addresses.
7215 Expressions appearing inside an output section definition treat
7216 absolute symbols as numbers. If @code{LD_FEATURE ("SANE_EXPR")} is
7217 given, then absolute symbols and numbers are simply treated as numbers
7220 In the following simple example,
7227 __executable_start = 0x100;
7231 __data_start = 0x10;
7239 both @code{.} and @code{__executable_start} are set to the absolute
7240 address 0x100 in the first two assignments, then both @code{.} and
7241 @code{__data_start} are set to 0x10 relative to the @code{.data}
7242 section in the second two assignments.
7244 For expressions involving numbers, relative addresses and absolute
7245 addresses, ld follows these rules to evaluate terms:
7249 Unary operations on an absolute address or number, and binary
7250 operations on two absolute addresses or two numbers, or between one
7251 absolute address and a number, apply the operator to the value(s).
7253 Unary operations on a relative address, and binary operations on two
7254 relative addresses in the same section or between one relative address
7255 and a number, apply the operator to the offset part of the address(es).
7257 Other binary operations, that is, between two relative addresses not
7258 in the same section, or between a relative address and an absolute
7259 address, first convert any non-absolute term to an absolute address
7260 before applying the operator.
7263 The result section of each sub-expression is as follows:
7267 An operation involving only numbers results in a number.
7269 The result of comparisons, @samp{&&} and @samp{||} is also a number.
7271 The result of other binary arithmetic and logical operations on two
7272 relative addresses in the same section or two absolute addresses
7273 (after above conversions) is also a number when
7274 @code{LD_FEATURE ("SANE_EXPR")} or inside an output section definition
7275 but an absolute address otherwise.
7277 The result of other operations on relative addresses or one
7278 relative address and a number, is a relative address in the same
7279 section as the relative operand(s).
7281 The result of other operations on absolute addresses (after above
7282 conversions) is an absolute address.
7285 You can use the builtin function @code{ABSOLUTE} to force an expression
7286 to be absolute when it would otherwise be relative. For example, to
7287 create an absolute symbol set to the address of the end of the output
7288 section @samp{.data}:
7292 .data : @{ *(.data) _edata = ABSOLUTE(.); @}
7296 If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
7297 @samp{.data} section.
7299 Using @code{LOADADDR} also forces an expression absolute, since this
7300 particular builtin function returns an absolute address.
7302 @node Builtin Functions
7303 @subsection Builtin Functions
7304 @cindex functions in expressions
7305 The linker script language includes a number of builtin functions for
7306 use in linker script expressions.
7309 @item ABSOLUTE(@var{exp})
7310 @kindex ABSOLUTE(@var{exp})
7311 @cindex expression, absolute
7312 Return the absolute (non-relocatable, as opposed to non-negative) value
7313 of the expression @var{exp}. Primarily useful to assign an absolute
7314 value to a symbol within a section definition, where symbol values are
7315 normally section relative. @xref{Expression Section}.
7317 @item ADDR(@var{section})
7318 @kindex ADDR(@var{section})
7319 @cindex section address in expression
7320 Return the address (VMA) of the named @var{section}. Your
7321 script must previously have defined the location of that section. In
7322 the following example, @code{start_of_output_1}, @code{symbol_1} and
7323 @code{symbol_2} are assigned equivalent values, except that
7324 @code{symbol_1} will be relative to the @code{.output1} section while
7325 the other two will be absolute:
7331 start_of_output_1 = ABSOLUTE(.);
7336 symbol_1 = ADDR(.output1);
7337 symbol_2 = start_of_output_1;
7343 @item ALIGN(@var{align})
7344 @itemx ALIGN(@var{exp},@var{align})
7345 @kindex ALIGN(@var{align})
7346 @kindex ALIGN(@var{exp},@var{align})
7347 @cindex round up location counter
7348 @cindex align location counter
7349 @cindex round up expression
7350 @cindex align expression
7351 Return the location counter (@code{.}) or arbitrary expression aligned
7352 to the next @var{align} boundary. The single operand @code{ALIGN}
7353 doesn't change the value of the location counter---it just does
7354 arithmetic on it. The two operand @code{ALIGN} allows an arbitrary
7355 expression to be aligned upwards (@code{ALIGN(@var{align})} is
7356 equivalent to @code{ALIGN(ABSOLUTE(.), @var{align})}).
7358 Here is an example which aligns the output @code{.data} section to the
7359 next @code{0x2000} byte boundary after the preceding section and sets a
7360 variable within the section to the next @code{0x8000} boundary after the
7365 .data ALIGN(0x2000): @{
7367 variable = ALIGN(0x8000);
7373 The first use of @code{ALIGN} in this example specifies the location of
7374 a section because it is used as the optional @var{address} attribute of
7375 a section definition (@pxref{Output Section Address}). The second use
7376 of @code{ALIGN} is used to defines the value of a symbol.
7378 The builtin function @code{NEXT} is closely related to @code{ALIGN}.
7380 @item ALIGNOF(@var{section})
7381 @kindex ALIGNOF(@var{section})
7382 @cindex section alignment
7383 Return the alignment in bytes of the named @var{section}, if that section has
7384 been allocated, or zero if the section has not been allocated. If the
7385 section does not exist in the linker script the linker will report an
7386 error. If @var{section} is @code{NEXT_SECTION} then @code{ALIGNOF} will
7387 return the alignment of the next allocated section specified in the
7388 linker script, or zero if there is no such section. In the following
7389 example, the alignment of the @code{.output} section is stored as the
7390 first value in that section.
7395 LONG (ALIGNOF (.output))
7402 @item BLOCK(@var{exp})
7403 @kindex BLOCK(@var{exp})
7404 This is a synonym for @code{ALIGN}, for compatibility with older linker
7405 scripts. It is most often seen when setting the address of an output
7408 @item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7409 @kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7410 This is equivalent to either
7412 (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
7416 (ALIGN(@var{maxpagesize})
7417 + ((. + @var{commonpagesize} - 1) & (@var{maxpagesize} - @var{commonpagesize})))
7420 depending on whether the latter uses fewer @var{commonpagesize} sized pages
7421 for the data segment (area between the result of this expression and
7422 @code{DATA_SEGMENT_END}) than the former or not.
7423 If the latter form is used, it means @var{commonpagesize} bytes of runtime
7424 memory will be saved at the expense of up to @var{commonpagesize} wasted
7425 bytes in the on-disk file.
7427 This expression can only be used directly in @code{SECTIONS} commands, not in
7428 any output section descriptions and only once in the linker script.
7429 @var{commonpagesize} should be less or equal to @var{maxpagesize} and should
7430 be the system page size the object wants to be optimized for while still
7431 running on system page sizes up to @var{maxpagesize}. Note however
7432 that @samp{-z relro} protection will not be effective if the system
7433 page size is larger than @var{commonpagesize}.
7438 . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
7441 @item DATA_SEGMENT_END(@var{exp})
7442 @kindex DATA_SEGMENT_END(@var{exp})
7443 This defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
7444 evaluation purposes.
7447 . = DATA_SEGMENT_END(.);
7450 @item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7451 @kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7452 This defines the end of the @code{PT_GNU_RELRO} segment when
7453 @samp{-z relro} option is used.
7454 When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
7455 does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
7456 @var{exp} + @var{offset} is aligned to the @var{commonpagesize}
7457 argument given to @code{DATA_SEGMENT_ALIGN}. If present in the linker
7458 script, it must be placed between @code{DATA_SEGMENT_ALIGN} and
7459 @code{DATA_SEGMENT_END}. Evaluates to the second argument plus any
7460 padding needed at the end of the @code{PT_GNU_RELRO} segment due to
7464 . = DATA_SEGMENT_RELRO_END(24, .);
7467 @item DEFINED(@var{symbol})
7468 @kindex DEFINED(@var{symbol})
7469 @cindex symbol defaults
7470 Return 1 if @var{symbol} is in the linker global symbol table and is
7471 defined before the statement using DEFINED in the script, otherwise
7472 return 0. You can use this function to provide
7473 default values for symbols. For example, the following script fragment
7474 shows how to set a global symbol @samp{begin} to the first location in
7475 the @samp{.text} section---but if a symbol called @samp{begin} already
7476 existed, its value is preserved:
7482 begin = DEFINED(begin) ? begin : . ;
7490 @item LENGTH(@var{memory})
7491 @kindex LENGTH(@var{memory})
7492 Return the length of the memory region named @var{memory}.
7494 @item LOADADDR(@var{section})
7495 @kindex LOADADDR(@var{section})
7496 @cindex section load address in expression
7497 Return the absolute LMA of the named @var{section}. (@pxref{Output
7500 @item LOG2CEIL(@var{exp})
7501 @kindex LOG2CEIL(@var{exp})
7502 Return the binary logarithm of @var{exp} rounded towards infinity.
7503 @code{LOG2CEIL(0)} returns 0.
7506 @item MAX(@var{exp1}, @var{exp2})
7507 Returns the maximum of @var{exp1} and @var{exp2}.
7510 @item MIN(@var{exp1}, @var{exp2})
7511 Returns the minimum of @var{exp1} and @var{exp2}.
7513 @item NEXT(@var{exp})
7514 @kindex NEXT(@var{exp})
7515 @cindex unallocated address, next
7516 Return the next unallocated address that is a multiple of @var{exp}.
7517 This function is closely related to @code{ALIGN(@var{exp})}; unless you
7518 use the @code{MEMORY} command to define discontinuous memory for the
7519 output file, the two functions are equivalent.
7521 @item ORIGIN(@var{memory})
7522 @kindex ORIGIN(@var{memory})
7523 Return the origin of the memory region named @var{memory}.
7525 @item SEGMENT_START(@var{segment}, @var{default})
7526 @kindex SEGMENT_START(@var{segment}, @var{default})
7527 Return the base address of the named @var{segment}. If an explicit
7528 value has already been given for this segment (with a command-line
7529 @samp{-T} option) then that value will be returned otherwise the value
7530 will be @var{default}. At present, the @samp{-T} command-line option
7531 can only be used to set the base address for the ``text'', ``data'', and
7532 ``bss'' sections, but you can use @code{SEGMENT_START} with any segment
7535 @item SIZEOF(@var{section})
7536 @kindex SIZEOF(@var{section})
7537 @cindex section size
7538 Return the size in bytes of the named @var{section}, if that section has
7539 been allocated, or zero if the section has not been allocated. If the
7540 section does not exist in the linker script the linker will report an
7541 error. If @var{section} is @code{NEXT_SECTION} then @code{SIZEOF} will
7542 return the alignment of the next allocated section specified in the
7543 linker script, or zero if there is no such section. In the following
7544 example, @code{symbol_1} and @code{symbol_2} are assigned identical
7554 symbol_1 = .end - .start ;
7555 symbol_2 = SIZEOF(.output);
7560 @item SIZEOF_HEADERS
7561 @kindex SIZEOF_HEADERS
7563 Return the size in bytes of the output file's headers. This is
7564 information which appears at the start of the output file. You can use
7565 this number when setting the start address of the first section, if you
7566 choose, to facilitate paging.
7568 @cindex not enough room for program headers
7569 @cindex program headers, not enough room
7570 When producing an ELF output file, if the linker script uses the
7571 @code{SIZEOF_HEADERS} builtin function, the linker must compute the
7572 number of program headers before it has determined all the section
7573 addresses and sizes. If the linker later discovers that it needs
7574 additional program headers, it will report an error @samp{not enough
7575 room for program headers}. To avoid this error, you must avoid using
7576 the @code{SIZEOF_HEADERS} function, or you must rework your linker
7577 script to avoid forcing the linker to use additional program headers, or
7578 you must define the program headers yourself using the @code{PHDRS}
7579 command (@pxref{PHDRS}).
7582 @node Implicit Linker Scripts
7583 @section Implicit Linker Scripts
7584 @cindex implicit linker scripts
7585 If you specify a linker input file which the linker can not recognize as
7586 an object file or an archive file, it will try to read the file as a
7587 linker script. If the file can not be parsed as a linker script, the
7588 linker will report an error.
7590 An implicit linker script will not replace the default linker script.
7592 Typically an implicit linker script would contain only symbol
7593 assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
7596 Any input files read because of an implicit linker script will be read
7597 at the position in the command line where the implicit linker script was
7598 read. This can affect archive searching.
7601 @chapter Linker Plugins
7604 @cindex linker plugins
7605 The linker can use dynamically loaded plugins to modify its behavior.
7606 For example, the link-time optimization feature that some compilers
7607 support is implemented with a linker plugin.
7609 Currently there is only one plugin shipped by default, but more may
7610 be added here later.
7612 Plugins are enabled via the use of the @option{-plugin @var{name}}
7613 command line option. @xref{Options}.
7616 * libdep Plugin:: Static Library Dependencies Plugin
7617 * lto Plugin:: LTO Plugin
7621 @section Static Library Dependencies Plugin
7622 @cindex static library dependencies
7623 Originally, static libraries were contained in an archive file consisting
7624 just of a collection of relocatable object files. Later they evolved to
7625 optionally include a symbol table, to assist in finding the needed objects
7626 within a library. There their evolution ended, and dynamic libraries
7629 One useful feature of dynamic libraries was that, more than just collecting
7630 multiple objects into a single file, they also included a list of their
7631 dependencies, such that one could specify just the name of a single dynamic
7632 library at link time, and all of its dependencies would be implicitly
7633 referenced as well. But static libraries lacked this feature, so if a
7634 link invocation was switched from using dynamic libraries to static
7635 libraries, the link command would usually fail unless it was rewritten to
7636 explicitly list the dependencies of the static library.
7638 The GNU @command{ar} utility now supports a @option{--record-libdeps} option
7639 to embed dependency lists into static libraries as well, and the @file{libdep}
7640 plugin may be used to read this dependency information at link time. The
7641 dependency information is stored as a single string, carrying @option{-l}
7642 and @option{-L} arguments as they would normally appear in a linker
7643 command line. As such, the information can be written with any text
7644 utility and stored into any archive, even if GNU @command{ar} is not
7645 being used to create the archive. The information is stored in an
7646 archive member named @samp{__.LIBDEP}.
7648 For example, given a library @file{libssl.a} that depends on another
7649 library @file{libcrypto.a} which may be found in @file{/usr/local/lib},
7650 the @samp{__.LIBDEP} member of @file{libssl.a} would contain
7653 -L/usr/local/lib -lcrypto
7656 Note any library search directories added in this way are only used to
7657 search for libraries which are also added the same plugin. They are
7658 not used for searching for libraries specified on the linker command
7659 line, linker scripts or other plugins. This does however present a
7660 problem if multiple archives with @samp{__.LIBDEP} entries are present
7661 as they will all be handled by the libdep plugin and thus they will
7662 share library search paths. This could result in a library being
7663 loaded from an unexpected location.
7667 Although not shipped with the binutils the LTO Plugin from the GCC
7668 project is nevertheless a plugin that is designed to work with the
7669 linker. The plugin intercepts object files as they are loaded by the
7670 linker and instead sends them to the LTO compiler. When that compiler
7671 finishes the resulting object file(s) are passed back to the linker
7672 for normal processing.
7674 @node Special Sections
7675 @chapter Special Sections
7676 When linking ELF format object files @command{ld} treats some sections
7677 in a special, non standard manner. This part of the manual describes
7682 The contents of any section with this name are assumed to be an ascii
7683 format warning message. The contents will be displayed to the user if
7684 the sections appears in any input file, but the section will not be
7685 copied into the output image. If the @option{--fatal-warnings} option
7686 is enabled then the warnings - if any are encountered - will also stop
7687 the link from completing.
7689 Note - the @samp{.gnu.warning} section is not subject to linker
7690 garbage collection or orphan handling.
7692 @item .gnu.warning.@var{SYM}
7693 The contents of any section whoes name starts with the prefix
7694 @samp{.gnu.warning.} and then finishes with the name of a symbol is
7695 treated in a similar fashion to the @samp{.gnu.warning} section, but
7696 only if the named symbol is referenced. So for example the contents
7697 of a section called @samp{.gnu.warning.foo} will be displayed as
7698 warning message if, and only if, the symbol @samp{foo} is referenced
7699 by one or more of the input files. This includes object files pulled
7700 in from static libraries, shared objects needed to complete the link
7703 Note - because these warning messages are generated before the linker
7704 performs garbage collection (if enabled) it is possible for a warning
7705 to be displayed for a symbol that is later removed and then never
7706 appears in the final output.
7708 @item .note.gnu.property
7709 When the linker combines sections of this name it will merge them
7710 together according to various rules encoded into the notes
7711 themselves. Therefore the contents of the output .note.gnu.property
7712 section may not correspond to a simple concatenation of the input
7713 sections. If the @option{-Map} option has been used to request a
7714 linker map then details of any property merging will be included in
7720 @node Machine Dependent
7721 @chapter Machine Dependent Features
7723 @cindex machine dependencies
7724 @command{ld} has additional features on some platforms; the following
7725 sections describe them. Machines where @command{ld} has no additional
7726 functionality are not listed.
7730 * H8/300:: @command{ld} and the H8/300
7733 * M68HC11/68HC12:: @code{ld} and the Motorola 68HC11 and 68HC12 families
7736 * ARM:: @command{ld} and the ARM family
7739 * HPPA ELF32:: @command{ld} and HPPA 32-bit ELF
7742 * M68K:: @command{ld} and the Motorola 68K family
7745 * MIPS:: @command{ld} and the MIPS family
7748 * MMIX:: @command{ld} and MMIX
7751 * MSP430:: @command{ld} and MSP430
7754 * NDS32:: @command{ld} and NDS32
7757 * Nios II:: @command{ld} and the Altera Nios II
7760 * PowerPC ELF32:: @command{ld} and PowerPC 32-bit ELF Support
7763 * PowerPC64 ELF64:: @command{ld} and PowerPC64 64-bit ELF Support
7766 * S/390 ELF:: @command{ld} and S/390 ELF Support
7769 * SPU ELF:: @command{ld} and SPU ELF Support
7772 * TI COFF:: @command{ld} and TI COFF
7775 * WIN32:: @command{ld} and WIN32 (cygwin/mingw)
7778 * Xtensa:: @command{ld} and Xtensa Processors
7789 @section @command{ld} and the H8/300
7791 @cindex H8/300 support
7792 For the H8/300, @command{ld} can perform these global optimizations when
7793 you specify the @samp{--relax} command-line option.
7796 @cindex relaxing on H8/300
7797 @item relaxing address modes
7798 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7799 targets are within eight bits, and turns them into eight-bit
7800 program-counter relative @code{bsr} and @code{bra} instructions,
7803 @cindex synthesizing on H8/300
7804 @item synthesizing instructions
7805 @c FIXME: specifically mov.b, or any mov instructions really? -> mov.b only, at least on H8, H8H, H8S
7806 @command{ld} finds all @code{mov.b} instructions which use the
7807 sixteen-bit absolute address form, but refer to the top
7808 page of memory, and changes them to use the eight-bit address form.
7809 (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
7810 @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
7811 top page of memory).
7813 @command{ld} finds all @code{mov} instructions which use the register
7814 indirect with 32-bit displacement addressing mode, but use a small
7815 displacement inside 16-bit displacement range, and changes them to use
7816 the 16-bit displacement form. (That is: the linker turns @samp{mov.b
7817 @code{@@}@var{d}:32,ERx} into @samp{mov.b @code{@@}@var{d}:16,ERx}
7818 whenever the displacement @var{d} is in the 16 bit signed integer
7819 range. Only implemented in ELF-format ld).
7821 @item bit manipulation instructions
7822 @command{ld} finds all bit manipulation instructions like @code{band, bclr,
7823 biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor}
7824 which use 32 bit and 16 bit absolute address form, but refer to the top
7825 page of memory, and changes them to use the 8 bit address form.
7826 (That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into
7827 @samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in
7828 the top page of memory).
7830 @item system control instructions
7831 @command{ld} finds all @code{ldc.w, stc.w} instructions which use the
7832 32 bit absolute address form, but refer to the top page of memory, and
7833 changes them to use 16 bit address form.
7834 (That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into
7835 @samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in
7836 the top page of memory).
7846 @c This stuff is pointless to say unless you're especially concerned
7847 @c with Renesas chips; don't enable it for generic case, please.
7849 @chapter @command{ld} and Other Renesas Chips
7851 @command{ld} also supports the Renesas (formerly Hitachi) H8/300H,
7852 H8/500, and SH chips. No special features, commands, or command-line
7853 options are required for these chips.
7867 @node M68HC11/68HC12
7868 @section @command{ld} and the Motorola 68HC11 and 68HC12 families
7870 @cindex M68HC11 and 68HC12 support
7872 @subsection Linker Relaxation
7874 For the Motorola 68HC11, @command{ld} can perform these global
7875 optimizations when you specify the @samp{--relax} command-line option.
7878 @cindex relaxing on M68HC11
7879 @item relaxing address modes
7880 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7881 targets are within eight bits, and turns them into eight-bit
7882 program-counter relative @code{bsr} and @code{bra} instructions,
7885 @command{ld} also looks at all 16-bit extended addressing modes and
7886 transforms them in a direct addressing mode when the address is in
7887 page 0 (between 0 and 0x0ff).
7889 @item relaxing gcc instruction group
7890 When @command{gcc} is called with @option{-mrelax}, it can emit group
7891 of instructions that the linker can optimize to use a 68HC11 direct
7892 addressing mode. These instructions consists of @code{bclr} or
7893 @code{bset} instructions.
7897 @subsection Trampoline Generation
7899 @cindex trampoline generation on M68HC11
7900 @cindex trampoline generation on M68HC12
7901 For 68HC11 and 68HC12, @command{ld} can generate trampoline code to
7902 call a far function using a normal @code{jsr} instruction. The linker
7903 will also change the relocation to some far function to use the
7904 trampoline address instead of the function address. This is typically the
7905 case when a pointer to a function is taken. The pointer will in fact
7906 point to the function trampoline.
7914 @section @command{ld} and the ARM family
7916 @cindex ARM interworking support
7917 @kindex --support-old-code
7918 For the ARM, @command{ld} will generate code stubs to allow functions calls
7919 between ARM and Thumb code. These stubs only work with code that has
7920 been compiled and assembled with the @samp{-mthumb-interwork} command
7921 line option. If it is necessary to link with old ARM object files or
7922 libraries, which have not been compiled with the -mthumb-interwork
7923 option then the @samp{--support-old-code} command-line switch should be
7924 given to the linker. This will make it generate larger stub functions
7925 which will work with non-interworking aware ARM code. Note, however,
7926 the linker does not support generating stubs for function calls to
7927 non-interworking aware Thumb code.
7929 @cindex thumb entry point
7930 @cindex entry point, thumb
7931 @kindex --thumb-entry=@var{entry}
7932 The @samp{--thumb-entry} switch is a duplicate of the generic
7933 @samp{--entry} switch, in that it sets the program's starting address.
7934 But it also sets the bottom bit of the address, so that it can be
7935 branched to using a BX instruction, and the program will start
7936 executing in Thumb mode straight away.
7938 @cindex PE import table prefixing
7939 @kindex --use-nul-prefixed-import-tables
7940 The @samp{--use-nul-prefixed-import-tables} switch is specifying, that
7941 the import tables idata4 and idata5 have to be generated with a zero
7942 element prefix for import libraries. This is the old style to generate
7943 import tables. By default this option is turned off.
7947 The @samp{--be8} switch instructs @command{ld} to generate BE8 format
7948 executables. This option is only valid when linking big-endian
7949 objects - ie ones which have been assembled with the @option{-EB}
7950 option. The resulting image will contain big-endian data and
7954 @kindex --target1-rel
7955 @kindex --target1-abs
7956 The @samp{R_ARM_TARGET1} relocation is typically used for entries in the
7957 @samp{.init_array} section. It is interpreted as either @samp{R_ARM_REL32}
7958 or @samp{R_ARM_ABS32}, depending on the target. The @samp{--target1-rel}
7959 and @samp{--target1-abs} switches override the default.
7962 @kindex --target2=@var{type}
7963 The @samp{--target2=type} switch overrides the default definition of the
7964 @samp{R_ARM_TARGET2} relocation. Valid values for @samp{type}, their
7965 meanings, and target defaults are as follows:
7968 @samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
7972 @samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
7977 The @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
7978 specification) enables objects compiled for the ARMv4 architecture to be
7979 interworking-safe when linked with other objects compiled for ARMv4t, but
7980 also allows pure ARMv4 binaries to be built from the same ARMv4 objects.
7982 In the latter case, the switch @option{--fix-v4bx} must be passed to the
7983 linker, which causes v4t @code{BX rM} instructions to be rewritten as
7984 @code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
7986 In the former case, the switch should not be used, and @samp{R_ARM_V4BX}
7987 relocations are ignored.
7989 @cindex FIX_V4BX_INTERWORKING
7990 @kindex --fix-v4bx-interworking
7991 Replace @code{BX rM} instructions identified by @samp{R_ARM_V4BX}
7992 relocations with a branch to the following veneer:
8000 This allows generation of libraries/applications that work on ARMv4 cores
8001 and are still interworking safe. Note that the above veneer clobbers the
8002 condition flags, so may cause incorrect program behavior in rare cases.
8006 The @samp{--use-blx} switch enables the linker to use ARM/Thumb
8007 BLX instructions (available on ARMv5t and above) in various
8008 situations. Currently it is used to perform calls via the PLT from Thumb
8009 code using BLX rather than using BX and a mode-switching stub before
8010 each PLT entry. This should lead to such calls executing slightly faster.
8012 @cindex VFP11_DENORM_FIX
8013 @kindex --vfp11-denorm-fix
8014 The @samp{--vfp11-denorm-fix} switch enables a link-time workaround for a
8015 bug in certain VFP11 coprocessor hardware, which sometimes allows
8016 instructions with denorm operands (which must be handled by support code)
8017 to have those operands overwritten by subsequent instructions before
8018 the support code can read the intended values.
8020 The bug may be avoided in scalar mode if you allow at least one
8021 intervening instruction between a VFP11 instruction which uses a register
8022 and another instruction which writes to the same register, or at least two
8023 intervening instructions if vector mode is in use. The bug only affects
8024 full-compliance floating-point mode: you do not need this workaround if
8025 you are using "runfast" mode. Please contact ARM for further details.
8027 If you know you are using buggy VFP11 hardware, you can
8028 enable this workaround by specifying the linker option
8029 @samp{--vfp-denorm-fix=scalar} if you are using the VFP11 scalar
8030 mode only, or @samp{--vfp-denorm-fix=vector} if you are using
8031 vector mode (the latter also works for scalar code). The default is
8032 @samp{--vfp-denorm-fix=none}.
8034 If the workaround is enabled, instructions are scanned for
8035 potentially-troublesome sequences, and a veneer is created for each
8036 such sequence which may trigger the erratum. The veneer consists of the
8037 first instruction of the sequence and a branch back to the subsequent
8038 instruction. The original instruction is then replaced with a branch to
8039 the veneer. The extra cycles required to call and return from the veneer
8040 are sufficient to avoid the erratum in both the scalar and vector cases.
8042 @cindex ARM1176 erratum workaround
8043 @kindex --fix-arm1176
8044 @kindex --no-fix-arm1176
8045 The @samp{--fix-arm1176} switch enables a link-time workaround for an erratum
8046 in certain ARM1176 processors. The workaround is enabled by default if you
8047 are targeting ARM v6 (excluding ARM v6T2) or earlier. It can be disabled
8048 unconditionally by specifying @samp{--no-fix-arm1176}.
8050 Further information is available in the ``ARM1176JZ-S and ARM1176JZF-S
8051 Programmer Advice Notice'' available on the ARM documentation website at:
8052 http://infocenter.arm.com/.
8054 @cindex STM32L4xx erratum workaround
8055 @kindex --fix-stm32l4xx-629360
8057 The @samp{--fix-stm32l4xx-629360} switch enables a link-time
8058 workaround for a bug in the bus matrix / memory controller for some of
8059 the STM32 Cortex-M4 based products (STM32L4xx). When accessing
8060 off-chip memory via the affected bus for bus reads of 9 words or more,
8061 the bus can generate corrupt data and/or abort. These are only
8062 core-initiated accesses (not DMA), and might affect any access:
8063 integer loads such as LDM, POP and floating-point loads such as VLDM,
8064 VPOP. Stores are not affected.
8066 The bug can be avoided by splitting memory accesses into the
8067 necessary chunks to keep bus reads below 8 words.
8069 The workaround is not enabled by default, this is equivalent to use
8070 @samp{--fix-stm32l4xx-629360=none}. If you know you are using buggy
8071 STM32L4xx hardware, you can enable the workaround by specifying the
8072 linker option @samp{--fix-stm32l4xx-629360}, or the equivalent
8073 @samp{--fix-stm32l4xx-629360=default}.
8075 If the workaround is enabled, instructions are scanned for
8076 potentially-troublesome sequences, and a veneer is created for each
8077 such sequence which may trigger the erratum. The veneer consists in a
8078 replacement sequence emulating the behaviour of the original one and a
8079 branch back to the subsequent instruction. The original instruction is
8080 then replaced with a branch to the veneer.
8082 The workaround does not always preserve the memory access order for
8083 the LDMDB instruction, when the instruction loads the PC.
8085 The workaround is not able to handle problematic instructions when
8086 they are in the middle of an IT block, since a branch is not allowed
8087 there. In that case, the linker reports a warning and no replacement
8090 The workaround is not able to replace problematic instructions with a
8091 PC-relative branch instruction if the @samp{.text} section is too
8092 large. In that case, when the branch that replaces the original code
8093 cannot be encoded, the linker reports a warning and no replacement
8096 @cindex NO_ENUM_SIZE_WARNING
8097 @kindex --no-enum-size-warning
8098 The @option{--no-enum-size-warning} switch prevents the linker from
8099 warning when linking object files that specify incompatible EABI
8100 enumeration size attributes. For example, with this switch enabled,
8101 linking of an object file using 32-bit enumeration values with another
8102 using enumeration values fitted into the smallest possible space will
8105 @cindex NO_WCHAR_SIZE_WARNING
8106 @kindex --no-wchar-size-warning
8107 The @option{--no-wchar-size-warning} switch prevents the linker from
8108 warning when linking object files that specify incompatible EABI
8109 @code{wchar_t} size attributes. For example, with this switch enabled,
8110 linking of an object file using 32-bit @code{wchar_t} values with another
8111 using 16-bit @code{wchar_t} values will not be diagnosed.
8114 @kindex --pic-veneer
8115 The @samp{--pic-veneer} switch makes the linker use PIC sequences for
8116 ARM/Thumb interworking veneers, even if the rest of the binary
8117 is not PIC. This avoids problems on uClinux targets where
8118 @samp{--emit-relocs} is used to generate relocatable binaries.
8120 @cindex STUB_GROUP_SIZE
8121 @kindex --stub-group-size=@var{N}
8122 The linker will automatically generate and insert small sequences of
8123 code into a linked ARM ELF executable whenever an attempt is made to
8124 perform a function call to a symbol that is too far away. The
8125 placement of these sequences of instructions - called stubs - is
8126 controlled by the command-line option @option{--stub-group-size=N}.
8127 The placement is important because a poor choice can create a need for
8128 duplicate stubs, increasing the code size. The linker will try to
8129 group stubs together in order to reduce interruptions to the flow of
8130 code, but it needs guidance as to how big these groups should be and
8131 where they should be placed.
8133 The value of @samp{N}, the parameter to the
8134 @option{--stub-group-size=} option controls where the stub groups are
8135 placed. If it is negative then all stubs are placed after the first
8136 branch that needs them. If it is positive then the stubs can be
8137 placed either before or after the branches that need them. If the
8138 value of @samp{N} is 1 (either +1 or -1) then the linker will choose
8139 exactly where to place groups of stubs, using its built in heuristics.
8140 A value of @samp{N} greater than 1 (or smaller than -1) tells the
8141 linker that a single group of stubs can service at most @samp{N} bytes
8142 from the input sections.
8144 The default, if @option{--stub-group-size=} is not specified, is
8147 Farcalls stubs insertion is fully supported for the ARM-EABI target
8148 only, because it relies on object files properties not present
8151 @cindex Cortex-A8 erratum workaround
8152 @kindex --fix-cortex-a8
8153 @kindex --no-fix-cortex-a8
8154 The @samp{--fix-cortex-a8} switch enables a link-time workaround for an erratum in certain Cortex-A8 processors. The workaround is enabled by default if you are targeting the ARM v7-A architecture profile. It can be enabled otherwise by specifying @samp{--fix-cortex-a8}, or disabled unconditionally by specifying @samp{--no-fix-cortex-a8}.
8156 The erratum only affects Thumb-2 code. Please contact ARM for further details.
8158 @cindex Cortex-A53 erratum 835769 workaround
8159 @kindex --fix-cortex-a53-835769
8160 @kindex --no-fix-cortex-a53-835769
8161 The @samp{--fix-cortex-a53-835769} switch enables a link-time workaround for erratum 835769 present on certain early revisions of Cortex-A53 processors. The workaround is disabled by default. It can be enabled by specifying @samp{--fix-cortex-a53-835769}, or disabled unconditionally by specifying @samp{--no-fix-cortex-a53-835769}.
8163 Please contact ARM for further details.
8165 @kindex --merge-exidx-entries
8166 @kindex --no-merge-exidx-entries
8167 @cindex Merging exidx entries
8168 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent exidx entries in debuginfo.
8171 @cindex 32-bit PLT entries
8172 The @samp{--long-plt} option enables the use of 16 byte PLT entries
8173 which support up to 4Gb of code. The default is to use 12 byte PLT
8174 entries which only support 512Mb of code.
8176 @kindex --no-apply-dynamic-relocs
8177 @cindex AArch64 rela addend
8178 The @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
8179 link-time values for dynamic relocations.
8181 @cindex Placement of SG veneers
8182 All SG veneers are placed in the special output section @code{.gnu.sgstubs}.
8183 Its start address must be set, either with the command-line option
8184 @samp{--section-start} or in a linker script, to indicate where to place these
8187 @kindex --cmse-implib
8188 @cindex Secure gateway import library
8189 The @samp{--cmse-implib} option requests that the import libraries
8190 specified by the @samp{--out-implib} and @samp{--in-implib} options are
8191 secure gateway import libraries, suitable for linking a non-secure
8192 executable against secure code as per ARMv8-M Security Extensions.
8194 @kindex --in-implib=@var{file}
8195 @cindex Input import library
8196 The @samp{--in-implib=file} specifies an input import library whose symbols
8197 must keep the same address in the executable being produced. A warning is
8198 given if no @samp{--out-implib} is given but new symbols have been introduced
8199 in the executable that should be listed in its import library. Otherwise, if
8200 @samp{--out-implib} is specified, the symbols are added to the output import
8201 library. A warning is also given if some symbols present in the input import
8202 library have disappeared from the executable. This option is only effective
8203 for Secure Gateway import libraries, ie. when @samp{--cmse-implib} is
8217 @section @command{ld} and HPPA 32-bit ELF Support
8218 @cindex HPPA multiple sub-space stubs
8219 @kindex --multi-subspace
8220 When generating a shared library, @command{ld} will by default generate
8221 import stubs suitable for use with a single sub-space application.
8222 The @samp{--multi-subspace} switch causes @command{ld} to generate export
8223 stubs, and different (larger) import stubs suitable for use with
8224 multiple sub-spaces.
8226 @cindex HPPA stub grouping
8227 @kindex --stub-group-size=@var{N}
8228 Long branch stubs and import/export stubs are placed by @command{ld} in
8229 stub sections located between groups of input sections.
8230 @samp{--stub-group-size} specifies the maximum size of a group of input
8231 sections handled by one stub section. Since branch offsets are signed,
8232 a stub section may serve two groups of input sections, one group before
8233 the stub section, and one group after it. However, when using
8234 conditional branches that require stubs, it may be better (for branch
8235 prediction) that stub sections only serve one group of input sections.
8236 A negative value for @samp{N} chooses this scheme, ensuring that
8237 branches to stubs always use a negative offset. Two special values of
8238 @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
8239 @command{ld} to automatically size input section groups for the branch types
8240 detected, with the same behaviour regarding stub placement as other
8241 positive or negative values of @samp{N} respectively.
8243 Note that @samp{--stub-group-size} does not split input sections. A
8244 single input section larger than the group size specified will of course
8245 create a larger group (of one section). If input sections are too
8246 large, it may not be possible for a branch to reach its stub.
8259 @section @command{ld} and the Motorola 68K family
8261 @cindex Motorola 68K GOT generation
8262 @kindex --got=@var{type}
8263 The @samp{--got=@var{type}} option lets you choose the GOT generation scheme.
8264 The choices are @samp{single}, @samp{negative}, @samp{multigot} and
8265 @samp{target}. When @samp{target} is selected the linker chooses
8266 the default GOT generation scheme for the current target.
8267 @samp{single} tells the linker to generate a single GOT with
8268 entries only at non-negative offsets.
8269 @samp{negative} instructs the linker to generate a single GOT with
8270 entries at both negative and positive offsets. Not all environments
8272 @samp{multigot} allows the linker to generate several GOTs in the
8273 output file. All GOT references from a single input object
8274 file access the same GOT, but references from different input object
8275 files might access different GOTs. Not all environments support such GOTs.
8288 @section @command{ld} and the MIPS family
8290 @cindex MIPS microMIPS instruction choice selection
8293 The @samp{--insn32} and @samp{--no-insn32} options control the choice of
8294 microMIPS instructions used in code generated by the linker, such as that
8295 in the PLT or lazy binding stubs, or in relaxation. If @samp{--insn32} is
8296 used, then the linker only uses 32-bit instruction encodings. By default
8297 or if @samp{--no-insn32} is used, all instruction encodings are used,
8298 including 16-bit ones where possible.
8300 @cindex MIPS branch relocation check control
8301 @kindex --ignore-branch-isa
8302 @kindex --no-ignore-branch-isa
8303 The @samp{--ignore-branch-isa} and @samp{--no-ignore-branch-isa} options
8304 control branch relocation checks for invalid ISA mode transitions. If
8305 @samp{--ignore-branch-isa} is used, then the linker accepts any branch
8306 relocations and any ISA mode transition required is lost in relocation
8307 calculation, except for some cases of @code{BAL} instructions which meet
8308 relaxation conditions and are converted to equivalent @code{JALX}
8309 instructions as the associated relocation is calculated. By default
8310 or if @samp{--no-ignore-branch-isa} is used a check is made causing
8311 the loss of an ISA mode transition to produce an error.
8324 @section @code{ld} and MMIX
8325 For MMIX, there is a choice of generating @code{ELF} object files or
8326 @code{mmo} object files when linking. The simulator @code{mmix}
8327 understands the @code{mmo} format. The binutils @code{objcopy} utility
8328 can translate between the two formats.
8330 There is one special section, the @samp{.MMIX.reg_contents} section.
8331 Contents in this section is assumed to correspond to that of global
8332 registers, and symbols referring to it are translated to special symbols,
8333 equal to registers. In a final link, the start address of the
8334 @samp{.MMIX.reg_contents} section corresponds to the first allocated
8335 global register multiplied by 8. Register @code{$255} is not included in
8336 this section; it is always set to the program entry, which is at the
8337 symbol @code{Main} for @code{mmo} files.
8339 Global symbols with the prefix @code{__.MMIX.start.}, for example
8340 @code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special.
8341 The default linker script uses these to set the default start address
8344 Initial and trailing multiples of zero-valued 32-bit words in a section,
8345 are left out from an mmo file.
8358 @section @code{ld} and MSP430
8359 For the MSP430 it is possible to select the MPU architecture. The flag @samp{-m [mpu type]}
8360 will select an appropriate linker script for selected MPU type. (To get a list of known MPUs
8361 just pass @samp{-m help} option to the linker).
8363 @cindex MSP430 extra sections
8364 The linker will recognize some extra sections which are MSP430 specific:
8367 @item @samp{.vectors}
8368 Defines a portion of ROM where interrupt vectors located.
8370 @item @samp{.bootloader}
8371 Defines the bootloader portion of the ROM (if applicable). Any code
8372 in this section will be uploaded to the MPU.
8374 @item @samp{.infomem}
8375 Defines an information memory section (if applicable). Any code in
8376 this section will be uploaded to the MPU.
8378 @item @samp{.infomemnobits}
8379 This is the same as the @samp{.infomem} section except that any code
8380 in this section will not be uploaded to the MPU.
8382 @item @samp{.noinit}
8383 Denotes a portion of RAM located above @samp{.bss} section.
8385 The last two sections are used by gcc.
8389 @cindex MSP430 Options
8390 @kindex --code-region
8391 @item --code-region=[either,lower,upper,none]
8392 This will transform .text* sections to [either,lower,upper].text* sections. The
8393 argument passed to GCC for -mcode-region is propagated to the linker
8396 @kindex --data-region
8397 @item --data-region=[either,lower,upper,none]
8398 This will transform .data*, .bss* and .rodata* sections to
8399 [either,lower,upper].[data,bss,rodata]* sections. The argument passed to GCC
8400 for -mdata-region is propagated to the linker using this option.
8402 @kindex --disable-sec-transformation
8403 @item --disable-sec-transformation
8404 Prevent the transformation of sections as specified by the @code{--code-region}
8405 and @code{--data-region} options.
8406 This is useful if you are compiling and linking using a single call to the GCC
8407 wrapper, and want to compile the source files using -m[code,data]-region but
8408 not transform the sections for prebuilt libraries and objects.
8422 @section @code{ld} and NDS32
8423 @kindex relaxing on NDS32
8424 For NDS32, there are some options to select relaxation behavior. The linker
8425 relaxes objects according to these options.
8428 @item @samp{--m[no-]fp-as-gp}
8429 Disable/enable fp-as-gp relaxation.
8431 @item @samp{--mexport-symbols=FILE}
8432 Exporting symbols and their address into FILE as linker script.
8434 @item @samp{--m[no-]ex9}
8435 Disable/enable link-time EX9 relaxation.
8437 @item @samp{--mexport-ex9=FILE}
8438 Export the EX9 table after linking.
8440 @item @samp{--mimport-ex9=FILE}
8441 Import the Ex9 table for EX9 relaxation.
8443 @item @samp{--mupdate-ex9}
8444 Update the existing EX9 table.
8446 @item @samp{--mex9-limit=NUM}
8447 Maximum number of entries in the ex9 table.
8449 @item @samp{--mex9-loop-aware}
8450 Avoid generating the EX9 instruction inside the loop.
8452 @item @samp{--m[no-]ifc}
8453 Disable/enable the link-time IFC optimization.
8455 @item @samp{--mifc-loop-aware}
8456 Avoid generating the IFC instruction inside the loop.
8470 @section @command{ld} and the Altera Nios II
8471 @cindex Nios II call relaxation
8472 @kindex --relax on Nios II
8474 Call and immediate jump instructions on Nios II processors are limited to
8475 transferring control to addresses in the same 256MB memory segment,
8476 which may result in @command{ld} giving
8477 @samp{relocation truncated to fit} errors with very large programs.
8478 The command-line option @option{--relax} enables the generation of
8479 trampolines that can access the entire 32-bit address space for calls
8480 outside the normal @code{call} and @code{jmpi} address range. These
8481 trampolines are inserted at section boundaries, so may not themselves
8482 be reachable if an input section and its associated call trampolines are
8485 The @option{--relax} option is enabled by default unless @option{-r}
8486 is also specified. You can disable trampoline generation by using the
8487 @option{--no-relax} linker option. You can also disable this optimization
8488 locally by using the @samp{set .noat} directive in assembly-language
8489 source files, as the linker-inserted trampolines use the @code{at}
8490 register as a temporary.
8492 Note that the linker @option{--relax} option is independent of assembler
8493 relaxation options, and that using the GNU assembler's @option{-relax-all}
8494 option interferes with the linker's more selective call instruction relaxation.
8507 @section @command{ld} and PowerPC 32-bit ELF Support
8508 @cindex PowerPC long branches
8509 @kindex --relax on PowerPC
8510 Branches on PowerPC processors are limited to a signed 26-bit
8511 displacement, which may result in @command{ld} giving
8512 @samp{relocation truncated to fit} errors with very large programs.
8513 @samp{--relax} enables the generation of trampolines that can access
8514 the entire 32-bit address space. These trampolines are inserted at
8515 section boundaries, so may not themselves be reachable if an input
8516 section exceeds 33M in size. You may combine @samp{-r} and
8517 @samp{--relax} to add trampolines in a partial link. In that case
8518 both branches to undefined symbols and inter-section branches are also
8519 considered potentially out of range, and trampolines inserted.
8521 @cindex PowerPC ELF32 options
8526 Current PowerPC GCC accepts a @samp{-msecure-plt} option that
8527 generates code capable of using a newer PLT and GOT layout that has
8528 the security advantage of no executable section ever needing to be
8529 writable and no writable section ever being executable. PowerPC
8530 @command{ld} will generate this layout, including stubs to access the
8531 PLT, if all input files (including startup and static libraries) were
8532 compiled with @samp{-msecure-plt}. @samp{--bss-plt} forces the old
8533 BSS PLT (and GOT layout) which can give slightly better performance.
8535 @kindex --secure-plt
8537 @command{ld} will use the new PLT and GOT layout if it is linking new
8538 @samp{-fpic} or @samp{-fPIC} code, but does not do so automatically
8539 when linking non-PIC code. This option requests the new PLT and GOT
8540 layout. A warning will be given if some object file requires the old
8546 The new secure PLT and GOT are placed differently relative to other
8547 sections compared to older BSS PLT and GOT placement. The location of
8548 @code{.plt} must change because the new secure PLT is an initialized
8549 section while the old PLT is uninitialized. The reason for the
8550 @code{.got} change is more subtle: The new placement allows
8551 @code{.got} to be read-only in applications linked with
8552 @samp{-z relro -z now}. However, this placement means that
8553 @code{.sdata} cannot always be used in shared libraries, because the
8554 PowerPC ABI accesses @code{.sdata} in shared libraries from the GOT
8555 pointer. @samp{--sdata-got} forces the old GOT placement. PowerPC
8556 GCC doesn't use @code{.sdata} in shared libraries, so this option is
8557 really only useful for other compilers that may do so.
8559 @cindex PowerPC stub symbols
8560 @kindex --emit-stub-syms
8561 @item --emit-stub-syms
8562 This option causes @command{ld} to label linker stubs with a local
8563 symbol that encodes the stub type and destination.
8565 @cindex PowerPC TLS optimization
8566 @kindex --no-tls-optimize
8567 @item --no-tls-optimize
8568 PowerPC @command{ld} normally performs some optimization of code
8569 sequences used to access Thread-Local Storage. Use this option to
8570 disable the optimization.
8583 @node PowerPC64 ELF64
8584 @section @command{ld} and PowerPC64 64-bit ELF Support
8586 @cindex PowerPC64 ELF64 options
8588 @cindex PowerPC64 stub grouping
8589 @kindex --stub-group-size
8590 @item --stub-group-size
8591 Long branch stubs, PLT call stubs and TOC adjusting stubs are placed
8592 by @command{ld} in stub sections located between groups of input sections.
8593 @samp{--stub-group-size} specifies the maximum size of a group of input
8594 sections handled by one stub section. Since branch offsets are signed,
8595 a stub section may serve two groups of input sections, one group before
8596 the stub section, and one group after it. However, when using
8597 conditional branches that require stubs, it may be better (for branch
8598 prediction) that stub sections only serve one group of input sections.
8599 A negative value for @samp{N} chooses this scheme, ensuring that
8600 branches to stubs always use a negative offset. Two special values of
8601 @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
8602 @command{ld} to automatically size input section groups for the branch types
8603 detected, with the same behaviour regarding stub placement as other
8604 positive or negative values of @samp{N} respectively.
8606 Note that @samp{--stub-group-size} does not split input sections. A
8607 single input section larger than the group size specified will of course
8608 create a larger group (of one section). If input sections are too
8609 large, it may not be possible for a branch to reach its stub.
8611 @cindex PowerPC64 stub symbols
8612 @kindex --emit-stub-syms
8613 @item --emit-stub-syms
8614 This option causes @command{ld} to label linker stubs with a local
8615 symbol that encodes the stub type and destination.
8617 @cindex PowerPC64 dot symbols
8619 @kindex --no-dotsyms
8622 These two options control how @command{ld} interprets version patterns
8623 in a version script. Older PowerPC64 compilers emitted both a
8624 function descriptor symbol with the same name as the function, and a
8625 code entry symbol with the name prefixed by a dot (@samp{.}). To
8626 properly version a function @samp{foo}, the version script thus needs
8627 to control both @samp{foo} and @samp{.foo}. The option
8628 @samp{--dotsyms}, on by default, automatically adds the required
8629 dot-prefixed patterns. Use @samp{--no-dotsyms} to disable this
8632 @cindex PowerPC64 register save/restore functions
8633 @kindex --save-restore-funcs
8634 @kindex --no-save-restore-funcs
8635 @item --save-restore-funcs
8636 @itemx --no-save-restore-funcs
8637 These two options control whether PowerPC64 @command{ld} automatically
8638 provides out-of-line register save and restore functions used by
8639 @samp{-Os} code. The default is to provide any such referenced
8640 function for a normal final link, and to not do so for a relocatable
8643 @cindex PowerPC64 TLS optimization
8644 @kindex --no-tls-optimize
8645 @item --no-tls-optimize
8646 PowerPC64 @command{ld} normally performs some optimization of code
8647 sequences used to access Thread-Local Storage. Use this option to
8648 disable the optimization.
8650 @cindex PowerPC64 __tls_get_addr optimization
8651 @kindex --tls-get-addr-optimize
8652 @kindex --no-tls-get-addr-optimize
8653 @kindex --tls-get-addr-regsave
8654 @kindex --no-tls-get-addr-regsave
8655 @item --tls-get-addr-optimize
8656 @itemx --no-tls-get-addr-optimize
8657 These options control how PowerPC64 @command{ld} uses a special
8658 stub to call __tls_get_addr. PowerPC64 glibc 2.22 and later support
8659 an optimization that allows the second and subsequent calls to
8660 @code{__tls_get_addr} for a given symbol to be resolved by the special
8661 stub without calling in to glibc. By default the linker enables
8662 generation of the stub when glibc advertises the availability of
8664 Using @option{--tls-get-addr-optimize} with an older glibc won't do
8665 much besides slow down your applications, but may be useful if linking
8666 an application against an older glibc with the expectation that it
8667 will normally be used on systems having a newer glibc.
8668 @option{--tls-get-addr-regsave} forces generation of a stub that saves
8669 and restores volatile registers around the call into glibc. Normally,
8670 this is done when the linker detects a call to __tls_get_addr_desc.
8671 Such calls then go via the register saving stub to __tls_get_addr_opt.
8672 @option{--no-tls-get-addr-regsave} disables generation of the
8675 @cindex PowerPC64 OPD optimization
8676 @kindex --no-opd-optimize
8677 @item --no-opd-optimize
8678 PowerPC64 @command{ld} normally removes @code{.opd} section entries
8679 corresponding to deleted link-once functions, or functions removed by
8680 the action of @samp{--gc-sections} or linker script @code{/DISCARD/}.
8681 Use this option to disable @code{.opd} optimization.
8683 @cindex PowerPC64 OPD spacing
8684 @kindex --non-overlapping-opd
8685 @item --non-overlapping-opd
8686 Some PowerPC64 compilers have an option to generate compressed
8687 @code{.opd} entries spaced 16 bytes apart, overlapping the third word,
8688 the static chain pointer (unused in C) with the first word of the next
8689 entry. This option expands such entries to the full 24 bytes.
8691 @cindex PowerPC64 TOC optimization
8692 @kindex --no-toc-optimize
8693 @item --no-toc-optimize
8694 PowerPC64 @command{ld} normally removes unused @code{.toc} section
8695 entries. Such entries are detected by examining relocations that
8696 reference the TOC in code sections. A reloc in a deleted code section
8697 marks a TOC word as unneeded, while a reloc in a kept code section
8698 marks a TOC word as needed. Since the TOC may reference itself, TOC
8699 relocs are also examined. TOC words marked as both needed and
8700 unneeded will of course be kept. TOC words without any referencing
8701 reloc are assumed to be part of a multi-word entry, and are kept or
8702 discarded as per the nearest marked preceding word. This works
8703 reliably for compiler generated code, but may be incorrect if assembly
8704 code is used to insert TOC entries. Use this option to disable the
8707 @cindex PowerPC64 inline PLT call optimization
8708 @kindex --no-inline-optimize
8709 @item --no-inline-optimize
8710 PowerPC64 @command{ld} normally replaces inline PLT call sequences
8711 marked with @code{R_PPC64_PLTSEQ}, @code{R_PPC64_PLTCALL},
8712 @code{R_PPC64_PLT16_HA} and @code{R_PPC64_PLT16_LO_DS} relocations by
8713 a number of @code{nop}s and a direct call when the function is defined
8714 locally and can't be overridden by some other definition. This option
8715 disables that optimization.
8717 @cindex PowerPC64 multi-TOC
8718 @kindex --no-multi-toc
8719 @item --no-multi-toc
8720 If given any toc option besides @code{-mcmodel=medium} or
8721 @code{-mcmodel=large}, PowerPC64 GCC generates code for a TOC model
8723 entries are accessed with a 16-bit offset from r2. This limits the
8724 total TOC size to 64K. PowerPC64 @command{ld} extends this limit by
8725 grouping code sections such that each group uses less than 64K for its
8726 TOC entries, then inserts r2 adjusting stubs between inter-group
8727 calls. @command{ld} does not split apart input sections, so cannot
8728 help if a single input file has a @code{.toc} section that exceeds
8729 64K, most likely from linking multiple files with @command{ld -r}.
8730 Use this option to turn off this feature.
8732 @cindex PowerPC64 TOC sorting
8733 @kindex --no-toc-sort
8735 By default, @command{ld} sorts TOC sections so that those whose file
8736 happens to have a section called @code{.init} or @code{.fini} are
8737 placed first, followed by TOC sections referenced by code generated
8738 with PowerPC64 gcc's @code{-mcmodel=small}, and lastly TOC sections
8739 referenced only by code generated with PowerPC64 gcc's
8740 @code{-mcmodel=medium} or @code{-mcmodel=large} options. Doing this
8741 results in better TOC grouping for multi-TOC. Use this option to turn
8744 @cindex PowerPC64 PLT stub alignment
8746 @kindex --no-plt-align
8748 @itemx --no-plt-align
8749 Use these options to control whether individual PLT call stubs are
8750 aligned to a 32-byte boundary, or to the specified power of two
8751 boundary when using @code{--plt-align=}. A negative value may be
8752 specified to pad PLT call stubs so that they do not cross the
8753 specified power of two boundary (or the minimum number of boundaries
8754 if a PLT stub is so large that it must cross a boundary). By default
8755 PLT call stubs are aligned to 32-byte boundaries.
8757 @cindex PowerPC64 PLT call stub static chain
8758 @kindex --plt-static-chain
8759 @kindex --no-plt-static-chain
8760 @item --plt-static-chain
8761 @itemx --no-plt-static-chain
8762 Use these options to control whether PLT call stubs load the static
8763 chain pointer (r11). @code{ld} defaults to not loading the static
8764 chain since there is never any need to do so on a PLT call.
8766 @cindex PowerPC64 PLT call stub thread safety
8767 @kindex --plt-thread-safe
8768 @kindex --no-plt-thread-safe
8769 @item --plt-thread-safe
8770 @itemx --no-plt-thread-safe
8771 With power7's weakly ordered memory model, it is possible when using
8772 lazy binding for ld.so to update a plt entry in one thread and have
8773 another thread see the individual plt entry words update in the wrong
8774 order, despite ld.so carefully writing in the correct order and using
8775 memory write barriers. To avoid this we need some sort of read
8776 barrier in the call stub, or use LD_BIND_NOW=1. By default, @code{ld}
8777 looks for calls to commonly used functions that create threads, and if
8778 seen, adds the necessary barriers. Use these options to change the
8781 @cindex PowerPC64 ELFv2 PLT localentry optimization
8782 @kindex --plt-localentry
8783 @kindex --no-plt-localentry
8784 @item --plt-localentry
8785 @itemx --no-localentry
8786 ELFv2 functions with localentry:0 are those with a single entry point,
8787 ie. global entry == local entry, and that have no requirement on r2
8788 (the TOC/GOT pointer) or r12, and guarantee r2 is unchanged on return.
8789 Such an external function can be called via the PLT without saving r2
8790 or restoring it on return, avoiding a common load-hit-store for small
8791 functions. The optimization is attractive, with up to 40% reduction
8792 in execution time for a small function, but can result in symbol
8793 interposition failures. Also, minor changes in a shared library,
8794 including system libraries, can cause a function that was localentry:0
8795 to become localentry:8. This will result in a dynamic loader
8796 complaint and failure to run. The option is experimental, use with
8797 care. @option{--no-plt-localentry} is the default.
8799 @cindex PowerPC64 Power10 stubs
8800 @kindex --power10-stubs
8801 @kindex --no-power10-stubs
8802 @item --power10-stubs
8803 @itemx --no-power10-stubs
8804 When PowerPC64 @command{ld} links input object files containing
8805 relocations used on power10 prefixed instructions it normally creates
8806 linkage stubs (PLT call and long branch) using power10 instructions
8807 for @code{@@notoc} PLT calls where @code{r2} is not known. The
8808 power10 notoc stubs are smaller and faster, so are preferred for
8809 power10. @option{--power10-stubs} and @option{--no-power10-stubs}
8810 allow you to override the linker's selection of stub instructions.
8811 @option{--power10-stubs=auto} allows the user to select the default
8826 @section @command{ld} and S/390 ELF Support
8828 @cindex S/390 ELF options
8832 @kindex --s390-pgste
8834 This option marks the result file with a @code{PT_S390_PGSTE}
8835 segment. The Linux kernel is supposed to allocate 4k page tables for
8836 binaries marked that way.
8850 @section @command{ld} and SPU ELF Support
8852 @cindex SPU ELF options
8858 This option marks an executable as a PIC plugin module.
8860 @cindex SPU overlays
8861 @kindex --no-overlays
8863 Normally, @command{ld} recognizes calls to functions within overlay
8864 regions, and redirects such calls to an overlay manager via a stub.
8865 @command{ld} also provides a built-in overlay manager. This option
8866 turns off all this special overlay handling.
8868 @cindex SPU overlay stub symbols
8869 @kindex --emit-stub-syms
8870 @item --emit-stub-syms
8871 This option causes @command{ld} to label overlay stubs with a local
8872 symbol that encodes the stub type and destination.
8874 @cindex SPU extra overlay stubs
8875 @kindex --extra-overlay-stubs
8876 @item --extra-overlay-stubs
8877 This option causes @command{ld} to add overlay call stubs on all
8878 function calls out of overlay regions. Normally stubs are not added
8879 on calls to non-overlay regions.
8881 @cindex SPU local store size
8882 @kindex --local-store=lo:hi
8883 @item --local-store=lo:hi
8884 @command{ld} usually checks that a final executable for SPU fits in
8885 the address range 0 to 256k. This option may be used to change the
8886 range. Disable the check entirely with @option{--local-store=0:0}.
8889 @kindex --stack-analysis
8890 @item --stack-analysis
8891 SPU local store space is limited. Over-allocation of stack space
8892 unnecessarily limits space available for code and data, while
8893 under-allocation results in runtime failures. If given this option,
8894 @command{ld} will provide an estimate of maximum stack usage.
8895 @command{ld} does this by examining symbols in code sections to
8896 determine the extents of functions, and looking at function prologues
8897 for stack adjusting instructions. A call-graph is created by looking
8898 for relocations on branch instructions. The graph is then searched
8899 for the maximum stack usage path. Note that this analysis does not
8900 find calls made via function pointers, and does not handle recursion
8901 and other cycles in the call graph. Stack usage may be
8902 under-estimated if your code makes such calls. Also, stack usage for
8903 dynamic allocation, e.g. alloca, will not be detected. If a link map
8904 is requested, detailed information about each function's stack usage
8905 and calls will be given.
8908 @kindex --emit-stack-syms
8909 @item --emit-stack-syms
8910 This option, if given along with @option{--stack-analysis} will result
8911 in @command{ld} emitting stack sizing symbols for each function.
8912 These take the form @code{__stack_<function_name>} for global
8913 functions, and @code{__stack_<number>_<function_name>} for static
8914 functions. @code{<number>} is the section id in hex. The value of
8915 such symbols is the stack requirement for the corresponding function.
8916 The symbol size will be zero, type @code{STT_NOTYPE}, binding
8917 @code{STB_LOCAL}, and section @code{SHN_ABS}.
8931 @section @command{ld}'s Support for Various TI COFF Versions
8932 @cindex TI COFF versions
8933 @kindex --format=@var{version}
8934 The @samp{--format} switch allows selection of one of the various
8935 TI COFF versions. The latest of this writing is 2; versions 0 and 1 are
8936 also supported. The TI COFF versions also vary in header byte-order
8937 format; @command{ld} will read any version or byte order, but the output
8938 header format depends on the default specified by the specific target.
8951 @section @command{ld} and WIN32 (cygwin/mingw)
8953 This section describes some of the win32 specific @command{ld} issues.
8954 See @ref{Options,,Command-line Options} for detailed description of the
8955 command-line options mentioned here.
8958 @cindex import libraries
8959 @item import libraries
8960 The standard Windows linker creates and uses so-called import
8961 libraries, which contains information for linking to dll's. They are
8962 regular static archives and are handled as any other static
8963 archive. The cygwin and mingw ports of @command{ld} have specific
8964 support for creating such libraries provided with the
8965 @samp{--out-implib} command-line option.
8967 @item Resource only DLLs
8968 It is possible to create a DLL that only contains resources, ie just a
8969 @samp{.rsrc} section, but in order to do so a custom linker script
8970 must be used. This is because the built-in default linker scripts
8971 will always create @samp{.text} and @samp{.idata} sections, even if
8972 there is no input to go into them.
8974 The script should look like this, although the @code{OUTPUT_FORMAT}
8975 should be changed to match the desired format.
8978 OUTPUT_FORMAT(pei-i386)
8982 . = ALIGN(__section_alignment__);
8983 .rsrc __image_base__ + __section_alignment__ : ALIGN(4)
8988 /DISCARD/ : @{ *(*) @}
8992 With this script saved to a file called, eg @file{rsrc.ld}, a command
8993 line like this can be used to create the resource only DLL
8994 @file{rsrc.dll} from an input file called @file{rsrc.o}:
8997 ld -dll --subsystem windows -e 0 -s rsrc.o -o rsrc.dll -T rsrc.ld
9000 @item exporting DLL symbols
9001 @cindex exporting DLL symbols
9002 The cygwin/mingw @command{ld} has several ways to export symbols for dll's.
9005 @item using auto-export functionality
9006 @cindex using auto-export functionality
9007 By default @command{ld} exports symbols with the auto-export functionality,
9008 which is controlled by the following command-line options:
9011 @item --export-all-symbols [This is the default]
9012 @item --exclude-symbols
9013 @item --exclude-libs
9014 @item --exclude-modules-for-implib
9015 @item --version-script
9018 When auto-export is in operation, @command{ld} will export all the non-local
9019 (global and common) symbols it finds in a DLL, with the exception of a few
9020 symbols known to belong to the system's runtime and libraries. As it will
9021 often not be desirable to export all of a DLL's symbols, which may include
9022 private functions that are not part of any public interface, the command-line
9023 options listed above may be used to filter symbols out from the list for
9024 exporting. The @samp{--output-def} option can be used in order to see the
9025 final list of exported symbols with all exclusions taken into effect.
9027 If @samp{--export-all-symbols} is not given explicitly on the
9028 command line, then the default auto-export behavior will be @emph{disabled}
9029 if either of the following are true:
9032 @item A DEF file is used.
9033 @item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
9036 @item using a DEF file
9037 @cindex using a DEF file
9038 Another way of exporting symbols is using a DEF file. A DEF file is
9039 an ASCII file containing definitions of symbols which should be
9040 exported when a dll is created. Usually it is named @samp{<dll
9041 name>.def} and is added as any other object file to the linker's
9042 command line. The file's name must end in @samp{.def} or @samp{.DEF}.
9045 gcc -o <output> <objectfiles> <dll name>.def
9048 Using a DEF file turns off the normal auto-export behavior, unless the
9049 @samp{--export-all-symbols} option is also used.
9051 Here is an example of a DEF file for a shared library called @samp{xyz.dll}:
9054 LIBRARY "xyz.dll" BASE=0x20000000
9060 another_foo = abc.dll.afoo
9066 This example defines a DLL with a non-default base address and seven
9067 symbols in the export table. The third exported symbol @code{_bar} is an
9068 alias for the second. The fourth symbol, @code{another_foo} is resolved
9069 by "forwarding" to another module and treating it as an alias for
9070 @code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
9071 @code{var1} is declared to be a data object. The @samp{doo} symbol in
9072 export library is an alias of @samp{foo}, which gets the string name
9073 in export table @samp{foo2}. The @samp{eoo} symbol is an data export
9074 symbol, which gets in export table the name @samp{var1}.
9076 The optional @code{LIBRARY <name>} command indicates the @emph{internal}
9077 name of the output DLL. If @samp{<name>} does not include a suffix,
9078 the default library suffix, @samp{.DLL} is appended.
9080 When the .DEF file is used to build an application, rather than a
9081 library, the @code{NAME <name>} command should be used instead of
9082 @code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
9083 executable suffix, @samp{.EXE} is appended.
9085 With either @code{LIBRARY <name>} or @code{NAME <name>} the optional
9086 specification @code{BASE = <number>} may be used to specify a
9087 non-default base address for the image.
9089 If neither @code{LIBRARY <name>} nor @code{NAME <name>} is specified,
9090 or they specify an empty string, the internal name is the same as the
9091 filename specified on the command line.
9093 The complete specification of an export symbol is:
9097 ( ( ( <name1> [ = <name2> ] )
9098 | ( <name1> = <module-name> . <external-name>))
9099 [ @@ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] [== <name3>] ) *
9102 Declares @samp{<name1>} as an exported symbol from the DLL, or declares
9103 @samp{<name1>} as an exported alias for @samp{<name2>}; or declares
9104 @samp{<name1>} as a "forward" alias for the symbol
9105 @samp{<external-name>} in the DLL @samp{<module-name>}.
9106 Optionally, the symbol may be exported by the specified ordinal
9107 @samp{<integer>} alias. The optional @samp{<name3>} is the to be used
9108 string in import/export table for the symbol.
9110 The optional keywords that follow the declaration indicate:
9112 @code{NONAME}: Do not put the symbol name in the DLL's export table. It
9113 will still be exported by its ordinal alias (either the value specified
9114 by the .def specification or, otherwise, the value assigned by the
9115 linker). The symbol name, however, does remain visible in the import
9116 library (if any), unless @code{PRIVATE} is also specified.
9118 @code{DATA}: The symbol is a variable or object, rather than a function.
9119 The import lib will export only an indirect reference to @code{foo} as
9120 the symbol @code{_imp__foo} (ie, @code{foo} must be resolved as
9123 @code{CONSTANT}: Like @code{DATA}, but put the undecorated @code{foo} as
9124 well as @code{_imp__foo} into the import library. Both refer to the
9125 read-only import address table's pointer to the variable, not to the
9126 variable itself. This can be dangerous. If the user code fails to add
9127 the @code{dllimport} attribute and also fails to explicitly add the
9128 extra indirection that the use of the attribute enforces, the
9129 application will behave unexpectedly.
9131 @code{PRIVATE}: Put the symbol in the DLL's export table, but do not put
9132 it into the static import library used to resolve imports at link time. The
9133 symbol can still be imported using the @code{LoadLibrary/GetProcAddress}
9134 API at runtime or by using the GNU ld extension of linking directly to
9135 the DLL without an import library.
9137 See ld/deffilep.y in the binutils sources for the full specification of
9138 other DEF file statements
9140 @cindex creating a DEF file
9141 While linking a shared dll, @command{ld} is able to create a DEF file
9142 with the @samp{--output-def <file>} command-line option.
9144 @item Using decorations
9145 @cindex Using decorations
9146 Another way of marking symbols for export is to modify the source code
9147 itself, so that when building the DLL each symbol to be exported is
9151 __declspec(dllexport) int a_variable
9152 __declspec(dllexport) void a_function(int with_args)
9155 All such symbols will be exported from the DLL. If, however,
9156 any of the object files in the DLL contain symbols decorated in
9157 this way, then the normal auto-export behavior is disabled, unless
9158 the @samp{--export-all-symbols} option is also used.
9160 Note that object files that wish to access these symbols must @emph{not}
9161 decorate them with dllexport. Instead, they should use dllimport,
9165 __declspec(dllimport) int a_variable
9166 __declspec(dllimport) void a_function(int with_args)
9169 This complicates the structure of library header files, because
9170 when included by the library itself the header must declare the
9171 variables and functions as dllexport, but when included by client
9172 code the header must declare them as dllimport. There are a number
9173 of idioms that are typically used to do this; often client code can
9174 omit the __declspec() declaration completely. See
9175 @samp{--enable-auto-import} and @samp{automatic data imports} for more
9179 @cindex automatic data imports
9180 @item automatic data imports
9181 The standard Windows dll format supports data imports from dlls only
9182 by adding special decorations (dllimport/dllexport), which let the
9183 compiler produce specific assembler instructions to deal with this
9184 issue. This increases the effort necessary to port existing Un*x
9185 code to these platforms, especially for large
9186 c++ libraries and applications. The auto-import feature, which was
9187 initially provided by Paul Sokolovsky, allows one to omit the
9188 decorations to achieve a behavior that conforms to that on POSIX/Un*x
9189 platforms. This feature is enabled with the @samp{--enable-auto-import}
9190 command-line option, although it is enabled by default on cygwin/mingw.
9191 The @samp{--enable-auto-import} option itself now serves mainly to
9192 suppress any warnings that are ordinarily emitted when linked objects
9193 trigger the feature's use.
9195 auto-import of variables does not always work flawlessly without
9196 additional assistance. Sometimes, you will see this message
9198 "variable '<var>' can't be auto-imported. Please read the
9199 documentation for ld's @code{--enable-auto-import} for details."
9201 The @samp{--enable-auto-import} documentation explains why this error
9202 occurs, and several methods that can be used to overcome this difficulty.
9203 One of these methods is the @emph{runtime pseudo-relocs} feature, described
9206 @cindex runtime pseudo-relocation
9207 For complex variables imported from DLLs (such as structs or classes),
9208 object files typically contain a base address for the variable and an
9209 offset (@emph{addend}) within the variable--to specify a particular
9210 field or public member, for instance. Unfortunately, the runtime loader used
9211 in win32 environments is incapable of fixing these references at runtime
9212 without the additional information supplied by dllimport/dllexport decorations.
9213 The standard auto-import feature described above is unable to resolve these
9216 The @samp{--enable-runtime-pseudo-relocs} switch allows these references to
9217 be resolved without error, while leaving the task of adjusting the references
9218 themselves (with their non-zero addends) to specialized code provided by the
9219 runtime environment. Recent versions of the cygwin and mingw environments and
9220 compilers provide this runtime support; older versions do not. However, the
9221 support is only necessary on the developer's platform; the compiled result will
9222 run without error on an older system.
9224 @samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
9227 @cindex direct linking to a dll
9228 @item direct linking to a dll
9229 The cygwin/mingw ports of @command{ld} support the direct linking,
9230 including data symbols, to a dll without the usage of any import
9231 libraries. This is much faster and uses much less memory than does the
9232 traditional import library method, especially when linking large
9233 libraries or applications. When @command{ld} creates an import lib, each
9234 function or variable exported from the dll is stored in its own bfd, even
9235 though a single bfd could contain many exports. The overhead involved in
9236 storing, loading, and processing so many bfd's is quite large, and explains the
9237 tremendous time, memory, and storage needed to link against particularly
9238 large or complex libraries when using import libs.
9240 Linking directly to a dll uses no extra command-line switches other than
9241 @samp{-L} and @samp{-l}, because @command{ld} already searches for a number
9242 of names to match each library. All that is needed from the developer's
9243 perspective is an understanding of this search, in order to force ld to
9244 select the dll instead of an import library.
9247 For instance, when ld is called with the argument @samp{-lxxx} it will attempt
9248 to find, in the first directory of its search path,
9261 before moving on to the next directory in the search path.
9263 (*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
9264 where @samp{<prefix>} is set by the @command{ld} option
9265 @samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
9266 file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
9269 Other win32-based unix environments, such as mingw or pw32, may use other
9270 @samp{<prefix>}es, although at present only cygwin makes use of this feature. It
9271 was originally intended to help avoid name conflicts among dll's built for the
9272 various win32/un*x environments, so that (for example) two versions of a zlib dll
9273 could coexist on the same machine.
9275 The generic cygwin/mingw path layout uses a @samp{bin} directory for
9276 applications and dll's and a @samp{lib} directory for the import
9277 libraries (using cygwin nomenclature):
9283 libxxx.dll.a (in case of dll's)
9284 libxxx.a (in case of static archive)
9287 Linking directly to a dll without using the import library can be
9290 1. Use the dll directly by adding the @samp{bin} path to the link line
9292 gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx
9295 However, as the dll's often have version numbers appended to their names
9296 (@samp{cygncurses-5.dll}) this will often fail, unless one specifies
9297 @samp{-L../bin -lncurses-5} to include the version. Import libs are generally
9298 not versioned, and do not have this difficulty.
9300 2. Create a symbolic link from the dll to a file in the @samp{lib}
9301 directory according to the above mentioned search pattern. This
9302 should be used to avoid unwanted changes in the tools needed for
9306 ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
9309 Then you can link without any make environment changes.
9312 gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx
9315 This technique also avoids the version number problems, because the following is
9322 libxxx.dll.a -> ../bin/cygxxx-5.dll
9325 Linking directly to a dll without using an import lib will work
9326 even when auto-import features are exercised, and even when
9327 @samp{--enable-runtime-pseudo-relocs} is used.
9329 Given the improvements in speed and memory usage, one might justifiably
9330 wonder why import libraries are used at all. There are three reasons:
9332 1. Until recently, the link-directly-to-dll functionality did @emph{not}
9333 work with auto-imported data.
9335 2. Sometimes it is necessary to include pure static objects within the
9336 import library (which otherwise contains only bfd's for indirection
9337 symbols that point to the exports of a dll). Again, the import lib
9338 for the cygwin kernel makes use of this ability, and it is not
9339 possible to do this without an import lib.
9341 3. Symbol aliases can only be resolved using an import lib. This is
9342 critical when linking against OS-supplied dll's (eg, the win32 API)
9343 in which symbols are usually exported as undecorated aliases of their
9344 stdcall-decorated assembly names.
9346 So, import libs are not going away. But the ability to replace
9347 true import libs with a simple symbolic link to (or a copy of)
9348 a dll, in many cases, is a useful addition to the suite of tools
9349 binutils makes available to the win32 developer. Given the
9350 massive improvements in memory requirements during linking, storage
9351 requirements, and linking speed, we expect that many developers
9352 will soon begin to use this feature whenever possible.
9354 @item symbol aliasing
9356 @item adding additional names
9357 Sometimes, it is useful to export symbols with additional names.
9358 A symbol @samp{foo} will be exported as @samp{foo}, but it can also be
9359 exported as @samp{_foo} by using special directives in the DEF file
9360 when creating the dll. This will affect also the optional created
9361 import library. Consider the following DEF file:
9364 LIBRARY "xyz.dll" BASE=0x61000000
9371 The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
9373 Another method for creating a symbol alias is to create it in the
9374 source code using the "weak" attribute:
9377 void foo () @{ /* Do something. */; @}
9378 void _foo () __attribute__ ((weak, alias ("foo")));
9381 See the gcc manual for more information about attributes and weak
9384 @item renaming symbols
9385 Sometimes it is useful to rename exports. For instance, the cygwin
9386 kernel does this regularly. A symbol @samp{_foo} can be exported as
9387 @samp{foo} but not as @samp{_foo} by using special directives in the
9388 DEF file. (This will also affect the import library, if it is
9389 created). In the following example:
9392 LIBRARY "xyz.dll" BASE=0x61000000
9398 The line @samp{_foo = foo} maps the exported symbol @samp{foo} to
9402 Note: using a DEF file disables the default auto-export behavior,
9403 unless the @samp{--export-all-symbols} command-line option is used.
9404 If, however, you are trying to rename symbols, then you should list
9405 @emph{all} desired exports in the DEF file, including the symbols
9406 that are not being renamed, and do @emph{not} use the
9407 @samp{--export-all-symbols} option. If you list only the
9408 renamed symbols in the DEF file, and use @samp{--export-all-symbols}
9409 to handle the other symbols, then the both the new names @emph{and}
9410 the original names for the renamed symbols will be exported.
9411 In effect, you'd be aliasing those symbols, not renaming them,
9412 which is probably not what you wanted.
9414 @cindex weak externals
9415 @item weak externals
9416 The Windows object format, PE, specifies a form of weak symbols called
9417 weak externals. When a weak symbol is linked and the symbol is not
9418 defined, the weak symbol becomes an alias for some other symbol. There
9419 are three variants of weak externals:
9421 @item Definition is searched for in objects and libraries, historically
9422 called lazy externals.
9423 @item Definition is searched for only in other objects, not in libraries.
9424 This form is not presently implemented.
9425 @item No search; the symbol is an alias. This form is not presently
9428 As a GNU extension, weak symbols that do not specify an alternate symbol
9429 are supported. If the symbol is undefined when linking, the symbol
9430 uses a default value.
9432 @cindex aligned common symbols
9433 @item aligned common symbols
9434 As a GNU extension to the PE file format, it is possible to specify the
9435 desired alignment for a common symbol. This information is conveyed from
9436 the assembler or compiler to the linker by means of GNU-specific commands
9437 carried in the object file's @samp{.drectve} section, which are recognized
9438 by @command{ld} and respected when laying out the common symbols. Native
9439 tools will be able to process object files employing this GNU extension,
9440 but will fail to respect the alignment instructions, and may issue noisy
9441 warnings about unknown linker directives.
9456 @section @code{ld} and Xtensa Processors
9458 @cindex Xtensa processors
9459 The default @command{ld} behavior for Xtensa processors is to interpret
9460 @code{SECTIONS} commands so that lists of explicitly named sections in a
9461 specification with a wildcard file will be interleaved when necessary to
9462 keep literal pools within the range of PC-relative load offsets. For
9463 example, with the command:
9475 @command{ld} may interleave some of the @code{.literal}
9476 and @code{.text} sections from different object files to ensure that the
9477 literal pools are within the range of PC-relative load offsets. A valid
9478 interleaving might place the @code{.literal} sections from an initial
9479 group of files followed by the @code{.text} sections of that group of
9480 files. Then, the @code{.literal} sections from the rest of the files
9481 and the @code{.text} sections from the rest of the files would follow.
9483 @cindex @option{--relax} on Xtensa
9484 @cindex relaxing on Xtensa
9485 Relaxation is enabled by default for the Xtensa version of @command{ld} and
9486 provides two important link-time optimizations. The first optimization
9487 is to combine identical literal values to reduce code size. A redundant
9488 literal will be removed and all the @code{L32R} instructions that use it
9489 will be changed to reference an identical literal, as long as the
9490 location of the replacement literal is within the offset range of all
9491 the @code{L32R} instructions. The second optimization is to remove
9492 unnecessary overhead from assembler-generated ``longcall'' sequences of
9493 @code{L32R}/@code{CALLX@var{n}} when the target functions are within
9494 range of direct @code{CALL@var{n}} instructions.
9496 For each of these cases where an indirect call sequence can be optimized
9497 to a direct call, the linker will change the @code{CALLX@var{n}}
9498 instruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
9499 instruction, and remove the literal referenced by the @code{L32R}
9500 instruction if it is not used for anything else. Removing the
9501 @code{L32R} instruction always reduces code size but can potentially
9502 hurt performance by changing the alignment of subsequent branch targets.
9503 By default, the linker will always preserve alignments, either by
9504 switching some instructions between 24-bit encodings and the equivalent
9505 density instructions or by inserting a no-op in place of the @code{L32R}
9506 instruction that was removed. If code size is more important than
9507 performance, the @option{--size-opt} option can be used to prevent the
9508 linker from widening density instructions or inserting no-ops, except in
9509 a few cases where no-ops are required for correctness.
9511 The following Xtensa-specific command-line options can be used to
9514 @cindex Xtensa options
9517 When optimizing indirect calls to direct calls, optimize for code size
9518 more than performance. With this option, the linker will not insert
9519 no-ops or widen density instructions to preserve branch target
9520 alignment. There may still be some cases where no-ops are required to
9521 preserve the correctness of the code.
9523 @item --abi-windowed
9525 Choose ABI for the output object and for the generated PLT code.
9526 PLT code inserted by the linker must match ABI of the output object
9527 because windowed and call0 ABI use incompatible function call
9529 Default ABI is chosen by the ABI tag in the @code{.xtensa.info} section
9530 of the first input object.
9531 A warning is issued if ABI tags of input objects do not match each other
9532 or the chosen output object ABI.
9540 @ifclear SingleFormat
9545 @cindex object file management
9546 @cindex object formats available
9548 The linker accesses object and archive files using the BFD libraries.
9549 These libraries allow the linker to use the same routines to operate on
9550 object files whatever the object file format. A different object file
9551 format can be supported simply by creating a new BFD back end and adding
9552 it to the library. To conserve runtime memory, however, the linker and
9553 associated tools are usually configured to support only a subset of the
9554 object file formats available. You can use @code{objdump -i}
9555 (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
9556 list all the formats available for your configuration.
9558 @cindex BFD requirements
9559 @cindex requirements for BFD
9560 As with most implementations, BFD is a compromise between
9561 several conflicting requirements. The major factor influencing
9562 BFD design was efficiency: any time used converting between
9563 formats is time which would not have been spent had BFD not
9564 been involved. This is partly offset by abstraction payback; since
9565 BFD simplifies applications and back ends, more time and care
9566 may be spent optimizing algorithms for a greater speed.
9568 One minor artifact of the BFD solution which you should bear in
9569 mind is the potential for information loss. There are two places where
9570 useful information can be lost using the BFD mechanism: during
9571 conversion and during output. @xref{BFD information loss}.
9574 * BFD outline:: How it works: an outline of BFD
9578 @section How It Works: An Outline of BFD
9579 @cindex opening object files
9580 @include bfdsumm.texi
9583 @node Reporting Bugs
9584 @chapter Reporting Bugs
9585 @cindex bugs in @command{ld}
9586 @cindex reporting bugs in @command{ld}
9588 Your bug reports play an essential role in making @command{ld} reliable.
9590 Reporting a bug may help you by bringing a solution to your problem, or
9591 it may not. But in any case the principal function of a bug report is
9592 to help the entire community by making the next version of @command{ld}
9593 work better. Bug reports are your contribution to the maintenance of
9596 In order for a bug report to serve its purpose, you must include the
9597 information that enables us to fix the bug.
9600 * Bug Criteria:: Have you found a bug?
9601 * Bug Reporting:: How to report bugs
9605 @section Have You Found a Bug?
9606 @cindex bug criteria
9608 If you are not sure whether you have found a bug, here are some guidelines:
9611 @cindex fatal signal
9612 @cindex linker crash
9613 @cindex crash of linker
9615 If the linker gets a fatal signal, for any input whatever, that is a
9616 @command{ld} bug. Reliable linkers never crash.
9618 @cindex error on valid input
9620 If @command{ld} produces an error message for valid input, that is a bug.
9622 @cindex invalid input
9624 If @command{ld} does not produce an error message for invalid input, that
9625 may be a bug. In the general case, the linker can not verify that
9626 object files are correct.
9629 If you are an experienced user of linkers, your suggestions for
9630 improvement of @command{ld} are welcome in any case.
9634 @section How to Report Bugs
9636 @cindex @command{ld} bugs, reporting
9638 A number of companies and individuals offer support for @sc{gnu}
9639 products. If you obtained @command{ld} from a support organization, we
9640 recommend you contact that organization first.
9642 You can find contact information for many support companies and
9643 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
9647 Otherwise, send bug reports for @command{ld} to
9651 The fundamental principle of reporting bugs usefully is this:
9652 @strong{report all the facts}. If you are not sure whether to state a
9653 fact or leave it out, state it!
9655 Often people omit facts because they think they know what causes the
9656 problem and assume that some details do not matter. Thus, you might
9657 assume that the name of a symbol you use in an example does not
9658 matter. Well, probably it does not, but one cannot be sure. Perhaps
9659 the bug is a stray memory reference which happens to fetch from the
9660 location where that name is stored in memory; perhaps, if the name
9661 were different, the contents of that location would fool the linker
9662 into doing the right thing despite the bug. Play it safe and give a
9663 specific, complete example. That is the easiest thing for you to do,
9664 and the most helpful.
9666 Keep in mind that the purpose of a bug report is to enable us to fix
9667 the bug if it is new to us. Therefore, always write your bug reports
9668 on the assumption that the bug has not been reported previously.
9670 Sometimes people give a few sketchy facts and ask, ``Does this ring a
9671 bell?'' This cannot help us fix a bug, so it is basically useless. We
9672 respond by asking for enough details to enable us to investigate.
9673 You might as well expedite matters by sending them to begin with.
9675 To enable us to fix the bug, you should include all these things:
9679 The version of @command{ld}. @command{ld} announces it if you start it with
9680 the @samp{--version} argument.
9682 Without this, we will not know whether there is any point in looking for
9683 the bug in the current version of @command{ld}.
9686 Any patches you may have applied to the @command{ld} source, including any
9687 patches made to the @code{BFD} library.
9690 The type of machine you are using, and the operating system name and
9694 What compiler (and its version) was used to compile @command{ld}---e.g.
9698 The command arguments you gave the linker to link your example and
9699 observe the bug. To guarantee you will not omit something important,
9700 list them all. A copy of the Makefile (or the output from make) is
9703 If we were to try to guess the arguments, we would probably guess wrong
9704 and then we might not encounter the bug.
9707 A complete input file, or set of input files, that will reproduce the
9708 bug. It is generally most helpful to send the actual object files
9709 provided that they are reasonably small. Say no more than 10K. For
9710 bigger files you can either make them available by FTP or HTTP or else
9711 state that you are willing to send the object file(s) to whomever
9712 requests them. (Note - your email will be going to a mailing list, so
9713 we do not want to clog it up with large attachments). But small
9714 attachments are best.
9716 If the source files were assembled using @code{gas} or compiled using
9717 @code{gcc}, then it may be OK to send the source files rather than the
9718 object files. In this case, be sure to say exactly what version of
9719 @code{gas} or @code{gcc} was used to produce the object files. Also say
9720 how @code{gas} or @code{gcc} were configured.
9723 A description of what behavior you observe that you believe is
9724 incorrect. For example, ``It gets a fatal signal.''
9726 Of course, if the bug is that @command{ld} gets a fatal signal, then we
9727 will certainly notice it. But if the bug is incorrect output, we might
9728 not notice unless it is glaringly wrong. You might as well not give us
9729 a chance to make a mistake.
9731 Even if the problem you experience is a fatal signal, you should still
9732 say so explicitly. Suppose something strange is going on, such as, your
9733 copy of @command{ld} is out of sync, or you have encountered a bug in the
9734 C library on your system. (This has happened!) Your copy might crash
9735 and ours would not. If you told us to expect a crash, then when ours
9736 fails to crash, we would know that the bug was not happening for us. If
9737 you had not told us to expect a crash, then we would not be able to draw
9738 any conclusion from our observations.
9741 If you wish to suggest changes to the @command{ld} source, send us context
9742 diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
9743 @samp{-p} option. Always send diffs from the old file to the new file.
9744 If you even discuss something in the @command{ld} source, refer to it by
9745 context, not by line number.
9747 The line numbers in our development sources will not match those in your
9748 sources. Your line numbers would convey no useful information to us.
9751 Here are some things that are not necessary:
9755 A description of the envelope of the bug.
9757 Often people who encounter a bug spend a lot of time investigating
9758 which changes to the input file will make the bug go away and which
9759 changes will not affect it.
9761 This is often time consuming and not very useful, because the way we
9762 will find the bug is by running a single example under the debugger
9763 with breakpoints, not by pure deduction from a series of examples.
9764 We recommend that you save your time for something else.
9766 Of course, if you can find a simpler example to report @emph{instead}
9767 of the original one, that is a convenience for us. Errors in the
9768 output will be easier to spot, running under the debugger will take
9769 less time, and so on.
9771 However, simplification is not vital; if you do not want to do this,
9772 report the bug anyway and send us the entire test case you used.
9775 A patch for the bug.
9777 A patch for the bug does help us if it is a good one. But do not omit
9778 the necessary information, such as the test case, on the assumption that
9779 a patch is all we need. We might see problems with your patch and decide
9780 to fix the problem another way, or we might not understand it at all.
9782 Sometimes with a program as complicated as @command{ld} it is very hard to
9783 construct an example that will make the program follow a certain path
9784 through the code. If you do not send us the example, we will not be
9785 able to construct one, so we will not be able to verify that the bug is
9788 And if we cannot understand what bug you are trying to fix, or why your
9789 patch should be an improvement, we will not install it. A test case will
9790 help us to understand.
9793 A guess about what the bug is or what it depends on.
9795 Such guesses are usually wrong. Even we cannot guess right about such
9796 things without first using the debugger to find the facts.
9800 @appendix MRI Compatible Script Files
9801 @cindex MRI compatibility
9802 To aid users making the transition to @sc{gnu} @command{ld} from the MRI
9803 linker, @command{ld} can use MRI compatible linker scripts as an
9804 alternative to the more general-purpose linker scripting language
9805 described in @ref{Scripts}. MRI compatible linker scripts have a much
9806 simpler command set than the scripting language otherwise used with
9807 @command{ld}. @sc{gnu} @command{ld} supports the most commonly used MRI
9808 linker commands; these commands are described here.
9810 In general, MRI scripts aren't of much use with the @code{a.out} object
9811 file format, since it only has three sections and MRI scripts lack some
9812 features to make use of them.
9814 You can specify a file containing an MRI-compatible script using the
9815 @samp{-c} command-line option.
9817 Each command in an MRI-compatible script occupies its own line; each
9818 command line starts with the keyword that identifies the command (though
9819 blank lines are also allowed for punctuation). If a line of an
9820 MRI-compatible script begins with an unrecognized keyword, @command{ld}
9821 issues a warning message, but continues processing the script.
9823 Lines beginning with @samp{*} are comments.
9825 You can write these commands using all upper-case letters, or all
9826 lower case; for example, @samp{chip} is the same as @samp{CHIP}.
9827 The following list shows only the upper-case form of each command.
9830 @cindex @code{ABSOLUTE} (MRI)
9831 @item ABSOLUTE @var{secname}
9832 @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
9833 Normally, @command{ld} includes in the output file all sections from all
9834 the input files. However, in an MRI-compatible script, you can use the
9835 @code{ABSOLUTE} command to restrict the sections that will be present in
9836 your output program. If the @code{ABSOLUTE} command is used at all in a
9837 script, then only the sections named explicitly in @code{ABSOLUTE}
9838 commands will appear in the linker output. You can still use other
9839 input sections (whatever you select on the command line, or using
9840 @code{LOAD}) to resolve addresses in the output file.
9842 @cindex @code{ALIAS} (MRI)
9843 @item ALIAS @var{out-secname}, @var{in-secname}
9844 Use this command to place the data from input section @var{in-secname}
9845 in a section called @var{out-secname} in the linker output file.
9847 @var{in-secname} may be an integer.
9849 @cindex @code{ALIGN} (MRI)
9850 @item ALIGN @var{secname} = @var{expression}
9851 Align the section called @var{secname} to @var{expression}. The
9852 @var{expression} should be a power of two.
9854 @cindex @code{BASE} (MRI)
9855 @item BASE @var{expression}
9856 Use the value of @var{expression} as the lowest address (other than
9857 absolute addresses) in the output file.
9859 @cindex @code{CHIP} (MRI)
9860 @item CHIP @var{expression}
9861 @itemx CHIP @var{expression}, @var{expression}
9862 This command does nothing; it is accepted only for compatibility.
9864 @cindex @code{END} (MRI)
9866 This command does nothing whatever; it's only accepted for compatibility.
9868 @cindex @code{FORMAT} (MRI)
9869 @item FORMAT @var{output-format}
9870 Similar to the @code{OUTPUT_FORMAT} command in the more general linker
9871 language, but restricted to S-records, if @var{output-format} is @samp{S}
9873 @cindex @code{LIST} (MRI)
9874 @item LIST @var{anything}@dots{}
9875 Print (to the standard output file) a link map, as produced by the
9876 @command{ld} command-line option @samp{-M}.
9878 The keyword @code{LIST} may be followed by anything on the
9879 same line, with no change in its effect.
9881 @cindex @code{LOAD} (MRI)
9882 @item LOAD @var{filename}
9883 @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
9884 Include one or more object file @var{filename} in the link; this has the
9885 same effect as specifying @var{filename} directly on the @command{ld}
9888 @cindex @code{NAME} (MRI)
9889 @item NAME @var{output-name}
9890 @var{output-name} is the name for the program produced by @command{ld}; the
9891 MRI-compatible command @code{NAME} is equivalent to the command-line
9892 option @samp{-o} or the general script language command @code{OUTPUT}.
9894 @cindex @code{ORDER} (MRI)
9895 @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
9896 @itemx ORDER @var{secname} @var{secname} @var{secname}
9897 Normally, @command{ld} orders the sections in its output file in the
9898 order in which they first appear in the input files. In an MRI-compatible
9899 script, you can override this ordering with the @code{ORDER} command. The
9900 sections you list with @code{ORDER} will appear first in your output
9901 file, in the order specified.
9903 @cindex @code{PUBLIC} (MRI)
9904 @item PUBLIC @var{name}=@var{expression}
9905 @itemx PUBLIC @var{name},@var{expression}
9906 @itemx PUBLIC @var{name} @var{expression}
9907 Supply a value (@var{expression}) for external symbol
9908 @var{name} used in the linker input files.
9910 @cindex @code{SECT} (MRI)
9911 @item SECT @var{secname}, @var{expression}
9912 @itemx SECT @var{secname}=@var{expression}
9913 @itemx SECT @var{secname} @var{expression}
9914 You can use any of these three forms of the @code{SECT} command to
9915 specify the start address (@var{expression}) for section @var{secname}.
9916 If you have more than one @code{SECT} statement for the same
9917 @var{secname}, only the @emph{first} sets the start address.
9920 @node GNU Free Documentation License
9921 @appendix GNU Free Documentation License
9925 @unnumbered LD Index
9930 % I think something like @@colophon should be in texinfo. In the
9932 \long\def\colophon{\hbox to0pt{}\vfill
9933 \centerline{The body of this manual is set in}
9934 \centerline{\fontname\tenrm,}
9935 \centerline{with headings in {\bf\fontname\tenbf}}
9936 \centerline{and examples in {\tt\fontname\tentt}.}
9937 \centerline{{\it\fontname\tenit\/} and}
9938 \centerline{{\sl\fontname\tensl\/}}
9939 \centerline{are used for emphasis.}\vfill}
9941 % Blame: doc@@cygnus.com, 28mar91.