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
46 @dircategory Software development
48 * Ld: (ld). The GNU linker.
53 This file documents the @sc{gnu} linker LD
54 @ifset VERSION_PACKAGE
55 @value{VERSION_PACKAGE}
57 version @value{VERSION}.
59 Copyright @copyright{} 1991-2024 Free Software Foundation, Inc.
61 Permission is granted to copy, distribute and/or modify this document
62 under the terms of the GNU Free Documentation License, Version 1.3
63 or any later version published by the Free Software Foundation;
64 with no Invariant Sections, with no Front-Cover Texts, and with no
65 Back-Cover Texts. A copy of the license is included in the
66 section entitled ``GNU Free Documentation License''.
70 @setchapternewpage odd
71 @settitle The GNU linker
76 @ifset VERSION_PACKAGE
77 @subtitle @value{VERSION_PACKAGE}
79 @subtitle Version @value{VERSION}
80 @author Steve Chamberlain
81 @author Ian Lance Taylor
86 \hfill Red Hat Inc\par
87 \hfill nickc\@redhat.com, doc\@redhat.com\par
88 \hfill {\it The GNU linker}\par
89 \hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
91 \global\parindent=0pt % Steve likes it this way.
94 @vskip 0pt plus 1filll
95 @c man begin COPYRIGHT
96 Copyright @copyright{} 1991-2024 Free Software Foundation, Inc.
98 Permission is granted to copy, distribute and/or modify this document
99 under the terms of the GNU Free Documentation License, Version 1.3
100 or any later version published by the Free Software Foundation;
101 with no Invariant Sections, with no Front-Cover Texts, and with no
102 Back-Cover Texts. A copy of the license is included in the
103 section entitled ``GNU Free Documentation License''.
109 @c FIXME: Talk about importance of *order* of args, cmds to linker!
114 This file documents the @sc{gnu} linker ld
115 @ifset VERSION_PACKAGE
116 @value{VERSION_PACKAGE}
118 version @value{VERSION}.
120 This document is distributed under the terms of the GNU Free
121 Documentation License version 1.3. A copy of the license is included
122 in the section entitled ``GNU Free Documentation License''.
125 * Overview:: Overview
126 * Invocation:: Invocation
127 * Scripts:: Linker Scripts
128 * Plugins:: Linker Plugins
129 * Special Sections:: Special Sections
131 * Machine Dependent:: Machine Dependent Features
135 * H8/300:: ld and the H8/300
138 * Renesas:: ld and other Renesas micros
141 * ARM:: ld and the ARM family
144 * M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families
147 * HPPA ELF32:: ld and HPPA 32-bit ELF
150 * M68K:: ld and Motorola 68K family
153 * MIPS:: ld and MIPS family
156 * PowerPC ELF32:: ld and PowerPC 32-bit ELF Support
159 * PowerPC64 ELF64:: ld and PowerPC64 64-bit ELF Support
162 * S/390 ELF:: ld and S/390 ELF Support
165 * SPU ELF:: ld and SPU ELF Support
168 * TI COFF:: ld and the TI COFF
171 * Win32:: ld and WIN32 (cygwin/mingw)
174 * Xtensa:: ld and Xtensa Processors
177 @ifclear SingleFormat
180 @c Following blank line required for remaining bug in makeinfo conds/menus
182 * Reporting Bugs:: Reporting Bugs
183 * MRI:: MRI Compatible Script Files
184 * GNU Free Documentation License:: GNU Free Documentation License
185 * LD Index:: LD Index
192 @cindex @sc{gnu} linker
193 @cindex what is this?
196 @c man begin SYNOPSIS
197 ld [@b{options}] @var{objfile} @dots{}
201 ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
202 the Info entries for @file{binutils} and
207 @c man begin DESCRIPTION
209 @command{ld} combines a number of object and archive files, relocates
210 their data and ties up symbol references. Usually the last step in
211 compiling a program is to run @command{ld}.
213 @command{ld} accepts Linker Command Language files written in
214 a superset of AT&T's Link Editor Command Language syntax,
215 to provide explicit and total control over the linking process.
219 This man page does not describe the command language; see the
220 @command{ld} entry in @code{info} for full details on the command
221 language and on other aspects of the GNU linker.
224 @ifclear SingleFormat
225 This version of @command{ld} uses the general purpose BFD libraries
226 to operate on object files. This allows @command{ld} to read, combine, and
227 write object files in many different formats---for example, COFF or
228 @code{a.out}. Different formats may be linked together to produce any
229 available kind of object file. @xref{BFD}, for more information.
232 Aside from its flexibility, the @sc{gnu} linker is more helpful than other
233 linkers in providing diagnostic information. Many linkers abandon
234 execution immediately upon encountering an error; whenever possible,
235 @command{ld} continues executing, allowing you to identify other errors
236 (or, in some cases, to get an output file in spite of the error).
243 @c man begin DESCRIPTION
245 The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
246 and to be as compatible as possible with other linkers. As a result,
247 you have many choices to control its behavior.
253 * Options:: Command-line Options
254 * Environment:: Environment Variables
258 @section Command-line Options
266 The linker supports a plethora of command-line options, but in actual
267 practice few of them are used in any particular context.
268 @cindex standard Unix system
269 For instance, a frequent use of @command{ld} is to link standard Unix
270 object files on a standard, supported Unix system. On such a system, to
271 link a file @code{hello.o}:
274 ld -o @var{output} /lib/crt0.o hello.o -lc
277 This tells @command{ld} to produce a file called @var{output} as the
278 result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
279 the library @code{libc.a}, which will come from the standard search
280 directories. (See the discussion of the @samp{-l} option below.)
282 Some of the command-line options to @command{ld} may be specified at any
283 point in the command line. However, options which refer to files, such
284 as @samp{-l} or @samp{-T}, cause the file to be read at the point at
285 which the option appears in the command line, relative to the object
286 files and other file options. Repeating non-file options with a
287 different argument will either have no further effect, or override prior
288 occurrences (those further to the left on the command line) of that
289 option. Options which may be meaningfully specified more than once are
290 noted in the descriptions below.
293 Non-option arguments are object files or archives which are to be linked
294 together. They may follow, precede, or be mixed in with command-line
295 options, except that an object file argument may not be placed between
296 an option and its argument.
298 Usually the linker is invoked with at least one object file, but you can
299 specify other forms of binary input files using @samp{-l}, @samp{-R},
300 and the script command language. If @emph{no} binary input files at all
301 are specified, the linker does not produce any output, and issues the
302 message @samp{No input files}.
304 @anchor{unrecognised-input-files}
305 If the linker cannot recognize the format of an object file, it will
306 assume that it is a linker script. A script specified in this way
307 augments the main linker script used for the link (either the default
308 linker script or the one specified by using @samp{-T}). This feature
309 permits the linker to link against a file which appears to be an object
310 or an archive, but actually merely defines some symbol values, or uses
311 @code{INPUT} or @code{GROUP} to load other objects. Specifying a
312 script in this way merely augments the main linker script, with the
313 extra commands placed after the main script; use the @samp{-T} option
314 to replace the default linker script entirely, but note the effect of
315 the @code{INSERT} command. @xref{Scripts}.
317 For options whose names are a single letter,
318 option arguments must either follow the option letter without intervening
319 whitespace, or be given as separate arguments immediately following the
320 option that requires them.
322 For options whose names are multiple letters, either one dash or two can
323 precede the option name; for example, @samp{-trace-symbol} and
324 @samp{--trace-symbol} are equivalent. Note---there is one exception to
325 this rule. Multiple letter options that start with a lower case 'o' can
326 only be preceded by two dashes. This is to reduce confusion with the
327 @samp{-o} option. So for example @samp{-omagic} sets the output file
328 name to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the
331 Arguments to multiple-letter options must either be separated from the
332 option name by an equals sign, or be given as separate arguments
333 immediately following the option that requires them. For example,
334 @samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent.
335 Unique abbreviations of the names of multiple-letter options are
338 Note---if the linker is being invoked indirectly, via a compiler driver
339 (e.g. @samp{gcc}) then all the linker command-line options should be
340 prefixed by @samp{-Wl,} (or whatever is appropriate for the particular
341 compiler driver) like this:
344 gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
347 This is important, because otherwise the compiler driver program may
348 silently drop the linker options, resulting in a bad link. Confusion
349 may also arise when passing options that require values through a
350 driver, as the use of a space between option and argument acts as
351 a separator, and causes the driver to pass only the option to the linker
352 and the argument to the compiler. In this case, it is simplest to use
353 the joined forms of both single- and multiple-letter options, such as:
356 gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
359 Here is a table of the generic command-line switches accepted by the GNU
363 @include at-file.texi
365 @kindex -a @var{keyword}
366 @item -a @var{keyword}
367 This option is supported for HP/UX compatibility. The @var{keyword}
368 argument must be one of the strings @samp{archive}, @samp{shared}, or
369 @samp{default}. @samp{-aarchive} is functionally equivalent to
370 @samp{-Bstatic}, and the other two keywords are functionally equivalent
371 to @samp{-Bdynamic}. This option may be used any number of times.
373 @kindex --audit @var{AUDITLIB}
374 @item --audit @var{AUDITLIB}
375 Adds @var{AUDITLIB} to the @code{DT_AUDIT} entry of the dynamic section.
376 @var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
377 specified in the library. If specified multiple times @code{DT_AUDIT}
378 will contain a colon separated list of audit interfaces to use. If the linker
379 finds an object with an audit entry while searching for shared libraries,
380 it will add a corresponding @code{DT_DEPAUDIT} entry in the output file.
381 This option is only meaningful on ELF platforms supporting the rtld-audit
384 @ifclear SingleFormat
385 @cindex binary input format
386 @kindex -b @var{format}
387 @kindex --format=@var{format}
390 @item -b @var{input-format}
391 @itemx --format=@var{input-format}
392 @command{ld} may be configured to support more than one kind of object
393 file. If your @command{ld} is configured this way, you can use the
394 @samp{-b} option to specify the binary format for input object files
395 that follow this option on the command line. Even when @command{ld} is
396 configured to support alternative object formats, you don't usually need
397 to specify this, as @command{ld} should be configured to expect as a
398 default input format the most usual format on each machine.
399 @var{input-format} is a text string, the name of a particular format
400 supported by the BFD libraries. (You can list the available binary
401 formats with @samp{objdump -i}.)
404 You may want to use this option if you are linking files with an unusual
405 binary format. You can also use @samp{-b} to switch formats explicitly (when
406 linking object files of different formats), by including
407 @samp{-b @var{input-format}} before each group of object files in a
410 The default format is taken from the environment variable
415 You can also define the input format from a script, using the command
418 see @ref{Format Commands}.
422 @kindex -c @var{MRI-cmdfile}
423 @kindex --mri-script=@var{MRI-cmdfile}
424 @cindex compatibility, MRI
425 @item -c @var{MRI-commandfile}
426 @itemx --mri-script=@var{MRI-commandfile}
427 For compatibility with linkers produced by MRI, @command{ld} accepts script
428 files written in an alternate, restricted command language, described in
430 @ref{MRI,,MRI Compatible Script Files}.
433 the MRI Compatible Script Files section of GNU ld documentation.
435 Introduce MRI script files with
436 the option @samp{-c}; use the @samp{-T} option to run linker
437 scripts written in the general-purpose @command{ld} scripting language.
438 If @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories
439 specified by any @samp{-L} options.
441 @cindex common allocation
448 These three options are equivalent; multiple forms are supported for
449 compatibility with other linkers. They assign space to common symbols
450 even if a relocatable output file is specified (with @samp{-r}). The
451 script command @code{FORCE_COMMON_ALLOCATION} has the same effect.
452 @xref{Miscellaneous Commands}.
454 @kindex --depaudit @var{AUDITLIB}
455 @kindex -P @var{AUDITLIB}
456 @item --depaudit @var{AUDITLIB}
457 @itemx -P @var{AUDITLIB}
458 Adds @var{AUDITLIB} to the @code{DT_DEPAUDIT} entry of the dynamic section.
459 @var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
460 specified in the library. If specified multiple times @code{DT_DEPAUDIT}
461 will contain a colon separated list of audit interfaces to use. This
462 option is only meaningful on ELF platforms supporting the rtld-audit interface.
463 The -P option is provided for Solaris compatibility.
465 @kindex --enable-linker-version
466 @item --enable-linker-version
467 Enables the @code{LINKER_VERSION} linker script directive, described
468 in @ref{Output Section Data}. If this directive is used in a linker
469 script and this option has been enabled then a string containing the
470 linker version will be inserted at the current point.
472 Note - this location of this option on the linker command line is
473 significant. It will only affect linker scripts that come after it on
474 the command line, or which are built into the linker.
476 @kindex --disable-linker-version
477 @item --disable-linker-version
478 Disables the @code{LINKER_VERSION} linker script directive, so that it
479 does not insert a version string. This is the default.
481 @kindex --enable-non-contiguous-regions
482 @item --enable-non-contiguous-regions
483 This option avoids generating an error if an input section does not
484 fit a matching output section. The linker tries to allocate the input
485 section to subseque nt matching output sections, and generates an
486 error only if no output section is large enough. This is useful when
487 several non-contiguous memory regions are available and the input
488 section does not require a particular one. The order in which input
489 sections are evaluated does not change, for instance:
493 MEM1 (rwx) : ORIGIN = 0x1000, LENGTH = 0x14
494 MEM2 (rwx) : ORIGIN = 0x1000, LENGTH = 0x40
495 MEM3 (rwx) : ORIGIN = 0x2000, LENGTH = 0x40
498 mem1 : @{ *(.data.*); @} > MEM1
499 mem2 : @{ *(.data.*); @} > MEM2
500 mem3 : @{ *(.data.*); @} > MEM3
508 results in .data.1 affected to mem1, and .data.2 and .data.3
509 affected to mem2, even though .data.3 would fit in mem3.
512 This option is incompatible with INSERT statements because it changes
513 the way input sections are mapped to output sections.
515 @kindex --enable-non-contiguous-regions-warnings
516 @item --enable-non-contiguous-regions-warnings
517 This option enables warnings when
518 @code{--enable-non-contiguous-regions} allows possibly unexpected
519 matches in sections mapping, potentially leading to silently
520 discarding a section instead of failing because it does not fit any
523 @cindex entry point, from command line
524 @kindex -e @var{entry}
525 @kindex --entry=@var{entry}
527 @itemx --entry=@var{entry}
528 Use @var{entry} as the explicit symbol for beginning execution of your
529 program, rather than the default entry point. If there is no symbol
530 named @var{entry}, the linker will try to parse @var{entry} as a number,
531 and use that as the entry address (the number will be interpreted in
532 base 10; you may use a leading @samp{0x} for base 16, or a leading
533 @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults
534 and other ways of specifying the entry point.
536 @kindex --exclude-libs
537 @item --exclude-libs @var{lib},@var{lib},...
538 Specifies a list of archive libraries from which symbols should not be automatically
539 exported. The library names may be delimited by commas or colons. Specifying
540 @code{--exclude-libs ALL} excludes symbols in all archive libraries from
541 automatic export. This option is available only for the i386 PE targeted
542 port of the linker and for ELF targeted ports. For i386 PE, symbols
543 explicitly listed in a .def file are still exported, regardless of this
544 option. For ELF targeted ports, symbols affected by this option will
545 be treated as hidden.
547 @kindex --exclude-modules-for-implib
548 @item --exclude-modules-for-implib @var{module},@var{module},...
549 Specifies a list of object files or archive members, from which symbols
550 should not be automatically exported, but which should be copied wholesale
551 into the import library being generated during the link. The module names
552 may be delimited by commas or colons, and must match exactly the filenames
553 used by @command{ld} to open the files; for archive members, this is simply
554 the member name, but for object files the name listed must include and
555 match precisely any path used to specify the input file on the linker's
556 command-line. This option is available only for the i386 PE targeted port
557 of the linker. Symbols explicitly listed in a .def file are still exported,
558 regardless of this option.
560 @cindex dynamic symbol table
562 @kindex --export-dynamic
563 @kindex --no-export-dynamic
565 @itemx --export-dynamic
566 @itemx --no-export-dynamic
567 When creating a dynamically linked executable, using the @option{-E}
568 option or the @option{--export-dynamic} option causes the linker to add
569 all symbols to the dynamic symbol table. The dynamic symbol table is the
570 set of symbols which are visible from dynamic objects at run time.
572 If you do not use either of these options (or use the
573 @option{--no-export-dynamic} option to restore the default behavior), the
574 dynamic symbol table will normally contain only those symbols which are
575 referenced by some dynamic object mentioned in the link.
577 If you use @code{dlopen} to load a dynamic object which needs to refer
578 back to the symbols defined by the program, rather than some other
579 dynamic object, then you will probably need to use this option when
580 linking the program itself.
582 You can also use the dynamic list to control what symbols should
583 be added to the dynamic symbol table if the output format supports it.
584 See the description of @samp{--dynamic-list}.
586 Note that this option is specific to ELF targeted ports. PE targets
587 support a similar function to export all symbols from a DLL or EXE; see
588 the description of @samp{--export-all-symbols} below.
590 @kindex --export-dynamic-symbol=@var{glob}
591 @cindex export dynamic symbol
592 @item --export-dynamic-symbol=@var{glob}
593 When creating a dynamically linked executable, symbols matching
594 @var{glob} will be added to the dynamic symbol table. When creating a
595 shared library, references to symbols matching @var{glob} will not be
596 bound to the definitions within the shared library. This option is a
597 no-op when creating a shared library and @samp{-Bsymbolic} or
598 @samp{--dynamic-list} are not specified. This option is only meaningful
599 on ELF platforms which support shared libraries.
601 @kindex --export-dynamic-symbol-list=@var{file}
602 @cindex export dynamic symbol list
603 @item --export-dynamic-symbol-list=@var{file}
604 Specify a @samp{--export-dynamic-symbol} for each pattern in the file.
605 The format of the file is the same as the version node without
606 scope and node name. See @ref{VERSION} for more information.
608 @ifclear SingleFormat
609 @cindex big-endian objects
613 Link big-endian objects. This affects the default output format.
615 @cindex little-endian objects
618 Link little-endian objects. This affects the default output format.
621 @kindex -f @var{name}
622 @kindex --auxiliary=@var{name}
624 @itemx --auxiliary=@var{name}
625 When creating an ELF shared object, set the internal DT_AUXILIARY field
626 to the specified name. This tells the dynamic linker that the symbol
627 table of the shared object should be used as an auxiliary filter on the
628 symbol table of the shared object @var{name}.
630 If you later link a program against this filter object, then, when you
631 run the program, the dynamic linker will see the DT_AUXILIARY field. If
632 the dynamic linker resolves any symbols from the filter object, it will
633 first check whether there is a definition in the shared object
634 @var{name}. If there is one, it will be used instead of the definition
635 in the filter object. The shared object @var{name} need not exist.
636 Thus the shared object @var{name} may be used to provide an alternative
637 implementation of certain functions, perhaps for debugging or for
638 machine-specific performance.
640 This option may be specified more than once. The DT_AUXILIARY entries
641 will be created in the order in which they appear on the command line.
643 @kindex -F @var{name}
644 @kindex --filter=@var{name}
646 @itemx --filter=@var{name}
647 When creating an ELF shared object, set the internal DT_FILTER field to
648 the specified name. This tells the dynamic linker that the symbol table
649 of the shared object which is being created should be used as a filter
650 on the symbol table of the shared object @var{name}.
652 If you later link a program against this filter object, then, when you
653 run the program, the dynamic linker will see the DT_FILTER field. The
654 dynamic linker will resolve symbols according to the symbol table of the
655 filter object as usual, but it will actually link to the definitions
656 found in the shared object @var{name}. Thus the filter object can be
657 used to select a subset of the symbols provided by the object
660 Some older linkers used the @option{-F} option throughout a compilation
661 toolchain for specifying object-file format for both input and output
663 @ifclear SingleFormat
664 The @sc{gnu} linker uses other mechanisms for this purpose: the
665 @option{-b}, @option{--format}, @option{--oformat} options, the
666 @code{TARGET} command in linker scripts, and the @code{GNUTARGET}
667 environment variable.
669 The @sc{gnu} linker will ignore the @option{-F} option when not
670 creating an ELF shared object.
672 @cindex finalization function
673 @kindex -fini=@var{name}
674 @item -fini=@var{name}
675 When creating an ELF executable or shared object, call NAME when the
676 executable or shared object is unloaded, by setting DT_FINI to the
677 address of the function. By default, the linker uses @code{_fini} as
678 the function to call.
682 Ignored. Provided for compatibility with other tools.
684 @kindex -G @var{value}
685 @kindex --gpsize=@var{value}
688 @itemx --gpsize=@var{value}
689 Set the maximum size of objects to be optimized using the GP register to
690 @var{size}. This is only meaningful for object file formats such as
691 MIPS ELF that support putting large and small objects into different
692 sections. This is ignored for other object file formats.
694 @cindex runtime library name
695 @kindex -h @var{name}
696 @kindex -soname=@var{name}
698 @itemx -soname=@var{name}
699 When creating an ELF shared object, set the internal DT_SONAME field to
700 the specified name. When an executable is linked with a shared object
701 which has a DT_SONAME field, then when the executable is run the dynamic
702 linker will attempt to load the shared object specified by the DT_SONAME
703 field rather than using the file name given to the linker.
706 @cindex incremental link
708 Perform an incremental link (same as option @samp{-r}).
710 @cindex initialization function
711 @kindex -init=@var{name}
712 @item -init=@var{name}
713 When creating an ELF executable or shared object, call NAME when the
714 executable or shared object is loaded, by setting DT_INIT to the address
715 of the function. By default, the linker uses @code{_init} as the
718 @cindex archive files, from cmd line
719 @kindex -l @var{namespec}
720 @kindex --library=@var{namespec}
721 @item -l @var{namespec}
722 @itemx --library=@var{namespec}
723 Add the archive or object file specified by @var{namespec} to the
724 list of files to link. This option may be used any number of times.
725 If @var{namespec} is of the form @file{:@var{filename}}, @command{ld}
726 will search the library path for a file called @var{filename}, otherwise it
727 will search the library path for a file called @file{lib@var{namespec}.a}.
729 On systems which support shared libraries, @command{ld} may also search for
730 files other than @file{lib@var{namespec}.a}. Specifically, on ELF
731 and SunOS systems, @command{ld} will search a directory for a library
732 called @file{lib@var{namespec}.so} before searching for one called
733 @file{lib@var{namespec}.a}. (By convention, a @code{.so} extension
734 indicates a shared library.) Note that this behavior does not apply
735 to @file{:@var{filename}}, which always specifies a file called
738 The linker will search an archive only once, at the location where it is
739 specified on the command line. If the archive defines a symbol which
740 was undefined in some object which appeared before the archive on the
741 command line, the linker will include the appropriate file(s) from the
742 archive. However, an undefined symbol in an object appearing later on
743 the command line will not cause the linker to search the archive again.
745 See the @option{-(} option for a way to force the linker to search
746 archives multiple times.
748 You may list the same archive multiple times on the command line.
751 This type of archive searching is standard for Unix linkers. However,
752 if you are using @command{ld} on AIX, note that it is different from the
753 behaviour of the AIX linker.
756 @cindex search directory, from cmd line
758 @kindex --library-path=@var{dir}
759 @item -L @var{searchdir}
760 @itemx --library-path=@var{searchdir}
762 Add path @var{searchdir} to the list of paths that @command{ld} will search
763 for archive libraries and @command{ld} control scripts. You may use this
764 option any number of times. The directories are searched in the order
765 in which they are specified on the command line. Directories specified
766 on the command line are searched before the default directories. All
767 @option{-L} options apply to all @option{-l} options, regardless of the
768 order in which the options appear. @option{-L} options do not affect
769 how @command{ld} searches for a linker script unless @option{-T}
772 If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
773 prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
774 @samp{--sysroot} option, or specified when the linker is configured.
777 The default set of paths searched (without being specified with
778 @samp{-L}) depends on which emulation mode @command{ld} is using, and in
779 some cases also on how it was configured. @xref{Environment}.
782 The paths can also be specified in a link script with the
783 @code{SEARCH_DIR} command. Directories specified this way are searched
784 at the point in which the linker script appears in the command line.
787 @kindex -m @var{emulation}
788 @item -m @var{emulation}
789 Emulate the @var{emulation} linker. You can list the available
790 emulations with the @samp{--verbose} or @samp{-V} options.
792 If the @samp{-m} option is not used, the emulation is taken from the
793 @code{LDEMULATION} environment variable, if that is defined.
795 Otherwise, the default emulation depends upon how the linker was
798 @cindex remapping inputs
799 @kindex --remap-inputs=@file{pattern}=@file{filename}
800 @kindex --remap-inputs-file=@file{file}
801 @item --remap-inputs=@file{pattern}=@file{filename}
802 @itemx --remap-inputs-file=@file{file}
803 These options allow the names of input files to be changed before the
804 linker attempts to open them. The option
805 @option{--remap-inputs=foo.o=bar.o} will cause any attempt to load a
806 file called @file{foo.o} to instead try to load a file called
807 @file{bar.o}. Wildcard patterns are permitted in the first filename,
808 so @option{--remap-inputs=foo*.o=bar.o} will rename any input file that
809 matches @file{foo*.o} to @file{bar.o}.
811 An alternative form of the option
812 @option{--remap-inputs-file=filename} allows the remappings to be read
813 from a file. Each line in the file can contain a single remapping.
814 Blank lines are ignored. Anything from a hash character (@samp{#}) to
815 the end of a line is considered to be a comment and is also ignored.
816 The mapping pattern can be separated from the filename by whitespace
817 or an equals (@samp{=}) character.
819 The options can be specified multiple times. Their contents
820 accumulate. The remappings will be processed in the order in which
821 they occur on the command line, and if they come from a file, in the
822 order in which they occur in the file. If a match is made, no further
823 checking for that filename will be performed.
825 If the replacement filename is @file{/dev/null} or just @file{NUL}
826 then the remapping will actually cause the input file to be ignored.
827 This can be a convenient way to experiment with removing input files
828 from a complicated build environment.
830 Note that this option is position dependent and only affects filenames
831 that come after it on the command line. Thus:
834 ld foo.o --remap-inputs=foo.o=bar.o
837 Will have no effect, whereas:
840 ld --remap-inputs=foo.o=bar.o foo.o
843 Will rename the input file @file{foo.o} to @file{bar.o}.
845 Note - these options also affect files referenced by @emph{INPUT}
846 statements in linker scripts. But since linker scripts are processed
847 after the entire command line is read, the position of the remap
848 options on the command line is not significant.
850 If the @option{verbose} option is enabled then any mappings that match
851 will be reported, although again the @option{verbose} option needs to
852 be enabled on the command line @emph{before} the remaped filenames
855 If the @option{-Map} or @option{--print-map} options are enabled then
856 the remapping list will be included in the map output.
863 Print a link map to the standard output. A link map provides
864 information about the link, including the following:
868 Where object files are mapped into memory.
870 How common symbols are allocated.
872 All archive members included in the link, with a mention of the symbol
873 which caused the archive member to be brought in.
875 The values assigned to symbols.
877 Note - symbols whose values are computed by an expression which
878 involves a reference to a previous value of the same symbol may not
879 have correct result displayed in the link map. This is because the
880 linker discards intermediate results and only retains the final value
881 of an expression. Under such circumstances the linker will display
882 the final value enclosed by square brackets. Thus for example a
883 linker script containing:
891 will produce the following output in the link map if the @option{-M}
896 [0x0000000c] foo = (foo * 0x4)
897 [0x0000000c] foo = (foo + 0x8)
900 See @ref{Expressions} for more information about expressions in linker
904 How GNU properties are merged.
906 When the linker merges input .note.gnu.property sections into one output
907 .note.gnu.property section, some properties are removed or updated.
908 These actions are reported in the link map. For example:
911 Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
914 This indicates that property 0xc0000002 is removed from output when
915 merging properties in @file{foo.o}, whose property 0xc0000002 value
916 is 0x1, and @file{bar.o}, which doesn't have property 0xc0000002.
919 Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
922 This indicates that property 0xc0010001 value is updated to 0x1 in output
923 when merging properties in @file{foo.o}, whose 0xc0010001 property value
924 is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1.
927 On some ELF targets, a list of fixups inserted by @option{--relax}
930 foo.o: Adjusting branch at 0x00000008 towards "far" in section .text
933 This indicates that the branch at 0x00000008 in foo.o, targeting
934 the symbol "far" in section .text, has been replaced by a trampoline.
938 @cindex link map discarded
939 @kindex --print-map-discarded
940 @kindex --no-print-map-discarded
941 @item --print-map-discarded
942 @itemx --no-print-map-discarded
943 Print (or do not print) the list of discarded and garbage collected sections
944 in the link map. Enabled by default.
946 @kindex --print-map-locals
947 @kindex --no-print-map-locals
948 @item --print-map-locals
949 @itemx --no-print-map-locals
950 Print (or do not print) local symbols in the link map. Local symbols
951 will have the text @samp{(local)} printed before their name, and will
952 be listed after all of the global symbols in a given section.
953 Temporary local symbols (typically those that start with @samp{.L})
954 will not be included in the output. Disabled by default.
957 @cindex read-only text
962 Turn off page alignment of sections, and disable linking against shared
963 libraries. If the output format supports Unix style magic numbers,
964 mark the output as @code{NMAGIC}.
968 @cindex read/write from cmd line
972 Set the text and data sections to be readable and writable. Also, do
973 not page-align the data segment, and disable linking against shared
974 libraries. If the output format supports Unix style magic numbers,
975 mark the output as @code{OMAGIC}. Note: Although a writable text section
976 is allowed for PE-COFF targets, it does not conform to the format
977 specification published by Microsoft.
982 This option negates most of the effects of the @option{-N} option. It
983 sets the text section to be read-only, and forces the data segment to
984 be page-aligned. Note - this option does not enable linking against
985 shared libraries. Use @option{-Bdynamic} for this.
987 @kindex -o @var{output}
988 @kindex --output=@var{output}
989 @cindex naming the output file
990 @item -o @var{output}
991 @itemx --output=@var{output}
992 Use @var{output} as the name for the program produced by @command{ld}; if this
993 option is not specified, the name @file{a.out} is used by default. The
994 script command @code{OUTPUT} can also specify the output file name.
996 Note - the linker will delete the output file before it starts to
997 write to it. It will do this even if it turns out that the link
998 cannot be completed due to errors.
1000 Note - the linker will check to make sure that the output file name
1001 does not match the name of any of the input files, but that is all.
1002 In particular it will not complain if the output file might overwrite
1003 a source file or some other important file. Therefore in build
1004 systems it is recommended to use the @option{-o} option as the last
1005 option on the linker command line. For example consider:
1008 ld -o $(EXE) $(OBJS)
1009 ld $(OBJS) -o $(EXE)
1012 If the @samp{EXE} variable is not defined for some reason, the first
1013 version of the linker command could end up deleting one of the object
1014 files (the first one in the @samp{OBJS} list) whereas the second
1015 version of the linker command will generate an error message and not
1018 @kindex --dependency-file=@var{depfile}
1019 @cindex dependency file
1020 @item --dependency-file=@var{depfile}
1021 Write a @dfn{dependency file} to @var{depfile}. This file contains a rule
1022 suitable for @code{make} describing the output file and all the input files
1023 that were read to produce it. The output is similar to the compiler's
1024 output with @samp{-M -MP} (@pxref{Preprocessor Options,, Options
1025 Controlling the Preprocessor, gcc.info, Using the GNU Compiler
1026 Collection}). Note that there is no option like the compiler's @samp{-MM},
1027 to exclude ``system files'' (which is not a well-specified concept in the
1028 linker, unlike ``system headers'' in the compiler). So the output from
1029 @samp{--dependency-file} is always specific to the exact state of the
1030 installation where it was produced, and should not be copied into
1031 distributed makefiles without careful editing.
1033 @kindex -O @var{level}
1034 @cindex generating optimized output
1035 @item -O @var{level}
1036 If @var{level} is a numeric values greater than zero @command{ld} optimizes
1037 the output. This might take significantly longer and therefore probably
1038 should only be enabled for the final binary. At the moment this
1039 option only affects ELF shared library generation. Future releases of
1040 the linker may make more use of this option. Also currently there is
1041 no difference in the linker's behaviour for different non-zero values
1042 of this option. Again this may change with future releases.
1044 @kindex -plugin @var{name}
1045 @item -plugin @var{name}
1046 Involve a plugin in the linking process. The @var{name} parameter is
1047 the absolute filename of the plugin. Usually this parameter is
1048 automatically added by the complier, when using link time
1049 optimization, but users can also add their own plugins if they so
1052 Note that the location of the compiler originated plugins is different
1053 from the place where the @command{ar}, @command{nm} and
1054 @command{ranlib} programs search for their plugins. In order for
1055 those commands to make use of a compiler based plugin it must first be
1056 copied into the @file{$@{libdir@}/bfd-plugins} directory. All gcc
1057 based linker plugins are backward compatible, so it is sufficient to
1058 just copy in the newest one.
1060 @kindex --push-state
1061 @cindex push state governing input file handling
1063 The @option{--push-state} allows one to preserve the current state of the
1064 flags which govern the input file handling so that they can all be
1065 restored with one corresponding @option{--pop-state} option.
1067 The option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
1068 @option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
1069 @option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
1070 @option{--no-whole-archive}, @option{-r}, @option{-Ur},
1071 @option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
1072 @option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
1074 One target for this option are specifications for @file{pkg-config}. When
1075 used with the @option{--libs} option all possibly needed libraries are
1076 listed and then possibly linked with all the time. It is better to return
1077 something as follows:
1080 -Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
1084 @cindex pop state governing input file handling
1086 Undoes the effect of --push-state, restores the previous values of the
1087 flags governing input file handling.
1090 @kindex --emit-relocs
1091 @cindex retain relocations in final executable
1093 @itemx --emit-relocs
1094 Leave relocation sections and contents in fully linked executables.
1095 Post link analysis and optimization tools may need this information in
1096 order to perform correct modifications of executables. This results
1097 in larger executables.
1099 This option is currently only supported on ELF platforms.
1101 @kindex --force-dynamic
1102 @cindex forcing the creation of dynamic sections
1103 @item --force-dynamic
1104 Force the output file to have dynamic sections. This option is specific
1107 @cindex partial link
1108 @cindex relocatable output
1110 @kindex --relocatable
1112 @itemx --relocatable
1113 Generate relocatable output---i.e., generate an output file that can in
1114 turn serve as input to @command{ld}. This is often called @dfn{partial
1115 linking}. As a side effect, in environments that support standard Unix
1116 magic numbers, this option also sets the output file's magic number to
1118 @c ; see @option{-N}.
1119 If this option is not specified, an absolute file is produced. When
1120 linking C++ programs, this option @emph{will not} resolve references to
1121 constructors; to do that, use @samp{-Ur}.
1123 When an input file does not have the same format as the output file,
1124 partial linking is only supported if that input file does not contain any
1125 relocations. Different output formats can have further restrictions; for
1126 example some @code{a.out}-based formats do not support partial linking
1127 with input files in other formats at all.
1129 This option does the same thing as @samp{-i}.
1131 @kindex -R @var{file}
1132 @kindex --just-symbols=@var{file}
1133 @cindex symbol-only input
1134 @item -R @var{filename}
1135 @itemx --just-symbols=@var{filename}
1136 Read symbol names and their addresses from @var{filename}, but do not
1137 relocate it or include it in the output. This allows your output file
1138 to refer symbolically to absolute locations of memory defined in other
1139 programs. You may use this option more than once.
1141 For compatibility with other ELF linkers, if the @option{-R} option is
1142 followed by a directory name, rather than a file name, it is treated as
1143 the @option{-rpath} option.
1146 @itemx --no-rosegment
1147 Attempt to ensure that only a single read-only, non-code segment is
1148 created. Only useful when used in conjunction with the @option{-z
1149 separate-code} option. The resulting binaries should be smaller than
1150 if @option{-z separate-code} is used on its own. Without this option,
1151 or if @option{--no-rosegment} is specified, the @option{-z separate-code}
1152 option will create two read-only segments, one before the code segment
1155 The name of the options are misleading, but they have been chosen in
1156 order for the linker to be compatible with the LLD and GOLD linkers.
1158 Thse options are only supported by ELF targets.
1162 @cindex strip all symbols
1165 Omit all symbol information from the output file.
1168 @kindex --strip-debug
1169 @cindex strip debugger symbols
1171 @itemx --strip-debug
1172 Omit debugger symbol information (but not all symbols) from the output file.
1174 @kindex --strip-discarded
1175 @kindex --no-strip-discarded
1176 @item --strip-discarded
1177 @itemx --no-strip-discarded
1178 Omit (or do not omit) global symbols defined in discarded sections.
1181 @kindex -plugin-save-temps
1182 @item -plugin-save-temps
1183 Store the plugin ``temporary'' intermediate files permanently.
1187 @cindex input files, displaying
1190 Print the names of the input files as @command{ld} processes them. If
1191 @samp{-t} is given twice then members within archives are also printed.
1192 @samp{-t} output is useful to generate a list of all the object files
1193 and scripts involved in linking, for example, when packaging files for
1194 a linker bug report.
1196 @kindex -T @var{script}
1197 @kindex --script=@var{script}
1198 @cindex script files
1199 @item -T @var{scriptfile}
1200 @itemx --script=@var{scriptfile}
1201 Use @var{scriptfile} as the linker script. This script replaces
1202 @command{ld}'s default linker script (rather than adding to it),
1203 unless the script contains @code{INSERT}, so @var{commandfile} must
1204 specify everything necessary to describe the output file.
1207 If @var{scriptfile} does not exist in the current directory, @code{ld}
1208 looks for it in the directories specified by any preceding @samp{-L}
1211 Command line options that appear before the @option{-T} option can
1212 affect the script, but command line options that appear after it do
1215 Multiple @samp{-T} options will accumulate if they are augmenting the
1216 current script, otherwise the last, non-augmenting, @option{-T} option
1219 There are other ways of specifying linker scripts. See
1220 @xref{--default-script}, @xref{--section-ordering-file}, and
1221 @xref{unrecognised-input-files}.
1223 @kindex -dT @var{script}
1224 @kindex --default-script=@var{script}
1225 @cindex script files
1226 @item -dT @var{scriptfile}
1227 @itemx --default-script=@var{scriptfile}
1228 @anchor{--default-script}
1229 Use @var{scriptfile} as the default linker script. @xref{Scripts}.
1231 This option is similar to the @option{--script} option except that
1232 processing of the script is delayed until after the rest of the
1233 command line has been processed. This allows options placed after the
1234 @option{--default-script} option on the command line to affect the
1235 behaviour of the linker script, which can be important when the linker
1236 command line cannot be directly controlled by the user. (eg because
1237 the command line is being constructed by another tool, such as
1240 @kindex -u @var{symbol}
1241 @kindex --undefined=@var{symbol}
1242 @cindex undefined symbol
1243 @item -u @var{symbol}
1244 @itemx --undefined=@var{symbol}
1245 Force @var{symbol} to be entered in the output file as an undefined
1246 symbol. Doing this may, for example, trigger linking of additional
1247 modules from standard libraries. @samp{-u} may be repeated with
1248 different option arguments to enter additional undefined symbols. This
1249 option is equivalent to the @code{EXTERN} linker script command.
1251 If this option is being used to force additional modules to be pulled
1252 into the link, and if it is an error for the symbol to remain
1253 undefined, then the option @option{--require-defined} should be used
1256 @kindex --require-defined=@var{symbol}
1257 @cindex symbols, require defined
1258 @cindex defined symbol
1259 @item --require-defined=@var{symbol}
1260 Require that @var{symbol} is defined in the output file. This option
1261 is the same as option @option{--undefined} except that if @var{symbol}
1262 is not defined in the output file then the linker will issue an error
1263 and exit. The same effect can be achieved in a linker script by using
1264 @code{EXTERN}, @code{ASSERT} and @code{DEFINED} together. This option
1265 can be used multiple times to require additional symbols.
1268 @cindex constructors
1271 For programs that do not use constructors or destructors, or for ELF
1272 based systems this option is equivalent to @option{-r}: it generates
1273 relocatable output---i.e., an output file that can in turn serve as
1274 input to @command{ld}. For other binaries however the @option{-Ur}
1275 option is similar to @option{-r} but it also resolves references to
1276 constructors and destructors.
1278 For those systems where @option{-r} and @option{-Ur} behave
1279 differently, it does not work to use @option{-Ur} on files that were
1280 themselves linked with @option{-Ur}; once the constructor table has
1281 been built, it cannot be added to. Use @option{-Ur} only for the last
1282 partial link, and @option{-r} for the others.
1284 @kindex --orphan-handling=@var{MODE}
1285 @cindex orphan sections
1286 @cindex sections, orphan
1287 @item --orphan-handling=@var{MODE}
1288 Control how orphan sections are handled. An orphan section is one not
1289 specifically mentioned in a linker script. @xref{Orphan Sections}.
1291 @var{MODE} can have any of the following values:
1295 Orphan sections are placed into a suitable output section following
1296 the strategy described in @ref{Orphan Sections}. The option
1297 @samp{--unique} also affects how sections are placed.
1300 All orphan sections are discarded, by placing them in the
1301 @samp{/DISCARD/} section (@pxref{Output Section Discarding}).
1304 The linker will place the orphan section as for @code{place} and also
1308 The linker will exit with an error if any orphan section is found.
1311 The default if @samp{--orphan-handling} is not given is @code{place}.
1313 @kindex --unique[=@var{SECTION}]
1314 @item --unique[=@var{SECTION}]
1315 Creates a separate output section for every input section matching
1316 @var{SECTION}, or if the optional wildcard @var{SECTION} argument is
1317 missing, for every orphan input section. An orphan section is one not
1318 specifically mentioned in a linker script. You may use this option
1319 multiple times on the command line; It prevents the normal merging of
1320 input sections with the same name, overriding output section assignments
1330 Display the version number for @command{ld}. The @option{-V} option also
1331 lists the supported emulations. See also the description of the
1332 @option{--enable-linker-version} in @ref{Options,,Command-line Options}
1333 which can be used to insert the linker version string into a binary.
1336 @kindex --discard-all
1337 @cindex deleting local symbols
1339 @itemx --discard-all
1340 Delete all local symbols.
1343 @kindex --discard-locals
1344 @cindex local symbols, deleting
1346 @itemx --discard-locals
1347 Delete all temporary local symbols. (These symbols start with
1348 system-specific local label prefixes, typically @samp{.L} for ELF systems
1349 or @samp{L} for traditional a.out systems.)
1351 @kindex -y @var{symbol}
1352 @kindex --trace-symbol=@var{symbol}
1353 @cindex symbol tracing
1354 @item -y @var{symbol}
1355 @itemx --trace-symbol=@var{symbol}
1356 Print the name of each linked file in which @var{symbol} appears. This
1357 option may be given any number of times. On many systems it is necessary
1358 to prepend an underscore.
1360 This option is useful when you have an undefined symbol in your link but
1361 don't know where the reference is coming from.
1363 @kindex -Y @var{path}
1365 Add @var{path} to the default library search path. This option exists
1366 for Solaris compatibility.
1368 @kindex -z @var{keyword}
1369 @item -z @var{keyword}
1370 The recognized keywords are:
1373 @item call-nop=prefix-addr
1374 @itemx call-nop=suffix-nop
1375 @itemx call-nop=prefix-@var{byte}
1376 @itemx call-nop=suffix-@var{byte}
1377 Specify the 1-byte @code{NOP} padding when transforming indirect call
1378 to a locally defined function, foo, via its GOT slot.
1379 @option{call-nop=prefix-addr} generates @code{0x67 call foo}.
1380 @option{call-nop=suffix-nop} generates @code{call foo 0x90}.
1381 @option{call-nop=prefix-@var{byte}} generates @code{@var{byte} call foo}.
1382 @option{call-nop=suffix-@var{byte}} generates @code{call foo @var{byte}}.
1383 Supported for i386 and x86_64.
1385 @item cet-report=none
1386 @itemx cet-report=warning
1387 @itemx cet-report=error
1388 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT and
1389 GNU_PROPERTY_X86_FEATURE_1_SHSTK properties in input .note.gnu.property
1390 section. @option{cet-report=none}, which is the default, will make the
1391 linker not report missing properties in input files.
1392 @option{cet-report=warning} will make the linker issue a warning for
1393 missing properties in input files. @option{cet-report=error} will make
1394 the linker issue an error for missing properties in input files.
1395 Note that @option{ibt} will turn off the missing
1396 GNU_PROPERTY_X86_FEATURE_1_IBT property report and @option{shstk} will
1397 turn off the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property report.
1398 Supported for Linux/i386 and Linux/x86_64.
1402 Combine multiple dynamic relocation sections and sort to improve
1403 dynamic symbol lookup caching. Do not do this if @samp{nocombreloc}.
1407 Generate common symbols with STT_COMMON type during a relocatable
1408 link. Use STT_OBJECT type if @samp{nocommon}.
1410 @item common-page-size=@var{value}
1411 Set the page size most commonly used to @var{value}. Memory image
1412 layout will be optimized to minimize memory pages if the system is
1413 using pages of this size.
1416 Report unresolved symbol references from regular object files. This
1417 is done even if the linker is creating a non-symbolic shared library.
1418 This option is the inverse of @samp{-z undefs}.
1420 @item dynamic-undefined-weak
1421 @itemx nodynamic-undefined-weak
1422 Make undefined weak symbols dynamic when building a dynamic object,
1423 if they are referenced from a regular object file and not forced local
1424 by symbol visibility or versioning. Do not make them dynamic if
1425 @samp{nodynamic-undefined-weak}. If neither option is given, a target
1426 may default to either option being in force, or make some other
1427 selection of undefined weak symbols dynamic. Not all targets support
1431 Marks the object as requiring executable stack.
1434 This option is only meaningful when building a shared object. It makes
1435 the symbols defined by this shared object available for symbol resolution
1436 of subsequently loaded libraries.
1439 This option is only meaningful when building a dynamic executable.
1440 This option marks the executable as requiring global auditing by
1441 setting the @code{DF_1_GLOBAUDIT} bit in the @code{DT_FLAGS_1} dynamic
1442 tag. Global auditing requires that any auditing library defined via
1443 the @option{--depaudit} or @option{-P} command-line options be run for
1444 all dynamic objects loaded by the application.
1447 Generate Intel Indirect Branch Tracking (IBT) enabled PLT entries.
1448 Supported for Linux/i386 and Linux/x86_64.
1451 Generate GNU_PROPERTY_X86_FEATURE_1_IBT in .note.gnu.property section
1452 to indicate compatibility with IBT. This also implies @option{ibtplt}.
1453 Supported for Linux/i386 and Linux/x86_64.
1455 @item indirect-extern-access
1456 @itemx noindirect-extern-access
1457 Generate GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS in
1458 .note.gnu.property section to indicate that object file requires
1459 canonical function pointers and cannot be used with copy relocation.
1460 This option also implies @option{noextern-protected-data} and
1461 @option{nocopyreloc}. Supported for i386 and x86-64.
1463 @option{noindirect-extern-access} removes
1464 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS from .note.gnu.property
1468 This option is only meaningful when building a shared object.
1469 It marks the object so that its runtime initialization will occur
1470 before the runtime initialization of any other objects brought into
1471 the process at the same time. Similarly the runtime finalization of
1472 the object will occur after the runtime finalization of any other
1476 Specify that the dynamic loader should modify its symbol search order
1477 so that symbols in this shared library interpose all other shared
1478 libraries not so marked.
1482 When generating a shared library or other dynamically loadable ELF
1483 object mark it as one that should (by default) only ever be loaded once,
1484 and only in the main namespace (when using @code{dlmopen}). This is
1485 primarily used to mark fundamental libraries such as libc, libpthread et
1486 al which do not usually function correctly unless they are the sole instances
1487 of themselves. This behaviour can be overridden by the @code{dlmopen} caller
1488 and does not apply to certain loading mechanisms (such as audit libraries).
1491 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U48 in .note.gnu.property section
1492 to indicate compatibility with Intel LAM_U48. Supported for Linux/x86_64.
1495 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U57 in .note.gnu.property section
1496 to indicate compatibility with Intel LAM_U57. Supported for Linux/x86_64.
1498 @item lam-u48-report=none
1499 @itemx lam-u48-report=warning
1500 @itemx lam-u48-report=error
1501 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48
1502 property in input .note.gnu.property section.
1503 @option{lam-u48-report=none}, which is the default, will make the
1504 linker not report missing properties in input files.
1505 @option{lam-u48-report=warning} will make the linker issue a warning for
1506 missing properties in input files. @option{lam-u48-report=error} will
1507 make the linker issue an error for missing properties in input files.
1508 Supported for Linux/x86_64.
1510 @item lam-u57-report=none
1511 @itemx lam-u57-report=warning
1512 @itemx lam-u57-report=error
1513 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U57
1514 property in input .note.gnu.property section.
1515 @option{lam-u57-report=none}, which is the default, will make the
1516 linker not report missing properties in input files.
1517 @option{lam-u57-report=warning} will make the linker issue a warning for
1518 missing properties in input files. @option{lam-u57-report=error} will
1519 make the linker issue an error for missing properties in input files.
1520 Supported for Linux/x86_64.
1522 @item lam-report=none
1523 @itemx lam-report=warning
1524 @itemx lam-report=error
1525 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
1526 GNU_PROPERTY_X86_FEATURE_1_LAM_U57 properties in input .note.gnu.property
1527 section. @option{lam-report=none}, which is the default, will make the
1528 linker not report missing properties in input files.
1529 @option{lam-report=warning} will make the linker issue a warning for
1530 missing properties in input files. @option{lam-report=error} will make
1531 the linker issue an error for missing properties in input files.
1532 Supported for Linux/x86_64.
1535 When generating an executable or shared library, mark it to tell the
1536 dynamic linker to defer function call resolution to the point when
1537 the function is called (lazy binding), rather than at load time.
1538 Lazy binding is the default.
1541 Specify that the object's filters be processed immediately at runtime.
1543 @item max-page-size=@var{value}
1544 Set the maximum memory page size supported to @var{value}.
1548 Mark PLT entries with dynamic tags, DT_X86_64_PLT, DT_X86_64_PLTSZ and
1549 DT_X86_64_PLTENT. Since this option stores a non-zero value in the
1550 r_addend field of R_X86_64_JUMP_SLOT relocations, the resulting
1551 executables and shared libraries are incompatible with dynamic linkers,
1552 such as those in older versions of glibc without the change to ignore
1553 r_addend in R_X86_64_GLOB_DAT and R_X86_64_JUMP_SLOT relocations, which
1554 don't ignore the r_addend field of R_X86_64_JUMP_SLOT relocations.
1555 Supported for x86_64.
1558 Allow multiple definitions.
1561 Disable linker generated .dynbss variables used in place of variables
1562 defined in shared libraries. May result in dynamic text relocations.
1565 Specify that the dynamic loader search for dependencies of this object
1566 should ignore any default library search paths.
1569 Specify that the object shouldn't be unloaded at runtime.
1572 Specify that the object is not available to @code{dlopen}.
1575 Specify that the object can not be dumped by @code{dldump}.
1578 Marks the object as not requiring executable stack.
1580 @item noextern-protected-data
1581 Don't treat protected data symbols as external when building a shared
1582 library. This option overrides the linker backend default. It can be
1583 used to work around incorrect relocations against protected data symbols
1584 generated by compiler. Updates on protected data symbols by another
1585 module aren't visible to the resulting shared library. Supported for
1588 @item noreloc-overflow
1589 Disable relocation overflow check. This can be used to disable
1590 relocation overflow check if there will be no dynamic relocation
1591 overflow at run-time. Supported for x86_64.
1594 When generating an executable or shared library, mark it to tell the
1595 dynamic linker to resolve all symbols when the program is started, or
1596 when the shared library is loaded by dlopen, instead of deferring
1597 function call resolution to the point when the function is first
1601 Specify that the object requires @samp{$ORIGIN} handling in paths.
1603 @item pack-relative-relocs
1604 @itemx nopack-relative-relocs
1605 Generate compact relative relocation in position-independent executable
1606 and shared library. It adds @code{DT_RELR}, @code{DT_RELRSZ} and
1607 @code{DT_RELRENT} entries to the dynamic section. It is ignored when
1608 building position-dependent executable and relocatable output.
1609 @option{nopack-relative-relocs} is the default, which disables compact
1610 relative relocation. When linked against the GNU C Library, a
1611 GLIBC_ABI_DT_RELR symbol version dependency on the shared C Library is
1612 added to the output. Supported for i386 and x86-64.
1616 Create an ELF @code{PT_GNU_RELRO} segment header in the object. This
1617 specifies a memory segment that should be made read-only after
1618 relocation, if supported. Specifying @samp{common-page-size} smaller
1619 than the system page size will render this protection ineffective.
1620 Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
1622 @item report-relative-reloc
1623 Report dynamic relative relocations generated by linker. Supported for
1624 Linux/i386 and Linux/x86_64.
1627 @itemx nosectionheader
1628 Generate section header. Don't generate section header if
1629 @samp{nosectionheader} is used. @option{sectionheader} is the default.
1632 @itemx noseparate-code
1633 Create separate code @code{PT_LOAD} segment header in the object. This
1634 specifies a memory segment that should contain only instructions and must
1635 be in wholly disjoint pages from any other data. Don't create separate
1636 code @code{PT_LOAD} segment if @samp{noseparate-code} is used.
1639 Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
1640 to indicate compatibility with Intel Shadow Stack. Supported for
1641 Linux/i386 and Linux/x86_64.
1643 @item stack-size=@var{value}
1644 Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
1645 Specifying zero will override any default non-zero sized
1646 @code{PT_GNU_STACK} segment creation.
1649 @itemx nostart-stop-gc
1650 @cindex start-stop-gc
1651 When @samp{--gc-sections} is in effect, a reference from a retained
1652 section to @code{__start_SECNAME} or @code{__stop_SECNAME} causes all
1653 input sections named @code{SECNAME} to also be retained, if
1654 @code{SECNAME} is representable as a C identifier and either
1655 @code{__start_SECNAME} or @code{__stop_SECNAME} is synthesized by the
1656 linker. @samp{-z start-stop-gc} disables this effect, allowing
1657 sections to be garbage collected as if the special synthesized symbols
1658 were not defined. @samp{-z start-stop-gc} has no effect on a
1659 definition of @code{__start_SECNAME} or @code{__stop_SECNAME} in an
1660 object file or linker script. Such a definition will prevent the
1661 linker providing a synthesized @code{__start_SECNAME} or
1662 @code{__stop_SECNAME} respectively, and therefore the special
1663 treatment by garbage collection for those references.
1665 @item start-stop-visibility=@var{value}
1667 @cindex ELF symbol visibility
1668 Specify the ELF symbol visibility for synthesized
1669 @code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input
1670 Section Example}). @var{value} must be exactly @samp{default},
1671 @samp{internal}, @samp{hidden}, or @samp{protected}. If no @samp{-z
1672 start-stop-visibility} option is given, @samp{protected} is used for
1673 compatibility with historical practice. However, it's highly
1674 recommended to use @samp{-z start-stop-visibility=hidden} in new
1675 programs and shared libraries so that these symbols are not exported
1676 between shared objects, which is not usually what's intended.
1681 Report an error if DT_TEXTREL is set, i.e., if the position-independent
1682 or shared object has dynamic relocations in read-only sections. Don't
1683 report an error if @samp{notext} or @samp{textoff}.
1686 Do not report unresolved symbol references from regular object files,
1687 either when creating an executable, or when creating a shared library.
1688 This option is the inverse of @samp{-z defs}.
1691 @itemx nounique-symbol
1692 Avoid duplicated local symbol names in the symbol string table. Append
1693 ".@code{number}" to duplicated local symbol names if @samp{unique-symbol}
1694 is used. @option{nounique-symbol} is the default.
1696 @item x86-64-baseline
1700 Specify the x86-64 ISA level needed in .note.gnu.property section.
1701 @option{x86-64-baseline} generates @code{GNU_PROPERTY_X86_ISA_1_BASELINE}.
1702 @option{x86-64-v2} generates @code{GNU_PROPERTY_X86_ISA_1_V2}.
1703 @option{x86-64-v3} generates @code{GNU_PROPERTY_X86_ISA_1_V3}.
1704 @option{x86-64-v4} generates @code{GNU_PROPERTY_X86_ISA_1_V4}.
1705 Supported for Linux/i386 and Linux/x86_64.
1707 @item isa-level-report=none
1708 @itemx isa-level-report=all
1709 @itemx isa-level-report=needed
1710 @itemx isa-level-report=used
1711 Specify how to report x86-64 ISA levels in input relocatable files.
1712 @option{isa-level-report=none}, which is the default, will make the
1713 linker not report x86-64 ISA levels in input files.
1714 @option{isa-level-report=all} will make the linker report needed and
1715 used x86-64 ISA levels in input files.
1716 @option{isa-level-report=needed} will make the linker report needed
1717 x86-64 ISA levels in input files.
1718 @option{isa-level-report=used} will make the linker report used
1719 x86-64 ISA levels in input files.
1720 Supported for Linux/i386 and Linux/x86_64.
1724 Other keywords are ignored for Solaris compatibility.
1727 @cindex groups of archives
1728 @item -( @var{archives} -)
1729 @itemx --start-group @var{archives} --end-group
1730 The @var{archives} should be a list of archive files. They may be
1731 either explicit file names, or @samp{-l} options.
1733 The specified archives are searched repeatedly until no new undefined
1734 references are created. Normally, an archive is searched only once in
1735 the order that it is specified on the command line. If a symbol in that
1736 archive is needed to resolve an undefined symbol referred to by an
1737 object in an archive that appears later on the command line, the linker
1738 would not be able to resolve that reference. By grouping the archives,
1739 they will all be searched repeatedly until all possible references are
1742 Using this option has a significant performance cost. It is best to use
1743 it only when there are unavoidable circular references between two or
1746 @kindex --accept-unknown-input-arch
1747 @kindex --no-accept-unknown-input-arch
1748 @item --accept-unknown-input-arch
1749 @itemx --no-accept-unknown-input-arch
1750 Tells the linker to accept input files whose architecture cannot be
1751 recognised. The assumption is that the user knows what they are doing
1752 and deliberately wants to link in these unknown input files. This was
1753 the default behaviour of the linker, before release 2.14. The default
1754 behaviour from release 2.14 onwards is to reject such input files, and
1755 so the @samp{--accept-unknown-input-arch} option has been added to
1756 restore the old behaviour.
1759 @kindex --no-as-needed
1761 @itemx --no-as-needed
1762 This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
1763 on the command line after the @option{--as-needed} option. Normally
1764 the linker will add a DT_NEEDED tag for each dynamic library mentioned
1765 on the command line, regardless of whether the library is actually
1766 needed or not. @option{--as-needed} causes a DT_NEEDED tag to only be
1767 emitted for a library that @emph{at that point in the link} satisfies a
1768 non-weak undefined symbol reference from a regular object file or, if
1769 the library is not found in the DT_NEEDED lists of other needed libraries, a
1770 non-weak undefined symbol reference from another needed dynamic library.
1771 Object files or libraries appearing on the command line @emph{after}
1772 the library in question do not affect whether the library is seen as
1773 needed. This is similar to the rules for extraction of object files
1774 from archives. @option{--no-as-needed} restores the default behaviour.
1776 Note: On Linux based systems the @option{--as-needed} option also has
1777 an affect on the behaviour of the @option{--rpath} and
1778 @option{--rpath-link} options. See the description of
1779 @option{--rpath-link} for more details.
1781 @kindex --add-needed
1782 @kindex --no-add-needed
1784 @itemx --no-add-needed
1785 These two options have been deprecated because of the similarity of
1786 their names to the @option{--as-needed} and @option{--no-as-needed}
1787 options. They have been replaced by @option{--copy-dt-needed-entries}
1788 and @option{--no-copy-dt-needed-entries}.
1790 @kindex -assert @var{keyword}
1791 @item -assert @var{keyword}
1792 This option is ignored for SunOS compatibility.
1796 @kindex -call_shared
1800 Link against dynamic libraries. This is only meaningful on platforms
1801 for which shared libraries are supported. This option is normally the
1802 default on such platforms. The different variants of this option are
1803 for compatibility with various systems. You may use this option
1804 multiple times on the command line: it affects library searching for
1805 @option{-l} options which follow it.
1809 Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
1810 section. This causes the runtime linker to handle lookups in this
1811 object and its dependencies to be performed only inside the group.
1812 @option{--unresolved-symbols=report-all} is implied. This option is
1813 only meaningful on ELF platforms which support shared libraries.
1823 Do not link against shared libraries. This is only meaningful on
1824 platforms for which shared libraries are supported. The different
1825 variants of this option are for compatibility with various systems. You
1826 may use this option multiple times on the command line: it affects
1827 library searching for @option{-l} options which follow it. This
1828 option also implies @option{--unresolved-symbols=report-all}. This
1829 option can be used with @option{-shared}. Doing so means that a
1830 shared library is being created but that all of the library's external
1831 references must be resolved by pulling in entries from static
1836 When creating a shared library, bind references to global symbols to the
1837 definition within the shared library, if any. Normally, it is possible
1838 for a program linked against a shared library to override the definition
1839 within the shared library. This option is only meaningful on ELF
1840 platforms which support shared libraries.
1842 @kindex -Bsymbolic-functions
1843 @item -Bsymbolic-functions
1844 When creating a shared library, bind references to global function
1845 symbols to the definition within the shared library, if any.
1846 This option is only meaningful on ELF platforms which support shared
1849 @kindex -Bno-symbolic
1851 This option can cancel previously specified @samp{-Bsymbolic} and
1852 @samp{-Bsymbolic-functions}.
1854 @kindex --dynamic-list=@var{dynamic-list-file}
1855 @item --dynamic-list=@var{dynamic-list-file}
1856 Specify the name of a dynamic list file to the linker. This is
1857 typically used when creating shared libraries to specify a list of
1858 global symbols whose references shouldn't be bound to the definition
1859 within the shared library, or creating dynamically linked executables
1860 to specify a list of symbols which should be added to the symbol table
1861 in the executable. This option is only meaningful on ELF platforms
1862 which support shared libraries.
1864 The format of the dynamic list is the same as the version node without
1865 scope and node name. See @ref{VERSION} for more information.
1867 @kindex --dynamic-list-data
1868 @item --dynamic-list-data
1869 Include all global data symbols to the dynamic list.
1871 @kindex --dynamic-list-cpp-new
1872 @item --dynamic-list-cpp-new
1873 Provide the builtin dynamic list for C++ operator new and delete. It
1874 is mainly useful for building shared libstdc++.
1876 @kindex --dynamic-list-cpp-typeinfo
1877 @item --dynamic-list-cpp-typeinfo
1878 Provide the builtin dynamic list for C++ runtime type identification.
1880 @kindex --check-sections
1881 @kindex --no-check-sections
1882 @item --check-sections
1883 @itemx --no-check-sections
1884 Asks the linker @emph{not} to check section addresses after they have
1885 been assigned to see if there are any overlaps. Normally the linker will
1886 perform this check, and if it finds any overlaps it will produce
1887 suitable error messages. The linker does know about, and does make
1888 allowances for sections in overlays. The default behaviour can be
1889 restored by using the command-line switch @option{--check-sections}.
1890 Section overlap is not usually checked for relocatable links. You can
1891 force checking in that case by using the @option{--check-sections}
1894 @kindex --copy-dt-needed-entries
1895 @kindex --no-copy-dt-needed-entries
1896 @item --copy-dt-needed-entries
1897 @itemx --no-copy-dt-needed-entries
1898 This option affects the treatment of dynamic libraries referred to
1899 by DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
1900 command line. Normally the linker won't add a DT_NEEDED tag to the
1901 output binary for each library mentioned in a DT_NEEDED tag in an
1902 input dynamic library. With @option{--copy-dt-needed-entries}
1903 specified on the command line however any dynamic libraries that
1904 follow it will have their DT_NEEDED entries added. The default
1905 behaviour can be restored with @option{--no-copy-dt-needed-entries}.
1907 This option also has an effect on the resolution of symbols in dynamic
1908 libraries. With @option{--copy-dt-needed-entries} dynamic libraries
1909 mentioned on the command line will be recursively searched, following
1910 their DT_NEEDED tags to other libraries, in order to resolve symbols
1911 required by the output binary. With the default setting however
1912 the searching of dynamic libraries that follow it will stop with the
1913 dynamic library itself. No DT_NEEDED links will be traversed to resolve
1916 @cindex cross reference table
1919 Output a cross reference table. If a linker map file is being
1920 generated, the cross reference table is printed to the map file.
1921 Otherwise, it is printed on the standard output.
1923 The format of the table is intentionally simple, so that it may be
1924 easily processed by a script if necessary. The symbols are printed out,
1925 sorted by name. For each symbol, a list of file names is given. If the
1926 symbol is defined, the first file listed is the location of the
1927 definition. If the symbol is defined as a common value then any files
1928 where this happens appear next. Finally any files that reference the
1931 @cindex ctf variables
1932 @kindex --ctf-variables
1933 @kindex --no-ctf-variables
1934 @item --ctf-variables
1935 @item --no-ctf-variables
1936 The CTF debuginfo format supports a section which encodes the names and
1937 types of variables found in the program which do not appear in any symbol
1938 table. These variables clearly cannot be looked up by address by
1939 conventional debuggers, so the space used for their types and names is
1940 usually wasted: the types are usually small but the names are often not.
1941 @option{--ctf-variables} causes the generation of such a section.
1942 The default behaviour can be restored with @option{--no-ctf-variables}.
1944 @cindex ctf type sharing
1945 @kindex --ctf-share-types
1946 @item --ctf-share-types=@var{method}
1947 Adjust the method used to share types between translation units in CTF.
1950 @item share-unconflicted
1951 Put all types that do not have ambiguous definitions into the shared dictionary,
1952 where debuggers can easily access them, even if they only occur in one
1953 translation unit. This is the default.
1955 @item share-duplicated
1956 Put only types that occur in multiple translation units into the shared
1957 dictionary: types with only one definition go into per-translation-unit
1958 dictionaries. Types with ambiguous definitions in multiple translation units
1959 always go into per-translation-unit dictionaries. This tends to make the CTF
1960 larger, but may reduce the amount of CTF in the shared dictionary. For very
1961 large projects this may speed up opening the CTF and save memory in the CTF
1962 consumer at runtime.
1965 @cindex common allocation
1966 @kindex --no-define-common
1967 @item --no-define-common
1968 This option inhibits the assignment of addresses to common symbols.
1969 The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
1970 @xref{Miscellaneous Commands}.
1972 The @samp{--no-define-common} option allows decoupling
1973 the decision to assign addresses to Common symbols from the choice
1974 of the output file type; otherwise a non-Relocatable output type
1975 forces assigning addresses to Common symbols.
1976 Using @samp{--no-define-common} allows Common symbols that are referenced
1977 from a shared library to be assigned addresses only in the main program.
1978 This eliminates the unused duplicate space in the shared library,
1979 and also prevents any possible confusion over resolving to the wrong
1980 duplicate when there are many dynamic modules with specialized search
1981 paths for runtime symbol resolution.
1983 @cindex group allocation in linker script
1984 @cindex section groups
1986 @kindex --force-group-allocation
1987 @item --force-group-allocation
1988 This option causes the linker to place section group members like
1989 normal input sections, and to delete the section groups. This is the
1990 default behaviour for a final link but this option can be used to
1991 change the behaviour of a relocatable link (@samp{-r}). The script
1992 command @code{FORCE_GROUP_ALLOCATION} has the same
1993 effect. @xref{Miscellaneous Commands}.
1995 @cindex symbols, from command line
1996 @kindex --defsym=@var{symbol}=@var{exp}
1997 @item --defsym=@var{symbol}=@var{expression}
1998 Create a global symbol in the output file, containing the absolute
1999 address given by @var{expression}. You may use this option as many
2000 times as necessary to define multiple symbols in the command line. A
2001 limited form of arithmetic is supported for the @var{expression} in this
2002 context: you may give a hexadecimal constant or the name of an existing
2003 symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
2004 constants or symbols. If you need more elaborate expressions, consider
2005 using the linker command language from a script (@pxref{Assignments}).
2006 @emph{Note:} there should be no white space between @var{symbol}, the
2007 equals sign (``@key{=}''), and @var{expression}.
2009 The linker processes @samp{--defsym} arguments and @samp{-T} arguments
2010 in order, placing @samp{--defsym} before @samp{-T} will define the
2011 symbol before the linker script from @samp{-T} is processed, while
2012 placing @samp{--defsym} after @samp{-T} will define the symbol after
2013 the linker script has been processed. This difference has
2014 consequences for expressions within the linker script that use the
2015 @samp{--defsym} symbols, which order is correct will depend on what
2016 you are trying to achieve.
2018 @cindex demangling, from command line
2019 @kindex --demangle[=@var{style}]
2020 @kindex --no-demangle
2021 @item --demangle[=@var{style}]
2022 @itemx --no-demangle
2023 These options control whether to demangle symbol names in error messages
2024 and other output. When the linker is told to demangle, it tries to
2025 present symbol names in a readable fashion: it strips leading
2026 underscores if they are used by the object file format, and converts C++
2027 mangled symbol names into user readable names. Different compilers have
2028 different mangling styles. The optional demangling style argument can be used
2029 to choose an appropriate demangling style for your compiler. The linker will
2030 demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
2031 is set. These options may be used to override the default.
2033 @cindex dynamic linker, from command line
2034 @kindex -I@var{file}
2035 @kindex --dynamic-linker=@var{file}
2037 @itemx --dynamic-linker=@var{file}
2038 Set the name of the dynamic linker. This is only meaningful when
2039 generating dynamically linked ELF executables. The default dynamic
2040 linker is normally correct; don't use this unless you know what you are
2043 @kindex --no-dynamic-linker
2044 @item --no-dynamic-linker
2045 When producing an executable file, omit the request for a dynamic
2046 linker to be used at load-time. This is only meaningful for ELF
2047 executables that contain dynamic relocations, and usually requires
2048 entry point code that is capable of processing these relocations.
2050 @kindex --embedded-relocs
2051 @item --embedded-relocs
2052 This option is similar to the @option{--emit-relocs} option except
2053 that the relocs are stored in a target-specific section. This option
2054 is only supported by the @samp{BFIN}, @samp{CR16} and @emph{M68K}
2057 @kindex --disable-multiple-abs-defs
2058 @item --disable-multiple-abs-defs
2059 Do not allow multiple definitions with symbols included
2060 in filename invoked by -R or --just-symbols
2062 @kindex --fatal-warnings
2063 @kindex --no-fatal-warnings
2064 @item --fatal-warnings
2065 @itemx --no-fatal-warnings
2066 Treat all warnings as errors. The default behaviour can be restored
2067 with the option @option{--no-fatal-warnings}.
2070 @kindex --no-warnings
2072 @itemx --no-warnings
2073 Do not display any warning or error messages. This overrides
2074 @option{--fatal-warnings} if it has been enabled. This option can be
2075 used when it is known that the output binary will not work, but there
2076 is still a need to create it.
2078 @kindex --force-exe-suffix
2079 @item --force-exe-suffix
2080 Make sure that an output file has a .exe suffix.
2082 If a successfully built fully linked output file does not have a
2083 @code{.exe} or @code{.dll} suffix, this option forces the linker to copy
2084 the output file to one of the same name with a @code{.exe} suffix. This
2085 option is useful when using unmodified Unix makefiles on a Microsoft
2086 Windows host, since some versions of Windows won't run an image unless
2087 it ends in a @code{.exe} suffix.
2089 @kindex --gc-sections
2090 @kindex --no-gc-sections
2091 @cindex garbage collection
2093 @itemx --no-gc-sections
2094 Enable garbage collection of unused input sections. It is ignored on
2095 targets that do not support this option. The default behaviour (of not
2096 performing this garbage collection) can be restored by specifying
2097 @samp{--no-gc-sections} on the command line. Note that garbage
2098 collection for COFF and PE format targets is supported, but the
2099 implementation is currently considered to be experimental.
2101 @samp{--gc-sections} decides which input sections are used by
2102 examining symbols and relocations. The section containing the entry
2103 symbol and all sections containing symbols undefined on the
2104 command-line will be kept, as will sections containing symbols
2105 referenced by dynamic objects. Note that when building shared
2106 libraries, the linker must assume that any visible symbol is
2107 referenced. Once this initial set of sections has been determined,
2108 the linker recursively marks as used any section referenced by their
2109 relocations. See @samp{--entry}, @samp{--undefined}, and
2110 @samp{--gc-keep-exported}.
2112 This option can be set when doing a partial link (enabled with option
2113 @samp{-r}). In this case the root of symbols kept must be explicitly
2114 specified either by one of the options @samp{--entry},
2115 @samp{--undefined}, or @samp{--gc-keep-exported} or by a @code{ENTRY}
2116 command in the linker script.
2118 As a GNU extension, ELF input sections marked with the
2119 @code{SHF_GNU_RETAIN} flag will not be garbage collected.
2121 @kindex --print-gc-sections
2122 @kindex --no-print-gc-sections
2123 @cindex garbage collection
2124 @item --print-gc-sections
2125 @itemx --no-print-gc-sections
2126 List all sections removed by garbage collection. The listing is
2127 printed on stderr. This option is only effective if garbage
2128 collection has been enabled via the @samp{--gc-sections}) option. The
2129 default behaviour (of not listing the sections that are removed) can
2130 be restored by specifying @samp{--no-print-gc-sections} on the command
2133 @kindex --gc-keep-exported
2134 @cindex garbage collection
2135 @item --gc-keep-exported
2136 When @samp{--gc-sections} is enabled, this option prevents garbage
2137 collection of unused input sections that contain global symbols having
2138 default or protected visibility. This option is intended to be used for
2139 executables where unreferenced sections would otherwise be garbage
2140 collected regardless of the external visibility of contained symbols.
2141 Note that this option has no effect when linking shared objects since
2142 it is already the default behaviour. This option is only supported for
2145 @kindex --print-output-format
2146 @cindex output format
2147 @item --print-output-format
2148 Print the name of the default output format (perhaps influenced by
2149 other command-line options). This is the string that would appear
2150 in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
2152 @kindex --print-memory-usage
2153 @cindex memory usage
2154 @item --print-memory-usage
2155 Print used size, total size and used size of memory regions created with
2156 the @ref{MEMORY} command. This is useful on embedded targets to have a
2157 quick view of amount of free memory. The format of the output has one
2158 headline and one line per region. It is both human readable and easily
2159 parsable by tools. Here is an example of an output:
2162 Memory region Used Size Region Size %age Used
2163 ROM: 256 KB 1 MB 25.00%
2164 RAM: 32 B 2 GB 0.00%
2171 Print a summary of the command-line options on the standard output and exit.
2173 @kindex --target-help
2175 Print a summary of all target-specific options on the standard output and exit.
2177 @kindex -Map=@var{mapfile}
2178 @item -Map=@var{mapfile}
2179 Print a link map to the file @var{mapfile}. See the description of the
2180 @option{-M} option, above. If @var{mapfile} is just the character
2181 @code{-} then the map will be written to stdout.
2183 Specifying a directory as @var{mapfile} causes the linker map to be
2184 written as a file inside the directory. Normally name of the file
2185 inside the directory is computed as the basename of the @var{output}
2186 file with @code{.map} appended. If however the special character
2187 @code{%} is used then this will be replaced by the full path of the
2188 output file. Additionally if there are any characters after the
2189 @var{%} symbol then @code{.map} will no longer be appended.
2192 -o foo.exe -Map=bar [Creates ./bar]
2193 -o ../dir/foo.exe -Map=bar [Creates ./bar]
2194 -o foo.exe -Map=../dir [Creates ../dir/foo.exe.map]
2195 -o ../dir2/foo.exe -Map=../dir [Creates ../dir/foo.exe.map]
2196 -o foo.exe -Map=% [Creates ./foo.exe.map]
2197 -o ../dir/foo.exe -Map=% [Creates ../dir/foo.exe.map]
2198 -o foo.exe -Map=%.bar [Creates ./foo.exe.bar]
2199 -o ../dir/foo.exe -Map=%.bar [Creates ../dir/foo.exe.bar]
2200 -o ../dir2/foo.exe -Map=../dir/% [Creates ../dir/../dir2/foo.exe.map]
2201 -o ../dir2/foo.exe -Map=../dir/%.bar [Creates ../dir/../dir2/foo.exe.bar]
2204 It is an error to specify more than one @code{%} character.
2206 If the map file already exists then it will be overwritten by this
2209 @cindex memory usage
2210 @kindex --no-keep-memory
2211 @item --no-keep-memory
2212 @command{ld} normally optimizes for speed over memory usage by caching the
2213 symbol tables of input files in memory. This option tells @command{ld} to
2214 instead optimize for memory usage, by rereading the symbol tables as
2215 necessary. This may be required if @command{ld} runs out of memory space
2216 while linking a large executable.
2218 @kindex --no-undefined
2221 @item --no-undefined
2223 Report unresolved symbol references from regular object files. This
2224 is done even if the linker is creating a non-symbolic shared library.
2225 The switch @option{--[no-]allow-shlib-undefined} controls the
2226 behaviour for reporting unresolved references found in shared
2227 libraries being linked in.
2229 The effects of this option can be reverted by using @code{-z undefs}.
2231 @kindex --allow-multiple-definition
2233 @item --allow-multiple-definition
2235 Normally when a symbol is defined multiple times, the linker will
2236 report a fatal error. These options allow multiple definitions and the
2237 first definition will be used.
2239 @kindex --allow-shlib-undefined
2240 @kindex --no-allow-shlib-undefined
2241 @item --allow-shlib-undefined
2242 @itemx --no-allow-shlib-undefined
2243 Allows or disallows undefined symbols in shared libraries.
2244 This switch is similar to @option{--no-undefined} except that it
2245 determines the behaviour when the undefined symbols are in a
2246 shared library rather than a regular object file. It does not affect
2247 how undefined symbols in regular object files are handled.
2249 The default behaviour is to report errors for any undefined symbols
2250 referenced in shared libraries if the linker is being used to create
2251 an executable, but to allow them if the linker is being used to create
2254 The reasons for allowing undefined symbol references in shared
2255 libraries specified at link time are that:
2259 A shared library specified at link time may not be the same as the one
2260 that is available at load time, so the symbol might actually be
2261 resolvable at load time.
2263 There are some operating systems, eg BeOS and HPPA, where undefined
2264 symbols in shared libraries are normal.
2266 The BeOS kernel for example patches shared libraries at load time to
2267 select whichever function is most appropriate for the current
2268 architecture. This is used, for example, to dynamically select an
2269 appropriate memset function.
2272 @kindex --error-handling-script=@var{scriptname}
2273 @item --error-handling-script=@var{scriptname}
2274 If this option is provided then the linker will invoke
2275 @var{scriptname} whenever an error is encountered. Currently however
2276 only two kinds of error are supported: missing symbols and missing
2277 libraries. Two arguments will be passed to script: the keyword
2278 ``undefined-symbol'' or `missing-lib'' and the @var{name} of the
2279 undefined symbol or missing library. The intention is that the script
2280 will provide suggestions to the user as to where the symbol or library
2281 might be found. After the script has finished then the normal linker
2282 error message will be displayed.
2284 The availability of this option is controlled by a configure time
2285 switch, so it may not be present in specific implementations.
2287 @kindex --no-undefined-version
2288 @item --no-undefined-version
2289 Normally when a symbol has an undefined version, the linker will ignore
2290 it. This option disallows symbols with undefined version and a fatal error
2291 will be issued instead.
2293 @kindex --default-symver
2294 @item --default-symver
2295 Create and use a default symbol version (the soname) for unversioned
2298 @kindex --default-imported-symver
2299 @item --default-imported-symver
2300 Create and use a default symbol version (the soname) for unversioned
2303 @kindex --no-warn-mismatch
2304 @item --no-warn-mismatch
2305 Normally @command{ld} will give an error if you try to link together input
2306 files that are mismatched for some reason, perhaps because they have
2307 been compiled for different processors or for different endiannesses.
2308 This option tells @command{ld} that it should silently permit such possible
2309 errors. This option should only be used with care, in cases when you
2310 have taken some special action that ensures that the linker errors are
2313 @kindex --no-warn-search-mismatch
2314 @item --no-warn-search-mismatch
2315 Normally @command{ld} will give a warning if it finds an incompatible
2316 library during a library search. This option silences the warning.
2318 @kindex --no-whole-archive
2319 @item --no-whole-archive
2320 Turn off the effect of the @option{--whole-archive} option for subsequent
2323 @cindex output file after errors
2324 @kindex --noinhibit-exec
2325 @item --noinhibit-exec
2326 Retain the executable output file whenever it is still usable.
2327 Normally, the linker will not produce an output file if it encounters
2328 errors during the link process; it exits without writing an output file
2329 when it issues any error whatsoever.
2333 Only search library directories explicitly specified on the
2334 command line. Library directories specified in linker scripts
2335 (including linker scripts specified on the command line) are ignored.
2337 @ifclear SingleFormat
2338 @kindex --oformat=@var{output-format}
2339 @item --oformat=@var{output-format}
2340 @command{ld} may be configured to support more than one kind of object
2341 file. If your @command{ld} is configured this way, you can use the
2342 @samp{--oformat} option to specify the binary format for the output
2343 object file. Even when @command{ld} is configured to support alternative
2344 object formats, you don't usually need to specify this, as @command{ld}
2345 should be configured to produce as a default output format the most
2346 usual format on each machine. @var{output-format} is a text string, the
2347 name of a particular format supported by the BFD libraries. (You can
2348 list the available binary formats with @samp{objdump -i}.) The script
2349 command @code{OUTPUT_FORMAT} can also specify the output format, but
2350 this option overrides it. @xref{BFD}.
2353 @kindex --out-implib
2354 @item --out-implib @var{file}
2355 Create an import library in @var{file} corresponding to the executable
2356 the linker is generating (eg. a DLL or ELF program). This import
2357 library (which should be called @code{*.dll.a} or @code{*.a} for DLLs)
2358 may be used to link clients against the generated executable; this
2359 behaviour makes it possible to skip a separate import library creation
2360 step (eg. @code{dlltool} for DLLs). This option is only available for
2361 the i386 PE and ELF targetted ports of the linker.
2364 @kindex --pic-executable
2366 @itemx --pic-executable
2367 @cindex position independent executables
2368 Create a position independent executable. This is currently only
2369 supported on ELF platforms. Position independent executables are
2370 relocated by the dynamic linker to the virtual address the OS chooses
2371 for them, which can vary between invocations. They are marked ET_DYN
2372 in the ELF file header, but differ from shared libraries in a number
2373 of ways. In particular, defined symbols in a PIE by default can not
2374 be overridden by another object as they can be in a shared library.
2378 @cindex position dependent executables
2379 Create a position dependent executable. This is the default.
2383 This option is ignored for Linux compatibility.
2387 This option is ignored for SVR4 compatibility.
2390 @cindex synthesizing linker
2391 @cindex relaxing addressing modes
2395 An option with machine dependent effects.
2397 This option is only supported on a few targets.
2400 @xref{H8/300,,@command{ld} and the H8/300}.
2403 @xref{Xtensa,, @command{ld} and Xtensa Processors}.
2406 @xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
2409 @xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}.
2412 On some platforms the @option{--relax} option performs target specific,
2413 global optimizations that become possible when the linker resolves
2414 addressing in the program, such as relaxing address modes,
2415 synthesizing new instructions, selecting shorter version of current
2416 instructions, and combining constant values.
2418 On some platforms these link time global optimizations may make symbolic
2419 debugging of the resulting executable impossible.
2421 This is known to be the case for the Matsushita MN10200 and MN10300
2422 family of processors.
2425 On platforms where the feature is supported, the option
2426 @option{--no-relax} will disable it.
2428 On platforms where the feature is not supported, both @option{--relax}
2429 and @option{--no-relax} are accepted, but ignored.
2431 @cindex retaining specified symbols
2432 @cindex stripping all but some symbols
2433 @cindex symbols, retaining selectively
2434 @kindex --retain-symbols-file=@var{filename}
2435 @item --retain-symbols-file=@var{filename}
2436 Retain @emph{only} the symbols listed in the file @var{filename},
2437 discarding all others. @var{filename} is simply a flat file, with one
2438 symbol name per line. This option is especially useful in environments
2442 where a large global symbol table is accumulated gradually, to conserve
2445 @samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
2446 or symbols needed for relocations.
2448 You may only specify @samp{--retain-symbols-file} once in the command
2449 line. It overrides @samp{-s} and @samp{-S}.
2452 @item -rpath=@var{dir}
2453 @cindex runtime library search path
2454 @kindex -rpath=@var{dir}
2455 Add a directory to the runtime library search path. This is used when
2456 linking an ELF executable with shared objects. All @option{-rpath}
2457 arguments are concatenated and passed to the runtime linker, which uses
2458 them to locate shared objects at runtime.
2460 The @option{-rpath} option is also used when locating shared objects which
2461 are needed by shared objects explicitly included in the link; see the
2462 description of the @option{-rpath-link} option. Searching @option{-rpath}
2463 in this way is only supported by native linkers and cross linkers which
2464 have been configured with the @option{--with-sysroot} option.
2466 If @option{-rpath} is not used when linking an ELF executable, the
2467 contents of the environment variable @code{LD_RUN_PATH} will be used if it
2470 The @option{-rpath} option may also be used on SunOS. By default, on
2471 SunOS, the linker will form a runtime search path out of all the
2472 @option{-L} options it is given. If a @option{-rpath} option is used, the
2473 runtime search path will be formed exclusively using the @option{-rpath}
2474 options, ignoring the @option{-L} options. This can be useful when using
2475 gcc, which adds many @option{-L} options which may be on NFS mounted
2478 For compatibility with other ELF linkers, if the @option{-R} option is
2479 followed by a directory name, rather than a file name, it is treated as
2480 the @option{-rpath} option.
2484 @cindex link-time runtime library search path
2485 @kindex -rpath-link=@var{dir}
2486 @item -rpath-link=@var{dir}
2487 When using ELF or SunOS, one shared library may require another. This
2488 happens when an @code{ld -shared} link includes a shared library as one
2491 When the linker encounters such a dependency when doing a non-shared,
2492 non-relocatable link, it will automatically try to locate the required
2493 shared library and include it in the link, if it is not included
2494 explicitly. In such a case, several directories are searched as
2495 described below. The @option{-rpath-link} option specifies the first
2496 set of directories to search. This option may specify a sequence of
2497 directory names either by providing a list of names separated by
2498 colons, or by appearing multiple times.
2500 The tokens @var{$ORIGIN} and @var{$LIB} can appear in these search
2501 directories. They will be replaced by the full path to the directory
2502 containing the program or shared object in the case of @var{$ORIGIN}
2503 and either @samp{lib} - for 32-bit binaries - or @samp{lib64} - for
2504 64-bit binaries - in the case of @var{$LIB}.
2506 The alternative form of these tokens - @var{$@{ORIGIN@}} and
2507 @var{$@{LIB@}} can also be used. The token @var{$PLATFORM} is not
2510 The @option{--rpath-link} option should be used with caution as it
2511 overrides the search path that may have been hard compiled into a
2512 shared library. In such a case it is possible to unintentionally use
2513 a different search path than the runtime linker would have used.
2515 When additional shared libraries are required, the linker will search
2516 directories in the order listed below in order to find them. Note
2517 however that this only applies to additional libraries needed to
2518 satisfy already included shared libraries. It does @emph{not}
2519 apply to libraries that are included via the @option{-l} command line
2520 option. Searches for @option{-l} libraries are only conducted in
2521 directories specified by the @option{-L} option (@pxref{-L}).
2525 Any directories specified by @option{-rpath-link} options.
2527 Any directories specified by @option{-rpath} options. The difference
2528 between @option{-rpath} and @option{-rpath-link} is that directories
2529 specified by @option{-rpath} options are included in the executable and
2530 used at runtime, whereas the @option{-rpath-link} option is only effective
2531 at link time. Searching @option{-rpath} in this way is only supported
2532 by native linkers and cross linkers which have been configured with
2533 the @option{--with-sysroot} option.
2535 On an ELF system, for native linkers, if the @option{-rpath} and
2536 @option{-rpath-link} options were not used, search the contents of the
2537 environment variable @code{LD_RUN_PATH}.
2539 On SunOS, if the @option{-rpath} option was not used, search any
2540 directories specified using @option{-L} options.
2542 For a native linker, search the contents of the environment
2543 variable @code{LD_LIBRARY_PATH}.
2545 For a native ELF linker, the directories in @code{DT_RUNPATH} or
2546 @code{DT_RPATH} of a shared library are searched for shared
2547 libraries needed by it. The @code{DT_RPATH} entries are ignored if
2548 @code{DT_RUNPATH} entries exist.
2550 For a linker for a Linux system, if the file @file{/etc/ld.so.conf}
2551 exists, the list of directories found in that file. Note: the path
2552 to this file is prefixed with the @code{sysroot} value, if that is
2553 defined, and then any @code{prefix} string if the linker was
2554 configured with the @command{--prefix=<path>} option.
2556 For a native linker on a FreeBSD system, any directories specified by
2557 the @code{_PATH_ELF_HINTS} macro defined in the @file{elf-hints.h}
2560 Any directories specified by a @code{SEARCH_DIR} command in a
2561 linker script given on the command line, including scripts specified
2562 by @option{-T} (but not @option{-dT}).
2564 The default directories, normally @file{/lib} and @file{/usr/lib}.
2566 Any directories specified by a plugin LDPT_SET_EXTRA_LIBRARY_PATH.
2568 Any directories specified by a @code{SEARCH_DIR} command in a default
2572 Note however on Linux based systems there is an additional caveat: If
2573 the @option{--as-needed} option is active @emph{and} a shared library
2574 is located which would normally satisfy the search @emph{and} this
2575 library does not have DT_NEEDED tag for @file{libc.so}
2576 @emph{and} there is a shared library later on in the set of search
2577 directories which also satisfies the search @emph{and}
2578 this second shared library does have a DT_NEEDED tag for
2579 @file{libc.so} @emph{then} the second library will be selected instead
2582 If the required shared library is not found, the linker will issue a
2583 warning and continue with the link.
2587 @kindex --section-ordering-file
2588 @item --section-ordering-file=@var{script}
2589 @anchor{--section-ordering-file}
2590 This option is used to augment the current linker script with
2591 additional mapping of input sections to output sections. This file
2592 must use the same syntax for @code{SECTIONS} as is used in normal
2593 linker scripts, but it should not do anything other than place input
2594 sections into output sections. @pxref{SECTIONS}
2596 A second constraint on the section ordering script is that it can only
2597 reference output sections that are already defined by whichever linker
2598 script is currently in use. (Ie the default linker script or a script
2599 specified on the command line). The benefit of the section ordering
2600 script however is that the input sections are mapped to the start of
2601 the output sections, so that they can ensure the ordering of sections
2602 in the output section. For example, imagine that the default linker
2603 script looks like this:
2607 .text : @{ *(.text.hot) ; *(.text .text.*) @}
2608 .data : @{ *(.data.big) ; *(.data .data.*) @}
2612 Then if a section ordering file like this is used:
2615 .text : @{ *(.text.first) ; *(.text.z*) @}
2616 .data : @{ foo.o(.data.first) ; *(.data.small) @}
2619 This would be equivalent to a linker script like this:
2623 .text : @{ *(.text.first) ; *(.text.z*) ; *(.text.hot) ; *(.text .text.*) @}
2624 .data : @{ foo.o(.data.first) ; *(.data.small) ; *(.data.big) ; *(.data .data.*) @}
2628 The advantage of the section ordering file is that it can be used to
2629 order those sections that matter to the user without having to worry
2630 about any other sections, or memory regions, or anything else.
2636 @cindex shared libraries
2637 Create a shared library. This is currently only supported on ELF, XCOFF
2638 and SunOS platforms. On SunOS, the linker will automatically create a
2639 shared library if the @option{-e} option is not used and there are
2640 undefined symbols in the link.
2642 @kindex --sort-common
2644 @itemx --sort-common=ascending
2645 @itemx --sort-common=descending
2646 This option tells @command{ld} to sort the common symbols by alignment in
2647 ascending or descending order when it places them in the appropriate output
2648 sections. The symbol alignments considered are sixteen-byte or larger,
2649 eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
2650 between symbols due to alignment constraints. If no sorting order is
2651 specified, then descending order is assumed.
2653 @kindex --sort-section=name
2654 @item --sort-section=name
2655 This option will apply @code{SORT_BY_NAME} to all wildcard section
2656 patterns in the linker script.
2658 @kindex --sort-section=alignment
2659 @item --sort-section=alignment
2660 This option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
2661 patterns in the linker script.
2663 @kindex --spare-dynamic-tags
2664 @item --spare-dynamic-tags=@var{count}
2665 This option specifies the number of empty slots to leave in the
2666 .dynamic section of ELF shared objects. Empty slots may be needed by
2667 post processing tools, such as the prelinker. The default is 5.
2669 @kindex --split-by-file
2670 @item --split-by-file[=@var{size}]
2671 Similar to @option{--split-by-reloc} but creates a new output section for
2672 each input file when @var{size} is reached. @var{size} defaults to a
2673 size of 1 if not given.
2675 @kindex --split-by-reloc
2676 @item --split-by-reloc[=@var{count}]
2677 Tries to creates extra sections in the output file so that no single
2678 output section in the file contains more than @var{count} relocations.
2679 This is useful when generating huge relocatable files for downloading into
2680 certain real time kernels with the COFF object file format; since COFF
2681 cannot represent more than 65535 relocations in a single section. Note
2682 that this will fail to work with object file formats which do not
2683 support arbitrary sections. The linker will not split up individual
2684 input sections for redistribution, so if a single input section contains
2685 more than @var{count} relocations one output section will contain that
2686 many relocations. @var{count} defaults to a value of 32768.
2690 Compute and display statistics about the operation of the linker, such
2691 as execution time and memory usage.
2693 @kindex --sysroot=@var{directory}
2694 @item --sysroot=@var{directory}
2695 Use @var{directory} as the location of the sysroot, overriding the
2696 configure-time default. This option is only supported by linkers
2697 that were configured using @option{--with-sysroot}.
2701 This is used by COFF/PE based targets to create a task-linked object
2702 file where all of the global symbols have been converted to statics.
2704 @kindex --traditional-format
2705 @cindex traditional format
2706 @item --traditional-format
2707 For some targets, the output of @command{ld} is different in some ways from
2708 the output of some existing linker. This switch requests @command{ld} to
2709 use the traditional format instead.
2712 For example, on SunOS, @command{ld} combines duplicate entries in the
2713 symbol string table. This can reduce the size of an output file with
2714 full debugging information by over 30 percent. Unfortunately, the SunOS
2715 @code{dbx} program can not read the resulting program (@code{gdb} has no
2716 trouble). The @samp{--traditional-format} switch tells @command{ld} to not
2717 combine duplicate entries.
2719 @kindex --section-start=@var{sectionname}=@var{org}
2720 @item --section-start=@var{sectionname}=@var{org}
2721 Locate a section in the output file at the absolute
2722 address given by @var{org}. You may use this option as many
2723 times as necessary to locate multiple sections in the command
2725 @var{org} must be a single hexadecimal integer;
2726 for compatibility with other linkers, you may omit the leading
2727 @samp{0x} usually associated with hexadecimal values. @emph{Note:} there
2728 should be no white space between @var{sectionname}, the equals
2729 sign (``@key{=}''), and @var{org}.
2731 @kindex --image-base=@var{org}
2732 @item --image-base=@var{org}
2733 @cindex image base address, cmd line
2734 When using ELF, same as @option{-Ttext-segment}, with both options effectively
2735 setting the base address of the ELF executable.
2737 When using PE, use @var{value} as the base address of your program or dll.
2738 This is the lowest memory location that will be used when your program or
2739 dll is loaded. To reduce the need to relocate and improve performance of
2740 your dlls, each should have a unique base address and not overlap any
2741 other dlls. The default is 0x400000 for executables, and 0x10000000
2744 @kindex -Tbss=@var{org}
2745 @kindex -Tdata=@var{org}
2746 @kindex -Ttext=@var{org}
2747 @cindex segment origins, cmd line
2748 @item -Tbss=@var{org}
2749 @itemx -Tdata=@var{org}
2750 @itemx -Ttext=@var{org}
2751 Same as @option{--section-start}, with @code{.bss}, @code{.data} or
2752 @code{.text} as the @var{sectionname}.
2754 @kindex -Ttext-segment=@var{org}
2755 @item -Ttext-segment=@var{org}
2756 @cindex text segment origin, cmd line
2757 When creating an ELF executable, it will set the address of the first
2758 byte of the first segment. Note that when @option{-pie} is used with
2759 @option{-Ttext-segment=@var{org}}, the output executable is marked
2760 ET_EXEC so that the address of the first byte of the text segment will
2761 be guaranteed to be @var{org} at run time.
2763 @kindex -Trodata-segment=@var{org}
2764 @item -Trodata-segment=@var{org}
2765 @cindex rodata segment origin, cmd line
2766 When creating an ELF executable or shared object for a target where
2767 the read-only data is in its own segment separate from the executable
2768 text, it will set the address of the first byte of the read-only data segment.
2770 @kindex -Tldata-segment=@var{org}
2771 @item -Tldata-segment=@var{org}
2772 @cindex ldata segment origin, cmd line
2773 When creating an ELF executable or shared object for x86-64 medium memory
2774 model, it will set the address of the first byte of the ldata segment.
2776 @kindex --unresolved-symbols
2777 @item --unresolved-symbols=@var{method}
2778 Determine how to handle unresolved symbols. There are four possible
2779 values for @samp{method}:
2783 Do not report any unresolved symbols.
2786 Report all unresolved symbols. This is the default.
2788 @item ignore-in-object-files
2789 Report unresolved symbols that are contained in shared libraries, but
2790 ignore them if they come from regular object files.
2792 @item ignore-in-shared-libs
2793 Report unresolved symbols that come from regular object files, but
2794 ignore them if they come from shared libraries. This can be useful
2795 when creating a dynamic binary and it is known that all the shared
2796 libraries that it should be referencing are included on the linker's
2800 The behaviour for shared libraries on their own can also be controlled
2801 by the @option{--[no-]allow-shlib-undefined} option.
2803 Normally the linker will generate an error message for each reported
2804 unresolved symbol but the option @option{--warn-unresolved-symbols}
2805 can change this to a warning.
2807 @kindex --verbose[=@var{NUMBER}]
2808 @cindex verbose[=@var{NUMBER}]
2810 @itemx --verbose[=@var{NUMBER}]
2811 Display the version number for @command{ld} and list the linker emulations
2812 supported. Display which input files can and cannot be opened. Display
2813 the linker script being used by the linker. If the optional @var{NUMBER}
2814 argument > 1, plugin symbol status will also be displayed.
2816 @kindex --version-script=@var{version-scriptfile}
2817 @cindex version script, symbol versions
2818 @item --version-script=@var{version-scriptfile}
2819 Specify the name of a version script to the linker. This is typically
2820 used when creating shared libraries to specify additional information
2821 about the version hierarchy for the library being created. This option
2822 is only fully supported on ELF platforms which support shared libraries;
2823 see @ref{VERSION}. It is partially supported on PE platforms, which can
2824 use version scripts to filter symbol visibility in auto-export mode: any
2825 symbols marked @samp{local} in the version script will not be exported.
2828 @kindex --warn-common
2829 @cindex warnings, on combining symbols
2830 @cindex combining symbols, warnings on
2832 Warn when a common symbol is combined with another common symbol or with
2833 a symbol definition. Unix linkers allow this somewhat sloppy practice,
2834 but linkers on some other operating systems do not. This option allows
2835 you to find potential problems from combining global symbols.
2836 Unfortunately, some C libraries use this practice, so you may get some
2837 warnings about symbols in the libraries as well as in your programs.
2839 There are three kinds of global symbols, illustrated here by C examples:
2843 A definition, which goes in the initialized data section of the output
2847 An undefined reference, which does not allocate space.
2848 There must be either a definition or a common symbol for the
2852 A common symbol. If there are only (one or more) common symbols for a
2853 variable, it goes in the uninitialized data area of the output file.
2854 The linker merges multiple common symbols for the same variable into a
2855 single symbol. If they are of different sizes, it picks the largest
2856 size. The linker turns a common symbol into a declaration, if there is
2857 a definition of the same variable.
2860 The @samp{--warn-common} option can produce five kinds of warnings.
2861 Each warning consists of a pair of lines: the first describes the symbol
2862 just encountered, and the second describes the previous symbol
2863 encountered with the same name. One or both of the two symbols will be
2868 Turning a common symbol into a reference, because there is already a
2869 definition for the symbol.
2871 @var{file}(@var{section}): warning: common of `@var{symbol}'
2872 overridden by definition
2873 @var{file}(@var{section}): warning: defined here
2877 Turning a common symbol into a reference, because a later definition for
2878 the symbol is encountered. This is the same as the previous case,
2879 except that the symbols are encountered in a different order.
2881 @var{file}(@var{section}): warning: definition of `@var{symbol}'
2883 @var{file}(@var{section}): warning: common is here
2887 Merging a common symbol with a previous same-sized common symbol.
2889 @var{file}(@var{section}): warning: multiple common
2891 @var{file}(@var{section}): warning: previous common is here
2895 Merging a common symbol with a previous larger common symbol.
2897 @var{file}(@var{section}): warning: common of `@var{symbol}'
2898 overridden by larger common
2899 @var{file}(@var{section}): warning: larger common is here
2903 Merging a common symbol with a previous smaller common symbol. This is
2904 the same as the previous case, except that the symbols are
2905 encountered in a different order.
2907 @var{file}(@var{section}): warning: common of `@var{symbol}'
2908 overriding smaller common
2909 @var{file}(@var{section}): warning: smaller common is here
2913 @kindex --warn-constructors
2914 @item --warn-constructors
2915 Warn if any global constructors are used. This is only useful for a few
2916 object file formats. For formats like COFF or ELF, the linker can not
2917 detect the use of global constructors.
2919 @kindex --warn-execstack
2920 @cindex warnings, on executable stack
2921 @cindex executable stack, warnings on
2922 @item --warn-execstack
2923 @itemx --warn-execstack-objects
2924 @itemx --no-warn-execstack
2925 On ELF platforms the linker may generate warning messages if it is
2926 asked to create an output file that contains an executable stack.
2927 There are three possible states:
2930 Do not generate any warnings.
2932 Always generate warnings, even if the executable stack is requested
2933 via the @option{-z execstack} command line option.
2935 Only generate a warning if an object file requests an executable
2936 stack, but not if the @option{-z execstack} option is used.
2939 The default state depends upon how the linker was configured when it
2940 was built. The @option{--no-warn-execstack} option always puts the
2941 linker into the no-warnings state. The @option{--warn-execstack}
2942 option puts the linker into the warn-always state. The
2943 @option{--warn-execstack-objects} option puts the linker into the
2944 warn-for-object-files-only state.
2946 Note: ELF format input files can specify that they need an executable
2947 stack by having a @var{.note.GNU-stack} section with the executable
2948 bit set in its section flags. They can specify that they do not need
2949 an executable stack by having the same section, but without the
2950 executable flag bit set. If an input file does not have a
2951 @var{.note.GNU-stack} section then the default behaviour is target
2952 specific. For some targets, then absence of such a section implies
2953 that an executable stack @emph{is} required. This is often a problem
2954 for hand crafted assembler files.
2956 @kindex --error-execstack
2957 @item --error-execstack
2958 @itemx --no-error-execstack
2959 If the linker is going to generate a warning message about an
2960 executable stack then the @option{--error-execstack} option will
2961 instead change that warning into an error. Note - this option does
2962 not change the linker's execstack warning generation state. Use
2963 @option{--warn-execstack} or @option{--warn-execstack-objects} to set
2964 a specific warning state.
2966 The @option{--no-error-execstack} option will restore the default
2967 behaviour of generating warning messages.
2969 @kindex --warn-multiple-gp
2970 @item --warn-multiple-gp
2971 Warn if multiple global pointer values are required in the output file.
2972 This is only meaningful for certain processors, such as the Alpha.
2973 Specifically, some processors put large-valued constants in a special
2974 section. A special register (the global pointer) points into the middle
2975 of this section, so that constants can be loaded efficiently via a
2976 base-register relative addressing mode. Since the offset in
2977 base-register relative mode is fixed and relatively small (e.g., 16
2978 bits), this limits the maximum size of the constant pool. Thus, in
2979 large programs, it is often necessary to use multiple global pointer
2980 values in order to be able to address all possible constants. This
2981 option causes a warning to be issued whenever this case occurs.
2984 @cindex warnings, on undefined symbols
2985 @cindex undefined symbols, warnings on
2987 Only warn once for each undefined symbol, rather than once per module
2990 @kindex --warn-rwx-segments
2991 @cindex warnings, on writeable and exectuable segments
2992 @cindex executable segments, warnings on
2993 @item --warn-rwx-segments
2994 @itemx --no-warn-rwx-segments
2995 Warn if the linker creates a loadable, non-zero sized segment that has
2996 all three of the read, write and execute permission flags set. Such a
2997 segment represents a potential security vulnerability. In addition
2998 warnings will be generated if a thread local storage segment is
2999 created with the execute permission flag set, regardless of whether or
3000 not it has the read and/or write flags set.
3002 These warnings are enabled by default. They can be disabled via the
3003 @option{--no-warn-rwx-segments} option and re-enabled via the
3004 @option{--warn-rwx-segments} option.
3006 @kindex --error-rwx-segments
3007 @item --error-rwx-segments
3008 @itemx --no-error-rwx-segments
3009 If the linker is going to generate a warning message about an
3010 executable, writeable segment, or an executable TLS segment, then the
3011 @option{--error-rwx-segments} option will turn this warning into an
3012 error instead. The @option{--no-error-rwx-segments} option will
3013 restore the default behaviour of just generating a warning message.
3015 Note - the @option{--error-rwx-segments} option does not by itself
3016 turn on warnings about these segments. These warnings are either
3017 enabled by default, if the linker was configured that way, or via the
3018 @option{--warn-rwx-segments} command line option.
3020 @kindex --warn-section-align
3021 @cindex warnings, on section alignment
3022 @cindex section alignment, warnings on
3023 @item --warn-section-align
3024 Warn if the address of an output section is changed because of
3025 alignment. Typically, the alignment will be set by an input section.
3026 The address will only be changed if it not explicitly specified; that
3027 is, if the @code{SECTIONS} command does not specify a start address for
3028 the section (@pxref{SECTIONS}).
3030 @kindex --warn-textrel
3031 @item --warn-textrel
3032 Warn if the linker adds DT_TEXTREL to a position-independent executable
3035 @kindex --warn-alternate-em
3036 @item --warn-alternate-em
3037 Warn if an object has alternate ELF machine code.
3039 @kindex --warn-unresolved-symbols
3040 @item --warn-unresolved-symbols
3041 If the linker is going to report an unresolved symbol (see the option
3042 @option{--unresolved-symbols}) it will normally generate an error.
3043 This option makes it generate a warning instead.
3045 @kindex --error-unresolved-symbols
3046 @item --error-unresolved-symbols
3047 This restores the linker's default behaviour of generating errors when
3048 it is reporting unresolved symbols.
3050 @kindex --whole-archive
3051 @cindex including an entire archive
3052 @item --whole-archive
3053 For each archive mentioned on the command line after the
3054 @option{--whole-archive} option, include every object file in the archive
3055 in the link, rather than searching the archive for the required object
3056 files. This is normally used to turn an archive file into a shared
3057 library, forcing every object to be included in the resulting shared
3058 library. This option may be used more than once.
3060 Two notes when using this option from gcc: First, gcc doesn't know
3061 about this option, so you have to use @option{-Wl,-whole-archive}.
3062 Second, don't forget to use @option{-Wl,-no-whole-archive} after your
3063 list of archives, because gcc will add its own list of archives to
3064 your link and you may not want this flag to affect those as well.
3066 @kindex --wrap=@var{symbol}
3067 @item --wrap=@var{symbol}
3068 Use a wrapper function for @var{symbol}. Any undefined reference to
3069 @var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any
3070 undefined reference to @code{__real_@var{symbol}} will be resolved to
3073 This can be used to provide a wrapper for a system function. The
3074 wrapper function should be called @code{__wrap_@var{symbol}}. If it
3075 wishes to call the system function, it should call
3076 @code{__real_@var{symbol}}.
3078 Here is a trivial example:
3082 __wrap_malloc (size_t c)
3084 printf ("malloc called with %zu\n", c);
3085 return __real_malloc (c);
3089 If you link other code with this file using @option{--wrap malloc}, then
3090 all calls to @code{malloc} will call the function @code{__wrap_malloc}
3091 instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will
3092 call the real @code{malloc} function.
3094 You may wish to provide a @code{__real_malloc} function as well, so that
3095 links without the @option{--wrap} option will succeed. If you do this,
3096 you should not put the definition of @code{__real_malloc} in the same
3097 file as @code{__wrap_malloc}; if you do, the assembler may resolve the
3098 call before the linker has a chance to wrap it to @code{malloc}.
3100 Only undefined references are replaced by the linker. So, translation unit
3101 internal references to @var{symbol} are not resolved to
3102 @code{__wrap_@var{symbol}}. In the next example, the call to @code{f} in
3103 @code{g} is not resolved to @code{__wrap_f}.
3119 @kindex --eh-frame-hdr
3120 @kindex --no-eh-frame-hdr
3121 @item --eh-frame-hdr
3122 @itemx --no-eh-frame-hdr
3123 Request (@option{--eh-frame-hdr}) or suppress
3124 (@option{--no-eh-frame-hdr}) the creation of @code{.eh_frame_hdr}
3125 section and ELF @code{PT_GNU_EH_FRAME} segment header.
3127 @kindex --ld-generated-unwind-info
3128 @item --no-ld-generated-unwind-info
3129 Request creation of @code{.eh_frame} unwind info for linker
3130 generated code sections like PLT. This option is on by default
3131 if linker generated unwind info is supported. This option also
3132 controls the generation of @code{.sframe} stack trace info for linker
3133 generated code sections like PLT.
3135 @kindex --enable-new-dtags
3136 @kindex --disable-new-dtags
3137 @item --enable-new-dtags
3138 @itemx --disable-new-dtags
3139 This linker can create the new dynamic tags in ELF. But the older ELF
3140 systems may not understand them. If you specify
3141 @option{--enable-new-dtags}, the new dynamic tags will be created as needed
3142 and older dynamic tags will be omitted.
3143 If you specify @option{--disable-new-dtags}, no new dynamic tags will be
3144 created. By default, the new dynamic tags are not created. Note that
3145 those options are only available for ELF systems.
3147 @kindex --hash-size=@var{number}
3148 @item --hash-size=@var{number}
3149 Set the default size of the linker's hash tables to a prime number
3150 close to @var{number}. Increasing this value can reduce the length of
3151 time it takes the linker to perform its tasks, at the expense of
3152 increasing the linker's memory requirements. Similarly reducing this
3153 value can reduce the memory requirements at the expense of speed.
3155 @kindex --hash-style=@var{style}
3156 @item --hash-style=@var{style}
3157 Set the type of linker's hash table(s). @var{style} can be either
3158 @code{sysv} for classic ELF @code{.hash} section, @code{gnu} for
3159 new style GNU @code{.gnu.hash} section or @code{both} for both
3160 the classic ELF @code{.hash} and new style GNU @code{.gnu.hash}
3161 hash tables. The default depends upon how the linker was configured,
3162 but for most Linux based systems it will be @code{both}.
3164 @kindex --compress-debug-sections=none
3165 @kindex --compress-debug-sections=zlib
3166 @kindex --compress-debug-sections=zlib-gnu
3167 @kindex --compress-debug-sections=zlib-gabi
3168 @kindex --compress-debug-sections=zstd
3169 @item --compress-debug-sections=none
3170 @itemx --compress-debug-sections=zlib
3171 @itemx --compress-debug-sections=zlib-gnu
3172 @itemx --compress-debug-sections=zlib-gabi
3173 @itemx --compress-debug-sections=zstd
3174 On ELF platforms, these options control how DWARF debug sections are
3175 compressed using zlib.
3177 @option{--compress-debug-sections=none} doesn't compress DWARF debug
3178 sections. @option{--compress-debug-sections=zlib-gnu} compresses
3179 DWARF debug sections and renames them to begin with @samp{.zdebug}
3180 instead of @samp{.debug}. @option{--compress-debug-sections=zlib-gabi}
3181 also compresses DWARF debug sections, but rather than renaming them it
3182 sets the SHF_COMPRESSED flag in the sections' headers.
3184 The @option{--compress-debug-sections=zlib} option is an alias for
3185 @option{--compress-debug-sections=zlib-gabi}.
3187 @option{--compress-debug-sections=zstd} compresses DWARF debug sections using
3190 Note that this option overrides any compression in input debug
3191 sections, so if a binary is linked with @option{--compress-debug-sections=none}
3192 for example, then any compressed debug sections in input files will be
3193 uncompressed before they are copied into the output binary.
3195 The default compression behaviour varies depending upon the target
3196 involved and the configure options used to build the toolchain. The
3197 default can be determined by examining the output from the linker's
3198 @option{--help} option.
3200 @kindex --reduce-memory-overheads
3201 @item --reduce-memory-overheads
3202 This option reduces memory requirements at ld runtime, at the expense of
3203 linking speed. This was introduced to select the old O(n^2) algorithm
3204 for link map file generation, rather than the new O(n) algorithm which uses
3205 about 40% more memory for symbol storage.
3207 Another effect of the switch is to set the default hash table size to
3208 1021, which again saves memory at the cost of lengthening the linker's
3209 run time. This is not done however if the @option{--hash-size} switch
3212 The @option{--reduce-memory-overheads} switch may be also be used to
3213 enable other tradeoffs in future versions of the linker.
3215 @kindex --max-cache-size=@var{size}
3216 @item --max-cache-size=@var{size}
3217 @command{ld} normally caches the relocation information and symbol tables
3218 of input files in memory with the unlimited size. This option sets the
3219 maximum cache size to @var{size}.
3222 @kindex --build-id=@var{style}
3224 @itemx --build-id=@var{style}
3225 Request the creation of a @code{.note.gnu.build-id} ELF note section
3226 or a @code{.buildid} COFF section. The contents of the note are
3227 unique bits identifying this linked file. @var{style} can be
3228 @code{uuid} to use 128 random bits; @code{sha1} to use a 160-bit
3229 @sc{SHA1} hash, @code{md5} to use a 128-bit @sc{MD5} hash, or @code{xx}
3230 to use a 128-bit @sc{XXHASH} on the normative parts of the output
3231 contents; or @code{0x@var{hexstring}} to use a chosen bit string
3232 specified as an even number of hexadecimal digits (@code{-} and
3233 @code{:} characters between digit pairs are ignored). If @var{style}
3234 is omitted, @code{sha1} is used.
3236 The @code{md5}, @code{sha1}, and @code{xx} styles produces an
3237 identifier that is always the same in an identical output file, but
3238 are almost certainly unique among all nonidentical output files. It
3239 is not intended to be compared as a checksum for the file's contents.
3240 A linked file may be changed later by other tools, but the build ID
3241 bit string identifying the original linked file does not change.
3243 Passing @code{none} for @var{style} disables the setting from any
3244 @code{--build-id} options earlier on the command line.
3246 @kindex --package-metadata=@var{JSON}
3247 @item --package-metadata=@var{JSON}
3248 Request the creation of a @code{.note.package} ELF note section. The
3249 contents of the note are in JSON format, as per the package metadata
3250 specification. For more information see:
3251 https://systemd.io/ELF_PACKAGE_METADATA/
3252 The JSON argument support percent-encoding and following %[string]
3253 (where string refers to the name in HTML's Named Character References)
3254 encoding: @samp{%[comma]} for @samp{,}, @samp{%[lbrace]} for @samp{@{},
3255 @samp{%[quot]} for @samp{"}, @samp{%[rbrace]} for @samp{@}}, and
3256 @samp{%[space]} for space character.
3257 If the JSON argument is missing/empty then this will disable the
3258 creation of the metadata note, if one had been enabled by an earlier
3259 occurrence of the --package-metadata option.
3260 If the linker has been built with libjansson, then the JSON string
3266 @subsection Options Specific to i386 PE Targets
3268 @c man begin OPTIONS
3270 The i386 PE linker supports the @option{-shared} option, which causes
3271 the output to be a dynamically linked library (DLL) instead of a
3272 normal executable. You should name the output @code{*.dll} when you
3273 use this option. In addition, the linker fully supports the standard
3274 @code{*.def} files, which may be specified on the linker command line
3275 like an object file (in fact, it should precede archives it exports
3276 symbols from, to ensure that they get linked in, just like a normal
3279 In addition to the options common to all targets, the i386 PE linker
3280 support additional command-line options that are specific to the i386
3281 PE target. Options that take values may be separated from their
3282 values by either a space or an equals sign.
3286 @kindex --add-stdcall-alias
3287 @item --add-stdcall-alias
3288 If given, symbols with a stdcall suffix (@@@var{nn}) will be exported
3289 as-is and also with the suffix stripped.
3290 [This option is specific to the i386 PE targeted port of the linker]
3293 @item --base-file @var{file}
3294 Use @var{file} as the name of a file in which to save the base
3295 addresses of all the relocations needed for generating DLLs with
3297 [This is an i386 PE specific option]
3301 Create a DLL instead of a regular executable. You may also use
3302 @option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
3304 [This option is specific to the i386 PE targeted port of the linker]
3306 @kindex --enable-long-section-names
3307 @kindex --disable-long-section-names
3308 @item --enable-long-section-names
3309 @itemx --disable-long-section-names
3310 The PE variants of the COFF object format add an extension that permits
3311 the use of section names longer than eight characters, the normal limit
3312 for COFF. By default, these names are only allowed in object files, as
3313 fully-linked executable images do not carry the COFF string table required
3314 to support the longer names. As a GNU extension, it is possible to
3315 allow their use in executable images as well, or to (probably pointlessly!)
3316 disallow it in object files, by using these two options. Executable images
3317 generated with these long section names are slightly non-standard, carrying
3318 as they do a string table, and may generate confusing output when examined
3319 with non-GNU PE-aware tools, such as file viewers and dumpers. However,
3320 GDB relies on the use of PE long section names to find Dwarf-2 debug
3321 information sections in an executable image at runtime, and so if neither
3322 option is specified on the command-line, @command{ld} will enable long
3323 section names, overriding the default and technically correct behaviour,
3324 when it finds the presence of debug information while linking an executable
3325 image and not stripping symbols.
3326 [This option is valid for all PE targeted ports of the linker]
3328 @kindex --enable-stdcall-fixup
3329 @kindex --disable-stdcall-fixup
3330 @item --enable-stdcall-fixup
3331 @itemx --disable-stdcall-fixup
3332 If the link finds a symbol that it cannot resolve, it will attempt to
3333 do ``fuzzy linking'' by looking for another defined symbol that differs
3334 only in the format of the symbol name (cdecl vs stdcall) and will
3335 resolve that symbol by linking to the match. For example, the
3336 undefined symbol @code{_foo} might be linked to the function
3337 @code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
3338 to the function @code{_bar}. When the linker does this, it prints a
3339 warning, since it normally should have failed to link, but sometimes
3340 import libraries generated from third-party dlls may need this feature
3341 to be usable. If you specify @option{--enable-stdcall-fixup}, this
3342 feature is fully enabled and warnings are not printed. If you specify
3343 @option{--disable-stdcall-fixup}, this feature is disabled and such
3344 mismatches are considered to be errors.
3345 [This option is specific to the i386 PE targeted port of the linker]
3347 @kindex --leading-underscore
3348 @kindex --no-leading-underscore
3349 @item --leading-underscore
3350 @itemx --no-leading-underscore
3351 For most targets default symbol-prefix is an underscore and is defined
3352 in target's description. By this option it is possible to
3353 disable/enable the default underscore symbol-prefix.
3355 @cindex DLLs, creating
3356 @kindex --export-all-symbols
3357 @item --export-all-symbols
3358 If given, all global symbols in the objects used to build a DLL will
3359 be exported by the DLL. Note that this is the default if there
3360 otherwise wouldn't be any exported symbols. When symbols are
3361 explicitly exported via DEF files or implicitly exported via function
3362 attributes, the default is to not export anything else unless this
3363 option is given. Note that the symbols @code{DllMain@@12},
3364 @code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
3365 @code{impure_ptr} will not be automatically
3366 exported. Also, symbols imported from other DLLs will not be
3367 re-exported, nor will symbols specifying the DLL's internal layout
3368 such as those beginning with @code{_head_} or ending with
3369 @code{_iname}. In addition, no symbols from @code{libgcc},
3370 @code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
3371 Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will
3372 not be exported, to help with C++ DLLs. Finally, there is an
3373 extensive list of cygwin-private symbols that are not exported
3374 (obviously, this applies on when building DLLs for cygwin targets).
3375 These cygwin-excludes are: @code{_cygwin_dll_entry@@12},
3376 @code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
3377 @code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
3378 @code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
3379 @code{cygwin_premain3}, and @code{environ}.
3380 [This option is specific to the i386 PE targeted port of the linker]
3382 @kindex --exclude-symbols
3383 @item --exclude-symbols @var{symbol},@var{symbol},...
3384 Specifies a list of symbols which should not be automatically
3385 exported. The symbol names may be delimited by commas or colons.
3386 [This option is specific to the i386 PE targeted port of the linker]
3388 @kindex --exclude-all-symbols
3389 @item --exclude-all-symbols
3390 Specifies no symbols should be automatically exported.
3391 [This option is specific to the i386 PE targeted port of the linker]
3393 @kindex --file-alignment
3394 @item --file-alignment
3395 Specify the file alignment. Sections in the file will always begin at
3396 file offsets which are multiples of this number. This defaults to
3398 [This option is specific to the i386 PE targeted port of the linker]
3402 @item --heap @var{reserve}
3403 @itemx --heap @var{reserve},@var{commit}
3404 Specify the number of bytes of memory to reserve (and optionally commit)
3405 to be used as heap for this program. The default is 1MB reserved, 4K
3407 [This option is specific to the i386 PE targeted port of the linker]
3411 If given, the stdcall suffixes (@@@var{nn}) will be stripped from
3412 symbols before they are exported.
3413 [This option is specific to the i386 PE targeted port of the linker]
3415 @kindex --large-address-aware
3416 @item --large-address-aware
3417 If given, the appropriate bit in the ``Characteristics'' field of the COFF
3418 header is set to indicate that this executable supports virtual addresses
3419 greater than 2 gigabytes. This should be used in conjunction with the /3GB
3420 or /USERVA=@var{value} megabytes switch in the ``[operating systems]''
3421 section of the BOOT.INI. Otherwise, this bit has no effect.
3422 [This option is specific to PE targeted ports of the linker]
3424 @kindex --disable-large-address-aware
3425 @item --disable-large-address-aware
3426 Reverts the effect of a previous @samp{--large-address-aware} option.
3427 This is useful if @samp{--large-address-aware} is always set by the compiler
3428 driver (e.g. Cygwin gcc) and the executable does not support virtual
3429 addresses greater than 2 gigabytes.
3430 [This option is specific to PE targeted ports of the linker]
3432 @kindex --major-image-version
3433 @item --major-image-version @var{value}
3434 Sets the major number of the ``image version''. Defaults to 1.
3435 [This option is specific to the i386 PE targeted port of the linker]
3437 @kindex --major-os-version
3438 @item --major-os-version @var{value}
3439 Sets the major number of the ``os version''. Defaults to 4.
3440 [This option is specific to the i386 PE targeted port of the linker]
3442 @kindex --major-subsystem-version
3443 @item --major-subsystem-version @var{value}
3444 Sets the major number of the ``subsystem version''. Defaults to 4.
3445 [This option is specific to the i386 PE targeted port of the linker]
3447 @kindex --minor-image-version
3448 @item --minor-image-version @var{value}
3449 Sets the minor number of the ``image version''. Defaults to 0.
3450 [This option is specific to the i386 PE targeted port of the linker]
3452 @kindex --minor-os-version
3453 @item --minor-os-version @var{value}
3454 Sets the minor number of the ``os version''. Defaults to 0.
3455 [This option is specific to the i386 PE targeted port of the linker]
3457 @kindex --minor-subsystem-version
3458 @item --minor-subsystem-version @var{value}
3459 Sets the minor number of the ``subsystem version''. Defaults to 0.
3460 [This option is specific to the i386 PE targeted port of the linker]
3462 @cindex DEF files, creating
3463 @cindex DLLs, creating
3464 @kindex --output-def
3465 @item --output-def @var{file}
3466 The linker will create the file @var{file} which will contain a DEF
3467 file corresponding to the DLL the linker is generating. This DEF file
3468 (which should be called @code{*.def}) may be used to create an import
3469 library with @code{dlltool} or may be used as a reference to
3470 automatically or implicitly exported symbols.
3471 [This option is specific to the i386 PE targeted port of the linker]
3473 @cindex DLLs, creating
3474 @kindex --enable-auto-image-base
3475 @item --enable-auto-image-base
3476 @itemx --enable-auto-image-base=@var{value}
3477 Automatically choose the image base for DLLs, optionally starting with base
3478 @var{value}, unless one is specified using the @code{--image-base} argument.
3479 By using a hash generated from the dllname to create unique image bases
3480 for each DLL, in-memory collisions and relocations which can delay program
3481 execution are avoided.
3482 [This option is specific to the i386 PE targeted port of the linker]
3484 @kindex --disable-auto-image-base
3485 @item --disable-auto-image-base
3486 Do not automatically generate a unique image base. If there is no
3487 user-specified image base (@code{--image-base}) then use the platform
3489 [This option is specific to the i386 PE targeted port of the linker]
3491 @cindex DLLs, linking to
3492 @kindex --dll-search-prefix
3493 @item --dll-search-prefix @var{string}
3494 When linking dynamically to a dll without an import library,
3495 search for @code{<string><basename>.dll} in preference to
3496 @code{lib<basename>.dll}. This behaviour allows easy distinction
3497 between DLLs built for the various "subplatforms": native, cygwin,
3498 uwin, pw, etc. For instance, cygwin DLLs typically use
3499 @code{--dll-search-prefix=cyg}.
3500 [This option is specific to the i386 PE targeted port of the linker]
3502 @kindex --enable-auto-import
3503 @item --enable-auto-import
3504 Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
3505 DATA imports from DLLs, thus making it possible to bypass the dllimport
3506 mechanism on the user side and to reference unmangled symbol names.
3507 [This option is specific to the i386 PE targeted port of the linker]
3509 The following remarks pertain to the original implementation of the
3510 feature and are obsolete nowadays for Cygwin and MinGW targets.
3512 Note: Use of the 'auto-import' extension will cause the text section
3513 of the image file to be made writable. This does not conform to the
3514 PE-COFF format specification published by Microsoft.
3516 Note - use of the 'auto-import' extension will also cause read only
3517 data which would normally be placed into the .rdata section to be
3518 placed into the .data section instead. This is in order to work
3519 around a problem with consts that is described here:
3520 http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
3522 Using 'auto-import' generally will 'just work' -- but sometimes you may
3525 "variable '<var>' can't be auto-imported. Please read the
3526 documentation for ld's @code{--enable-auto-import} for details."
3528 This message occurs when some (sub)expression accesses an address
3529 ultimately given by the sum of two constants (Win32 import tables only
3530 allow one). Instances where this may occur include accesses to member
3531 fields of struct variables imported from a DLL, as well as using a
3532 constant index into an array variable imported from a DLL. Any
3533 multiword variable (arrays, structs, long long, etc) may trigger
3534 this error condition. However, regardless of the exact data type
3535 of the offending exported variable, ld will always detect it, issue
3536 the warning, and exit.
3538 There are several ways to address this difficulty, regardless of the
3539 data type of the exported variable:
3541 One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
3542 of adjusting references in your client code for runtime environment, so
3543 this method works only when runtime environment supports this feature.
3545 A second solution is to force one of the 'constants' to be a variable --
3546 that is, unknown and un-optimizable at compile time. For arrays,
3547 there are two possibilities: a) make the indexee (the array's address)
3548 a variable, or b) make the 'constant' index a variable. Thus:
3551 extern type extern_array[];
3553 @{ volatile type *t=extern_array; t[1] @}
3559 extern type extern_array[];
3561 @{ volatile int t=1; extern_array[t] @}
3564 For structs (and most other multiword data types) the only option
3565 is to make the struct itself (or the long long, or the ...) variable:
3568 extern struct s extern_struct;
3569 extern_struct.field -->
3570 @{ volatile struct s *t=&extern_struct; t->field @}
3576 extern long long extern_ll;
3578 @{ volatile long long * local_ll=&extern_ll; *local_ll @}
3581 A third method of dealing with this difficulty is to abandon
3582 'auto-import' for the offending symbol and mark it with
3583 @code{__declspec(dllimport)}. However, in practice that
3584 requires using compile-time #defines to indicate whether you are
3585 building a DLL, building client code that will link to the DLL, or
3586 merely building/linking to a static library. In making the choice
3587 between the various methods of resolving the 'direct address with
3588 constant offset' problem, you should consider typical real-world usage:
3596 void main(int argc, char **argv)@{
3597 printf("%d\n",arr[1]);
3607 void main(int argc, char **argv)@{
3608 /* This workaround is for win32 and cygwin; do not "optimize" */
3609 volatile int *parr = arr;
3610 printf("%d\n",parr[1]);
3617 /* Note: auto-export is assumed (no __declspec(dllexport)) */
3618 #if (defined(_WIN32) || defined(__CYGWIN__)) && \
3619 !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
3620 #define FOO_IMPORT __declspec(dllimport)
3624 extern FOO_IMPORT int arr[];
3627 void main(int argc, char **argv)@{
3628 printf("%d\n",arr[1]);
3632 A fourth way to avoid this problem is to re-code your
3633 library to use a functional interface rather than a data interface
3634 for the offending variables (e.g. set_foo() and get_foo() accessor
3637 @kindex --disable-auto-import
3638 @item --disable-auto-import
3639 Do not attempt to do sophisticated linking of @code{_symbol} to
3640 @code{__imp__symbol} for DATA imports from DLLs.
3641 [This option is specific to the i386 PE targeted port of the linker]
3643 @kindex --enable-runtime-pseudo-reloc
3644 @item --enable-runtime-pseudo-reloc
3645 If your code contains expressions described in --enable-auto-import section,
3646 that is, DATA imports from DLL with non-zero offset, this switch will create
3647 a vector of 'runtime pseudo relocations' which can be used by runtime
3648 environment to adjust references to such data in your client code.
3649 [This option is specific to the i386 PE targeted port of the linker]
3651 @kindex --disable-runtime-pseudo-reloc
3652 @item --disable-runtime-pseudo-reloc
3653 Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
3654 [This option is specific to the i386 PE targeted port of the linker]
3656 @kindex --enable-extra-pe-debug
3657 @item --enable-extra-pe-debug
3658 Show additional debug info related to auto-import symbol thunking.
3659 [This option is specific to the i386 PE targeted port of the linker]
3661 @kindex --section-alignment
3662 @item --section-alignment
3663 Sets the section alignment. Sections in memory will always begin at
3664 addresses which are a multiple of this number. Defaults to 0x1000.
3665 [This option is specific to the i386 PE targeted port of the linker]
3669 @item --stack @var{reserve}
3670 @itemx --stack @var{reserve},@var{commit}
3671 Specify the number of bytes of memory to reserve (and optionally commit)
3672 to be used as stack for this program. The default is 2MB reserved, 4K
3674 [This option is specific to the i386 PE targeted port of the linker]
3677 @item --subsystem @var{which}
3678 @itemx --subsystem @var{which}:@var{major}
3679 @itemx --subsystem @var{which}:@var{major}.@var{minor}
3680 Specifies the subsystem under which your program will execute. The
3681 legal values for @var{which} are @code{native}, @code{windows},
3682 @code{console}, @code{posix}, and @code{xbox}. You may optionally set
3683 the subsystem version also. Numeric values are also accepted for
3685 [This option is specific to the i386 PE targeted port of the linker]
3687 The following options set flags in the @code{DllCharacteristics} field
3688 of the PE file header:
3689 [These options are specific to PE targeted ports of the linker]
3691 @kindex --high-entropy-va
3692 @item --high-entropy-va
3693 @itemx --disable-high-entropy-va
3694 Image is compatible with 64-bit address space layout randomization
3695 (ASLR). This option is enabled by default for 64-bit PE images.
3697 This option also implies @option{--dynamicbase} and
3698 @option{--enable-reloc-section}.
3700 @kindex --dynamicbase
3702 @itemx --disable-dynamicbase
3703 The image base address may be relocated using address space layout
3704 randomization (ASLR). This feature was introduced with MS Windows
3705 Vista for i386 PE targets. This option is enabled by default but
3706 can be disabled via the @option{--disable-dynamicbase} option.
3707 This option also implies @option{--enable-reloc-section}.
3709 @kindex --forceinteg
3711 @itemx --disable-forceinteg
3712 Code integrity checks are enforced. This option is disabled by
3717 @item --disable-nxcompat
3718 The image is compatible with the Data Execution Prevention.
3719 This feature was introduced with MS Windows XP SP2 for i386 PE
3720 targets. The option is enabled by default.
3722 @kindex --no-isolation
3723 @item --no-isolation
3724 @itemx --disable-no-isolation
3725 Although the image understands isolation, do not isolate the image.
3726 This option is disabled by default.
3730 @itemx --disable-no-seh
3731 The image does not use SEH. No SE handler may be called from
3732 this image. This option is disabled by default.
3736 @itemx --disable-no-bind
3737 Do not bind this image. This option is disabled by default.
3741 @itemx --disable-wdmdriver
3742 The driver uses the MS Windows Driver Model. This option is disabled
3747 @itemx --disable-tsaware
3748 The image is Terminal Server aware. This option is disabled by
3751 @kindex --insert-timestamp
3752 @item --insert-timestamp
3753 @itemx --no-insert-timestamp
3754 Insert a real timestamp into the image. This is the default behaviour
3755 as it matches legacy code and it means that the image will work with
3756 other, proprietary tools. The problem with this default is that it
3757 will result in slightly different images being produced each time the
3758 same sources are linked. The option @option{--no-insert-timestamp}
3759 can be used to insert a zero value for the timestamp, this ensuring
3760 that binaries produced from identical sources will compare
3763 If @option{--insert-timestamp} is active then the time inserted is
3764 either the time that the linking takes place or, if the
3765 @code{SOURCE_DATE_EPOCH} environment variable is defined, the number
3766 of seconds since Unix epoch as specified by that variable.
3768 @kindex --enable-reloc-section
3769 @item --enable-reloc-section
3770 @itemx --disable-reloc-section
3771 Create the base relocation table, which is necessary if the image
3772 is loaded at a different image base than specified in the PE header.
3773 This option is enabled by default.
3779 @subsection Options specific to C6X uClinux targets
3781 @c man begin OPTIONS
3783 The C6X uClinux target uses a binary format called DSBT to support shared
3784 libraries. Each shared library in the system needs to have a unique index;
3785 all executables use an index of 0.
3790 @item --dsbt-size @var{size}
3791 This option sets the number of entries in the DSBT of the current executable
3792 or shared library to @var{size}. The default is to create a table with 64
3795 @kindex --dsbt-index
3796 @item --dsbt-index @var{index}
3797 This option sets the DSBT index of the current executable or shared library
3798 to @var{index}. The default is 0, which is appropriate for generating
3799 executables. If a shared library is generated with a DSBT index of 0, the
3800 @code{R_C6000_DSBT_INDEX} relocs are copied into the output file.
3802 @kindex --no-merge-exidx-entries
3803 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent
3804 exidx entries in frame unwind info.
3812 @subsection Options specific to C-SKY targets
3814 @c man begin OPTIONS
3818 @kindex --branch-stub on C-SKY
3820 This option enables linker branch relaxation by inserting branch stub
3821 sections when needed to extend the range of branches. This option is
3822 usually not required since C-SKY supports branch and call instructions that
3823 can access the full memory range and branch relaxation is normally handled by
3824 the compiler or assembler.
3826 @kindex --stub-group-size on C-SKY
3827 @item --stub-group-size=@var{N}
3828 This option allows finer control of linker branch stub creation.
3829 It sets the maximum size of a group of input sections that can
3830 be handled by one stub section. A negative value of @var{N} locates
3831 stub sections after their branches, while a positive value allows stub
3832 sections to appear either before or after the branches. Values of
3833 @samp{1} or @samp{-1} indicate that the
3834 linker should choose suitable defaults.
3842 @subsection Options specific to Motorola 68HC11 and 68HC12 targets
3844 @c man begin OPTIONS
3846 The 68HC11 and 68HC12 linkers support specific options to control the
3847 memory bank switching mapping and trampoline code generation.
3851 @kindex --no-trampoline
3852 @item --no-trampoline
3853 This option disables the generation of trampoline. By default a trampoline
3854 is generated for each far function which is called using a @code{jsr}
3855 instruction (this happens when a pointer to a far function is taken).
3857 @kindex --bank-window
3858 @item --bank-window @var{name}
3859 This option indicates to the linker the name of the memory region in
3860 the @samp{MEMORY} specification that describes the memory bank window.
3861 The definition of such region is then used by the linker to compute
3862 paging and addresses within the memory window.
3870 @subsection Options specific to Motorola 68K target
3872 @c man begin OPTIONS
3874 The following options are supported to control handling of GOT generation
3875 when linking for 68K targets.
3880 @item --got=@var{type}
3881 This option tells the linker which GOT generation scheme to use.
3882 @var{type} should be one of @samp{single}, @samp{negative},
3883 @samp{multigot} or @samp{target}. For more information refer to the
3884 Info entry for @file{ld}.
3892 @subsection Options specific to MIPS targets
3894 @c man begin OPTIONS
3896 The following options are supported to control microMIPS instruction
3897 generation and branch relocation checks for ISA mode transitions when
3898 linking for MIPS targets.
3906 These options control the choice of microMIPS instructions used in code
3907 generated by the linker, such as that in the PLT or lazy binding stubs,
3908 or in relaxation. If @samp{--insn32} is used, then the linker only uses
3909 32-bit instruction encodings. By default or if @samp{--no-insn32} is
3910 used, all instruction encodings are used, including 16-bit ones where
3913 @kindex --ignore-branch-isa
3914 @item --ignore-branch-isa
3915 @kindex --no-ignore-branch-isa
3916 @itemx --no-ignore-branch-isa
3917 These options control branch relocation checks for invalid ISA mode
3918 transitions. If @samp{--ignore-branch-isa} is used, then the linker
3919 accepts any branch relocations and any ISA mode transition required
3920 is lost in relocation calculation, except for some cases of @code{BAL}
3921 instructions which meet relaxation conditions and are converted to
3922 equivalent @code{JALX} instructions as the associated relocation is
3923 calculated. By default or if @samp{--no-ignore-branch-isa} is used
3924 a check is made causing the loss of an ISA mode transition to produce
3927 @kindex --compact-branches
3928 @item --compact-branches
3929 @kindex --no-compact-branches
3930 @itemx --no-compact-branches
3931 These options control the generation of compact instructions by the linker
3932 in the PLT entries for MIPS R6.
3941 @subsection Options specific to PDP11 targets
3943 @c man begin OPTIONS
3945 For the pdp11-aout target, three variants of the output format can be
3946 produced as selected by the following options. The default variant
3947 for pdp11-aout is the @samp{--omagic} option, whereas for other
3948 targets @samp{--nmagic} is the default. The @samp{--imagic} option is
3949 defined only for the pdp11-aout target, while the others are described
3950 here as they apply to the pdp11-aout target.
3959 Mark the output as @code{OMAGIC} (0407) in the @file{a.out} header to
3960 indicate that the text segment is not to be write-protected and
3961 shared. Since the text and data sections are both readable and
3962 writable, the data section is allocated immediately contiguous after
3963 the text segment. This is the oldest format for PDP11 executable
3964 programs and is the default for @command{ld} on PDP11 Unix systems
3965 from the beginning through 2.11BSD.
3972 Mark the output as @code{NMAGIC} (0410) in the @file{a.out} header to
3973 indicate that when the output file is executed, the text portion will
3974 be read-only and shareable among all processes executing the same
3975 file. This involves moving the data areas up to the first possible 8K
3976 byte page boundary following the end of the text. This option creates
3977 a @emph{pure executable} format.
3984 Mark the output as @code{IMAGIC} (0411) in the @file{a.out} header to
3985 indicate that when the output file is executed, the program text and
3986 data areas will be loaded into separate address spaces using the split
3987 instruction and data space feature of the memory management unit in
3988 larger models of the PDP11. This doubles the address space available
3989 to the program. The text segment is again pure, write-protected, and
3990 shareable. The only difference in the output format between this
3991 option and the others, besides the magic number, is that both the text
3992 and data sections start at location 0. The @samp{-z} option selected
3993 this format in 2.11BSD. This option creates a @emph{separate
3999 Equivalent to @samp{--nmagic} for pdp11-aout.
4008 @section Environment Variables
4010 @c man begin ENVIRONMENT
4012 You can change the behaviour of @command{ld} with the environment variables
4013 @ifclear SingleFormat
4016 @code{LDEMULATION} and @code{COLLECT_NO_DEMANGLE}.
4018 @ifclear SingleFormat
4020 @cindex default input format
4021 @code{GNUTARGET} determines the input-file object format if you don't
4022 use @samp{-b} (or its synonym @samp{--format}). Its value should be one
4023 of the BFD names for an input format (@pxref{BFD}). If there is no
4024 @code{GNUTARGET} in the environment, @command{ld} uses the natural format
4025 of the target. If @code{GNUTARGET} is set to @code{default} then BFD
4026 attempts to discover the input format by examining binary input files;
4027 this method often succeeds, but there are potential ambiguities, since
4028 there is no method of ensuring that the magic number used to specify
4029 object-file formats is unique. However, the configuration procedure for
4030 BFD on each system places the conventional format for that system first
4031 in the search-list, so ambiguities are resolved in favor of convention.
4035 @cindex default emulation
4036 @cindex emulation, default
4037 @code{LDEMULATION} determines the default emulation if you don't use the
4038 @samp{-m} option. The emulation can affect various aspects of linker
4039 behaviour, particularly the default linker script. You can list the
4040 available emulations with the @samp{--verbose} or @samp{-V} options. If
4041 the @samp{-m} option is not used, and the @code{LDEMULATION} environment
4042 variable is not defined, the default emulation depends upon how the
4043 linker was configured.
4045 @kindex COLLECT_NO_DEMANGLE
4046 @cindex demangling, default
4047 Normally, the linker will default to demangling symbols. However, if
4048 @code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
4049 default to not demangling symbols. This environment variable is used in
4050 a similar fashion by the @code{gcc} linker wrapper program. The default
4051 may be overridden by the @samp{--demangle} and @samp{--no-demangle}
4054 @kindex SOURCE_DATE_EPOCH
4056 If the PE/COFF specific @option{--insert-timestamp} is active and the
4057 @env{SOURCE_DATE_EPOCH} environment variable is defined, then the
4058 timestamp value in this variable will be inserted into the COFF header
4059 instead of the current time.
4065 @chapter Linker Scripts
4068 @cindex linker scripts
4069 @cindex command files
4070 Every link is controlled by a @dfn{linker script}. This script is
4071 written in the linker command language.
4073 The main purpose of the linker script is to describe how the sections in
4074 the input files should be mapped into the output file, and to control
4075 the memory layout of the output file. Most linker scripts do nothing
4076 more than this. However, when necessary, the linker script can also
4077 direct the linker to perform many other operations, using the commands
4080 The linker always uses a linker script. If you do not supply one
4081 yourself, the linker will use a default script that is compiled into the
4082 linker executable. You can use the @samp{--verbose} command-line option
4083 to display the default linker script. Certain command-line options,
4084 such as @samp{-r} or @samp{-N}, will affect the default linker script.
4086 You may supply your own linker script by using the @samp{-T} command
4087 line option. When you do this, your linker script will replace the
4088 default linker script.
4090 You may also use linker scripts implicitly by naming them as input files
4091 to the linker, as though they were files to be linked. @xref{Implicit
4095 * Basic Script Concepts:: Basic Linker Script Concepts
4096 * Script Format:: Linker Script Format
4097 * Simple Example:: Simple Linker Script Example
4098 * Simple Commands:: Simple Linker Script Commands
4099 * Assignments:: Assigning Values to Symbols
4100 * SECTIONS:: SECTIONS Command
4101 * MEMORY:: MEMORY Command
4102 * PHDRS:: PHDRS Command
4103 * VERSION:: VERSION Command
4104 * Expressions:: Expressions in Linker Scripts
4105 * Implicit Linker Scripts:: Implicit Linker Scripts
4108 @node Basic Script Concepts
4109 @section Basic Linker Script Concepts
4110 @cindex linker script concepts
4111 We need to define some basic concepts and vocabulary in order to
4112 describe the linker script language.
4114 The linker combines input files into a single output file. The output
4115 file and each input file are in a special data format known as an
4116 @dfn{object file format}. Each file is called an @dfn{object file}.
4117 The output file is often called an @dfn{executable}, but for our
4118 purposes we will also call it an object file. Each object file has,
4119 among other things, a list of @dfn{sections}. We sometimes refer to a
4120 section in an input file as an @dfn{input section}; similarly, a section
4121 in the output file is an @dfn{output section}.
4123 Each section in an object file has a name and a size. Most sections
4124 also have an associated block of data, known as the @dfn{section
4125 contents}. A section may be marked as @dfn{loadable}, which means that
4126 the contents should be loaded into memory when the output file is run.
4127 A section with no contents may be @dfn{allocatable}, which means that an
4128 area in memory should be set aside, but nothing in particular should be
4129 loaded there (in some cases this memory must be zeroed out). A section
4130 which is neither loadable nor allocatable typically contains some sort
4131 of debugging information.
4133 Every loadable or allocatable output section has two addresses. The
4134 first is the @dfn{VMA}, or virtual memory address. This is the address
4135 the section will have when the output file is run. The second is the
4136 @dfn{LMA}, or load memory address. This is the address at which the
4137 section will be loaded. In most cases the two addresses will be the
4138 same. An example of when they might be different is when a data section
4139 is loaded into ROM, and then copied into RAM when the program starts up
4140 (this technique is often used to initialize global variables in a ROM
4141 based system). In this case the ROM address would be the LMA, and the
4142 RAM address would be the VMA.
4144 You can see the sections in an object file by using the @code{objdump}
4145 program with the @samp{-h} option.
4147 Every object file also has a list of @dfn{symbols}, known as the
4148 @dfn{symbol table}. A symbol may be defined or undefined. Each symbol
4149 has a name, and each defined symbol has an address, among other
4150 information. If you compile a C or C++ program into an object file, you
4151 will get a defined symbol for every defined function and global or
4152 static variable. Every undefined function or global variable which is
4153 referenced in the input file will become an undefined symbol.
4155 You can see the symbols in an object file by using the @code{nm}
4156 program, or by using the @code{objdump} program with the @samp{-t}
4160 @section Linker Script Format
4161 @cindex linker script format
4162 Linker scripts are text files.
4164 You write a linker script as a series of commands. Each command is
4165 either a keyword, possibly followed by arguments, or an assignment to a
4166 symbol. You may separate commands using semicolons. Whitespace is
4169 Strings such as file or format names can normally be entered directly.
4170 If the file name contains a character such as a comma which would
4171 otherwise serve to separate file names, you may put the file name in
4172 double quotes. There is no way to use a double quote character in a
4175 You may include comments in linker scripts just as in C, delimited by
4176 @samp{/*} and @samp{*/}. As in C, comments are syntactically equivalent
4179 @node Simple Example
4180 @section Simple Linker Script Example
4181 @cindex linker script example
4182 @cindex example of linker script
4183 Many linker scripts are fairly simple.
4185 The simplest possible linker script has just one command:
4186 @samp{SECTIONS}. You use the @samp{SECTIONS} command to describe the
4187 memory layout of the output file.
4189 The @samp{SECTIONS} command is a powerful command. Here we will
4190 describe a simple use of it. Let's assume your program consists only of
4191 code, initialized data, and uninitialized data. These will be in the
4192 @samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
4193 Let's assume further that these are the only sections which appear in
4196 For this example, let's say that the code should be loaded at address
4197 0x10000, and that the data should start at address 0x8000000. Here is a
4198 linker script which will do that:
4203 .text : @{ *(.text) @}
4205 .data : @{ *(.data) @}
4206 .bss : @{ *(.bss) @}
4210 You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
4211 followed by a series of symbol assignments and output section
4212 descriptions enclosed in curly braces.
4214 The first line inside the @samp{SECTIONS} command of the above example
4215 sets the value of the special symbol @samp{.}, which is the location
4216 counter. If you do not specify the address of an output section in some
4217 other way (other ways are described later), the address is set from the
4218 current value of the location counter. The location counter is then
4219 incremented by the size of the output section. At the start of the
4220 @samp{SECTIONS} command, the location counter has the value @samp{0}.
4222 The second line defines an output section, @samp{.text}. The colon is
4223 required syntax which may be ignored for now. Within the curly braces
4224 after the output section name, you list the names of the input sections
4225 which should be placed into this output section. The @samp{*} is a
4226 wildcard which matches any file name. The expression @samp{*(.text)}
4227 means all @samp{.text} input sections in all input files.
4229 Since the location counter is @samp{0x10000} when the output section
4230 @samp{.text} is defined, the linker will set the address of the
4231 @samp{.text} section in the output file to be @samp{0x10000}.
4233 The remaining lines define the @samp{.data} and @samp{.bss} sections in
4234 the output file. The linker will place the @samp{.data} output section
4235 at address @samp{0x8000000}. After the linker places the @samp{.data}
4236 output section, the value of the location counter will be
4237 @samp{0x8000000} plus the size of the @samp{.data} output section. The
4238 effect is that the linker will place the @samp{.bss} output section
4239 immediately after the @samp{.data} output section in memory.
4241 The linker will ensure that each output section has the required
4242 alignment, by increasing the location counter if necessary. In this
4243 example, the specified addresses for the @samp{.text} and @samp{.data}
4244 sections will probably satisfy any alignment constraints, but the linker
4245 may have to create a small gap between the @samp{.data} and @samp{.bss}
4248 That's it! That's a simple and complete linker script.
4250 @node Simple Commands
4251 @section Simple Linker Script Commands
4252 @cindex linker script simple commands
4253 In this section we describe the simple linker script commands.
4256 * Entry Point:: Setting the entry point
4257 * File Commands:: Commands dealing with files
4258 @ifclear SingleFormat
4259 * Format Commands:: Commands dealing with object file formats
4262 * REGION_ALIAS:: Assign alias names to memory regions
4263 * Miscellaneous Commands:: Other linker script commands
4267 @subsection Setting the Entry Point
4268 @kindex ENTRY(@var{symbol})
4269 @cindex start of execution
4270 @cindex first instruction
4272 The first instruction to execute in a program is called the @dfn{entry
4273 point}. You can use the @code{ENTRY} linker script command to set the
4274 entry point. The argument is a symbol name:
4279 There are several ways to set the entry point. The linker will set the
4280 entry point by trying each of the following methods in order, and
4281 stopping when one of them succeeds:
4284 the @samp{-e} @var{entry} command-line option;
4286 the @code{ENTRY(@var{symbol})} command in a linker script;
4288 the value of a target-specific symbol, if it is defined; For many
4289 targets this is @code{start}, but PE- and BeOS-based systems for example
4290 check a list of possible entry symbols, matching the first one found.
4292 the address of the first byte of the code section, if present and an
4293 executable is being created - the code section is usually
4294 @samp{.text}, but can be something else;
4296 The address @code{0}.
4300 @subsection Commands Dealing with Files
4301 @cindex linker script file commands
4302 Several linker script commands deal with files.
4305 @item INCLUDE @var{filename}
4306 @kindex INCLUDE @var{filename}
4307 @cindex including a linker script
4308 Include the linker script @var{filename} at this point. The file will
4309 be searched for in the current directory, and in any directory specified
4310 with the @option{-L} option. You can nest calls to @code{INCLUDE} up to
4313 You can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or
4314 @code{SECTIONS} commands, or in output section descriptions.
4316 @item INPUT(@var{file}, @var{file}, @dots{})
4317 @itemx INPUT(@var{file} @var{file} @dots{})
4318 @kindex INPUT(@var{files})
4319 @cindex input files in linker scripts
4320 @cindex input object files in linker scripts
4321 @cindex linker script input object files
4322 The @code{INPUT} command directs the linker to include the named files
4323 in the link, as though they were named on the command line.
4325 For example, if you always want to include @file{subr.o} any time you do
4326 a link, but you can't be bothered to put it on every link command line,
4327 then you can put @samp{INPUT (subr.o)} in your linker script.
4329 In fact, if you like, you can list all of your input files in the linker
4330 script, and then invoke the linker with nothing but a @samp{-T} option.
4332 In case a @dfn{sysroot prefix} is configured, and the filename starts
4333 with the @samp{/} character, and the script being processed was
4334 located inside the @dfn{sysroot prefix}, the filename will be looked
4335 for in the @dfn{sysroot prefix}. The @dfn{sysroot prefix} can also be forced by specifying
4336 @code{=} as the first character in the filename path, or prefixing the
4337 filename path with @code{$SYSROOT}. See also the description of
4338 @samp{-L} in @ref{Options,,Command-line Options}.
4340 If a @dfn{sysroot prefix} is not used then the linker will try to open
4341 the file in the directory containing the linker script. If it is not
4342 found the linker will then search the current directory. If it is still
4343 not found the linker will search through the archive library search
4346 If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
4347 name to @code{lib@var{file}.a}, as with the command-line argument
4350 When you use the @code{INPUT} command in an implicit linker script, the
4351 files will be included in the link at the point at which the linker
4352 script file is included. This can affect archive searching.
4354 @item GROUP(@var{file}, @var{file}, @dots{})
4355 @itemx GROUP(@var{file} @var{file} @dots{})
4356 @kindex GROUP(@var{files})
4357 @cindex grouping input files
4358 The @code{GROUP} command is like @code{INPUT}, except that the named
4359 files should all be archives, and they are searched repeatedly until no
4360 new undefined references are created. See the description of @samp{-(}
4361 in @ref{Options,,Command-line Options}.
4363 @item AS_NEEDED(@var{file}, @var{file}, @dots{})
4364 @itemx AS_NEEDED(@var{file} @var{file} @dots{})
4365 @kindex AS_NEEDED(@var{files})
4366 This construct can appear only inside of the @code{INPUT} or @code{GROUP}
4367 commands, among other filenames. The files listed will be handled
4368 as if they appear directly in the @code{INPUT} or @code{GROUP} commands,
4369 with the exception of ELF shared libraries, that will be added only
4370 when they are actually needed. This construct essentially enables
4371 @option{--as-needed} option for all the files listed inside of it
4372 and restores previous @option{--as-needed} resp. @option{--no-as-needed}
4375 @item OUTPUT(@var{filename})
4376 @kindex OUTPUT(@var{filename})
4377 @cindex output file name in linker script
4378 The @code{OUTPUT} command names the output file. Using
4379 @code{OUTPUT(@var{filename})} in the linker script is exactly like using
4380 @samp{-o @var{filename}} on the command line (@pxref{Options,,Command
4381 Line Options}). If both are used, the command-line option takes
4384 You can use the @code{OUTPUT} command to define a default name for the
4385 output file other than the usual default of @file{a.out}.
4387 @item SEARCH_DIR(@var{path})
4388 @kindex SEARCH_DIR(@var{path})
4389 @cindex library search path in linker script
4390 @cindex archive search path in linker script
4391 @cindex search path in linker script
4392 The @code{SEARCH_DIR} command adds @var{path} to the list of paths where
4393 @command{ld} looks for archive libraries. Using
4394 @code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
4395 on the command line (@pxref{Options,,Command-line Options}). If both
4396 are used, then the linker will search both paths. Paths specified using
4397 the command-line option are searched first.
4399 @item STARTUP(@var{filename})
4400 @kindex STARTUP(@var{filename})
4401 @cindex first input file
4402 The @code{STARTUP} command is just like the @code{INPUT} command, except
4403 that @var{filename} will become the first input file to be linked, as
4404 though it were specified first on the command line. This may be useful
4405 when using a system in which the entry point is always the start of the
4409 @ifclear SingleFormat
4410 @node Format Commands
4411 @subsection Commands Dealing with Object File Formats
4412 A couple of linker script commands deal with object file formats.
4415 @item OUTPUT_FORMAT(@var{bfdname})
4416 @itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
4417 @kindex OUTPUT_FORMAT(@var{bfdname})
4418 @cindex output file format in linker script
4419 The @code{OUTPUT_FORMAT} command names the BFD format to use for the
4420 output file (@pxref{BFD}). Using @code{OUTPUT_FORMAT(@var{bfdname})} is
4421 exactly like using @samp{--oformat @var{bfdname}} on the command line
4422 (@pxref{Options,,Command-line Options}). If both are used, the command
4423 line option takes precedence.
4425 You can use @code{OUTPUT_FORMAT} with three arguments to use different
4426 formats based on the @samp{-EB} and @samp{-EL} command-line options.
4427 This permits the linker script to set the output format based on the
4430 If neither @samp{-EB} nor @samp{-EL} are used, then the output format
4431 will be the first argument, @var{default}. If @samp{-EB} is used, the
4432 output format will be the second argument, @var{big}. If @samp{-EL} is
4433 used, the output format will be the third argument, @var{little}.
4435 For example, the default linker script for the MIPS ELF target uses this
4438 OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
4440 This says that the default format for the output file is
4441 @samp{elf32-bigmips}, but if the user uses the @samp{-EL} command-line
4442 option, the output file will be created in the @samp{elf32-littlemips}
4445 @item TARGET(@var{bfdname})
4446 @kindex TARGET(@var{bfdname})
4447 @cindex input file format in linker script
4448 The @code{TARGET} command names the BFD format to use when reading input
4449 files. It affects subsequent @code{INPUT} and @code{GROUP} commands.
4450 This command is like using @samp{-b @var{bfdname}} on the command line
4451 (@pxref{Options,,Command-line Options}). If the @code{TARGET} command
4452 is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
4453 command is also used to set the format for the output file. @xref{BFD}.
4458 @subsection Assign alias names to memory regions
4459 @kindex REGION_ALIAS(@var{alias}, @var{region})
4460 @cindex region alias
4461 @cindex region names
4463 Alias names can be added to existing memory regions created with the
4464 @ref{MEMORY} command. Each name corresponds to at most one memory region.
4467 REGION_ALIAS(@var{alias}, @var{region})
4470 The @code{REGION_ALIAS} function creates an alias name @var{alias} for the
4471 memory region @var{region}. This allows a flexible mapping of output sections
4472 to memory regions. An example follows.
4474 Suppose we have an application for embedded systems which come with various
4475 memory storage devices. All have a general purpose, volatile memory @code{RAM}
4476 that allows code execution or data storage. Some may have a read-only,
4477 non-volatile memory @code{ROM} that allows code execution and read-only data
4478 access. The last variant is a read-only, non-volatile memory @code{ROM2} with
4479 read-only data access and no code execution capability. We have four output
4484 @code{.text} program code;
4486 @code{.rodata} read-only data;
4488 @code{.data} read-write initialized data;
4490 @code{.bss} read-write zero initialized data.
4493 The goal is to provide a linker command file that contains a system independent
4494 part defining the output sections and a system dependent part mapping the
4495 output sections to the memory regions available on the system. Our embedded
4496 systems come with three different memory setups @code{A}, @code{B} and
4498 @multitable @columnfractions .25 .25 .25 .25
4499 @item Section @tab Variant A @tab Variant B @tab Variant C
4500 @item .text @tab RAM @tab ROM @tab ROM
4501 @item .rodata @tab RAM @tab ROM @tab ROM2
4502 @item .data @tab RAM @tab RAM/ROM @tab RAM/ROM2
4503 @item .bss @tab RAM @tab RAM @tab RAM
4505 The notation @code{RAM/ROM} or @code{RAM/ROM2} means that this section is
4506 loaded into region @code{ROM} or @code{ROM2} respectively. Please note that
4507 the load address of the @code{.data} section starts in all three variants at
4508 the end of the @code{.rodata} section.
4510 The base linker script that deals with the output sections follows. It
4511 includes the system dependent @code{linkcmds.memory} file that describes the
4514 INCLUDE linkcmds.memory
4527 .data : AT (rodata_end)
4532 data_size = SIZEOF(.data);
4533 data_load_start = LOADADDR(.data);
4541 Now we need three different @code{linkcmds.memory} files to define memory
4542 regions and alias names. The content of @code{linkcmds.memory} for the three
4543 variants @code{A}, @code{B} and @code{C}:
4546 Here everything goes into the @code{RAM}.
4550 RAM : ORIGIN = 0, LENGTH = 4M
4553 REGION_ALIAS("REGION_TEXT", RAM);
4554 REGION_ALIAS("REGION_RODATA", RAM);
4555 REGION_ALIAS("REGION_DATA", RAM);
4556 REGION_ALIAS("REGION_BSS", RAM);
4559 Program code and read-only data go into the @code{ROM}. Read-write data goes
4560 into the @code{RAM}. An image of the initialized data is loaded into the
4561 @code{ROM} and will be copied during system start into the @code{RAM}.
4565 ROM : ORIGIN = 0, LENGTH = 3M
4566 RAM : ORIGIN = 0x10000000, LENGTH = 1M
4569 REGION_ALIAS("REGION_TEXT", ROM);
4570 REGION_ALIAS("REGION_RODATA", ROM);
4571 REGION_ALIAS("REGION_DATA", RAM);
4572 REGION_ALIAS("REGION_BSS", RAM);
4575 Program code goes into the @code{ROM}. Read-only data goes into the
4576 @code{ROM2}. Read-write data goes into the @code{RAM}. An image of the
4577 initialized data is loaded into the @code{ROM2} and will be copied during
4578 system start into the @code{RAM}.
4582 ROM : ORIGIN = 0, LENGTH = 2M
4583 ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
4584 RAM : ORIGIN = 0x20000000, LENGTH = 1M
4587 REGION_ALIAS("REGION_TEXT", ROM);
4588 REGION_ALIAS("REGION_RODATA", ROM2);
4589 REGION_ALIAS("REGION_DATA", RAM);
4590 REGION_ALIAS("REGION_BSS", RAM);
4594 It is possible to write a common system initialization routine to copy the
4595 @code{.data} section from @code{ROM} or @code{ROM2} into the @code{RAM} if
4600 extern char data_start [];
4601 extern char data_size [];
4602 extern char data_load_start [];
4604 void copy_data(void)
4606 if (data_start != data_load_start)
4608 memcpy(data_start, data_load_start, (size_t) data_size);
4613 @node Miscellaneous Commands
4614 @subsection Other Linker Script Commands
4615 There are a few other linker scripts commands.
4618 @item ASSERT(@var{exp}, @var{message})
4620 @cindex assertion in linker script
4621 Ensure that @var{exp} is non-zero. If it is zero, then exit the linker
4622 with an error code, and print @var{message}.
4624 Note that assertions are checked before the final stages of linking
4625 take place. This means that expressions involving symbols PROVIDEd
4626 inside section definitions will fail if the user has not set values
4627 for those symbols. The only exception to this rule is PROVIDEd
4628 symbols that just reference dot. Thus an assertion like this:
4633 PROVIDE (__stack = .);
4634 PROVIDE (__stack_size = 0x100);
4635 ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4639 will fail if @code{__stack_size} is not defined elsewhere. Symbols
4640 PROVIDEd outside of section definitions are evaluated earlier, so they
4641 can be used inside ASSERTions. Thus:
4644 PROVIDE (__stack_size = 0x100);
4647 PROVIDE (__stack = .);
4648 ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4654 @item EXTERN(@var{symbol} @var{symbol} @dots{})
4656 @cindex undefined symbol in linker script
4657 Force @var{symbol} to be entered in the output file as an undefined
4658 symbol. Doing this may, for example, trigger linking of additional
4659 modules from standard libraries. You may list several @var{symbol}s for
4660 each @code{EXTERN}, and you may use @code{EXTERN} multiple times. This
4661 command has the same effect as the @samp{-u} command-line option.
4663 @item FORCE_COMMON_ALLOCATION
4664 @kindex FORCE_COMMON_ALLOCATION
4665 @cindex common allocation in linker script
4666 This command has the same effect as the @samp{-d} command-line option:
4667 to make @command{ld} assign space to common symbols even if a relocatable
4668 output file is specified (@samp{-r}).
4670 @item INHIBIT_COMMON_ALLOCATION
4671 @kindex INHIBIT_COMMON_ALLOCATION
4672 @cindex common allocation in linker script
4673 This command has the same effect as the @samp{--no-define-common}
4674 command-line option: to make @code{ld} omit the assignment of addresses
4675 to common symbols even for a non-relocatable output file.
4677 @item FORCE_GROUP_ALLOCATION
4678 @kindex FORCE_GROUP_ALLOCATION
4679 @cindex group allocation in linker script
4680 @cindex section groups
4682 This command has the same effect as the
4683 @samp{--force-group-allocation} command-line option: to make
4684 @command{ld} place section group members like normal input sections,
4685 and to delete the section groups even if a relocatable output file is
4686 specified (@samp{-r}).
4688 @item INSERT [ AFTER | BEFORE ] @var{output_section}
4690 @cindex insert user script into default script
4691 This command is typically used in a script specified by @samp{-T} to
4692 augment the default @code{SECTIONS} with, for example, overlays. It
4693 inserts all prior linker script statements after (or before)
4694 @var{output_section}, and also causes @samp{-T} to not override the
4695 default linker script. The exact insertion point is as for orphan
4696 sections. @xref{Location Counter}. The insertion happens after the
4697 linker has mapped input sections to output sections. Prior to the
4698 insertion, since @samp{-T} scripts are parsed before the default
4699 linker script, statements in the @samp{-T} script occur before the
4700 default linker script statements in the internal linker representation
4701 of the script. In particular, input section assignments will be made
4702 to @samp{-T} output sections before those in the default script. Here
4703 is an example of how a @samp{-T} script using @code{INSERT} might look:
4710 .ov1 @{ ov1*(.text) @}
4711 .ov2 @{ ov2*(.text) @}
4717 Note that when @samp{-T} is used twice, once to override the default
4718 script and once to augment that script using @code{INSERT} the order
4719 of parsing and section assignments apply as for the default script.
4720 The script with @code{INSERT} should be specified @emph{first} on the
4723 @item NOCROSSREFS(@var{section} @var{section} @dots{})
4724 @kindex NOCROSSREFS(@var{sections})
4725 @cindex cross references
4726 This command may be used to tell @command{ld} to issue an error about any
4727 references among certain output sections.
4729 In certain types of programs, particularly on embedded systems when
4730 using overlays, when one section is loaded into memory, another section
4731 will not be. Any direct references between the two sections would be
4732 errors. For example, it would be an error if code in one section called
4733 a function defined in the other section.
4735 The @code{NOCROSSREFS} command takes a list of output section names. If
4736 @command{ld} detects any cross references between the sections, it reports
4737 an error and returns a non-zero exit status. Note that the
4738 @code{NOCROSSREFS} command uses output section names, not input section
4741 @item NOCROSSREFS_TO(@var{tosection} @var{fromsection} @dots{})
4742 @kindex NOCROSSREFS_TO(@var{tosection} @var{fromsections})
4743 @cindex cross references
4744 This command may be used to tell @command{ld} to issue an error about any
4745 references to one section from a list of other sections.
4747 The @code{NOCROSSREFS} command is useful when ensuring that two or more
4748 output sections are entirely independent but there are situations where
4749 a one-way dependency is needed. For example, in a multi-core application
4750 there may be shared code that can be called from each core but for safety
4751 must never call back.
4753 The @code{NOCROSSREFS_TO} command takes a list of output section names.
4754 The first section can not be referenced from any of the other sections.
4755 If @command{ld} detects any references to the first section from any of
4756 the other sections, it reports an error and returns a non-zero exit
4757 status. Note that the @code{NOCROSSREFS_TO} command uses output section
4758 names, not input section names.
4760 @ifclear SingleFormat
4761 @item OUTPUT_ARCH(@var{bfdarch})
4762 @kindex OUTPUT_ARCH(@var{bfdarch})
4763 @cindex machine architecture
4764 @cindex architecture
4765 Specify a particular output machine architecture. The argument is one
4766 of the names used by the BFD library (@pxref{BFD}). You can see the
4767 architecture of an object file by using the @code{objdump} program with
4768 the @samp{-f} option.
4771 @item LD_FEATURE(@var{string})
4772 @kindex LD_FEATURE(@var{string})
4773 This command may be used to modify @command{ld} behavior. If
4774 @var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
4775 in a script are simply treated as numbers everywhere.
4776 @xref{Expression Section}.
4780 @section Assigning Values to Symbols
4781 @cindex assignment in scripts
4782 @cindex symbol definition, scripts
4783 @cindex variables, defining
4784 You may assign a value to a symbol in a linker script. This will define
4785 the symbol and place it into the symbol table with a global scope.
4788 * Simple Assignments:: Simple Assignments
4791 * PROVIDE_HIDDEN:: PROVIDE_HIDDEN
4792 * Source Code Reference:: How to use a linker script defined symbol in source code
4795 @node Simple Assignments
4796 @subsection Simple Assignments
4798 You may assign to a symbol using any of the C assignment operators:
4801 @item @var{symbol} = @var{expression} ;
4802 @itemx @var{symbol} += @var{expression} ;
4803 @itemx @var{symbol} -= @var{expression} ;
4804 @itemx @var{symbol} *= @var{expression} ;
4805 @itemx @var{symbol} /= @var{expression} ;
4806 @itemx @var{symbol} <<= @var{expression} ;
4807 @itemx @var{symbol} >>= @var{expression} ;
4808 @itemx @var{symbol} &= @var{expression} ;
4809 @itemx @var{symbol} |= @var{expression} ;
4812 The first case will define @var{symbol} to the value of
4813 @var{expression}. In the other cases, @var{symbol} must already be
4814 defined, and the value will be adjusted accordingly.
4816 The special symbol name @samp{.} indicates the location counter. You
4817 may only use this within a @code{SECTIONS} command. @xref{Location Counter}.
4819 The semicolon after @var{expression} is required.
4821 Expressions are defined below; see @ref{Expressions}.
4823 You may write symbol assignments as commands in their own right, or as
4824 statements within a @code{SECTIONS} command, or as part of an output
4825 section description in a @code{SECTIONS} command.
4827 The section of the symbol will be set from the section of the
4828 expression; for more information, see @ref{Expression Section}.
4830 Here is an example showing the three different places that symbol
4831 assignments may be used:
4842 _bdata = (. + 3) & ~ 3;
4843 .data : @{ *(.data) @}
4847 In this example, the symbol @samp{floating_point} will be defined as
4848 zero. The symbol @samp{_etext} will be defined as the address following
4849 the last @samp{.text} input section. The symbol @samp{_bdata} will be
4850 defined as the address following the @samp{.text} output section aligned
4851 upward to a 4 byte boundary.
4856 For ELF targeted ports, define a symbol that will be hidden and won't be
4857 exported. The syntax is @code{HIDDEN(@var{symbol} = @var{expression})}.
4859 Here is the example from @ref{Simple Assignments}, rewritten to use
4863 HIDDEN(floating_point = 0);
4871 HIDDEN(_bdata = (. + 3) & ~ 3);
4872 .data : @{ *(.data) @}
4876 In this case none of the three symbols will be visible outside this module.
4881 In some cases, it is desirable for a linker script to define a symbol
4882 only if it is referenced and is not defined by any object included in
4883 the link. For example, traditional linkers defined the symbol
4884 @samp{etext}. However, ANSI C requires that the user be able to use
4885 @samp{etext} as a function name without encountering an error. The
4886 @code{PROVIDE} keyword may be used to define a symbol, such as
4887 @samp{etext}, only if it is referenced but not defined. The syntax is
4888 @code{PROVIDE(@var{symbol} = @var{expression})}.
4890 Here is an example of using @code{PROVIDE} to define @samp{etext}:
4903 In this example, if the program defines @samp{_etext} (with a leading
4904 underscore), the linker will give a multiple definition diagnostic. If,
4905 on the other hand, the program defines @samp{etext} (with no leading
4906 underscore), the linker will silently use the definition in the program.
4907 If the program references @samp{etext} but does not define it, the
4908 linker will use the definition in the linker script.
4910 Note - the @code{PROVIDE} directive considers a common symbol to be
4911 defined, even though such a symbol could be combined with the symbol
4912 that the @code{PROVIDE} would create. This is particularly important
4913 when considering constructor and destructor list symbols such as
4914 @samp{__CTOR_LIST__} as these are often defined as common symbols.
4916 @node PROVIDE_HIDDEN
4917 @subsection PROVIDE_HIDDEN
4918 @cindex PROVIDE_HIDDEN
4919 Similar to @code{PROVIDE}. For ELF targeted ports, the symbol will be
4920 hidden and won't be exported.
4922 @node Source Code Reference
4923 @subsection Source Code Reference
4925 Accessing a linker script defined variable from source code is not
4926 intuitive. In particular a linker script symbol is not equivalent to
4927 a variable declaration in a high level language, it is instead a
4928 symbol that does not have a value.
4930 Before going further, it is important to note that compilers often
4931 transform names in the source code into different names when they are
4932 stored in the symbol table. For example, Fortran compilers commonly
4933 prepend or append an underscore, and C++ performs extensive @samp{name
4934 mangling}. Therefore there might be a discrepancy between the name
4935 of a variable as it is used in source code and the name of the same
4936 variable as it is defined in a linker script. For example in C a
4937 linker script variable might be referred to as:
4943 But in the linker script it might be defined as:
4949 In the remaining examples however it is assumed that no name
4950 transformation has taken place.
4952 When a symbol is declared in a high level language such as C, two
4953 things happen. The first is that the compiler reserves enough space
4954 in the program's memory to hold the @emph{value} of the symbol. The
4955 second is that the compiler creates an entry in the program's symbol
4956 table which holds the symbol's @emph{address}. ie the symbol table
4957 contains the address of the block of memory holding the symbol's
4958 value. So for example the following C declaration, at file scope:
4964 creates an entry called @samp{foo} in the symbol table. This entry
4965 holds the address of an @samp{int} sized block of memory where the
4966 number 1000 is initially stored.
4968 When a program references a symbol the compiler generates code that
4969 first accesses the symbol table to find the address of the symbol's
4970 memory block and then code to read the value from that memory block.
4977 looks up the symbol @samp{foo} in the symbol table, gets the address
4978 associated with this symbol and then writes the value 1 into that
4985 looks up the symbol @samp{foo} in the symbol table, gets its address
4986 and then copies this address into the block of memory associated with
4987 the variable @samp{a}.
4989 Linker scripts symbol declarations, by contrast, create an entry in
4990 the symbol table but do not assign any memory to them. Thus they are
4991 an address without a value. So for example the linker script definition:
4997 creates an entry in the symbol table called @samp{foo} which holds
4998 the address of memory location 1000, but nothing special is stored at
4999 address 1000. This means that you cannot access the @emph{value} of a
5000 linker script defined symbol - it has no value - all you can do is
5001 access the @emph{address} of a linker script defined symbol.
5003 Hence when you are using a linker script defined symbol in source code
5004 you should always take the address of the symbol, and never attempt to
5005 use its value. For example suppose you want to copy the contents of a
5006 section of memory called .ROM into a section called .FLASH and the
5007 linker script contains these declarations:
5011 start_of_ROM = .ROM;
5012 end_of_ROM = .ROM + sizeof (.ROM);
5013 start_of_FLASH = .FLASH;
5017 Then the C source code to perform the copy would be:
5021 extern char start_of_ROM, end_of_ROM, start_of_FLASH;
5023 memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
5027 Note the use of the @samp{&} operators. These are correct.
5028 Alternatively the symbols can be treated as the names of vectors or
5029 arrays and then the code will again work as expected:
5033 extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
5035 memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
5039 Note how using this method does not require the use of @samp{&}
5043 @section SECTIONS Command
5045 The @code{SECTIONS} command tells the linker how to map input sections
5046 into output sections, and how to place the output sections in memory.
5048 The format of the @code{SECTIONS} command is:
5052 @var{sections-command}
5053 @var{sections-command}
5058 Each @var{sections-command} may of be one of the following:
5062 an @code{ENTRY} command (@pxref{Entry Point,,Entry command})
5064 a symbol assignment (@pxref{Assignments})
5066 an output section description
5068 an overlay description
5071 The @code{ENTRY} command and symbol assignments are permitted inside the
5072 @code{SECTIONS} command for convenience in using the location counter in
5073 those commands. This can also make the linker script easier to
5074 understand because you can use those commands at meaningful points in
5075 the layout of the output file.
5077 Output section descriptions and overlay descriptions are described
5080 If you do not use a @code{SECTIONS} command in your linker script, the
5081 linker will place each input section into an identically named output
5082 section in the order that the sections are first encountered in the
5083 input files. If all input sections are present in the first file, for
5084 example, the order of sections in the output file will match the order
5085 in the first input file. The first section will be at address zero.
5088 * Output Section Description:: Output section description
5089 * Output Section Name:: Output section name
5090 * Output Section Address:: Output section address
5091 * Input Section:: Input section description
5092 * Output Section Data:: Output section data
5093 * Output Section Keywords:: Output section keywords
5094 * Output Section Discarding:: Output section discarding
5095 * Output Section Attributes:: Output section attributes
5096 * Overlay Description:: Overlay description
5099 @node Output Section Description
5100 @subsection Output Section Description
5101 The full description of an output section looks like this:
5104 @var{section} [@var{address}] [(@var{type})] :
5106 [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
5107 [SUBALIGN(@var{subsection_align})]
5110 @var{output-section-command}
5111 @var{output-section-command}
5113 @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] [,]
5117 Most output sections do not use most of the optional section attributes.
5119 The whitespace around @var{section} is required, so that the section
5120 name is unambiguous. The colon and the curly braces are also required.
5121 The comma at the end may be required if a @var{fillexp} is used and
5122 the next @var{sections-command} looks like a continuation of the expression.
5123 The line breaks and other white space are optional.
5125 Each @var{output-section-command} may be one of the following:
5129 a symbol assignment (@pxref{Assignments})
5131 an input section description (@pxref{Input Section})
5133 data values to include directly (@pxref{Output Section Data})
5135 a special output section keyword (@pxref{Output Section Keywords})
5138 @node Output Section Name
5139 @subsection Output Section Name
5140 @cindex name, section
5141 @cindex section name
5142 The name of the output section is @var{section}. @var{section} must
5143 meet the constraints of your output format. In formats which only
5144 support a limited number of sections, such as @code{a.out}, the name
5145 must be one of the names supported by the format (@code{a.out}, for
5146 example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
5147 output format supports any number of sections, but with numbers and not
5148 names (as is the case for Oasys), the name should be supplied as a
5149 quoted numeric string. A section name may consist of any sequence of
5150 characters, but a name which contains any unusual characters such as
5151 commas must be quoted.
5153 The output section name @samp{/DISCARD/} is special; @ref{Output Section
5156 @node Output Section Address
5157 @subsection Output Section Address
5158 @cindex address, section
5159 @cindex section address
5160 The @var{address} is an expression for the VMA (the virtual memory
5161 address) of the output section. This address is optional, but if it
5162 is provided then the output address will be set exactly as specified.
5164 If the output address is not specified then one will be chosen for the
5165 section, based on the heuristic below. This address will be adjusted
5166 to fit the alignment requirement of the output section. The
5167 alignment requirement is the strictest alignment of any input section
5168 contained within the output section.
5170 The output section address heuristic is as follows:
5174 If an output memory @var{region} is set for the section then it
5175 is added to this region and its address will be the next free address
5179 If the MEMORY command has been used to create a list of memory
5180 regions then the first region which has attributes compatible with the
5181 section is selected to contain it. The section's output address will
5182 be the next free address in that region; @ref{MEMORY}.
5185 If no memory regions were specified, or none match the section then
5186 the output address will be based on the current value of the location
5194 .text . : @{ *(.text) @}
5201 .text : @{ *(.text) @}
5205 are subtly different. The first will set the address of the
5206 @samp{.text} output section to the current value of the location
5207 counter. The second will set it to the current value of the location
5208 counter aligned to the strictest alignment of any of the @samp{.text}
5211 The @var{address} may be an arbitrary expression; @ref{Expressions}.
5212 For example, if you want to align the section on a 0x10 byte boundary,
5213 so that the lowest four bits of the section address are zero, you could
5214 do something like this:
5216 .text ALIGN(0x10) : @{ *(.text) @}
5219 This works because @code{ALIGN} returns the current location counter
5220 aligned upward to the specified value.
5222 Specifying @var{address} for a section will change the value of the
5223 location counter, provided that the section is non-empty. (Empty
5224 sections are ignored).
5227 @subsection Input Section Description
5228 @cindex input sections
5229 @cindex mapping input sections to output sections
5230 The most common output section command is an input section description.
5232 The input section description is the most basic linker script operation.
5233 You use output sections to tell the linker how to lay out your program
5234 in memory. You use input section descriptions to tell the linker how to
5235 map the input files into your memory layout.
5238 * Input Section Basics:: Input section basics
5239 * Input Section Wildcards:: Input section wildcard patterns
5240 * Input Section Common:: Input section for common symbols
5241 * Input Section Keep:: Input section and garbage collection
5242 * Input Section Example:: Input section example
5245 @node Input Section Basics
5246 @subsubsection Input Section Basics
5247 @cindex input section basics
5248 An input section description consists of a file name optionally followed
5249 by a list of section names in parentheses.
5251 The file name and the section name may be wildcard patterns, which we
5252 describe further below (@pxref{Input Section Wildcards}).
5254 The most common input section description is to include all input
5255 sections with a particular name in the output section. For example, to
5256 include all input @samp{.text} sections, you would write:
5261 Here the @samp{*} is a wildcard which matches any file name. To exclude a list
5262 @cindex EXCLUDE_FILE
5263 of files from matching the file name wildcard, EXCLUDE_FILE may be used to
5264 match all files except the ones specified in the EXCLUDE_FILE list. For
5267 EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
5270 will cause all .ctors sections from all files except @file{crtend.o}
5271 and @file{otherfile.o} to be included. The EXCLUDE_FILE can also be
5272 placed inside the section list, for example:
5274 *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
5277 The result of this is identically to the previous example. Supporting
5278 two syntaxes for EXCLUDE_FILE is useful if the section list contains
5279 more than one section, as described below.
5281 There are two ways to include more than one section:
5287 The difference between these is the order in which the @samp{.text} and
5288 @samp{.rdata} input sections will appear in the output section. In the
5289 first example, they will be intermingled, appearing in the same order as
5290 they are found in the linker input. In the second example, all
5291 @samp{.text} input sections will appear first, followed by all
5292 @samp{.rdata} input sections.
5294 When using EXCLUDE_FILE with more than one section, if the exclusion
5295 is within the section list then the exclusion only applies to the
5296 immediately following section, for example:
5298 *(EXCLUDE_FILE (*somefile.o) .text .rdata)
5301 will cause all @samp{.text} sections from all files except
5302 @file{somefile.o} to be included, while all @samp{.rdata} sections
5303 from all files, including @file{somefile.o}, will be included. To
5304 exclude the @samp{.rdata} sections from @file{somefile.o} the example
5305 could be modified to:
5307 *(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
5310 Alternatively, placing the EXCLUDE_FILE outside of the section list,
5311 before the input file selection, will cause the exclusion to apply for
5312 all sections. Thus the previous example can be rewritten as:
5314 EXCLUDE_FILE (*somefile.o) *(.text .rdata)
5317 You can specify a file name to include sections from a particular file.
5318 You would do this if one or more of your files contain special data that
5319 needs to be at a particular location in memory. For example:
5324 To refine the sections that are included based on the section flags
5325 of an input section, INPUT_SECTION_FLAGS may be used.
5327 Here is a simple example for using Section header flags for ELF sections:
5332 .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @}
5333 .text2 : @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @}
5338 In this example, the output section @samp{.text} will be comprised of any
5339 input section matching the name *(.text) whose section header flags
5340 @code{SHF_MERGE} and @code{SHF_STRINGS} are set. The output section
5341 @samp{.text2} will be comprised of any input section matching the name *(.text)
5342 whose section header flag @code{SHF_WRITE} is clear.
5344 You can also specify files within archives by writing a pattern
5345 matching the archive, a colon, then the pattern matching the file,
5346 with no whitespace around the colon.
5350 matches file within archive
5352 matches the whole archive
5354 matches file but not one in an archive
5357 Either one or both of @samp{archive} and @samp{file} can contain shell
5358 wildcards. On DOS based file systems, the linker will assume that a
5359 single letter followed by a colon is a drive specifier, so
5360 @samp{c:myfile.o} is a simple file specification, not @samp{myfile.o}
5361 within an archive called @samp{c}. @samp{archive:file} filespecs may
5362 also be used within an @code{EXCLUDE_FILE} list, but may not appear in
5363 other linker script contexts. For instance, you cannot extract a file
5364 from an archive by using @samp{archive:file} in an @code{INPUT}
5367 If you use a file name without a list of sections, then all sections in
5368 the input file will be included in the output section. This is not
5369 commonly done, but it may by useful on occasion. For example:
5374 When you use a file name which is not an @samp{archive:file} specifier
5375 and does not contain any wild card
5376 characters, the linker will first see if you also specified the file
5377 name on the linker command line or in an @code{INPUT} command. If you
5378 did not, the linker will attempt to open the file as an input file, as
5379 though it appeared on the command line. Note that this differs from an
5380 @code{INPUT} command, because the linker will not search for the file in
5381 the archive search path.
5383 @node Input Section Wildcards
5384 @subsubsection Input Section Wildcard Patterns
5385 @cindex input section wildcards
5386 @cindex wildcard file name patterns
5387 @cindex file name wildcard patterns
5388 @cindex section name wildcard patterns
5389 In an input section description, either the file name or the section
5390 name or both may be wildcard patterns.
5392 The file name of @samp{*} seen in many examples is a simple wildcard
5393 pattern for the file name.
5395 The wildcard patterns are like those used by the Unix shell.
5399 matches any number of characters
5401 matches any single character
5403 matches a single instance of any of the @var{chars}; the @samp{-}
5404 character may be used to specify a range of characters, as in
5405 @samp{[a-z]} to match any lower case letter
5407 quotes the following character
5410 File name wildcard patterns only match files which are explicitly
5411 specified on the command line or in an @code{INPUT} command. The linker
5412 does not search directories to expand wildcards.
5414 If a file name matches more than one wildcard pattern, or if a file name
5415 appears explicitly and is also matched by a wildcard pattern, the linker
5416 will use the first match in the linker script. For example, this
5417 sequence of input section descriptions is probably in error, because the
5418 @file{data.o} rule will not be used:
5420 .data : @{ *(.data) @}
5421 .data1 : @{ data.o(.data) @}
5424 @cindex SORT_BY_NAME
5425 Normally, the linker will place files and sections matched by wildcards
5426 in the order in which they are seen during the link. You can change
5427 this by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
5428 pattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}). When the
5429 @code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
5430 into ascending order by name before placing them in the output file.
5432 @cindex SORT_BY_ALIGNMENT
5433 @code{SORT_BY_ALIGNMENT} is similar to @code{SORT_BY_NAME}.
5434 @code{SORT_BY_ALIGNMENT} will sort sections into descending order of
5435 alignment before placing them in the output file. Placing larger
5436 alignments before smaller alignments can reduce the amount of padding
5439 @cindex SORT_BY_INIT_PRIORITY
5440 @code{SORT_BY_INIT_PRIORITY} is also similar to @code{SORT_BY_NAME}.
5441 @code{SORT_BY_INIT_PRIORITY} will sort sections into ascending
5442 numerical order of the GCC init_priority attribute encoded in the
5443 section name before placing them in the output file. In
5444 @code{.init_array.NNNNN} and @code{.fini_array.NNNNN}, @code{NNNNN} is
5445 the init_priority. In @code{.ctors.NNNNN} and @code{.dtors.NNNNN},
5446 @code{NNNNN} is 65535 minus the init_priority.
5449 @code{SORT} is an alias for @code{SORT_BY_NAME}.
5452 @code{REVERSE} indicates that the sorting should be reversed. If used
5453 on its own then @code{REVERSE} implies @code{SORT_BY_NAME}, otherwise
5454 it reverses the enclosed @code{SORT..} command. Note - reverse
5455 sorting of alignment is not currently supported.
5457 Note - the sorting commands only accept a single wildcard pattern. So
5458 for example the following will not work:
5460 *(REVERSE(.text* .init*))
5462 To resolve this problem list the patterns individually, like this:
5468 Note - you can put the @code{EXCLUDE_FILE} command inside a sorting
5469 command, but not the other way around. So for example:
5471 *(SORT_BY_NAME(EXCLUDE_FILE(foo) .text*))
5475 *(EXCLUDE_FILE(foo) SORT_BY_NAME(.text*))
5480 When there are nested section sorting commands in linker script, there
5481 can be at most 1 level of nesting for section sorting commands.
5485 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5486 It will sort the input sections by name first, then by alignment if two
5487 sections have the same name.
5489 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5490 It will sort the input sections by alignment first, then by name if two
5491 sections have the same alignment.
5493 @code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is
5494 treated the same as @code{SORT_BY_NAME} (wildcard section pattern).
5496 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
5497 is treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
5499 @code{SORT_BY_NAME} (@code{REVERSE} (wildcard section pattern))
5500 reverse sorts by name.
5502 @code{REVERSE} (@code{SORT_BY_NAME} (wildcard section pattern))
5503 reverse sorts by name.
5505 @code{SORT_BY_INIT_PRIORITY} (@code{REVERSE} (wildcard section pattern))
5506 reverse sorts by init priority.
5508 All other nested section sorting commands are invalid.
5511 When both command-line section sorting option and linker script
5512 section sorting command are used, section sorting command always
5513 takes precedence over the command-line option.
5515 If the section sorting command in linker script isn't nested, the
5516 command-line option will make the section sorting command to be
5517 treated as nested sorting command.
5521 @code{SORT_BY_NAME} (wildcard section pattern ) with
5522 @option{--sort-sections alignment} is equivalent to
5523 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5525 @code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
5526 @option{--sort-section name} is equivalent to
5527 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5530 If the section sorting command in linker script is nested, the
5531 command-line option will be ignored.
5534 @code{SORT_NONE} disables section sorting by ignoring the command-line
5535 section sorting option.
5537 If you ever get confused about where input sections are going, use the
5538 @samp{-M} linker option to generate a map file. The map file shows
5539 precisely how input sections are mapped to output sections.
5541 This example shows how wildcard patterns might be used to partition
5542 files. This linker script directs the linker to place all @samp{.text}
5543 sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
5544 The linker will place the @samp{.data} section from all files beginning
5545 with an upper case character in @samp{.DATA}; for all other files, the
5546 linker will place the @samp{.data} section in @samp{.data}.
5550 .text : @{ *(.text) @}
5551 .DATA : @{ [A-Z]*(.data) @}
5552 .data : @{ *(.data) @}
5553 .bss : @{ *(.bss) @}
5558 @node Input Section Common
5559 @subsubsection Input Section for Common Symbols
5560 @cindex common symbol placement
5561 @cindex uninitialized data placement
5562 A special notation is needed for common symbols, because in many object
5563 file formats common symbols do not have a particular input section. The
5564 linker treats common symbols as though they are in an input section
5565 named @samp{COMMON}.
5567 You may use file names with the @samp{COMMON} section just as with any
5568 other input sections. You can use this to place common symbols from a
5569 particular input file in one section while common symbols from other
5570 input files are placed in another section.
5572 In most cases, common symbols in input files will be placed in the
5573 @samp{.bss} section in the output file. For example:
5575 .bss @{ *(.bss) *(COMMON) @}
5578 @cindex scommon section
5579 @cindex small common symbols
5580 Some object file formats have more than one type of common symbol. For
5581 example, the MIPS ELF object file format distinguishes standard common
5582 symbols and small common symbols. In this case, the linker will use a
5583 different special section name for other types of common symbols. In
5584 the case of MIPS ELF, the linker uses @samp{COMMON} for standard common
5585 symbols and @samp{.scommon} for small common symbols. This permits you
5586 to map the different types of common symbols into memory at different
5590 You will sometimes see @samp{[COMMON]} in old linker scripts. This
5591 notation is now considered obsolete. It is equivalent to
5594 @node Input Section Keep
5595 @subsubsection Input Section and Garbage Collection
5597 @cindex garbage collection
5598 When link-time garbage collection is in use (@samp{--gc-sections}),
5599 it is often useful to mark sections that should not be eliminated.
5600 This is accomplished by surrounding an input section's wildcard entry
5601 with @code{KEEP()}, as in @code{KEEP(*(.init))} or
5602 @code{KEEP(SORT_BY_NAME(*)(.ctors))}.
5604 @node Input Section Example
5605 @subsubsection Input Section Example
5606 The following example is a complete linker script. It tells the linker
5607 to read all of the sections from file @file{all.o} and place them at the
5608 start of output section @samp{outputa} which starts at location
5609 @samp{0x10000}. All of section @samp{.input1} from file @file{foo.o}
5610 follows immediately, in the same output section. All of section
5611 @samp{.input2} from @file{foo.o} goes into output section
5612 @samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
5613 All of the remaining @samp{.input1} and @samp{.input2} sections from any
5614 files are written to output section @samp{outputc}.
5642 If an output section's name is the same as the input section's name
5643 and is representable as a C identifier, then the linker will
5644 automatically @pxref{PROVIDE} two symbols: __start_SECNAME and
5645 __stop_SECNAME, where SECNAME is the name of the section. These
5646 indicate the start address and end address of the output section
5647 respectively. Note: most section names are not representable as
5648 C identifiers because they contain a @samp{.} character.
5650 @node Output Section Data
5651 @subsection Output Section Data
5653 @cindex section data
5654 @cindex output section data
5655 @kindex ASCIZ ``@var{string}''
5656 @kindex BYTE(@var{expression})
5657 @kindex SHORT(@var{expression})
5658 @kindex LONG(@var{expression})
5659 @kindex QUAD(@var{expression})
5660 @kindex SQUAD(@var{expression})
5661 You can include explicit bytes of data in an output section by using
5662 @code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
5663 an output section command. Each keyword is followed by an expression in
5664 parentheses providing the value to store (@pxref{Expressions}). The
5665 value of the expression is stored at the current value of the location
5668 The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
5669 store one, two, four, and eight bytes (respectively). After storing the
5670 bytes, the location counter is incremented by the number of bytes
5673 For example, this will store the byte 1 followed by the four byte value
5674 of the symbol @samp{addr}:
5680 When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
5681 same; they both store an 8 byte, or 64 bit, value. When both host and
5682 target are 32 bits, an expression is computed as 32 bits. In this case
5683 @code{QUAD} stores a 32 bit value zero extended to 64 bits, and
5684 @code{SQUAD} stores a 32 bit value sign extended to 64 bits.
5686 If the object file format of the output file has an explicit endianness,
5687 which is the normal case, the value will be stored in that endianness.
5688 When the object file format does not have an explicit endianness, as is
5689 true of, for example, S-records, the value will be stored in the
5690 endianness of the first input object file.
5692 You can include a zero-terminated string in an output section by using
5693 @code{ASCIZ}. The keyword is followed by a string which is stored at
5694 the current value of the location counter adding a zero byte at the
5695 end. If the string includes spaces it must be enclosed in double
5696 quotes. The string may contain '\n', '\r', '\t' and octal numbers.
5697 Hex numbers are not supported.
5699 For example, this string of 16 characters will create a 17 byte area
5701 ASCIZ "This is 16 bytes"
5704 Note---these commands only work inside a section description and not
5705 between them, so the following will produce an error from the linker:
5707 SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
5709 whereas this will work:
5711 SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
5714 @kindex FILL(@var{expression})
5715 @cindex holes, filling
5716 @cindex unspecified memory
5717 You may use the @code{FILL} command to set the fill pattern for the
5718 current section. It is followed by an expression in parentheses. Any
5719 otherwise unspecified regions of memory within the section (for example,
5720 gaps left due to the required alignment of input sections) are filled
5721 with the value of the expression, repeated as
5722 necessary. A @code{FILL} statement covers memory locations after the
5723 point at which it occurs in the section definition; by including more
5724 than one @code{FILL} statement, you can have different fill patterns in
5725 different parts of an output section.
5727 This example shows how to fill unspecified regions of memory with the
5733 The @code{FILL} command is similar to the @samp{=@var{fillexp}} output
5734 section attribute, but it only affects the
5735 part of the section following the @code{FILL} command, rather than the
5736 entire section. If both are used, the @code{FILL} command takes
5737 precedence. @xref{Output Section Fill}, for details on the fill
5740 Note - normally the value of @code{expression} is zero extended to 4
5741 bytes when used to fill gaps. Thus @samp{FILL(144)} will fill a
5742 region with repeats of the pattern @samp{0 0 0 144}. The value is
5743 treated as a big-endian number, so for example
5744 @samp{FILL(22 * 256 + 23)} will fill the region with repeats of the
5745 pattern @samp{0 0 22 23}. If the expression results in a value with
5746 more than 4 significant bytes only the least 4 bytes of the value will
5749 The above rules do not apply when the @code{expression} is a simple
5750 hexadecimal number. In this case zero extension is not performed and
5751 all bytes are significant. So @samp{FILL(0x90)} will fill a region with
5752 repeats of @samp{0x90} with no zero bytes, and @samp{FILL(0x9192)}
5753 will fill the region with repeats of @samp{0x91 0x92}. Zero bytes
5754 in a hexadecimal expression are significant even at the start, so
5755 @samp{FILL(0x0090)} will fill a region with repeats of @samp{0x00 0x90}.
5757 Hexadecimal numbers can be longer than 4 bytes, and all of the bytes
5758 are significant, so @samp{FILL(0x123456789a)} will fill a region with
5759 repeats of the 5 byte sequence @samp{0x12 0x34 0x56 0x78 0x9a}.
5760 Excess bytes in a hexadecimal value beyond the size of a region will
5761 be silently ignored.
5763 The above only applies to hexadecimal numbers specified as
5764 @samp{0x[0-9][a-f][A-F]}. Hexadecimal numbers specified with a
5765 @samp{$} prefix, or a @samp{h}, @samp{H}, @samp{x} or @samp{X} suffix
5766 will follow the normal fill value rules. This also applies to
5767 expressions that involve hexadecimal numbers, and hexadecimal numbers
5768 that have a magnitude suffix.
5770 @kindex LINKER_VERSION
5771 @cindex LINKER_VERSION
5772 The @code{LINKER_VERSION} command inserts a string containing the
5773 version of the linker at the current point. Note - by default this
5774 directive is disabled and will do nothing. It only becomes active if
5775 the @option{--enable-linker-version} command line option is used.
5777 Built-in linker scripts for ELF based targets already include this
5778 directive in their @samp{.comment} section.
5780 @node Output Section Keywords
5781 @subsection Output Section Keywords
5782 There are a couple of keywords which can appear as output section
5786 @kindex CREATE_OBJECT_SYMBOLS
5787 @cindex input filename symbols
5788 @cindex filename symbols
5789 @item CREATE_OBJECT_SYMBOLS
5790 The command tells the linker to create a symbol for each input file.
5791 The name of each symbol will be the name of the corresponding input
5792 file. The section of each symbol will be the output section in which
5793 the @code{CREATE_OBJECT_SYMBOLS} command appears.
5795 This is conventional for the a.out object file format. It is not
5796 normally used for any other object file format.
5798 @kindex CONSTRUCTORS
5799 @cindex C++ constructors, arranging in link
5800 @cindex constructors, arranging in link
5802 When linking using the a.out object file format, the linker uses an
5803 unusual set construct to support C++ global constructors and
5804 destructors. When linking object file formats which do not support
5805 arbitrary sections, such as ECOFF and XCOFF, the linker will
5806 automatically recognize C++ global constructors and destructors by name.
5807 For these object file formats, the @code{CONSTRUCTORS} command tells the
5808 linker to place constructor information in the output section where the
5809 @code{CONSTRUCTORS} command appears. The @code{CONSTRUCTORS} command is
5810 ignored for other object file formats.
5812 The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
5813 constructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
5814 Similarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
5815 the start and end of the global destructors. The
5816 first word in the list is the number of entries, followed by the address
5817 of each constructor or destructor, followed by a zero word. The
5818 compiler must arrange to actually run the code. For these object file
5819 formats @sc{gnu} C++ normally calls constructors from a subroutine
5820 @code{__main}; a call to @code{__main} is automatically inserted into
5821 the startup code for @code{main}. @sc{gnu} C++ normally runs
5822 destructors either by using @code{atexit}, or directly from the function
5825 For object file formats such as @code{COFF} or @code{ELF} which support
5826 arbitrary section names, @sc{gnu} C++ will normally arrange to put the
5827 addresses of global constructors and destructors into the @code{.ctors}
5828 and @code{.dtors} sections. Placing the following sequence into your
5829 linker script will build the sort of table which the @sc{gnu} C++
5830 runtime code expects to see.
5834 LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
5839 LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
5845 If you are using the @sc{gnu} C++ support for initialization priority,
5846 which provides some control over the order in which global constructors
5847 are run, you must sort the constructors at link time to ensure that they
5848 are executed in the correct order. When using the @code{CONSTRUCTORS}
5849 command, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead. When using the
5850 @code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
5851 @samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
5854 Normally the compiler and linker will handle these issues automatically,
5855 and you will not need to concern yourself with them. However, you may
5856 need to consider this if you are using C++ and writing your own linker
5861 @node Output Section Discarding
5862 @subsection Output Section Discarding
5863 @cindex discarding sections
5864 @cindex sections, discarding
5865 @cindex removing sections
5866 The linker will not normally create output sections with no contents.
5867 This is for convenience when referring to input sections that may or
5868 may not be present in any of the input files. For example:
5870 .foo : @{ *(.foo) @}
5873 will only create a @samp{.foo} section in the output file if there is a
5874 @samp{.foo} section in at least one input file, and if the input
5875 sections are not all empty. Other link script directives that allocate
5876 space in an output section will also create the output section. So
5877 too will assignments to dot even if the assignment does not create
5878 space, except for @samp{. = 0}, @samp{. = . + 0}, @samp{. = sym},
5879 @samp{. = . + sym} and @samp{. = ALIGN (. != 0, expr, 1)} when
5880 @samp{sym} is an absolute symbol of value 0 defined in the script.
5881 This allows you to force output of an empty section with @samp{. = .}.
5883 The linker will ignore address assignments (@pxref{Output Section Address})
5884 on discarded output sections, except when the linker script defines
5885 symbols in the output section. In that case the linker will obey
5886 the address assignments, possibly advancing dot even though the
5887 section is discarded.
5890 The special output section name @samp{/DISCARD/} may be used to discard
5891 input sections. Any input sections which are assigned to an output
5892 section named @samp{/DISCARD/} are not included in the output file.
5894 This can be used to discard input sections marked with the ELF flag
5895 @code{SHF_GNU_RETAIN}, which would otherwise have been saved from linker
5898 Note, sections that match the @samp{/DISCARD/} output section will be
5899 discarded even if they are in an ELF section group which has other
5900 members which are not being discarded. This is deliberate.
5901 Discarding takes precedence over grouping.
5903 @node Output Section Attributes
5904 @subsection Output Section Attributes
5905 @cindex output section attributes
5906 We showed above that the full description of an output section looked
5911 @var{section} [@var{address}] [(@var{type})] :
5913 [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
5914 [SUBALIGN(@var{subsection_align})]
5917 @var{output-section-command}
5918 @var{output-section-command}
5920 @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
5924 We've already described @var{section}, @var{address}, and
5925 @var{output-section-command}. In this section we will describe the
5926 remaining section attributes.
5929 * Output Section Type:: Output section type
5930 * Output Section LMA:: Output section LMA
5931 * Forced Output Alignment:: Forced Output Alignment
5932 * Forced Input Alignment:: Forced Input Alignment
5933 * Output Section Constraint:: Output section constraint
5934 * Output Section Region:: Output section region
5935 * Output Section Phdr:: Output section phdr
5936 * Output Section Fill:: Output section fill
5939 @node Output Section Type
5940 @subsubsection Output Section Type
5941 Each output section may have a type. The type is a keyword in
5942 parentheses. The following types are defined:
5947 The section should be marked as not loadable, so that it will not be
5948 loaded into memory when the program is run.
5951 The section should be marked as read-only.
5957 These type names are supported for backward compatibility, and are
5958 rarely used. They all have the same effect: the section should be
5959 marked as not allocatable, so that no memory is allocated for the
5960 section when the program is run.
5962 @item TYPE = @var{type}
5963 Set the section type to the integer @var{type}. When generating an ELF
5964 output file, type names @code{SHT_PROGBITS}, @code{SHT_STRTAB},
5965 @code{SHT_NOTE}, @code{SHT_NOBITS}, @code{SHT_INIT_ARRAY},
5966 @code{SHT_FINI_ARRAY}, and @code{SHT_PREINIT_ARRAY} are also allowed
5967 for @var{type}. It is the user's responsibility to ensure that any
5968 special requirements of the section type are met.
5970 Note - the TYPE only is used if some or all of the contents of the
5971 section do not have an implicit type of their own. So for example:
5973 .foo . (TYPE = SHT_PROGBITS) : @{ *(.bar) @}
5975 will set the type of section @samp{.foo} to the type of the section
5976 @samp{.bar} in the input files, which may not be the SHT_PROGBITS
5979 .foo . (TYPE = SHT_PROGBITS) : @{ BYTE(1) @}
5981 will set the type of @samp{.foo} to SHT_PROGBBITS. If it is necessary
5982 to override the type of incoming sections and force the output section
5983 type then an extra piece of untyped data will be needed:
5985 .foo . (TYPE = SHT_PROGBITS) : @{ BYTE(1); *(.bar) @}
5988 @item READONLY ( TYPE = @var{type} )
5989 This form of the syntax combines the @var{READONLY} type with the
5990 type specified by @var{type}.
5995 @cindex prevent unnecessary loading
5996 @cindex loading, preventing
5997 The linker normally sets the attributes of an output section based on
5998 the input sections which map into it. You can override this by using
5999 the section type. For example, in the script sample below, the
6000 @samp{ROM} section is addressed at memory location @samp{0} and does not
6001 need to be loaded when the program is run.
6005 ROM 0 (NOLOAD) : @{ @dots{} @}
6011 @node Output Section LMA
6012 @subsubsection Output Section LMA
6013 @kindex AT>@var{lma_region}
6014 @kindex AT(@var{lma})
6015 @cindex load address
6016 @cindex section load address
6017 Every section has a virtual address (VMA) and a load address (LMA); see
6018 @ref{Basic Script Concepts}. The virtual address is specified by the
6019 @pxref{Output Section Address} described earlier. The load address is
6020 specified by the @code{AT} or @code{AT>} keywords. Specifying a load
6021 address is optional.
6023 The @code{AT} keyword takes an expression as an argument. This
6024 specifies the exact load address of the section. The @code{AT>} keyword
6025 takes the name of a memory region as an argument. @xref{MEMORY}. The
6026 load address of the section is set to the next free address in the
6027 region, aligned to the section's alignment requirements.
6029 If neither @code{AT} nor @code{AT>} is specified for an allocatable
6030 section, the linker will use the following heuristic to determine the
6035 If the section has a specific VMA address, then this is used as
6036 the LMA address as well.
6039 If the section is not allocatable then its LMA is set to its VMA.
6042 Otherwise if a memory region can be found that is compatible
6043 with the current section, and this region contains at least one
6044 section, then the LMA is set so the difference between the
6045 VMA and LMA is the same as the difference between the VMA and LMA of
6046 the last section in the located region.
6049 If no memory regions have been declared then a default region
6050 that covers the entire address space is used in the previous step.
6053 If no suitable region could be found, or there was no previous
6054 section then the LMA is set equal to the VMA.
6057 @cindex ROM initialized data
6058 @cindex initialized data in ROM
6059 This feature is designed to make it easy to build a ROM image. For
6060 example, the following linker script creates three output sections: one
6061 called @samp{.text}, which starts at @code{0x1000}, one called
6062 @samp{.mdata}, which is loaded at the end of the @samp{.text} section
6063 even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
6064 uninitialized data at address @code{0x3000}. The symbol @code{_data} is
6065 defined with the value @code{0x2000}, which shows that the location
6066 counter holds the VMA value, not the LMA value.
6072 .text 0x1000 : @{ *(.text) _etext = . ; @}
6074 AT ( ADDR (.text) + SIZEOF (.text) )
6075 @{ _data = . ; *(.data); _edata = . ; @}
6077 @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@}
6082 The run-time initialization code for use with a program generated with
6083 this linker script would include something like the following, to copy
6084 the initialized data from the ROM image to its runtime address. Notice
6085 how this code takes advantage of the symbols defined by the linker
6090 extern char _etext, _data, _edata, _bstart, _bend;
6091 char *src = &_etext;
6094 /* ROM has data at end of text; copy it. */
6095 while (dst < &_edata)
6099 for (dst = &_bstart; dst< &_bend; dst++)
6104 @node Forced Output Alignment
6105 @subsubsection Forced Output Alignment
6106 @kindex ALIGN(@var{section_align})
6107 @cindex forcing output section alignment
6108 @cindex output section alignment
6109 You can increase an output section's alignment by using ALIGN. As an
6110 alternative you can enforce that the difference between the VMA and LMA remains
6111 intact throughout this output section with the ALIGN_WITH_INPUT attribute.
6113 @node Forced Input Alignment
6114 @subsubsection Forced Input Alignment
6115 @kindex SUBALIGN(@var{subsection_align})
6116 @cindex forcing input section alignment
6117 @cindex input section alignment
6118 You can force input section alignment within an output section by using
6119 SUBALIGN. The value specified overrides any alignment given by input
6120 sections, whether larger or smaller.
6122 @node Output Section Constraint
6123 @subsubsection Output Section Constraint
6126 @cindex constraints on output sections
6127 You can specify that an output section should only be created if all
6128 of its input sections are read-only or all of its input sections are
6129 read-write by using the keyword @code{ONLY_IF_RO} and
6130 @code{ONLY_IF_RW} respectively.
6132 @node Output Section Region
6133 @subsubsection Output Section Region
6134 @kindex >@var{region}
6135 @cindex section, assigning to memory region
6136 @cindex memory regions and sections
6137 You can assign a section to a previously defined region of memory by
6138 using @samp{>@var{region}}. @xref{MEMORY}.
6140 Here is a simple example:
6143 MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
6144 SECTIONS @{ ROM : @{ *(.text) @} >rom @}
6148 @node Output Section Phdr
6149 @subsubsection Output Section Phdr
6151 @cindex section, assigning to program header
6152 @cindex program headers and sections
6153 You can assign a section to a previously defined program segment by
6154 using @samp{:@var{phdr}}. @xref{PHDRS}. If a section is assigned to
6155 one or more segments, then all subsequent allocated sections will be
6156 assigned to those segments as well, unless they use an explicitly
6157 @code{:@var{phdr}} modifier. You can use @code{:NONE} to tell the
6158 linker to not put the section in any segment at all.
6160 Here is a simple example:
6163 PHDRS @{ text PT_LOAD ; @}
6164 SECTIONS @{ .text : @{ *(.text) @} :text @}
6168 @node Output Section Fill
6169 @subsubsection Output Section Fill
6170 @kindex =@var{fillexp}
6171 @cindex section fill pattern
6172 @cindex fill pattern, entire section
6173 You can set the fill pattern for an entire section by using
6174 @samp{=@var{fillexp}}. @var{fillexp} is an expression
6175 (@pxref{Expressions}). Any otherwise unspecified regions of memory
6176 within the output section (for example, gaps left due to the required
6177 alignment of input sections) will be filled with the value, repeated as
6178 necessary. If the fill expression is a simple hex number, ie. a string
6179 of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
6180 an arbitrarily long sequence of hex digits can be used to specify the
6181 fill pattern; Leading zeros become part of the pattern too. For all
6182 other cases, including extra parentheses or a unary @code{+}, the fill
6183 pattern is the four least significant bytes of the value of the
6184 expression. If the value is less than four bytes in size then it will
6185 be zero extended to four bytes. In all cases, the number is big-endian.
6188 Fill Value Fill Pattern
6194 You can also change the fill value with a @code{FILL} command in the
6195 output section commands; (@pxref{Output Section Data}).
6197 Here is a simple example:
6200 SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
6204 @node Overlay Description
6205 @subsection Overlay Description
6208 An overlay description provides an easy way to describe sections which
6209 are to be loaded as part of a single memory image but are to be run at
6210 the same memory address. At run time, some sort of overlay manager will
6211 copy the overlaid sections in and out of the runtime memory address as
6212 required, perhaps by simply manipulating addressing bits. This approach
6213 can be useful, for example, when a certain region of memory is faster
6216 Overlays are described using the @code{OVERLAY} command. The
6217 @code{OVERLAY} command is used within a @code{SECTIONS} command, like an
6218 output section description. The full syntax of the @code{OVERLAY}
6219 command is as follows:
6222 OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
6226 @var{output-section-command}
6227 @var{output-section-command}
6229 @} [:@var{phdr}@dots{}] [=@var{fill}]
6232 @var{output-section-command}
6233 @var{output-section-command}
6235 @} [:@var{phdr}@dots{}] [=@var{fill}]
6237 @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] [,]
6241 Everything is optional except @code{OVERLAY} (a keyword), and each
6242 section must have a name (@var{secname1} and @var{secname2} above). The
6243 section definitions within the @code{OVERLAY} construct are identical to
6244 those within the general @code{SECTIONS} construct (@pxref{SECTIONS}),
6245 except that no addresses and no memory regions may be defined for
6246 sections within an @code{OVERLAY}.
6248 The comma at the end may be required if a @var{fill} is used and
6249 the next @var{sections-command} looks like a continuation of the expression.
6251 The sections are all defined with the same starting address. The load
6252 addresses of the sections are arranged such that they are consecutive in
6253 memory starting at the load address used for the @code{OVERLAY} as a
6254 whole (as with normal section definitions, the load address is optional,
6255 and defaults to the start address; the start address is also optional,
6256 and defaults to the current value of the location counter).
6258 If the @code{NOCROSSREFS} keyword is used, and there are any
6259 references among the sections, the linker will report an error. Since
6260 the sections all run at the same address, it normally does not make
6261 sense for one section to refer directly to another.
6262 @xref{Miscellaneous Commands, NOCROSSREFS}.
6264 For each section within the @code{OVERLAY}, the linker automatically
6265 provides two symbols. The symbol @code{__load_start_@var{secname}} is
6266 defined as the starting load address of the section. The symbol
6267 @code{__load_stop_@var{secname}} is defined as the final load address of
6268 the section. Any characters within @var{secname} which are not legal
6269 within C identifiers are removed. C (or assembler) code may use these
6270 symbols to move the overlaid sections around as necessary.
6272 At the end of the overlay, the value of the location counter is set to
6273 the start address of the overlay plus the size of the largest section.
6275 Here is an example. Remember that this would appear inside a
6276 @code{SECTIONS} construct.
6279 OVERLAY 0x1000 : AT (0x4000)
6281 .text0 @{ o1/*.o(.text) @}
6282 .text1 @{ o2/*.o(.text) @}
6287 This will define both @samp{.text0} and @samp{.text1} to start at
6288 address 0x1000. @samp{.text0} will be loaded at address 0x4000, and
6289 @samp{.text1} will be loaded immediately after @samp{.text0}. The
6290 following symbols will be defined if referenced: @code{__load_start_text0},
6291 @code{__load_stop_text0}, @code{__load_start_text1},
6292 @code{__load_stop_text1}.
6294 C code to copy overlay @code{.text1} into the overlay area might look
6299 extern char __load_start_text1, __load_stop_text1;
6300 memcpy ((char *) 0x1000, &__load_start_text1,
6301 &__load_stop_text1 - &__load_start_text1);
6305 Note that the @code{OVERLAY} command is just syntactic sugar, since
6306 everything it does can be done using the more basic commands. The above
6307 example could have been written identically as follows.
6311 .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
6312 PROVIDE (__load_start_text0 = LOADADDR (.text0));
6313 PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
6314 .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
6315 PROVIDE (__load_start_text1 = LOADADDR (.text1));
6316 PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
6317 . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
6322 @section MEMORY Command
6324 @cindex memory regions
6325 @cindex regions of memory
6326 @cindex allocating memory
6327 @cindex discontinuous memory
6328 The linker's default configuration permits allocation of all available
6329 memory. You can override this by using the @code{MEMORY} command.
6331 The @code{MEMORY} command describes the location and size of blocks of
6332 memory in the target. You can use it to describe which memory regions
6333 may be used by the linker, and which memory regions it must avoid. You
6334 can then assign sections to particular memory regions. The linker will
6335 set section addresses based on the memory regions, and will warn about
6336 regions that become too full. The linker will not shuffle sections
6337 around to fit into the available regions.
6339 A linker script may contain many uses of the @code{MEMORY} command,
6340 however, all memory blocks defined are treated as if they were
6341 specified inside a single @code{MEMORY} command. The syntax for
6347 @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
6353 The @var{name} is a name used in the linker script to refer to the
6354 region. The region name has no meaning outside of the linker script.
6355 Region names are stored in a separate name space, and will not conflict
6356 with symbol names, file names, or section names. Each memory region
6357 must have a distinct name within the @code{MEMORY} command. However you can
6358 add later alias names to existing memory regions with the @ref{REGION_ALIAS}
6361 @cindex memory region attributes
6362 The @var{attr} string is an optional list of attributes that specify
6363 whether to use a particular memory region for an input section which is
6364 not explicitly mapped in the linker script. As described in
6365 @ref{SECTIONS}, if you do not specify an output section for some input
6366 section, the linker will create an output section with the same name as
6367 the input section. If you define region attributes, the linker will use
6368 them to select the memory region for the output section that it creates.
6370 The @var{attr} string must consist only of the following characters:
6385 Invert the sense of any of the attributes that follow
6388 If an unmapped section matches any of the listed attributes other than
6389 @samp{!}, it will be placed in the memory region. The @samp{!}
6390 attribute reverses the test for the characters that follow, so that an
6391 unmapped section will be placed in the memory region only if it does
6392 not match any of the attributes listed afterwards. Thus an attribute
6393 string of @samp{RW!X} will match any unmapped section that has either
6394 or both of the @samp{R} and @samp{W} attributes, but only as long as
6395 the section does not also have the @samp{X} attribute.
6400 The @var{origin} is an numerical expression for the start address of
6401 the memory region. The expression must evaluate to a constant and it
6402 cannot involve any symbols. The keyword @code{ORIGIN} may be
6403 abbreviated to @code{org} or @code{o} (but not, for example,
6409 The @var{len} is an expression for the size in bytes of the memory
6410 region. As with the @var{origin} expression, the expression must
6411 be numerical only and must evaluate to a constant. The keyword
6412 @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
6414 In the following example, we specify that there are two memory regions
6415 available for allocation: one starting at @samp{0} for 256 kilobytes,
6416 and the other starting at @samp{0x40000000} for four megabytes. The
6417 linker will place into the @samp{rom} memory region every section which
6418 is not explicitly mapped into a memory region, and is either read-only
6419 or executable. The linker will place other sections which are not
6420 explicitly mapped into a memory region into the @samp{ram} memory
6427 rom (rx) : ORIGIN = 0, LENGTH = 256K
6428 ram (!rx) : org = 0x40000000, l = 4M
6433 Once you define a memory region, you can direct the linker to place
6434 specific output sections into that memory region by using the
6435 @samp{>@var{region}} output section attribute. For example, if you have
6436 a memory region named @samp{mem}, you would use @samp{>mem} in the
6437 output section definition. @xref{Output Section Region}. If no address
6438 was specified for the output section, the linker will set the address to
6439 the next available address within the memory region. If the combined
6440 output sections directed to a memory region are too large for the
6441 region, the linker will issue an error message.
6443 It is possible to access the origin and length of a memory in an
6444 expression via the @code{ORIGIN(@var{memory})} and
6445 @code{LENGTH(@var{memory})} functions:
6449 _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
6454 @section PHDRS Command
6456 @cindex program headers
6457 @cindex ELF program headers
6458 @cindex program segments
6459 @cindex segments, ELF
6460 The ELF object file format uses @dfn{program headers}, also knows as
6461 @dfn{segments}. The program headers describe how the program should be
6462 loaded into memory. You can print them out by using the @code{objdump}
6463 program with the @samp{-p} option.
6465 When you run an ELF program on a native ELF system, the system loader
6466 reads the program headers in order to figure out how to load the
6467 program. This will only work if the program headers are set correctly.
6468 This manual does not describe the details of how the system loader
6469 interprets program headers; for more information, see the ELF ABI.
6471 The linker will create reasonable program headers by default. However,
6472 in some cases, you may need to specify the program headers more
6473 precisely. You may use the @code{PHDRS} command for this purpose. When
6474 the linker sees the @code{PHDRS} command in the linker script, it will
6475 not create any program headers other than the ones specified.
6477 The linker only pays attention to the @code{PHDRS} command when
6478 generating an ELF output file. In other cases, the linker will simply
6479 ignore @code{PHDRS}.
6481 This is the syntax of the @code{PHDRS} command. The words @code{PHDRS},
6482 @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
6488 @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
6489 [ FLAGS ( @var{flags} ) ] ;
6494 The @var{name} is used only for reference in the @code{SECTIONS} command
6495 of the linker script. It is not put into the output file. Program
6496 header names are stored in a separate name space, and will not conflict
6497 with symbol names, file names, or section names. Each program header
6498 must have a distinct name. The headers are processed in order and it
6499 is usual for them to map to sections in ascending load address order.
6501 Certain program header types describe segments of memory which the
6502 system loader will load from the file. In the linker script, you
6503 specify the contents of these segments by placing allocatable output
6504 sections in the segments. You use the @samp{:@var{phdr}} output section
6505 attribute to place a section in a particular segment. @xref{Output
6508 It is normal to put certain sections in more than one segment. This
6509 merely implies that one segment of memory contains another. You may
6510 repeat @samp{:@var{phdr}}, using it once for each segment which should
6511 contain the section.
6513 If you place a section in one or more segments using @samp{:@var{phdr}},
6514 then the linker will place all subsequent allocatable sections which do
6515 not specify @samp{:@var{phdr}} in the same segments. This is for
6516 convenience, since generally a whole set of contiguous sections will be
6517 placed in a single segment. You can use @code{:NONE} to override the
6518 default segment and tell the linker to not put the section in any
6523 You may use the @code{FILEHDR} and @code{PHDRS} keywords after
6524 the program header type to further describe the contents of the segment.
6525 The @code{FILEHDR} keyword means that the segment should include the ELF
6526 file header. The @code{PHDRS} keyword means that the segment should
6527 include the ELF program headers themselves. If applied to a loadable
6528 segment (@code{PT_LOAD}), all prior loadable segments must have one of
6531 The @var{type} may be one of the following. The numbers indicate the
6532 value of the keyword.
6535 @item @code{PT_NULL} (0)
6536 Indicates an unused program header.
6538 @item @code{PT_LOAD} (1)
6539 Indicates that this program header describes a segment to be loaded from
6542 @item @code{PT_DYNAMIC} (2)
6543 Indicates a segment where dynamic linking information can be found.
6545 @item @code{PT_INTERP} (3)
6546 Indicates a segment where the name of the program interpreter may be
6549 @item @code{PT_NOTE} (4)
6550 Indicates a segment holding note information.
6552 @item @code{PT_SHLIB} (5)
6553 A reserved program header type, defined but not specified by the ELF
6556 @item @code{PT_PHDR} (6)
6557 Indicates a segment where the program headers may be found.
6559 @item @code{PT_TLS} (7)
6560 Indicates a segment containing thread local storage.
6562 @item @var{expression}
6563 An expression giving the numeric type of the program header. This may
6564 be used for types not defined above.
6567 You can specify that a segment should be loaded at a particular address
6568 in memory by using an @code{AT} expression. This is identical to the
6569 @code{AT} command used as an output section attribute (@pxref{Output
6570 Section LMA}). The @code{AT} command for a program header overrides the
6571 output section attribute.
6573 The linker will normally set the segment flags based on the sections
6574 which comprise the segment. You may use the @code{FLAGS} keyword to
6575 explicitly specify the segment flags. The value of @var{flags} must be
6576 an integer. It is used to set the @code{p_flags} field of the program
6579 Here is an example of @code{PHDRS}. This shows a typical set of program
6580 headers used on a native ELF system.
6586 headers PT_PHDR PHDRS ;
6588 text PT_LOAD FILEHDR PHDRS ;
6590 dynamic PT_DYNAMIC ;
6596 .interp : @{ *(.interp) @} :text :interp
6597 .text : @{ *(.text) @} :text
6598 .rodata : @{ *(.rodata) @} /* defaults to :text */
6600 . = . + 0x1000; /* move to a new page in memory */
6601 .data : @{ *(.data) @} :data
6602 .dynamic : @{ *(.dynamic) @} :data :dynamic
6609 @section VERSION Command
6610 @kindex VERSION @{script text@}
6611 @cindex symbol versions
6612 @cindex version script
6613 @cindex versions of symbols
6614 The linker supports symbol versions when using ELF. Symbol versions are
6615 only useful when using shared libraries. The dynamic linker can use
6616 symbol versions to select a specific version of a function when it runs
6617 a program that may have been linked against an earlier version of the
6620 You can include a version script directly in the main linker script, or
6621 you can supply the version script as an implicit linker script. You can
6622 also use the @samp{--version-script} linker option.
6624 The syntax of the @code{VERSION} command is simply
6626 VERSION @{ version-script-commands @}
6629 The format of the version script commands is identical to that used by
6630 Sun's linker in Solaris 2.5. The version script defines a tree of
6631 version nodes. You specify the node names and interdependencies in the
6632 version script. You can specify which symbols are bound to which
6633 version nodes, and you can reduce a specified set of symbols to local
6634 scope so that they are not globally visible outside of the shared
6637 The easiest way to demonstrate the version script language is with a few
6663 This example version script defines three version nodes. The first
6664 version node defined is @samp{VERS_1.1}; it has no other dependencies.
6665 The script binds the symbol @samp{foo1} to @samp{VERS_1.1}. It reduces
6666 a number of symbols to local scope so that they are not visible outside
6667 of the shared library; this is done using wildcard patterns, so that any
6668 symbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
6669 is matched. The wildcard patterns available are the same as those used
6670 in the shell when matching filenames (also known as ``globbing'').
6671 However, if you specify the symbol name inside double quotes, then the
6672 name is treated as literal, rather than as a glob pattern.
6674 Next, the version script defines node @samp{VERS_1.2}. This node
6675 depends upon @samp{VERS_1.1}. The script binds the symbol @samp{foo2}
6676 to the version node @samp{VERS_1.2}.
6678 Finally, the version script defines node @samp{VERS_2.0}. This node
6679 depends upon @samp{VERS_1.2}. The scripts binds the symbols @samp{bar1}
6680 and @samp{bar2} are bound to the version node @samp{VERS_2.0}.
6682 When the linker finds a symbol defined in a library which is not
6683 specifically bound to a version node, it will effectively bind it to an
6684 unspecified base version of the library. You can bind all otherwise
6685 unspecified symbols to a given version node by using @samp{global: *;}
6686 somewhere in the version script. Note that it's slightly crazy to use
6687 wildcards in a global spec except on the last version node. Global
6688 wildcards elsewhere run the risk of accidentally adding symbols to the
6689 set exported for an old version. That's wrong since older versions
6690 ought to have a fixed set of symbols.
6692 The names of the version nodes have no specific meaning other than what
6693 they might suggest to the person reading them. The @samp{2.0} version
6694 could just as well have appeared in between @samp{1.1} and @samp{1.2}.
6695 However, this would be a confusing way to write a version script.
6697 Node name can be omitted, provided it is the only version node
6698 in the version script. Such version script doesn't assign any versions to
6699 symbols, only selects which symbols will be globally visible out and which
6703 @{ global: foo; bar; local: *; @};
6706 When you link an application against a shared library that has versioned
6707 symbols, the application itself knows which version of each symbol it
6708 requires, and it also knows which version nodes it needs from each
6709 shared library it is linked against. Thus at runtime, the dynamic
6710 loader can make a quick check to make sure that the libraries you have
6711 linked against do in fact supply all of the version nodes that the
6712 application will need to resolve all of the dynamic symbols. In this
6713 way it is possible for the dynamic linker to know with certainty that
6714 all external symbols that it needs will be resolvable without having to
6715 search for each symbol reference.
6717 The symbol versioning is in effect a much more sophisticated way of
6718 doing minor version checking that SunOS does. The fundamental problem
6719 that is being addressed here is that typically references to external
6720 functions are bound on an as-needed basis, and are not all bound when
6721 the application starts up. If a shared library is out of date, a
6722 required interface may be missing; when the application tries to use
6723 that interface, it may suddenly and unexpectedly fail. With symbol
6724 versioning, the user will get a warning when they start their program if
6725 the libraries being used with the application are too old.
6727 There are several GNU extensions to Sun's versioning approach. The
6728 first of these is the ability to bind a symbol to a version node in the
6729 source file where the symbol is defined instead of in the versioning
6730 script. This was done mainly to reduce the burden on the library
6731 maintainer. You can do this by putting something like:
6733 __asm__(".symver original_foo,foo@@VERS_1.1");
6736 in the C source file. This renames the function @samp{original_foo} to
6737 be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
6738 The @samp{local:} directive can be used to prevent the symbol
6739 @samp{original_foo} from being exported. A @samp{.symver} directive
6740 takes precedence over a version script.
6742 The second GNU extension is to allow multiple versions of the same
6743 function to appear in a given shared library. In this way you can make
6744 an incompatible change to an interface without increasing the major
6745 version number of the shared library, while still allowing applications
6746 linked against the old interface to continue to function.
6748 To do this, you must use multiple @samp{.symver} directives in the
6749 source file. Here is an example:
6752 __asm__(".symver original_foo,foo@@");
6753 __asm__(".symver old_foo,foo@@VERS_1.1");
6754 __asm__(".symver old_foo1,foo@@VERS_1.2");
6755 __asm__(".symver new_foo,foo@@@@VERS_2.0");
6758 In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
6759 unspecified base version of the symbol. The source file that contains this
6760 example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
6761 @samp{old_foo1}, and @samp{new_foo}.
6763 When you have multiple definitions of a given symbol, there needs to be
6764 some way to specify a default version to which external references to
6765 this symbol will be bound. You can do this with the
6766 @samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. You can only
6767 declare one version of a symbol as the default in this manner; otherwise
6768 you would effectively have multiple definitions of the same symbol.
6770 If you wish to bind a reference to a specific version of the symbol
6771 within the shared library, you can use the aliases of convenience
6772 (i.e., @samp{old_foo}), or you can use the @samp{.symver} directive to
6773 specifically bind to an external version of the function in question.
6775 You can also specify the language in the version script:
6778 VERSION extern "lang" @{ version-script-commands @}
6781 The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
6782 The linker will iterate over the list of symbols at the link time and
6783 demangle them according to @samp{lang} before matching them to the
6784 patterns specified in @samp{version-script-commands}. The default
6785 @samp{lang} is @samp{C}.
6787 Demangled names may contains spaces and other special characters. As
6788 described above, you can use a glob pattern to match demangled names,
6789 or you can use a double-quoted string to match the string exactly. In
6790 the latter case, be aware that minor differences (such as differing
6791 whitespace) between the version script and the demangler output will
6792 cause a mismatch. As the exact string generated by the demangler
6793 might change in the future, even if the mangled name does not, you
6794 should check that all of your version directives are behaving as you
6795 expect when you upgrade.
6798 @section Expressions in Linker Scripts
6801 The syntax for expressions in the linker script language is identical to
6802 that of C expressions, except that whitespace is required in some
6803 places to resolve syntactic ambiguities. All expressions are
6804 evaluated as integers. All expressions are evaluated in the same
6805 size, which is 32 bits if both the host and target are 32 bits, and is
6808 You can use and set symbol values in expressions.
6810 The linker defines several special purpose builtin functions for use in
6814 * Constants:: Constants
6815 * Symbolic Constants:: Symbolic constants
6816 * Symbols:: Symbol Names
6817 * Orphan Sections:: Orphan Sections
6818 * Location Counter:: The Location Counter
6819 * Operators:: Operators
6820 * Evaluation:: Evaluation
6821 * Expression Section:: The Section of an Expression
6822 * Builtin Functions:: Builtin Functions
6826 @subsection Constants
6827 @cindex integer notation
6828 @cindex constants in linker scripts
6829 All constants are integers.
6831 As in C, the linker considers an integer beginning with @samp{0} to be
6832 octal, and an integer beginning with @samp{0x} or @samp{0X} to be
6833 hexadecimal. Alternatively the linker accepts suffixes of @samp{h} or
6834 @samp{H} for hexadecimal, @samp{o} or @samp{O} for octal, @samp{b} or
6835 @samp{B} for binary and @samp{d} or @samp{D} for decimal. Any integer
6836 value without a prefix or a suffix is considered to be decimal.
6838 @cindex scaled integers
6839 @cindex K and M integer suffixes
6840 @cindex M and K integer suffixes
6841 @cindex suffixes for integers
6842 @cindex integer suffixes
6843 In addition, you can use the suffixes @code{K} and @code{M} to scale a
6847 @c END TEXI2ROFF-KILL
6848 @code{1024} or @code{1024*1024}
6852 ${\rm 1024}$ or ${\rm 1024}^2$
6854 @c END TEXI2ROFF-KILL
6855 respectively. For example, the following
6856 all refer to the same quantity:
6865 Note - the @code{K} and @code{M} suffixes cannot be used in
6866 conjunction with the base suffixes mentioned above.
6868 @node Symbolic Constants
6869 @subsection Symbolic Constants
6870 @cindex symbolic constants
6872 It is possible to refer to target-specific constants via the use of
6873 the @code{CONSTANT(@var{name})} operator, where @var{name} is one of:
6878 The target's maximum page size.
6880 @item COMMONPAGESIZE
6881 @kindex COMMONPAGESIZE
6882 The target's default page size.
6888 .text ALIGN (CONSTANT (MAXPAGESIZE)) : @{ *(.text) @}
6891 will create a text section aligned to the largest page boundary
6892 supported by the target.
6895 @subsection Symbol Names
6896 @cindex symbol names
6898 @cindex quoted symbol names
6900 Unless quoted, symbol names start with a letter, underscore, or period
6901 and may include letters, digits, underscores, periods, and hyphens.
6902 Unquoted symbol names must not conflict with any keywords. You can
6903 specify a symbol which contains odd characters or has the same name as a
6904 keyword by surrounding the symbol name in double quotes:
6907 "with a space" = "also with a space" + 10;
6910 Since symbols can contain many non-alphabetic characters, it is safest
6911 to delimit symbols with spaces. For example, @samp{A-B} is one symbol,
6912 whereas @samp{A - B} is an expression involving subtraction.
6914 @node Orphan Sections
6915 @subsection Orphan Sections
6917 Orphan sections are sections present in the input files which
6918 are not explicitly placed into the output file by the linker
6919 script. The linker will still copy these sections into the
6920 output file by either finding, or creating a suitable output section
6921 in which to place the orphaned input section.
6923 If the name of an orphaned input section exactly matches the name of
6924 an existing output section, then the orphaned input section will be
6925 placed at the end of that output section.
6927 If there is no output section with a matching name then new output
6928 sections will be created. Each new output section will have the same
6929 name as the orphan section placed within it. If there are multiple
6930 orphan sections with the same name, these will all be combined into
6931 one new output section.
6933 If new output sections are created to hold orphaned input sections,
6934 then the linker must decide where to place these new output sections
6935 in relation to existing output sections. On most modern targets, the
6936 linker attempts to place orphan sections after sections of the same
6937 attribute, such as code vs data, loadable vs non-loadable, etc. If no
6938 sections with matching attributes are found, or your target lacks this
6939 support, the orphan section is placed at the end of the file.
6941 The command-line options @samp{--orphan-handling} and @samp{--unique}
6942 (@pxref{Options,,Command-line Options}) can be used to control which
6943 output sections an orphan is placed in.
6945 @node Location Counter
6946 @subsection The Location Counter
6949 @cindex location counter
6950 @cindex current output location
6951 The special linker variable @dfn{dot} @samp{.} always contains the
6952 current output location counter. Since the @code{.} always refers to a
6953 location in an output section, it may only appear in an expression
6954 within a @code{SECTIONS} command. The @code{.} symbol may appear
6955 anywhere that an ordinary symbol is allowed in an expression.
6958 Assigning a value to @code{.} will cause the location counter to be
6959 moved. This may be used to create holes in the output section. The
6960 location counter may not be moved backwards inside an output section,
6961 and may not be moved backwards outside of an output section if so
6962 doing creates areas with overlapping LMAs.
6978 In the previous example, the @samp{.text} section from @file{file1} is
6979 located at the beginning of the output section @samp{output}. It is
6980 followed by a 1000 byte gap. Then the @samp{.text} section from
6981 @file{file2} appears, also with a 1000 byte gap following before the
6982 @samp{.text} section from @file{file3}. The notation @samp{= 0x12345678}
6983 specifies what data to write in the gaps (@pxref{Output Section Fill}).
6985 @cindex dot inside sections
6986 Note: @code{.} actually refers to the byte offset from the start of the
6987 current containing object. Normally this is the @code{SECTIONS}
6988 statement, whose start address is 0, hence @code{.} can be used as an
6989 absolute address. If @code{.} is used inside a section description
6990 however, it refers to the byte offset from the start of that section,
6991 not an absolute address. Thus in a script like this:
7009 The @samp{.text} section will be assigned a starting address of 0x100
7010 and a size of exactly 0x200 bytes, even if there is not enough data in
7011 the @samp{.text} input sections to fill this area. (If there is too
7012 much data, an error will be produced because this would be an attempt to
7013 move @code{.} backwards). The @samp{.data} section will start at 0x500
7014 and it will have an extra 0x600 bytes worth of space after the end of
7015 the values from the @samp{.data} input sections and before the end of
7016 the @samp{.data} output section itself.
7018 @cindex dot outside sections
7019 Setting symbols to the value of the location counter outside of an
7020 output section statement can result in unexpected values if the linker
7021 needs to place orphan sections. For example, given the following:
7027 .text: @{ *(.text) @}
7031 .data: @{ *(.data) @}
7036 If the linker needs to place some input section, e.g. @code{.rodata},
7037 not mentioned in the script, it might choose to place that section
7038 between @code{.text} and @code{.data}. You might think the linker
7039 should place @code{.rodata} on the blank line in the above script, but
7040 blank lines are of no particular significance to the linker. As well,
7041 the linker doesn't associate the above symbol names with their
7042 sections. Instead, it assumes that all assignments or other
7043 statements belong to the previous output section, except for the
7044 special case of an assignment to @code{.}. I.e., the linker will
7045 place the orphan @code{.rodata} section as if the script was written
7052 .text: @{ *(.text) @}
7056 .rodata: @{ *(.rodata) @}
7057 .data: @{ *(.data) @}
7062 This may or may not be the script author's intention for the value of
7063 @code{start_of_data}. One way to influence the orphan section
7064 placement is to assign the location counter to itself, as the linker
7065 assumes that an assignment to @code{.} is setting the start address of
7066 a following output section and thus should be grouped with that
7067 section. So you could write:
7073 .text: @{ *(.text) @}
7078 .data: @{ *(.data) @}
7083 Now, the orphan @code{.rodata} section will be placed between
7084 @code{end_of_text} and @code{start_of_data}.
7088 @subsection Operators
7089 @cindex operators for arithmetic
7090 @cindex arithmetic operators
7091 @cindex precedence in expressions
7092 The linker recognizes the standard C set of arithmetic operators, with
7093 the standard bindings and precedence levels:
7096 @c END TEXI2ROFF-KILL
7098 precedence associativity Operators Notes
7112 13 right += -= *= /= <<= >>= &= |= ^= (2)
7116 (1) Prefix operators
7117 (2) @xref{Assignments}.
7121 \vskip \baselineskip
7122 %"lispnarrowing" is the extra indent used generally for smallexample
7123 \hskip\lispnarrowing\vbox{\offinterlineskip
7126 {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
7127 height2pt&\omit&&\omit&&\omit&\cr
7128 &Precedence&& Associativity &&{\rm Operators}&\cr
7129 height2pt&\omit&&\omit&&\omit&\cr
7131 height2pt&\omit&&\omit&&\omit&\cr
7133 % '176 is tilde, '~' in tt font
7134 &1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
7135 &2&&left&&* / \%&\cr
7138 &5&&left&& > < <= >=&\cr
7143 &10&&left&&{\&\&}&\cr
7146 &13&&right&&\qquad += -= *= /= <<= >>= \&= |= \^{}=\qquad\ddag&\cr
7148 height2pt&\omit&&\omit&&\omit&\cr}
7153 @obeylines@parskip=0pt@parindent=0pt
7154 @dag@quad Prefix operators.
7155 @ddag@quad @xref{Assignments}.
7158 @c END TEXI2ROFF-KILL
7161 @subsection Evaluation
7162 @cindex lazy evaluation
7163 @cindex expression evaluation order
7164 The linker evaluates expressions lazily. It only computes the value of
7165 an expression when absolutely necessary.
7167 The linker needs some information, such as the value of the start
7168 address of the first section, and the origins and lengths of memory
7169 regions, in order to do any linking at all. These values are computed
7170 as soon as possible when the linker reads in the linker script.
7172 However, other values (such as symbol values) are not known or needed
7173 until after storage allocation. Such values are evaluated later, when
7174 other information (such as the sizes of output sections) is available
7175 for use in the symbol assignment expression.
7177 The sizes of sections cannot be known until after allocation, so
7178 assignments dependent upon these are not performed until after
7181 Some expressions, such as those depending upon the location counter
7182 @samp{.}, must be evaluated during section allocation.
7184 If the result of an expression is required, but the value is not
7185 available, then an error results. For example, a script like the
7191 .text 9+this_isnt_constant :
7197 will cause the error message @samp{non constant expression for initial
7200 @node Expression Section
7201 @subsection The Section of an Expression
7202 @cindex expression sections
7203 @cindex absolute expressions
7204 @cindex relative expressions
7205 @cindex absolute and relocatable symbols
7206 @cindex relocatable and absolute symbols
7207 @cindex symbols, relocatable and absolute
7208 Addresses and symbols may be section relative, or absolute. A section
7209 relative symbol is relocatable. If you request relocatable output
7210 using the @samp{-r} option, a further link operation may change the
7211 value of a section relative symbol. On the other hand, an absolute
7212 symbol will retain the same value throughout any further link
7215 Some terms in linker expressions are addresses. This is true of
7216 section relative symbols and for builtin functions that return an
7217 address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
7218 @code{SEGMENT_START}. Other terms are simply numbers, or are builtin
7219 functions that return a non-address value, such as @code{LENGTH}.
7220 One complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
7221 (@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
7222 differently depending on their location, for compatibility with older
7223 versions of @code{ld}. Expressions appearing outside an output
7224 section definition treat all numbers as absolute addresses.
7225 Expressions appearing inside an output section definition treat
7226 absolute symbols as numbers. If @code{LD_FEATURE ("SANE_EXPR")} is
7227 given, then absolute symbols and numbers are simply treated as numbers
7230 In the following simple example,
7237 __executable_start = 0x100;
7241 __data_start = 0x10;
7249 both @code{.} and @code{__executable_start} are set to the absolute
7250 address 0x100 in the first two assignments, then both @code{.} and
7251 @code{__data_start} are set to 0x10 relative to the @code{.data}
7252 section in the second two assignments.
7254 For expressions involving numbers, relative addresses and absolute
7255 addresses, ld follows these rules to evaluate terms:
7259 Unary operations on an absolute address or number, and binary
7260 operations on two absolute addresses or two numbers, or between one
7261 absolute address and a number, apply the operator to the value(s).
7263 Unary operations on a relative address, and binary operations on two
7264 relative addresses in the same section or between one relative address
7265 and a number, apply the operator to the offset part of the address(es).
7267 Other binary operations, that is, between two relative addresses not
7268 in the same section, or between a relative address and an absolute
7269 address, first convert any non-absolute term to an absolute address
7270 before applying the operator.
7273 The result section of each sub-expression is as follows:
7277 An operation involving only numbers results in a number.
7279 The result of comparisons, @samp{&&} and @samp{||} is also a number.
7281 The result of other binary arithmetic and logical operations on two
7282 relative addresses in the same section or two absolute addresses
7283 (after above conversions) is also a number when
7284 @code{LD_FEATURE ("SANE_EXPR")} or inside an output section definition
7285 but an absolute address otherwise.
7287 The result of other operations on relative addresses or one
7288 relative address and a number, is a relative address in the same
7289 section as the relative operand(s).
7291 The result of other operations on absolute addresses (after above
7292 conversions) is an absolute address.
7295 You can use the builtin function @code{ABSOLUTE} to force an expression
7296 to be absolute when it would otherwise be relative. For example, to
7297 create an absolute symbol set to the address of the end of the output
7298 section @samp{.data}:
7302 .data : @{ *(.data) _edata = ABSOLUTE(.); @}
7306 If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
7307 @samp{.data} section.
7309 Using @code{LOADADDR} also forces an expression absolute, since this
7310 particular builtin function returns an absolute address.
7312 @node Builtin Functions
7313 @subsection Builtin Functions
7314 @cindex functions in expressions
7315 The linker script language includes a number of builtin functions for
7316 use in linker script expressions.
7319 @item ABSOLUTE(@var{exp})
7320 @kindex ABSOLUTE(@var{exp})
7321 @cindex expression, absolute
7322 Return the absolute (non-relocatable, as opposed to non-negative) value
7323 of the expression @var{exp}. Primarily useful to assign an absolute
7324 value to a symbol within a section definition, where symbol values are
7325 normally section relative. @xref{Expression Section}.
7327 @item ADDR(@var{section})
7328 @kindex ADDR(@var{section})
7329 @cindex section address in expression
7330 Return the address (VMA) of the named @var{section}. Your
7331 script must previously have defined the location of that section. In
7332 the following example, @code{start_of_output_1}, @code{symbol_1} and
7333 @code{symbol_2} are assigned equivalent values, except that
7334 @code{symbol_1} will be relative to the @code{.output1} section while
7335 the other two will be absolute:
7341 start_of_output_1 = ABSOLUTE(.);
7346 symbol_1 = ADDR(.output1);
7347 symbol_2 = start_of_output_1;
7353 @item ALIGN(@var{align})
7354 @itemx ALIGN(@var{exp},@var{align})
7355 @kindex ALIGN(@var{align})
7356 @kindex ALIGN(@var{exp},@var{align})
7357 @cindex round up location counter
7358 @cindex align location counter
7359 @cindex round up expression
7360 @cindex align expression
7361 Return the location counter (@code{.}) or arbitrary expression aligned
7362 to the next @var{align} boundary. The single operand @code{ALIGN}
7363 doesn't change the value of the location counter---it just does
7364 arithmetic on it. The two operand @code{ALIGN} allows an arbitrary
7365 expression to be aligned upwards (@code{ALIGN(@var{align})} is
7366 equivalent to @code{ALIGN(ABSOLUTE(.), @var{align})}).
7368 Here is an example which aligns the output @code{.data} section to the
7369 next @code{0x2000} byte boundary after the preceding section and sets a
7370 variable within the section to the next @code{0x8000} boundary after the
7375 .data ALIGN(0x2000): @{
7377 variable = ALIGN(0x8000);
7383 The first use of @code{ALIGN} in this example specifies the location of
7384 a section because it is used as the optional @var{address} attribute of
7385 a section definition (@pxref{Output Section Address}). The second use
7386 of @code{ALIGN} is used to defines the value of a symbol.
7388 The builtin function @code{NEXT} is closely related to @code{ALIGN}.
7390 @item ALIGNOF(@var{section})
7391 @kindex ALIGNOF(@var{section})
7392 @cindex section alignment
7393 Return the alignment in bytes of the named @var{section}, if that section has
7394 been allocated, or zero if the section has not been allocated. If the
7395 section does not exist in the linker script the linker will report an
7396 error. If @var{section} is @code{NEXT_SECTION} then @code{ALIGNOF} will
7397 return the alignment of the next allocated section specified in the
7398 linker script, or zero if there is no such section. In the following
7399 example, the alignment of the @code{.output} section is stored as the
7400 first value in that section.
7405 LONG (ALIGNOF (.output))
7412 @item BLOCK(@var{exp})
7413 @kindex BLOCK(@var{exp})
7414 This is a synonym for @code{ALIGN}, for compatibility with older linker
7415 scripts. It is most often seen when setting the address of an output
7418 @item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7419 @kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7420 This is equivalent to either
7422 (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
7426 (ALIGN(@var{maxpagesize})
7427 + ((. + @var{commonpagesize} - 1) & (@var{maxpagesize} - @var{commonpagesize})))
7430 depending on whether the latter uses fewer @var{commonpagesize} sized pages
7431 for the data segment (area between the result of this expression and
7432 @code{DATA_SEGMENT_END}) than the former or not.
7433 If the latter form is used, it means @var{commonpagesize} bytes of runtime
7434 memory will be saved at the expense of up to @var{commonpagesize} wasted
7435 bytes in the on-disk file.
7437 This expression can only be used directly in @code{SECTIONS} commands, not in
7438 any output section descriptions and only once in the linker script.
7439 @var{commonpagesize} should be less or equal to @var{maxpagesize} and should
7440 be the system page size the object wants to be optimized for while still
7441 running on system page sizes up to @var{maxpagesize}. Note however
7442 that @samp{-z relro} protection will not be effective if the system
7443 page size is larger than @var{commonpagesize}.
7448 . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
7451 @item DATA_SEGMENT_END(@var{exp})
7452 @kindex DATA_SEGMENT_END(@var{exp})
7453 This defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
7454 evaluation purposes.
7457 . = DATA_SEGMENT_END(.);
7460 @item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7461 @kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7462 This defines the end of the @code{PT_GNU_RELRO} segment when
7463 @samp{-z relro} option is used.
7464 When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
7465 does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
7466 @var{exp} + @var{offset} is aligned to the @var{commonpagesize}
7467 argument given to @code{DATA_SEGMENT_ALIGN}. If present in the linker
7468 script, it must be placed between @code{DATA_SEGMENT_ALIGN} and
7469 @code{DATA_SEGMENT_END}. Evaluates to the second argument plus any
7470 padding needed at the end of the @code{PT_GNU_RELRO} segment due to
7474 . = DATA_SEGMENT_RELRO_END(24, .);
7477 @item DEFINED(@var{symbol})
7478 @kindex DEFINED(@var{symbol})
7479 @cindex symbol defaults
7480 Return 1 if @var{symbol} is in the linker global symbol table and is
7481 defined before the statement using DEFINED in the script, otherwise
7482 return 0. You can use this function to provide
7483 default values for symbols. For example, the following script fragment
7484 shows how to set a global symbol @samp{begin} to the first location in
7485 the @samp{.text} section---but if a symbol called @samp{begin} already
7486 existed, its value is preserved:
7492 begin = DEFINED(begin) ? begin : . ;
7500 @item LENGTH(@var{memory})
7501 @kindex LENGTH(@var{memory})
7502 Return the length of the memory region named @var{memory}.
7504 @item LOADADDR(@var{section})
7505 @kindex LOADADDR(@var{section})
7506 @cindex section load address in expression
7507 Return the absolute LMA of the named @var{section}. (@pxref{Output
7510 @item LOG2CEIL(@var{exp})
7511 @kindex LOG2CEIL(@var{exp})
7512 Return the binary logarithm of @var{exp} rounded towards infinity.
7513 @code{LOG2CEIL(0)} returns 0.
7516 @item MAX(@var{exp1}, @var{exp2})
7517 Returns the maximum of @var{exp1} and @var{exp2}.
7520 @item MIN(@var{exp1}, @var{exp2})
7521 Returns the minimum of @var{exp1} and @var{exp2}.
7523 @item NEXT(@var{exp})
7524 @kindex NEXT(@var{exp})
7525 @cindex unallocated address, next
7526 Return the next unallocated address that is a multiple of @var{exp}.
7527 This function is closely related to @code{ALIGN(@var{exp})}; unless you
7528 use the @code{MEMORY} command to define discontinuous memory for the
7529 output file, the two functions are equivalent.
7531 @item ORIGIN(@var{memory})
7532 @kindex ORIGIN(@var{memory})
7533 Return the origin of the memory region named @var{memory}.
7535 @item SEGMENT_START(@var{segment}, @var{default})
7536 @kindex SEGMENT_START(@var{segment}, @var{default})
7537 Return the base address of the named @var{segment}. If an explicit
7538 value has already been given for this segment (with a command-line
7539 @samp{-T} option) then that value will be returned otherwise the value
7540 will be @var{default}. At present, the @samp{-T} command-line option
7541 can only be used to set the base address for the ``text'', ``data'', and
7542 ``bss'' sections, but you can use @code{SEGMENT_START} with any segment
7545 @item SIZEOF(@var{section})
7546 @kindex SIZEOF(@var{section})
7547 @cindex section size
7548 Return the size in bytes of the named @var{section}, if that section has
7549 been allocated, or zero if the section has not been allocated. If the
7550 section does not exist in the linker script the linker will report an
7551 error. If @var{section} is @code{NEXT_SECTION} then @code{SIZEOF} will
7552 return the alignment of the next allocated section specified in the
7553 linker script, or zero if there is no such section. In the following
7554 example, @code{symbol_1} and @code{symbol_2} are assigned identical
7564 symbol_1 = .end - .start ;
7565 symbol_2 = SIZEOF(.output);
7570 @item SIZEOF_HEADERS
7571 @kindex SIZEOF_HEADERS
7573 Return the size in bytes of the output file's headers. This is
7574 information which appears at the start of the output file. You can use
7575 this number when setting the start address of the first section, if you
7576 choose, to facilitate paging.
7578 @cindex not enough room for program headers
7579 @cindex program headers, not enough room
7580 When producing an ELF output file, if the linker script uses the
7581 @code{SIZEOF_HEADERS} builtin function, the linker must compute the
7582 number of program headers before it has determined all the section
7583 addresses and sizes. If the linker later discovers that it needs
7584 additional program headers, it will report an error @samp{not enough
7585 room for program headers}. To avoid this error, you must avoid using
7586 the @code{SIZEOF_HEADERS} function, or you must rework your linker
7587 script to avoid forcing the linker to use additional program headers, or
7588 you must define the program headers yourself using the @code{PHDRS}
7589 command (@pxref{PHDRS}).
7592 @node Implicit Linker Scripts
7593 @section Implicit Linker Scripts
7594 @cindex implicit linker scripts
7595 If you specify a linker input file which the linker can not recognize as
7596 an object file or an archive file, it will try to read the file as a
7597 linker script. If the file can not be parsed as a linker script, the
7598 linker will report an error.
7600 An implicit linker script will not replace the default linker script.
7602 Typically an implicit linker script would contain only symbol
7603 assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
7606 Any input files read because of an implicit linker script will be read
7607 at the position in the command line where the implicit linker script was
7608 read. This can affect archive searching.
7611 @chapter Linker Plugins
7614 @cindex linker plugins
7615 The linker can use dynamically loaded plugins to modify its behavior.
7616 For example, the link-time optimization feature that some compilers
7617 support is implemented with a linker plugin.
7619 Currently there is only one plugin shipped by default, but more may
7620 be added here later.
7622 Plugins are enabled via the use of the @option{-plugin @var{name}}
7623 command line option. @xref{Options}.
7626 * libdep Plugin:: Static Library Dependencies Plugin
7630 @section Static Library Dependencies Plugin
7631 @cindex static library dependencies
7632 Originally, static libraries were contained in an archive file consisting
7633 just of a collection of relocatable object files. Later they evolved to
7634 optionally include a symbol table, to assist in finding the needed objects
7635 within a library. There their evolution ended, and dynamic libraries
7638 One useful feature of dynamic libraries was that, more than just collecting
7639 multiple objects into a single file, they also included a list of their
7640 dependencies, such that one could specify just the name of a single dynamic
7641 library at link time, and all of its dependencies would be implicitly
7642 referenced as well. But static libraries lacked this feature, so if a
7643 link invocation was switched from using dynamic libraries to static
7644 libraries, the link command would usually fail unless it was rewritten to
7645 explicitly list the dependencies of the static library.
7647 The GNU @command{ar} utility now supports a @option{--record-libdeps} option
7648 to embed dependency lists into static libraries as well, and the @file{libdep}
7649 plugin may be used to read this dependency information at link time. The
7650 dependency information is stored as a single string, carrying @option{-l}
7651 and @option{-L} arguments as they would normally appear in a linker
7652 command line. As such, the information can be written with any text
7653 utility and stored into any archive, even if GNU @command{ar} is not
7654 being used to create the archive. The information is stored in an
7655 archive member named @samp{__.LIBDEP}.
7657 For example, given a library @file{libssl.a} that depends on another
7658 library @file{libcrypto.a} which may be found in @file{/usr/local/lib},
7659 the @samp{__.LIBDEP} member of @file{libssl.a} would contain
7662 -L/usr/local/lib -lcrypto
7665 @node Special Sections
7666 @chapter Special Sections
7667 When linking ELF format object files @command{ld} treats some sections
7668 in a special, non standard manner. This part of the manual describes
7673 The contents of any section with this name are assumed to be an ascii
7674 format warning message. The contents will be displayed to the user if
7675 the sections appears in any input file, but the section will not be
7676 copied into the output image. If the @option{--fatal-warnings} option
7677 is enabled then the warnings - if any are encountered - will also stop
7678 the link from completing.
7680 Note - the @samp{.gnu.warning} section is not subject to linker
7681 garbage collection or orphan handling.
7683 @item .gnu.warning.@var{SYM}
7684 The contents of any section whoes name starts with the prefix
7685 @samp{.gnu.warning.} and then finishes with the name of a symbol is
7686 treated in a similar fashion to the @samp{.gnu.warning} section, but
7687 only if the named symbol is referenced. So for example the contents
7688 of a section called @samp{.gnu.warning.foo} will be displayed as
7689 warning message if, and only if, the symbol @samp{foo} is referenced
7690 by one or more of the input files. This includes object files pulled
7691 in from static libraries, shared objects needed to complete the link
7694 Note - because these warning messages are generated before the linker
7695 performs garbage collection (if enabled) it is possible for a warning
7696 to be displayed for a symbol that is later removed and then never
7697 appears in the final output.
7699 @item .note.gnu.property
7700 When the linker combines sections of this name it will merge them
7701 together according to various rules encoded into the notes
7702 themselves. Therefore the contents of the output .note.gnu.property
7703 section may not correspond to a simple concatenation of the input
7704 sections. If the @option{-Map} option has been used to request a
7705 linker map then details of any property merging will be included in
7711 @node Machine Dependent
7712 @chapter Machine Dependent Features
7714 @cindex machine dependencies
7715 @command{ld} has additional features on some platforms; the following
7716 sections describe them. Machines where @command{ld} has no additional
7717 functionality are not listed.
7721 * H8/300:: @command{ld} and the H8/300
7724 * M68HC11/68HC12:: @code{ld} and the Motorola 68HC11 and 68HC12 families
7727 * ARM:: @command{ld} and the ARM family
7730 * HPPA ELF32:: @command{ld} and HPPA 32-bit ELF
7733 * M68K:: @command{ld} and the Motorola 68K family
7736 * MIPS:: @command{ld} and the MIPS family
7739 * MMIX:: @command{ld} and MMIX
7742 * MSP430:: @command{ld} and MSP430
7745 * NDS32:: @command{ld} and NDS32
7748 * PowerPC ELF32:: @command{ld} and PowerPC 32-bit ELF Support
7751 * PowerPC64 ELF64:: @command{ld} and PowerPC64 64-bit ELF Support
7754 * S/390 ELF:: @command{ld} and S/390 ELF Support
7757 * SPU ELF:: @command{ld} and SPU ELF Support
7760 * TI COFF:: @command{ld} and TI COFF
7763 * WIN32:: @command{ld} and WIN32 (cygwin/mingw)
7766 * Xtensa:: @command{ld} and Xtensa Processors
7777 @section @command{ld} and the H8/300
7779 @cindex H8/300 support
7780 For the H8/300, @command{ld} can perform these global optimizations when
7781 you specify the @samp{--relax} command-line option.
7784 @cindex relaxing on H8/300
7785 @item relaxing address modes
7786 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7787 targets are within eight bits, and turns them into eight-bit
7788 program-counter relative @code{bsr} and @code{bra} instructions,
7791 @cindex synthesizing on H8/300
7792 @item synthesizing instructions
7793 @c FIXME: specifically mov.b, or any mov instructions really? -> mov.b only, at least on H8, H8H, H8S
7794 @command{ld} finds all @code{mov.b} instructions which use the
7795 sixteen-bit absolute address form, but refer to the top
7796 page of memory, and changes them to use the eight-bit address form.
7797 (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
7798 @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
7799 top page of memory).
7801 @command{ld} finds all @code{mov} instructions which use the register
7802 indirect with 32-bit displacement addressing mode, but use a small
7803 displacement inside 16-bit displacement range, and changes them to use
7804 the 16-bit displacement form. (That is: the linker turns @samp{mov.b
7805 @code{@@}@var{d}:32,ERx} into @samp{mov.b @code{@@}@var{d}:16,ERx}
7806 whenever the displacement @var{d} is in the 16 bit signed integer
7807 range. Only implemented in ELF-format ld).
7809 @item bit manipulation instructions
7810 @command{ld} finds all bit manipulation instructions like @code{band, bclr,
7811 biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor}
7812 which use 32 bit and 16 bit absolute address form, but refer to the top
7813 page of memory, and changes them to use the 8 bit address form.
7814 (That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into
7815 @samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in
7816 the top page of memory).
7818 @item system control instructions
7819 @command{ld} finds all @code{ldc.w, stc.w} instructions which use the
7820 32 bit absolute address form, but refer to the top page of memory, and
7821 changes them to use 16 bit address form.
7822 (That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into
7823 @samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in
7824 the top page of memory).
7834 @c This stuff is pointless to say unless you're especially concerned
7835 @c with Renesas chips; don't enable it for generic case, please.
7837 @chapter @command{ld} and Other Renesas Chips
7839 @command{ld} also supports the Renesas (formerly Hitachi) H8/300H,
7840 H8/500, and SH chips. No special features, commands, or command-line
7841 options are required for these chips.
7855 @node M68HC11/68HC12
7856 @section @command{ld} and the Motorola 68HC11 and 68HC12 families
7858 @cindex M68HC11 and 68HC12 support
7860 @subsection Linker Relaxation
7862 For the Motorola 68HC11, @command{ld} can perform these global
7863 optimizations when you specify the @samp{--relax} command-line option.
7866 @cindex relaxing on M68HC11
7867 @item relaxing address modes
7868 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7869 targets are within eight bits, and turns them into eight-bit
7870 program-counter relative @code{bsr} and @code{bra} instructions,
7873 @command{ld} also looks at all 16-bit extended addressing modes and
7874 transforms them in a direct addressing mode when the address is in
7875 page 0 (between 0 and 0x0ff).
7877 @item relaxing gcc instruction group
7878 When @command{gcc} is called with @option{-mrelax}, it can emit group
7879 of instructions that the linker can optimize to use a 68HC11 direct
7880 addressing mode. These instructions consists of @code{bclr} or
7881 @code{bset} instructions.
7885 @subsection Trampoline Generation
7887 @cindex trampoline generation on M68HC11
7888 @cindex trampoline generation on M68HC12
7889 For 68HC11 and 68HC12, @command{ld} can generate trampoline code to
7890 call a far function using a normal @code{jsr} instruction. The linker
7891 will also change the relocation to some far function to use the
7892 trampoline address instead of the function address. This is typically the
7893 case when a pointer to a function is taken. The pointer will in fact
7894 point to the function trampoline.
7902 @section @command{ld} and the ARM family
7904 @cindex ARM interworking support
7905 @kindex --support-old-code
7906 For the ARM, @command{ld} will generate code stubs to allow functions calls
7907 between ARM and Thumb code. These stubs only work with code that has
7908 been compiled and assembled with the @samp{-mthumb-interwork} command
7909 line option. If it is necessary to link with old ARM object files or
7910 libraries, which have not been compiled with the -mthumb-interwork
7911 option then the @samp{--support-old-code} command-line switch should be
7912 given to the linker. This will make it generate larger stub functions
7913 which will work with non-interworking aware ARM code. Note, however,
7914 the linker does not support generating stubs for function calls to
7915 non-interworking aware Thumb code.
7917 @cindex thumb entry point
7918 @cindex entry point, thumb
7919 @kindex --thumb-entry=@var{entry}
7920 The @samp{--thumb-entry} switch is a duplicate of the generic
7921 @samp{--entry} switch, in that it sets the program's starting address.
7922 But it also sets the bottom bit of the address, so that it can be
7923 branched to using a BX instruction, and the program will start
7924 executing in Thumb mode straight away.
7926 @cindex PE import table prefixing
7927 @kindex --use-nul-prefixed-import-tables
7928 The @samp{--use-nul-prefixed-import-tables} switch is specifying, that
7929 the import tables idata4 and idata5 have to be generated with a zero
7930 element prefix for import libraries. This is the old style to generate
7931 import tables. By default this option is turned off.
7935 The @samp{--be8} switch instructs @command{ld} to generate BE8 format
7936 executables. This option is only valid when linking big-endian
7937 objects - ie ones which have been assembled with the @option{-EB}
7938 option. The resulting image will contain big-endian data and
7942 @kindex --target1-rel
7943 @kindex --target1-abs
7944 The @samp{R_ARM_TARGET1} relocation is typically used for entries in the
7945 @samp{.init_array} section. It is interpreted as either @samp{R_ARM_REL32}
7946 or @samp{R_ARM_ABS32}, depending on the target. The @samp{--target1-rel}
7947 and @samp{--target1-abs} switches override the default.
7950 @kindex --target2=@var{type}
7951 The @samp{--target2=type} switch overrides the default definition of the
7952 @samp{R_ARM_TARGET2} relocation. Valid values for @samp{type}, their
7953 meanings, and target defaults are as follows:
7956 @samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
7960 @samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
7965 The @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
7966 specification) enables objects compiled for the ARMv4 architecture to be
7967 interworking-safe when linked with other objects compiled for ARMv4t, but
7968 also allows pure ARMv4 binaries to be built from the same ARMv4 objects.
7970 In the latter case, the switch @option{--fix-v4bx} must be passed to the
7971 linker, which causes v4t @code{BX rM} instructions to be rewritten as
7972 @code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
7974 In the former case, the switch should not be used, and @samp{R_ARM_V4BX}
7975 relocations are ignored.
7977 @cindex FIX_V4BX_INTERWORKING
7978 @kindex --fix-v4bx-interworking
7979 Replace @code{BX rM} instructions identified by @samp{R_ARM_V4BX}
7980 relocations with a branch to the following veneer:
7988 This allows generation of libraries/applications that work on ARMv4 cores
7989 and are still interworking safe. Note that the above veneer clobbers the
7990 condition flags, so may cause incorrect program behavior in rare cases.
7994 The @samp{--use-blx} switch enables the linker to use ARM/Thumb
7995 BLX instructions (available on ARMv5t and above) in various
7996 situations. Currently it is used to perform calls via the PLT from Thumb
7997 code using BLX rather than using BX and a mode-switching stub before
7998 each PLT entry. This should lead to such calls executing slightly faster.
8000 @cindex VFP11_DENORM_FIX
8001 @kindex --vfp11-denorm-fix
8002 The @samp{--vfp11-denorm-fix} switch enables a link-time workaround for a
8003 bug in certain VFP11 coprocessor hardware, which sometimes allows
8004 instructions with denorm operands (which must be handled by support code)
8005 to have those operands overwritten by subsequent instructions before
8006 the support code can read the intended values.
8008 The bug may be avoided in scalar mode if you allow at least one
8009 intervening instruction between a VFP11 instruction which uses a register
8010 and another instruction which writes to the same register, or at least two
8011 intervening instructions if vector mode is in use. The bug only affects
8012 full-compliance floating-point mode: you do not need this workaround if
8013 you are using "runfast" mode. Please contact ARM for further details.
8015 If you know you are using buggy VFP11 hardware, you can
8016 enable this workaround by specifying the linker option
8017 @samp{--vfp-denorm-fix=scalar} if you are using the VFP11 scalar
8018 mode only, or @samp{--vfp-denorm-fix=vector} if you are using
8019 vector mode (the latter also works for scalar code). The default is
8020 @samp{--vfp-denorm-fix=none}.
8022 If the workaround is enabled, instructions are scanned for
8023 potentially-troublesome sequences, and a veneer is created for each
8024 such sequence which may trigger the erratum. The veneer consists of the
8025 first instruction of the sequence and a branch back to the subsequent
8026 instruction. The original instruction is then replaced with a branch to
8027 the veneer. The extra cycles required to call and return from the veneer
8028 are sufficient to avoid the erratum in both the scalar and vector cases.
8030 @cindex ARM1176 erratum workaround
8031 @kindex --fix-arm1176
8032 @kindex --no-fix-arm1176
8033 The @samp{--fix-arm1176} switch enables a link-time workaround for an erratum
8034 in certain ARM1176 processors. The workaround is enabled by default if you
8035 are targeting ARM v6 (excluding ARM v6T2) or earlier. It can be disabled
8036 unconditionally by specifying @samp{--no-fix-arm1176}.
8038 Further information is available in the ``ARM1176JZ-S and ARM1176JZF-S
8039 Programmer Advice Notice'' available on the ARM documentation website at:
8040 http://infocenter.arm.com/.
8042 @cindex STM32L4xx erratum workaround
8043 @kindex --fix-stm32l4xx-629360
8045 The @samp{--fix-stm32l4xx-629360} switch enables a link-time
8046 workaround for a bug in the bus matrix / memory controller for some of
8047 the STM32 Cortex-M4 based products (STM32L4xx). When accessing
8048 off-chip memory via the affected bus for bus reads of 9 words or more,
8049 the bus can generate corrupt data and/or abort. These are only
8050 core-initiated accesses (not DMA), and might affect any access:
8051 integer loads such as LDM, POP and floating-point loads such as VLDM,
8052 VPOP. Stores are not affected.
8054 The bug can be avoided by splitting memory accesses into the
8055 necessary chunks to keep bus reads below 8 words.
8057 The workaround is not enabled by default, this is equivalent to use
8058 @samp{--fix-stm32l4xx-629360=none}. If you know you are using buggy
8059 STM32L4xx hardware, you can enable the workaround by specifying the
8060 linker option @samp{--fix-stm32l4xx-629360}, or the equivalent
8061 @samp{--fix-stm32l4xx-629360=default}.
8063 If the workaround is enabled, instructions are scanned for
8064 potentially-troublesome sequences, and a veneer is created for each
8065 such sequence which may trigger the erratum. The veneer consists in a
8066 replacement sequence emulating the behaviour of the original one and a
8067 branch back to the subsequent instruction. The original instruction is
8068 then replaced with a branch to the veneer.
8070 The workaround does not always preserve the memory access order for
8071 the LDMDB instruction, when the instruction loads the PC.
8073 The workaround is not able to handle problematic instructions when
8074 they are in the middle of an IT block, since a branch is not allowed
8075 there. In that case, the linker reports a warning and no replacement
8078 The workaround is not able to replace problematic instructions with a
8079 PC-relative branch instruction if the @samp{.text} section is too
8080 large. In that case, when the branch that replaces the original code
8081 cannot be encoded, the linker reports a warning and no replacement
8084 @cindex NO_ENUM_SIZE_WARNING
8085 @kindex --no-enum-size-warning
8086 The @option{--no-enum-size-warning} switch prevents the linker from
8087 warning when linking object files that specify incompatible EABI
8088 enumeration size attributes. For example, with this switch enabled,
8089 linking of an object file using 32-bit enumeration values with another
8090 using enumeration values fitted into the smallest possible space will
8093 @cindex NO_WCHAR_SIZE_WARNING
8094 @kindex --no-wchar-size-warning
8095 The @option{--no-wchar-size-warning} switch prevents the linker from
8096 warning when linking object files that specify incompatible EABI
8097 @code{wchar_t} size attributes. For example, with this switch enabled,
8098 linking of an object file using 32-bit @code{wchar_t} values with another
8099 using 16-bit @code{wchar_t} values will not be diagnosed.
8102 @kindex --pic-veneer
8103 The @samp{--pic-veneer} switch makes the linker use PIC sequences for
8104 ARM/Thumb interworking veneers, even if the rest of the binary
8105 is not PIC. This avoids problems on uClinux targets where
8106 @samp{--emit-relocs} is used to generate relocatable binaries.
8108 @cindex STUB_GROUP_SIZE
8109 @kindex --stub-group-size=@var{N}
8110 The linker will automatically generate and insert small sequences of
8111 code into a linked ARM ELF executable whenever an attempt is made to
8112 perform a function call to a symbol that is too far away. The
8113 placement of these sequences of instructions - called stubs - is
8114 controlled by the command-line option @option{--stub-group-size=N}.
8115 The placement is important because a poor choice can create a need for
8116 duplicate stubs, increasing the code size. The linker will try to
8117 group stubs together in order to reduce interruptions to the flow of
8118 code, but it needs guidance as to how big these groups should be and
8119 where they should be placed.
8121 The value of @samp{N}, the parameter to the
8122 @option{--stub-group-size=} option controls where the stub groups are
8123 placed. If it is negative then all stubs are placed after the first
8124 branch that needs them. If it is positive then the stubs can be
8125 placed either before or after the branches that need them. If the
8126 value of @samp{N} is 1 (either +1 or -1) then the linker will choose
8127 exactly where to place groups of stubs, using its built in heuristics.
8128 A value of @samp{N} greater than 1 (or smaller than -1) tells the
8129 linker that a single group of stubs can service at most @samp{N} bytes
8130 from the input sections.
8132 The default, if @option{--stub-group-size=} is not specified, is
8135 Farcalls stubs insertion is fully supported for the ARM-EABI target
8136 only, because it relies on object files properties not present
8139 @cindex Cortex-A8 erratum workaround
8140 @kindex --fix-cortex-a8
8141 @kindex --no-fix-cortex-a8
8142 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}.
8144 The erratum only affects Thumb-2 code. Please contact ARM for further details.
8146 @cindex Cortex-A53 erratum 835769 workaround
8147 @kindex --fix-cortex-a53-835769
8148 @kindex --no-fix-cortex-a53-835769
8149 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}.
8151 Please contact ARM for further details.
8153 @kindex --merge-exidx-entries
8154 @kindex --no-merge-exidx-entries
8155 @cindex Merging exidx entries
8156 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent exidx entries in debuginfo.
8159 @cindex 32-bit PLT entries
8160 The @samp{--long-plt} option enables the use of 16 byte PLT entries
8161 which support up to 4Gb of code. The default is to use 12 byte PLT
8162 entries which only support 512Mb of code.
8164 @kindex --no-apply-dynamic-relocs
8165 @cindex AArch64 rela addend
8166 The @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
8167 link-time values for dynamic relocations.
8169 @cindex Placement of SG veneers
8170 All SG veneers are placed in the special output section @code{.gnu.sgstubs}.
8171 Its start address must be set, either with the command-line option
8172 @samp{--section-start} or in a linker script, to indicate where to place these
8175 @kindex --cmse-implib
8176 @cindex Secure gateway import library
8177 The @samp{--cmse-implib} option requests that the import libraries
8178 specified by the @samp{--out-implib} and @samp{--in-implib} options are
8179 secure gateway import libraries, suitable for linking a non-secure
8180 executable against secure code as per ARMv8-M Security Extensions.
8182 @kindex --in-implib=@var{file}
8183 @cindex Input import library
8184 The @samp{--in-implib=file} specifies an input import library whose symbols
8185 must keep the same address in the executable being produced. A warning is
8186 given if no @samp{--out-implib} is given but new symbols have been introduced
8187 in the executable that should be listed in its import library. Otherwise, if
8188 @samp{--out-implib} is specified, the symbols are added to the output import
8189 library. A warning is also given if some symbols present in the input import
8190 library have disappeared from the executable. This option is only effective
8191 for Secure Gateway import libraries, ie. when @samp{--cmse-implib} is
8194 @kindex -z force-bti
8195 @cindex Protect PLTs with Branch Target Identification
8196 The @samp{-z force-bti} option turns on the verification of Branch Target
8197 Identification (BTI) in input objects, generates PLTs with BTI, and marks the
8198 output with BTI. If this option is omitted, but all input objects belonging to
8199 the link unit have the BTI marking, the linker implicitly generates PLTs with
8200 BTI, and marks the output with BTI.
8202 @kindex -z bti-report[=none|warning|error]
8203 @cindex Control warnings for missing BTI markings.
8204 The @samp{-z bti-report[=none|warning|error]} option specifies how to report
8205 missing BTI markings on inputs, i.e. the GNU_PROPERTY_AARCH64_FEATURE_1_BTI
8207 By default, if the option is omitted and @samp{-z force-bti} is provided,
8208 warnings are emitted.
8210 @item @samp{none} disables any warning messages.
8211 @item @samp{warning} (the default value) emits warning messages when input objects
8212 composing the link unit are missing BTI markings.
8213 @item @samp{error} turns the warning messages into errors.
8215 If issues are found, a maximum of 20 messages will be emitted, and then a summary
8216 with the total number of issues will be displayed at the end.
8219 @cindex Protect PLTs with Returned Pointer Authentication
8220 The @samp{-z pac-plt} option enables the usage of pointer authentication in PLTs.
8222 @kindex -z gcs=[always|never|implicit]
8223 @cindex Controls whether the output object supports the Guarded Control Stack (GCS) mechanism.
8224 The @samp{-z gcs} option controls the verification of Guarded Control Stack (GCS)
8225 markings on input objects and marks the output with GCS if all conditions are
8228 @item @samp{implicit} (default if @samp{-z gcs} is omitted) enables GCS marking
8229 on the output if, and only if, all input objects composing the link unit are
8231 @item @samp{always} forces the marking of the output with GCS.
8232 @item @samp{never} ignores any GCS marking on the input objects, and does not
8233 mark the output with GCS.
8236 @kindex -z gcs-report[=none|warning|error]
8237 @cindex Control warnings for missing GCS markings.
8238 The @samp{-z gcs-report[=none|warning|error]} specifies how to report the missing
8239 GCS markings on inputs, i.e. the GNU_PROPERTY_AARCH64_FEATURE_1_GCS property.
8240 By default, if the option is omitted and @samp{-z gcs} is provided, warnings are
8243 @item @samp{none} disables any warning messages.
8244 @item @samp{warning} (the default value) emits warning messages when input objects
8245 composing the link unit are missing GCS markings, or dynamic objects containing
8246 external symbols used in the link unit.
8247 @item @samp{error} turns the warning messages into errors.
8249 If issues are found, a maximum of 20 messages will be emitted, and then a summary
8250 with the total number of issues will be displayed at the end.
8263 @section @command{ld} and HPPA 32-bit ELF Support
8264 @cindex HPPA multiple sub-space stubs
8265 @kindex --multi-subspace
8266 When generating a shared library, @command{ld} will by default generate
8267 import stubs suitable for use with a single sub-space application.
8268 The @samp{--multi-subspace} switch causes @command{ld} to generate export
8269 stubs, and different (larger) import stubs suitable for use with
8270 multiple sub-spaces.
8272 @cindex HPPA stub grouping
8273 @kindex --stub-group-size=@var{N}
8274 Long branch stubs and import/export stubs are placed by @command{ld} in
8275 stub sections located between groups of input sections.
8276 @samp{--stub-group-size} specifies the maximum size of a group of input
8277 sections handled by one stub section. Since branch offsets are signed,
8278 a stub section may serve two groups of input sections, one group before
8279 the stub section, and one group after it. However, when using
8280 conditional branches that require stubs, it may be better (for branch
8281 prediction) that stub sections only serve one group of input sections.
8282 A negative value for @samp{N} chooses this scheme, ensuring that
8283 branches to stubs always use a negative offset. Two special values of
8284 @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
8285 @command{ld} to automatically size input section groups for the branch types
8286 detected, with the same behaviour regarding stub placement as other
8287 positive or negative values of @samp{N} respectively.
8289 Note that @samp{--stub-group-size} does not split input sections. A
8290 single input section larger than the group size specified will of course
8291 create a larger group (of one section). If input sections are too
8292 large, it may not be possible for a branch to reach its stub.
8305 @section @command{ld} and the Motorola 68K family
8307 @cindex Motorola 68K GOT generation
8308 @kindex --got=@var{type}
8309 The @samp{--got=@var{type}} option lets you choose the GOT generation scheme.
8310 The choices are @samp{single}, @samp{negative}, @samp{multigot} and
8311 @samp{target}. When @samp{target} is selected the linker chooses
8312 the default GOT generation scheme for the current target.
8313 @samp{single} tells the linker to generate a single GOT with
8314 entries only at non-negative offsets.
8315 @samp{negative} instructs the linker to generate a single GOT with
8316 entries at both negative and positive offsets. Not all environments
8318 @samp{multigot} allows the linker to generate several GOTs in the
8319 output file. All GOT references from a single input object
8320 file access the same GOT, but references from different input object
8321 files might access different GOTs. Not all environments support such GOTs.
8334 @section @command{ld} and the MIPS family
8336 @cindex MIPS microMIPS instruction choice selection
8339 The @samp{--insn32} and @samp{--no-insn32} options control the choice of
8340 microMIPS instructions used in code generated by the linker, such as that
8341 in the PLT or lazy binding stubs, or in relaxation. If @samp{--insn32} is
8342 used, then the linker only uses 32-bit instruction encodings. By default
8343 or if @samp{--no-insn32} is used, all instruction encodings are used,
8344 including 16-bit ones where possible.
8346 @cindex MIPS branch relocation check control
8347 @kindex --ignore-branch-isa
8348 @kindex --no-ignore-branch-isa
8349 The @samp{--ignore-branch-isa} and @samp{--no-ignore-branch-isa} options
8350 control branch relocation checks for invalid ISA mode transitions. If
8351 @samp{--ignore-branch-isa} is used, then the linker accepts any branch
8352 relocations and any ISA mode transition required is lost in relocation
8353 calculation, except for some cases of @code{BAL} instructions which meet
8354 relaxation conditions and are converted to equivalent @code{JALX}
8355 instructions as the associated relocation is calculated. By default
8356 or if @samp{--no-ignore-branch-isa} is used a check is made causing
8357 the loss of an ISA mode transition to produce an error.
8370 @section @code{ld} and MMIX
8371 For MMIX, there is a choice of generating @code{ELF} object files or
8372 @code{mmo} object files when linking. The simulator @code{mmix}
8373 understands the @code{mmo} format. The binutils @code{objcopy} utility
8374 can translate between the two formats.
8376 There is one special section, the @samp{.MMIX.reg_contents} section.
8377 Contents in this section is assumed to correspond to that of global
8378 registers, and symbols referring to it are translated to special symbols,
8379 equal to registers. In a final link, the start address of the
8380 @samp{.MMIX.reg_contents} section corresponds to the first allocated
8381 global register multiplied by 8. Register @code{$255} is not included in
8382 this section; it is always set to the program entry, which is at the
8383 symbol @code{Main} for @code{mmo} files.
8385 Global symbols with the prefix @code{__.MMIX.start.}, for example
8386 @code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special.
8387 The default linker script uses these to set the default start address
8390 Initial and trailing multiples of zero-valued 32-bit words in a section,
8391 are left out from an mmo file.
8404 @section @code{ld} and MSP430
8405 For the MSP430 it is possible to select the MPU architecture. The flag @samp{-m [mpu type]}
8406 will select an appropriate linker script for selected MPU type. (To get a list of known MPUs
8407 just pass @samp{-m help} option to the linker).
8409 @cindex MSP430 extra sections
8410 The linker will recognize some extra sections which are MSP430 specific:
8413 @item @samp{.vectors}
8414 Defines a portion of ROM where interrupt vectors located.
8416 @item @samp{.bootloader}
8417 Defines the bootloader portion of the ROM (if applicable). Any code
8418 in this section will be uploaded to the MPU.
8420 @item @samp{.infomem}
8421 Defines an information memory section (if applicable). Any code in
8422 this section will be uploaded to the MPU.
8424 @item @samp{.infomemnobits}
8425 This is the same as the @samp{.infomem} section except that any code
8426 in this section will not be uploaded to the MPU.
8428 @item @samp{.noinit}
8429 Denotes a portion of RAM located above @samp{.bss} section.
8431 The last two sections are used by gcc.
8435 @cindex MSP430 Options
8436 @kindex --code-region
8437 @item --code-region=[either,lower,upper,none]
8438 This will transform .text* sections to [either,lower,upper].text* sections. The
8439 argument passed to GCC for -mcode-region is propagated to the linker
8442 @kindex --data-region
8443 @item --data-region=[either,lower,upper,none]
8444 This will transform .data*, .bss* and .rodata* sections to
8445 [either,lower,upper].[data,bss,rodata]* sections. The argument passed to GCC
8446 for -mdata-region is propagated to the linker using this option.
8448 @kindex --disable-sec-transformation
8449 @item --disable-sec-transformation
8450 Prevent the transformation of sections as specified by the @code{--code-region}
8451 and @code{--data-region} options.
8452 This is useful if you are compiling and linking using a single call to the GCC
8453 wrapper, and want to compile the source files using -m[code,data]-region but
8454 not transform the sections for prebuilt libraries and objects.
8468 @section @code{ld} and NDS32
8469 @kindex relaxing on NDS32
8470 For NDS32, there are some options to select relaxation behavior. The linker
8471 relaxes objects according to these options.
8474 @item @samp{--m[no-]fp-as-gp}
8475 Disable/enable fp-as-gp relaxation.
8477 @item @samp{--mexport-symbols=FILE}
8478 Exporting symbols and their address into FILE as linker script.
8480 @item @samp{--m[no-]ex9}
8481 Disable/enable link-time EX9 relaxation.
8483 @item @samp{--mexport-ex9=FILE}
8484 Export the EX9 table after linking.
8486 @item @samp{--mimport-ex9=FILE}
8487 Import the Ex9 table for EX9 relaxation.
8489 @item @samp{--mupdate-ex9}
8490 Update the existing EX9 table.
8492 @item @samp{--mex9-limit=NUM}
8493 Maximum number of entries in the ex9 table.
8495 @item @samp{--mex9-loop-aware}
8496 Avoid generating the EX9 instruction inside the loop.
8498 @item @samp{--m[no-]ifc}
8499 Disable/enable the link-time IFC optimization.
8501 @item @samp{--mifc-loop-aware}
8502 Avoid generating the IFC instruction inside the loop.
8516 @section @command{ld} and PowerPC 32-bit ELF Support
8517 @cindex PowerPC long branches
8518 @kindex --relax on PowerPC
8519 Branches on PowerPC processors are limited to a signed 26-bit
8520 displacement, which may result in @command{ld} giving
8521 @samp{relocation truncated to fit} errors with very large programs.
8522 @samp{--relax} enables the generation of trampolines that can access
8523 the entire 32-bit address space. These trampolines are inserted at
8524 section boundaries, so may not themselves be reachable if an input
8525 section exceeds 33M in size. You may combine @samp{-r} and
8526 @samp{--relax} to add trampolines in a partial link. In that case
8527 both branches to undefined symbols and inter-section branches are also
8528 considered potentially out of range, and trampolines inserted.
8530 @cindex PowerPC ELF32 options
8535 Current PowerPC GCC accepts a @samp{-msecure-plt} option that
8536 generates code capable of using a newer PLT and GOT layout that has
8537 the security advantage of no executable section ever needing to be
8538 writable and no writable section ever being executable. PowerPC
8539 @command{ld} will generate this layout, including stubs to access the
8540 PLT, if all input files (including startup and static libraries) were
8541 compiled with @samp{-msecure-plt}. @samp{--bss-plt} forces the old
8542 BSS PLT (and GOT layout) which can give slightly better performance.
8544 @kindex --secure-plt
8546 @command{ld} will use the new PLT and GOT layout if it is linking new
8547 @samp{-fpic} or @samp{-fPIC} code, but does not do so automatically
8548 when linking non-PIC code. This option requests the new PLT and GOT
8549 layout. A warning will be given if some object file requires the old
8555 The new secure PLT and GOT are placed differently relative to other
8556 sections compared to older BSS PLT and GOT placement. The location of
8557 @code{.plt} must change because the new secure PLT is an initialized
8558 section while the old PLT is uninitialized. The reason for the
8559 @code{.got} change is more subtle: The new placement allows
8560 @code{.got} to be read-only in applications linked with
8561 @samp{-z relro -z now}. However, this placement means that
8562 @code{.sdata} cannot always be used in shared libraries, because the
8563 PowerPC ABI accesses @code{.sdata} in shared libraries from the GOT
8564 pointer. @samp{--sdata-got} forces the old GOT placement. PowerPC
8565 GCC doesn't use @code{.sdata} in shared libraries, so this option is
8566 really only useful for other compilers that may do so.
8568 @cindex PowerPC stub symbols
8569 @kindex --emit-stub-syms
8570 @item --emit-stub-syms
8571 This option causes @command{ld} to label linker stubs with a local
8572 symbol that encodes the stub type and destination.
8574 @cindex PowerPC TLS optimization
8575 @kindex --no-tls-optimize
8576 @item --no-tls-optimize
8577 PowerPC @command{ld} normally performs some optimization of code
8578 sequences used to access Thread-Local Storage. Use this option to
8579 disable the optimization.
8592 @node PowerPC64 ELF64
8593 @section @command{ld} and PowerPC64 64-bit ELF Support
8595 @cindex PowerPC64 ELF64 options
8597 @cindex PowerPC64 stub grouping
8598 @kindex --stub-group-size
8599 @item --stub-group-size
8600 Long branch stubs, PLT call stubs and TOC adjusting stubs are placed
8601 by @command{ld} in stub sections located between groups of input sections.
8602 @samp{--stub-group-size} specifies the maximum size of a group of input
8603 sections handled by one stub section. Since branch offsets are signed,
8604 a stub section may serve two groups of input sections, one group before
8605 the stub section, and one group after it. However, when using
8606 conditional branches that require stubs, it may be better (for branch
8607 prediction) that stub sections only serve one group of input sections.
8608 A negative value for @samp{N} chooses this scheme, ensuring that
8609 branches to stubs always use a negative offset. Two special values of
8610 @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
8611 @command{ld} to automatically size input section groups for the branch types
8612 detected, with the same behaviour regarding stub placement as other
8613 positive or negative values of @samp{N} respectively.
8615 Note that @samp{--stub-group-size} does not split input sections. A
8616 single input section larger than the group size specified will of course
8617 create a larger group (of one section). If input sections are too
8618 large, it may not be possible for a branch to reach its stub.
8620 @cindex PowerPC64 stub symbols
8621 @kindex --emit-stub-syms
8622 @item --emit-stub-syms
8623 This option causes @command{ld} to label linker stubs with a local
8624 symbol that encodes the stub type and destination.
8626 @cindex PowerPC64 dot symbols
8628 @kindex --no-dotsyms
8631 These two options control how @command{ld} interprets version patterns
8632 in a version script. Older PowerPC64 compilers emitted both a
8633 function descriptor symbol with the same name as the function, and a
8634 code entry symbol with the name prefixed by a dot (@samp{.}). To
8635 properly version a function @samp{foo}, the version script thus needs
8636 to control both @samp{foo} and @samp{.foo}. The option
8637 @samp{--dotsyms}, on by default, automatically adds the required
8638 dot-prefixed patterns. Use @samp{--no-dotsyms} to disable this
8641 @cindex PowerPC64 register save/restore functions
8642 @kindex --save-restore-funcs
8643 @kindex --no-save-restore-funcs
8644 @item --save-restore-funcs
8645 @itemx --no-save-restore-funcs
8646 These two options control whether PowerPC64 @command{ld} automatically
8647 provides out-of-line register save and restore functions used by
8648 @samp{-Os} code. The default is to provide any such referenced
8649 function for a normal final link, and to not do so for a relocatable
8652 @cindex PowerPC64 TLS optimization
8653 @kindex --no-tls-optimize
8654 @item --no-tls-optimize
8655 PowerPC64 @command{ld} normally performs some optimization of code
8656 sequences used to access Thread-Local Storage. Use this option to
8657 disable the optimization.
8659 @cindex PowerPC64 __tls_get_addr optimization
8660 @kindex --tls-get-addr-optimize
8661 @kindex --no-tls-get-addr-optimize
8662 @kindex --tls-get-addr-regsave
8663 @kindex --no-tls-get-addr-regsave
8664 @item --tls-get-addr-optimize
8665 @itemx --no-tls-get-addr-optimize
8666 These options control how PowerPC64 @command{ld} uses a special
8667 stub to call __tls_get_addr. PowerPC64 glibc 2.22 and later support
8668 an optimization that allows the second and subsequent calls to
8669 @code{__tls_get_addr} for a given symbol to be resolved by the special
8670 stub without calling in to glibc. By default the linker enables
8671 generation of the stub when glibc advertises the availability of
8673 Using @option{--tls-get-addr-optimize} with an older glibc won't do
8674 much besides slow down your applications, but may be useful if linking
8675 an application against an older glibc with the expectation that it
8676 will normally be used on systems having a newer glibc.
8677 @option{--tls-get-addr-regsave} forces generation of a stub that saves
8678 and restores volatile registers around the call into glibc. Normally,
8679 this is done when the linker detects a call to __tls_get_addr_desc.
8680 Such calls then go via the register saving stub to __tls_get_addr_opt.
8681 @option{--no-tls-get-addr-regsave} disables generation of the
8684 @cindex PowerPC64 OPD optimization
8685 @kindex --no-opd-optimize
8686 @item --no-opd-optimize
8687 PowerPC64 @command{ld} normally removes @code{.opd} section entries
8688 corresponding to deleted link-once functions, or functions removed by
8689 the action of @samp{--gc-sections} or linker script @code{/DISCARD/}.
8690 Use this option to disable @code{.opd} optimization.
8692 @cindex PowerPC64 OPD spacing
8693 @kindex --non-overlapping-opd
8694 @item --non-overlapping-opd
8695 Some PowerPC64 compilers have an option to generate compressed
8696 @code{.opd} entries spaced 16 bytes apart, overlapping the third word,
8697 the static chain pointer (unused in C) with the first word of the next
8698 entry. This option expands such entries to the full 24 bytes.
8700 @cindex PowerPC64 TOC optimization
8701 @kindex --no-toc-optimize
8702 @item --no-toc-optimize
8703 PowerPC64 @command{ld} normally removes unused @code{.toc} section
8704 entries. Such entries are detected by examining relocations that
8705 reference the TOC in code sections. A reloc in a deleted code section
8706 marks a TOC word as unneeded, while a reloc in a kept code section
8707 marks a TOC word as needed. Since the TOC may reference itself, TOC
8708 relocs are also examined. TOC words marked as both needed and
8709 unneeded will of course be kept. TOC words without any referencing
8710 reloc are assumed to be part of a multi-word entry, and are kept or
8711 discarded as per the nearest marked preceding word. This works
8712 reliably for compiler generated code, but may be incorrect if assembly
8713 code is used to insert TOC entries. Use this option to disable the
8716 @cindex PowerPC64 inline PLT call optimization
8717 @kindex --no-inline-optimize
8718 @item --no-inline-optimize
8719 PowerPC64 @command{ld} normally replaces inline PLT call sequences
8720 marked with @code{R_PPC64_PLTSEQ}, @code{R_PPC64_PLTCALL},
8721 @code{R_PPC64_PLT16_HA} and @code{R_PPC64_PLT16_LO_DS} relocations by
8722 a number of @code{nop}s and a direct call when the function is defined
8723 locally and can't be overridden by some other definition. This option
8724 disables that optimization.
8726 @cindex PowerPC64 multi-TOC
8727 @kindex --no-multi-toc
8728 @item --no-multi-toc
8729 If given any toc option besides @code{-mcmodel=medium} or
8730 @code{-mcmodel=large}, PowerPC64 GCC generates code for a TOC model
8732 entries are accessed with a 16-bit offset from r2. This limits the
8733 total TOC size to 64K. PowerPC64 @command{ld} extends this limit by
8734 grouping code sections such that each group uses less than 64K for its
8735 TOC entries, then inserts r2 adjusting stubs between inter-group
8736 calls. @command{ld} does not split apart input sections, so cannot
8737 help if a single input file has a @code{.toc} section that exceeds
8738 64K, most likely from linking multiple files with @command{ld -r}.
8739 Use this option to turn off this feature.
8741 @cindex PowerPC64 TOC sorting
8742 @kindex --no-toc-sort
8744 By default, @command{ld} sorts TOC sections so that those whose file
8745 happens to have a section called @code{.init} or @code{.fini} are
8746 placed first, followed by TOC sections referenced by code generated
8747 with PowerPC64 gcc's @code{-mcmodel=small}, and lastly TOC sections
8748 referenced only by code generated with PowerPC64 gcc's
8749 @code{-mcmodel=medium} or @code{-mcmodel=large} options. Doing this
8750 results in better TOC grouping for multi-TOC. Use this option to turn
8753 @cindex PowerPC64 PLT stub alignment
8755 @kindex --no-plt-align
8757 @itemx --no-plt-align
8758 Use these options to control whether individual PLT call stubs are
8759 aligned to a 32-byte boundary, or to the specified power of two
8760 boundary when using @code{--plt-align=}. A negative value may be
8761 specified to pad PLT call stubs so that they do not cross the
8762 specified power of two boundary (or the minimum number of boundaries
8763 if a PLT stub is so large that it must cross a boundary). By default
8764 PLT call stubs are aligned to 32-byte boundaries.
8766 @cindex PowerPC64 PLT call stub static chain
8767 @kindex --plt-static-chain
8768 @kindex --no-plt-static-chain
8769 @item --plt-static-chain
8770 @itemx --no-plt-static-chain
8771 Use these options to control whether PLT call stubs load the static
8772 chain pointer (r11). @code{ld} defaults to not loading the static
8773 chain since there is never any need to do so on a PLT call.
8775 @cindex PowerPC64 PLT call stub thread safety
8776 @kindex --plt-thread-safe
8777 @kindex --no-plt-thread-safe
8778 @item --plt-thread-safe
8779 @itemx --no-plt-thread-safe
8780 With power7's weakly ordered memory model, it is possible when using
8781 lazy binding for ld.so to update a plt entry in one thread and have
8782 another thread see the individual plt entry words update in the wrong
8783 order, despite ld.so carefully writing in the correct order and using
8784 memory write barriers. To avoid this we need some sort of read
8785 barrier in the call stub, or use LD_BIND_NOW=1. By default, @code{ld}
8786 looks for calls to commonly used functions that create threads, and if
8787 seen, adds the necessary barriers. Use these options to change the
8790 @cindex PowerPC64 ELFv2 PLT localentry optimization
8791 @kindex --plt-localentry
8792 @kindex --no-plt-localentry
8793 @item --plt-localentry
8794 @itemx --no-localentry
8795 ELFv2 functions with localentry:0 are those with a single entry point,
8796 ie. global entry == local entry, and that have no requirement on r2
8797 (the TOC/GOT pointer) or r12, and guarantee r2 is unchanged on return.
8798 Such an external function can be called via the PLT without saving r2
8799 or restoring it on return, avoiding a common load-hit-store for small
8800 functions. The optimization is attractive, with up to 40% reduction
8801 in execution time for a small function, but can result in symbol
8802 interposition failures. Also, minor changes in a shared library,
8803 including system libraries, can cause a function that was localentry:0
8804 to become localentry:8. This will result in a dynamic loader
8805 complaint and failure to run. The option is experimental, use with
8806 care. @option{--no-plt-localentry} is the default.
8808 @cindex PowerPC64 Power10 stubs
8809 @kindex --power10-stubs
8810 @kindex --no-power10-stubs
8811 @item --power10-stubs
8812 @itemx --no-power10-stubs
8813 When PowerPC64 @command{ld} links input object files containing
8814 relocations used on power10 prefixed instructions it normally creates
8815 linkage stubs (PLT call and long branch) using power10 instructions
8816 for @code{@@notoc} PLT calls where @code{r2} is not known. The
8817 power10 notoc stubs are smaller and faster, so are preferred for
8818 power10. @option{--power10-stubs} and @option{--no-power10-stubs}
8819 allow you to override the linker's selection of stub instructions.
8820 @option{--power10-stubs=auto} allows the user to select the default
8835 @section @command{ld} and S/390 ELF Support
8837 @cindex S/390 ELF options
8841 @kindex --s390-pgste
8843 This option marks the result file with a @code{PT_S390_PGSTE}
8844 segment. The Linux kernel is supposed to allocate 4k page tables for
8845 binaries marked that way.
8859 @section @command{ld} and SPU ELF Support
8861 @cindex SPU ELF options
8867 This option marks an executable as a PIC plugin module.
8869 @cindex SPU overlays
8870 @kindex --no-overlays
8872 Normally, @command{ld} recognizes calls to functions within overlay
8873 regions, and redirects such calls to an overlay manager via a stub.
8874 @command{ld} also provides a built-in overlay manager. This option
8875 turns off all this special overlay handling.
8877 @cindex SPU overlay stub symbols
8878 @kindex --emit-stub-syms
8879 @item --emit-stub-syms
8880 This option causes @command{ld} to label overlay stubs with a local
8881 symbol that encodes the stub type and destination.
8883 @cindex SPU extra overlay stubs
8884 @kindex --extra-overlay-stubs
8885 @item --extra-overlay-stubs
8886 This option causes @command{ld} to add overlay call stubs on all
8887 function calls out of overlay regions. Normally stubs are not added
8888 on calls to non-overlay regions.
8890 @cindex SPU local store size
8891 @kindex --local-store=lo:hi
8892 @item --local-store=lo:hi
8893 @command{ld} usually checks that a final executable for SPU fits in
8894 the address range 0 to 256k. This option may be used to change the
8895 range. Disable the check entirely with @option{--local-store=0:0}.
8898 @kindex --stack-analysis
8899 @item --stack-analysis
8900 SPU local store space is limited. Over-allocation of stack space
8901 unnecessarily limits space available for code and data, while
8902 under-allocation results in runtime failures. If given this option,
8903 @command{ld} will provide an estimate of maximum stack usage.
8904 @command{ld} does this by examining symbols in code sections to
8905 determine the extents of functions, and looking at function prologues
8906 for stack adjusting instructions. A call-graph is created by looking
8907 for relocations on branch instructions. The graph is then searched
8908 for the maximum stack usage path. Note that this analysis does not
8909 find calls made via function pointers, and does not handle recursion
8910 and other cycles in the call graph. Stack usage may be
8911 under-estimated if your code makes such calls. Also, stack usage for
8912 dynamic allocation, e.g. alloca, will not be detected. If a link map
8913 is requested, detailed information about each function's stack usage
8914 and calls will be given.
8917 @kindex --emit-stack-syms
8918 @item --emit-stack-syms
8919 This option, if given along with @option{--stack-analysis} will result
8920 in @command{ld} emitting stack sizing symbols for each function.
8921 These take the form @code{__stack_<function_name>} for global
8922 functions, and @code{__stack_<number>_<function_name>} for static
8923 functions. @code{<number>} is the section id in hex. The value of
8924 such symbols is the stack requirement for the corresponding function.
8925 The symbol size will be zero, type @code{STT_NOTYPE}, binding
8926 @code{STB_LOCAL}, and section @code{SHN_ABS}.
8940 @section @command{ld}'s Support for Various TI COFF Versions
8941 @cindex TI COFF versions
8942 @kindex --format=@var{version}
8943 The @samp{--format} switch allows selection of one of the various
8944 TI COFF versions. The latest of this writing is 2; versions 0 and 1 are
8945 also supported. The TI COFF versions also vary in header byte-order
8946 format; @command{ld} will read any version or byte order, but the output
8947 header format depends on the default specified by the specific target.
8960 @section @command{ld} and WIN32 (cygwin/mingw)
8962 This section describes some of the win32 specific @command{ld} issues.
8963 See @ref{Options,,Command-line Options} for detailed description of the
8964 command-line options mentioned here.
8967 @cindex import libraries
8968 @item import libraries
8969 The standard Windows linker creates and uses so-called import
8970 libraries, which contains information for linking to dll's. They are
8971 regular static archives and are handled as any other static
8972 archive. The cygwin and mingw ports of @command{ld} have specific
8973 support for creating such libraries provided with the
8974 @samp{--out-implib} command-line option.
8976 @item Resource only DLLs
8977 It is possible to create a DLL that only contains resources, ie just a
8978 @samp{.rsrc} section, but in order to do so a custom linker script
8979 must be used. This is because the built-in default linker scripts
8980 will always create @samp{.text} and @samp{.idata} sections, even if
8981 there is no input to go into them.
8983 The script should look like this, although the @code{OUTPUT_FORMAT}
8984 should be changed to match the desired format.
8987 OUTPUT_FORMAT(pei-i386)
8991 . = ALIGN(__section_alignment__);
8992 .rsrc __image_base__ + __section_alignment__ : ALIGN(4)
8997 /DISCARD/ : @{ *(*) @}
9001 With this script saved to a file called, eg @file{rsrc.ld}, a command
9002 line like this can be used to create the resource only DLL
9003 @file{rsrc.dll} from an input file called @file{rsrc.o}:
9006 ld -dll --subsystem windows -e 0 -s rsrc.o -o rsrc.dll -T rsrc.ld
9009 @item exporting DLL symbols
9010 @cindex exporting DLL symbols
9011 The cygwin/mingw @command{ld} has several ways to export symbols for dll's.
9014 @item using auto-export functionality
9015 @cindex using auto-export functionality
9016 By default @command{ld} exports symbols with the auto-export functionality,
9017 which is controlled by the following command-line options:
9020 @item --export-all-symbols [This is the default]
9021 @item --exclude-symbols
9022 @item --exclude-libs
9023 @item --exclude-modules-for-implib
9024 @item --version-script
9027 When auto-export is in operation, @command{ld} will export all the non-local
9028 (global and common) symbols it finds in a DLL, with the exception of a few
9029 symbols known to belong to the system's runtime and libraries. As it will
9030 often not be desirable to export all of a DLL's symbols, which may include
9031 private functions that are not part of any public interface, the command-line
9032 options listed above may be used to filter symbols out from the list for
9033 exporting. The @samp{--output-def} option can be used in order to see the
9034 final list of exported symbols with all exclusions taken into effect.
9036 If @samp{--export-all-symbols} is not given explicitly on the
9037 command line, then the default auto-export behavior will be @emph{disabled}
9038 if either of the following are true:
9041 @item A DEF file is used.
9042 @item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
9045 @item using a DEF file
9046 @cindex using a DEF file
9047 Another way of exporting symbols is using a DEF file. A DEF file is
9048 an ASCII file containing definitions of symbols which should be
9049 exported when a dll is created. Usually it is named @samp{<dll
9050 name>.def} and is added as any other object file to the linker's
9051 command line. The file's name must end in @samp{.def} or @samp{.DEF}.
9054 gcc -o <output> <objectfiles> <dll name>.def
9057 Using a DEF file turns off the normal auto-export behavior, unless the
9058 @samp{--export-all-symbols} option is also used.
9060 Here is an example of a DEF file for a shared library called @samp{xyz.dll}:
9063 LIBRARY "xyz.dll" BASE=0x20000000
9069 another_foo = abc.dll.afoo
9075 This example defines a DLL with a non-default base address and seven
9076 symbols in the export table. The third exported symbol @code{_bar} is an
9077 alias for the second. The fourth symbol, @code{another_foo} is resolved
9078 by "forwarding" to another module and treating it as an alias for
9079 @code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
9080 @code{var1} is declared to be a data object. The @samp{doo} symbol in
9081 export library is an alias of @samp{foo}, which gets the string name
9082 in export table @samp{foo2}. The @samp{eoo} symbol is an data export
9083 symbol, which gets in export table the name @samp{var1}.
9085 The optional @code{LIBRARY <name>} command indicates the @emph{internal}
9086 name of the output DLL. If @samp{<name>} does not include a suffix,
9087 the default library suffix, @samp{.DLL} is appended.
9089 When the .DEF file is used to build an application, rather than a
9090 library, the @code{NAME <name>} command should be used instead of
9091 @code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
9092 executable suffix, @samp{.EXE} is appended.
9094 With either @code{LIBRARY <name>} or @code{NAME <name>} the optional
9095 specification @code{BASE = <number>} may be used to specify a
9096 non-default base address for the image.
9098 If neither @code{LIBRARY <name>} nor @code{NAME <name>} is specified,
9099 or they specify an empty string, the internal name is the same as the
9100 filename specified on the command line.
9102 The complete specification of an export symbol is:
9106 ( ( ( <name1> [ = <name2> ] )
9107 | ( <name1> = <module-name> . <external-name>))
9108 [ @@ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] [== <name3>] ) *
9111 Declares @samp{<name1>} as an exported symbol from the DLL, or declares
9112 @samp{<name1>} as an exported alias for @samp{<name2>}; or declares
9113 @samp{<name1>} as a "forward" alias for the symbol
9114 @samp{<external-name>} in the DLL @samp{<module-name>}.
9115 Optionally, the symbol may be exported by the specified ordinal
9116 @samp{<integer>} alias. The optional @samp{<name3>} is the to be used
9117 string in import/export table for the symbol.
9119 The optional keywords that follow the declaration indicate:
9121 @code{NONAME}: Do not put the symbol name in the DLL's export table. It
9122 will still be exported by its ordinal alias (either the value specified
9123 by the .def specification or, otherwise, the value assigned by the
9124 linker). The symbol name, however, does remain visible in the import
9125 library (if any), unless @code{PRIVATE} is also specified.
9127 @code{DATA}: The symbol is a variable or object, rather than a function.
9128 The import lib will export only an indirect reference to @code{foo} as
9129 the symbol @code{_imp__foo} (ie, @code{foo} must be resolved as
9132 @code{CONSTANT}: Like @code{DATA}, but put the undecorated @code{foo} as
9133 well as @code{_imp__foo} into the import library. Both refer to the
9134 read-only import address table's pointer to the variable, not to the
9135 variable itself. This can be dangerous. If the user code fails to add
9136 the @code{dllimport} attribute and also fails to explicitly add the
9137 extra indirection that the use of the attribute enforces, the
9138 application will behave unexpectedly.
9140 @code{PRIVATE}: Put the symbol in the DLL's export table, but do not put
9141 it into the static import library used to resolve imports at link time. The
9142 symbol can still be imported using the @code{LoadLibrary/GetProcAddress}
9143 API at runtime or by using the GNU ld extension of linking directly to
9144 the DLL without an import library.
9146 See ld/deffilep.y in the binutils sources for the full specification of
9147 other DEF file statements
9149 @cindex creating a DEF file
9150 While linking a shared dll, @command{ld} is able to create a DEF file
9151 with the @samp{--output-def <file>} command-line option.
9153 @item Using decorations
9154 @cindex Using decorations
9155 Another way of marking symbols for export is to modify the source code
9156 itself, so that when building the DLL each symbol to be exported is
9160 __declspec(dllexport) int a_variable
9161 __declspec(dllexport) void a_function(int with_args)
9164 All such symbols will be exported from the DLL. If, however,
9165 any of the object files in the DLL contain symbols decorated in
9166 this way, then the normal auto-export behavior is disabled, unless
9167 the @samp{--export-all-symbols} option is also used.
9169 Note that object files that wish to access these symbols must @emph{not}
9170 decorate them with dllexport. Instead, they should use dllimport,
9174 __declspec(dllimport) int a_variable
9175 __declspec(dllimport) void a_function(int with_args)
9178 This complicates the structure of library header files, because
9179 when included by the library itself the header must declare the
9180 variables and functions as dllexport, but when included by client
9181 code the header must declare them as dllimport. There are a number
9182 of idioms that are typically used to do this; often client code can
9183 omit the __declspec() declaration completely. See
9184 @samp{--enable-auto-import} and @samp{automatic data imports} for more
9188 @cindex automatic data imports
9189 @item automatic data imports
9190 The standard Windows dll format supports data imports from dlls only
9191 by adding special decorations (dllimport/dllexport), which let the
9192 compiler produce specific assembler instructions to deal with this
9193 issue. This increases the effort necessary to port existing Un*x
9194 code to these platforms, especially for large
9195 c++ libraries and applications. The auto-import feature, which was
9196 initially provided by Paul Sokolovsky, allows one to omit the
9197 decorations to achieve a behavior that conforms to that on POSIX/Un*x
9198 platforms. This feature is enabled with the @samp{--enable-auto-import}
9199 command-line option, although it is enabled by default on cygwin/mingw.
9200 The @samp{--enable-auto-import} option itself now serves mainly to
9201 suppress any warnings that are ordinarily emitted when linked objects
9202 trigger the feature's use.
9204 auto-import of variables does not always work flawlessly without
9205 additional assistance. Sometimes, you will see this message
9207 "variable '<var>' can't be auto-imported. Please read the
9208 documentation for ld's @code{--enable-auto-import} for details."
9210 The @samp{--enable-auto-import} documentation explains why this error
9211 occurs, and several methods that can be used to overcome this difficulty.
9212 One of these methods is the @emph{runtime pseudo-relocs} feature, described
9215 @cindex runtime pseudo-relocation
9216 For complex variables imported from DLLs (such as structs or classes),
9217 object files typically contain a base address for the variable and an
9218 offset (@emph{addend}) within the variable--to specify a particular
9219 field or public member, for instance. Unfortunately, the runtime loader used
9220 in win32 environments is incapable of fixing these references at runtime
9221 without the additional information supplied by dllimport/dllexport decorations.
9222 The standard auto-import feature described above is unable to resolve these
9225 The @samp{--enable-runtime-pseudo-relocs} switch allows these references to
9226 be resolved without error, while leaving the task of adjusting the references
9227 themselves (with their non-zero addends) to specialized code provided by the
9228 runtime environment. Recent versions of the cygwin and mingw environments and
9229 compilers provide this runtime support; older versions do not. However, the
9230 support is only necessary on the developer's platform; the compiled result will
9231 run without error on an older system.
9233 @samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
9236 @cindex direct linking to a dll
9237 @item direct linking to a dll
9238 The cygwin/mingw ports of @command{ld} support the direct linking,
9239 including data symbols, to a dll without the usage of any import
9240 libraries. This is much faster and uses much less memory than does the
9241 traditional import library method, especially when linking large
9242 libraries or applications. When @command{ld} creates an import lib, each
9243 function or variable exported from the dll is stored in its own bfd, even
9244 though a single bfd could contain many exports. The overhead involved in
9245 storing, loading, and processing so many bfd's is quite large, and explains the
9246 tremendous time, memory, and storage needed to link against particularly
9247 large or complex libraries when using import libs.
9249 Linking directly to a dll uses no extra command-line switches other than
9250 @samp{-L} and @samp{-l}, because @command{ld} already searches for a number
9251 of names to match each library. All that is needed from the developer's
9252 perspective is an understanding of this search, in order to force ld to
9253 select the dll instead of an import library.
9256 For instance, when ld is called with the argument @samp{-lxxx} it will attempt
9257 to find, in the first directory of its search path,
9270 before moving on to the next directory in the search path.
9272 (*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
9273 where @samp{<prefix>} is set by the @command{ld} option
9274 @samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
9275 file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
9278 Other win32-based unix environments, such as mingw or pw32, may use other
9279 @samp{<prefix>}es, although at present only cygwin makes use of this feature. It
9280 was originally intended to help avoid name conflicts among dll's built for the
9281 various win32/un*x environments, so that (for example) two versions of a zlib dll
9282 could coexist on the same machine.
9284 The generic cygwin/mingw path layout uses a @samp{bin} directory for
9285 applications and dll's and a @samp{lib} directory for the import
9286 libraries (using cygwin nomenclature):
9292 libxxx.dll.a (in case of dll's)
9293 libxxx.a (in case of static archive)
9296 Linking directly to a dll without using the import library can be
9299 1. Use the dll directly by adding the @samp{bin} path to the link line
9301 gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx
9304 However, as the dll's often have version numbers appended to their names
9305 (@samp{cygncurses-5.dll}) this will often fail, unless one specifies
9306 @samp{-L../bin -lncurses-5} to include the version. Import libs are generally
9307 not versioned, and do not have this difficulty.
9309 2. Create a symbolic link from the dll to a file in the @samp{lib}
9310 directory according to the above mentioned search pattern. This
9311 should be used to avoid unwanted changes in the tools needed for
9315 ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
9318 Then you can link without any make environment changes.
9321 gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx
9324 This technique also avoids the version number problems, because the following is
9331 libxxx.dll.a -> ../bin/cygxxx-5.dll
9334 Linking directly to a dll without using an import lib will work
9335 even when auto-import features are exercised, and even when
9336 @samp{--enable-runtime-pseudo-relocs} is used.
9338 Given the improvements in speed and memory usage, one might justifiably
9339 wonder why import libraries are used at all. There are three reasons:
9341 1. Until recently, the link-directly-to-dll functionality did @emph{not}
9342 work with auto-imported data.
9344 2. Sometimes it is necessary to include pure static objects within the
9345 import library (which otherwise contains only bfd's for indirection
9346 symbols that point to the exports of a dll). Again, the import lib
9347 for the cygwin kernel makes use of this ability, and it is not
9348 possible to do this without an import lib.
9350 3. Symbol aliases can only be resolved using an import lib. This is
9351 critical when linking against OS-supplied dll's (eg, the win32 API)
9352 in which symbols are usually exported as undecorated aliases of their
9353 stdcall-decorated assembly names.
9355 So, import libs are not going away. But the ability to replace
9356 true import libs with a simple symbolic link to (or a copy of)
9357 a dll, in many cases, is a useful addition to the suite of tools
9358 binutils makes available to the win32 developer. Given the
9359 massive improvements in memory requirements during linking, storage
9360 requirements, and linking speed, we expect that many developers
9361 will soon begin to use this feature whenever possible.
9363 @item symbol aliasing
9365 @item adding additional names
9366 Sometimes, it is useful to export symbols with additional names.
9367 A symbol @samp{foo} will be exported as @samp{foo}, but it can also be
9368 exported as @samp{_foo} by using special directives in the DEF file
9369 when creating the dll. This will affect also the optional created
9370 import library. Consider the following DEF file:
9373 LIBRARY "xyz.dll" BASE=0x61000000
9380 The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
9382 Another method for creating a symbol alias is to create it in the
9383 source code using the "weak" attribute:
9386 void foo () @{ /* Do something. */; @}
9387 void _foo () __attribute__ ((weak, alias ("foo")));
9390 See the gcc manual for more information about attributes and weak
9393 @item renaming symbols
9394 Sometimes it is useful to rename exports. For instance, the cygwin
9395 kernel does this regularly. A symbol @samp{_foo} can be exported as
9396 @samp{foo} but not as @samp{_foo} by using special directives in the
9397 DEF file. (This will also affect the import library, if it is
9398 created). In the following example:
9401 LIBRARY "xyz.dll" BASE=0x61000000
9407 The line @samp{_foo = foo} maps the exported symbol @samp{foo} to
9411 Note: using a DEF file disables the default auto-export behavior,
9412 unless the @samp{--export-all-symbols} command-line option is used.
9413 If, however, you are trying to rename symbols, then you should list
9414 @emph{all} desired exports in the DEF file, including the symbols
9415 that are not being renamed, and do @emph{not} use the
9416 @samp{--export-all-symbols} option. If you list only the
9417 renamed symbols in the DEF file, and use @samp{--export-all-symbols}
9418 to handle the other symbols, then the both the new names @emph{and}
9419 the original names for the renamed symbols will be exported.
9420 In effect, you'd be aliasing those symbols, not renaming them,
9421 which is probably not what you wanted.
9423 @cindex weak externals
9424 @item weak externals
9425 The Windows object format, PE, specifies a form of weak symbols called
9426 weak externals. When a weak symbol is linked and the symbol is not
9427 defined, the weak symbol becomes an alias for some other symbol. There
9428 are three variants of weak externals:
9430 @item Definition is searched for in objects and libraries, historically
9431 called lazy externals.
9432 @item Definition is searched for only in other objects, not in libraries.
9433 This form is not presently implemented.
9434 @item No search; the symbol is an alias. This form is not presently
9437 As a GNU extension, weak symbols that do not specify an alternate symbol
9438 are supported. If the symbol is undefined when linking, the symbol
9439 uses a default value.
9441 @cindex aligned common symbols
9442 @item aligned common symbols
9443 As a GNU extension to the PE file format, it is possible to specify the
9444 desired alignment for a common symbol. This information is conveyed from
9445 the assembler or compiler to the linker by means of GNU-specific commands
9446 carried in the object file's @samp{.drectve} section, which are recognized
9447 by @command{ld} and respected when laying out the common symbols. Native
9448 tools will be able to process object files employing this GNU extension,
9449 but will fail to respect the alignment instructions, and may issue noisy
9450 warnings about unknown linker directives.
9465 @section @code{ld} and Xtensa Processors
9467 @cindex Xtensa processors
9468 The default @command{ld} behavior for Xtensa processors is to interpret
9469 @code{SECTIONS} commands so that lists of explicitly named sections in a
9470 specification with a wildcard file will be interleaved when necessary to
9471 keep literal pools within the range of PC-relative load offsets. For
9472 example, with the command:
9484 @command{ld} may interleave some of the @code{.literal}
9485 and @code{.text} sections from different object files to ensure that the
9486 literal pools are within the range of PC-relative load offsets. A valid
9487 interleaving might place the @code{.literal} sections from an initial
9488 group of files followed by the @code{.text} sections of that group of
9489 files. Then, the @code{.literal} sections from the rest of the files
9490 and the @code{.text} sections from the rest of the files would follow.
9492 @cindex @option{--relax} on Xtensa
9493 @cindex relaxing on Xtensa
9494 Relaxation is enabled by default for the Xtensa version of @command{ld} and
9495 provides two important link-time optimizations. The first optimization
9496 is to combine identical literal values to reduce code size. A redundant
9497 literal will be removed and all the @code{L32R} instructions that use it
9498 will be changed to reference an identical literal, as long as the
9499 location of the replacement literal is within the offset range of all
9500 the @code{L32R} instructions. The second optimization is to remove
9501 unnecessary overhead from assembler-generated ``longcall'' sequences of
9502 @code{L32R}/@code{CALLX@var{n}} when the target functions are within
9503 range of direct @code{CALL@var{n}} instructions.
9505 For each of these cases where an indirect call sequence can be optimized
9506 to a direct call, the linker will change the @code{CALLX@var{n}}
9507 instruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
9508 instruction, and remove the literal referenced by the @code{L32R}
9509 instruction if it is not used for anything else. Removing the
9510 @code{L32R} instruction always reduces code size but can potentially
9511 hurt performance by changing the alignment of subsequent branch targets.
9512 By default, the linker will always preserve alignments, either by
9513 switching some instructions between 24-bit encodings and the equivalent
9514 density instructions or by inserting a no-op in place of the @code{L32R}
9515 instruction that was removed. If code size is more important than
9516 performance, the @option{--size-opt} option can be used to prevent the
9517 linker from widening density instructions or inserting no-ops, except in
9518 a few cases where no-ops are required for correctness.
9520 The following Xtensa-specific command-line options can be used to
9523 @cindex Xtensa options
9526 When optimizing indirect calls to direct calls, optimize for code size
9527 more than performance. With this option, the linker will not insert
9528 no-ops or widen density instructions to preserve branch target
9529 alignment. There may still be some cases where no-ops are required to
9530 preserve the correctness of the code.
9532 @item --abi-windowed
9534 Choose ABI for the output object and for the generated PLT code.
9535 PLT code inserted by the linker must match ABI of the output object
9536 because windowed and call0 ABI use incompatible function call
9538 Default ABI is chosen by the ABI tag in the @code{.xtensa.info} section
9539 of the first input object.
9540 A warning is issued if ABI tags of input objects do not match each other
9541 or the chosen output object ABI.
9549 @ifclear SingleFormat
9554 @cindex object file management
9555 @cindex object formats available
9557 The linker accesses object and archive files using the BFD libraries.
9558 These libraries allow the linker to use the same routines to operate on
9559 object files whatever the object file format. A different object file
9560 format can be supported simply by creating a new BFD back end and adding
9561 it to the library. To conserve runtime memory, however, the linker and
9562 associated tools are usually configured to support only a subset of the
9563 object file formats available. You can use @code{objdump -i}
9564 (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
9565 list all the formats available for your configuration.
9567 @cindex BFD requirements
9568 @cindex requirements for BFD
9569 As with most implementations, BFD is a compromise between
9570 several conflicting requirements. The major factor influencing
9571 BFD design was efficiency: any time used converting between
9572 formats is time which would not have been spent had BFD not
9573 been involved. This is partly offset by abstraction payback; since
9574 BFD simplifies applications and back ends, more time and care
9575 may be spent optimizing algorithms for a greater speed.
9577 One minor artifact of the BFD solution which you should bear in
9578 mind is the potential for information loss. There are two places where
9579 useful information can be lost using the BFD mechanism: during
9580 conversion and during output. @xref{BFD information loss}.
9583 * BFD outline:: How it works: an outline of BFD
9587 @section How It Works: An Outline of BFD
9588 @cindex opening object files
9589 @include bfdsumm.texi
9592 @node Reporting Bugs
9593 @chapter Reporting Bugs
9594 @cindex bugs in @command{ld}
9595 @cindex reporting bugs in @command{ld}
9597 Your bug reports play an essential role in making @command{ld} reliable.
9599 Reporting a bug may help you by bringing a solution to your problem, or
9600 it may not. But in any case the principal function of a bug report is
9601 to help the entire community by making the next version of @command{ld}
9602 work better. Bug reports are your contribution to the maintenance of
9605 In order for a bug report to serve its purpose, you must include the
9606 information that enables us to fix the bug.
9609 * Bug Criteria:: Have you found a bug?
9610 * Bug Reporting:: How to report bugs
9614 @section Have You Found a Bug?
9615 @cindex bug criteria
9617 If you are not sure whether you have found a bug, here are some guidelines:
9620 @cindex fatal signal
9621 @cindex linker crash
9622 @cindex crash of linker
9624 If the linker gets a fatal signal, for any input whatever, that is a
9625 @command{ld} bug. Reliable linkers never crash.
9627 @cindex error on valid input
9629 If @command{ld} produces an error message for valid input, that is a bug.
9631 @cindex invalid input
9633 If @command{ld} does not produce an error message for invalid input, that
9634 may be a bug. In the general case, the linker can not verify that
9635 object files are correct.
9638 If you are an experienced user of linkers, your suggestions for
9639 improvement of @command{ld} are welcome in any case.
9643 @section How to Report Bugs
9645 @cindex @command{ld} bugs, reporting
9647 A number of companies and individuals offer support for @sc{gnu}
9648 products. If you obtained @command{ld} from a support organization, we
9649 recommend you contact that organization first.
9651 You can find contact information for many support companies and
9652 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
9656 Otherwise, send bug reports for @command{ld} to
9660 The fundamental principle of reporting bugs usefully is this:
9661 @strong{report all the facts}. If you are not sure whether to state a
9662 fact or leave it out, state it!
9664 Often people omit facts because they think they know what causes the
9665 problem and assume that some details do not matter. Thus, you might
9666 assume that the name of a symbol you use in an example does not
9667 matter. Well, probably it does not, but one cannot be sure. Perhaps
9668 the bug is a stray memory reference which happens to fetch from the
9669 location where that name is stored in memory; perhaps, if the name
9670 were different, the contents of that location would fool the linker
9671 into doing the right thing despite the bug. Play it safe and give a
9672 specific, complete example. That is the easiest thing for you to do,
9673 and the most helpful.
9675 Keep in mind that the purpose of a bug report is to enable us to fix
9676 the bug if it is new to us. Therefore, always write your bug reports
9677 on the assumption that the bug has not been reported previously.
9679 Sometimes people give a few sketchy facts and ask, ``Does this ring a
9680 bell?'' This cannot help us fix a bug, so it is basically useless. We
9681 respond by asking for enough details to enable us to investigate.
9682 You might as well expedite matters by sending them to begin with.
9684 To enable us to fix the bug, you should include all these things:
9688 The version of @command{ld}. @command{ld} announces it if you start it with
9689 the @samp{--version} argument.
9691 Without this, we will not know whether there is any point in looking for
9692 the bug in the current version of @command{ld}.
9695 Any patches you may have applied to the @command{ld} source, including any
9696 patches made to the @code{BFD} library.
9699 The type of machine you are using, and the operating system name and
9703 What compiler (and its version) was used to compile @command{ld}---e.g.
9707 The command arguments you gave the linker to link your example and
9708 observe the bug. To guarantee you will not omit something important,
9709 list them all. A copy of the Makefile (or the output from make) is
9712 If we were to try to guess the arguments, we would probably guess wrong
9713 and then we might not encounter the bug.
9716 A complete input file, or set of input files, that will reproduce the
9717 bug. It is generally most helpful to send the actual object files
9718 provided that they are reasonably small. Say no more than 10K. For
9719 bigger files you can either make them available by FTP or HTTP or else
9720 state that you are willing to send the object file(s) to whomever
9721 requests them. (Note - your email will be going to a mailing list, so
9722 we do not want to clog it up with large attachments). But small
9723 attachments are best.
9725 If the source files were assembled using @code{gas} or compiled using
9726 @code{gcc}, then it may be OK to send the source files rather than the
9727 object files. In this case, be sure to say exactly what version of
9728 @code{gas} or @code{gcc} was used to produce the object files. Also say
9729 how @code{gas} or @code{gcc} were configured.
9732 A description of what behavior you observe that you believe is
9733 incorrect. For example, ``It gets a fatal signal.''
9735 Of course, if the bug is that @command{ld} gets a fatal signal, then we
9736 will certainly notice it. But if the bug is incorrect output, we might
9737 not notice unless it is glaringly wrong. You might as well not give us
9738 a chance to make a mistake.
9740 Even if the problem you experience is a fatal signal, you should still
9741 say so explicitly. Suppose something strange is going on, such as, your
9742 copy of @command{ld} is out of sync, or you have encountered a bug in the
9743 C library on your system. (This has happened!) Your copy might crash
9744 and ours would not. If you told us to expect a crash, then when ours
9745 fails to crash, we would know that the bug was not happening for us. If
9746 you had not told us to expect a crash, then we would not be able to draw
9747 any conclusion from our observations.
9750 If you wish to suggest changes to the @command{ld} source, send us context
9751 diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
9752 @samp{-p} option. Always send diffs from the old file to the new file.
9753 If you even discuss something in the @command{ld} source, refer to it by
9754 context, not by line number.
9756 The line numbers in our development sources will not match those in your
9757 sources. Your line numbers would convey no useful information to us.
9760 Here are some things that are not necessary:
9764 A description of the envelope of the bug.
9766 Often people who encounter a bug spend a lot of time investigating
9767 which changes to the input file will make the bug go away and which
9768 changes will not affect it.
9770 This is often time consuming and not very useful, because the way we
9771 will find the bug is by running a single example under the debugger
9772 with breakpoints, not by pure deduction from a series of examples.
9773 We recommend that you save your time for something else.
9775 Of course, if you can find a simpler example to report @emph{instead}
9776 of the original one, that is a convenience for us. Errors in the
9777 output will be easier to spot, running under the debugger will take
9778 less time, and so on.
9780 However, simplification is not vital; if you do not want to do this,
9781 report the bug anyway and send us the entire test case you used.
9784 A patch for the bug.
9786 A patch for the bug does help us if it is a good one. But do not omit
9787 the necessary information, such as the test case, on the assumption that
9788 a patch is all we need. We might see problems with your patch and decide
9789 to fix the problem another way, or we might not understand it at all.
9791 Sometimes with a program as complicated as @command{ld} it is very hard to
9792 construct an example that will make the program follow a certain path
9793 through the code. If you do not send us the example, we will not be
9794 able to construct one, so we will not be able to verify that the bug is
9797 And if we cannot understand what bug you are trying to fix, or why your
9798 patch should be an improvement, we will not install it. A test case will
9799 help us to understand.
9802 A guess about what the bug is or what it depends on.
9804 Such guesses are usually wrong. Even we cannot guess right about such
9805 things without first using the debugger to find the facts.
9809 @appendix MRI Compatible Script Files
9810 @cindex MRI compatibility
9811 To aid users making the transition to @sc{gnu} @command{ld} from the MRI
9812 linker, @command{ld} can use MRI compatible linker scripts as an
9813 alternative to the more general-purpose linker scripting language
9814 described in @ref{Scripts}. MRI compatible linker scripts have a much
9815 simpler command set than the scripting language otherwise used with
9816 @command{ld}. @sc{gnu} @command{ld} supports the most commonly used MRI
9817 linker commands; these commands are described here.
9819 In general, MRI scripts aren't of much use with the @code{a.out} object
9820 file format, since it only has three sections and MRI scripts lack some
9821 features to make use of them.
9823 You can specify a file containing an MRI-compatible script using the
9824 @samp{-c} command-line option.
9826 Each command in an MRI-compatible script occupies its own line; each
9827 command line starts with the keyword that identifies the command (though
9828 blank lines are also allowed for punctuation). If a line of an
9829 MRI-compatible script begins with an unrecognized keyword, @command{ld}
9830 issues a warning message, but continues processing the script.
9832 Lines beginning with @samp{*} are comments.
9834 You can write these commands using all upper-case letters, or all
9835 lower case; for example, @samp{chip} is the same as @samp{CHIP}.
9836 The following list shows only the upper-case form of each command.
9839 @cindex @code{ABSOLUTE} (MRI)
9840 @item ABSOLUTE @var{secname}
9841 @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
9842 Normally, @command{ld} includes in the output file all sections from all
9843 the input files. However, in an MRI-compatible script, you can use the
9844 @code{ABSOLUTE} command to restrict the sections that will be present in
9845 your output program. If the @code{ABSOLUTE} command is used at all in a
9846 script, then only the sections named explicitly in @code{ABSOLUTE}
9847 commands will appear in the linker output. You can still use other
9848 input sections (whatever you select on the command line, or using
9849 @code{LOAD}) to resolve addresses in the output file.
9851 @cindex @code{ALIAS} (MRI)
9852 @item ALIAS @var{out-secname}, @var{in-secname}
9853 Use this command to place the data from input section @var{in-secname}
9854 in a section called @var{out-secname} in the linker output file.
9856 @var{in-secname} may be an integer.
9858 @cindex @code{ALIGN} (MRI)
9859 @item ALIGN @var{secname} = @var{expression}
9860 Align the section called @var{secname} to @var{expression}. The
9861 @var{expression} should be a power of two.
9863 @cindex @code{BASE} (MRI)
9864 @item BASE @var{expression}
9865 Use the value of @var{expression} as the lowest address (other than
9866 absolute addresses) in the output file.
9868 @cindex @code{CHIP} (MRI)
9869 @item CHIP @var{expression}
9870 @itemx CHIP @var{expression}, @var{expression}
9871 This command does nothing; it is accepted only for compatibility.
9873 @cindex @code{END} (MRI)
9875 This command does nothing whatever; it's only accepted for compatibility.
9877 @cindex @code{FORMAT} (MRI)
9878 @item FORMAT @var{output-format}
9879 Similar to the @code{OUTPUT_FORMAT} command in the more general linker
9880 language, but restricted to S-records, if @var{output-format} is @samp{S}
9882 @cindex @code{LIST} (MRI)
9883 @item LIST @var{anything}@dots{}
9884 Print (to the standard output file) a link map, as produced by the
9885 @command{ld} command-line option @samp{-M}.
9887 The keyword @code{LIST} may be followed by anything on the
9888 same line, with no change in its effect.
9890 @cindex @code{LOAD} (MRI)
9891 @item LOAD @var{filename}
9892 @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
9893 Include one or more object file @var{filename} in the link; this has the
9894 same effect as specifying @var{filename} directly on the @command{ld}
9897 @cindex @code{NAME} (MRI)
9898 @item NAME @var{output-name}
9899 @var{output-name} is the name for the program produced by @command{ld}; the
9900 MRI-compatible command @code{NAME} is equivalent to the command-line
9901 option @samp{-o} or the general script language command @code{OUTPUT}.
9903 @cindex @code{ORDER} (MRI)
9904 @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
9905 @itemx ORDER @var{secname} @var{secname} @var{secname}
9906 Normally, @command{ld} orders the sections in its output file in the
9907 order in which they first appear in the input files. In an MRI-compatible
9908 script, you can override this ordering with the @code{ORDER} command. The
9909 sections you list with @code{ORDER} will appear first in your output
9910 file, in the order specified.
9912 @cindex @code{PUBLIC} (MRI)
9913 @item PUBLIC @var{name}=@var{expression}
9914 @itemx PUBLIC @var{name},@var{expression}
9915 @itemx PUBLIC @var{name} @var{expression}
9916 Supply a value (@var{expression}) for external symbol
9917 @var{name} used in the linker input files.
9919 @cindex @code{SECT} (MRI)
9920 @item SECT @var{secname}, @var{expression}
9921 @itemx SECT @var{secname}=@var{expression}
9922 @itemx SECT @var{secname} @var{expression}
9923 You can use any of these three forms of the @code{SECT} command to
9924 specify the start address (@var{expression}) for section @var{secname}.
9925 If you have more than one @code{SECT} statement for the same
9926 @var{secname}, only the @emph{first} sets the start address.
9929 @node GNU Free Documentation License
9930 @appendix GNU Free Documentation License
9934 @unnumbered LD Index
9939 % I think something like @@colophon should be in texinfo. In the
9941 \long\def\colophon{\hbox to0pt{}\vfill
9942 \centerline{The body of this manual is set in}
9943 \centerline{\fontname\tenrm,}
9944 \centerline{with headings in {\bf\fontname\tenbf}}
9945 \centerline{and examples in {\tt\fontname\tentt}.}
9946 \centerline{{\it\fontname\tenit\/} and}
9947 \centerline{{\sl\fontname\tensl\/}}
9948 \centerline{are used for emphasis.}\vfill}
9950 % Blame: doc@@cygnus.com, 28mar91.