Automatic date update in version.in
[binutils-gdb.git] / ld / ld.texi
blobca9574dfc71bf46f3ace541fb544cdcbb061c497
1 \input texinfo
2 @setfilename ld.info
3 @c Copyright (C) 1991-2024 Free Software Foundation, Inc.
4 @syncodeindex ky cp
5 @c man begin INCLUDE
6 @include configdoc.texi
7 @c (configdoc.texi is generated by the Makefile)
8 @include bfdver.texi
9 @c man end
11 @c @smallbook
13 @macro gcctabopt{body}
14 @code{\body\}
15 @end macro
17 @c man begin NAME
18 @ifset man
19 @c Configure for the generation of man pages
20 @set UsesEnvVars
21 @set GENERIC
22 @set ARM
23 @set C6X
24 @set CSKY
25 @set H8300
26 @set HPPA
27 @set M68HC11
28 @set M68K
29 @set MIPS
30 @set MMIX
31 @set MSP430
32 @set NDS32
33 @set NIOSII
34 @set PDP11
35 @set POWERPC
36 @set POWERPC64
37 @set Renesas
38 @set S/390
39 @set SPU
40 @set TICOFF
41 @set WIN32
42 @set XTENSA
43 @end ifset
44 @c man end
46 @ifnottex
47 @dircategory Software development
48 @direntry
49 * Ld: (ld).                       The GNU linker.
50 @end direntry
51 @end ifnottex
53 @copying
54 This file documents the @sc{gnu} linker LD
55 @ifset VERSION_PACKAGE
56 @value{VERSION_PACKAGE}
57 @end ifset
58 version @value{VERSION}.
60 Copyright @copyright{} 1991-2024 Free Software Foundation, Inc.
62 Permission is granted to copy, distribute and/or modify this document
63 under the terms of the GNU Free Documentation License, Version 1.3
64 or any later version published by the Free Software Foundation;
65 with no Invariant Sections, with no Front-Cover Texts, and with no
66 Back-Cover Texts.  A copy of the license is included in the
67 section entitled ``GNU Free Documentation License''.
68 @end copying
69 @iftex
70 @finalout
71 @setchapternewpage odd
72 @settitle The GNU linker
73 @titlepage
74 @title The GNU linker
75 @sp 1
76 @subtitle @code{ld}
77 @ifset VERSION_PACKAGE
78 @subtitle @value{VERSION_PACKAGE}
79 @end ifset
80 @subtitle Version @value{VERSION}
81 @author Steve Chamberlain
82 @author Ian Lance Taylor
83 @page
85 @tex
86 {\parskip=0pt
87 \hfill Red Hat Inc\par
88 \hfill nickc\@redhat.com, doc\@redhat.com\par
89 \hfill {\it The GNU linker}\par
90 \hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
92 \global\parindent=0pt % Steve likes it this way.
93 @end tex
95 @vskip 0pt plus 1filll
96 @c man begin COPYRIGHT
97 Copyright @copyright{} 1991-2024 Free Software Foundation, Inc.
99 Permission is granted to copy, distribute and/or modify this document
100 under the terms of the GNU Free Documentation License, Version 1.3
101 or any later version published by the Free Software Foundation;
102 with no Invariant Sections, with no Front-Cover Texts, and with no
103 Back-Cover Texts.  A copy of the license is included in the
104 section entitled ``GNU Free Documentation License''.
105 @c man end
107 @end titlepage
108 @end iftex
109 @contents
110 @c FIXME: Talk about importance of *order* of args, cmds to linker!
112 @ifnottex
113 @node Top
114 @top LD
115 This file documents the @sc{gnu} linker ld
116 @ifset VERSION_PACKAGE
117 @value{VERSION_PACKAGE}
118 @end ifset
119 version @value{VERSION}.
121 This document is distributed under the terms of the GNU Free
122 Documentation License version 1.3.  A copy of the license is included
123 in the section entitled ``GNU Free Documentation License''.
125 @menu
126 * Overview::                    Overview
127 * Invocation::                  Invocation
128 * Scripts::                     Linker Scripts
129 * Plugins::                     Linker Plugins
130 * Special Sections::            Special Sections
131 @ifset GENERIC
132 * Machine Dependent::           Machine Dependent Features
133 @end ifset
134 @ifclear GENERIC
135 @ifset H8300
136 * H8/300::                      ld and the H8/300
137 @end ifset
138 @ifset Renesas
139 * Renesas::                     ld and other Renesas micros
140 @end ifset
141 @ifset ARM
142 * ARM::                         ld and the ARM family
143 @end ifset
144 @ifset M68HC11
145 * M68HC11/68HC12::              ld and the Motorola 68HC11 and 68HC12 families
146 @end ifset
147 @ifset HPPA
148 * HPPA ELF32::                  ld and HPPA 32-bit ELF
149 @end ifset
150 @ifset M68K
151 * M68K::                        ld and Motorola 68K family
152 @end ifset
153 @ifset MIPS
154 * MIPS::                        ld and MIPS family
155 @end ifset
156 @ifset POWERPC
157 * PowerPC ELF32::               ld and PowerPC 32-bit ELF Support
158 @end ifset
159 @ifset POWERPC64
160 * PowerPC64 ELF64::             ld and PowerPC64 64-bit ELF Support
161 @end ifset
162 @ifset S/390
163 * S/390 ELF::                   ld and S/390 ELF Support
164 @end ifset
165 @ifset SPU
166 * SPU ELF::                     ld and SPU ELF Support
167 @end ifset
168 @ifset TICOFF
169 * TI COFF::                     ld and the TI COFF
170 @end ifset
171 @ifset WIN32
172 * Win32::                       ld and WIN32 (cygwin/mingw)
173 @end ifset
174 @ifset XTENSA
175 * Xtensa::                      ld and Xtensa Processors
176 @end ifset
177 @end ifclear
178 @ifclear SingleFormat
179 * BFD::                         BFD
180 @end ifclear
181 @c Following blank line required for remaining bug in makeinfo conds/menus
183 * Reporting Bugs::              Reporting Bugs
184 * MRI::                         MRI Compatible Script Files
185 * GNU Free Documentation License::  GNU Free Documentation License
186 * LD Index::                       LD Index
187 @end menu
188 @end ifnottex
190 @node Overview
191 @chapter Overview
193 @cindex @sc{gnu} linker
194 @cindex what is this?
196 @ifset man
197 @c man begin SYNOPSIS
198 ld [@b{options}] @var{objfile} @dots{}
199 @c man end
201 @c man begin SEEALSO
202 ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
203 the Info entries for @file{binutils} and
204 @file{ld}.
205 @c man end
206 @end ifset
208 @c man begin DESCRIPTION
210 @command{ld} combines a number of object and archive files, relocates
211 their data and ties up symbol references. Usually the last step in
212 compiling a program is to run @command{ld}.
214 @command{ld} accepts Linker Command Language files written in
215 a superset of AT&T's Link Editor Command Language syntax,
216 to provide explicit and total control over the linking process.
218 @ifset man
219 @c For the man only
220 This man page does not describe the command language; see the
221 @command{ld} entry in @code{info} for full details on the command
222 language and on other aspects of the GNU linker.
223 @end ifset
225 @ifclear SingleFormat
226 This version of @command{ld} uses the general purpose BFD libraries
227 to operate on object files. This allows @command{ld} to read, combine, and
228 write object files in many different formats---for example, COFF or
229 @code{a.out}.  Different formats may be linked together to produce any
230 available kind of object file.  @xref{BFD}, for more information.
231 @end ifclear
233 Aside from its flexibility, the @sc{gnu} linker is more helpful than other
234 linkers in providing diagnostic information.  Many linkers abandon
235 execution immediately upon encountering an error; whenever possible,
236 @command{ld} continues executing, allowing you to identify other errors
237 (or, in some cases, to get an output file in spite of the error).
239 @c man end
241 @node Invocation
242 @chapter Invocation
244 @c man begin DESCRIPTION
246 The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
247 and to be as compatible as possible with other linkers.  As a result,
248 you have many choices to control its behavior.
250 @c man end
252 @ifset UsesEnvVars
253 @menu
254 * Options::                     Command-line Options
255 * Environment::                 Environment Variables
256 @end menu
258 @node Options
259 @section Command-line Options
260 @end ifset
262 @cindex command line
263 @cindex options
265 @c man begin OPTIONS
267 The linker supports a plethora of command-line options, but in actual
268 practice few of them are used in any particular context.
269 @cindex standard Unix system
270 For instance, a frequent use of @command{ld} is to link standard Unix
271 object files on a standard, supported Unix system.  On such a system, to
272 link a file @code{hello.o}:
274 @smallexample
275 ld -o @var{output} /lib/crt0.o hello.o -lc
276 @end smallexample
278 This tells @command{ld} to produce a file called @var{output} as the
279 result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
280 the library @code{libc.a}, which will come from the standard search
281 directories.  (See the discussion of the @samp{-l} option below.)
283 Some of the command-line options to @command{ld} may be specified at any
284 point in the command line.  However, options which refer to files, such
285 as @samp{-l} or @samp{-T}, cause the file to be read at the point at
286 which the option appears in the command line, relative to the object
287 files and other file options.  Repeating non-file options with a
288 different argument will either have no further effect, or override prior
289 occurrences (those further to the left on the command line) of that
290 option.  Options which may be meaningfully specified more than once are
291 noted in the descriptions below.
293 @cindex object files
294 Non-option arguments are object files or archives which are to be linked
295 together.  They may follow, precede, or be mixed in with command-line
296 options, except that an object file argument may not be placed between
297 an option and its argument.
299 Usually the linker is invoked with at least one object file, but you can
300 specify other forms of binary input files using @samp{-l}, @samp{-R},
301 and the script command language.  If @emph{no} binary input files at all
302 are specified, the linker does not produce any output, and issues the
303 message @samp{No input files}.
305 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
329 output.
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
336 accepted.
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:
343 @smallexample
344   gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
345 @end smallexample
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:
355 @smallexample
356   gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
357 @end smallexample
359 Here is a table of the generic command-line switches accepted by the GNU
360 linker:
362 @table @gcctabopt
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
382 interface.
384 @ifclear SingleFormat
385 @cindex binary input format
386 @kindex -b @var{format}
387 @kindex --format=@var{format}
388 @cindex input format
389 @cindex input 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}.)
402 @xref{BFD}.
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
408 particular format.
410 The default format is taken from the environment variable
411 @code{GNUTARGET}.
412 @ifset UsesEnvVars
413 @xref{Environment}.
414 @end ifset
415 You can also define the input format from a script, using the command
416 @code{TARGET};
417 @ifclear man
418 see @ref{Format Commands}.
419 @end ifclear
420 @end ifclear
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
429 @ifclear man
430 @ref{MRI,,MRI Compatible Script Files}.
431 @end ifclear
432 @ifset man
433 the MRI Compatible Script Files section of GNU ld documentation.
434 @end ifset
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
442 @kindex -d
443 @kindex -dc
444 @kindex -dp
445 @item -d
446 @itemx -dc
447 @itemx -dp
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:
491 @smallexample
492   MEMORY @{
493     MEM1 (rwx) : ORIGIN = 0x1000, LENGTH = 0x14
494     MEM2 (rwx) : ORIGIN = 0x1000, LENGTH = 0x40
495     MEM3 (rwx) : ORIGIN = 0x2000, LENGTH = 0x40
496   @}
497   SECTIONS @{
498     mem1 : @{ *(.data.*); @} > MEM1
499     mem2 : @{ *(.data.*); @} > MEM2
500     mem3 : @{ *(.data.*); @} > MEM3
501   @}
503   with input sections:
504   .data.1: size 8
505   .data.2: size 0x10
506   .data.3: size 4
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.
510 @end smallexample
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
521 output region.
523 @cindex entry point, from command line
524 @kindex -e @var{entry}
525 @kindex --entry=@var{entry}
526 @item -e @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
561 @kindex -E
562 @kindex --export-dynamic
563 @kindex --no-export-dynamic
564 @item -E
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
610 @cindex endianness
611 @kindex -EB
612 @item -EB
613 Link big-endian objects.  This affects the default output format.
615 @cindex little-endian objects
616 @kindex -EL
617 @item -EL
618 Link little-endian objects.  This affects the default output format.
619 @end ifclear
621 @kindex -f @var{name}
622 @kindex --auxiliary=@var{name}
623 @item -f @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}
645 @item -F @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
658 @var{name}.
660 Some older linkers used the @option{-F} option throughout a compilation
661 toolchain for specifying object-file format for both input and output
662 object files.
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.
668 @end ifclear
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.
680 @kindex -g
681 @item -g
682 Ignored.  Provided for compatibility with other tools.
684 @kindex -G @var{value}
685 @kindex --gpsize=@var{value}
686 @cindex object size
687 @item -G @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}
697 @item -h @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.
705 @kindex -i
706 @cindex incremental link
707 @item -i
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
716 function to call.
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
736 @var{filename}.
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.
750 @ifset GENERIC
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.
754 @end ifset
756 @cindex search directory, from cmd line
757 @kindex -L @var{dir}
758 @kindex --library-path=@var{dir}
759 @item -L @var{searchdir}
760 @itemx --library-path=@var{searchdir}
761 @anchor{-L}
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}
770 option is specified.
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.
776 @ifset UsesEnvVars
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}.
780 @end ifset
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.
786 @cindex emulation
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
796 configured.
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:
833 @smallexample
834   ld foo.o --remap-inputs=foo.o=bar.o
835 @end smallexample
837 Will have no effect, whereas:
839 @smallexample
840   ld --remap-inputs=foo.o=bar.o foo.o 
841 @end smallexample
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
853 appear.
855 If the @option{-Map} or @option{--print-map} options are enabled then
856 the remapping list will be included in the map output.
858 @cindex link map
859 @kindex -M
860 @kindex --print-map
861 @item -M
862 @itemx --print-map
863 Print a link map to the standard output.  A link map provides
864 information about the link, including the following:
866 @itemize @bullet
867 @item
868 Where object files are mapped into memory.
869 @item
870 How common symbols are allocated.
871 @item
872 All archive members included in the link, with a mention of the symbol
873 which caused the archive member to be brought in.
874 @item
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:
885 @smallexample
886    foo = 1
887    foo = foo * 4
888    foo = foo + 8
889 @end smallexample
891 will produce the following output in the link map if the @option{-M}
892 option is used:
894 @smallexample
895    0x00000001                foo = 0x1
896    [0x0000000c]                foo = (foo * 0x4)
897    [0x0000000c]                foo = (foo + 0x8)
898 @end smallexample
900 See @ref{Expressions} for more information about expressions in linker
901 scripts.
903 @item
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:
910 @smallexample
911 Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
912 @end smallexample
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.
918 @smallexample
919 Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
920 @end smallexample
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.
926 @item
927 On some ELF targets, a list of fixups inserted by @option{--relax}
929 @smallexample
930 foo.o: Adjusting branch at 0x00000008 towards "far" in section .text
931 @end smallexample
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.
936 @end itemize
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.
956 @kindex -n
957 @cindex read-only text
958 @cindex NMAGIC
959 @kindex --nmagic
960 @item -n
961 @itemx --nmagic
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}.
966 @kindex -N
967 @kindex --omagic
968 @cindex read/write from cmd line
969 @cindex OMAGIC
970 @item -N
971 @itemx --omagic
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.
979 @kindex --no-omagic
980 @cindex OMAGIC
981 @item --no-omagic
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 @kindex --dependency-file=@var{depfile}
997 @cindex dependency file
998 @item --dependency-file=@var{depfile}
999 Write a @dfn{dependency file} to @var{depfile}.  This file contains a rule
1000 suitable for @code{make} describing the output file and all the input files
1001 that were read to produce it.  The output is similar to the compiler's
1002 output with @samp{-M -MP} (@pxref{Preprocessor Options,, Options
1003 Controlling the Preprocessor, gcc.info, Using the GNU Compiler
1004 Collection}).  Note that there is no option like the compiler's @samp{-MM},
1005 to exclude ``system files'' (which is not a well-specified concept in the
1006 linker, unlike ``system headers'' in the compiler).  So the output from
1007 @samp{--dependency-file} is always specific to the exact state of the
1008 installation where it was produced, and should not be copied into
1009 distributed makefiles without careful editing.
1011 @kindex -O @var{level}
1012 @cindex generating optimized output
1013 @item -O @var{level}
1014 If @var{level} is a numeric values greater than zero @command{ld} optimizes
1015 the output.  This might take significantly longer and therefore probably
1016 should only be enabled for the final binary.  At the moment this
1017 option only affects ELF shared library generation.  Future releases of
1018 the linker may make more use of this option.  Also currently there is
1019 no difference in the linker's behaviour for different non-zero values
1020 of this option.  Again this may change with future releases.
1022 @kindex -plugin @var{name}
1023 @item -plugin @var{name}
1024 Involve a plugin in the linking process.  The @var{name} parameter is
1025 the absolute filename of the plugin.  Usually this parameter is
1026 automatically added by the complier, when using link time
1027 optimization, but users can also add their own plugins if they so
1028 wish.
1030 Note that the location of the compiler originated plugins is different
1031 from the place where the @command{ar}, @command{nm} and
1032 @command{ranlib} programs search for their plugins.  In order for
1033 those commands to make use of a compiler based plugin it must first be
1034 copied into the @file{$@{libdir@}/bfd-plugins} directory.  All gcc
1035 based linker plugins are backward compatible, so it is sufficient to
1036 just copy in the newest one.
1038 @kindex --push-state
1039 @cindex push state governing input file handling
1040 @item --push-state
1041 The @option{--push-state} allows one to preserve the current state of the
1042 flags which govern the input file handling so that they can all be
1043 restored with one corresponding @option{--pop-state} option.
1045 The option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
1046 @option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
1047 @option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
1048 @option{--no-whole-archive}, @option{-r}, @option{-Ur},
1049 @option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
1050 @option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
1052 One target for this option are specifications for @file{pkg-config}.  When
1053 used with the @option{--libs} option all possibly needed libraries are
1054 listed and then possibly linked with all the time.  It is better to return
1055 something as follows:
1057 @smallexample
1058 -Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
1059 @end smallexample
1061 @kindex --pop-state
1062 @cindex pop state governing input file handling
1063 @item --pop-state
1064 Undoes the effect of --push-state, restores the previous values of the
1065 flags governing input file handling.
1067 @kindex -q
1068 @kindex --emit-relocs
1069 @cindex retain relocations in final executable
1070 @item -q
1071 @itemx --emit-relocs
1072 Leave relocation sections and contents in fully linked executables.
1073 Post link analysis and optimization tools may need this information in
1074 order to perform correct modifications of executables.  This results
1075 in larger executables.
1077 This option is currently only supported on ELF platforms.
1079 @kindex --force-dynamic
1080 @cindex forcing the creation of dynamic sections
1081 @item --force-dynamic
1082 Force the output file to have dynamic sections.  This option is specific
1083 to VxWorks targets.
1085 @cindex partial link
1086 @cindex relocatable output
1087 @kindex -r
1088 @kindex --relocatable
1089 @item -r
1090 @itemx --relocatable
1091 Generate relocatable output---i.e., generate an output file that can in
1092 turn serve as input to @command{ld}.  This is often called @dfn{partial
1093 linking}.  As a side effect, in environments that support standard Unix
1094 magic numbers, this option also sets the output file's magic number to
1095 @code{OMAGIC}.
1096 @c ; see @option{-N}.
1097 If this option is not specified, an absolute file is produced.  When
1098 linking C++ programs, this option @emph{will not} resolve references to
1099 constructors; to do that, use @samp{-Ur}.
1101 When an input file does not have the same format as the output file,
1102 partial linking is only supported if that input file does not contain any
1103 relocations.  Different output formats can have further restrictions; for
1104 example some @code{a.out}-based formats do not support partial linking
1105 with input files in other formats at all.
1107 This option does the same thing as @samp{-i}.
1109 @kindex -R @var{file}
1110 @kindex --just-symbols=@var{file}
1111 @cindex symbol-only input
1112 @item -R @var{filename}
1113 @itemx --just-symbols=@var{filename}
1114 Read symbol names and their addresses from @var{filename}, but do not
1115 relocate it or include it in the output.  This allows your output file
1116 to refer symbolically to absolute locations of memory defined in other
1117 programs.  You may use this option more than once.
1119 For compatibility with other ELF linkers, if the @option{-R} option is
1120 followed by a directory name, rather than a file name, it is treated as
1121 the @option{-rpath} option.
1123 @kindex -s
1124 @kindex --strip-all
1125 @cindex strip all symbols
1126 @item -s
1127 @itemx --strip-all
1128 Omit all symbol information from the output file.
1130 @kindex -S
1131 @kindex --strip-debug
1132 @cindex strip debugger symbols
1133 @item -S
1134 @itemx --strip-debug
1135 Omit debugger symbol information (but not all symbols) from the output file.
1137 @kindex --strip-discarded
1138 @kindex --no-strip-discarded
1139 @item --strip-discarded
1140 @itemx --no-strip-discarded
1141 Omit (or do not omit) global symbols defined in discarded sections.
1142 Enabled by default.
1144 @kindex -plugin-save-temps
1145 @item -plugin-save-temps
1146 Store the plugin ``temporary'' intermediate files permanently.
1148 @kindex -t
1149 @kindex --trace
1150 @cindex input files, displaying
1151 @item -t
1152 @itemx --trace
1153 Print the names of the input files as @command{ld} processes them.  If
1154 @samp{-t} is given twice then members within archives are also printed.
1155 @samp{-t} output is useful to generate a list of all the object files
1156 and scripts involved in linking, for example, when packaging files for
1157 a linker bug report.
1159 @kindex -T @var{script}
1160 @kindex --script=@var{script}
1161 @cindex script files
1162 @item -T @var{scriptfile}
1163 @itemx --script=@var{scriptfile}
1164 Use @var{scriptfile} as the linker script.  This script replaces
1165 @command{ld}'s default linker script (rather than adding to it),
1166 unless the script contains @code{INSERT}, so
1167 @var{commandfile} must specify everything necessary to describe the
1168 output file.  @xref{Scripts}.  If @var{scriptfile} does not exist in
1169 the current directory, @code{ld} looks for it in the directories
1170 specified by any preceding @samp{-L} options.  Multiple @samp{-T}
1171 options accumulate.
1173 @kindex -dT @var{script}
1174 @kindex --default-script=@var{script}
1175 @cindex script files
1176 @item -dT @var{scriptfile}
1177 @itemx --default-script=@var{scriptfile}
1178 Use @var{scriptfile} as the default linker script.  @xref{Scripts}.
1180 This option is similar to the @option{--script} option except that
1181 processing of the script is delayed until after the rest of the
1182 command line has been processed.  This allows options placed after the
1183 @option{--default-script} option on the command line to affect the
1184 behaviour of the linker script, which can be important when the linker
1185 command line cannot be directly controlled by the user.  (eg because
1186 the command line is being constructed by another tool, such as
1187 @samp{gcc}).
1189 @kindex -u @var{symbol}
1190 @kindex --undefined=@var{symbol}
1191 @cindex undefined symbol
1192 @item -u @var{symbol}
1193 @itemx --undefined=@var{symbol}
1194 Force @var{symbol} to be entered in the output file as an undefined
1195 symbol.  Doing this may, for example, trigger linking of additional
1196 modules from standard libraries.  @samp{-u} may be repeated with
1197 different option arguments to enter additional undefined symbols.  This
1198 option is equivalent to the @code{EXTERN} linker script command.
1200 If this option is being used to force additional modules to be pulled
1201 into the link, and if it is an error for the symbol to remain
1202 undefined, then the option @option{--require-defined} should be used
1203 instead.
1205 @kindex --require-defined=@var{symbol}
1206 @cindex symbols, require defined
1207 @cindex defined symbol
1208 @item --require-defined=@var{symbol}
1209 Require that @var{symbol} is defined in the output file.  This option
1210 is the same as option @option{--undefined} except that if @var{symbol}
1211 is not defined in the output file then the linker will issue an error
1212 and exit.  The same effect can be achieved in a linker script by using
1213 @code{EXTERN}, @code{ASSERT} and @code{DEFINED} together.  This option
1214 can be used multiple times to require additional symbols.
1216 @kindex -Ur
1217 @cindex constructors
1218 @item -Ur
1220 For programs that do not use constructors or destructors, or for ELF
1221 based systems this option is equivalent to @option{-r}:  it generates
1222 relocatable output---i.e., an output file that can in turn serve as
1223 input to @command{ld}.  For other binaries however the @option{-Ur}
1224 option is similar to @option{-r} but it also resolves references to
1225 constructors and destructors.
1227 For those systems where @option{-r} and @option{-Ur} behave
1228 differently, it does not work to use @option{-Ur} on files that were
1229 themselves linked with @option{-Ur}; once the constructor table has
1230 been built, it cannot be added to.  Use @option{-Ur} only for the last
1231 partial link, and @option{-r} for the others.
1233 @kindex --orphan-handling=@var{MODE}
1234 @cindex orphan sections
1235 @cindex sections, orphan
1236 @item --orphan-handling=@var{MODE}
1237 Control how orphan sections are handled.  An orphan section is one not
1238 specifically mentioned in a linker script.  @xref{Orphan Sections}.
1240 @var{MODE} can have any of the following values:
1242 @table @code
1243 @item place
1244 Orphan sections are placed into a suitable output section following
1245 the strategy described in @ref{Orphan Sections}.  The option
1246 @samp{--unique} also affects how sections are placed.
1248 @item discard
1249 All orphan sections are discarded, by placing them in the
1250 @samp{/DISCARD/} section (@pxref{Output Section Discarding}).
1252 @item warn
1253 The linker will place the orphan section as for @code{place} and also
1254 issue a warning.
1256 @item error
1257 The linker will exit with an error if any orphan section is found.
1258 @end table
1260 The default if @samp{--orphan-handling} is not given is @code{place}.
1262 @kindex --unique[=@var{SECTION}]
1263 @item --unique[=@var{SECTION}]
1264 Creates a separate output section for every input section matching
1265 @var{SECTION}, or if the optional wildcard @var{SECTION} argument is
1266 missing, for every orphan input section.  An orphan section is one not
1267 specifically mentioned in a linker script.  You may use this option
1268 multiple times on the command line;  It prevents the normal merging of
1269 input sections with the same name, overriding output section assignments
1270 in a linker script.
1272 @kindex -v
1273 @kindex -V
1274 @kindex --version
1275 @cindex version
1276 @item -v
1277 @itemx --version
1278 @itemx -V
1279 Display the version number for @command{ld}.  The @option{-V} option also
1280 lists the supported emulations.  See also the description of the
1281 @option{--enable-linker-version} in @ref{Options,,Command-line Options}
1282 which can be used to insert the linker version string into a binary.
1284 @kindex -x
1285 @kindex --discard-all
1286 @cindex deleting local symbols
1287 @item -x
1288 @itemx --discard-all
1289 Delete all local symbols.
1291 @kindex -X
1292 @kindex --discard-locals
1293 @cindex local symbols, deleting
1294 @item -X
1295 @itemx --discard-locals
1296 Delete all temporary local symbols.  (These symbols start with
1297 system-specific local label prefixes, typically @samp{.L} for ELF systems
1298 or @samp{L} for traditional a.out systems.)
1300 @kindex -y @var{symbol}
1301 @kindex --trace-symbol=@var{symbol}
1302 @cindex symbol tracing
1303 @item -y @var{symbol}
1304 @itemx --trace-symbol=@var{symbol}
1305 Print the name of each linked file in which @var{symbol} appears.  This
1306 option may be given any number of times.  On many systems it is necessary
1307 to prepend an underscore.
1309 This option is useful when you have an undefined symbol in your link but
1310 don't know where the reference is coming from.
1312 @kindex -Y @var{path}
1313 @item -Y @var{path}
1314 Add @var{path} to the default library search path.  This option exists
1315 for Solaris compatibility.
1317 @kindex -z @var{keyword}
1318 @item -z @var{keyword}
1319 The recognized keywords are:
1320 @table @samp
1322 @item call-nop=prefix-addr
1323 @itemx call-nop=suffix-nop
1324 @itemx call-nop=prefix-@var{byte}
1325 @itemx call-nop=suffix-@var{byte}
1326 Specify the 1-byte @code{NOP} padding when transforming indirect call
1327 to a locally defined function, foo, via its GOT slot.
1328 @option{call-nop=prefix-addr} generates @code{0x67 call foo}.
1329 @option{call-nop=suffix-nop} generates @code{call foo 0x90}.
1330 @option{call-nop=prefix-@var{byte}} generates @code{@var{byte} call foo}.
1331 @option{call-nop=suffix-@var{byte}} generates @code{call foo @var{byte}}.
1332 Supported for i386 and x86_64.
1334 @item cet-report=none
1335 @itemx cet-report=warning
1336 @itemx cet-report=error
1337 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT and
1338 GNU_PROPERTY_X86_FEATURE_1_SHSTK properties in input .note.gnu.property
1339 section.  @option{cet-report=none}, which is the default, will make the
1340 linker not report missing properties in input files.
1341 @option{cet-report=warning} will make the linker issue a warning for
1342 missing properties in input files.  @option{cet-report=error} will make
1343 the linker issue an error for missing properties in input files.
1344 Note that @option{ibt} will turn off the missing
1345 GNU_PROPERTY_X86_FEATURE_1_IBT property report and @option{shstk} will
1346 turn off the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property report.
1347 Supported for Linux/i386 and Linux/x86_64.
1349 @item combreloc
1350 @itemx nocombreloc
1351 Combine multiple dynamic relocation sections and sort to improve
1352 dynamic symbol lookup caching.  Do not do this if @samp{nocombreloc}.
1354 @item common
1355 @itemx nocommon
1356 Generate common symbols with STT_COMMON type during a relocatable
1357 link.  Use STT_OBJECT type if @samp{nocommon}.
1359 @item common-page-size=@var{value}
1360 Set the page size most commonly used to @var{value}.  Memory image
1361 layout will be optimized to minimize memory pages if the system is
1362 using pages of this size.
1364 @item defs
1365 Report unresolved symbol references from regular object files.  This
1366 is done even if the linker is creating a non-symbolic shared library.
1367 This option is the inverse of @samp{-z undefs}.
1369 @item dynamic-undefined-weak
1370 @itemx nodynamic-undefined-weak
1371 Make undefined weak symbols dynamic when building a dynamic object,
1372 if they are referenced from a regular object file and not forced local
1373 by symbol visibility or versioning.  Do not make them dynamic if
1374 @samp{nodynamic-undefined-weak}.  If neither option is given, a target
1375 may default to either option being in force, or make some other
1376 selection of undefined weak symbols dynamic.  Not all targets support
1377 these options.
1379 @item execstack
1380 Marks the object as requiring executable stack.
1382 @item global
1383 This option is only meaningful when building a shared object.  It makes
1384 the symbols defined by this shared object available for symbol resolution
1385 of subsequently loaded libraries.
1387 @item globalaudit
1388 This option is only meaningful when building a dynamic executable.
1389 This option marks the executable as requiring global auditing by
1390 setting the @code{DF_1_GLOBAUDIT} bit in the @code{DT_FLAGS_1} dynamic
1391 tag.  Global auditing requires that any auditing library defined via
1392 the @option{--depaudit} or @option{-P} command-line options be run for
1393 all dynamic objects loaded by the application.
1395 @item ibtplt
1396 Generate Intel Indirect Branch Tracking (IBT) enabled PLT entries.
1397 Supported for Linux/i386 and Linux/x86_64.
1399 @item ibt
1400 Generate GNU_PROPERTY_X86_FEATURE_1_IBT in .note.gnu.property section
1401 to indicate compatibility with IBT.  This also implies @option{ibtplt}.
1402 Supported for Linux/i386 and Linux/x86_64.
1404 @item indirect-extern-access
1405 @itemx noindirect-extern-access
1406 Generate GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS in
1407 .note.gnu.property section to indicate that object file requires
1408 canonical function pointers and cannot be used with copy relocation.
1409 This option also implies @option{noextern-protected-data} and
1410 @option{nocopyreloc}.  Supported for i386 and x86-64.
1412 @option{noindirect-extern-access} removes
1413 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS from .note.gnu.property
1414 section.
1416 @item initfirst
1417 This option is only meaningful when building a shared object.
1418 It marks the object so that its runtime initialization will occur
1419 before the runtime initialization of any other objects brought into
1420 the process at the same time.  Similarly the runtime finalization of
1421 the object will occur after the runtime finalization of any other
1422 objects.
1424 @item interpose
1425 Specify that the dynamic loader should modify its symbol search order
1426 so that symbols in this shared library interpose all other shared
1427 libraries not so marked.
1429 @item unique
1430 @itemx nounique
1431 When generating a shared library or other dynamically loadable ELF
1432 object mark it as one that should (by default) only ever be loaded once,
1433 and only in the main namespace (when using @code{dlmopen}). This is
1434 primarily used to mark fundamental libraries such as libc, libpthread et
1435 al which do not usually function correctly unless they are the sole instances
1436 of themselves. This behaviour can be overridden by the @code{dlmopen} caller
1437 and does not apply to certain loading mechanisms (such as audit libraries).
1439 @item lam-u48
1440 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U48 in .note.gnu.property section
1441 to indicate compatibility with Intel LAM_U48.  Supported for Linux/x86_64.
1443 @item lam-u57
1444 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U57 in .note.gnu.property section
1445 to indicate compatibility with Intel LAM_U57.  Supported for Linux/x86_64.
1447 @item lam-u48-report=none
1448 @itemx lam-u48-report=warning
1449 @itemx lam-u48-report=error
1450 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48
1451 property in input .note.gnu.property section.
1452 @option{lam-u48-report=none}, which is the default, will make the
1453 linker not report missing properties in input files.
1454 @option{lam-u48-report=warning} will make the linker issue a warning for
1455 missing properties in input files.  @option{lam-u48-report=error} will
1456 make the linker issue an error for missing properties in input files.
1457 Supported for Linux/x86_64.
1459 @item lam-u57-report=none
1460 @itemx lam-u57-report=warning
1461 @itemx lam-u57-report=error
1462 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U57
1463 property in input .note.gnu.property section.
1464 @option{lam-u57-report=none}, which is the default, will make the
1465 linker not report missing properties in input files.
1466 @option{lam-u57-report=warning} will make the linker issue a warning for
1467 missing properties in input files.  @option{lam-u57-report=error} will
1468 make the linker issue an error for missing properties in input files.
1469 Supported for Linux/x86_64.
1471 @item lam-report=none
1472 @itemx lam-report=warning
1473 @itemx lam-report=error
1474 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
1475 GNU_PROPERTY_X86_FEATURE_1_LAM_U57 properties in input .note.gnu.property
1476 section.  @option{lam-report=none}, which is the default, will make the
1477 linker not report missing properties in input files.
1478 @option{lam-report=warning} will make the linker issue a warning for
1479 missing properties in input files.  @option{lam-report=error} will make
1480 the linker issue an error for missing properties in input files.
1481 Supported for Linux/x86_64.
1483 @item lazy
1484 When generating an executable or shared library, mark it to tell the
1485 dynamic linker to defer function call resolution to the point when
1486 the function is called (lazy binding), rather than at load time.
1487 Lazy binding is the default.
1489 @item loadfltr
1490 Specify that the object's filters be processed immediately at runtime.
1492 @item max-page-size=@var{value}
1493 Set the maximum memory page size supported to @var{value}.
1495 @item mark-plt
1496 @itemx nomark-plt
1497 Mark PLT entries with dynamic tags, DT_X86_64_PLT, DT_X86_64_PLTSZ and
1498 DT_X86_64_PLTENT.  Since this option stores a non-zero value in the
1499 r_addend field of R_X86_64_JUMP_SLOT relocations, the resulting
1500 executables and shared libraries are incompatible with dynamic linkers,
1501 such as those in older versions of glibc without the change to ignore
1502 r_addend in R_X86_64_GLOB_DAT and R_X86_64_JUMP_SLOT relocations, which
1503 don't ignore the r_addend field of R_X86_64_JUMP_SLOT relocations.
1504 Supported for x86_64.
1506 @item muldefs
1507 Allow multiple definitions.
1509 @item nocopyreloc
1510 Disable linker generated .dynbss variables used in place of variables
1511 defined in shared libraries.  May result in dynamic text relocations.
1513 @item nodefaultlib
1514 Specify that the dynamic loader search for dependencies of this object
1515 should ignore any default library search paths.
1517 @item nodelete
1518 Specify that the object shouldn't be unloaded at runtime.
1520 @item nodlopen
1521 Specify that the object is not available to @code{dlopen}.
1523 @item nodump
1524 Specify that the object can not be dumped by @code{dldump}.
1526 @item noexecstack
1527 Marks the object as not requiring executable stack.
1529 @item noextern-protected-data
1530 Don't treat protected data symbols as external when building a shared
1531 library.  This option overrides the linker backend default.  It can be
1532 used to work around incorrect relocations against protected data symbols
1533 generated by compiler.  Updates on protected data symbols by another
1534 module aren't visible to the resulting shared library.  Supported for
1535 i386 and x86-64.
1537 @item noreloc-overflow
1538 Disable relocation overflow check.  This can be used to disable
1539 relocation overflow check if there will be no dynamic relocation
1540 overflow at run-time.  Supported for x86_64.
1542 @item now
1543 When generating an executable or shared library, mark it to tell the
1544 dynamic linker to resolve all symbols when the program is started, or
1545 when the shared library is loaded by dlopen, instead of deferring
1546 function call resolution to the point when the function is first
1547 called.
1549 @item origin
1550 Specify that the object requires @samp{$ORIGIN} handling in paths.
1552 @item pack-relative-relocs
1553 @itemx nopack-relative-relocs
1554 Generate compact relative relocation in position-independent executable
1555 and shared library.  It adds @code{DT_RELR}, @code{DT_RELRSZ} and
1556 @code{DT_RELRENT} entries to the dynamic section.  It is ignored when
1557 building position-dependent executable and relocatable output.
1558 @option{nopack-relative-relocs} is the default, which disables compact
1559 relative relocation.  When linked against the GNU C Library, a
1560 GLIBC_ABI_DT_RELR symbol version dependency on the shared C Library is
1561 added to the output.  Supported for i386 and x86-64.
1563 @item relro
1564 @itemx norelro
1565 Create an ELF @code{PT_GNU_RELRO} segment header in the object.  This
1566 specifies a memory segment that should be made read-only after
1567 relocation, if supported.  Specifying @samp{common-page-size} smaller
1568 than the system page size will render this protection ineffective.
1569 Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
1571 @item report-relative-reloc
1572 Report dynamic relative relocations generated by linker.  Supported for
1573 Linux/i386 and Linux/x86_64.
1575 @item sectionheader
1576 @itemx nosectionheader
1577 Generate section header.  Don't generate section header if
1578 @samp{nosectionheader} is used.  @option{sectionheader} is the default.
1580 @item separate-code
1581 @itemx noseparate-code
1582 Create separate code @code{PT_LOAD} segment header in the object.  This
1583 specifies a memory segment that should contain only instructions and must
1584 be in wholly disjoint pages from any other data.  Don't create separate
1585 code @code{PT_LOAD} segment if @samp{noseparate-code} is used.
1587 @item shstk
1588 Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
1589 to indicate compatibility with Intel Shadow Stack.  Supported for
1590 Linux/i386 and Linux/x86_64.
1592 @item stack-size=@var{value}
1593 Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
1594 Specifying zero will override any default non-zero sized
1595 @code{PT_GNU_STACK} segment creation.
1597 @item start-stop-gc
1598 @itemx nostart-stop-gc
1599 @cindex start-stop-gc
1600 When @samp{--gc-sections} is in effect, a reference from a retained
1601 section to @code{__start_SECNAME} or @code{__stop_SECNAME} causes all
1602 input sections named @code{SECNAME} to also be retained, if
1603 @code{SECNAME} is representable as a C identifier and either
1604 @code{__start_SECNAME} or @code{__stop_SECNAME} is synthesized by the
1605 linker.  @samp{-z start-stop-gc} disables this effect, allowing
1606 sections to be garbage collected as if the special synthesized symbols
1607 were not defined.  @samp{-z start-stop-gc} has no effect on a
1608 definition of @code{__start_SECNAME} or @code{__stop_SECNAME} in an
1609 object file or linker script.  Such a definition will prevent the
1610 linker providing a synthesized @code{__start_SECNAME} or
1611 @code{__stop_SECNAME} respectively, and therefore the special
1612 treatment by garbage collection for those references.
1614 @item start-stop-visibility=@var{value}
1615 @cindex visibility
1616 @cindex ELF symbol visibility
1617 Specify the ELF symbol visibility for synthesized
1618 @code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input
1619 Section Example}).  @var{value} must be exactly @samp{default},
1620 @samp{internal}, @samp{hidden}, or @samp{protected}.  If no @samp{-z
1621 start-stop-visibility} option is given, @samp{protected} is used for
1622 compatibility with historical practice.  However, it's highly
1623 recommended to use @samp{-z start-stop-visibility=hidden} in new
1624 programs and shared libraries so that these symbols are not exported
1625 between shared objects, which is not usually what's intended.
1627 @item text
1628 @itemx notext
1629 @itemx textoff
1630 Report an error if DT_TEXTREL is set, i.e., if the position-independent
1631 or shared object has dynamic relocations in read-only sections.  Don't
1632 report an error if @samp{notext} or @samp{textoff}.
1634 @item undefs
1635 Do not report unresolved symbol references from regular object files,
1636 either when creating an executable, or when creating a shared library.
1637 This option is the inverse of @samp{-z defs}.
1639 @item unique-symbol
1640 @itemx nounique-symbol
1641 Avoid duplicated local symbol names in the symbol string table.  Append
1642 ".@code{number}" to duplicated local symbol names if @samp{unique-symbol}
1643 is used.  @option{nounique-symbol} is the default.
1645 @item x86-64-baseline
1646 @item x86-64-v2
1647 @item x86-64-v3
1648 @itemx x86-64-v4
1649 Specify the x86-64 ISA level needed in .note.gnu.property section.
1650 @option{x86-64-baseline} generates @code{GNU_PROPERTY_X86_ISA_1_BASELINE}.
1651 @option{x86-64-v2} generates @code{GNU_PROPERTY_X86_ISA_1_V2}.
1652 @option{x86-64-v3} generates @code{GNU_PROPERTY_X86_ISA_1_V3}.
1653 @option{x86-64-v4} generates @code{GNU_PROPERTY_X86_ISA_1_V4}.
1654 Supported for Linux/i386 and Linux/x86_64.
1656 @end table
1658 Other keywords are ignored for Solaris compatibility.
1660 @kindex -(
1661 @cindex groups of archives
1662 @item -( @var{archives} -)
1663 @itemx --start-group @var{archives} --end-group
1664 The @var{archives} should be a list of archive files.  They may be
1665 either explicit file names, or @samp{-l} options.
1667 The specified archives are searched repeatedly until no new undefined
1668 references are created.  Normally, an archive is searched only once in
1669 the order that it is specified on the command line.  If a symbol in that
1670 archive is needed to resolve an undefined symbol referred to by an
1671 object in an archive that appears later on the command line, the linker
1672 would not be able to resolve that reference.  By grouping the archives,
1673 they will all be searched repeatedly until all possible references are
1674 resolved.
1676 Using this option has a significant performance cost.  It is best to use
1677 it only when there are unavoidable circular references between two or
1678 more archives.
1680 @kindex --accept-unknown-input-arch
1681 @kindex --no-accept-unknown-input-arch
1682 @item --accept-unknown-input-arch
1683 @itemx --no-accept-unknown-input-arch
1684 Tells the linker to accept input files whose architecture cannot be
1685 recognised.  The assumption is that the user knows what they are doing
1686 and deliberately wants to link in these unknown input files.  This was
1687 the default behaviour of the linker, before release 2.14.  The default
1688 behaviour from release 2.14 onwards is to reject such input files, and
1689 so the @samp{--accept-unknown-input-arch} option has been added to
1690 restore the old behaviour.
1692 @kindex --as-needed
1693 @kindex --no-as-needed
1694 @item --as-needed
1695 @itemx --no-as-needed
1696 This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
1697 on the command line after the @option{--as-needed} option.  Normally
1698 the linker will add a DT_NEEDED tag for each dynamic library mentioned
1699 on the command line, regardless of whether the library is actually
1700 needed or not.  @option{--as-needed} causes a DT_NEEDED tag to only be
1701 emitted for a library that @emph{at that point in the link} satisfies a
1702 non-weak undefined symbol reference from a regular object file or, if
1703 the library is not found in the DT_NEEDED lists of other needed libraries, a
1704 non-weak undefined symbol reference from another needed dynamic library.
1705 Object files or libraries appearing on the command line @emph{after}
1706 the library in question do not affect whether the library is seen as
1707 needed.  This is similar to the rules for extraction of object files
1708 from archives.  @option{--no-as-needed} restores the default behaviour.
1710 Note: On Linux based systems the @option{--as-needed} option also has
1711 an affect on the behaviour of the @option{--rpath} and
1712 @option{--rpath-link} options.  See the description of
1713 @option{--rpath-link} for more details.
1715 @kindex --add-needed
1716 @kindex --no-add-needed
1717 @item --add-needed
1718 @itemx --no-add-needed
1719 These two options have been deprecated because of the similarity of
1720 their names to the @option{--as-needed} and @option{--no-as-needed}
1721 options.  They have been replaced by @option{--copy-dt-needed-entries}
1722 and @option{--no-copy-dt-needed-entries}.
1724 @kindex -assert @var{keyword}
1725 @item -assert @var{keyword}
1726 This option is ignored for SunOS compatibility.
1728 @kindex -Bdynamic
1729 @kindex -dy
1730 @kindex -call_shared
1731 @item -Bdynamic
1732 @itemx -dy
1733 @itemx -call_shared
1734 Link against dynamic libraries.  This is only meaningful on platforms
1735 for which shared libraries are supported.  This option is normally the
1736 default on such platforms.  The different variants of this option are
1737 for compatibility with various systems.  You may use this option
1738 multiple times on the command line: it affects library searching for
1739 @option{-l} options which follow it.
1741 @kindex -Bgroup
1742 @item -Bgroup
1743 Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
1744 section.  This causes the runtime linker to handle lookups in this
1745 object and its dependencies to be performed only inside the group.
1746 @option{--unresolved-symbols=report-all} is implied.  This option is
1747 only meaningful on ELF platforms which support shared libraries.
1749 @kindex -Bstatic
1750 @kindex -dn
1751 @kindex -non_shared
1752 @kindex -static
1753 @item -Bstatic
1754 @itemx -dn
1755 @itemx -non_shared
1756 @itemx -static
1757 Do not link against shared libraries.  This is only meaningful on
1758 platforms for which shared libraries are supported.  The different
1759 variants of this option are for compatibility with various systems.  You
1760 may use this option multiple times on the command line: it affects
1761 library searching for @option{-l} options which follow it.  This
1762 option also implies @option{--unresolved-symbols=report-all}.  This
1763 option can be used with @option{-shared}.  Doing so means that a
1764 shared library is being created but that all of the library's external
1765 references must be resolved by pulling in entries from static
1766 libraries.
1768 @kindex -Bsymbolic
1769 @item -Bsymbolic
1770 When creating a shared library, bind references to global symbols to the
1771 definition within the shared library, if any.  Normally, it is possible
1772 for a program linked against a shared library to override the definition
1773 within the shared library.  This option is only meaningful on ELF
1774 platforms which support shared libraries.
1776 @kindex -Bsymbolic-functions
1777 @item -Bsymbolic-functions
1778 When creating a shared library, bind references to global function
1779 symbols to the definition within the shared library, if any.
1780 This option is only meaningful on ELF platforms which support shared
1781 libraries.
1783 @kindex -Bno-symbolic
1784 @item -Bno-symbolic
1785 This option can cancel previously specified @samp{-Bsymbolic} and
1786 @samp{-Bsymbolic-functions}.
1788 @kindex --dynamic-list=@var{dynamic-list-file}
1789 @item --dynamic-list=@var{dynamic-list-file}
1790 Specify the name of a dynamic list file to the linker.  This is
1791 typically used when creating shared libraries to specify a list of
1792 global symbols whose references shouldn't be bound to the definition
1793 within the shared library, or creating dynamically linked executables
1794 to specify a list of symbols which should be added to the symbol table
1795 in the executable.  This option is only meaningful on ELF platforms
1796 which support shared libraries.
1798 The format of the dynamic list is the same as the version node without
1799 scope and node name.  See @ref{VERSION} for more information.
1801 @kindex --dynamic-list-data
1802 @item --dynamic-list-data
1803 Include all global data symbols to the dynamic list.
1805 @kindex --dynamic-list-cpp-new
1806 @item --dynamic-list-cpp-new
1807 Provide the builtin dynamic list for C++ operator new and delete.  It
1808 is mainly useful for building shared libstdc++.
1810 @kindex --dynamic-list-cpp-typeinfo
1811 @item --dynamic-list-cpp-typeinfo
1812 Provide the builtin dynamic list for C++ runtime type identification.
1814 @kindex --check-sections
1815 @kindex --no-check-sections
1816 @item --check-sections
1817 @itemx --no-check-sections
1818 Asks the linker @emph{not} to check section addresses after they have
1819 been assigned to see if there are any overlaps.  Normally the linker will
1820 perform this check, and if it finds any overlaps it will produce
1821 suitable error messages.  The linker does know about, and does make
1822 allowances for sections in overlays.  The default behaviour can be
1823 restored by using the command-line switch @option{--check-sections}.
1824 Section overlap is not usually checked for relocatable links.  You can
1825 force checking in that case by using the @option{--check-sections}
1826 option.
1828 @kindex --copy-dt-needed-entries
1829 @kindex --no-copy-dt-needed-entries
1830 @item --copy-dt-needed-entries
1831 @itemx --no-copy-dt-needed-entries
1832 This option affects the treatment of dynamic libraries referred to
1833 by DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
1834 command line.  Normally the linker won't add a DT_NEEDED tag to the
1835 output binary for each library mentioned in a DT_NEEDED tag in an
1836 input dynamic library.  With @option{--copy-dt-needed-entries}
1837 specified on the command line however any dynamic libraries that
1838 follow it will have their DT_NEEDED entries added.  The default
1839 behaviour can be restored with @option{--no-copy-dt-needed-entries}.
1841 This option also has an effect on the resolution of symbols in dynamic
1842 libraries.  With @option{--copy-dt-needed-entries} dynamic libraries
1843 mentioned on the command line will be recursively searched, following
1844 their DT_NEEDED tags to other libraries, in order to resolve symbols
1845 required by the output binary.  With the default setting however
1846 the searching of dynamic libraries that follow it will stop with the
1847 dynamic library itself.  No DT_NEEDED links will be traversed to resolve
1848 symbols.
1850 @cindex cross reference table
1851 @kindex --cref
1852 @item --cref
1853 Output a cross reference table.  If a linker map file is being
1854 generated, the cross reference table is printed to the map file.
1855 Otherwise, it is printed on the standard output.
1857 The format of the table is intentionally simple, so that it may be
1858 easily processed by a script if necessary.  The symbols are printed out,
1859 sorted by name.  For each symbol, a list of file names is given.  If the
1860 symbol is defined, the first file listed is the location of the
1861 definition.  If the symbol is defined as a common value then any files
1862 where this happens appear next.  Finally any files that reference the
1863 symbol are listed.
1865 @cindex ctf variables
1866 @kindex --ctf-variables
1867 @kindex --no-ctf-variables
1868 @item --ctf-variables
1869 @item --no-ctf-variables
1870 The CTF debuginfo format supports a section which encodes the names and
1871 types of variables found in the program which do not appear in any symbol
1872 table. These variables clearly cannot be looked up by address by
1873 conventional debuggers, so the space used for their types and names is
1874 usually wasted: the types are usually small but the names are often not.
1875 @option{--ctf-variables} causes the generation of such a section.
1876 The default behaviour can be restored with @option{--no-ctf-variables}.
1878 @cindex ctf type sharing
1879 @kindex --ctf-share-types
1880 @item --ctf-share-types=@var{method}
1881 Adjust the method used to share types between translation units in CTF.
1883 @table @samp
1884 @item share-unconflicted
1885 Put all types that do not have ambiguous definitions into the shared dictionary,
1886 where debuggers can easily access them, even if they only occur in one
1887 translation unit.  This is the default.
1889 @item share-duplicated
1890 Put only types that occur in multiple translation units into the shared
1891 dictionary: types with only one definition go into per-translation-unit
1892 dictionaries.  Types with ambiguous definitions in multiple translation units
1893 always go into per-translation-unit dictionaries.  This tends to make the CTF
1894 larger, but may reduce the amount of CTF in the shared dictionary.  For very
1895 large projects this may speed up opening the CTF and save memory in the CTF
1896 consumer at runtime.
1897 @end table
1899 @cindex common allocation
1900 @kindex --no-define-common
1901 @item --no-define-common
1902 This option inhibits the assignment of addresses to common symbols.
1903 The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
1904 @xref{Miscellaneous Commands}.
1906 The @samp{--no-define-common} option allows decoupling
1907 the decision to assign addresses to Common symbols from the choice
1908 of the output file type; otherwise a non-Relocatable output type
1909 forces assigning addresses to Common symbols.
1910 Using @samp{--no-define-common} allows Common symbols that are referenced
1911 from a shared library to be assigned addresses only in the main program.
1912 This eliminates the unused duplicate space in the shared library,
1913 and also prevents any possible confusion over resolving to the wrong
1914 duplicate when there are many dynamic modules with specialized search
1915 paths for runtime symbol resolution.
1917 @cindex group allocation in linker script
1918 @cindex section groups
1919 @cindex COMDAT
1920 @kindex --force-group-allocation
1921 @item --force-group-allocation
1922 This option causes the linker to place section group members like
1923 normal input sections, and to delete the section groups.  This is the
1924 default behaviour for a final link but this option can be used to
1925 change the behaviour of a relocatable link (@samp{-r}).  The script
1926 command @code{FORCE_GROUP_ALLOCATION} has the same
1927 effect. @xref{Miscellaneous Commands}.
1929 @cindex symbols, from command line
1930 @kindex --defsym=@var{symbol}=@var{exp}
1931 @item --defsym=@var{symbol}=@var{expression}
1932 Create a global symbol in the output file, containing the absolute
1933 address given by @var{expression}.  You may use this option as many
1934 times as necessary to define multiple symbols in the command line.  A
1935 limited form of arithmetic is supported for the @var{expression} in this
1936 context: you may give a hexadecimal constant or the name of an existing
1937 symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
1938 constants or symbols.  If you need more elaborate expressions, consider
1939 using the linker command language from a script (@pxref{Assignments}).
1940 @emph{Note:} there should be no white space between @var{symbol}, the
1941 equals sign (``@key{=}''), and @var{expression}.
1943 The linker processes @samp{--defsym} arguments and @samp{-T} arguments
1944 in order, placing @samp{--defsym} before @samp{-T} will define the
1945 symbol before the linker script from @samp{-T} is processed, while
1946 placing @samp{--defsym} after @samp{-T} will define the symbol after
1947 the linker script has been processed.  This difference has
1948 consequences for expressions within the linker script that use the
1949 @samp{--defsym} symbols, which order is correct will depend on what
1950 you are trying to achieve.
1952 @cindex demangling, from command line
1953 @kindex --demangle[=@var{style}]
1954 @kindex --no-demangle
1955 @item --demangle[=@var{style}]
1956 @itemx --no-demangle
1957 These options control whether to demangle symbol names in error messages
1958 and other output.  When the linker is told to demangle, it tries to
1959 present symbol names in a readable fashion: it strips leading
1960 underscores if they are used by the object file format, and converts C++
1961 mangled symbol names into user readable names.  Different compilers have
1962 different mangling styles.  The optional demangling style argument can be used
1963 to choose an appropriate demangling style for your compiler.  The linker will
1964 demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
1965 is set.  These options may be used to override the default.
1967 @cindex dynamic linker, from command line
1968 @kindex -I@var{file}
1969 @kindex --dynamic-linker=@var{file}
1970 @item -I@var{file}
1971 @itemx --dynamic-linker=@var{file}
1972 Set the name of the dynamic linker.  This is only meaningful when
1973 generating dynamically linked ELF executables.  The default dynamic
1974 linker is normally correct; don't use this unless you know what you are
1975 doing.
1977 @kindex --no-dynamic-linker
1978 @item --no-dynamic-linker
1979 When producing an executable file, omit the request for a dynamic
1980 linker to be used at load-time.  This is only meaningful for ELF
1981 executables that contain dynamic relocations, and usually requires
1982 entry point code that is capable of processing these relocations.
1984 @kindex --embedded-relocs
1985 @item --embedded-relocs
1986 This option is similar to the @option{--emit-relocs} option except
1987 that the relocs are stored in a target-specific section.  This option
1988 is only supported by the @samp{BFIN}, @samp{CR16} and @emph{M68K}
1989 targets.
1991 @kindex --disable-multiple-abs-defs
1992 @item --disable-multiple-abs-defs
1993 Do not allow multiple definitions with symbols included
1994 in filename invoked by -R or --just-symbols
1996 @kindex --fatal-warnings
1997 @kindex --no-fatal-warnings
1998 @item --fatal-warnings
1999 @itemx --no-fatal-warnings
2000 Treat all warnings as errors.  The default behaviour can be restored
2001 with the option @option{--no-fatal-warnings}.
2003 @kindex -w
2004 @kindex --no-warnings
2005 @item -w
2006 @itemx --no-warnings
2007 Do not display any warning or error messages.  This overrides
2008 @option{--fatal-warnings} if it has been enabled.  This option can be
2009 used when it is known that the output binary will not work, but there
2010 is still a need to create it.
2012 @kindex --force-exe-suffix
2013 @item  --force-exe-suffix
2014 Make sure that an output file has a .exe suffix.
2016 If a successfully built fully linked output file does not have a
2017 @code{.exe} or @code{.dll} suffix, this option forces the linker to copy
2018 the output file to one of the same name with a @code{.exe} suffix. This
2019 option is useful when using unmodified Unix makefiles on a Microsoft
2020 Windows host, since some versions of Windows won't run an image unless
2021 it ends in a @code{.exe} suffix.
2023 @kindex --gc-sections
2024 @kindex --no-gc-sections
2025 @cindex garbage collection
2026 @item --gc-sections
2027 @itemx --no-gc-sections
2028 Enable garbage collection of unused input sections.  It is ignored on
2029 targets that do not support this option.  The default behaviour (of not
2030 performing this garbage collection) can be restored by specifying
2031 @samp{--no-gc-sections} on the command line.  Note that garbage
2032 collection for COFF and PE format targets is supported, but the
2033 implementation is currently considered to be experimental.
2035 @samp{--gc-sections} decides which input sections are used by
2036 examining symbols and relocations.  The section containing the entry
2037 symbol and all sections containing symbols undefined on the
2038 command-line will be kept, as will sections containing symbols
2039 referenced by dynamic objects.  Note that when building shared
2040 libraries, the linker must assume that any visible symbol is
2041 referenced.  Once this initial set of sections has been determined,
2042 the linker recursively marks as used any section referenced by their
2043 relocations.  See @samp{--entry}, @samp{--undefined}, and
2044 @samp{--gc-keep-exported}.
2046 This option can be set when doing a partial link (enabled with option
2047 @samp{-r}).  In this case the root of symbols kept must be explicitly
2048 specified either by one of the options @samp{--entry},
2049 @samp{--undefined}, or @samp{--gc-keep-exported} or by a @code{ENTRY}
2050 command in the linker script.
2052 As a GNU extension, ELF input sections marked with the
2053 @code{SHF_GNU_RETAIN} flag will not be garbage collected.
2055 @kindex --print-gc-sections
2056 @kindex --no-print-gc-sections
2057 @cindex garbage collection
2058 @item --print-gc-sections
2059 @itemx --no-print-gc-sections
2060 List all sections removed by garbage collection.  The listing is
2061 printed on stderr.  This option is only effective if garbage
2062 collection has been enabled via the @samp{--gc-sections}) option.  The
2063 default behaviour (of not listing the sections that are removed) can
2064 be restored by specifying @samp{--no-print-gc-sections} on the command
2065 line.
2067 @kindex --gc-keep-exported
2068 @cindex garbage collection
2069 @item --gc-keep-exported
2070 When @samp{--gc-sections} is enabled, this option prevents garbage
2071 collection of unused input sections that contain global symbols having
2072 default or protected visibility.  This option is intended to be used for
2073 executables where unreferenced sections would otherwise be garbage
2074 collected regardless of the external visibility of contained symbols.
2075 Note that this option has no effect when linking shared objects since
2076 it is already the default behaviour.  This option is only supported for
2077 ELF format targets.
2079 @kindex --print-output-format
2080 @cindex output format
2081 @item --print-output-format
2082 Print the name of the default output format (perhaps influenced by
2083 other command-line options).  This is the string that would appear
2084 in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
2086 @kindex --print-memory-usage
2087 @cindex memory usage
2088 @item --print-memory-usage
2089 Print used size, total size and used size of memory regions created with
2090 the @ref{MEMORY} command.  This is useful on embedded targets to have a
2091 quick view of amount of free memory.  The format of the output has one
2092 headline and one line per region.  It is both human readable and easily
2093 parsable by tools.  Here is an example of an output:
2095 @smallexample
2096 Memory region         Used Size  Region Size  %age Used
2097              ROM:        256 KB         1 MB     25.00%
2098              RAM:          32 B         2 GB      0.00%
2099 @end smallexample
2101 @cindex help
2102 @cindex usage
2103 @kindex --help
2104 @item --help
2105 Print a summary of the command-line options on the standard output and exit.
2107 @kindex --target-help
2108 @item --target-help
2109 Print a summary of all target-specific options on the standard output and exit.
2111 @kindex -Map=@var{mapfile}
2112 @item -Map=@var{mapfile}
2113 Print a link map to the file @var{mapfile}.  See the description of the
2114 @option{-M} option, above.  If @var{mapfile} is just the character
2115 @code{-} then the map will be written to stdout.
2117 Specifying a directory as @var{mapfile} causes the linker map to be
2118 written as a file inside the directory.  Normally name of the file
2119 inside the directory is computed as the basename of the @var{output}
2120 file with @code{.map} appended.   If however the special character
2121 @code{%} is used then this will be replaced by the full path of the
2122 output file.  Additionally if there are any characters after the
2123 @var{%} symbol then @code{.map} will no longer be appended.
2125 @smallexample
2126  -o foo.exe -Map=bar                  [Creates ./bar]
2127  -o ../dir/foo.exe -Map=bar           [Creates ./bar]
2128  -o foo.exe -Map=../dir               [Creates ../dir/foo.exe.map]
2129  -o ../dir2/foo.exe -Map=../dir       [Creates ../dir/foo.exe.map]
2130  -o foo.exe -Map=%                    [Creates ./foo.exe.map]
2131  -o ../dir/foo.exe -Map=%             [Creates ../dir/foo.exe.map]
2132  -o foo.exe -Map=%.bar                [Creates ./foo.exe.bar]
2133  -o ../dir/foo.exe -Map=%.bar         [Creates ../dir/foo.exe.bar]
2134  -o ../dir2/foo.exe -Map=../dir/%     [Creates ../dir/../dir2/foo.exe.map]
2135  -o ../dir2/foo.exe -Map=../dir/%.bar [Creates ../dir/../dir2/foo.exe.bar]
2136 @end smallexample
2138 It is an error to specify more than one @code{%} character.
2140 If the map file already exists then it will be overwritten by this
2141 operation.
2143 @cindex memory usage
2144 @kindex --no-keep-memory
2145 @item --no-keep-memory
2146 @command{ld} normally optimizes for speed over memory usage by caching the
2147 symbol tables of input files in memory.  This option tells @command{ld} to
2148 instead optimize for memory usage, by rereading the symbol tables as
2149 necessary.  This may be required if @command{ld} runs out of memory space
2150 while linking a large executable.
2152 @kindex --no-undefined
2153 @kindex -z defs
2154 @kindex -z undefs
2155 @item --no-undefined
2156 @itemx -z defs
2157 Report unresolved symbol references from regular object files.  This
2158 is done even if the linker is creating a non-symbolic shared library.
2159 The switch @option{--[no-]allow-shlib-undefined} controls the
2160 behaviour for reporting unresolved references found in shared
2161 libraries being linked in.
2163 The effects of this option can be reverted by using @code{-z undefs}.
2165 @kindex --allow-multiple-definition
2166 @kindex -z muldefs
2167 @item --allow-multiple-definition
2168 @itemx -z muldefs
2169 Normally when a symbol is defined multiple times, the linker will
2170 report a fatal error. These options allow multiple definitions and the
2171 first definition will be used.
2173 @kindex --allow-shlib-undefined
2174 @kindex --no-allow-shlib-undefined
2175 @item --allow-shlib-undefined
2176 @itemx --no-allow-shlib-undefined
2177 Allows or disallows undefined symbols in shared libraries.
2178 This switch is similar to @option{--no-undefined} except that it
2179 determines the behaviour when the undefined symbols are in a
2180 shared library rather than a regular object file.  It does not affect
2181 how undefined symbols in regular object files are handled.
2183 The default behaviour is to report errors for any undefined symbols
2184 referenced in shared libraries if the linker is being used to create
2185 an executable, but to allow them if the linker is being used to create
2186 a shared library.
2188 The reasons for allowing undefined symbol references in shared
2189 libraries specified at link time are that:
2191 @itemize @bullet
2192 @item
2193 A shared library specified at link time may not be the same as the one
2194 that is available at load time, so the symbol might actually be
2195 resolvable at load time.
2196 @item
2197 There are some operating systems, eg BeOS and HPPA, where undefined
2198 symbols in shared libraries are normal.
2200 The BeOS kernel for example patches shared libraries at load time to
2201 select whichever function is most appropriate for the current
2202 architecture.  This is used, for example, to dynamically select an
2203 appropriate memset function.
2204 @end itemize
2206 @kindex --error-handling-script=@var{scriptname}
2207 @item --error-handling-script=@var{scriptname}
2208 If this option is provided then the linker will invoke
2209 @var{scriptname} whenever an error is encountered.  Currently however
2210 only two kinds of error are supported: missing symbols and missing
2211 libraries.  Two arguments will be passed to script: the keyword
2212 ``undefined-symbol'' or `missing-lib'' and the @var{name} of the
2213 undefined symbol or missing library.  The intention is that the script
2214 will provide suggestions to the user as to where the symbol or library
2215 might be found.  After the script has finished then the normal linker
2216 error message will be displayed.
2218 The availability of this option is controlled by a configure time
2219 switch, so it may not be present in specific implementations.
2221 @kindex --no-undefined-version
2222 @item --no-undefined-version
2223 Normally when a symbol has an undefined version, the linker will ignore
2224 it. This option disallows symbols with undefined version and a fatal error
2225 will be issued instead.
2227 @kindex --default-symver
2228 @item --default-symver
2229 Create and use a default symbol version (the soname) for unversioned
2230 exported symbols.
2232 @kindex --default-imported-symver
2233 @item --default-imported-symver
2234 Create and use a default symbol version (the soname) for unversioned
2235 imported symbols.
2237 @kindex --no-warn-mismatch
2238 @item --no-warn-mismatch
2239 Normally @command{ld} will give an error if you try to link together input
2240 files that are mismatched for some reason, perhaps because they have
2241 been compiled for different processors or for different endiannesses.
2242 This option tells @command{ld} that it should silently permit such possible
2243 errors.  This option should only be used with care, in cases when you
2244 have taken some special action that ensures that the linker errors are
2245 inappropriate.
2247 @kindex --no-warn-search-mismatch
2248 @item --no-warn-search-mismatch
2249 Normally @command{ld} will give a warning if it finds an incompatible
2250 library during a library search.  This option silences the warning.
2252 @kindex --no-whole-archive
2253 @item --no-whole-archive
2254 Turn off the effect of the @option{--whole-archive} option for subsequent
2255 archive files.
2257 @cindex output file after errors
2258 @kindex --noinhibit-exec
2259 @item --noinhibit-exec
2260 Retain the executable output file whenever it is still usable.
2261 Normally, the linker will not produce an output file if it encounters
2262 errors during the link process; it exits without writing an output file
2263 when it issues any error whatsoever.
2265 @kindex -nostdlib
2266 @item -nostdlib
2267 Only search library directories explicitly specified on the
2268 command line.  Library directories specified in linker scripts
2269 (including linker scripts specified on the command line) are ignored.
2271 @ifclear SingleFormat
2272 @kindex --oformat=@var{output-format}
2273 @item --oformat=@var{output-format}
2274 @command{ld} may be configured to support more than one kind of object
2275 file.  If your @command{ld} is configured this way, you can use the
2276 @samp{--oformat} option to specify the binary format for the output
2277 object file.  Even when @command{ld} is configured to support alternative
2278 object formats, you don't usually need to specify this, as @command{ld}
2279 should be configured to produce as a default output format the most
2280 usual format on each machine.  @var{output-format} is a text string, the
2281 name of a particular format supported by the BFD libraries.  (You can
2282 list the available binary formats with @samp{objdump -i}.)  The script
2283 command @code{OUTPUT_FORMAT} can also specify the output format, but
2284 this option overrides it.  @xref{BFD}.
2285 @end ifclear
2287 @kindex --out-implib
2288 @item --out-implib @var{file}
2289 Create an import library in @var{file} corresponding to the executable
2290 the linker is generating (eg. a DLL or ELF program).  This import
2291 library (which should be called @code{*.dll.a} or @code{*.a} for DLLs)
2292 may be used to link clients against the generated executable; this
2293 behaviour makes it possible to skip a separate import library creation
2294 step (eg. @code{dlltool} for DLLs).  This option is only available for
2295 the i386 PE and ELF targetted ports of the linker.
2297 @kindex -pie
2298 @kindex --pic-executable
2299 @item -pie
2300 @itemx --pic-executable
2301 @cindex position independent executables
2302 Create a position independent executable.  This is currently only
2303 supported on ELF platforms.  Position independent executables are
2304 relocated by the dynamic linker to the virtual address the OS chooses
2305 for them, which can vary between invocations.  They are marked ET_DYN
2306 in the ELF file header, but differ from shared libraries in a number
2307 of ways.  In particular, defined symbols in a PIE by default can not
2308 be overridden by another object as they can be in a shared library.
2310 @kindex -no-pie
2311 @item -no-pie
2312 @cindex position dependent executables
2313 Create a position dependent executable.  This is the default.
2315 @kindex -qmagic
2316 @item -qmagic
2317 This option is ignored for Linux compatibility.
2319 @kindex -Qy
2320 @item -Qy
2321 This option is ignored for SVR4 compatibility.
2323 @kindex --relax
2324 @cindex synthesizing linker
2325 @cindex relaxing addressing modes
2326 @cindex --no-relax
2327 @item --relax
2328 @itemx --no-relax
2329 An option with machine dependent effects.
2330 @ifset GENERIC
2331 This option is only supported on a few targets.
2332 @end ifset
2333 @ifset H8300
2334 @xref{H8/300,,@command{ld} and the H8/300}.
2335 @end ifset
2336 @ifset XTENSA
2337 @xref{Xtensa,, @command{ld} and Xtensa Processors}.
2338 @end ifset
2339 @ifset M68HC11
2340 @xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
2341 @end ifset
2342 @ifset NIOSII
2343 @xref{Nios II,,@command{ld} and the Altera Nios II}.
2344 @end ifset
2345 @ifset POWERPC
2346 @xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}.
2347 @end ifset
2349 On some platforms the @option{--relax} option performs target specific,
2350 global optimizations that become possible when the linker resolves
2351 addressing in the program, such as relaxing address modes,
2352 synthesizing new instructions, selecting shorter version of current
2353 instructions, and combining constant values.
2355 On some platforms these link time global optimizations may make symbolic
2356 debugging of the resulting executable impossible.
2357 @ifset GENERIC
2358 This is known to be the case for the Matsushita MN10200 and MN10300
2359 family of processors.
2360 @end ifset
2362 On platforms where the feature is supported, the option
2363 @option{--no-relax} will disable it.
2365 On platforms where the feature is not supported, both @option{--relax}
2366 and @option{--no-relax} are accepted, but ignored.
2368 @cindex retaining specified symbols
2369 @cindex stripping all but some symbols
2370 @cindex symbols, retaining selectively
2371 @kindex --retain-symbols-file=@var{filename}
2372 @item --retain-symbols-file=@var{filename}
2373 Retain @emph{only} the symbols listed in the file @var{filename},
2374 discarding all others.  @var{filename} is simply a flat file, with one
2375 symbol name per line.  This option is especially useful in environments
2376 @ifset GENERIC
2377 (such as VxWorks)
2378 @end ifset
2379 where a large global symbol table is accumulated gradually, to conserve
2380 run-time memory.
2382 @samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
2383 or symbols needed for relocations.
2385 You may only specify @samp{--retain-symbols-file} once in the command
2386 line.  It overrides @samp{-s} and @samp{-S}.
2388 @ifset GENERIC
2389 @item -rpath=@var{dir}
2390 @cindex runtime library search path
2391 @kindex -rpath=@var{dir}
2392 Add a directory to the runtime library search path.  This is used when
2393 linking an ELF executable with shared objects.  All @option{-rpath}
2394 arguments are concatenated and passed to the runtime linker, which uses
2395 them to locate shared objects at runtime.
2397 The @option{-rpath} option is also used when locating shared objects which
2398 are needed by shared objects explicitly included in the link; see the
2399 description of the @option{-rpath-link} option.  Searching @option{-rpath}
2400 in this way is only supported by native linkers and cross linkers which
2401 have been configured with the @option{--with-sysroot} option.
2403 If @option{-rpath} is not used when linking an ELF executable, the
2404 contents of the environment variable @code{LD_RUN_PATH} will be used if it
2405 is defined.
2407 The @option{-rpath} option may also be used on SunOS.  By default, on
2408 SunOS, the linker will form a runtime search path out of all the
2409 @option{-L} options it is given.  If a @option{-rpath} option is used, the
2410 runtime search path will be formed exclusively using the @option{-rpath}
2411 options, ignoring the @option{-L} options.  This can be useful when using
2412 gcc, which adds many @option{-L} options which may be on NFS mounted
2413 file systems.
2415 For compatibility with other ELF linkers, if the @option{-R} option is
2416 followed by a directory name, rather than a file name, it is treated as
2417 the @option{-rpath} option.
2418 @end ifset
2420 @ifset GENERIC
2421 @cindex link-time runtime library search path
2422 @kindex -rpath-link=@var{dir}
2423 @item -rpath-link=@var{dir}
2424 When using ELF or SunOS, one shared library may require another.  This
2425 happens when an @code{ld -shared} link includes a shared library as one
2426 of the input files.
2428 When the linker encounters such a dependency when doing a non-shared,
2429 non-relocatable link, it will automatically try to locate the required
2430 shared library and include it in the link, if it is not included
2431 explicitly.  In such a case, several directories are searched as
2432 described below.  The @option{-rpath-link} option specifies the first
2433 set of directories to search.  This option may specify a sequence of
2434 directory names either by providing a list of names separated by
2435 colons, or by appearing multiple times.
2437 The tokens @var{$ORIGIN} and @var{$LIB} can appear in these search
2438 directories.  They will be replaced by the full path to the directory
2439 containing the program or shared object in the case of @var{$ORIGIN}
2440 and either @samp{lib} - for 32-bit binaries - or @samp{lib64} - for
2441 64-bit binaries - in the case of @var{$LIB}.
2443 The alternative form of these tokens - @var{$@{ORIGIN@}} and
2444 @var{$@{LIB@}} can also be used.  The token @var{$PLATFORM} is not
2445 supported.
2447 The @option{--rpath-link} option should be used with caution as it
2448 overrides the search path that may have been hard compiled into a
2449 shared library.  In such a case it is possible to unintentionally use
2450 a different search path than the runtime linker would have used.
2452 When additional shared libraries are required, the linker will search
2453 directories in the order listed below in order to find them.  Note
2454 however that this only applies to additional libraries needed to
2455 satisfy already included shared libraries.  It does @emph{not}
2456 apply to libraries that are included via the @option{-l} command line
2457 option.  Searches for @option{-l} libraries are only conducted in
2458 directories specified by the @option{-L} option (@xref{-L}).
2460 @enumerate
2461 @item
2462 Any directories specified by @option{-rpath-link} options.
2463 @item
2464 Any directories specified by @option{-rpath} options.  The difference
2465 between @option{-rpath} and @option{-rpath-link} is that directories
2466 specified by @option{-rpath} options are included in the executable and
2467 used at runtime, whereas the @option{-rpath-link} option is only effective
2468 at link time. Searching @option{-rpath} in this way is only supported
2469 by native linkers and cross linkers which have been configured with
2470 the @option{--with-sysroot} option.
2471 @item
2472 On an ELF system, for native linkers, if the @option{-rpath} and
2473 @option{-rpath-link} options were not used, search the contents of the
2474 environment variable @code{LD_RUN_PATH}.
2475 @item
2476 On SunOS, if the @option{-rpath} option was not used, search any
2477 directories specified using @option{-L} options.
2478 @item
2479 For a native linker, search the contents of the environment
2480 variable @code{LD_LIBRARY_PATH}.
2481 @item
2482 For a native ELF linker, the directories in @code{DT_RUNPATH} or
2483 @code{DT_RPATH} of a shared library are searched for shared
2484 libraries needed by it. The @code{DT_RPATH} entries are ignored if
2485 @code{DT_RUNPATH} entries exist.
2486 @item
2487 For a linker for a Linux system, if the file @file{/etc/ld.so.conf}
2488 exists, the list of directories found in that file.  Note: the path
2489 to this file is prefixed with the @code{sysroot} value, if that is
2490 defined, and then any @code{prefix} string if the linker was
2491 configured with the @command{--prefix=<path>} option.
2492 @item
2493 For a native linker on a FreeBSD system, any directories specified by
2494 the @code{_PATH_ELF_HINTS} macro defined in the @file{elf-hints.h}
2495 header file.
2496 @item
2497 Any directories specified by a @code{SEARCH_DIR} command in a
2498 linker script given on the command line, including scripts specified
2499 by @option{-T} (but not @option{-dT}).
2500 @item
2501 The default directories, normally @file{/lib} and @file{/usr/lib}.
2502 @item
2503 Any directories specified by a plugin LDPT_SET_EXTRA_LIBRARY_PATH.
2504 @item
2505 Any directories specified by a @code{SEARCH_DIR} command in a default
2506 linker script.
2507 @end enumerate
2509 Note however on Linux based systems there is an additional caveat:  If
2510 the @option{--as-needed} option is active @emph{and} a shared library
2511 is located which would normally satisfy the search @emph{and} this
2512 library does not have DT_NEEDED tag for @file{libc.so}
2513 @emph{and} there is a shared library later on in the set of search
2514 directories which also satisfies the search @emph{and}
2515 this second shared library does have a DT_NEEDED tag for
2516 @file{libc.so} @emph{then} the second library will be selected instead
2517 of the first.
2519 If the required shared library is not found, the linker will issue a
2520 warning and continue with the link.
2522 @end ifset
2524 @kindex -shared
2525 @kindex -Bshareable
2526 @item -shared
2527 @itemx -Bshareable
2528 @cindex shared libraries
2529 Create a shared library.  This is currently only supported on ELF, XCOFF
2530 and SunOS platforms.  On SunOS, the linker will automatically create a
2531 shared library if the @option{-e} option is not used and there are
2532 undefined symbols in the link.
2534 @kindex --sort-common
2535 @item --sort-common
2536 @itemx --sort-common=ascending
2537 @itemx --sort-common=descending
2538 This option tells @command{ld} to sort the common symbols by alignment in
2539 ascending or descending order when it places them in the appropriate output
2540 sections.  The symbol alignments considered are sixteen-byte or larger,
2541 eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
2542 between symbols due to alignment constraints.  If no sorting order is
2543 specified, then descending order is assumed.
2545 @kindex --sort-section=name
2546 @item --sort-section=name
2547 This option will apply @code{SORT_BY_NAME} to all wildcard section
2548 patterns in the linker script.
2550 @kindex --sort-section=alignment
2551 @item --sort-section=alignment
2552 This option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
2553 patterns in the linker script.
2555 @kindex --spare-dynamic-tags
2556 @item --spare-dynamic-tags=@var{count}
2557 This option specifies the number of empty slots to leave in the
2558 .dynamic section of ELF shared objects.  Empty slots may be needed by
2559 post processing tools, such as the prelinker.  The default is 5.
2561 @kindex --split-by-file
2562 @item --split-by-file[=@var{size}]
2563 Similar to @option{--split-by-reloc} but creates a new output section for
2564 each input file when @var{size} is reached.  @var{size} defaults to a
2565 size of 1 if not given.
2567 @kindex --split-by-reloc
2568 @item --split-by-reloc[=@var{count}]
2569 Tries to creates extra sections in the output file so that no single
2570 output section in the file contains more than @var{count} relocations.
2571 This is useful when generating huge relocatable files for downloading into
2572 certain real time kernels with the COFF object file format; since COFF
2573 cannot represent more than 65535 relocations in a single section.  Note
2574 that this will fail to work with object file formats which do not
2575 support arbitrary sections.  The linker will not split up individual
2576 input sections for redistribution, so if a single input section contains
2577 more than @var{count} relocations one output section will contain that
2578 many relocations.  @var{count} defaults to a value of 32768.
2580 @kindex --stats
2581 @item --stats
2582 Compute and display statistics about the operation of the linker, such
2583 as execution time and memory usage.
2585 @kindex --sysroot=@var{directory}
2586 @item --sysroot=@var{directory}
2587 Use @var{directory} as the location of the sysroot, overriding the
2588 configure-time default.  This option is only supported by linkers
2589 that were configured using @option{--with-sysroot}.
2591 @kindex --task-link
2592 @item --task-link
2593 This is used by COFF/PE based targets to create a task-linked object
2594 file where all of the global symbols have been converted to statics.
2596 @kindex --traditional-format
2597 @cindex traditional format
2598 @item --traditional-format
2599 For some targets, the output of @command{ld} is different in some ways from
2600 the output of some existing linker.  This switch requests @command{ld} to
2601 use the traditional format instead.
2603 @cindex dbx
2604 For example, on SunOS, @command{ld} combines duplicate entries in the
2605 symbol string table.  This can reduce the size of an output file with
2606 full debugging information by over 30 percent.  Unfortunately, the SunOS
2607 @code{dbx} program can not read the resulting program (@code{gdb} has no
2608 trouble).  The @samp{--traditional-format} switch tells @command{ld} to not
2609 combine duplicate entries.
2611 @kindex --section-start=@var{sectionname}=@var{org}
2612 @item --section-start=@var{sectionname}=@var{org}
2613 Locate a section in the output file at the absolute
2614 address given by @var{org}.  You may use this option as many
2615 times as necessary to locate multiple sections in the command
2616 line.
2617 @var{org} must be a single hexadecimal integer;
2618 for compatibility with other linkers, you may omit the leading
2619 @samp{0x} usually associated with hexadecimal values.  @emph{Note:} there
2620 should be no white space between @var{sectionname}, the equals
2621 sign (``@key{=}''), and @var{org}.
2623 @kindex -Tbss=@var{org}
2624 @kindex -Tdata=@var{org}
2625 @kindex -Ttext=@var{org}
2626 @cindex segment origins, cmd line
2627 @item -Tbss=@var{org}
2628 @itemx -Tdata=@var{org}
2629 @itemx -Ttext=@var{org}
2630 Same as @option{--section-start}, with @code{.bss}, @code{.data} or
2631 @code{.text} as the @var{sectionname}.
2633 @kindex -Ttext-segment=@var{org}
2634 @item -Ttext-segment=@var{org}
2635 @cindex text segment origin, cmd line
2636 When creating an ELF executable, it will set the address of the first
2637 byte of the text segment.
2639 @kindex -Trodata-segment=@var{org}
2640 @item -Trodata-segment=@var{org}
2641 @cindex rodata segment origin, cmd line
2642 When creating an ELF executable or shared object for a target where
2643 the read-only data is in its own segment separate from the executable
2644 text, it will set the address of the first byte of the read-only data segment.
2646 @kindex -Tldata-segment=@var{org}
2647 @item -Tldata-segment=@var{org}
2648 @cindex ldata segment origin, cmd line
2649 When creating an ELF executable or shared object for x86-64 medium memory
2650 model, it will set the address of the first byte of the ldata segment.
2652 @kindex --unresolved-symbols
2653 @item --unresolved-symbols=@var{method}
2654 Determine how to handle unresolved symbols.  There are four possible
2655 values for @samp{method}:
2657 @table @samp
2658 @item ignore-all
2659 Do not report any unresolved symbols.
2661 @item report-all
2662 Report all unresolved symbols.  This is the default.
2664 @item ignore-in-object-files
2665 Report unresolved symbols that are contained in shared libraries, but
2666 ignore them if they come from regular object files.
2668 @item ignore-in-shared-libs
2669 Report unresolved symbols that come from regular object files, but
2670 ignore them if they come from shared libraries.  This can be useful
2671 when creating a dynamic binary and it is known that all the shared
2672 libraries that it should be referencing are included on the linker's
2673 command line.
2674 @end table
2676 The behaviour for shared libraries on their own can also be controlled
2677 by the @option{--[no-]allow-shlib-undefined} option.
2679 Normally the linker will generate an error message for each reported
2680 unresolved symbol but the option @option{--warn-unresolved-symbols}
2681 can change this to a warning.
2683 @kindex --verbose[=@var{NUMBER}]
2684 @cindex verbose[=@var{NUMBER}]
2685 @item --dll-verbose
2686 @itemx --verbose[=@var{NUMBER}]
2687 Display the version number for @command{ld} and list the linker emulations
2688 supported.  Display which input files can and cannot be opened.  Display
2689 the linker script being used by the linker. If the optional @var{NUMBER}
2690 argument > 1, plugin symbol status will also be displayed.
2692 @kindex --version-script=@var{version-scriptfile}
2693 @cindex version script, symbol versions
2694 @item --version-script=@var{version-scriptfile}
2695 Specify the name of a version script to the linker.  This is typically
2696 used when creating shared libraries to specify additional information
2697 about the version hierarchy for the library being created.  This option
2698 is only fully supported on ELF platforms which support shared libraries;
2699 see @ref{VERSION}.  It is partially supported on PE platforms, which can
2700 use version scripts to filter symbol visibility in auto-export mode: any
2701 symbols marked @samp{local} in the version script will not be exported.
2702 @xref{WIN32}.
2704 @kindex --warn-common
2705 @cindex warnings, on combining symbols
2706 @cindex combining symbols, warnings on
2707 @item --warn-common
2708 Warn when a common symbol is combined with another common symbol or with
2709 a symbol definition.  Unix linkers allow this somewhat sloppy practice,
2710 but linkers on some other operating systems do not.  This option allows
2711 you to find potential problems from combining global symbols.
2712 Unfortunately, some C libraries use this practice, so you may get some
2713 warnings about symbols in the libraries as well as in your programs.
2715 There are three kinds of global symbols, illustrated here by C examples:
2717 @table @samp
2718 @item int i = 1;
2719 A definition, which goes in the initialized data section of the output
2720 file.
2722 @item extern int i;
2723 An undefined reference, which does not allocate space.
2724 There must be either a definition or a common symbol for the
2725 variable somewhere.
2727 @item int i;
2728 A common symbol.  If there are only (one or more) common symbols for a
2729 variable, it goes in the uninitialized data area of the output file.
2730 The linker merges multiple common symbols for the same variable into a
2731 single symbol.  If they are of different sizes, it picks the largest
2732 size.  The linker turns a common symbol into a declaration, if there is
2733 a definition of the same variable.
2734 @end table
2736 The @samp{--warn-common} option can produce five kinds of warnings.
2737 Each warning consists of a pair of lines: the first describes the symbol
2738 just encountered, and the second describes the previous symbol
2739 encountered with the same name.  One or both of the two symbols will be
2740 a common symbol.
2742 @enumerate
2743 @item
2744 Turning a common symbol into a reference, because there is already a
2745 definition for the symbol.
2746 @smallexample
2747 @var{file}(@var{section}): warning: common of `@var{symbol}'
2748    overridden by definition
2749 @var{file}(@var{section}): warning: defined here
2750 @end smallexample
2752 @item
2753 Turning a common symbol into a reference, because a later definition for
2754 the symbol is encountered.  This is the same as the previous case,
2755 except that the symbols are encountered in a different order.
2756 @smallexample
2757 @var{file}(@var{section}): warning: definition of `@var{symbol}'
2758    overriding common
2759 @var{file}(@var{section}): warning: common is here
2760 @end smallexample
2762 @item
2763 Merging a common symbol with a previous same-sized common symbol.
2764 @smallexample
2765 @var{file}(@var{section}): warning: multiple common
2766    of `@var{symbol}'
2767 @var{file}(@var{section}): warning: previous common is here
2768 @end smallexample
2770 @item
2771 Merging a common symbol with a previous larger common symbol.
2772 @smallexample
2773 @var{file}(@var{section}): warning: common of `@var{symbol}'
2774    overridden by larger common
2775 @var{file}(@var{section}): warning: larger common is here
2776 @end smallexample
2778 @item
2779 Merging a common symbol with a previous smaller common symbol.  This is
2780 the same as the previous case, except that the symbols are
2781 encountered in a different order.
2782 @smallexample
2783 @var{file}(@var{section}): warning: common of `@var{symbol}'
2784    overriding smaller common
2785 @var{file}(@var{section}): warning: smaller common is here
2786 @end smallexample
2787 @end enumerate
2789 @kindex --warn-constructors
2790 @item --warn-constructors
2791 Warn if any global constructors are used.  This is only useful for a few
2792 object file formats.  For formats like COFF or ELF, the linker can not
2793 detect the use of global constructors.
2795 @kindex --warn-execstack
2796 @cindex warnings, on executable stack
2797 @cindex executable stack, warnings on
2798 @item --warn-execstack
2799 @itemx --warn-execstack-objects
2800 @itemx --no-warn-execstack
2801 On ELF platforms the linker may generate warning messages if it is
2802 asked to create an output file that contains an executable stack.
2803 There are three possible states:
2804 @enumerate
2805 @item
2806 Do not generate any warnings.
2807 @item
2808 Always generate warnings, even if the executable stack is requested
2809 via the @option{-z execstack} command line option.
2810 @item
2811 Only generate a warning if an object file requests an executable
2812 stack, but not if the @option{-z execstack} option is used.
2813 @end enumerate
2815 The default state depends upon how the linker was configured when it
2816 was built.  The @option{--no-warn-execstack} option always puts the
2817 linker into the no-warnings state.  The @option{--warn-execstack}
2818 option puts the linker into the warn-always state.  The
2819 @option{--warn-execstack-objects} option puts the linker into the
2820 warn-for-object-files-only state.
2822 Note: ELF format input files can specify that they need an executable
2823 stack by having a @var{.note.GNU-stack} section with the executable
2824 bit set in its section flags.  They can specify that they do not need
2825 an executable stack by having the same section, but without the
2826 executable flag bit set.  If an input file does not have a
2827 @var{.note.GNU-stack} section then the default behaviour is target
2828 specific.  For some targets, then absence of such a section implies
2829 that an executable stack @emph{is} required.  This is often a problem
2830 for hand crafted assembler files.
2832 @kindex --error-execstack
2833 @item --error-execstack
2834 @itemx --no-error-execstack
2835 If the linker is going to generate a warning message about an
2836 executable stack then the @option{--error-execstack} option will
2837 instead change that warning into an error.  Note - this option does
2838 not change the linker's execstack warning generation state.  Use
2839 @option{--warn-execstack} or @option{--warn-execstack-objects} to set
2840 a specific warning state.
2842 The @option{--no-error-execstack} option will restore the default
2843 behaviour of generating warning messages.
2845 @kindex --warn-multiple-gp
2846 @item --warn-multiple-gp
2847 Warn if multiple global pointer values are required in the output file.
2848 This is only meaningful for certain processors, such as the Alpha.
2849 Specifically, some processors put large-valued constants in a special
2850 section.  A special register (the global pointer) points into the middle
2851 of this section, so that constants can be loaded efficiently via a
2852 base-register relative addressing mode.  Since the offset in
2853 base-register relative mode is fixed and relatively small (e.g., 16
2854 bits), this limits the maximum size of the constant pool.  Thus, in
2855 large programs, it is often necessary to use multiple global pointer
2856 values in order to be able to address all possible constants.  This
2857 option causes a warning to be issued whenever this case occurs.
2859 @kindex --warn-once
2860 @cindex warnings, on undefined symbols
2861 @cindex undefined symbols, warnings on
2862 @item --warn-once
2863 Only warn once for each undefined symbol, rather than once per module
2864 which refers to it.
2866 @kindex --warn-rwx-segments
2867 @cindex warnings, on writeable and exectuable segments
2868 @cindex executable segments, warnings on
2869 @item --warn-rwx-segments
2870 @itemx --no-warn-rwx-segments
2871 Warn if the linker creates a loadable, non-zero sized segment that has
2872 all three of the read, write and execute permission flags set.  Such a
2873 segment represents a potential security vulnerability.  In addition
2874 warnings will be generated if a thread local storage segment is
2875 created with the execute permission flag set, regardless of whether or
2876 not it has the read and/or write flags set.
2878 These warnings are enabled by default.  They can be disabled via the
2879 @option{--no-warn-rwx-segments} option and re-enabled via the
2880 @option{--warn-rwx-segments} option.
2882 @kindex --error-rwx-segments
2883 @item --error-rwx-segments
2884 @itemx --no-error-rwx-segments
2885 If the linker is going to generate a warning message about an
2886 executable, writeable segment, or an executable TLS segment, then the
2887 @option{--error-rwx-segments} option will turn this warning into an
2888 error instead.  The @option{--no-error-rwx-segments} option will
2889 restore the default behaviour of just generating a warning message.
2891 Note - the @option{--error-rwx-segments} option does not by itself
2892 turn on warnings about these segments.  These warnings are either
2893 enabled by default, if the linker was configured that way, or via the
2894 @option{--warn-rwx-segments} command line option.
2896 @kindex --warn-section-align
2897 @cindex warnings, on section alignment
2898 @cindex section alignment, warnings on
2899 @item --warn-section-align
2900 Warn if the address of an output section is changed because of
2901 alignment.  Typically, the alignment will be set by an input section.
2902 The address will only be changed if it not explicitly specified; that
2903 is, if the @code{SECTIONS} command does not specify a start address for
2904 the section (@pxref{SECTIONS}).
2906 @kindex --warn-textrel
2907 @item --warn-textrel
2908 Warn if the linker adds DT_TEXTREL to a position-independent executable
2909 or shared object.
2911 @kindex --warn-alternate-em
2912 @item --warn-alternate-em
2913 Warn if an object has alternate ELF machine code.
2915 @kindex --warn-unresolved-symbols
2916 @item --warn-unresolved-symbols
2917 If the linker is going to report an unresolved symbol (see the option
2918 @option{--unresolved-symbols}) it will normally generate an error.
2919 This option makes it generate a warning instead.
2921 @kindex --error-unresolved-symbols
2922 @item --error-unresolved-symbols
2923 This restores the linker's default behaviour of generating errors when
2924 it is reporting unresolved symbols.
2926 @kindex --whole-archive
2927 @cindex including an entire archive
2928 @item --whole-archive
2929 For each archive mentioned on the command line after the
2930 @option{--whole-archive} option, include every object file in the archive
2931 in the link, rather than searching the archive for the required object
2932 files.  This is normally used to turn an archive file into a shared
2933 library, forcing every object to be included in the resulting shared
2934 library.  This option may be used more than once.
2936 Two notes when using this option from gcc: First, gcc doesn't know
2937 about this option, so you have to use @option{-Wl,-whole-archive}.
2938 Second, don't forget to use @option{-Wl,-no-whole-archive} after your
2939 list of archives, because gcc will add its own list of archives to
2940 your link and you may not want this flag to affect those as well.
2942 @kindex --wrap=@var{symbol}
2943 @item --wrap=@var{symbol}
2944 Use a wrapper function for @var{symbol}.  Any undefined reference to
2945 @var{symbol} will be resolved to @code{__wrap_@var{symbol}}.  Any
2946 undefined reference to @code{__real_@var{symbol}} will be resolved to
2947 @var{symbol}.
2949 This can be used to provide a wrapper for a system function.  The
2950 wrapper function should be called @code{__wrap_@var{symbol}}.  If it
2951 wishes to call the system function, it should call
2952 @code{__real_@var{symbol}}.
2954 Here is a trivial example:
2956 @smallexample
2957 void *
2958 __wrap_malloc (size_t c)
2960   printf ("malloc called with %zu\n", c);
2961   return __real_malloc (c);
2963 @end smallexample
2965 If you link other code with this file using @option{--wrap malloc}, then
2966 all calls to @code{malloc} will call the function @code{__wrap_malloc}
2967 instead.  The call to @code{__real_malloc} in @code{__wrap_malloc} will
2968 call the real @code{malloc} function.
2970 You may wish to provide a @code{__real_malloc} function as well, so that
2971 links without the @option{--wrap} option will succeed.  If you do this,
2972 you should not put the definition of @code{__real_malloc} in the same
2973 file as @code{__wrap_malloc}; if you do, the assembler may resolve the
2974 call before the linker has a chance to wrap it to @code{malloc}.
2976 Only undefined references are replaced by the linker.  So, translation unit
2977 internal references to @var{symbol} are not resolved to
2978 @code{__wrap_@var{symbol}}.  In the next example, the call to @code{f} in
2979 @code{g} is not resolved to @code{__wrap_f}.
2981 @smallexample
2983 f (void)
2985   return 123;
2989 g (void)
2991   return f();
2993 @end smallexample
2995 @kindex --eh-frame-hdr
2996 @kindex --no-eh-frame-hdr
2997 @item --eh-frame-hdr
2998 @itemx --no-eh-frame-hdr
2999 Request (@option{--eh-frame-hdr}) or suppress
3000 (@option{--no-eh-frame-hdr}) the creation of @code{.eh_frame_hdr}
3001 section and ELF @code{PT_GNU_EH_FRAME} segment header.
3003 @kindex --ld-generated-unwind-info
3004 @item --no-ld-generated-unwind-info
3005 Request creation of @code{.eh_frame} unwind info for linker
3006 generated code sections like PLT.  This option is on by default
3007 if linker generated unwind info is supported.  This option also
3008 controls the generation of @code{.sframe} stack trace info for linker
3009 generated code sections like PLT.
3011 @kindex --enable-new-dtags
3012 @kindex --disable-new-dtags
3013 @item --enable-new-dtags
3014 @itemx --disable-new-dtags
3015 This linker can create the new dynamic tags in ELF. But the older ELF
3016 systems may not understand them. If you specify
3017 @option{--enable-new-dtags}, the new dynamic tags will be created as needed
3018 and older dynamic tags will be omitted.
3019 If you specify @option{--disable-new-dtags}, no new dynamic tags will be
3020 created. By default, the new dynamic tags are not created. Note that
3021 those options are only available for ELF systems.
3023 @kindex --hash-size=@var{number}
3024 @item --hash-size=@var{number}
3025 Set the default size of the linker's hash tables to a prime number
3026 close to @var{number}.  Increasing this value can reduce the length of
3027 time it takes the linker to perform its tasks, at the expense of
3028 increasing the linker's memory requirements.  Similarly reducing this
3029 value can reduce the memory requirements at the expense of speed.
3031 @kindex --hash-style=@var{style}
3032 @item --hash-style=@var{style}
3033 Set the type of linker's hash table(s).  @var{style} can be either
3034 @code{sysv} for classic ELF @code{.hash} section, @code{gnu} for
3035 new style GNU @code{.gnu.hash} section or @code{both} for both
3036 the classic ELF @code{.hash} and new style GNU @code{.gnu.hash}
3037 hash tables.  The default depends upon how the linker was configured,
3038 but for most Linux based systems it will be @code{both}.
3040 @kindex --compress-debug-sections=none
3041 @kindex --compress-debug-sections=zlib
3042 @kindex --compress-debug-sections=zlib-gnu
3043 @kindex --compress-debug-sections=zlib-gabi
3044 @kindex --compress-debug-sections=zstd
3045 @item --compress-debug-sections=none
3046 @itemx --compress-debug-sections=zlib
3047 @itemx --compress-debug-sections=zlib-gnu
3048 @itemx --compress-debug-sections=zlib-gabi
3049 @itemx --compress-debug-sections=zstd
3050 On ELF platforms, these options control how DWARF debug sections are
3051 compressed using zlib.
3053 @option{--compress-debug-sections=none} doesn't compress DWARF debug
3054 sections.  @option{--compress-debug-sections=zlib-gnu} compresses
3055 DWARF debug sections and renames them to begin with @samp{.zdebug}
3056 instead of @samp{.debug}.  @option{--compress-debug-sections=zlib-gabi}
3057 also compresses DWARF debug sections, but rather than renaming them it
3058 sets the SHF_COMPRESSED flag in the sections' headers.
3060 The @option{--compress-debug-sections=zlib} option is an alias for
3061 @option{--compress-debug-sections=zlib-gabi}.
3063 @option{--compress-debug-sections=zstd} compresses DWARF debug sections using
3064 zstd.
3066 Note that this option overrides any compression in input debug
3067 sections, so if a binary is linked with @option{--compress-debug-sections=none}
3068 for example, then any compressed debug sections in input files will be
3069 uncompressed before they are copied into the output binary.
3071 The default compression behaviour varies depending upon the target
3072 involved and the configure options used to build the toolchain.  The
3073 default can be determined by examining the output from the linker's
3074 @option{--help} option.
3076 @kindex --reduce-memory-overheads
3077 @item --reduce-memory-overheads
3078 This option reduces memory requirements at ld runtime, at the expense of
3079 linking speed.  This was introduced to select the old O(n^2) algorithm
3080 for link map file generation, rather than the new O(n) algorithm which uses
3081 about 40% more memory for symbol storage.
3083 Another effect of the switch is to set the default hash table size to
3084 1021, which again saves memory at the cost of lengthening the linker's
3085 run time.  This is not done however if the @option{--hash-size} switch
3086 has been used.
3088 The @option{--reduce-memory-overheads} switch may be also be used to
3089 enable other tradeoffs in future versions of the linker.
3091 @kindex --max-cache-size=@var{size}
3092 @item --max-cache-size=@var{size}
3093 @command{ld} normally caches the relocation information and symbol tables
3094 of input files in memory with the unlimited size.  This option sets the
3095 maximum cache size to @var{size}.
3097 @kindex --build-id
3098 @kindex --build-id=@var{style}
3099 @item --build-id
3100 @itemx --build-id=@var{style}
3101 Request the creation of a @code{.note.gnu.build-id} ELF note section
3102 or a @code{.buildid} COFF section.  The contents of the note are
3103 unique bits identifying this linked file.  @var{style} can be
3104 @code{uuid} to use 128 random bits, @code{sha1} to use a 160-bit
3105 @sc{SHA1} hash on the normative parts of the output contents,
3106 @code{md5} to use a 128-bit @sc{MD5} hash on the normative parts of
3107 the output contents, or @code{0x@var{hexstring}} to use a chosen bit
3108 string specified as an even number of hexadecimal digits (@code{-} and
3109 @code{:} characters between digit pairs are ignored).  If @var{style}
3110 is omitted, @code{sha1} is used.
3112 The @code{md5} and @code{sha1} styles produces an identifier
3113 that is always the same in an identical output file, but will be
3114 unique among all nonidentical output files.  It is not intended
3115 to be compared as a checksum for the file's contents.  A linked
3116 file may be changed later by other tools, but the build ID bit
3117 string identifying the original linked file does not change.
3119 Passing @code{none} for @var{style} disables the setting from any
3120 @code{--build-id} options earlier on the command line.
3122 @kindex --package-metadata=@var{JSON}
3123 @item --package-metadata=@var{JSON}
3124 Request the creation of a @code{.note.package} ELF note section.  The
3125 contents of the note are in JSON format, as per the package metadata
3126 specification.  For more information see:
3127 https://systemd.io/ELF_PACKAGE_METADATA/
3128 If the JSON argument is missing/empty then this will disable the
3129 creation of the metadata note, if one had been enabled by an earlier
3130 occurrence of the --package-metadata option.
3131 If the linker has been built with libjansson, then the JSON string
3132 will be validated.
3133 @end table
3135 @c man end
3137 @subsection Options Specific to i386 PE Targets
3139 @c man begin OPTIONS
3141 The i386 PE linker supports the @option{-shared} option, which causes
3142 the output to be a dynamically linked library (DLL) instead of a
3143 normal executable.  You should name the output @code{*.dll} when you
3144 use this option.  In addition, the linker fully supports the standard
3145 @code{*.def} files, which may be specified on the linker command line
3146 like an object file (in fact, it should precede archives it exports
3147 symbols from, to ensure that they get linked in, just like a normal
3148 object file).
3150 In addition to the options common to all targets, the i386 PE linker
3151 support additional command-line options that are specific to the i386
3152 PE target.  Options that take values may be separated from their
3153 values by either a space or an equals sign.
3155 @table @gcctabopt
3157 @kindex --add-stdcall-alias
3158 @item --add-stdcall-alias
3159 If given, symbols with a stdcall suffix (@@@var{nn}) will be exported
3160 as-is and also with the suffix stripped.
3161 [This option is specific to the i386 PE targeted port of the linker]
3163 @kindex --base-file
3164 @item --base-file @var{file}
3165 Use @var{file} as the name of a file in which to save the base
3166 addresses of all the relocations needed for generating DLLs with
3167 @file{dlltool}.
3168 [This is an i386 PE specific option]
3170 @kindex --dll
3171 @item --dll
3172 Create a DLL instead of a regular executable.  You may also use
3173 @option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
3174 file.
3175 [This option is specific to the i386 PE targeted port of the linker]
3177 @kindex --enable-long-section-names
3178 @kindex --disable-long-section-names
3179 @item --enable-long-section-names
3180 @itemx --disable-long-section-names
3181 The PE variants of the COFF object format add an extension that permits
3182 the use of section names longer than eight characters, the normal limit
3183 for COFF.  By default, these names are only allowed in object files, as
3184 fully-linked executable images do not carry the COFF string table required
3185 to support the longer names.  As a GNU extension, it is possible to
3186 allow their use in executable images as well, or to (probably pointlessly!)
3187 disallow it in object files, by using these two options.  Executable images
3188 generated with these long section names are slightly non-standard, carrying
3189 as they do a string table, and may generate confusing output when examined
3190 with non-GNU PE-aware tools, such as file viewers and dumpers.  However,
3191 GDB relies on the use of PE long section names to find Dwarf-2 debug
3192 information sections in an executable image at runtime, and so if neither
3193 option is specified on the command-line, @command{ld} will enable long
3194 section names, overriding the default and technically correct behaviour,
3195 when it finds the presence of debug information while linking an executable
3196 image and not stripping symbols.
3197 [This option is valid for all PE targeted ports of the linker]
3199 @kindex --enable-stdcall-fixup
3200 @kindex --disable-stdcall-fixup
3201 @item --enable-stdcall-fixup
3202 @itemx --disable-stdcall-fixup
3203 If the link finds a symbol that it cannot resolve, it will attempt to
3204 do ``fuzzy linking'' by looking for another defined symbol that differs
3205 only in the format of the symbol name (cdecl vs stdcall) and will
3206 resolve that symbol by linking to the match.  For example, the
3207 undefined symbol @code{_foo} might be linked to the function
3208 @code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
3209 to the function @code{_bar}.  When the linker does this, it prints a
3210 warning, since it normally should have failed to link, but sometimes
3211 import libraries generated from third-party dlls may need this feature
3212 to be usable.  If you specify @option{--enable-stdcall-fixup}, this
3213 feature is fully enabled and warnings are not printed.  If you specify
3214 @option{--disable-stdcall-fixup}, this feature is disabled and such
3215 mismatches are considered to be errors.
3216 [This option is specific to the i386 PE targeted port of the linker]
3218 @kindex --leading-underscore
3219 @kindex --no-leading-underscore
3220 @item --leading-underscore
3221 @itemx --no-leading-underscore
3222 For most targets default symbol-prefix is an underscore and is defined
3223 in target's description. By this option it is possible to
3224 disable/enable the default underscore symbol-prefix.
3226 @cindex DLLs, creating
3227 @kindex --export-all-symbols
3228 @item --export-all-symbols
3229 If given, all global symbols in the objects used to build a DLL will
3230 be exported by the DLL.  Note that this is the default if there
3231 otherwise wouldn't be any exported symbols.  When symbols are
3232 explicitly exported via DEF files or implicitly exported via function
3233 attributes, the default is to not export anything else unless this
3234 option is given.  Note that the symbols @code{DllMain@@12},
3235 @code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
3236 @code{impure_ptr} will not be automatically
3237 exported.  Also, symbols imported from other DLLs will not be
3238 re-exported, nor will symbols specifying the DLL's internal layout
3239 such as those beginning with @code{_head_} or ending with
3240 @code{_iname}.  In addition, no symbols from @code{libgcc},
3241 @code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
3242 Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will
3243 not be exported, to help with C++ DLLs.  Finally, there is an
3244 extensive list of cygwin-private symbols that are not exported
3245 (obviously, this applies on when building DLLs for cygwin targets).
3246 These cygwin-excludes are: @code{_cygwin_dll_entry@@12},
3247 @code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
3248 @code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
3249 @code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
3250 @code{cygwin_premain3}, and @code{environ}.
3251 [This option is specific to the i386 PE targeted port of the linker]
3253 @kindex --exclude-symbols
3254 @item --exclude-symbols @var{symbol},@var{symbol},...
3255 Specifies a list of symbols which should not be automatically
3256 exported.  The symbol names may be delimited by commas or colons.
3257 [This option is specific to the i386 PE targeted port of the linker]
3259 @kindex --exclude-all-symbols
3260 @item --exclude-all-symbols
3261 Specifies no symbols should be automatically exported.
3262 [This option is specific to the i386 PE targeted port of the linker]
3264 @kindex --file-alignment
3265 @item --file-alignment
3266 Specify the file alignment.  Sections in the file will always begin at
3267 file offsets which are multiples of this number.  This defaults to
3268 512.
3269 [This option is specific to the i386 PE targeted port of the linker]
3271 @cindex heap size
3272 @kindex --heap
3273 @item --heap @var{reserve}
3274 @itemx --heap @var{reserve},@var{commit}
3275 Specify the number of bytes of memory to reserve (and optionally commit)
3276 to be used as heap for this program.  The default is 1MB reserved, 4K
3277 committed.
3278 [This option is specific to the i386 PE targeted port of the linker]
3280 @cindex image base
3281 @kindex --image-base
3282 @item --image-base @var{value}
3283 Use @var{value} as the base address of your program or dll.  This is
3284 the lowest memory location that will be used when your program or dll
3285 is loaded.  To reduce the need to relocate and improve performance of
3286 your dlls, each should have a unique base address and not overlap any
3287 other dlls.  The default is 0x400000 for executables, and 0x10000000
3288 for dlls.
3289 [This option is specific to the i386 PE targeted port of the linker]
3291 @kindex --kill-at
3292 @item --kill-at
3293 If given, the stdcall suffixes (@@@var{nn}) will be stripped from
3294 symbols before they are exported.
3295 [This option is specific to the i386 PE targeted port of the linker]
3297 @kindex --large-address-aware
3298 @item --large-address-aware
3299 If given, the appropriate bit in the ``Characteristics'' field of the COFF
3300 header is set to indicate that this executable supports virtual addresses
3301 greater than 2 gigabytes.  This should be used in conjunction with the /3GB
3302 or /USERVA=@var{value} megabytes switch in the ``[operating systems]''
3303 section of the BOOT.INI.  Otherwise, this bit has no effect.
3304 [This option is specific to PE targeted ports of the linker]
3306 @kindex --disable-large-address-aware
3307 @item --disable-large-address-aware
3308 Reverts the effect of a previous @samp{--large-address-aware} option.
3309 This is useful if @samp{--large-address-aware} is always set by the compiler
3310 driver (e.g. Cygwin gcc) and the executable does not support virtual
3311 addresses greater than 2 gigabytes.
3312 [This option is specific to PE targeted ports of the linker]
3314 @kindex --major-image-version
3315 @item --major-image-version @var{value}
3316 Sets the major number of the ``image version''.  Defaults to 1.
3317 [This option is specific to the i386 PE targeted port of the linker]
3319 @kindex --major-os-version
3320 @item --major-os-version @var{value}
3321 Sets the major number of the ``os version''.  Defaults to 4.
3322 [This option is specific to the i386 PE targeted port of the linker]
3324 @kindex --major-subsystem-version
3325 @item --major-subsystem-version @var{value}
3326 Sets the major number of the ``subsystem version''.  Defaults to 4.
3327 [This option is specific to the i386 PE targeted port of the linker]
3329 @kindex --minor-image-version
3330 @item --minor-image-version @var{value}
3331 Sets the minor number of the ``image version''.  Defaults to 0.
3332 [This option is specific to the i386 PE targeted port of the linker]
3334 @kindex --minor-os-version
3335 @item --minor-os-version @var{value}
3336 Sets the minor number of the ``os version''.  Defaults to 0.
3337 [This option is specific to the i386 PE targeted port of the linker]
3339 @kindex --minor-subsystem-version
3340 @item --minor-subsystem-version @var{value}
3341 Sets the minor number of the ``subsystem version''.  Defaults to 0.
3342 [This option is specific to the i386 PE targeted port of the linker]
3344 @cindex DEF files, creating
3345 @cindex DLLs, creating
3346 @kindex --output-def
3347 @item --output-def @var{file}
3348 The linker will create the file @var{file} which will contain a DEF
3349 file corresponding to the DLL the linker is generating.  This DEF file
3350 (which should be called @code{*.def}) may be used to create an import
3351 library with @code{dlltool} or may be used as a reference to
3352 automatically or implicitly exported symbols.
3353 [This option is specific to the i386 PE targeted port of the linker]
3355 @cindex DLLs, creating
3356 @kindex --enable-auto-image-base
3357 @item --enable-auto-image-base
3358 @itemx --enable-auto-image-base=@var{value}
3359 Automatically choose the image base for DLLs, optionally starting with base
3360 @var{value}, unless one is specified using the @code{--image-base} argument.
3361 By using a hash generated from the dllname to create unique image bases
3362 for each DLL, in-memory collisions and relocations which can delay program
3363 execution are avoided.
3364 [This option is specific to the i386 PE targeted port of the linker]
3366 @kindex --disable-auto-image-base
3367 @item --disable-auto-image-base
3368 Do not automatically generate a unique image base.  If there is no
3369 user-specified image base (@code{--image-base}) then use the platform
3370 default.
3371 [This option is specific to the i386 PE targeted port of the linker]
3373 @cindex DLLs, linking to
3374 @kindex --dll-search-prefix
3375 @item --dll-search-prefix @var{string}
3376 When linking dynamically to a dll without an import library,
3377 search for @code{<string><basename>.dll} in preference to
3378 @code{lib<basename>.dll}. This behaviour allows easy distinction
3379 between DLLs built for the various "subplatforms": native, cygwin,
3380 uwin, pw, etc.  For instance, cygwin DLLs typically use
3381 @code{--dll-search-prefix=cyg}.
3382 [This option is specific to the i386 PE targeted port of the linker]
3384 @kindex --enable-auto-import
3385 @item --enable-auto-import
3386 Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
3387 DATA imports from DLLs, thus making it possible to bypass the dllimport
3388 mechanism on the user side and to reference unmangled symbol names.
3389 [This option is specific to the i386 PE targeted port of the linker]
3391 The following remarks pertain to the original implementation of the
3392 feature and are obsolete nowadays for Cygwin and MinGW targets.
3394 Note: Use of the 'auto-import' extension will cause the text section
3395 of the image file to be made writable. This does not conform to the
3396 PE-COFF format specification published by Microsoft.
3398 Note - use of the 'auto-import' extension will also cause read only
3399 data which would normally be placed into the .rdata section to be
3400 placed into the .data section instead.  This is in order to work
3401 around a problem with consts that is described here:
3402 http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
3404 Using 'auto-import' generally will 'just work' -- but sometimes you may
3405 see this message:
3407 "variable '<var>' can't be auto-imported. Please read the
3408 documentation for ld's @code{--enable-auto-import} for details."
3410 This message occurs when some (sub)expression accesses an address
3411 ultimately given by the sum of two constants (Win32 import tables only
3412 allow one).  Instances where this may occur include accesses to member
3413 fields of struct variables imported from a DLL, as well as using a
3414 constant index into an array variable imported from a DLL.  Any
3415 multiword variable (arrays, structs, long long, etc) may trigger
3416 this error condition.  However, regardless of the exact data type
3417 of the offending exported variable, ld will always detect it, issue
3418 the warning, and exit.
3420 There are several ways to address this difficulty, regardless of the
3421 data type of the exported variable:
3423 One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
3424 of adjusting references in your client code for runtime environment, so
3425 this method works only when runtime environment supports this feature.
3427 A second solution is to force one of the 'constants' to be a variable --
3428 that is, unknown and un-optimizable at compile time.  For arrays,
3429 there are two possibilities: a) make the indexee (the array's address)
3430 a variable, or b) make the 'constant' index a variable.  Thus:
3432 @example
3433 extern type extern_array[];
3434 extern_array[1] -->
3435    @{ volatile type *t=extern_array; t[1] @}
3436 @end example
3440 @example
3441 extern type extern_array[];
3442 extern_array[1] -->
3443    @{ volatile int t=1; extern_array[t] @}
3444 @end example
3446 For structs (and most other multiword data types) the only option
3447 is to make the struct itself (or the long long, or the ...) variable:
3449 @example
3450 extern struct s extern_struct;
3451 extern_struct.field -->
3452    @{ volatile struct s *t=&extern_struct; t->field @}
3453 @end example
3457 @example
3458 extern long long extern_ll;
3459 extern_ll -->
3460   @{ volatile long long * local_ll=&extern_ll; *local_ll @}
3461 @end example
3463 A third method of dealing with this difficulty is to abandon
3464 'auto-import' for the offending symbol and mark it with
3465 @code{__declspec(dllimport)}.  However, in practice that
3466 requires using compile-time #defines to indicate whether you are
3467 building a DLL, building client code that will link to the DLL, or
3468 merely building/linking to a static library.   In making the choice
3469 between the various methods of resolving the 'direct address with
3470 constant offset' problem, you should consider typical real-world usage:
3472 Original:
3473 @example
3474 --foo.h
3475 extern int arr[];
3476 --foo.c
3477 #include "foo.h"
3478 void main(int argc, char **argv)@{
3479   printf("%d\n",arr[1]);
3481 @end example
3483 Solution 1:
3484 @example
3485 --foo.h
3486 extern int arr[];
3487 --foo.c
3488 #include "foo.h"
3489 void main(int argc, char **argv)@{
3490   /* This workaround is for win32 and cygwin; do not "optimize" */
3491   volatile int *parr = arr;
3492   printf("%d\n",parr[1]);
3494 @end example
3496 Solution 2:
3497 @example
3498 --foo.h
3499 /* Note: auto-export is assumed (no __declspec(dllexport)) */
3500 #if (defined(_WIN32) || defined(__CYGWIN__)) && \
3501   !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
3502 #define FOO_IMPORT __declspec(dllimport)
3503 #else
3504 #define FOO_IMPORT
3505 #endif
3506 extern FOO_IMPORT int arr[];
3507 --foo.c
3508 #include "foo.h"
3509 void main(int argc, char **argv)@{
3510   printf("%d\n",arr[1]);
3512 @end example
3514 A fourth way to avoid this problem is to re-code your
3515 library to use a functional interface rather than a data interface
3516 for the offending variables (e.g. set_foo() and get_foo() accessor
3517 functions).
3519 @kindex --disable-auto-import
3520 @item --disable-auto-import
3521 Do not attempt to do sophisticated linking of @code{_symbol} to
3522 @code{__imp__symbol} for DATA imports from DLLs.
3523 [This option is specific to the i386 PE targeted port of the linker]
3525 @kindex --enable-runtime-pseudo-reloc
3526 @item --enable-runtime-pseudo-reloc
3527 If your code contains expressions described in --enable-auto-import section,
3528 that is, DATA imports from DLL with non-zero offset, this switch will create
3529 a vector of 'runtime pseudo relocations' which can be used by runtime
3530 environment to adjust references to such data in your client code.
3531 [This option is specific to the i386 PE targeted port of the linker]
3533 @kindex --disable-runtime-pseudo-reloc
3534 @item --disable-runtime-pseudo-reloc
3535 Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
3536 [This option is specific to the i386 PE targeted port of the linker]
3538 @kindex --enable-extra-pe-debug
3539 @item --enable-extra-pe-debug
3540 Show additional debug info related to auto-import symbol thunking.
3541 [This option is specific to the i386 PE targeted port of the linker]
3543 @kindex --section-alignment
3544 @item --section-alignment
3545 Sets the section alignment.  Sections in memory will always begin at
3546 addresses which are a multiple of this number.  Defaults to 0x1000.
3547 [This option is specific to the i386 PE targeted port of the linker]
3549 @cindex stack size
3550 @kindex --stack
3551 @item --stack @var{reserve}
3552 @itemx --stack @var{reserve},@var{commit}
3553 Specify the number of bytes of memory to reserve (and optionally commit)
3554 to be used as stack for this program.  The default is 2MB reserved, 4K
3555 committed.
3556 [This option is specific to the i386 PE targeted port of the linker]
3558 @kindex --subsystem
3559 @item --subsystem @var{which}
3560 @itemx --subsystem @var{which}:@var{major}
3561 @itemx --subsystem @var{which}:@var{major}.@var{minor}
3562 Specifies the subsystem under which your program will execute.  The
3563 legal values for @var{which} are @code{native}, @code{windows},
3564 @code{console}, @code{posix}, and @code{xbox}.  You may optionally set
3565 the subsystem version also.  Numeric values are also accepted for
3566 @var{which}.
3567 [This option is specific to the i386 PE targeted port of the linker]
3569 The following options set flags in the @code{DllCharacteristics} field
3570 of the PE file header:
3571 [These options are specific to PE targeted ports of the linker]
3573 @kindex --high-entropy-va
3574 @item --high-entropy-va
3575 @itemx --disable-high-entropy-va
3576 Image is compatible with 64-bit address space layout randomization
3577 (ASLR).  This option is enabled by default for 64-bit PE images.
3579 This option also implies @option{--dynamicbase} and
3580 @option{--enable-reloc-section}.
3582 @kindex --dynamicbase
3583 @item --dynamicbase
3584 @itemx --disable-dynamicbase
3585 The image base address may be relocated using address space layout
3586 randomization (ASLR).  This feature was introduced with MS Windows
3587 Vista for i386 PE targets.  This option is enabled by default but
3588 can be disabled via the @option{--disable-dynamicbase} option.
3589 This option also implies @option{--enable-reloc-section}.
3591 @kindex --forceinteg
3592 @item --forceinteg
3593 @itemx --disable-forceinteg
3594 Code integrity checks are enforced.  This option is disabled by
3595 default.
3597 @kindex --nxcompat
3598 @item --nxcompat
3599 @item --disable-nxcompat
3600 The image is compatible with the Data Execution Prevention.
3601 This feature was introduced with MS Windows XP SP2 for i386 PE
3602 targets.  The option is enabled by default.
3604 @kindex --no-isolation
3605 @item --no-isolation
3606 @itemx --disable-no-isolation
3607 Although the image understands isolation, do not isolate the image.
3608 This option is disabled by default.
3610 @kindex --no-seh
3611 @item --no-seh
3612 @itemx --disable-no-seh
3613 The image does not use SEH. No SE handler may be called from
3614 this image.  This option is disabled by default.
3616 @kindex --no-bind
3617 @item --no-bind
3618 @itemx --disable-no-bind
3619 Do not bind this image.  This option is disabled by default.
3621 @kindex --wdmdriver
3622 @item --wdmdriver
3623 @itemx --disable-wdmdriver
3624 The driver uses the MS Windows Driver Model.  This option is disabled
3625 by default.
3627 @kindex --tsaware
3628 @item --tsaware
3629 @itemx --disable-tsaware
3630 The image is Terminal Server aware.  This option is disabled by
3631 default.
3633 @kindex --insert-timestamp
3634 @item --insert-timestamp
3635 @itemx --no-insert-timestamp
3636 Insert a real timestamp into the image.  This is the default behaviour
3637 as it matches legacy code and it means that the image will work with
3638 other, proprietary tools.  The problem with this default is that it
3639 will result in slightly different images being produced each time the
3640 same sources are linked.  The option @option{--no-insert-timestamp}
3641 can be used to insert a zero value for the timestamp, this ensuring
3642 that binaries produced from identical sources will compare
3643 identically.
3645 If @option{--insert-timestamp} is active then the time inserted is
3646 either the time that the linking takes place or, if the
3647 @code{SOURCE_DATE_EPOCH} environment variable is defined, the number
3648 of seconds since Unix epoch as specified by that variable.
3650 @kindex --enable-reloc-section
3651 @item --enable-reloc-section
3652 @itemx --disable-reloc-section
3653 Create the base relocation table, which is necessary if the image
3654 is loaded at a different image base than specified in the PE header.
3655 This option is enabled by default.
3656 @end table
3658 @c man end
3660 @ifset C6X
3661 @subsection Options specific to C6X uClinux targets
3663 @c man begin OPTIONS
3665 The C6X uClinux target uses a binary format called DSBT to support shared
3666 libraries.  Each shared library in the system needs to have a unique index;
3667 all executables use an index of 0.
3669 @table @gcctabopt
3671 @kindex --dsbt-size
3672 @item --dsbt-size @var{size}
3673 This option sets the number of entries in the DSBT of the current executable
3674 or shared library to @var{size}.  The default is to create a table with 64
3675 entries.
3677 @kindex --dsbt-index
3678 @item --dsbt-index @var{index}
3679 This option sets the DSBT index of the current executable or shared library
3680 to @var{index}.  The default is 0, which is appropriate for generating
3681 executables.  If a shared library is generated with a DSBT index of 0, the
3682 @code{R_C6000_DSBT_INDEX} relocs are copied into the output file.
3684 @kindex --no-merge-exidx-entries
3685 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent
3686 exidx entries in frame unwind info.
3688 @end table
3690 @c man end
3691 @end ifset
3693 @ifset CSKY
3694 @subsection Options specific to C-SKY targets
3696 @c man begin OPTIONS
3698 @table @gcctabopt
3700 @kindex --branch-stub on C-SKY
3701 @item --branch-stub
3702 This option enables linker branch relaxation by inserting branch stub
3703 sections when needed to extend the range of branches.  This option is
3704 usually not required since C-SKY supports branch and call instructions that
3705 can access the full memory range and branch relaxation is normally handled by
3706 the compiler or assembler.
3708 @kindex --stub-group-size on C-SKY
3709 @item --stub-group-size=@var{N}
3710 This option allows finer control of linker branch stub creation.
3711 It sets the maximum size of a group of input sections that can
3712 be handled by one stub section.  A negative value of @var{N} locates
3713 stub sections after their branches, while a positive value allows stub
3714 sections to appear either before or after the branches.  Values of
3715 @samp{1} or @samp{-1} indicate that the
3716 linker should choose suitable defaults.
3718 @end table
3720 @c man end
3721 @end ifset
3723 @ifset M68HC11
3724 @subsection Options specific to Motorola 68HC11 and 68HC12 targets
3726 @c man begin OPTIONS
3728 The 68HC11 and 68HC12 linkers support specific options to control the
3729 memory bank switching mapping and trampoline code generation.
3731 @table @gcctabopt
3733 @kindex --no-trampoline
3734 @item --no-trampoline
3735 This option disables the generation of trampoline. By default a trampoline
3736 is generated for each far function which is called using a @code{jsr}
3737 instruction (this happens when a pointer to a far function is taken).
3739 @kindex --bank-window
3740 @item --bank-window @var{name}
3741 This option indicates to the linker the name of the memory region in
3742 the @samp{MEMORY} specification that describes the memory bank window.
3743 The definition of such region is then used by the linker to compute
3744 paging and addresses within the memory window.
3746 @end table
3748 @c man end
3749 @end ifset
3751 @ifset M68K
3752 @subsection Options specific to Motorola 68K target
3754 @c man begin OPTIONS
3756 The following options are supported to control handling of GOT generation
3757 when linking for 68K targets.
3759 @table @gcctabopt
3761 @kindex --got
3762 @item --got=@var{type}
3763 This option tells the linker which GOT generation scheme to use.
3764 @var{type} should be one of @samp{single}, @samp{negative},
3765 @samp{multigot} or @samp{target}.  For more information refer to the
3766 Info entry for @file{ld}.
3768 @end table
3770 @c man end
3771 @end ifset
3773 @ifset MIPS
3774 @subsection Options specific to MIPS targets
3776 @c man begin OPTIONS
3778 The following options are supported to control microMIPS instruction
3779 generation and branch relocation checks for ISA mode transitions when
3780 linking for MIPS targets.
3782 @table @gcctabopt
3784 @kindex --insn32
3785 @item --insn32
3786 @kindex --no-insn32
3787 @itemx --no-insn32
3788 These options control the choice of microMIPS instructions used in code
3789 generated by the linker, such as that in the PLT or lazy binding stubs,
3790 or in relaxation.  If @samp{--insn32} is used, then the linker only uses
3791 32-bit instruction encodings.  By default or if @samp{--no-insn32} is
3792 used, all instruction encodings are used, including 16-bit ones where
3793 possible.
3795 @kindex --ignore-branch-isa
3796 @item --ignore-branch-isa
3797 @kindex --no-ignore-branch-isa
3798 @itemx --no-ignore-branch-isa
3799 These options control branch relocation checks for invalid ISA mode
3800 transitions.  If @samp{--ignore-branch-isa} is used, then the linker
3801 accepts any branch relocations and any ISA mode transition required
3802 is lost in relocation calculation, except for some cases of @code{BAL}
3803 instructions which meet relaxation conditions and are converted to
3804 equivalent @code{JALX} instructions as the associated relocation is
3805 calculated.  By default or if @samp{--no-ignore-branch-isa} is used
3806 a check is made causing the loss of an ISA mode transition to produce
3807 an error.
3809 @kindex --compact-branches
3810 @item --compact-branches
3811 @kindex --no-compact-branches
3812 @itemx --no-compact-branches
3813 These options control the generation of compact instructions by the linker
3814 in the PLT entries for MIPS R6.
3816 @end table
3818 @c man end
3819 @end ifset
3822 @ifset PDP11
3823 @subsection Options specific to PDP11 targets
3825 @c man begin OPTIONS
3827 For the pdp11-aout target, three variants of the output format can be
3828 produced as selected by the following options.  The default variant
3829 for pdp11-aout is the @samp{--omagic} option, whereas for other
3830 targets @samp{--nmagic} is the default.  The @samp{--imagic} option is
3831 defined only for the pdp11-aout target, while the others are described
3832 here as they apply to the pdp11-aout target.
3834 @table @gcctabopt
3836 @kindex -N
3837 @item -N
3838 @kindex --omagic
3839 @itemx --omagic
3841 Mark the output as @code{OMAGIC} (0407) in the @file{a.out} header to
3842 indicate that the text segment is not to be write-protected and
3843 shared.  Since the text and data sections are both readable and
3844 writable, the data section is allocated immediately contiguous after
3845 the text segment.  This is the oldest format for PDP11 executable
3846 programs and is the default for @command{ld} on PDP11 Unix systems
3847 from the beginning through 2.11BSD.
3849 @kindex -n
3850 @item -n
3851 @kindex --nmagic
3852 @itemx --nmagic
3854 Mark the output as @code{NMAGIC} (0410) in the @file{a.out} header to
3855 indicate that when the output file is executed, the text portion will
3856 be read-only and shareable among all processes executing the same
3857 file.  This involves moving the data areas up to the first possible 8K
3858 byte page boundary following the end of the text.  This option creates
3859 a @emph{pure executable} format.
3861 @kindex -z
3862 @item -z
3863 @kindex --imagic
3864 @itemx --imagic
3866 Mark the output as @code{IMAGIC} (0411) in the @file{a.out} header to
3867 indicate that when the output file is executed, the program text and
3868 data areas will be loaded into separate address spaces using the split
3869 instruction and data space feature of the memory management unit in
3870 larger models of the PDP11.  This doubles the address space available
3871 to the program.  The text segment is again pure, write-protected, and
3872 shareable.  The only difference in the output format between this
3873 option and the others, besides the magic number, is that both the text
3874 and data sections start at location 0.  The @samp{-z} option selected
3875 this format in 2.11BSD.  This option creates a @emph{separate
3876 executable} format.
3878 @kindex --no-omagic
3879 @item --no-omagic
3881 Equivalent to @samp{--nmagic} for pdp11-aout.
3883 @end table
3885 @c man end
3886 @end ifset
3888 @ifset UsesEnvVars
3889 @node Environment
3890 @section Environment Variables
3892 @c man begin ENVIRONMENT
3894 You can change the behaviour of @command{ld} with the environment variables
3895 @ifclear SingleFormat
3896 @code{GNUTARGET},
3897 @end ifclear
3898 @code{LDEMULATION} and @code{COLLECT_NO_DEMANGLE}.
3900 @ifclear SingleFormat
3901 @kindex GNUTARGET
3902 @cindex default input format
3903 @code{GNUTARGET} determines the input-file object format if you don't
3904 use @samp{-b} (or its synonym @samp{--format}).  Its value should be one
3905 of the BFD names for an input format (@pxref{BFD}).  If there is no
3906 @code{GNUTARGET} in the environment, @command{ld} uses the natural format
3907 of the target. If @code{GNUTARGET} is set to @code{default} then BFD
3908 attempts to discover the input format by examining binary input files;
3909 this method often succeeds, but there are potential ambiguities, since
3910 there is no method of ensuring that the magic number used to specify
3911 object-file formats is unique.  However, the configuration procedure for
3912 BFD on each system places the conventional format for that system first
3913 in the search-list, so ambiguities are resolved in favor of convention.
3914 @end ifclear
3916 @kindex LDEMULATION
3917 @cindex default emulation
3918 @cindex emulation, default
3919 @code{LDEMULATION} determines the default emulation if you don't use the
3920 @samp{-m} option.  The emulation can affect various aspects of linker
3921 behaviour, particularly the default linker script.  You can list the
3922 available emulations with the @samp{--verbose} or @samp{-V} options.  If
3923 the @samp{-m} option is not used, and the @code{LDEMULATION} environment
3924 variable is not defined, the default emulation depends upon how the
3925 linker was configured.
3927 @kindex COLLECT_NO_DEMANGLE
3928 @cindex demangling, default
3929 Normally, the linker will default to demangling symbols.  However, if
3930 @code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
3931 default to not demangling symbols.  This environment variable is used in
3932 a similar fashion by the @code{gcc} linker wrapper program.  The default
3933 may be overridden by the @samp{--demangle} and @samp{--no-demangle}
3934 options.
3936 @c man end
3937 @end ifset
3939 @node Scripts
3940 @chapter Linker Scripts
3942 @cindex scripts
3943 @cindex linker scripts
3944 @cindex command files
3945 Every link is controlled by a @dfn{linker script}.  This script is
3946 written in the linker command language.
3948 The main purpose of the linker script is to describe how the sections in
3949 the input files should be mapped into the output file, and to control
3950 the memory layout of the output file.  Most linker scripts do nothing
3951 more than this.  However, when necessary, the linker script can also
3952 direct the linker to perform many other operations, using the commands
3953 described below.
3955 The linker always uses a linker script.  If you do not supply one
3956 yourself, the linker will use a default script that is compiled into the
3957 linker executable.  You can use the @samp{--verbose} command-line option
3958 to display the default linker script.  Certain command-line options,
3959 such as @samp{-r} or @samp{-N}, will affect the default linker script.
3961 You may supply your own linker script by using the @samp{-T} command
3962 line option.  When you do this, your linker script will replace the
3963 default linker script.
3965 You may also use linker scripts implicitly by naming them as input files
3966 to the linker, as though they were files to be linked.  @xref{Implicit
3967 Linker Scripts}.
3969 @menu
3970 * Basic Script Concepts::       Basic Linker Script Concepts
3971 * Script Format::               Linker Script Format
3972 * Simple Example::              Simple Linker Script Example
3973 * Simple Commands::             Simple Linker Script Commands
3974 * Assignments::                 Assigning Values to Symbols
3975 * SECTIONS::                    SECTIONS Command
3976 * MEMORY::                      MEMORY Command
3977 * PHDRS::                       PHDRS Command
3978 * VERSION::                     VERSION Command
3979 * Expressions::                 Expressions in Linker Scripts
3980 * Implicit Linker Scripts::     Implicit Linker Scripts
3981 @end menu
3983 @node Basic Script Concepts
3984 @section Basic Linker Script Concepts
3985 @cindex linker script concepts
3986 We need to define some basic concepts and vocabulary in order to
3987 describe the linker script language.
3989 The linker combines input files into a single output file.  The output
3990 file and each input file are in a special data format known as an
3991 @dfn{object file format}.  Each file is called an @dfn{object file}.
3992 The output file is often called an @dfn{executable}, but for our
3993 purposes we will also call it an object file.  Each object file has,
3994 among other things, a list of @dfn{sections}.  We sometimes refer to a
3995 section in an input file as an @dfn{input section}; similarly, a section
3996 in the output file is an @dfn{output section}.
3998 Each section in an object file has a name and a size.  Most sections
3999 also have an associated block of data, known as the @dfn{section
4000 contents}.  A section may be marked as @dfn{loadable}, which means that
4001 the contents should be loaded into memory when the output file is run.
4002 A section with no contents may be @dfn{allocatable}, which means that an
4003 area in memory should be set aside, but nothing in particular should be
4004 loaded there (in some cases this memory must be zeroed out).  A section
4005 which is neither loadable nor allocatable typically contains some sort
4006 of debugging information.
4008 Every loadable or allocatable output section has two addresses.  The
4009 first is the @dfn{VMA}, or virtual memory address.  This is the address
4010 the section will have when the output file is run.  The second is the
4011 @dfn{LMA}, or load memory address.  This is the address at which the
4012 section will be loaded.  In most cases the two addresses will be the
4013 same.  An example of when they might be different is when a data section
4014 is loaded into ROM, and then copied into RAM when the program starts up
4015 (this technique is often used to initialize global variables in a ROM
4016 based system).  In this case the ROM address would be the LMA, and the
4017 RAM address would be the VMA.
4019 You can see the sections in an object file by using the @code{objdump}
4020 program with the @samp{-h} option.
4022 Every object file also has a list of @dfn{symbols}, known as the
4023 @dfn{symbol table}.  A symbol may be defined or undefined.  Each symbol
4024 has a name, and each defined symbol has an address, among other
4025 information.  If you compile a C or C++ program into an object file, you
4026 will get a defined symbol for every defined function and global or
4027 static variable.  Every undefined function or global variable which is
4028 referenced in the input file will become an undefined symbol.
4030 You can see the symbols in an object file by using the @code{nm}
4031 program, or by using the @code{objdump} program with the @samp{-t}
4032 option.
4034 @node Script Format
4035 @section Linker Script Format
4036 @cindex linker script format
4037 Linker scripts are text files.
4039 You write a linker script as a series of commands.  Each command is
4040 either a keyword, possibly followed by arguments, or an assignment to a
4041 symbol.  You may separate commands using semicolons.  Whitespace is
4042 generally ignored.
4044 Strings such as file or format names can normally be entered directly.
4045 If the file name contains a character such as a comma which would
4046 otherwise serve to separate file names, you may put the file name in
4047 double quotes.  There is no way to use a double quote character in a
4048 file name.
4050 You may include comments in linker scripts just as in C, delimited by
4051 @samp{/*} and @samp{*/}.  As in C, comments are syntactically equivalent
4052 to whitespace.
4054 @node Simple Example
4055 @section Simple Linker Script Example
4056 @cindex linker script example
4057 @cindex example of linker script
4058 Many linker scripts are fairly simple.
4060 The simplest possible linker script has just one command:
4061 @samp{SECTIONS}.  You use the @samp{SECTIONS} command to describe the
4062 memory layout of the output file.
4064 The @samp{SECTIONS} command is a powerful command.  Here we will
4065 describe a simple use of it.  Let's assume your program consists only of
4066 code, initialized data, and uninitialized data.  These will be in the
4067 @samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
4068 Let's assume further that these are the only sections which appear in
4069 your input files.
4071 For this example, let's say that the code should be loaded at address
4072 0x10000, and that the data should start at address 0x8000000.  Here is a
4073 linker script which will do that:
4074 @smallexample
4075 SECTIONS
4077   . = 0x10000;
4078   .text : @{ *(.text) @}
4079   . = 0x8000000;
4080   .data : @{ *(.data) @}
4081   .bss : @{ *(.bss) @}
4083 @end smallexample
4085 You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
4086 followed by a series of symbol assignments and output section
4087 descriptions enclosed in curly braces.
4089 The first line inside the @samp{SECTIONS} command of the above example
4090 sets the value of the special symbol @samp{.}, which is the location
4091 counter.  If you do not specify the address of an output section in some
4092 other way (other ways are described later), the address is set from the
4093 current value of the location counter.  The location counter is then
4094 incremented by the size of the output section.  At the start of the
4095 @samp{SECTIONS} command, the location counter has the value @samp{0}.
4097 The second line defines an output section, @samp{.text}.  The colon is
4098 required syntax which may be ignored for now.  Within the curly braces
4099 after the output section name, you list the names of the input sections
4100 which should be placed into this output section.  The @samp{*} is a
4101 wildcard which matches any file name.  The expression @samp{*(.text)}
4102 means all @samp{.text} input sections in all input files.
4104 Since the location counter is @samp{0x10000} when the output section
4105 @samp{.text} is defined, the linker will set the address of the
4106 @samp{.text} section in the output file to be @samp{0x10000}.
4108 The remaining lines define the @samp{.data} and @samp{.bss} sections in
4109 the output file.  The linker will place the @samp{.data} output section
4110 at address @samp{0x8000000}.  After the linker places the @samp{.data}
4111 output section, the value of the location counter will be
4112 @samp{0x8000000} plus the size of the @samp{.data} output section.  The
4113 effect is that the linker will place the @samp{.bss} output section
4114 immediately after the @samp{.data} output section in memory.
4116 The linker will ensure that each output section has the required
4117 alignment, by increasing the location counter if necessary.  In this
4118 example, the specified addresses for the @samp{.text} and @samp{.data}
4119 sections will probably satisfy any alignment constraints, but the linker
4120 may have to create a small gap between the @samp{.data} and @samp{.bss}
4121 sections.
4123 That's it!  That's a simple and complete linker script.
4125 @node Simple Commands
4126 @section Simple Linker Script Commands
4127 @cindex linker script simple commands
4128 In this section we describe the simple linker script commands.
4130 @menu
4131 * Entry Point::                 Setting the entry point
4132 * File Commands::               Commands dealing with files
4133 @ifclear SingleFormat
4134 * Format Commands::             Commands dealing with object file formats
4135 @end ifclear
4137 * REGION_ALIAS::                Assign alias names to memory regions
4138 * Miscellaneous Commands::      Other linker script commands
4139 @end menu
4141 @node Entry Point
4142 @subsection Setting the Entry Point
4143 @kindex ENTRY(@var{symbol})
4144 @cindex start of execution
4145 @cindex first instruction
4146 @cindex entry point
4147 The first instruction to execute in a program is called the @dfn{entry
4148 point}.  You can use the @code{ENTRY} linker script command to set the
4149 entry point.  The argument is a symbol name:
4150 @smallexample
4151 ENTRY(@var{symbol})
4152 @end smallexample
4154 There are several ways to set the entry point.  The linker will set the
4155 entry point by trying each of the following methods in order, and
4156 stopping when one of them succeeds:
4157 @itemize @bullet
4158 @item
4159 the @samp{-e} @var{entry} command-line option;
4160 @item
4161 the @code{ENTRY(@var{symbol})} command in a linker script;
4162 @item
4163 the value of a target-specific symbol, if it is defined;  For many
4164 targets this is @code{start}, but PE- and BeOS-based systems for example
4165 check a list of possible entry symbols, matching the first one found.
4166 @item
4167 the address of the first byte of the code section, if present and an
4168 executable is being created - the code section is usually
4169 @samp{.text}, but can be something else;
4170 @item
4171 The address @code{0}.
4172 @end itemize
4174 @node File Commands
4175 @subsection Commands Dealing with Files
4176 @cindex linker script file commands
4177 Several linker script commands deal with files.
4179 @table @code
4180 @item INCLUDE @var{filename}
4181 @kindex INCLUDE @var{filename}
4182 @cindex including a linker script
4183 Include the linker script @var{filename} at this point.  The file will
4184 be searched for in the current directory, and in any directory specified
4185 with the @option{-L} option.  You can nest calls to @code{INCLUDE} up to
4186 10 levels deep.
4188 You can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or
4189 @code{SECTIONS} commands, or in output section descriptions.
4191 @item INPUT(@var{file}, @var{file}, @dots{})
4192 @itemx INPUT(@var{file} @var{file} @dots{})
4193 @kindex INPUT(@var{files})
4194 @cindex input files in linker scripts
4195 @cindex input object files in linker scripts
4196 @cindex linker script input object files
4197 The @code{INPUT} command directs the linker to include the named files
4198 in the link, as though they were named on the command line.
4200 For example, if you always want to include @file{subr.o} any time you do
4201 a link, but you can't be bothered to put it on every link command line,
4202 then you can put @samp{INPUT (subr.o)} in your linker script.
4204 In fact, if you like, you can list all of your input files in the linker
4205 script, and then invoke the linker with nothing but a @samp{-T} option.
4207 In case a @dfn{sysroot prefix} is configured, and the filename starts
4208 with the @samp{/} character, and the script being processed was
4209 located inside the @dfn{sysroot prefix}, the filename will be looked
4210 for in the @dfn{sysroot prefix}.  The @dfn{sysroot prefix} can also be forced by specifying
4211 @code{=} as the first character in the filename path, or prefixing the
4212 filename path with @code{$SYSROOT}. See also the description of
4213 @samp{-L} in @ref{Options,,Command-line Options}.
4215 If a @dfn{sysroot prefix} is not used then the linker will try to open
4216 the file in the directory containing the linker script.  If it is not
4217 found the linker will then search the current directory.  If it is still
4218 not found the linker will search through the archive library search
4219 path.
4221 If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
4222 name to @code{lib@var{file}.a}, as with the command-line argument
4223 @samp{-l}.
4225 When you use the @code{INPUT} command in an implicit linker script, the
4226 files will be included in the link at the point at which the linker
4227 script file is included.  This can affect archive searching.
4229 @item GROUP(@var{file}, @var{file}, @dots{})
4230 @itemx GROUP(@var{file} @var{file} @dots{})
4231 @kindex GROUP(@var{files})
4232 @cindex grouping input files
4233 The @code{GROUP} command is like @code{INPUT}, except that the named
4234 files should all be archives, and they are searched repeatedly until no
4235 new undefined references are created.  See the description of @samp{-(}
4236 in @ref{Options,,Command-line Options}.
4238 @item AS_NEEDED(@var{file}, @var{file}, @dots{})
4239 @itemx AS_NEEDED(@var{file} @var{file} @dots{})
4240 @kindex AS_NEEDED(@var{files})
4241 This construct can appear only inside of the @code{INPUT} or @code{GROUP}
4242 commands, among other filenames.  The files listed will be handled
4243 as if they appear directly in the @code{INPUT} or @code{GROUP} commands,
4244 with the exception of ELF shared libraries, that will be added only
4245 when they are actually needed.  This construct essentially enables
4246 @option{--as-needed} option for all the files listed inside of it
4247 and restores previous @option{--as-needed} resp. @option{--no-as-needed}
4248 setting afterwards.
4250 @item OUTPUT(@var{filename})
4251 @kindex OUTPUT(@var{filename})
4252 @cindex output file name in linker script
4253 The @code{OUTPUT} command names the output file.  Using
4254 @code{OUTPUT(@var{filename})} in the linker script is exactly like using
4255 @samp{-o @var{filename}} on the command line (@pxref{Options,,Command
4256 Line Options}).  If both are used, the command-line option takes
4257 precedence.
4259 You can use the @code{OUTPUT} command to define a default name for the
4260 output file other than the usual default of @file{a.out}.
4262 @item SEARCH_DIR(@var{path})
4263 @kindex SEARCH_DIR(@var{path})
4264 @cindex library search path in linker script
4265 @cindex archive search path in linker script
4266 @cindex search path in linker script
4267 The @code{SEARCH_DIR} command adds @var{path} to the list of paths where
4268 @command{ld} looks for archive libraries.  Using
4269 @code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
4270 on the command line (@pxref{Options,,Command-line Options}).  If both
4271 are used, then the linker will search both paths.  Paths specified using
4272 the command-line option are searched first.
4274 @item STARTUP(@var{filename})
4275 @kindex STARTUP(@var{filename})
4276 @cindex first input file
4277 The @code{STARTUP} command is just like the @code{INPUT} command, except
4278 that @var{filename} will become the first input file to be linked, as
4279 though it were specified first on the command line.  This may be useful
4280 when using a system in which the entry point is always the start of the
4281 first file.
4282 @end table
4284 @ifclear SingleFormat
4285 @node Format Commands
4286 @subsection Commands Dealing with Object File Formats
4287 A couple of linker script commands deal with object file formats.
4289 @table @code
4290 @item OUTPUT_FORMAT(@var{bfdname})
4291 @itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
4292 @kindex OUTPUT_FORMAT(@var{bfdname})
4293 @cindex output file format in linker script
4294 The @code{OUTPUT_FORMAT} command names the BFD format to use for the
4295 output file (@pxref{BFD}).  Using @code{OUTPUT_FORMAT(@var{bfdname})} is
4296 exactly like using @samp{--oformat @var{bfdname}} on the command line
4297 (@pxref{Options,,Command-line Options}).  If both are used, the command
4298 line option takes precedence.
4300 You can use @code{OUTPUT_FORMAT} with three arguments to use different
4301 formats based on the @samp{-EB} and @samp{-EL} command-line options.
4302 This permits the linker script to set the output format based on the
4303 desired endianness.
4305 If neither @samp{-EB} nor @samp{-EL} are used, then the output format
4306 will be the first argument, @var{default}.  If @samp{-EB} is used, the
4307 output format will be the second argument, @var{big}.  If @samp{-EL} is
4308 used, the output format will be the third argument, @var{little}.
4310 For example, the default linker script for the MIPS ELF target uses this
4311 command:
4312 @smallexample
4313 OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
4314 @end smallexample
4315 This says that the default format for the output file is
4316 @samp{elf32-bigmips}, but if the user uses the @samp{-EL} command-line
4317 option, the output file will be created in the @samp{elf32-littlemips}
4318 format.
4320 @item TARGET(@var{bfdname})
4321 @kindex TARGET(@var{bfdname})
4322 @cindex input file format in linker script
4323 The @code{TARGET} command names the BFD format to use when reading input
4324 files.  It affects subsequent @code{INPUT} and @code{GROUP} commands.
4325 This command is like using @samp{-b @var{bfdname}} on the command line
4326 (@pxref{Options,,Command-line Options}).  If the @code{TARGET} command
4327 is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
4328 command is also used to set the format for the output file.  @xref{BFD}.
4329 @end table
4330 @end ifclear
4332 @node REGION_ALIAS
4333 @subsection Assign alias names to memory regions
4334 @kindex REGION_ALIAS(@var{alias}, @var{region})
4335 @cindex region alias
4336 @cindex region names
4338 Alias names can be added to existing memory regions created with the
4339 @ref{MEMORY} command.  Each name corresponds to at most one memory region.
4341 @smallexample
4342 REGION_ALIAS(@var{alias}, @var{region})
4343 @end smallexample
4345 The @code{REGION_ALIAS} function creates an alias name @var{alias} for the
4346 memory region @var{region}.  This allows a flexible mapping of output sections
4347 to memory regions.  An example follows.
4349 Suppose we have an application for embedded systems which come with various
4350 memory storage devices.  All have a general purpose, volatile memory @code{RAM}
4351 that allows code execution or data storage.  Some may have a read-only,
4352 non-volatile memory @code{ROM} that allows code execution and read-only data
4353 access.  The last variant is a read-only, non-volatile memory @code{ROM2} with
4354 read-only data access and no code execution capability.  We have four output
4355 sections:
4357 @itemize @bullet
4358 @item
4359 @code{.text} program code;
4360 @item
4361 @code{.rodata} read-only data;
4362 @item
4363 @code{.data} read-write initialized data;
4364 @item
4365 @code{.bss} read-write zero initialized data.
4366 @end itemize
4368 The goal is to provide a linker command file that contains a system independent
4369 part defining the output sections and a system dependent part mapping the
4370 output sections to the memory regions available on the system.  Our embedded
4371 systems come with three different memory setups @code{A}, @code{B} and
4372 @code{C}:
4373 @multitable @columnfractions .25 .25 .25 .25
4374 @item Section @tab Variant A @tab Variant B @tab Variant C
4375 @item .text @tab RAM @tab ROM @tab ROM
4376 @item .rodata @tab RAM @tab ROM @tab ROM2
4377 @item .data @tab RAM @tab RAM/ROM @tab RAM/ROM2
4378 @item .bss @tab RAM @tab RAM @tab RAM
4379 @end multitable
4380 The notation @code{RAM/ROM} or @code{RAM/ROM2} means that this section is
4381 loaded into region @code{ROM} or @code{ROM2} respectively.  Please note that
4382 the load address of the @code{.data} section starts in all three variants at
4383 the end of the @code{.rodata} section.
4385 The base linker script that deals with the output sections follows.  It
4386 includes the system dependent @code{linkcmds.memory} file that describes the
4387 memory layout:
4388 @smallexample
4389 INCLUDE linkcmds.memory
4391 SECTIONS
4392   @{
4393     .text :
4394       @{
4395         *(.text)
4396       @} > REGION_TEXT
4397     .rodata :
4398       @{
4399         *(.rodata)
4400         rodata_end = .;
4401       @} > REGION_RODATA
4402     .data : AT (rodata_end)
4403       @{
4404         data_start = .;
4405         *(.data)
4406       @} > REGION_DATA
4407     data_size = SIZEOF(.data);
4408     data_load_start = LOADADDR(.data);
4409     .bss :
4410       @{
4411         *(.bss)
4412       @} > REGION_BSS
4413   @}
4414 @end smallexample
4416 Now we need three different @code{linkcmds.memory} files to define memory
4417 regions and alias names.  The content of @code{linkcmds.memory} for the three
4418 variants @code{A}, @code{B} and @code{C}:
4419 @table @code
4420 @item A
4421 Here everything goes into the @code{RAM}.
4422 @smallexample
4423 MEMORY
4424   @{
4425     RAM : ORIGIN = 0, LENGTH = 4M
4426   @}
4428 REGION_ALIAS("REGION_TEXT", RAM);
4429 REGION_ALIAS("REGION_RODATA", RAM);
4430 REGION_ALIAS("REGION_DATA", RAM);
4431 REGION_ALIAS("REGION_BSS", RAM);
4432 @end smallexample
4433 @item B
4434 Program code and read-only data go into the @code{ROM}.  Read-write data goes
4435 into the @code{RAM}.  An image of the initialized data is loaded into the
4436 @code{ROM} and will be copied during system start into the @code{RAM}.
4437 @smallexample
4438 MEMORY
4439   @{
4440     ROM : ORIGIN = 0, LENGTH = 3M
4441     RAM : ORIGIN = 0x10000000, LENGTH = 1M
4442   @}
4444 REGION_ALIAS("REGION_TEXT", ROM);
4445 REGION_ALIAS("REGION_RODATA", ROM);
4446 REGION_ALIAS("REGION_DATA", RAM);
4447 REGION_ALIAS("REGION_BSS", RAM);
4448 @end smallexample
4449 @item C
4450 Program code goes into the @code{ROM}.  Read-only data goes into the
4451 @code{ROM2}.  Read-write data goes into the @code{RAM}.  An image of the
4452 initialized data is loaded into the @code{ROM2} and will be copied during
4453 system start into the @code{RAM}.
4454 @smallexample
4455 MEMORY
4456   @{
4457     ROM : ORIGIN = 0, LENGTH = 2M
4458     ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
4459     RAM : ORIGIN = 0x20000000, LENGTH = 1M
4460   @}
4462 REGION_ALIAS("REGION_TEXT", ROM);
4463 REGION_ALIAS("REGION_RODATA", ROM2);
4464 REGION_ALIAS("REGION_DATA", RAM);
4465 REGION_ALIAS("REGION_BSS", RAM);
4466 @end smallexample
4467 @end table
4469 It is possible to write a common system initialization routine to copy the
4470 @code{.data} section from @code{ROM} or @code{ROM2} into the @code{RAM} if
4471 necessary:
4472 @smallexample
4473 #include <string.h>
4475 extern char data_start [];
4476 extern char data_size [];
4477 extern char data_load_start [];
4479 void copy_data(void)
4481   if (data_start != data_load_start)
4482     @{
4483       memcpy(data_start, data_load_start, (size_t) data_size);
4484     @}
4486 @end smallexample
4488 @node Miscellaneous Commands
4489 @subsection Other Linker Script Commands
4490 There are a few other linker scripts commands.
4492 @table @code
4493 @item ASSERT(@var{exp}, @var{message})
4494 @kindex ASSERT
4495 @cindex assertion in linker script
4496 Ensure that @var{exp} is non-zero.  If it is zero, then exit the linker
4497 with an error code, and print @var{message}.
4499 Note that assertions are checked before the final stages of linking
4500 take place.  This means that expressions involving symbols PROVIDEd
4501 inside section definitions will fail if the user has not set values
4502 for those symbols.  The only exception to this rule is PROVIDEd
4503 symbols that just reference dot.  Thus an assertion like this:
4505 @smallexample
4506   .stack :
4507   @{
4508     PROVIDE (__stack = .);
4509     PROVIDE (__stack_size = 0x100);
4510     ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4511   @}
4512 @end smallexample
4514 will fail if @code{__stack_size} is not defined elsewhere.  Symbols
4515 PROVIDEd outside of section definitions are evaluated earlier, so they
4516 can be used inside ASSERTions.  Thus:
4518 @smallexample
4519   PROVIDE (__stack_size = 0x100);
4520   .stack :
4521   @{
4522     PROVIDE (__stack = .);
4523     ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4524   @}
4525 @end smallexample
4527 will work.
4529 @item EXTERN(@var{symbol} @var{symbol} @dots{})
4530 @kindex EXTERN
4531 @cindex undefined symbol in linker script
4532 Force @var{symbol} to be entered in the output file as an undefined
4533 symbol.  Doing this may, for example, trigger linking of additional
4534 modules from standard libraries.  You may list several @var{symbol}s for
4535 each @code{EXTERN}, and you may use @code{EXTERN} multiple times.  This
4536 command has the same effect as the @samp{-u} command-line option.
4538 @item FORCE_COMMON_ALLOCATION
4539 @kindex FORCE_COMMON_ALLOCATION
4540 @cindex common allocation in linker script
4541 This command has the same effect as the @samp{-d} command-line option:
4542 to make @command{ld} assign space to common symbols even if a relocatable
4543 output file is specified (@samp{-r}).
4545 @item INHIBIT_COMMON_ALLOCATION
4546 @kindex INHIBIT_COMMON_ALLOCATION
4547 @cindex common allocation in linker script
4548 This command has the same effect as the @samp{--no-define-common}
4549 command-line option: to make @code{ld} omit the assignment of addresses
4550 to common symbols even for a non-relocatable output file.
4552 @item FORCE_GROUP_ALLOCATION
4553 @kindex FORCE_GROUP_ALLOCATION
4554 @cindex group allocation in linker script
4555 @cindex section groups
4556 @cindex COMDAT
4557 This command has the same effect as the
4558 @samp{--force-group-allocation} command-line option: to make
4559 @command{ld} place section group members like normal input sections,
4560 and to delete the section groups even if a relocatable output file is
4561 specified (@samp{-r}).
4563 @item INSERT [ AFTER | BEFORE ] @var{output_section}
4564 @kindex INSERT
4565 @cindex insert user script into default script
4566 This command is typically used in a script specified by @samp{-T} to
4567 augment the default @code{SECTIONS} with, for example, overlays.  It
4568 inserts all prior linker script statements after (or before)
4569 @var{output_section}, and also causes @samp{-T} to not override the
4570 default linker script.  The exact insertion point is as for orphan
4571 sections.  @xref{Location Counter}.  The insertion happens after the
4572 linker has mapped input sections to output sections.  Prior to the
4573 insertion, since @samp{-T} scripts are parsed before the default
4574 linker script, statements in the @samp{-T} script occur before the
4575 default linker script statements in the internal linker representation
4576 of the script.  In particular, input section assignments will be made
4577 to @samp{-T} output sections before those in the default script.  Here
4578 is an example of how a @samp{-T} script using @code{INSERT} might look:
4580 @smallexample
4581 SECTIONS
4583   OVERLAY :
4584   @{
4585     .ov1 @{ ov1*(.text) @}
4586     .ov2 @{ ov2*(.text) @}
4587   @}
4589 INSERT AFTER .text;
4590 @end smallexample
4592 Note that when @samp{-T} is used twice, once to override the default
4593 script and once to augment that script using @code{INSERT} the order
4594 of parsing and section assignments apply as for the default script.
4595 The script with @code{INSERT} should be specified @emph{first} on the
4596 command line.
4598 @item NOCROSSREFS(@var{section} @var{section} @dots{})
4599 @kindex NOCROSSREFS(@var{sections})
4600 @cindex cross references
4601 This command may be used to tell @command{ld} to issue an error about any
4602 references among certain output sections.
4604 In certain types of programs, particularly on embedded systems when
4605 using overlays, when one section is loaded into memory, another section
4606 will not be.  Any direct references between the two sections would be
4607 errors.  For example, it would be an error if code in one section called
4608 a function defined in the other section.
4610 The @code{NOCROSSREFS} command takes a list of output section names.  If
4611 @command{ld} detects any cross references between the sections, it reports
4612 an error and returns a non-zero exit status.  Note that the
4613 @code{NOCROSSREFS} command uses output section names, not input section
4614 names.
4616 @item NOCROSSREFS_TO(@var{tosection} @var{fromsection} @dots{})
4617 @kindex NOCROSSREFS_TO(@var{tosection} @var{fromsections})
4618 @cindex cross references
4619 This command may be used to tell @command{ld} to issue an error about any
4620 references to one section from a list of other sections.
4622 The @code{NOCROSSREFS} command is useful when ensuring that two or more
4623 output sections are entirely independent but there are situations where
4624 a one-way dependency is needed. For example, in a multi-core application
4625 there may be shared code that can be called from each core but for safety
4626 must never call back.
4628 The @code{NOCROSSREFS_TO} command takes a list of output section names.
4629 The first section can not be referenced from any of the other sections.
4630 If @command{ld} detects any references to the first section from any of
4631 the other sections, it reports an error and returns a non-zero exit
4632 status.  Note that the @code{NOCROSSREFS_TO} command uses output section
4633 names, not input section names.
4635 @ifclear SingleFormat
4636 @item OUTPUT_ARCH(@var{bfdarch})
4637 @kindex OUTPUT_ARCH(@var{bfdarch})
4638 @cindex machine architecture
4639 @cindex architecture
4640 Specify a particular output machine architecture.  The argument is one
4641 of the names used by the BFD library (@pxref{BFD}).  You can see the
4642 architecture of an object file by using the @code{objdump} program with
4643 the @samp{-f} option.
4644 @end ifclear
4646 @item LD_FEATURE(@var{string})
4647 @kindex LD_FEATURE(@var{string})
4648 This command may be used to modify @command{ld} behavior.  If
4649 @var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
4650 in a script are simply treated as numbers everywhere.
4651 @xref{Expression Section}.
4652 @end table
4654 @node Assignments
4655 @section Assigning Values to Symbols
4656 @cindex assignment in scripts
4657 @cindex symbol definition, scripts
4658 @cindex variables, defining
4659 You may assign a value to a symbol in a linker script.  This will define
4660 the symbol and place it into the symbol table with a global scope.
4662 @menu
4663 * Simple Assignments::          Simple Assignments
4664 * HIDDEN::                      HIDDEN
4665 * PROVIDE::                     PROVIDE
4666 * PROVIDE_HIDDEN::              PROVIDE_HIDDEN
4667 * Source Code Reference::       How to use a linker script defined symbol in source code
4668 @end menu
4670 @node Simple Assignments
4671 @subsection Simple Assignments
4673 You may assign to a symbol using any of the C assignment operators:
4675 @table @code
4676 @item @var{symbol} = @var{expression} ;
4677 @itemx @var{symbol} += @var{expression} ;
4678 @itemx @var{symbol} -= @var{expression} ;
4679 @itemx @var{symbol} *= @var{expression} ;
4680 @itemx @var{symbol} /= @var{expression} ;
4681 @itemx @var{symbol} <<= @var{expression} ;
4682 @itemx @var{symbol} >>= @var{expression} ;
4683 @itemx @var{symbol} &= @var{expression} ;
4684 @itemx @var{symbol} |= @var{expression} ;
4685 @end table
4687 The first case will define @var{symbol} to the value of
4688 @var{expression}.  In the other cases, @var{symbol} must already be
4689 defined, and the value will be adjusted accordingly.
4691 The special symbol name @samp{.} indicates the location counter.  You
4692 may only use this within a @code{SECTIONS} command.  @xref{Location Counter}.
4694 The semicolon after @var{expression} is required.
4696 Expressions are defined below; see @ref{Expressions}.
4698 You may write symbol assignments as commands in their own right, or as
4699 statements within a @code{SECTIONS} command, or as part of an output
4700 section description in a @code{SECTIONS} command.
4702 The section of the symbol will be set from the section of the
4703 expression; for more information, see @ref{Expression Section}.
4705 Here is an example showing the three different places that symbol
4706 assignments may be used:
4708 @smallexample
4709 floating_point = 0;
4710 SECTIONS
4712   .text :
4713     @{
4714       *(.text)
4715       _etext = .;
4716     @}
4717   _bdata = (. + 3) & ~ 3;
4718   .data : @{ *(.data) @}
4720 @end smallexample
4721 @noindent
4722 In this example, the symbol @samp{floating_point} will be defined as
4723 zero.  The symbol @samp{_etext} will be defined as the address following
4724 the last @samp{.text} input section.  The symbol @samp{_bdata} will be
4725 defined as the address following the @samp{.text} output section aligned
4726 upward to a 4 byte boundary.
4728 @node HIDDEN
4729 @subsection HIDDEN
4730 @cindex HIDDEN
4731 For ELF targeted ports, define a symbol that will be hidden and won't be
4732 exported.  The syntax is @code{HIDDEN(@var{symbol} = @var{expression})}.
4734 Here is the example from @ref{Simple Assignments}, rewritten to use
4735 @code{HIDDEN}:
4737 @smallexample
4738 HIDDEN(floating_point = 0);
4739 SECTIONS
4741   .text :
4742     @{
4743       *(.text)
4744       HIDDEN(_etext = .);
4745     @}
4746   HIDDEN(_bdata = (. + 3) & ~ 3);
4747   .data : @{ *(.data) @}
4749 @end smallexample
4750 @noindent
4751 In this case none of the three symbols will be visible outside this module.
4753 @node PROVIDE
4754 @subsection PROVIDE
4755 @cindex PROVIDE
4756 In some cases, it is desirable for a linker script to define a symbol
4757 only if it is referenced and is not defined by any object included in
4758 the link.  For example, traditional linkers defined the symbol
4759 @samp{etext}.  However, ANSI C requires that the user be able to use
4760 @samp{etext} as a function name without encountering an error.  The
4761 @code{PROVIDE} keyword may be used to define a symbol, such as
4762 @samp{etext}, only if it is referenced but not defined.  The syntax is
4763 @code{PROVIDE(@var{symbol} = @var{expression})}.
4765 Here is an example of using @code{PROVIDE} to define @samp{etext}:
4766 @smallexample
4767 SECTIONS
4769   .text :
4770     @{
4771       *(.text)
4772       _etext = .;
4773       PROVIDE(etext = .);
4774     @}
4776 @end smallexample
4778 In this example, if the program defines @samp{_etext} (with a leading
4779 underscore), the linker will give a multiple definition diagnostic.  If,
4780 on the other hand, the program defines @samp{etext} (with no leading
4781 underscore), the linker will silently use the definition in the program.
4782 If the program references @samp{etext} but does not define it, the
4783 linker will use the definition in the linker script.
4785 Note - the @code{PROVIDE} directive considers a common symbol to be
4786 defined, even though such a symbol could be combined with the symbol
4787 that the @code{PROVIDE} would create.  This is particularly important
4788 when considering constructor and destructor list symbols such as
4789 @samp{__CTOR_LIST__} as these are often defined as common symbols.
4791 @node PROVIDE_HIDDEN
4792 @subsection PROVIDE_HIDDEN
4793 @cindex PROVIDE_HIDDEN
4794 Similar to @code{PROVIDE}.  For ELF targeted ports, the symbol will be
4795 hidden and won't be exported.
4797 @node Source Code Reference
4798 @subsection Source Code Reference
4800 Accessing a linker script defined variable from source code is not
4801 intuitive.  In particular a linker script symbol is not equivalent to
4802 a variable declaration in a high level language, it is instead a
4803 symbol that does not have a value.
4805 Before going further, it is important to note that compilers often
4806 transform names in the source code into different names when they are
4807 stored in the symbol table.  For example, Fortran compilers commonly
4808 prepend or append an underscore, and C++ performs extensive @samp{name
4809 mangling}.  Therefore there might be a discrepancy between the name
4810 of a variable as it is used in source code and the name of the same
4811 variable as it is defined in a linker script.  For example in C a
4812 linker script variable might be referred to as:
4814 @smallexample
4815   extern int foo;
4816 @end smallexample
4818 But in the linker script it might be defined as:
4820 @smallexample
4821   _foo = 1000;
4822 @end smallexample
4824 In the remaining examples however it is assumed that no name
4825 transformation has taken place.
4827 When a symbol is declared in a high level language such as C, two
4828 things happen.  The first is that the compiler reserves enough space
4829 in the program's memory to hold the @emph{value} of the symbol.  The
4830 second is that the compiler creates an entry in the program's symbol
4831 table which holds the symbol's @emph{address}.  ie the symbol table
4832 contains the address of the block of memory holding the symbol's
4833 value.  So for example the following C declaration, at file scope:
4835 @smallexample
4836   int foo = 1000;
4837 @end smallexample
4839 creates an entry called @samp{foo} in the symbol table.  This entry
4840 holds the address of an @samp{int} sized block of memory where the
4841 number 1000 is initially stored.
4843 When a program references a symbol the compiler generates code that
4844 first accesses the symbol table to find the address of the symbol's
4845 memory block and then code to read the value from that memory block.
4848 @smallexample
4849   foo = 1;
4850 @end smallexample
4852 looks up the symbol @samp{foo} in the symbol table, gets the address
4853 associated with this symbol and then writes the value 1 into that
4854 address.  Whereas:
4856 @smallexample
4857   int * a = & foo;
4858 @end smallexample
4860 looks up the symbol @samp{foo} in the symbol table, gets its address
4861 and then copies this address into the block of memory associated with
4862 the variable @samp{a}.
4864 Linker scripts symbol declarations, by contrast, create an entry in
4865 the symbol table but do not assign any memory to them.  Thus they are
4866 an address without a value.  So for example the linker script definition:
4868 @smallexample
4869   foo = 1000;
4870 @end smallexample
4872 creates an entry in the symbol table called @samp{foo} which holds
4873 the address of memory location 1000, but nothing special is stored at
4874 address 1000.  This means that you cannot access the @emph{value} of a
4875 linker script defined symbol - it has no value - all you can do is
4876 access the @emph{address} of a linker script defined symbol.
4878 Hence when you are using a linker script defined symbol in source code
4879 you should always take the address of the symbol, and never attempt to
4880 use its value.  For example suppose you want to copy the contents of a
4881 section of memory called .ROM into a section called .FLASH and the
4882 linker script contains these declarations:
4884 @smallexample
4885 @group
4886   start_of_ROM   = .ROM;
4887   end_of_ROM     = .ROM + sizeof (.ROM);
4888   start_of_FLASH = .FLASH;
4889 @end group
4890 @end smallexample
4892 Then the C source code to perform the copy would be:
4894 @smallexample
4895 @group
4896   extern char start_of_ROM, end_of_ROM, start_of_FLASH;
4898   memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
4899 @end group
4900 @end smallexample
4902 Note the use of the @samp{&} operators.  These are correct.
4903 Alternatively the symbols can be treated as the names of vectors or
4904 arrays and then the code will again work as expected:
4906 @smallexample
4907 @group
4908   extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
4910   memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
4911 @end group
4912 @end smallexample
4914 Note how using this method does not require the use of @samp{&}
4915 operators.
4917 @node SECTIONS
4918 @section SECTIONS Command
4919 @kindex SECTIONS
4920 The @code{SECTIONS} command tells the linker how to map input sections
4921 into output sections, and how to place the output sections in memory.
4923 The format of the @code{SECTIONS} command is:
4924 @smallexample
4925 SECTIONS
4927   @var{sections-command}
4928   @var{sections-command}
4929   @dots{}
4931 @end smallexample
4933 Each @var{sections-command} may of be one of the following:
4935 @itemize @bullet
4936 @item
4937 an @code{ENTRY} command (@pxref{Entry Point,,Entry command})
4938 @item
4939 a symbol assignment (@pxref{Assignments})
4940 @item
4941 an output section description
4942 @item
4943 an overlay description
4944 @end itemize
4946 The @code{ENTRY} command and symbol assignments are permitted inside the
4947 @code{SECTIONS} command for convenience in using the location counter in
4948 those commands.  This can also make the linker script easier to
4949 understand because you can use those commands at meaningful points in
4950 the layout of the output file.
4952 Output section descriptions and overlay descriptions are described
4953 below.
4955 If you do not use a @code{SECTIONS} command in your linker script, the
4956 linker will place each input section into an identically named output
4957 section in the order that the sections are first encountered in the
4958 input files.  If all input sections are present in the first file, for
4959 example, the order of sections in the output file will match the order
4960 in the first input file.  The first section will be at address zero.
4962 @menu
4963 * Output Section Description::  Output section description
4964 * Output Section Name::         Output section name
4965 * Output Section Address::      Output section address
4966 * Input Section::               Input section description
4967 * Output Section Data::         Output section data
4968 * Output Section Keywords::     Output section keywords
4969 * Output Section Discarding::   Output section discarding
4970 * Output Section Attributes::   Output section attributes
4971 * Overlay Description::         Overlay description
4972 @end menu
4974 @node Output Section Description
4975 @subsection Output Section Description
4976 The full description of an output section looks like this:
4977 @smallexample
4978 @group
4979 @var{section} [@var{address}] [(@var{type})] :
4980   [AT(@var{lma})]
4981   [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
4982   [SUBALIGN(@var{subsection_align})]
4983   [@var{constraint}]
4984   @{
4985     @var{output-section-command}
4986     @var{output-section-command}
4987     @dots{}
4988   @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] [,]
4989 @end group
4990 @end smallexample
4992 Most output sections do not use most of the optional section attributes.
4994 The whitespace around @var{section} is required, so that the section
4995 name is unambiguous.  The colon and the curly braces are also required.
4996 The comma at the end may be required if a @var{fillexp} is used and
4997 the next @var{sections-command} looks like a continuation of the expression.
4998 The line breaks and other white space are optional.
5000 Each @var{output-section-command} may be one of the following:
5002 @itemize @bullet
5003 @item
5004 a symbol assignment (@pxref{Assignments})
5005 @item
5006 an input section description (@pxref{Input Section})
5007 @item
5008 data values to include directly (@pxref{Output Section Data})
5009 @item
5010 a special output section keyword (@pxref{Output Section Keywords})
5011 @end itemize
5013 @node Output Section Name
5014 @subsection Output Section Name
5015 @cindex name, section
5016 @cindex section name
5017 The name of the output section is @var{section}.  @var{section} must
5018 meet the constraints of your output format.  In formats which only
5019 support a limited number of sections, such as @code{a.out}, the name
5020 must be one of the names supported by the format (@code{a.out}, for
5021 example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
5022 output format supports any number of sections, but with numbers and not
5023 names (as is the case for Oasys), the name should be supplied as a
5024 quoted numeric string.  A section name may consist of any sequence of
5025 characters, but a name which contains any unusual characters such as
5026 commas must be quoted.
5028 The output section name @samp{/DISCARD/} is special; @ref{Output Section
5029 Discarding}.
5031 @node Output Section Address
5032 @subsection Output Section Address
5033 @cindex address, section
5034 @cindex section address
5035 The @var{address} is an expression for the VMA (the virtual memory
5036 address) of the output section.  This address is optional, but if it
5037 is provided then the output address will be set exactly as specified.
5039 If the output address is not specified then one will be chosen for the
5040 section, based on the heuristic below.  This address will be adjusted
5041 to fit the alignment requirement of the output section.  The
5042 alignment requirement is the strictest alignment of any input section
5043 contained within the output section.
5045 The output section address heuristic is as follows:
5047 @itemize @bullet
5048 @item
5049 If an output memory @var{region} is set for the section then it
5050 is added to this region and its address will be the next free address
5051 in that region.
5053 @item
5054 If the MEMORY command has been used to create a list of memory
5055 regions then the first region which has attributes compatible with the
5056 section is selected to contain it.  The section's output address will
5057 be the next free address in that region; @ref{MEMORY}.
5059 @item
5060 If no memory regions were specified, or none match the section then
5061 the output address will be based on the current value of the location
5062 counter.
5063 @end itemize
5065 @noindent
5066 For example:
5068 @smallexample
5069 .text . : @{ *(.text) @}
5070 @end smallexample
5072 @noindent
5075 @smallexample
5076 .text : @{ *(.text) @}
5077 @end smallexample
5079 @noindent
5080 are subtly different.  The first will set the address of the
5081 @samp{.text} output section to the current value of the location
5082 counter.  The second will set it to the current value of the location
5083 counter aligned to the strictest alignment of any of the @samp{.text}
5084 input sections.
5086 The @var{address} may be an arbitrary expression; @ref{Expressions}.
5087 For example, if you want to align the section on a 0x10 byte boundary,
5088 so that the lowest four bits of the section address are zero, you could
5089 do something like this:
5090 @smallexample
5091 .text ALIGN(0x10) : @{ *(.text) @}
5092 @end smallexample
5093 @noindent
5094 This works because @code{ALIGN} returns the current location counter
5095 aligned upward to the specified value.
5097 Specifying @var{address} for a section will change the value of the
5098 location counter, provided that the section is non-empty.  (Empty
5099 sections are ignored).
5101 @node Input Section
5102 @subsection Input Section Description
5103 @cindex input sections
5104 @cindex mapping input sections to output sections
5105 The most common output section command is an input section description.
5107 The input section description is the most basic linker script operation.
5108 You use output sections to tell the linker how to lay out your program
5109 in memory.  You use input section descriptions to tell the linker how to
5110 map the input files into your memory layout.
5112 @menu
5113 * Input Section Basics::        Input section basics
5114 * Input Section Wildcards::     Input section wildcard patterns
5115 * Input Section Common::        Input section for common symbols
5116 * Input Section Keep::          Input section and garbage collection
5117 * Input Section Example::       Input section example
5118 @end menu
5120 @node Input Section Basics
5121 @subsubsection Input Section Basics
5122 @cindex input section basics
5123 An input section description consists of a file name optionally followed
5124 by a list of section names in parentheses.
5126 The file name and the section name may be wildcard patterns, which we
5127 describe further below (@pxref{Input Section Wildcards}).
5129 The most common input section description is to include all input
5130 sections with a particular name in the output section.  For example, to
5131 include all input @samp{.text} sections, you would write:
5132 @smallexample
5133 *(.text)
5134 @end smallexample
5135 @noindent
5136 Here the @samp{*} is a wildcard which matches any file name.  To exclude a list
5137 @cindex EXCLUDE_FILE
5138 of files from matching the file name wildcard, EXCLUDE_FILE may be used to
5139 match all files except the ones specified in the EXCLUDE_FILE list.  For
5140 example:
5141 @smallexample
5142 EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
5143 @end smallexample
5144 @noindent
5145 will cause all .ctors sections from all files except @file{crtend.o}
5146 and @file{otherfile.o} to be included.  The EXCLUDE_FILE can also be
5147 placed inside the section list, for example:
5148 @smallexample
5149 *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
5150 @end smallexample
5151 @noindent
5152 The result of this is identically to the previous example.  Supporting
5153 two syntaxes for EXCLUDE_FILE is useful if the section list contains
5154 more than one section, as described below.
5156 There are two ways to include more than one section:
5157 @smallexample
5158 *(.text .rdata)
5159 *(.text) *(.rdata)
5160 @end smallexample
5161 @noindent
5162 The difference between these is the order in which the @samp{.text} and
5163 @samp{.rdata} input sections will appear in the output section.  In the
5164 first example, they will be intermingled, appearing in the same order as
5165 they are found in the linker input.  In the second example, all
5166 @samp{.text} input sections will appear first, followed by all
5167 @samp{.rdata} input sections.
5169 When using EXCLUDE_FILE with more than one section, if the exclusion
5170 is within the section list then the exclusion only applies to the
5171 immediately following section, for example:
5172 @smallexample
5173 *(EXCLUDE_FILE (*somefile.o) .text .rdata)
5174 @end smallexample
5175 @noindent
5176 will cause all @samp{.text} sections from all files except
5177 @file{somefile.o} to be included, while all @samp{.rdata} sections
5178 from all files, including @file{somefile.o}, will be included.  To
5179 exclude the @samp{.rdata} sections from @file{somefile.o} the example
5180 could be modified to:
5181 @smallexample
5182 *(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
5183 @end smallexample
5184 @noindent
5185 Alternatively, placing the EXCLUDE_FILE outside of the section list,
5186 before the input file selection, will cause the exclusion to apply for
5187 all sections.  Thus the previous example can be rewritten as:
5188 @smallexample
5189 EXCLUDE_FILE (*somefile.o) *(.text .rdata)
5190 @end smallexample
5192 You can specify a file name to include sections from a particular file.
5193 You would do this if one or more of your files contain special data that
5194 needs to be at a particular location in memory.  For example:
5195 @smallexample
5196 data.o(.data)
5197 @end smallexample
5199 To refine the sections that are included based on the section flags
5200 of an input section, INPUT_SECTION_FLAGS may be used.
5202 Here is a simple example for using Section header flags for ELF sections:
5204 @smallexample
5205 @group
5206 SECTIONS @{
5207   .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @}
5208   .text2 :  @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @}
5210 @end group
5211 @end smallexample
5213 In this example, the output section @samp{.text} will be comprised of any
5214 input section matching the name *(.text) whose section header flags
5215 @code{SHF_MERGE} and @code{SHF_STRINGS} are set.  The output section
5216 @samp{.text2} will be comprised of any input section matching the name *(.text)
5217 whose section header flag @code{SHF_WRITE} is clear.
5219 You can also specify files within archives by writing a pattern
5220 matching the archive, a colon, then the pattern matching the file,
5221 with no whitespace around the colon.
5223 @table @samp
5224 @item archive:file
5225 matches file within archive
5226 @item archive:
5227 matches the whole archive
5228 @item :file
5229 matches file but not one in an archive
5230 @end table
5232 Either one or both of @samp{archive} and @samp{file} can contain shell
5233 wildcards.  On DOS based file systems, the linker will assume that a
5234 single letter followed by a colon is a drive specifier, so
5235 @samp{c:myfile.o} is a simple file specification, not @samp{myfile.o}
5236 within an archive called @samp{c}.  @samp{archive:file} filespecs may
5237 also be used within an @code{EXCLUDE_FILE} list, but may not appear in
5238 other linker script contexts.  For instance, you cannot extract a file
5239 from an archive by using @samp{archive:file} in an @code{INPUT}
5240 command.
5242 If you use a file name without a list of sections, then all sections in
5243 the input file will be included in the output section.  This is not
5244 commonly done, but it may by useful on occasion.  For example:
5245 @smallexample
5246 data.o
5247 @end smallexample
5249 When you use a file name which is not an @samp{archive:file} specifier
5250 and does not contain any wild card
5251 characters, the linker will first see if you also specified the file
5252 name on the linker command line or in an @code{INPUT} command.  If you
5253 did not, the linker will attempt to open the file as an input file, as
5254 though it appeared on the command line.  Note that this differs from an
5255 @code{INPUT} command, because the linker will not search for the file in
5256 the archive search path.
5258 @node Input Section Wildcards
5259 @subsubsection Input Section Wildcard Patterns
5260 @cindex input section wildcards
5261 @cindex wildcard file name patterns
5262 @cindex file name wildcard patterns
5263 @cindex section name wildcard patterns
5264 In an input section description, either the file name or the section
5265 name or both may be wildcard patterns.
5267 The file name of @samp{*} seen in many examples is a simple wildcard
5268 pattern for the file name.
5270 The wildcard patterns are like those used by the Unix shell.
5272 @table @samp
5273 @item *
5274 matches any number of characters
5275 @item ?
5276 matches any single character
5277 @item [@var{chars}]
5278 matches a single instance of any of the @var{chars}; the @samp{-}
5279 character may be used to specify a range of characters, as in
5280 @samp{[a-z]} to match any lower case letter
5281 @item \
5282 quotes the following character
5283 @end table
5285 File name wildcard patterns only match files which are explicitly
5286 specified on the command line or in an @code{INPUT} command.  The linker
5287 does not search directories to expand wildcards.
5289 If a file name matches more than one wildcard pattern, or if a file name
5290 appears explicitly and is also matched by a wildcard pattern, the linker
5291 will use the first match in the linker script.  For example, this
5292 sequence of input section descriptions is probably in error, because the
5293 @file{data.o} rule will not be used:
5294 @smallexample
5295 .data : @{ *(.data) @}
5296 .data1 : @{ data.o(.data) @}
5297 @end smallexample
5299 @cindex SORT_BY_NAME
5300 Normally, the linker will place files and sections matched by wildcards
5301 in the order in which they are seen during the link.  You can change
5302 this by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
5303 pattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}).  When the
5304 @code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
5305 into ascending order by name before placing them in the output file.
5307 @cindex SORT_BY_ALIGNMENT
5308 @code{SORT_BY_ALIGNMENT} is similar to @code{SORT_BY_NAME}.
5309 @code{SORT_BY_ALIGNMENT} will sort sections into descending order of
5310 alignment before placing them in the output file.  Placing larger
5311 alignments before smaller alignments can reduce the amount of padding
5312 needed.
5314 @cindex SORT_BY_INIT_PRIORITY
5315 @code{SORT_BY_INIT_PRIORITY} is also similar to @code{SORT_BY_NAME}.
5316 @code{SORT_BY_INIT_PRIORITY} will sort sections into ascending
5317 numerical order of the GCC init_priority attribute encoded in the
5318 section name before placing them in the output file.  In
5319 @code{.init_array.NNNNN} and @code{.fini_array.NNNNN}, @code{NNNNN} is
5320 the init_priority.  In @code{.ctors.NNNNN} and @code{.dtors.NNNNN},
5321 @code{NNNNN} is 65535 minus the init_priority.
5323 @cindex SORT
5324 @code{SORT} is an alias for @code{SORT_BY_NAME}.
5326 @cindex REVERSE
5327 @code{REVERSE} indicates that the sorting should be reversed.  If used
5328 on its own then @code{REVERSE} implies @code{SORT_BY_NAME}, otherwise
5329 it reverses the enclosed @code{SORT..} command.  Note - reverse
5330 sorting of alignment is not currently supported.
5332 Note - the sorting commands only accept a single wildcard pattern.  So
5333 for example the following will not work:
5334 @smallexample
5335   *(REVERSE(.text* .init*))
5336 @end smallexample
5337 To resolve this problem list the patterns individually, like this:
5338 @smallexample
5339   *(REVERSE(.text*))
5340   *(REVERSE(.init*))
5341 @end smallexample
5343 Note - you can put the @code{EXCLUDE_FILE} command inside a sorting
5344 command, but not the other way around.  So for example:
5345 @smallexample
5346   *(SORT_BY_NAME(EXCLUDE_FILE(foo) .text*))
5347 @end smallexample
5348 will work, but:
5349 @smallexample
5350   *(EXCLUDE_FILE(foo) SORT_BY_NAME(.text*))
5351 @end smallexample
5352 will not.
5355 When there are nested section sorting commands in linker script, there
5356 can be at most 1 level of nesting for section sorting commands.
5358 @enumerate
5359 @item
5360 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5361 It will sort the input sections by name first, then by alignment if two
5362 sections have the same name.
5363 @item
5364 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5365 It will sort the input sections by alignment first, then by name if two
5366 sections have the same alignment.
5367 @item
5368 @code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is
5369 treated the same as @code{SORT_BY_NAME} (wildcard section pattern).
5370 @item
5371 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
5372 is treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
5373 @item
5374 @code{SORT_BY_NAME} (@code{REVERSE} (wildcard section pattern))
5375 reverse sorts by name.
5376 @item
5377 @code{REVERSE} (@code{SORT_BY_NAME} (wildcard section pattern))
5378 reverse sorts by name.
5379 @item
5380 @code{SORT_BY_INIT_PRIORITY} (@code{REVERSE} (wildcard section pattern))
5381 reverse sorts by init priority.
5382 @item
5383 All other nested section sorting commands are invalid.
5384 @end enumerate
5386 When both command-line section sorting option and linker script
5387 section sorting command are used, section sorting command always
5388 takes precedence over the command-line option.
5390 If the section sorting command in linker script isn't nested, the
5391 command-line option will make the section sorting command to be
5392 treated as nested sorting command.
5394 @enumerate
5395 @item
5396 @code{SORT_BY_NAME} (wildcard section pattern ) with
5397 @option{--sort-sections alignment} is equivalent to
5398 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5399 @item
5400 @code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
5401 @option{--sort-section name} is equivalent to
5402 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5403 @end enumerate
5405 If the section sorting command in linker script is nested, the
5406 command-line option will be ignored.
5408 @cindex SORT_NONE
5409 @code{SORT_NONE} disables section sorting by ignoring the command-line
5410 section sorting option.
5412 If you ever get confused about where input sections are going, use the
5413 @samp{-M} linker option to generate a map file.  The map file shows
5414 precisely how input sections are mapped to output sections.
5416 This example shows how wildcard patterns might be used to partition
5417 files.  This linker script directs the linker to place all @samp{.text}
5418 sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
5419 The linker will place the @samp{.data} section from all files beginning
5420 with an upper case character in @samp{.DATA}; for all other files, the
5421 linker will place the @samp{.data} section in @samp{.data}.
5422 @smallexample
5423 @group
5424 SECTIONS @{
5425   .text : @{ *(.text) @}
5426   .DATA : @{ [A-Z]*(.data) @}
5427   .data : @{ *(.data) @}
5428   .bss : @{ *(.bss) @}
5430 @end group
5431 @end smallexample
5433 @node Input Section Common
5434 @subsubsection Input Section for Common Symbols
5435 @cindex common symbol placement
5436 @cindex uninitialized data placement
5437 A special notation is needed for common symbols, because in many object
5438 file formats common symbols do not have a particular input section.  The
5439 linker treats common symbols as though they are in an input section
5440 named @samp{COMMON}.
5442 You may use file names with the @samp{COMMON} section just as with any
5443 other input sections.  You can use this to place common symbols from a
5444 particular input file in one section while common symbols from other
5445 input files are placed in another section.
5447 In most cases, common symbols in input files will be placed in the
5448 @samp{.bss} section in the output file.  For example:
5449 @smallexample
5450 .bss @{ *(.bss) *(COMMON) @}
5451 @end smallexample
5453 @cindex scommon section
5454 @cindex small common symbols
5455 Some object file formats have more than one type of common symbol.  For
5456 example, the MIPS ELF object file format distinguishes standard common
5457 symbols and small common symbols.  In this case, the linker will use a
5458 different special section name for other types of common symbols.  In
5459 the case of MIPS ELF, the linker uses @samp{COMMON} for standard common
5460 symbols and @samp{.scommon} for small common symbols.  This permits you
5461 to map the different types of common symbols into memory at different
5462 locations.
5464 @cindex [COMMON]
5465 You will sometimes see @samp{[COMMON]} in old linker scripts.  This
5466 notation is now considered obsolete.  It is equivalent to
5467 @samp{*(COMMON)}.
5469 @node Input Section Keep
5470 @subsubsection Input Section and Garbage Collection
5471 @cindex KEEP
5472 @cindex garbage collection
5473 When link-time garbage collection is in use (@samp{--gc-sections}),
5474 it is often useful to mark sections that should not be eliminated.
5475 This is accomplished by surrounding an input section's wildcard entry
5476 with @code{KEEP()}, as in @code{KEEP(*(.init))} or
5477 @code{KEEP(SORT_BY_NAME(*)(.ctors))}.
5479 @node Input Section Example
5480 @subsubsection Input Section Example
5481 The following example is a complete linker script.  It tells the linker
5482 to read all of the sections from file @file{all.o} and place them at the
5483 start of output section @samp{outputa} which starts at location
5484 @samp{0x10000}.  All of section @samp{.input1} from file @file{foo.o}
5485 follows immediately, in the same output section.  All of section
5486 @samp{.input2} from @file{foo.o} goes into output section
5487 @samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
5488 All of the remaining @samp{.input1} and @samp{.input2} sections from any
5489 files are written to output section @samp{outputc}.
5491 @smallexample
5492 @group
5493 SECTIONS @{
5494   outputa 0x10000 :
5495     @{
5496     all.o
5497     foo.o (.input1)
5498     @}
5499 @end group
5500 @group
5501   outputb :
5502     @{
5503     foo.o (.input2)
5504     foo1.o (.input1)
5505     @}
5506 @end group
5507 @group
5508   outputc :
5509     @{
5510     *(.input1)
5511     *(.input2)
5512     @}
5514 @end group
5515 @end smallexample
5517 If an output section's name is the same as the input section's name
5518 and is representable as a C identifier, then the linker will
5519 automatically @pxref{PROVIDE} two symbols: __start_SECNAME and
5520 __stop_SECNAME, where SECNAME is the name of the section.  These
5521 indicate the start address and end address of the output section
5522 respectively.  Note: most section names are not representable as
5523 C identifiers because they contain a @samp{.} character.
5525 @node Output Section Data
5526 @subsection Output Section Data
5527 @cindex data
5528 @cindex section data
5529 @cindex output section data
5530 @kindex ASCIZ ``@var{string}''
5531 @kindex BYTE(@var{expression})
5532 @kindex SHORT(@var{expression})
5533 @kindex LONG(@var{expression})
5534 @kindex QUAD(@var{expression})
5535 @kindex SQUAD(@var{expression})
5536 You can include explicit bytes of data in an output section by using
5537 @code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
5538 an output section command.  Each keyword is followed by an expression in
5539 parentheses providing the value to store (@pxref{Expressions}).  The
5540 value of the expression is stored at the current value of the location
5541 counter.
5543 The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
5544 store one, two, four, and eight bytes (respectively).  After storing the
5545 bytes, the location counter is incremented by the number of bytes
5546 stored.
5548 For example, this will store the byte 1 followed by the four byte value
5549 of the symbol @samp{addr}:
5550 @smallexample
5551 BYTE(1)
5552 LONG(addr)
5553 @end smallexample
5555 When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
5556 same; they both store an 8 byte, or 64 bit, value.  When both host and
5557 target are 32 bits, an expression is computed as 32 bits.  In this case
5558 @code{QUAD} stores a 32 bit value zero extended to 64 bits, and
5559 @code{SQUAD} stores a 32 bit value sign extended to 64 bits.
5561 If the object file format of the output file has an explicit endianness,
5562 which is the normal case, the value will be stored in that endianness.
5563 When the object file format does not have an explicit endianness, as is
5564 true of, for example, S-records, the value will be stored in the
5565 endianness of the first input object file.
5567 You can include a zero-terminated string in an output section by using
5568 @code{ASCIZ}.  The keyword is followed by a string which is stored at
5569 the current value of the location counter adding a zero byte at the
5570 end.  If the string includes spaces it must be enclosed in double
5571 quotes.  The string may contain '\n', '\r', '\t' and octal numbers.
5572 Hex numbers are not supported.
5574 For example, this string of 16 characters will create a 17 byte area
5575 @smallexample
5576   ASCIZ "This is 16 bytes"
5577 @end smallexample
5579 Note---these commands only work inside a section description and not
5580 between them, so the following will produce an error from the linker:
5581 @smallexample
5582 SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
5583 @end smallexample
5584 whereas this will work:
5585 @smallexample
5586 SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
5587 @end smallexample
5589 @kindex FILL(@var{expression})
5590 @cindex holes, filling
5591 @cindex unspecified memory
5592 You may use the @code{FILL} command to set the fill pattern for the
5593 current section.  It is followed by an expression in parentheses.  Any
5594 otherwise unspecified regions of memory within the section (for example,
5595 gaps left due to the required alignment of input sections) are filled
5596 with the value of the expression, repeated as
5597 necessary.  A @code{FILL} statement covers memory locations after the
5598 point at which it occurs in the section definition; by including more
5599 than one @code{FILL} statement, you can have different fill patterns in
5600 different parts of an output section.
5602 This example shows how to fill unspecified regions of memory with the
5603 value @samp{0x90}:
5604 @smallexample
5605 FILL(0x90909090)
5606 @end smallexample
5608 The @code{FILL} command is similar to the @samp{=@var{fillexp}} output
5609 section attribute, but it only affects the
5610 part of the section following the @code{FILL} command, rather than the
5611 entire section.  If both are used, the @code{FILL} command takes
5612 precedence.  @xref{Output Section Fill}, for details on the fill
5613 expression.
5615 Note - normally the value of @code{expression} is zero extended to 4
5616 bytes when used to fill gaps.  Thus @samp{FILL(144)} will fill a
5617 region with repeats of the pattern @samp{0 0 0 144}.  The value is
5618 treated as a big-endian number, so for example
5619 @samp{FILL(22 * 256 + 23)} will fill the region with repeats of the
5620 pattern @samp{0 0 22 23}.  If the expression results in a value with
5621 more than 4 significant bytes only the least 4 bytes of the value will
5622 be used.
5624 The above rules do not apply when the @code{expression} is a simple
5625 hexadecimal number.  In this case zero extension is not performed and
5626 all bytes are significant.  So @samp{FILL(0x90)} will fill a region with
5627 repeats of @samp{0x90} with no zero bytes, and @samp{FILL(0x9192)}
5628 will fill the region with repeats of @samp{0x91 0x92}.  Zero bytes
5629 in a hexadecimal expression are significant even at the start, so
5630 @samp{FILL(0x0090)} will fill a region with repeats of @samp{0x00 0x90}.
5632 Hexadecimal numbers can be longer than 4 bytes, and all of the bytes
5633 are significant, so @samp{FILL(0x123456789a)} will fill a region with
5634 repeats of the 5 byte sequence @samp{0x12 0x34 0x56 0x78 0x9a}.
5635 Excess bytes in a hexadecimal value beyond the size of a region will 
5636 be silently ignored.
5638 The above only applies to hexadecimal numbers specified as
5639 @samp{0x[0-9][a-f][A-F]}.  Hexadecimal numbers specified with a
5640 @samp{$} prefix, or a @samp{h}, @samp{H}, @samp{x} or @samp{X} suffix
5641 will follow the normal fill value rules.  This also applies to
5642 expressions that involve hexadecimal numbers, and hexadecimal numbers
5643 that have a magnitude suffix.
5645 @kindex LINKER_VERSION
5646 @cindex LINKER_VERSION
5647 The @code{LINKER_VERSION} command inserts a string containing the
5648 version of the linker at the current point.  Note - by default this
5649 directive is disabled and will do nothing.  It only becomes active if
5650 the @option{--enable-linker-version} command line option is used.
5652 Built-in linker scripts for ELF based targets already include this
5653 directive in their @samp{.comment} section.
5655 @node Output Section Keywords
5656 @subsection Output Section Keywords
5657 There are a couple of keywords which can appear as output section
5658 commands.
5660 @table @code
5661 @kindex CREATE_OBJECT_SYMBOLS
5662 @cindex input filename symbols
5663 @cindex filename symbols
5664 @item CREATE_OBJECT_SYMBOLS
5665 The command tells the linker to create a symbol for each input file.
5666 The name of each symbol will be the name of the corresponding input
5667 file.  The section of each symbol will be the output section in which
5668 the @code{CREATE_OBJECT_SYMBOLS} command appears.
5670 This is conventional for the a.out object file format.  It is not
5671 normally used for any other object file format.
5673 @kindex CONSTRUCTORS
5674 @cindex C++ constructors, arranging in link
5675 @cindex constructors, arranging in link
5676 @item CONSTRUCTORS
5677 When linking using the a.out object file format, the linker uses an
5678 unusual set construct to support C++ global constructors and
5679 destructors.  When linking object file formats which do not support
5680 arbitrary sections, such as ECOFF and XCOFF, the linker will
5681 automatically recognize C++ global constructors and destructors by name.
5682 For these object file formats, the @code{CONSTRUCTORS} command tells the
5683 linker to place constructor information in the output section where the
5684 @code{CONSTRUCTORS} command appears.  The @code{CONSTRUCTORS} command is
5685 ignored for other object file formats.
5687 The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
5688 constructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
5689 Similarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
5690 the start and end of the global destructors.  The
5691 first word in the list is the number of entries, followed by the address
5692 of each constructor or destructor, followed by a zero word.  The
5693 compiler must arrange to actually run the code.  For these object file
5694 formats @sc{gnu} C++ normally calls constructors from a subroutine
5695 @code{__main}; a call to @code{__main} is automatically inserted into
5696 the startup code for @code{main}.  @sc{gnu} C++ normally runs
5697 destructors either by using @code{atexit}, or directly from the function
5698 @code{exit}.
5700 For object file formats such as @code{COFF} or @code{ELF} which support
5701 arbitrary section names, @sc{gnu} C++ will normally arrange to put the
5702 addresses of global constructors and destructors into the @code{.ctors}
5703 and @code{.dtors} sections.  Placing the following sequence into your
5704 linker script will build the sort of table which the @sc{gnu} C++
5705 runtime code expects to see.
5707 @smallexample
5708       __CTOR_LIST__ = .;
5709       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
5710       *(.ctors)
5711       LONG(0)
5712       __CTOR_END__ = .;
5713       __DTOR_LIST__ = .;
5714       LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
5715       *(.dtors)
5716       LONG(0)
5717       __DTOR_END__ = .;
5718 @end smallexample
5720 If you are using the @sc{gnu} C++ support for initialization priority,
5721 which provides some control over the order in which global constructors
5722 are run, you must sort the constructors at link time to ensure that they
5723 are executed in the correct order.  When using the @code{CONSTRUCTORS}
5724 command, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead.  When using the
5725 @code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
5726 @samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
5727 @samp{*(.dtors)}.
5729 Normally the compiler and linker will handle these issues automatically,
5730 and you will not need to concern yourself with them.  However, you may
5731 need to consider this if you are using C++ and writing your own linker
5732 scripts.
5734 @end table
5736 @node Output Section Discarding
5737 @subsection Output Section Discarding
5738 @cindex discarding sections
5739 @cindex sections, discarding
5740 @cindex removing sections
5741 The linker will not normally create output sections with no contents.
5742 This is for convenience when referring to input sections that may or
5743 may not be present in any of the input files.  For example:
5744 @smallexample
5745 .foo : @{ *(.foo) @}
5746 @end smallexample
5747 @noindent
5748 will only create a @samp{.foo} section in the output file if there is a
5749 @samp{.foo} section in at least one input file, and if the input
5750 sections are not all empty.  Other link script directives that allocate
5751 space in an output section will also create the output section.  So
5752 too will assignments to dot even if the assignment does not create
5753 space, except for @samp{. = 0}, @samp{. = . + 0}, @samp{. = sym},
5754 @samp{. = . + sym} and @samp{. = ALIGN (. != 0, expr, 1)} when
5755 @samp{sym} is an absolute symbol of value 0 defined in the script.
5756 This allows you to force output of an empty section with @samp{. = .}.
5758 The linker will ignore address assignments (@pxref{Output Section Address})
5759 on discarded output sections, except when the linker script defines
5760 symbols in the output section.  In that case the linker will obey
5761 the address assignments, possibly advancing dot even though the
5762 section is discarded.
5764 @cindex /DISCARD/
5765 The special output section name @samp{/DISCARD/} may be used to discard
5766 input sections.  Any input sections which are assigned to an output
5767 section named @samp{/DISCARD/} are not included in the output file.
5769 This can be used to discard input sections marked with the ELF flag
5770 @code{SHF_GNU_RETAIN}, which would otherwise have been saved from linker
5771 garbage collection.
5773 Note, sections that match the @samp{/DISCARD/} output section will be
5774 discarded even if they are in an ELF section group which has other
5775 members which are not being discarded.  This is deliberate.
5776 Discarding takes precedence over grouping.
5778 @node Output Section Attributes
5779 @subsection Output Section Attributes
5780 @cindex output section attributes
5781 We showed above that the full description of an output section looked
5782 like this:
5784 @smallexample
5785 @group
5786 @var{section} [@var{address}] [(@var{type})] :
5787   [AT(@var{lma})]
5788   [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
5789   [SUBALIGN(@var{subsection_align})]
5790   [@var{constraint}]
5791   @{
5792     @var{output-section-command}
5793     @var{output-section-command}
5794     @dots{}
5795   @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
5796 @end group
5797 @end smallexample
5799 We've already described @var{section}, @var{address}, and
5800 @var{output-section-command}.  In this section we will describe the
5801 remaining section attributes.
5803 @menu
5804 * Output Section Type::         Output section type
5805 * Output Section LMA::          Output section LMA
5806 * Forced Output Alignment::     Forced Output Alignment
5807 * Forced Input Alignment::      Forced Input Alignment
5808 * Output Section Constraint::   Output section constraint
5809 * Output Section Region::       Output section region
5810 * Output Section Phdr::         Output section phdr
5811 * Output Section Fill::         Output section fill
5812 @end menu
5814 @node Output Section Type
5815 @subsubsection Output Section Type
5816 Each output section may have a type.  The type is a keyword in
5817 parentheses.  The following types are defined:
5819 @table @code
5821 @item NOLOAD
5822 The section should be marked as not loadable, so that it will not be
5823 loaded into memory when the program is run.
5825 @item READONLY
5826 The section should be marked as read-only.
5828 @item DSECT
5829 @item COPY
5830 @item INFO
5831 @item OVERLAY
5832 These type names are supported for backward compatibility, and are
5833 rarely used.  They all have the same effect: the section should be
5834 marked as not allocatable, so that no memory is allocated for the
5835 section when the program is run.
5837 @item TYPE = @var{type}
5838 Set the section type to the integer @var{type}. When generating an ELF
5839 output file, type names @code{SHT_PROGBITS}, @code{SHT_STRTAB},
5840 @code{SHT_NOTE}, @code{SHT_NOBITS}, @code{SHT_INIT_ARRAY},
5841 @code{SHT_FINI_ARRAY}, and @code{SHT_PREINIT_ARRAY} are also allowed
5842 for @var{type}.  It is the user's responsibility to ensure that any
5843 special requirements of the section type are met.
5845 Note - the TYPE only is used if some or all of the contents of the
5846 section do not have an implicit type of their own.  So for example:
5847 @smallexample
5848   .foo . TYPE = SHT_PROGBITS @{ *(.bar) @}
5849 @end smallexample
5850 will set the type of section @samp{.foo} to the type of the section
5851 @samp{.bar} in the input files, which may not be the SHT_PROGBITS
5852 type.  Whereas:
5853 @smallexample
5854   .foo . TYPE = SHT_PROGBITS @{ BYTE(1) @}
5855 @end smallexample
5856 will set the type of @samp{.foo} to SHT_PROGBBITS.  If it is necessary
5857 to override the type of incoming sections and force the output section
5858 type then an extra piece of untyped data will be needed:
5859 @smallexample
5860   .foo . TYPE = SHT_PROGBITS @{ BYTE(1); *(.bar) @}
5861 @end smallexample
5863 @item READONLY ( TYPE = @var{type} )
5864 This form of the syntax combines the @var{READONLY} type with the
5865 type specified by @var{type}.
5867 @end table
5869 @kindex NOLOAD
5870 @cindex prevent unnecessary loading
5871 @cindex loading, preventing
5872 The linker normally sets the attributes of an output section based on
5873 the input sections which map into it.  You can override this by using
5874 the section type.  For example, in the script sample below, the
5875 @samp{ROM} section is addressed at memory location @samp{0} and does not
5876 need to be loaded when the program is run.
5877 @smallexample
5878 @group
5879 SECTIONS @{
5880   ROM 0 (NOLOAD) : @{ @dots{} @}
5881   @dots{}
5883 @end group
5884 @end smallexample
5886 @node Output Section LMA
5887 @subsubsection Output Section LMA
5888 @kindex AT>@var{lma_region}
5889 @kindex AT(@var{lma})
5890 @cindex load address
5891 @cindex section load address
5892 Every section has a virtual address (VMA) and a load address (LMA); see
5893 @ref{Basic Script Concepts}.  The virtual address is specified by the
5894 @pxref{Output Section Address} described earlier.  The load address is
5895 specified by the @code{AT} or @code{AT>} keywords.  Specifying a load
5896 address is optional.
5898 The @code{AT} keyword takes an expression as an argument.  This
5899 specifies the exact load address of the section.  The @code{AT>} keyword
5900 takes the name of a memory region as an argument.  @xref{MEMORY}.  The
5901 load address of the section is set to the next free address in the
5902 region, aligned to the section's alignment requirements.
5904 If neither @code{AT} nor @code{AT>} is specified for an allocatable
5905 section, the linker will use the following heuristic to determine the
5906 load address:
5908 @itemize @bullet
5909 @item
5910 If the section has a specific VMA address, then this is used as
5911 the LMA address as well.
5913 @item
5914 If the section is not allocatable then its LMA is set to its VMA.
5916 @item
5917 Otherwise if a memory region can be found that is compatible
5918 with the current section, and this region contains at least one
5919 section, then the LMA is set so the difference between the
5920 VMA and LMA is the same as the difference between the VMA and LMA of
5921 the last section in the located region.
5923 @item
5924 If no memory regions have been declared then a default region
5925 that covers the entire address space is used in the previous step.
5927 @item
5928 If no suitable region could be found, or there was no previous
5929 section then the LMA is set equal to the VMA.
5930 @end itemize
5932 @cindex ROM initialized data
5933 @cindex initialized data in ROM
5934 This feature is designed to make it easy to build a ROM image.  For
5935 example, the following linker script creates three output sections: one
5936 called @samp{.text}, which starts at @code{0x1000}, one called
5937 @samp{.mdata}, which is loaded at the end of the @samp{.text} section
5938 even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
5939 uninitialized data at address @code{0x3000}.  The symbol @code{_data} is
5940 defined with the value @code{0x2000}, which shows that the location
5941 counter holds the VMA value, not the LMA value.
5943 @smallexample
5944 @group
5945 SECTIONS
5946   @{
5947   .text 0x1000 : @{ *(.text) _etext = . ; @}
5948   .mdata 0x2000 :
5949     AT ( ADDR (.text) + SIZEOF (.text) )
5950     @{ _data = . ; *(.data); _edata = . ;  @}
5951   .bss 0x3000 :
5952     @{ _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;@}
5954 @end group
5955 @end smallexample
5957 The run-time initialization code for use with a program generated with
5958 this linker script would include something like the following, to copy
5959 the initialized data from the ROM image to its runtime address.  Notice
5960 how this code takes advantage of the symbols defined by the linker
5961 script.
5963 @smallexample
5964 @group
5965 extern char _etext, _data, _edata, _bstart, _bend;
5966 char *src = &_etext;
5967 char *dst = &_data;
5969 /* ROM has data at end of text; copy it.  */
5970 while (dst < &_edata)
5971   *dst++ = *src++;
5973 /* Zero bss.  */
5974 for (dst = &_bstart; dst< &_bend; dst++)
5975   *dst = 0;
5976 @end group
5977 @end smallexample
5979 @node Forced Output Alignment
5980 @subsubsection Forced Output Alignment
5981 @kindex ALIGN(@var{section_align})
5982 @cindex forcing output section alignment
5983 @cindex output section alignment
5984 You can increase an output section's alignment by using ALIGN.  As an
5985 alternative you can enforce that the difference between the VMA and LMA remains
5986 intact throughout this output section with the ALIGN_WITH_INPUT attribute.
5988 @node Forced Input Alignment
5989 @subsubsection Forced Input Alignment
5990 @kindex SUBALIGN(@var{subsection_align})
5991 @cindex forcing input section alignment
5992 @cindex input section alignment
5993 You can force input section alignment within an output section by using
5994 SUBALIGN.  The value specified overrides any alignment given by input
5995 sections, whether larger or smaller.
5997 @node Output Section Constraint
5998 @subsubsection Output Section Constraint
5999 @kindex ONLY_IF_RO
6000 @kindex ONLY_IF_RW
6001 @cindex constraints on output sections
6002 You can specify that an output section should only be created if all
6003 of its input sections are read-only or all of its input sections are
6004 read-write by using the keyword @code{ONLY_IF_RO} and
6005 @code{ONLY_IF_RW} respectively.
6007 @node Output Section Region
6008 @subsubsection Output Section Region
6009 @kindex >@var{region}
6010 @cindex section, assigning to memory region
6011 @cindex memory regions and sections
6012 You can assign a section to a previously defined region of memory by
6013 using @samp{>@var{region}}.  @xref{MEMORY}.
6015 Here is a simple example:
6016 @smallexample
6017 @group
6018 MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
6019 SECTIONS @{ ROM : @{ *(.text) @} >rom @}
6020 @end group
6021 @end smallexample
6023 @node Output Section Phdr
6024 @subsubsection Output Section Phdr
6025 @kindex :@var{phdr}
6026 @cindex section, assigning to program header
6027 @cindex program headers and sections
6028 You can assign a section to a previously defined program segment by
6029 using @samp{:@var{phdr}}.  @xref{PHDRS}.  If a section is assigned to
6030 one or more segments, then all subsequent allocated sections will be
6031 assigned to those segments as well, unless they use an explicitly
6032 @code{:@var{phdr}} modifier.  You can use @code{:NONE} to tell the
6033 linker to not put the section in any segment at all.
6035 Here is a simple example:
6036 @smallexample
6037 @group
6038 PHDRS @{ text PT_LOAD ; @}
6039 SECTIONS @{ .text : @{ *(.text) @} :text @}
6040 @end group
6041 @end smallexample
6043 @node Output Section Fill
6044 @subsubsection Output Section Fill
6045 @kindex =@var{fillexp}
6046 @cindex section fill pattern
6047 @cindex fill pattern, entire section
6048 You can set the fill pattern for an entire section by using
6049 @samp{=@var{fillexp}}.  @var{fillexp} is an expression
6050 (@pxref{Expressions}).  Any otherwise unspecified regions of memory
6051 within the output section (for example, gaps left due to the required
6052 alignment of input sections) will be filled with the value, repeated as
6053 necessary.  If the fill expression is a simple hex number, ie. a string
6054 of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
6055 an arbitrarily long sequence of hex digits can be used to specify the
6056 fill pattern;  Leading zeros become part of the pattern too.  For all
6057 other cases, including extra parentheses or a unary @code{+}, the fill
6058 pattern is the four least significant bytes of the value of the
6059 expression.  If the value is less than four bytes in size then it will
6060 be zero extended to four bytes.  In all cases, the number is big-endian.
6062 @smallexample
6063 Fill Value     Fill Pattern
6064 0x90           90 90 90 90
6065 0x0090         00 90 00 90
6066 144            00 00 00 90
6067 @end smallexample
6069 You can also change the fill value with a @code{FILL} command in the
6070 output section commands; (@pxref{Output Section Data}).
6072 Here is a simple example:
6073 @smallexample
6074 @group
6075 SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
6076 @end group
6077 @end smallexample
6079 @node Overlay Description
6080 @subsection Overlay Description
6081 @kindex OVERLAY
6082 @cindex overlays
6083 An overlay description provides an easy way to describe sections which
6084 are to be loaded as part of a single memory image but are to be run at
6085 the same memory address.  At run time, some sort of overlay manager will
6086 copy the overlaid sections in and out of the runtime memory address as
6087 required, perhaps by simply manipulating addressing bits.  This approach
6088 can be useful, for example, when a certain region of memory is faster
6089 than another.
6091 Overlays are described using the @code{OVERLAY} command.  The
6092 @code{OVERLAY} command is used within a @code{SECTIONS} command, like an
6093 output section description.  The full syntax of the @code{OVERLAY}
6094 command is as follows:
6095 @smallexample
6096 @group
6097 OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
6098   @{
6099     @var{secname1}
6100       @{
6101         @var{output-section-command}
6102         @var{output-section-command}
6103         @dots{}
6104       @} [:@var{phdr}@dots{}] [=@var{fill}]
6105     @var{secname2}
6106       @{
6107         @var{output-section-command}
6108         @var{output-section-command}
6109         @dots{}
6110       @} [:@var{phdr}@dots{}] [=@var{fill}]
6111     @dots{}
6112   @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] [,]
6113 @end group
6114 @end smallexample
6116 Everything is optional except @code{OVERLAY} (a keyword), and each
6117 section must have a name (@var{secname1} and @var{secname2} above).  The
6118 section definitions within the @code{OVERLAY} construct are identical to
6119 those within the general @code{SECTIONS} construct (@pxref{SECTIONS}),
6120 except that no addresses and no memory regions may be defined for
6121 sections within an @code{OVERLAY}.
6123 The comma at the end may be required if a @var{fill} is used and
6124 the next @var{sections-command} looks like a continuation of the expression.
6126 The sections are all defined with the same starting address.  The load
6127 addresses of the sections are arranged such that they are consecutive in
6128 memory starting at the load address used for the @code{OVERLAY} as a
6129 whole (as with normal section definitions, the load address is optional,
6130 and defaults to the start address; the start address is also optional,
6131 and defaults to the current value of the location counter).
6133 If the @code{NOCROSSREFS} keyword is used, and there are any
6134 references among the sections, the linker will report an error.  Since
6135 the sections all run at the same address, it normally does not make
6136 sense for one section to refer directly to another.
6137 @xref{Miscellaneous Commands, NOCROSSREFS}.
6139 For each section within the @code{OVERLAY}, the linker automatically
6140 provides two symbols.  The symbol @code{__load_start_@var{secname}} is
6141 defined as the starting load address of the section.  The symbol
6142 @code{__load_stop_@var{secname}} is defined as the final load address of
6143 the section.  Any characters within @var{secname} which are not legal
6144 within C identifiers are removed.  C (or assembler) code may use these
6145 symbols to move the overlaid sections around as necessary.
6147 At the end of the overlay, the value of the location counter is set to
6148 the start address of the overlay plus the size of the largest section.
6150 Here is an example.  Remember that this would appear inside a
6151 @code{SECTIONS} construct.
6152 @smallexample
6153 @group
6154   OVERLAY 0x1000 : AT (0x4000)
6155    @{
6156      .text0 @{ o1/*.o(.text) @}
6157      .text1 @{ o2/*.o(.text) @}
6158    @}
6159 @end group
6160 @end smallexample
6161 @noindent
6162 This will define both @samp{.text0} and @samp{.text1} to start at
6163 address 0x1000.  @samp{.text0} will be loaded at address 0x4000, and
6164 @samp{.text1} will be loaded immediately after @samp{.text0}.  The
6165 following symbols will be defined if referenced: @code{__load_start_text0},
6166 @code{__load_stop_text0}, @code{__load_start_text1},
6167 @code{__load_stop_text1}.
6169 C code to copy overlay @code{.text1} into the overlay area might look
6170 like the following.
6172 @smallexample
6173 @group
6174   extern char __load_start_text1, __load_stop_text1;
6175   memcpy ((char *) 0x1000, &__load_start_text1,
6176           &__load_stop_text1 - &__load_start_text1);
6177 @end group
6178 @end smallexample
6180 Note that the @code{OVERLAY} command is just syntactic sugar, since
6181 everything it does can be done using the more basic commands.  The above
6182 example could have been written identically as follows.
6184 @smallexample
6185 @group
6186   .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
6187   PROVIDE (__load_start_text0 = LOADADDR (.text0));
6188   PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
6189   .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
6190   PROVIDE (__load_start_text1 = LOADADDR (.text1));
6191   PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
6192   . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
6193 @end group
6194 @end smallexample
6196 @node MEMORY
6197 @section MEMORY Command
6198 @kindex MEMORY
6199 @cindex memory regions
6200 @cindex regions of memory
6201 @cindex allocating memory
6202 @cindex discontinuous memory
6203 The linker's default configuration permits allocation of all available
6204 memory.  You can override this by using the @code{MEMORY} command.
6206 The @code{MEMORY} command describes the location and size of blocks of
6207 memory in the target.  You can use it to describe which memory regions
6208 may be used by the linker, and which memory regions it must avoid.  You
6209 can then assign sections to particular memory regions.  The linker will
6210 set section addresses based on the memory regions, and will warn about
6211 regions that become too full.  The linker will not shuffle sections
6212 around to fit into the available regions.
6214 A linker script may contain many uses of the @code{MEMORY} command,
6215 however, all memory blocks defined are treated as if they were
6216 specified inside a single @code{MEMORY} command.  The syntax for
6217 @code{MEMORY} is:
6218 @smallexample
6219 @group
6220 MEMORY
6221   @{
6222     @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
6223     @dots{}
6224   @}
6225 @end group
6226 @end smallexample
6228 The @var{name} is a name used in the linker script to refer to the
6229 region.  The region name has no meaning outside of the linker script.
6230 Region names are stored in a separate name space, and will not conflict
6231 with symbol names, file names, or section names.  Each memory region
6232 must have a distinct name within the @code{MEMORY} command.  However you can
6233 add later alias names to existing memory regions with the @ref{REGION_ALIAS}
6234 command.
6236 @cindex memory region attributes
6237 The @var{attr} string is an optional list of attributes that specify
6238 whether to use a particular memory region for an input section which is
6239 not explicitly mapped in the linker script.  As described in
6240 @ref{SECTIONS}, if you do not specify an output section for some input
6241 section, the linker will create an output section with the same name as
6242 the input section.  If you define region attributes, the linker will use
6243 them to select the memory region for the output section that it creates.
6245 The @var{attr} string must consist only of the following characters:
6246 @table @samp
6247 @item R
6248 Read-only section
6249 @item W
6250 Read/write section
6251 @item X
6252 Executable section
6253 @item A
6254 Allocatable section
6255 @item I
6256 Initialized section
6257 @item L
6258 Same as @samp{I}
6259 @item !
6260 Invert the sense of any of the attributes that follow
6261 @end table
6263 If an unmapped section matches any of the listed attributes other than
6264 @samp{!}, it will be placed in the memory region.  The @samp{!}
6265 attribute reverses the test for the characters that follow, so that an
6266 unmapped section will be placed in the memory region only if it does
6267 not match any of the attributes listed afterwards.  Thus an attribute
6268 string of @samp{RW!X} will match any unmapped section that has either
6269 or both of the @samp{R} and @samp{W} attributes, but only as long as
6270 the section does not also have the @samp{X} attribute.
6272 @kindex ORIGIN =
6273 @kindex o =
6274 @kindex org =
6275 The @var{origin} is an numerical expression for the start address of
6276 the memory region.  The expression must evaluate to a constant and it
6277 cannot involve any symbols.  The keyword @code{ORIGIN} may be
6278 abbreviated to @code{org} or @code{o} (but not, for example,
6279 @code{ORG}).
6281 @kindex LENGTH =
6282 @kindex len =
6283 @kindex l =
6284 The @var{len} is an expression for the size in bytes of the memory
6285 region.  As with the @var{origin} expression, the expression must
6286 be numerical only and must evaluate to a constant.  The keyword
6287 @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
6289 In the following example, we specify that there are two memory regions
6290 available for allocation: one starting at @samp{0} for 256 kilobytes,
6291 and the other starting at @samp{0x40000000} for four megabytes.  The
6292 linker will place into the @samp{rom} memory region every section which
6293 is not explicitly mapped into a memory region, and is either read-only
6294 or executable.  The linker will place other sections which are not
6295 explicitly mapped into a memory region into the @samp{ram} memory
6296 region.
6298 @smallexample
6299 @group
6300 MEMORY
6301   @{
6302     rom (rx)  : ORIGIN = 0, LENGTH = 256K
6303     ram (!rx) : org = 0x40000000, l = 4M
6304   @}
6305 @end group
6306 @end smallexample
6308 Once you define a memory region, you can direct the linker to place
6309 specific output sections into that memory region by using the
6310 @samp{>@var{region}} output section attribute.  For example, if you have
6311 a memory region named @samp{mem}, you would use @samp{>mem} in the
6312 output section definition.  @xref{Output Section Region}.  If no address
6313 was specified for the output section, the linker will set the address to
6314 the next available address within the memory region.  If the combined
6315 output sections directed to a memory region are too large for the
6316 region, the linker will issue an error message.
6318 It is possible to access the origin and length of a memory in an
6319 expression via the @code{ORIGIN(@var{memory})} and
6320 @code{LENGTH(@var{memory})} functions:
6322 @smallexample
6323 @group
6324   _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
6325 @end group
6326 @end smallexample
6328 @node PHDRS
6329 @section PHDRS Command
6330 @kindex PHDRS
6331 @cindex program headers
6332 @cindex ELF program headers
6333 @cindex program segments
6334 @cindex segments, ELF
6335 The ELF object file format uses @dfn{program headers}, also knows as
6336 @dfn{segments}.  The program headers describe how the program should be
6337 loaded into memory.  You can print them out by using the @code{objdump}
6338 program with the @samp{-p} option.
6340 When you run an ELF program on a native ELF system, the system loader
6341 reads the program headers in order to figure out how to load the
6342 program.  This will only work if the program headers are set correctly.
6343 This manual does not describe the details of how the system loader
6344 interprets program headers; for more information, see the ELF ABI.
6346 The linker will create reasonable program headers by default.  However,
6347 in some cases, you may need to specify the program headers more
6348 precisely.  You may use the @code{PHDRS} command for this purpose.  When
6349 the linker sees the @code{PHDRS} command in the linker script, it will
6350 not create any program headers other than the ones specified.
6352 The linker only pays attention to the @code{PHDRS} command when
6353 generating an ELF output file.  In other cases, the linker will simply
6354 ignore @code{PHDRS}.
6356 This is the syntax of the @code{PHDRS} command.  The words @code{PHDRS},
6357 @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
6359 @smallexample
6360 @group
6361 PHDRS
6363   @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
6364         [ FLAGS ( @var{flags} ) ] ;
6366 @end group
6367 @end smallexample
6369 The @var{name} is used only for reference in the @code{SECTIONS} command
6370 of the linker script.  It is not put into the output file.  Program
6371 header names are stored in a separate name space, and will not conflict
6372 with symbol names, file names, or section names.  Each program header
6373 must have a distinct name.  The headers are processed in order and it
6374 is usual for them to map to sections in ascending load address order.
6376 Certain program header types describe segments of memory which the
6377 system loader will load from the file.  In the linker script, you
6378 specify the contents of these segments by placing allocatable output
6379 sections in the segments.  You use the @samp{:@var{phdr}} output section
6380 attribute to place a section in a particular segment.  @xref{Output
6381 Section Phdr}.
6383 It is normal to put certain sections in more than one segment.  This
6384 merely implies that one segment of memory contains another.  You may
6385 repeat @samp{:@var{phdr}}, using it once for each segment which should
6386 contain the section.
6388 If you place a section in one or more segments using @samp{:@var{phdr}},
6389 then the linker will place all subsequent allocatable sections which do
6390 not specify @samp{:@var{phdr}} in the same segments.  This is for
6391 convenience, since generally a whole set of contiguous sections will be
6392 placed in a single segment.  You can use @code{:NONE} to override the
6393 default segment and tell the linker to not put the section in any
6394 segment at all.
6396 @kindex FILEHDR
6397 @kindex PHDRS
6398 You may use the @code{FILEHDR} and @code{PHDRS} keywords after
6399 the program header type to further describe the contents of the segment.
6400 The @code{FILEHDR} keyword means that the segment should include the ELF
6401 file header.  The @code{PHDRS} keyword means that the segment should
6402 include the ELF program headers themselves.  If applied to a loadable
6403 segment (@code{PT_LOAD}), all prior loadable segments must have one of
6404 these keywords.
6406 The @var{type} may be one of the following.  The numbers indicate the
6407 value of the keyword.
6409 @table @asis
6410 @item @code{PT_NULL} (0)
6411 Indicates an unused program header.
6413 @item @code{PT_LOAD} (1)
6414 Indicates that this program header describes a segment to be loaded from
6415 the file.
6417 @item @code{PT_DYNAMIC} (2)
6418 Indicates a segment where dynamic linking information can be found.
6420 @item @code{PT_INTERP} (3)
6421 Indicates a segment where the name of the program interpreter may be
6422 found.
6424 @item @code{PT_NOTE} (4)
6425 Indicates a segment holding note information.
6427 @item @code{PT_SHLIB} (5)
6428 A reserved program header type, defined but not specified by the ELF
6429 ABI.
6431 @item @code{PT_PHDR} (6)
6432 Indicates a segment where the program headers may be found.
6434 @item @code{PT_TLS} (7)
6435 Indicates a segment containing thread local storage.
6437 @item @var{expression}
6438 An expression giving the numeric type of the program header.  This may
6439 be used for types not defined above.
6440 @end table
6442 You can specify that a segment should be loaded at a particular address
6443 in memory by using an @code{AT} expression.  This is identical to the
6444 @code{AT} command used as an output section attribute (@pxref{Output
6445 Section LMA}).  The @code{AT} command for a program header overrides the
6446 output section attribute.
6448 The linker will normally set the segment flags based on the sections
6449 which comprise the segment.  You may use the @code{FLAGS} keyword to
6450 explicitly specify the segment flags.  The value of @var{flags} must be
6451 an integer.  It is used to set the @code{p_flags} field of the program
6452 header.
6454 Here is an example of @code{PHDRS}.  This shows a typical set of program
6455 headers used on a native ELF system.
6457 @example
6458 @group
6459 PHDRS
6461   headers PT_PHDR PHDRS ;
6462   interp PT_INTERP ;
6463   text PT_LOAD FILEHDR PHDRS ;
6464   data PT_LOAD ;
6465   dynamic PT_DYNAMIC ;
6468 SECTIONS
6470   . = SIZEOF_HEADERS;
6471   .interp : @{ *(.interp) @} :text :interp
6472   .text : @{ *(.text) @} :text
6473   .rodata : @{ *(.rodata) @} /* defaults to :text */
6474   @dots{}
6475   . = . + 0x1000; /* move to a new page in memory */
6476   .data : @{ *(.data) @} :data
6477   .dynamic : @{ *(.dynamic) @} :data :dynamic
6478   @dots{}
6480 @end group
6481 @end example
6483 @node VERSION
6484 @section VERSION Command
6485 @kindex VERSION @{script text@}
6486 @cindex symbol versions
6487 @cindex version script
6488 @cindex versions of symbols
6489 The linker supports symbol versions when using ELF.  Symbol versions are
6490 only useful when using shared libraries.  The dynamic linker can use
6491 symbol versions to select a specific version of a function when it runs
6492 a program that may have been linked against an earlier version of the
6493 shared library.
6495 You can include a version script directly in the main linker script, or
6496 you can supply the version script as an implicit linker script.  You can
6497 also use the @samp{--version-script} linker option.
6499 The syntax of the @code{VERSION} command is simply
6500 @smallexample
6501 VERSION @{ version-script-commands @}
6502 @end smallexample
6504 The format of the version script commands is identical to that used by
6505 Sun's linker in Solaris 2.5.  The version script defines a tree of
6506 version nodes.  You specify the node names and interdependencies in the
6507 version script.  You can specify which symbols are bound to which
6508 version nodes, and you can reduce a specified set of symbols to local
6509 scope so that they are not globally visible outside of the shared
6510 library.
6512 The easiest way to demonstrate the version script language is with a few
6513 examples.
6515 @smallexample
6516 VERS_1.1 @{
6517          global:
6518                  foo1;
6519          local:
6520                  old*;
6521                  original*;
6522                  new*;
6525 VERS_1.2 @{
6526                  foo2;
6527 @} VERS_1.1;
6529 VERS_2.0 @{
6530                  bar1; bar2;
6531          extern "C++" @{
6532                  ns::*;
6533                  "f(int, double)";
6534          @};
6535 @} VERS_1.2;
6536 @end smallexample
6538 This example version script defines three version nodes.  The first
6539 version node defined is @samp{VERS_1.1}; it has no other dependencies.
6540 The script binds the symbol @samp{foo1} to @samp{VERS_1.1}.  It reduces
6541 a number of symbols to local scope so that they are not visible outside
6542 of the shared library; this is done using wildcard patterns, so that any
6543 symbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
6544 is matched.  The wildcard patterns available are the same as those used
6545 in the shell when matching filenames (also known as ``globbing'').
6546 However, if you specify the symbol name inside double quotes, then the
6547 name is treated as literal, rather than as a glob pattern.
6549 Next, the version script defines node @samp{VERS_1.2}.  This node
6550 depends upon @samp{VERS_1.1}.  The script binds the symbol @samp{foo2}
6551 to the version node @samp{VERS_1.2}.
6553 Finally, the version script defines node @samp{VERS_2.0}.  This node
6554 depends upon @samp{VERS_1.2}.  The scripts binds the symbols @samp{bar1}
6555 and @samp{bar2} are bound to the version node @samp{VERS_2.0}.
6557 When the linker finds a symbol defined in a library which is not
6558 specifically bound to a version node, it will effectively bind it to an
6559 unspecified base version of the library.  You can bind all otherwise
6560 unspecified symbols to a given version node by using @samp{global: *;}
6561 somewhere in the version script.  Note that it's slightly crazy to use
6562 wildcards in a global spec except on the last version node.  Global
6563 wildcards elsewhere run the risk of accidentally adding symbols to the
6564 set exported for an old version.  That's wrong since older versions
6565 ought to have a fixed set of symbols.
6567 The names of the version nodes have no specific meaning other than what
6568 they might suggest to the person reading them.  The @samp{2.0} version
6569 could just as well have appeared in between @samp{1.1} and @samp{1.2}.
6570 However, this would be a confusing way to write a version script.
6572 Node name can be omitted, provided it is the only version node
6573 in the version script.  Such version script doesn't assign any versions to
6574 symbols, only selects which symbols will be globally visible out and which
6575 won't.
6577 @smallexample
6578 @{ global: foo; bar; local: *; @};
6579 @end smallexample
6581 When you link an application against a shared library that has versioned
6582 symbols, the application itself knows which version of each symbol it
6583 requires, and it also knows which version nodes it needs from each
6584 shared library it is linked against.  Thus at runtime, the dynamic
6585 loader can make a quick check to make sure that the libraries you have
6586 linked against do in fact supply all of the version nodes that the
6587 application will need to resolve all of the dynamic symbols.  In this
6588 way it is possible for the dynamic linker to know with certainty that
6589 all external symbols that it needs will be resolvable without having to
6590 search for each symbol reference.
6592 The symbol versioning is in effect a much more sophisticated way of
6593 doing minor version checking that SunOS does.  The fundamental problem
6594 that is being addressed here is that typically references to external
6595 functions are bound on an as-needed basis, and are not all bound when
6596 the application starts up.  If a shared library is out of date, a
6597 required interface may be missing; when the application tries to use
6598 that interface, it may suddenly and unexpectedly fail.  With symbol
6599 versioning, the user will get a warning when they start their program if
6600 the libraries being used with the application are too old.
6602 There are several GNU extensions to Sun's versioning approach.  The
6603 first of these is the ability to bind a symbol to a version node in the
6604 source file where the symbol is defined instead of in the versioning
6605 script.  This was done mainly to reduce the burden on the library
6606 maintainer.  You can do this by putting something like:
6607 @smallexample
6608 __asm__(".symver original_foo,foo@@VERS_1.1");
6609 @end smallexample
6610 @noindent
6611 in the C source file.  This renames the function @samp{original_foo} to
6612 be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
6613 The @samp{local:} directive can be used to prevent the symbol
6614 @samp{original_foo} from being exported. A @samp{.symver} directive
6615 takes precedence over a version script.
6617 The second GNU extension is to allow multiple versions of the same
6618 function to appear in a given shared library.  In this way you can make
6619 an incompatible change to an interface without increasing the major
6620 version number of the shared library, while still allowing applications
6621 linked against the old interface to continue to function.
6623 To do this, you must use multiple @samp{.symver} directives in the
6624 source file.  Here is an example:
6626 @smallexample
6627 __asm__(".symver original_foo,foo@@");
6628 __asm__(".symver old_foo,foo@@VERS_1.1");
6629 __asm__(".symver old_foo1,foo@@VERS_1.2");
6630 __asm__(".symver new_foo,foo@@@@VERS_2.0");
6631 @end smallexample
6633 In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
6634 unspecified base version of the symbol.  The source file that contains this
6635 example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
6636 @samp{old_foo1}, and @samp{new_foo}.
6638 When you have multiple definitions of a given symbol, there needs to be
6639 some way to specify a default version to which external references to
6640 this symbol will be bound.  You can do this with the
6641 @samp{foo@@@@VERS_2.0} type of @samp{.symver} directive.  You can only
6642 declare one version of a symbol as the default in this manner; otherwise
6643 you would effectively have multiple definitions of the same symbol.
6645 If you wish to bind a reference to a specific version of the symbol
6646 within the shared library, you can use the aliases of convenience
6647 (i.e., @samp{old_foo}), or you can use the @samp{.symver} directive to
6648 specifically bind to an external version of the function in question.
6650 You can also specify the language in the version script:
6652 @smallexample
6653 VERSION extern "lang" @{ version-script-commands @}
6654 @end smallexample
6656 The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
6657 The linker will iterate over the list of symbols at the link time and
6658 demangle them according to @samp{lang} before matching them to the
6659 patterns specified in @samp{version-script-commands}.  The default
6660 @samp{lang} is @samp{C}.
6662 Demangled names may contains spaces and other special characters.  As
6663 described above, you can use a glob pattern to match demangled names,
6664 or you can use a double-quoted string to match the string exactly.  In
6665 the latter case, be aware that minor differences (such as differing
6666 whitespace) between the version script and the demangler output will
6667 cause a mismatch.  As the exact string generated by the demangler
6668 might change in the future, even if the mangled name does not, you
6669 should check that all of your version directives are behaving as you
6670 expect when you upgrade.
6672 @node Expressions
6673 @section Expressions in Linker Scripts
6674 @cindex expressions
6675 @cindex arithmetic
6676 The syntax for expressions in the linker script language is identical to
6677 that of C expressions, except that whitespace is required in some
6678 places to resolve syntactic ambiguities.  All expressions are
6679 evaluated as integers.  All expressions are evaluated in the same
6680 size, which is 32 bits if both the host and target are 32 bits, and is
6681 otherwise 64 bits.
6683 You can use and set symbol values in expressions.
6685 The linker defines several special purpose builtin functions for use in
6686 expressions.
6688 @menu
6689 * Constants::                   Constants
6690 * Symbolic Constants::          Symbolic constants
6691 * Symbols::                     Symbol Names
6692 * Orphan Sections::             Orphan Sections
6693 * Location Counter::            The Location Counter
6694 * Operators::                   Operators
6695 * Evaluation::                  Evaluation
6696 * Expression Section::          The Section of an Expression
6697 * Builtin Functions::           Builtin Functions
6698 @end menu
6700 @node Constants
6701 @subsection Constants
6702 @cindex integer notation
6703 @cindex constants in linker scripts
6704 All constants are integers.
6706 As in C, the linker considers an integer beginning with @samp{0} to be
6707 octal, and an integer beginning with @samp{0x} or @samp{0X} to be
6708 hexadecimal.  Alternatively the linker accepts suffixes of @samp{h} or
6709 @samp{H} for hexadecimal, @samp{o} or @samp{O} for octal, @samp{b} or
6710 @samp{B} for binary and @samp{d} or @samp{D} for decimal.  Any integer
6711 value without a prefix or a suffix is considered to be decimal.
6713 @cindex scaled integers
6714 @cindex K and M integer suffixes
6715 @cindex M and K integer suffixes
6716 @cindex suffixes for integers
6717 @cindex integer suffixes
6718 In addition, you can use the suffixes @code{K} and @code{M} to scale a
6719 constant by
6720 @c TEXI2ROFF-KILL
6721 @ifnottex
6722 @c END TEXI2ROFF-KILL
6723 @code{1024} or @code{1024*1024}
6724 @c TEXI2ROFF-KILL
6725 @end ifnottex
6726 @tex
6727 ${\rm 1024}$ or ${\rm 1024}^2$
6728 @end tex
6729 @c END TEXI2ROFF-KILL
6730 respectively.  For example, the following
6731 all refer to the same quantity:
6733 @smallexample
6734 _fourk_1 = 4K;
6735 _fourk_2 = 4096;
6736 _fourk_3 = 0x1000;
6737 _fourk_4 = 10000o;
6738 @end smallexample
6740 Note - the @code{K} and @code{M} suffixes cannot be used in
6741 conjunction with the base suffixes mentioned above.
6743 @node Symbolic Constants
6744 @subsection Symbolic Constants
6745 @cindex symbolic constants
6746 @kindex CONSTANT
6747 It is possible to refer to target-specific constants via the use of
6748 the @code{CONSTANT(@var{name})} operator, where @var{name} is one of:
6750 @table @code
6751 @item MAXPAGESIZE
6752 @kindex MAXPAGESIZE
6753 The target's maximum page size.
6755 @item COMMONPAGESIZE
6756 @kindex COMMONPAGESIZE
6757 The target's default page size.
6758 @end table
6760 So for example:
6762 @smallexample
6763   .text ALIGN (CONSTANT (MAXPAGESIZE)) : @{ *(.text) @}
6764 @end smallexample
6766 will create a text section aligned to the largest page boundary
6767 supported by the target.
6769 @node Symbols
6770 @subsection Symbol Names
6771 @cindex symbol names
6772 @cindex names
6773 @cindex quoted symbol names
6774 @kindex "
6775 Unless quoted, symbol names start with a letter, underscore, or period
6776 and may include letters, digits, underscores, periods, and hyphens.
6777 Unquoted symbol names must not conflict with any keywords.  You can
6778 specify a symbol which contains odd characters or has the same name as a
6779 keyword by surrounding the symbol name in double quotes:
6780 @smallexample
6781 "SECTION" = 9;
6782 "with a space" = "also with a space" + 10;
6783 @end smallexample
6785 Since symbols can contain many non-alphabetic characters, it is safest
6786 to delimit symbols with spaces.  For example, @samp{A-B} is one symbol,
6787 whereas @samp{A - B} is an expression involving subtraction.
6789 @node Orphan Sections
6790 @subsection Orphan Sections
6791 @cindex orphan
6792 Orphan sections are sections present in the input files which
6793 are not explicitly placed into the output file by the linker
6794 script.  The linker will still copy these sections into the
6795 output file by either finding, or creating a suitable output section
6796 in which to place the orphaned input section.
6798 If the name of an orphaned input section exactly matches the name of
6799 an existing output section, then the orphaned input section will be
6800 placed at the end of that output section.
6802 If there is no output section with a matching name then new output
6803 sections will be created.  Each new output section will have the same
6804 name as the orphan section placed within it.  If there are multiple
6805 orphan sections with the same name, these will all be combined into
6806 one new output section.
6808 If new output sections are created to hold orphaned input sections,
6809 then the linker must decide where to place these new output sections
6810 in relation to existing output sections.  On most modern targets, the
6811 linker attempts to place orphan sections after sections of the same
6812 attribute, such as code vs data, loadable vs non-loadable, etc.  If no
6813 sections with matching attributes are found, or your target lacks this
6814 support, the orphan section is placed at the end of the file.
6816 The command-line options @samp{--orphan-handling} and @samp{--unique}
6817 (@pxref{Options,,Command-line Options}) can be used to control which
6818 output sections an orphan is placed in.
6820 @node Location Counter
6821 @subsection The Location Counter
6822 @kindex .
6823 @cindex dot
6824 @cindex location counter
6825 @cindex current output location
6826 The special linker variable @dfn{dot} @samp{.} always contains the
6827 current output location counter.  Since the @code{.} always refers to a
6828 location in an output section, it may only appear in an expression
6829 within a @code{SECTIONS} command.  The @code{.} symbol may appear
6830 anywhere that an ordinary symbol is allowed in an expression.
6832 @cindex holes
6833 Assigning a value to @code{.} will cause the location counter to be
6834 moved.  This may be used to create holes in the output section.  The
6835 location counter may not be moved backwards inside an output section,
6836 and may not be moved backwards outside of an output section if so
6837 doing creates areas with overlapping LMAs.
6839 @smallexample
6840 SECTIONS
6842   output :
6843     @{
6844       file1(.text)
6845       . = . + 1000;
6846       file2(.text)
6847       . += 1000;
6848       file3(.text)
6849     @} = 0x12345678;
6851 @end smallexample
6852 @noindent
6853 In the previous example, the @samp{.text} section from @file{file1} is
6854 located at the beginning of the output section @samp{output}.  It is
6855 followed by a 1000 byte gap.  Then the @samp{.text} section from
6856 @file{file2} appears, also with a 1000 byte gap following before the
6857 @samp{.text} section from @file{file3}.  The notation @samp{= 0x12345678}
6858 specifies what data to write in the gaps (@pxref{Output Section Fill}).
6860 @cindex dot inside sections
6861 Note: @code{.} actually refers to the byte offset from the start of the
6862 current containing object.  Normally this is the @code{SECTIONS}
6863 statement, whose start address is 0, hence @code{.} can be used as an
6864 absolute address.  If @code{.} is used inside a section description
6865 however, it refers to the byte offset from the start of that section,
6866 not an absolute address.  Thus in a script like this:
6868 @smallexample
6869 SECTIONS
6871     . = 0x100
6872     .text: @{
6873       *(.text)
6874       . = 0x200
6875     @}
6876     . = 0x500
6877     .data: @{
6878       *(.data)
6879       . += 0x600
6880     @}
6882 @end smallexample
6884 The @samp{.text} section will be assigned a starting address of 0x100
6885 and a size of exactly 0x200 bytes, even if there is not enough data in
6886 the @samp{.text} input sections to fill this area.  (If there is too
6887 much data, an error will be produced because this would be an attempt to
6888 move @code{.} backwards).  The @samp{.data} section will start at 0x500
6889 and it will have an extra 0x600 bytes worth of space after the end of
6890 the values from the @samp{.data} input sections and before the end of
6891 the @samp{.data} output section itself.
6893 @cindex dot outside sections
6894 Setting symbols to the value of the location counter outside of an
6895 output section statement can result in unexpected values if the linker
6896 needs to place orphan sections.  For example, given the following:
6898 @smallexample
6899 SECTIONS
6901     start_of_text = . ;
6902     .text: @{ *(.text) @}
6903     end_of_text = . ;
6905     start_of_data = . ;
6906     .data: @{ *(.data) @}
6907     end_of_data = . ;
6909 @end smallexample
6911 If the linker needs to place some input section, e.g. @code{.rodata},
6912 not mentioned in the script, it might choose to place that section
6913 between @code{.text} and @code{.data}.  You might think the linker
6914 should place @code{.rodata} on the blank line in the above script, but
6915 blank lines are of no particular significance to the linker.  As well,
6916 the linker doesn't associate the above symbol names with their
6917 sections.  Instead, it assumes that all assignments or other
6918 statements belong to the previous output section, except for the
6919 special case of an assignment to @code{.}.  I.e., the linker will
6920 place the orphan @code{.rodata} section as if the script was written
6921 as follows:
6923 @smallexample
6924 SECTIONS
6926     start_of_text = . ;
6927     .text: @{ *(.text) @}
6928     end_of_text = . ;
6930     start_of_data = . ;
6931     .rodata: @{ *(.rodata) @}
6932     .data: @{ *(.data) @}
6933     end_of_data = . ;
6935 @end smallexample
6937 This may or may not be the script author's intention for the value of
6938 @code{start_of_data}.  One way to influence the orphan section
6939 placement is to assign the location counter to itself, as the linker
6940 assumes that an assignment to @code{.} is setting the start address of
6941 a following output section and thus should be grouped with that
6942 section.  So you could write:
6944 @smallexample
6945 SECTIONS
6947     start_of_text = . ;
6948     .text: @{ *(.text) @}
6949     end_of_text = . ;
6951     . = . ;
6952     start_of_data = . ;
6953     .data: @{ *(.data) @}
6954     end_of_data = . ;
6956 @end smallexample
6958 Now, the orphan @code{.rodata} section will be placed between
6959 @code{end_of_text} and @code{start_of_data}.
6961 @need 2000
6962 @node Operators
6963 @subsection Operators
6964 @cindex operators for arithmetic
6965 @cindex arithmetic operators
6966 @cindex precedence in expressions
6967 The linker recognizes the standard C set of arithmetic operators, with
6968 the standard bindings and precedence levels:
6969 @c TEXI2ROFF-KILL
6970 @ifnottex
6971 @c END TEXI2ROFF-KILL
6972 @smallexample
6973 precedence      associativity   Operators                           Notes
6974 (highest)
6975 1               left            !  -  ~                             (1)
6976 2               left            *  /  %
6977 3               left            +  -
6978 4               left            >>  <<
6979 5               left            >  <  <=  >=
6980 6               left            ==  !=
6981 7               left            &
6982 8               left            ^
6983 9               left            |
6984 10              left            &&
6985 11              left            ||
6986 12              right           ? :
6987 13              right           +=  -=  *=  /=  <<=  >>=  &=  |= ^= (2)
6988 (lowest)
6989 @end smallexample
6990 Notes:
6991 (1) Prefix operators
6992 (2) @xref{Assignments}.
6993 @c TEXI2ROFF-KILL
6994 @end ifnottex
6995 @tex
6996 \vskip \baselineskip
6997 %"lispnarrowing" is the extra indent used generally for smallexample
6998 \hskip\lispnarrowing\vbox{\offinterlineskip
6999 \hrule
7000 \halign
7001 {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
7002 height2pt&\omit&&\omit&&\omit&\cr
7003 &Precedence&&  Associativity  &&{\rm Operators}&\cr
7004 height2pt&\omit&&\omit&&\omit&\cr
7005 \noalign{\hrule}
7006 height2pt&\omit&&\omit&&\omit&\cr
7007 &highest&&&&&\cr
7008 % '176 is tilde, '~' in tt font
7009 &1&&left&&\qquad-          \char'176\      !\qquad\dag&\cr
7010 &2&&left&&*          /        \%&\cr
7011 &3&&left&&+          -&\cr
7012 &4&&left&&>>         <<&\cr
7013 &5&&left&& >      <      <=      >=&\cr
7014 &6&&left&&==         !=&\cr
7015 &7&&left&&\&&\cr
7016 &8&&left&&\^{}&\cr
7017 &9&&left&&|&\cr
7018 &10&&left&&{\&\&}&\cr
7019 &11&&left&&||&\cr
7020 &12&&right&&?        :&\cr
7021 &13&&right&&\qquad +=       -=     *=     /= <<= >>= \&= |= \^{}=\qquad\ddag&\cr
7022 &lowest&&&&&\cr
7023 height2pt&\omit&&\omit&&\omit&\cr}
7024 \hrule}
7025 @end tex
7026 @iftex
7028 @obeylines@parskip=0pt@parindent=0pt
7029 @dag@quad Prefix operators.
7030 @ddag@quad @xref{Assignments}.
7032 @end iftex
7033 @c END TEXI2ROFF-KILL
7035 @node Evaluation
7036 @subsection Evaluation
7037 @cindex lazy evaluation
7038 @cindex expression evaluation order
7039 The linker evaluates expressions lazily.  It only computes the value of
7040 an expression when absolutely necessary.
7042 The linker needs some information, such as the value of the start
7043 address of the first section, and the origins and lengths of memory
7044 regions, in order to do any linking at all.  These values are computed
7045 as soon as possible when the linker reads in the linker script.
7047 However, other values (such as symbol values) are not known or needed
7048 until after storage allocation.  Such values are evaluated later, when
7049 other information (such as the sizes of output sections) is available
7050 for use in the symbol assignment expression.
7052 The sizes of sections cannot be known until after allocation, so
7053 assignments dependent upon these are not performed until after
7054 allocation.
7056 Some expressions, such as those depending upon the location counter
7057 @samp{.}, must be evaluated during section allocation.
7059 If the result of an expression is required, but the value is not
7060 available, then an error results.  For example, a script like the
7061 following
7062 @smallexample
7063 @group
7064 SECTIONS
7065   @{
7066     .text 9+this_isnt_constant :
7067       @{ *(.text) @}
7068   @}
7069 @end group
7070 @end smallexample
7071 @noindent
7072 will cause the error message @samp{non constant expression for initial
7073 address}.
7075 @node Expression Section
7076 @subsection The Section of an Expression
7077 @cindex expression sections
7078 @cindex absolute expressions
7079 @cindex relative expressions
7080 @cindex absolute and relocatable symbols
7081 @cindex relocatable and absolute symbols
7082 @cindex symbols, relocatable and absolute
7083 Addresses and symbols may be section relative, or absolute.  A section
7084 relative symbol is relocatable.  If you request relocatable output
7085 using the @samp{-r} option, a further link operation may change the
7086 value of a section relative symbol.  On the other hand, an absolute
7087 symbol will retain the same value throughout any further link
7088 operations.
7090 Some terms in linker expressions are addresses.  This is true of
7091 section relative symbols and for builtin functions that return an
7092 address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
7093 @code{SEGMENT_START}.  Other terms are simply numbers, or are builtin
7094 functions that return a non-address value, such as @code{LENGTH}.
7095 One complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
7096 (@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
7097 differently depending on their location, for compatibility with older
7098 versions of @code{ld}.  Expressions appearing outside an output
7099 section definition treat all numbers as absolute addresses.
7100 Expressions appearing inside an output section definition treat
7101 absolute symbols as numbers.  If @code{LD_FEATURE ("SANE_EXPR")} is
7102 given, then absolute symbols and numbers are simply treated as numbers
7103 everywhere.
7105 In the following simple example,
7107 @smallexample
7108 @group
7109 SECTIONS
7110   @{
7111     . = 0x100;
7112     __executable_start = 0x100;
7113     .data :
7114     @{
7115       . = 0x10;
7116       __data_start = 0x10;
7117       *(.data)
7118     @}
7119     @dots{}
7120   @}
7121 @end group
7122 @end smallexample
7124 both @code{.} and @code{__executable_start} are set to the absolute
7125 address 0x100 in the first two assignments, then both @code{.} and
7126 @code{__data_start} are set to 0x10 relative to the @code{.data}
7127 section in the second two assignments.
7129 For expressions involving numbers, relative addresses and absolute
7130 addresses, ld follows these rules to evaluate terms:
7132 @itemize @bullet
7133 @item
7134 Unary operations on an absolute address or number, and binary
7135 operations on two absolute addresses or two numbers, or between one
7136 absolute address and a number, apply the operator to the value(s).
7137 @item
7138 Unary operations on a relative address, and binary operations on two
7139 relative addresses in the same section or between one relative address
7140 and a number, apply the operator to the offset part of the address(es).
7141 @item
7142 Other binary operations, that is, between two relative addresses not
7143 in the same section, or between a relative address and an absolute
7144 address, first convert any non-absolute term to an absolute address
7145 before applying the operator.
7146 @end itemize
7148 The result section of each sub-expression is as follows:
7150 @itemize @bullet
7151 @item
7152 An operation involving only numbers results in a number.
7153 @item
7154 The result of comparisons, @samp{&&} and @samp{||} is also a number.
7155 @item
7156 The result of other binary arithmetic and logical operations on two
7157 relative addresses in the same section or two absolute addresses
7158 (after above conversions) is also a number when
7159 @code{LD_FEATURE ("SANE_EXPR")} or inside an output section definition
7160 but an absolute address otherwise.
7161 @item
7162 The result of other operations on relative addresses or one
7163 relative address and a number, is a relative address in the same
7164 section as the relative operand(s).
7165 @item
7166 The result of other operations on absolute addresses (after above
7167 conversions) is an absolute address.
7168 @end itemize
7170 You can use the builtin function @code{ABSOLUTE} to force an expression
7171 to be absolute when it would otherwise be relative.  For example, to
7172 create an absolute symbol set to the address of the end of the output
7173 section @samp{.data}:
7174 @smallexample
7175 SECTIONS
7176   @{
7177     .data : @{ *(.data) _edata = ABSOLUTE(.); @}
7178   @}
7179 @end smallexample
7180 @noindent
7181 If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
7182 @samp{.data} section.
7184 Using @code{LOADADDR} also forces an expression absolute, since this
7185 particular builtin function returns an absolute address.
7187 @node Builtin Functions
7188 @subsection Builtin Functions
7189 @cindex functions in expressions
7190 The linker script language includes a number of builtin functions for
7191 use in linker script expressions.
7193 @table @code
7194 @item ABSOLUTE(@var{exp})
7195 @kindex ABSOLUTE(@var{exp})
7196 @cindex expression, absolute
7197 Return the absolute (non-relocatable, as opposed to non-negative) value
7198 of the expression @var{exp}.  Primarily useful to assign an absolute
7199 value to a symbol within a section definition, where symbol values are
7200 normally section relative.  @xref{Expression Section}.
7202 @item ADDR(@var{section})
7203 @kindex ADDR(@var{section})
7204 @cindex section address in expression
7205 Return the address (VMA) of the named @var{section}.  Your
7206 script must previously have defined the location of that section.  In
7207 the following example, @code{start_of_output_1}, @code{symbol_1} and
7208 @code{symbol_2} are assigned equivalent values, except that
7209 @code{symbol_1} will be relative to the @code{.output1} section while
7210 the other two will be absolute:
7211 @smallexample
7212 @group
7213 SECTIONS @{ @dots{}
7214   .output1 :
7215     @{
7216     start_of_output_1 = ABSOLUTE(.);
7217     @dots{}
7218     @}
7219   .output :
7220     @{
7221     symbol_1 = ADDR(.output1);
7222     symbol_2 = start_of_output_1;
7223     @}
7224 @dots{} @}
7225 @end group
7226 @end smallexample
7228 @item ALIGN(@var{align})
7229 @itemx ALIGN(@var{exp},@var{align})
7230 @kindex ALIGN(@var{align})
7231 @kindex ALIGN(@var{exp},@var{align})
7232 @cindex round up location counter
7233 @cindex align location counter
7234 @cindex round up expression
7235 @cindex align expression
7236 Return the location counter (@code{.}) or arbitrary expression aligned
7237 to the next @var{align} boundary.  The single operand @code{ALIGN}
7238 doesn't change the value of the location counter---it just does
7239 arithmetic on it.  The two operand @code{ALIGN} allows an arbitrary
7240 expression to be aligned upwards (@code{ALIGN(@var{align})} is
7241 equivalent to @code{ALIGN(ABSOLUTE(.), @var{align})}).
7243 Here is an example which aligns the output @code{.data} section to the
7244 next @code{0x2000} byte boundary after the preceding section and sets a
7245 variable within the section to the next @code{0x8000} boundary after the
7246 input sections:
7247 @smallexample
7248 @group
7249 SECTIONS @{ @dots{}
7250   .data ALIGN(0x2000): @{
7251     *(.data)
7252     variable = ALIGN(0x8000);
7253   @}
7254 @dots{} @}
7255 @end group
7256 @end smallexample
7257 @noindent
7258 The first use of @code{ALIGN} in this example specifies the location of
7259 a section because it is used as the optional @var{address} attribute of
7260 a section definition (@pxref{Output Section Address}).  The second use
7261 of @code{ALIGN} is used to defines the value of a symbol.
7263 The builtin function @code{NEXT} is closely related to @code{ALIGN}.
7265 @item ALIGNOF(@var{section})
7266 @kindex ALIGNOF(@var{section})
7267 @cindex section alignment
7268 Return the alignment in bytes of the named @var{section}, if that section has
7269 been allocated, or zero if the section has not been allocated.  If the
7270 section does not exist in the linker script the linker will report an
7271 error.  If @var{section} is @code{NEXT_SECTION} then @code{ALIGNOF} will
7272 return the alignment of the next allocated section specified in the
7273 linker script, or zero if there is no such section.  In the following
7274 example, the alignment of the @code{.output} section is stored as the
7275 first value in that section.
7276 @smallexample
7277 @group
7278 SECTIONS@{ @dots{}
7279   .output @{
7280     LONG (ALIGNOF (.output))
7281     @dots{}
7282     @}
7283 @dots{} @}
7284 @end group
7285 @end smallexample
7287 @item BLOCK(@var{exp})
7288 @kindex BLOCK(@var{exp})
7289 This is a synonym for @code{ALIGN}, for compatibility with older linker
7290 scripts.  It is most often seen when setting the address of an output
7291 section.
7293 @item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7294 @kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7295 This is equivalent to either
7296 @smallexample
7297 (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
7298 @end smallexample
7300 @smallexample
7301 (ALIGN(@var{maxpagesize})
7302  + ((. + @var{commonpagesize} - 1) & (@var{maxpagesize} - @var{commonpagesize})))
7303 @end smallexample
7304 @noindent
7305 depending on whether the latter uses fewer @var{commonpagesize} sized pages
7306 for the data segment (area between the result of this expression and
7307 @code{DATA_SEGMENT_END}) than the former or not.
7308 If the latter form is used, it means @var{commonpagesize} bytes of runtime
7309 memory will be saved at the expense of up to @var{commonpagesize} wasted
7310 bytes in the on-disk file.
7312 This expression can only be used directly in @code{SECTIONS} commands, not in
7313 any output section descriptions and only once in the linker script.
7314 @var{commonpagesize} should be less or equal to @var{maxpagesize} and should
7315 be the system page size the object wants to be optimized for while still
7316 running on system page sizes up to @var{maxpagesize}.  Note however
7317 that @samp{-z relro} protection will not be effective if the system
7318 page size is larger than @var{commonpagesize}.
7320 @noindent
7321 Example:
7322 @smallexample
7323   . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
7324 @end smallexample
7326 @item DATA_SEGMENT_END(@var{exp})
7327 @kindex DATA_SEGMENT_END(@var{exp})
7328 This defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
7329 evaluation purposes.
7331 @smallexample
7332   . = DATA_SEGMENT_END(.);
7333 @end smallexample
7335 @item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7336 @kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7337 This defines the end of the @code{PT_GNU_RELRO} segment when
7338 @samp{-z relro} option is used.
7339 When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
7340 does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
7341 @var{exp} + @var{offset} is aligned to the @var{commonpagesize}
7342 argument given to @code{DATA_SEGMENT_ALIGN}.  If present in the linker
7343 script, it must be placed between @code{DATA_SEGMENT_ALIGN} and
7344 @code{DATA_SEGMENT_END}.  Evaluates to the second argument plus any
7345 padding needed at the end of the @code{PT_GNU_RELRO} segment due to
7346 section alignment.
7348 @smallexample
7349   . = DATA_SEGMENT_RELRO_END(24, .);
7350 @end smallexample
7352 @item DEFINED(@var{symbol})
7353 @kindex DEFINED(@var{symbol})
7354 @cindex symbol defaults
7355 Return 1 if @var{symbol} is in the linker global symbol table and is
7356 defined before the statement using DEFINED in the script, otherwise
7357 return 0.  You can use this function to provide
7358 default values for symbols.  For example, the following script fragment
7359 shows how to set a global symbol @samp{begin} to the first location in
7360 the @samp{.text} section---but if a symbol called @samp{begin} already
7361 existed, its value is preserved:
7363 @smallexample
7364 @group
7365 SECTIONS @{ @dots{}
7366   .text : @{
7367     begin = DEFINED(begin) ? begin : . ;
7368     @dots{}
7369   @}
7370   @dots{}
7372 @end group
7373 @end smallexample
7375 @item LENGTH(@var{memory})
7376 @kindex LENGTH(@var{memory})
7377 Return the length of the memory region named @var{memory}.
7379 @item LOADADDR(@var{section})
7380 @kindex LOADADDR(@var{section})
7381 @cindex section load address in expression
7382 Return the absolute LMA of the named @var{section}.  (@pxref{Output
7383 Section LMA}).
7385 @item LOG2CEIL(@var{exp})
7386 @kindex LOG2CEIL(@var{exp})
7387 Return the binary logarithm of @var{exp} rounded towards infinity.
7388 @code{LOG2CEIL(0)} returns 0.
7390 @kindex MAX
7391 @item MAX(@var{exp1}, @var{exp2})
7392 Returns the maximum of @var{exp1} and @var{exp2}.
7394 @kindex MIN
7395 @item MIN(@var{exp1}, @var{exp2})
7396 Returns the minimum of @var{exp1} and @var{exp2}.
7398 @item NEXT(@var{exp})
7399 @kindex NEXT(@var{exp})
7400 @cindex unallocated address, next
7401 Return the next unallocated address that is a multiple of @var{exp}.
7402 This function is closely related to @code{ALIGN(@var{exp})}; unless you
7403 use the @code{MEMORY} command to define discontinuous memory for the
7404 output file, the two functions are equivalent.
7406 @item ORIGIN(@var{memory})
7407 @kindex ORIGIN(@var{memory})
7408 Return the origin of the memory region named @var{memory}.
7410 @item SEGMENT_START(@var{segment}, @var{default})
7411 @kindex SEGMENT_START(@var{segment}, @var{default})
7412 Return the base address of the named @var{segment}.  If an explicit
7413 value has already been given for this segment (with a command-line
7414 @samp{-T} option) then that value will be returned otherwise the value
7415 will be @var{default}.  At present, the @samp{-T} command-line option
7416 can only be used to set the base address for the ``text'', ``data'', and
7417 ``bss'' sections, but you can use @code{SEGMENT_START} with any segment
7418 name.
7420 @item SIZEOF(@var{section})
7421 @kindex SIZEOF(@var{section})
7422 @cindex section size
7423 Return the size in bytes of the named @var{section}, if that section has
7424 been allocated, or zero if the section has not been allocated.  If the
7425 section does not exist in the linker script the linker will report an
7426 error.  If @var{section} is @code{NEXT_SECTION} then @code{SIZEOF} will
7427 return the alignment of the next allocated section specified in the
7428 linker script, or zero if there is no such section.  In the following
7429 example, @code{symbol_1} and @code{symbol_2} are assigned identical
7430 values:
7431 @smallexample
7432 @group
7433 SECTIONS@{ @dots{}
7434   .output @{
7435     .start = . ;
7436     @dots{}
7437     .end = . ;
7438     @}
7439   symbol_1 = .end - .start ;
7440   symbol_2 = SIZEOF(.output);
7441 @dots{} @}
7442 @end group
7443 @end smallexample
7445 @item SIZEOF_HEADERS
7446 @kindex SIZEOF_HEADERS
7447 @cindex header size
7448 Return the size in bytes of the output file's headers.  This is
7449 information which appears at the start of the output file.  You can use
7450 this number when setting the start address of the first section, if you
7451 choose, to facilitate paging.
7453 @cindex not enough room for program headers
7454 @cindex program headers, not enough room
7455 When producing an ELF output file, if the linker script uses the
7456 @code{SIZEOF_HEADERS} builtin function, the linker must compute the
7457 number of program headers before it has determined all the section
7458 addresses and sizes.  If the linker later discovers that it needs
7459 additional program headers, it will report an error @samp{not enough
7460 room for program headers}.  To avoid this error, you must avoid using
7461 the @code{SIZEOF_HEADERS} function, or you must rework your linker
7462 script to avoid forcing the linker to use additional program headers, or
7463 you must define the program headers yourself using the @code{PHDRS}
7464 command (@pxref{PHDRS}).
7465 @end table
7467 @node Implicit Linker Scripts
7468 @section Implicit Linker Scripts
7469 @cindex implicit linker scripts
7470 If you specify a linker input file which the linker can not recognize as
7471 an object file or an archive file, it will try to read the file as a
7472 linker script.  If the file can not be parsed as a linker script, the
7473 linker will report an error.
7475 An implicit linker script will not replace the default linker script.
7477 Typically an implicit linker script would contain only symbol
7478 assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
7479 commands.
7481 Any input files read because of an implicit linker script will be read
7482 at the position in the command line where the implicit linker script was
7483 read.  This can affect archive searching.
7485 @node Plugins
7486 @chapter Linker Plugins
7488 @cindex plugins
7489 @cindex linker plugins
7490 The linker can use dynamically loaded plugins to modify its behavior.
7491 For example, the link-time optimization feature that some compilers
7492 support is implemented with a linker plugin.
7494 Currently there is only one plugin shipped by default, but more may
7495 be added here later.
7497 Plugins are enabled via the use of the @option{-plugin @var{name}}
7498 command line option. @xref{Options}.
7500 @menu
7501 * libdep Plugin::       Static Library Dependencies Plugin
7502 @end menu
7504 @node libdep Plugin
7505 @section Static Library Dependencies Plugin
7506 @cindex static library dependencies
7507 Originally, static libraries were contained in an archive file consisting
7508 just of a collection of relocatable object files.  Later they evolved to
7509 optionally include a symbol table, to assist in finding the needed objects
7510 within a library.  There their evolution ended, and dynamic libraries
7511 rose to ascendance.
7513 One useful feature of dynamic libraries was that, more than just collecting
7514 multiple objects into a single file, they also included a list of their
7515 dependencies, such that one could specify just the name of a single dynamic
7516 library at link time, and all of its dependencies would be implicitly
7517 referenced as well.  But static libraries lacked this feature, so if a
7518 link invocation was switched from using dynamic libraries to static
7519 libraries, the link command would usually fail unless it was rewritten to
7520 explicitly list the dependencies of the static library.
7522 The GNU @command{ar} utility now supports a @option{--record-libdeps} option
7523 to embed dependency lists into static libraries as well, and the @file{libdep}
7524 plugin may be used to read this dependency information at link time.  The
7525 dependency information is stored as a single string, carrying @option{-l}
7526 and @option{-L} arguments as they would normally appear in a linker
7527 command line.  As such, the information can be written with any text
7528 utility and stored into any archive, even if GNU @command{ar} is not
7529 being used to create the archive.  The information is stored in an
7530 archive member named @samp{__.LIBDEP}.
7532 For example, given a library @file{libssl.a} that depends on another
7533 library @file{libcrypto.a} which may be found in @file{/usr/local/lib},
7534 the @samp{__.LIBDEP} member of @file{libssl.a} would contain
7536 @smallexample
7537 -L/usr/local/lib -lcrypto
7538 @end smallexample
7540 @node Special Sections
7541 @chapter Special Sections
7542 When linking ELF format object files @command{ld} treats some sections
7543 in a special, non standard manner.  This part of the manual describes
7544 these sections.
7546 @table @gcctabopt
7547 @item .gnu.warning
7548 The contents of any section with this name are assumed to be an ascii
7549 format warning message.  The contents will be displayed to the user if
7550 the sections appears in any input file, but the section will not be
7551 copied into the output image.  If the @option{--fatal-warnings} option
7552 is enabled then the warnings - if any are encountered - will also stop
7553 the link from completing.
7555 Note - the @samp{.gnu.warning} section is not subject to linker
7556 garbage collection or orphan handling.
7558 @item .gnu.warning.@var{SYM}
7559 The contents of any section whoes name starts with the prefix
7560 @samp{.gnu.warning.} and then finishes with the name of a symbol is
7561 treated in a similar fashion to the @samp{.gnu.warning} section, but
7562 only if the named symbol is referenced.  So for example the contents
7563 of a section called @samp{.gnu.warning.foo} will be displayed as
7564 warning message if, and only if, the symbol @samp{foo} is referenced
7565 by one or more of the input files.  This includes object files pulled
7566 in from static libraries, shared objects needed to complete the link
7567 and so on.
7569 Note - because these warning messages are generated before the linker
7570 performs garbage collection (if enabled) it is possible for a warning
7571 to be displayed for a symbol that is later removed and then never
7572 appears in the final output.
7574 @item .note.gnu.property
7575 When the linker combines sections of this name it will merge them
7576 together according to various rules encoded into the notes
7577 themselves.  Therefore the contents of the output .note.gnu.property
7578 section may not correspond to a simple concatenation of the input
7579 sections.  If the @option{-Map} option has been used to request a
7580 linker map then details of any property merging will be included in
7581 the map.
7583 @end table
7585 @ifset GENERIC
7586 @node Machine Dependent
7587 @chapter Machine Dependent Features
7589 @cindex machine dependencies
7590 @command{ld} has additional features on some platforms; the following
7591 sections describe them.  Machines where @command{ld} has no additional
7592 functionality are not listed.
7594 @menu
7595 @ifset H8300
7596 * H8/300::                      @command{ld} and the H8/300
7597 @end ifset
7598 @ifset M68HC11
7599 * M68HC11/68HC12::              @code{ld} and the Motorola 68HC11 and 68HC12 families
7600 @end ifset
7601 @ifset ARM
7602 * ARM::                         @command{ld} and the ARM family
7603 @end ifset
7604 @ifset HPPA
7605 * HPPA ELF32::                  @command{ld} and HPPA 32-bit ELF
7606 @end ifset
7607 @ifset M68K
7608 * M68K::                        @command{ld} and the Motorola 68K family
7609 @end ifset
7610 @ifset MIPS
7611 * MIPS::                        @command{ld} and the MIPS family
7612 @end ifset
7613 @ifset MMIX
7614 * MMIX::                        @command{ld} and MMIX
7615 @end ifset
7616 @ifset MSP430
7617 * MSP430::                      @command{ld} and MSP430
7618 @end ifset
7619 @ifset NDS32
7620 * NDS32::                       @command{ld} and NDS32
7621 @end ifset
7622 @ifset NIOSII
7623 * Nios II::                     @command{ld} and the Altera Nios II
7624 @end ifset
7625 @ifset POWERPC
7626 * PowerPC ELF32::               @command{ld} and PowerPC 32-bit ELF Support
7627 @end ifset
7628 @ifset POWERPC64
7629 * PowerPC64 ELF64::             @command{ld} and PowerPC64 64-bit ELF Support
7630 @end ifset
7631 @ifset S/390
7632 * S/390 ELF::                   @command{ld} and S/390 ELF Support
7633 @end ifset
7634 @ifset SPU
7635 * SPU ELF::                     @command{ld} and SPU ELF Support
7636 @end ifset
7637 @ifset TICOFF
7638 * TI COFF::                     @command{ld} and TI COFF
7639 @end ifset
7640 @ifset WIN32
7641 * WIN32::                       @command{ld} and WIN32 (cygwin/mingw)
7642 @end ifset
7643 @ifset XTENSA
7644 * Xtensa::                      @command{ld} and Xtensa Processors
7645 @end ifset
7646 @end menu
7647 @end ifset
7649 @ifset H8300
7650 @ifclear GENERIC
7651 @raisesections
7652 @end ifclear
7654 @node H8/300
7655 @section @command{ld} and the H8/300
7657 @cindex H8/300 support
7658 For the H8/300, @command{ld} can perform these global optimizations when
7659 you specify the @samp{--relax} command-line option.
7661 @table @emph
7662 @cindex relaxing on H8/300
7663 @item relaxing address modes
7664 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7665 targets are within eight bits, and turns them into eight-bit
7666 program-counter relative @code{bsr} and @code{bra} instructions,
7667 respectively.
7669 @cindex synthesizing on H8/300
7670 @item synthesizing instructions
7671 @c FIXME: specifically mov.b, or any mov instructions really? -> mov.b only, at least on H8, H8H, H8S
7672 @command{ld} finds all @code{mov.b} instructions which use the
7673 sixteen-bit absolute address form, but refer to the top
7674 page of memory, and changes them to use the eight-bit address form.
7675 (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
7676 @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
7677 top page of memory).
7679 @command{ld} finds all @code{mov} instructions which use the register
7680 indirect with 32-bit displacement addressing mode, but use a small
7681 displacement inside 16-bit displacement range, and changes them to use
7682 the 16-bit displacement form.  (That is: the linker turns @samp{mov.b
7683 @code{@@}@var{d}:32,ERx} into @samp{mov.b @code{@@}@var{d}:16,ERx}
7684 whenever the displacement @var{d} is in the 16 bit signed integer
7685 range. Only implemented in ELF-format ld).
7687 @item bit manipulation instructions
7688 @command{ld} finds all bit manipulation instructions like @code{band, bclr,
7689 biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor}
7690 which use 32 bit and 16 bit absolute address form, but refer to the top
7691 page of memory, and changes them to use the 8 bit address form.
7692 (That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into
7693 @samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in
7694 the top page of memory).
7696 @item system control instructions
7697 @command{ld} finds all @code{ldc.w, stc.w} instructions which use the
7698 32 bit absolute address form, but refer to the top page of memory, and
7699 changes them to use 16 bit address form.
7700 (That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into
7701 @samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in
7702 the top page of memory).
7703 @end table
7705 @ifclear GENERIC
7706 @lowersections
7707 @end ifclear
7708 @end ifset
7710 @ifclear GENERIC
7711 @ifset Renesas
7712 @c This stuff is pointless to say unless you're especially concerned
7713 @c with Renesas chips; don't enable it for generic case, please.
7714 @node Renesas
7715 @chapter @command{ld} and Other Renesas Chips
7717 @command{ld} also supports the Renesas (formerly Hitachi) H8/300H,
7718 H8/500, and SH chips.  No special features, commands, or command-line
7719 options are required for these chips.
7720 @end ifset
7721 @end ifclear
7723 @ifset ARM
7724 @ifclear GENERIC
7725 @raisesections
7726 @end ifclear
7728 @ifset M68HC11
7729 @ifclear GENERIC
7730 @raisesections
7731 @end ifclear
7733 @node M68HC11/68HC12
7734 @section @command{ld} and the Motorola 68HC11 and 68HC12 families
7736 @cindex M68HC11 and 68HC12 support
7738 @subsection Linker Relaxation
7740 For the Motorola 68HC11, @command{ld} can perform these global
7741 optimizations when you specify the @samp{--relax} command-line option.
7743 @table @emph
7744 @cindex relaxing on M68HC11
7745 @item relaxing address modes
7746 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7747 targets are within eight bits, and turns them into eight-bit
7748 program-counter relative @code{bsr} and @code{bra} instructions,
7749 respectively.
7751 @command{ld} also looks at all 16-bit extended addressing modes and
7752 transforms them in a direct addressing mode when the address is in
7753 page 0 (between 0 and 0x0ff).
7755 @item relaxing gcc instruction group
7756 When @command{gcc} is called with @option{-mrelax}, it can emit group
7757 of instructions that the linker can optimize to use a 68HC11 direct
7758 addressing mode. These instructions consists of @code{bclr} or
7759 @code{bset} instructions.
7761 @end table
7763 @subsection Trampoline Generation
7765 @cindex trampoline generation on M68HC11
7766 @cindex trampoline generation on M68HC12
7767 For 68HC11 and 68HC12, @command{ld} can generate trampoline code to
7768 call a far function using a normal @code{jsr} instruction. The linker
7769 will also change the relocation to some far function to use the
7770 trampoline address instead of the function address. This is typically the
7771 case when a pointer to a function is taken. The pointer will in fact
7772 point to the function trampoline.
7774 @ifclear GENERIC
7775 @lowersections
7776 @end ifclear
7777 @end ifset
7779 @node ARM
7780 @section @command{ld} and the ARM family
7782 @cindex ARM interworking support
7783 @kindex --support-old-code
7784 For the ARM, @command{ld} will generate code stubs to allow functions calls
7785 between ARM and Thumb code.  These stubs only work with code that has
7786 been compiled and assembled with the @samp{-mthumb-interwork} command
7787 line option.  If it is necessary to link with old ARM object files or
7788 libraries, which have not been compiled with the -mthumb-interwork
7789 option then the @samp{--support-old-code} command-line switch should be
7790 given to the linker.  This will make it generate larger stub functions
7791 which will work with non-interworking aware ARM code.  Note, however,
7792 the linker does not support generating stubs for function calls to
7793 non-interworking aware Thumb code.
7795 @cindex thumb entry point
7796 @cindex entry point, thumb
7797 @kindex --thumb-entry=@var{entry}
7798 The @samp{--thumb-entry} switch is a duplicate of the generic
7799 @samp{--entry} switch, in that it sets the program's starting address.
7800 But it also sets the bottom bit of the address, so that it can be
7801 branched to using a BX instruction, and the program will start
7802 executing in Thumb mode straight away.
7804 @cindex PE import table prefixing
7805 @kindex --use-nul-prefixed-import-tables
7806 The @samp{--use-nul-prefixed-import-tables} switch is specifying, that
7807 the import tables idata4 and idata5 have to be generated with a zero
7808 element prefix for import libraries. This is the old style to generate
7809 import tables. By default this option is turned off.
7811 @cindex BE8
7812 @kindex --be8
7813 The @samp{--be8} switch instructs @command{ld} to generate BE8 format
7814 executables.  This option is only valid when linking big-endian
7815 objects - ie ones which have been assembled with the @option{-EB}
7816 option.  The resulting image will contain big-endian data and
7817 little-endian code.
7819 @cindex TARGET1
7820 @kindex --target1-rel
7821 @kindex --target1-abs
7822 The @samp{R_ARM_TARGET1} relocation is typically used for entries in the
7823 @samp{.init_array} section.  It is interpreted as either @samp{R_ARM_REL32}
7824 or @samp{R_ARM_ABS32}, depending on the target.  The @samp{--target1-rel}
7825 and @samp{--target1-abs} switches override the default.
7827 @cindex TARGET2
7828 @kindex --target2=@var{type}
7829 The @samp{--target2=type} switch overrides the default definition of the
7830 @samp{R_ARM_TARGET2} relocation.  Valid values for @samp{type}, their
7831 meanings, and target defaults are as follows:
7832 @table @samp
7833 @item rel
7834 @samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
7835 @item abs
7836 @samp{R_ARM_ABS32}
7837 @item got-rel
7838 @samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
7839 @end table
7841 @cindex FIX_V4BX
7842 @kindex --fix-v4bx
7843 The @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
7844 specification) enables objects compiled for the ARMv4 architecture to be
7845 interworking-safe when linked with other objects compiled for ARMv4t, but
7846 also allows pure ARMv4 binaries to be built from the same ARMv4 objects.
7848 In the latter case, the switch @option{--fix-v4bx} must be passed to the
7849 linker, which causes v4t @code{BX rM} instructions to be rewritten as
7850 @code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
7852 In the former case, the switch should not be used, and @samp{R_ARM_V4BX}
7853 relocations are ignored.
7855 @cindex FIX_V4BX_INTERWORKING
7856 @kindex --fix-v4bx-interworking
7857 Replace @code{BX rM} instructions identified by @samp{R_ARM_V4BX}
7858 relocations with a branch to the following veneer:
7860 @smallexample
7861 TST rM, #1
7862 MOVEQ PC, rM
7863 BX Rn
7864 @end smallexample
7866 This allows generation of libraries/applications that work on ARMv4 cores
7867 and are still interworking safe.  Note that the above veneer clobbers the
7868 condition flags, so may cause incorrect program behavior in rare cases.
7870 @cindex USE_BLX
7871 @kindex --use-blx
7872 The @samp{--use-blx} switch enables the linker to use ARM/Thumb
7873 BLX instructions (available on ARMv5t and above) in various
7874 situations. Currently it is used to perform calls via the PLT from Thumb
7875 code using BLX rather than using BX and a mode-switching stub before
7876 each PLT entry. This should lead to such calls executing slightly faster.
7878 @cindex VFP11_DENORM_FIX
7879 @kindex --vfp11-denorm-fix
7880 The @samp{--vfp11-denorm-fix} switch enables a link-time workaround for a
7881 bug in certain VFP11 coprocessor hardware, which sometimes allows
7882 instructions with denorm operands (which must be handled by support code)
7883 to have those operands overwritten by subsequent instructions before
7884 the support code can read the intended values.
7886 The bug may be avoided in scalar mode if you allow at least one
7887 intervening instruction between a VFP11 instruction which uses a register
7888 and another instruction which writes to the same register, or at least two
7889 intervening instructions if vector mode is in use. The bug only affects
7890 full-compliance floating-point mode: you do not need this workaround if
7891 you are using "runfast" mode. Please contact ARM for further details.
7893 If you know you are using buggy VFP11 hardware, you can
7894 enable this workaround by specifying the linker option
7895 @samp{--vfp-denorm-fix=scalar} if you are using the VFP11 scalar
7896 mode only, or @samp{--vfp-denorm-fix=vector} if you are using
7897 vector mode (the latter also works for scalar code). The default is
7898 @samp{--vfp-denorm-fix=none}.
7900 If the workaround is enabled, instructions are scanned for
7901 potentially-troublesome sequences, and a veneer is created for each
7902 such sequence which may trigger the erratum. The veneer consists of the
7903 first instruction of the sequence and a branch back to the subsequent
7904 instruction. The original instruction is then replaced with a branch to
7905 the veneer. The extra cycles required to call and return from the veneer
7906 are sufficient to avoid the erratum in both the scalar and vector cases.
7908 @cindex ARM1176 erratum workaround
7909 @kindex --fix-arm1176
7910 @kindex --no-fix-arm1176
7911 The @samp{--fix-arm1176} switch enables a link-time workaround for an erratum
7912 in certain ARM1176 processors.  The workaround is enabled by default if you
7913 are targeting ARM v6 (excluding ARM v6T2) or earlier.  It can be disabled
7914 unconditionally by specifying @samp{--no-fix-arm1176}.
7916 Further information is available in the ``ARM1176JZ-S and ARM1176JZF-S
7917 Programmer Advice Notice'' available on the ARM documentation website at:
7918 http://infocenter.arm.com/.
7920 @cindex STM32L4xx erratum workaround
7921 @kindex --fix-stm32l4xx-629360
7923 The @samp{--fix-stm32l4xx-629360} switch enables a link-time
7924 workaround for a bug in the bus matrix / memory controller for some of
7925 the STM32 Cortex-M4 based products (STM32L4xx).  When accessing
7926 off-chip memory via the affected bus for bus reads of 9 words or more,
7927 the bus can generate corrupt data and/or abort.  These are only
7928 core-initiated accesses (not DMA), and might affect any access:
7929 integer loads such as LDM, POP and floating-point loads such as VLDM,
7930 VPOP.  Stores are not affected.
7932 The bug can be avoided by splitting memory accesses into the
7933 necessary chunks to keep bus reads below 8 words.
7935 The workaround is not enabled by default, this is equivalent to use
7936 @samp{--fix-stm32l4xx-629360=none}.  If you know you are using buggy
7937 STM32L4xx hardware, you can enable the workaround by specifying the
7938 linker option @samp{--fix-stm32l4xx-629360}, or the equivalent
7939 @samp{--fix-stm32l4xx-629360=default}.
7941 If the workaround is enabled, instructions are scanned for
7942 potentially-troublesome sequences, and a veneer is created for each
7943 such sequence which may trigger the erratum.  The veneer consists in a
7944 replacement sequence emulating the behaviour of the original one and a
7945 branch back to the subsequent instruction.  The original instruction is
7946 then replaced with a branch to the veneer.
7948 The workaround does not always preserve the memory access order for
7949 the LDMDB instruction, when the instruction loads the PC.
7951 The workaround is not able to handle problematic instructions when
7952 they are in the middle of an IT block, since a branch is not allowed
7953 there.  In that case, the linker reports a warning and no replacement
7954 occurs.
7956 The workaround is not able to replace problematic instructions with a
7957 PC-relative branch instruction if the @samp{.text} section is too
7958 large.  In that case, when the branch that replaces the original code
7959 cannot be encoded, the linker reports a warning and no replacement
7960 occurs.
7962 @cindex NO_ENUM_SIZE_WARNING
7963 @kindex --no-enum-size-warning
7964 The @option{--no-enum-size-warning} switch prevents the linker from
7965 warning when linking object files that specify incompatible EABI
7966 enumeration size attributes.  For example, with this switch enabled,
7967 linking of an object file using 32-bit enumeration values with another
7968 using enumeration values fitted into the smallest possible space will
7969 not be diagnosed.
7971 @cindex NO_WCHAR_SIZE_WARNING
7972 @kindex --no-wchar-size-warning
7973 The @option{--no-wchar-size-warning} switch prevents the linker from
7974 warning when linking object files that specify incompatible EABI
7975 @code{wchar_t} size attributes.  For example, with this switch enabled,
7976 linking of an object file using 32-bit @code{wchar_t} values with another
7977 using 16-bit @code{wchar_t} values will not be diagnosed.
7979 @cindex PIC_VENEER
7980 @kindex --pic-veneer
7981 The @samp{--pic-veneer} switch makes the linker use PIC sequences for
7982 ARM/Thumb interworking veneers, even if the rest of the binary
7983 is not PIC.  This avoids problems on uClinux targets where
7984 @samp{--emit-relocs} is used to generate relocatable binaries.
7986 @cindex STUB_GROUP_SIZE
7987 @kindex --stub-group-size=@var{N}
7988 The linker will automatically generate and insert small sequences of
7989 code into a linked ARM ELF executable whenever an attempt is made to
7990 perform a function call to a symbol that is too far away.  The
7991 placement of these sequences of instructions - called stubs - is
7992 controlled by the command-line option @option{--stub-group-size=N}.
7993 The placement is important because a poor choice can create a need for
7994 duplicate stubs, increasing the code size.  The linker will try to
7995 group stubs together in order to reduce interruptions to the flow of
7996 code, but it needs guidance as to how big these groups should be and
7997 where they should be placed.
7999 The value of @samp{N}, the parameter to the
8000 @option{--stub-group-size=} option controls where the stub groups are
8001 placed.  If it is negative then all stubs are placed after the first
8002 branch that needs them.  If it is positive then the stubs can be
8003 placed either before or after the branches that need them.  If the
8004 value of @samp{N} is 1 (either +1 or -1) then the linker will choose
8005 exactly where to place groups of stubs, using its built in heuristics.
8006 A value of @samp{N} greater than 1 (or smaller than -1) tells the
8007 linker that a single group of stubs can service at most @samp{N} bytes
8008 from the input sections.
8010 The default, if @option{--stub-group-size=} is not specified, is
8011 @samp{N = +1}.
8013 Farcalls stubs insertion is fully supported for the ARM-EABI target
8014 only, because it relies on object files properties not present
8015 otherwise.
8017 @cindex Cortex-A8 erratum workaround
8018 @kindex --fix-cortex-a8
8019 @kindex --no-fix-cortex-a8
8020 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}.
8022 The erratum only affects Thumb-2 code.  Please contact ARM for further details.
8024 @cindex Cortex-A53 erratum 835769 workaround
8025 @kindex --fix-cortex-a53-835769
8026 @kindex --no-fix-cortex-a53-835769
8027 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}.
8029 Please contact ARM for further details.
8031 @kindex --merge-exidx-entries
8032 @kindex --no-merge-exidx-entries
8033 @cindex Merging exidx entries
8034 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent exidx entries in debuginfo.
8036 @kindex --long-plt
8037 @cindex 32-bit PLT entries
8038 The @samp{--long-plt} option enables the use of 16 byte PLT entries
8039 which support up to 4Gb of code.  The default is to use 12 byte PLT
8040 entries which only support 512Mb of code.
8042 @kindex --no-apply-dynamic-relocs
8043 @cindex AArch64 rela addend
8044 The @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
8045 link-time values for dynamic relocations.
8047 @cindex Placement of SG veneers
8048 All SG veneers are placed in the special output section @code{.gnu.sgstubs}.
8049 Its start address must be set, either with the command-line option
8050 @samp{--section-start} or in a linker script, to indicate where to place these
8051 veneers in memory.
8053 @kindex --cmse-implib
8054 @cindex Secure gateway import library
8055 The @samp{--cmse-implib} option requests that the import libraries
8056 specified by the @samp{--out-implib} and @samp{--in-implib} options are
8057 secure gateway import libraries, suitable for linking a non-secure
8058 executable against secure code as per ARMv8-M Security Extensions.
8060 @kindex --in-implib=@var{file}
8061 @cindex Input import library
8062 The @samp{--in-implib=file} specifies an input import library whose symbols
8063 must keep the same address in the executable being produced.  A warning is
8064 given if no @samp{--out-implib} is given but new symbols have been introduced
8065 in the executable that should be listed in its import library.  Otherwise, if
8066 @samp{--out-implib} is specified, the symbols are added to the output import
8067 library.  A warning is also given if some symbols present in the input import
8068 library have disappeared from the executable.  This option is only effective
8069 for Secure Gateway import libraries, ie. when @samp{--cmse-implib} is
8070 specified.
8072 @ifclear GENERIC
8073 @lowersections
8074 @end ifclear
8075 @end ifset
8077 @ifset HPPA
8078 @ifclear GENERIC
8079 @raisesections
8080 @end ifclear
8082 @node HPPA ELF32
8083 @section @command{ld} and HPPA 32-bit ELF Support
8084 @cindex HPPA multiple sub-space stubs
8085 @kindex --multi-subspace
8086 When generating a shared library, @command{ld} will by default generate
8087 import stubs suitable for use with a single sub-space application.
8088 The @samp{--multi-subspace} switch causes @command{ld} to generate export
8089 stubs, and different (larger) import stubs suitable for use with
8090 multiple sub-spaces.
8092 @cindex HPPA stub grouping
8093 @kindex --stub-group-size=@var{N}
8094 Long branch stubs and import/export stubs are placed by @command{ld} in
8095 stub sections located between groups of input sections.
8096 @samp{--stub-group-size} specifies the maximum size of a group of input
8097 sections handled by one stub section.  Since branch offsets are signed,
8098 a stub section may serve two groups of input sections, one group before
8099 the stub section, and one group after it.  However, when using
8100 conditional branches that require stubs, it may be better (for branch
8101 prediction) that stub sections only serve one group of input sections.
8102 A negative value for @samp{N} chooses this scheme, ensuring that
8103 branches to stubs always use a negative offset.  Two special values of
8104 @samp{N} are recognized, @samp{1} and @samp{-1}.  These both instruct
8105 @command{ld} to automatically size input section groups for the branch types
8106 detected, with the same behaviour regarding stub placement as other
8107 positive or negative values of @samp{N} respectively.
8109 Note that @samp{--stub-group-size} does not split input sections.  A
8110 single input section larger than the group size specified will of course
8111 create a larger group (of one section).  If input sections are too
8112 large, it may not be possible for a branch to reach its stub.
8114 @ifclear GENERIC
8115 @lowersections
8116 @end ifclear
8117 @end ifset
8119 @ifset M68K
8120 @ifclear GENERIC
8121 @raisesections
8122 @end ifclear
8124 @node M68K
8125 @section @command{ld} and the Motorola 68K family
8127 @cindex Motorola 68K GOT generation
8128 @kindex --got=@var{type}
8129 The @samp{--got=@var{type}} option lets you choose the GOT generation scheme.
8130 The choices are @samp{single}, @samp{negative}, @samp{multigot} and
8131 @samp{target}.  When @samp{target} is selected the linker chooses
8132 the default GOT generation scheme for the current target.
8133 @samp{single} tells the linker to generate a single GOT with
8134 entries only at non-negative offsets.
8135 @samp{negative} instructs the linker to generate a single GOT with
8136 entries at both negative and positive offsets.  Not all environments
8137 support such GOTs.
8138 @samp{multigot} allows the linker to generate several GOTs in the
8139 output file.  All GOT references from a single input object
8140 file access the same GOT, but references from different input object
8141 files might access different GOTs.  Not all environments support such GOTs.
8143 @ifclear GENERIC
8144 @lowersections
8145 @end ifclear
8146 @end ifset
8148 @ifset MIPS
8149 @ifclear GENERIC
8150 @raisesections
8151 @end ifclear
8153 @node MIPS
8154 @section @command{ld} and the MIPS family
8156 @cindex MIPS microMIPS instruction choice selection
8157 @kindex --insn32
8158 @kindex --no-insn32
8159 The @samp{--insn32} and @samp{--no-insn32} options control the choice of
8160 microMIPS instructions used in code generated by the linker, such as that
8161 in the PLT or lazy binding stubs, or in relaxation.  If @samp{--insn32} is
8162 used, then the linker only uses 32-bit instruction encodings.  By default
8163 or if @samp{--no-insn32} is used, all instruction encodings are used,
8164 including 16-bit ones where possible.
8166 @cindex MIPS branch relocation check control
8167 @kindex --ignore-branch-isa
8168 @kindex --no-ignore-branch-isa
8169 The @samp{--ignore-branch-isa} and @samp{--no-ignore-branch-isa} options
8170 control branch relocation checks for invalid ISA mode transitions.  If
8171 @samp{--ignore-branch-isa} is used, then the linker accepts any branch
8172 relocations and any ISA mode transition required is lost in relocation
8173 calculation, except for some cases of @code{BAL} instructions which meet
8174 relaxation conditions and are converted to equivalent @code{JALX}
8175 instructions as the associated relocation is calculated.  By default
8176 or if @samp{--no-ignore-branch-isa} is used a check is made causing
8177 the loss of an ISA mode transition to produce an error.
8179 @ifclear GENERIC
8180 @lowersections
8181 @end ifclear
8182 @end ifset
8184 @ifset MMIX
8185 @ifclear GENERIC
8186 @raisesections
8187 @end ifclear
8189 @node MMIX
8190 @section @code{ld} and MMIX
8191 For MMIX, there is a choice of generating @code{ELF} object files or
8192 @code{mmo} object files when linking.  The simulator @code{mmix}
8193 understands the @code{mmo} format.  The binutils @code{objcopy} utility
8194 can translate between the two formats.
8196 There is one special section, the @samp{.MMIX.reg_contents} section.
8197 Contents in this section is assumed to correspond to that of global
8198 registers, and symbols referring to it are translated to special symbols,
8199 equal to registers.  In a final link, the start address of the
8200 @samp{.MMIX.reg_contents} section corresponds to the first allocated
8201 global register multiplied by 8.  Register @code{$255} is not included in
8202 this section; it is always set to the program entry, which is at the
8203 symbol @code{Main} for @code{mmo} files.
8205 Global symbols with the prefix @code{__.MMIX.start.}, for example
8206 @code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special.
8207 The default linker script uses these to set the default start address
8208 of a section.
8210 Initial and trailing multiples of zero-valued 32-bit words in a section,
8211 are left out from an mmo file.
8213 @ifclear GENERIC
8214 @lowersections
8215 @end ifclear
8216 @end ifset
8218 @ifset MSP430
8219 @ifclear GENERIC
8220 @raisesections
8221 @end ifclear
8223 @node  MSP430
8224 @section @code{ld} and MSP430
8225 For the MSP430 it is possible to select the MPU architecture.  The flag @samp{-m [mpu type]}
8226 will select an appropriate linker script for selected MPU type.  (To get a list of known MPUs
8227 just pass @samp{-m help} option to the linker).
8229 @cindex MSP430 extra sections
8230 The linker will recognize some extra sections which are MSP430 specific:
8232 @table @code
8233 @item @samp{.vectors}
8234 Defines a portion of ROM where interrupt vectors located.
8236 @item @samp{.bootloader}
8237 Defines the bootloader portion of the ROM (if applicable).  Any code
8238 in this section will be uploaded to the MPU.
8240 @item @samp{.infomem}
8241 Defines an information memory section (if applicable).  Any code in
8242 this section will be uploaded to the MPU.
8244 @item @samp{.infomemnobits}
8245 This is the same as the @samp{.infomem} section except that any code
8246 in this section will not be uploaded to the MPU.
8248 @item @samp{.noinit}
8249 Denotes a portion of RAM located above @samp{.bss} section.
8251 The last two sections are used by gcc.
8252 @end table
8254 @table @option
8255 @cindex MSP430 Options
8256 @kindex --code-region
8257 @item --code-region=[either,lower,upper,none]
8258 This will transform .text* sections to [either,lower,upper].text* sections. The
8259 argument passed to GCC for -mcode-region is propagated to the linker
8260 using this option.
8262 @kindex --data-region
8263 @item --data-region=[either,lower,upper,none]
8264 This will transform .data*, .bss* and .rodata* sections to
8265 [either,lower,upper].[data,bss,rodata]* sections. The argument passed to GCC
8266 for -mdata-region is propagated to the linker using this option.
8268 @kindex --disable-sec-transformation
8269 @item --disable-sec-transformation
8270 Prevent the transformation of sections as specified by the @code{--code-region}
8271 and @code{--data-region} options.
8272 This is useful if you are compiling and linking using a single call to the GCC
8273 wrapper, and want to compile the source files using -m[code,data]-region but
8274 not transform the sections for prebuilt libraries and objects.
8275 @end table
8277 @ifclear GENERIC
8278 @lowersections
8279 @end ifclear
8280 @end ifset
8282 @ifset NDS32
8283 @ifclear GENERIC
8284 @raisesections
8285 @end ifclear
8287 @node NDS32
8288 @section @code{ld} and NDS32
8289 @kindex relaxing on NDS32
8290 For NDS32, there are some options to select relaxation behavior.  The linker
8291 relaxes objects according to these options.
8293 @table @code
8294 @item @samp{--m[no-]fp-as-gp}
8295 Disable/enable fp-as-gp relaxation.
8297 @item @samp{--mexport-symbols=FILE}
8298 Exporting symbols and their address into FILE as linker script.
8300 @item @samp{--m[no-]ex9}
8301 Disable/enable link-time EX9 relaxation.
8303 @item @samp{--mexport-ex9=FILE}
8304 Export the EX9 table after linking.
8306 @item @samp{--mimport-ex9=FILE}
8307 Import the Ex9 table for EX9 relaxation.
8309 @item @samp{--mupdate-ex9}
8310 Update the existing EX9 table.
8312 @item @samp{--mex9-limit=NUM}
8313 Maximum number of entries in the ex9 table.
8315 @item @samp{--mex9-loop-aware}
8316 Avoid generating the EX9 instruction inside the loop.
8318 @item @samp{--m[no-]ifc}
8319 Disable/enable the link-time IFC optimization.
8321 @item @samp{--mifc-loop-aware}
8322 Avoid generating the IFC instruction inside the loop.
8323 @end table
8325 @ifclear GENERIC
8326 @lowersections
8327 @end ifclear
8328 @end ifset
8330 @ifset NIOSII
8331 @ifclear GENERIC
8332 @raisesections
8333 @end ifclear
8335 @node Nios II
8336 @section @command{ld} and the Altera Nios II
8337 @cindex Nios II call relaxation
8338 @kindex --relax on Nios II
8340 Call and immediate jump instructions on Nios II processors are limited to
8341 transferring control to addresses in the same 256MB memory segment,
8342 which may result in @command{ld} giving
8343 @samp{relocation truncated to fit} errors with very large programs.
8344 The command-line option @option{--relax} enables the generation of
8345 trampolines that can access the entire 32-bit address space for calls
8346 outside the normal @code{call} and @code{jmpi} address range.  These
8347 trampolines are inserted at section boundaries, so may not themselves
8348 be reachable if an input section and its associated call trampolines are
8349 larger than 256MB.
8351 The @option{--relax} option is enabled by default unless @option{-r}
8352 is also specified.  You can disable trampoline generation by using the
8353 @option{--no-relax} linker option.  You can also disable this optimization
8354 locally by using the @samp{set .noat} directive in assembly-language
8355 source files, as the linker-inserted trampolines use the @code{at}
8356 register as a temporary.
8358 Note that the linker @option{--relax} option is independent of assembler
8359 relaxation options, and that using the GNU assembler's @option{-relax-all}
8360 option interferes with the linker's more selective call instruction relaxation.
8362 @ifclear GENERIC
8363 @lowersections
8364 @end ifclear
8365 @end ifset
8367 @ifset POWERPC
8368 @ifclear GENERIC
8369 @raisesections
8370 @end ifclear
8372 @node PowerPC ELF32
8373 @section @command{ld} and PowerPC 32-bit ELF Support
8374 @cindex PowerPC long branches
8375 @kindex --relax on PowerPC
8376 Branches on PowerPC processors are limited to a signed 26-bit
8377 displacement, which may result in @command{ld} giving
8378 @samp{relocation truncated to fit} errors with very large programs.
8379 @samp{--relax} enables the generation of trampolines that can access
8380 the entire 32-bit address space.  These trampolines are inserted at
8381 section boundaries, so may not themselves be reachable if an input
8382 section exceeds 33M in size.  You may combine @samp{-r} and
8383 @samp{--relax} to add trampolines in a partial link.  In that case
8384 both branches to undefined symbols and inter-section branches are also
8385 considered potentially out of range, and trampolines inserted.
8387 @cindex PowerPC ELF32 options
8388 @table @option
8389 @cindex PowerPC PLT
8390 @kindex --bss-plt
8391 @item --bss-plt
8392 Current PowerPC GCC accepts a @samp{-msecure-plt} option that
8393 generates code capable of using a newer PLT and GOT layout that has
8394 the security advantage of no executable section ever needing to be
8395 writable and no writable section ever being executable.  PowerPC
8396 @command{ld} will generate this layout, including stubs to access the
8397 PLT, if all input files (including startup and static libraries) were
8398 compiled with @samp{-msecure-plt}.  @samp{--bss-plt} forces the old
8399 BSS PLT (and GOT layout) which can give slightly better performance.
8401 @kindex --secure-plt
8402 @item --secure-plt
8403 @command{ld} will use the new PLT and GOT layout if it is linking new
8404 @samp{-fpic} or @samp{-fPIC} code, but does not do so automatically
8405 when linking non-PIC code.  This option requests the new PLT and GOT
8406 layout.  A warning will be given if some object file requires the old
8407 style BSS PLT.
8409 @cindex PowerPC GOT
8410 @kindex --sdata-got
8411 @item --sdata-got
8412 The new secure PLT and GOT are placed differently relative to other
8413 sections compared to older BSS PLT and GOT placement.  The location of
8414 @code{.plt} must change because the new secure PLT is an initialized
8415 section while the old PLT is uninitialized.  The reason for the
8416 @code{.got} change is more subtle:  The new placement allows
8417 @code{.got} to be read-only in applications linked with
8418 @samp{-z relro -z now}.  However, this placement means that
8419 @code{.sdata} cannot always be used in shared libraries, because the
8420 PowerPC ABI accesses @code{.sdata} in shared libraries from the GOT
8421 pointer.  @samp{--sdata-got} forces the old GOT placement.  PowerPC
8422 GCC doesn't use @code{.sdata} in shared libraries, so this option is
8423 really only useful for other compilers that may do so.
8425 @cindex PowerPC stub symbols
8426 @kindex --emit-stub-syms
8427 @item --emit-stub-syms
8428 This option causes @command{ld} to label linker stubs with a local
8429 symbol that encodes the stub type and destination.
8431 @cindex PowerPC TLS optimization
8432 @kindex --no-tls-optimize
8433 @item --no-tls-optimize
8434 PowerPC @command{ld} normally performs some optimization of code
8435 sequences used to access Thread-Local Storage.  Use this option to
8436 disable the optimization.
8437 @end table
8439 @ifclear GENERIC
8440 @lowersections
8441 @end ifclear
8442 @end ifset
8444 @ifset POWERPC64
8445 @ifclear GENERIC
8446 @raisesections
8447 @end ifclear
8449 @node PowerPC64 ELF64
8450 @section @command{ld} and PowerPC64 64-bit ELF Support
8452 @cindex PowerPC64 ELF64 options
8453 @table @option
8454 @cindex PowerPC64 stub grouping
8455 @kindex --stub-group-size
8456 @item --stub-group-size
8457 Long branch stubs, PLT call stubs  and TOC adjusting stubs are placed
8458 by @command{ld} in stub sections located between groups of input sections.
8459 @samp{--stub-group-size} specifies the maximum size of a group of input
8460 sections handled by one stub section.  Since branch offsets are signed,
8461 a stub section may serve two groups of input sections, one group before
8462 the stub section, and one group after it.  However, when using
8463 conditional branches that require stubs, it may be better (for branch
8464 prediction) that stub sections only serve one group of input sections.
8465 A negative value for @samp{N} chooses this scheme, ensuring that
8466 branches to stubs always use a negative offset.  Two special values of
8467 @samp{N} are recognized, @samp{1} and @samp{-1}.  These both instruct
8468 @command{ld} to automatically size input section groups for the branch types
8469 detected, with the same behaviour regarding stub placement as other
8470 positive or negative values of @samp{N} respectively.
8472 Note that @samp{--stub-group-size} does not split input sections.  A
8473 single input section larger than the group size specified will of course
8474 create a larger group (of one section).  If input sections are too
8475 large, it may not be possible for a branch to reach its stub.
8477 @cindex PowerPC64 stub symbols
8478 @kindex --emit-stub-syms
8479 @item --emit-stub-syms
8480 This option causes @command{ld} to label linker stubs with a local
8481 symbol that encodes the stub type and destination.
8483 @cindex PowerPC64 dot symbols
8484 @kindex --dotsyms
8485 @kindex --no-dotsyms
8486 @item --dotsyms
8487 @itemx --no-dotsyms
8488 These two options control how @command{ld} interprets version patterns
8489 in a version script.  Older PowerPC64 compilers emitted both a
8490 function descriptor symbol with the same name as the function, and a
8491 code entry symbol with the name prefixed by a dot (@samp{.}).  To
8492 properly version a function @samp{foo}, the version script thus needs
8493 to control both @samp{foo} and @samp{.foo}.  The option
8494 @samp{--dotsyms}, on by default, automatically adds the required
8495 dot-prefixed patterns.  Use @samp{--no-dotsyms} to disable this
8496 feature.
8498 @cindex PowerPC64 register save/restore functions
8499 @kindex --save-restore-funcs
8500 @kindex --no-save-restore-funcs
8501 @item --save-restore-funcs
8502 @itemx --no-save-restore-funcs
8503 These two options control whether PowerPC64 @command{ld} automatically
8504 provides out-of-line register save and restore functions used by
8505 @samp{-Os} code.  The default is to provide any such referenced
8506 function for a normal final link, and to not do so for a relocatable
8507 link.
8509 @cindex PowerPC64 TLS optimization
8510 @kindex --no-tls-optimize
8511 @item --no-tls-optimize
8512 PowerPC64 @command{ld} normally performs some optimization of code
8513 sequences used to access Thread-Local Storage.  Use this option to
8514 disable the optimization.
8516 @cindex PowerPC64 __tls_get_addr optimization
8517 @kindex --tls-get-addr-optimize
8518 @kindex --no-tls-get-addr-optimize
8519 @kindex --tls-get-addr-regsave
8520 @kindex --no-tls-get-addr-regsave
8521 @item --tls-get-addr-optimize
8522 @itemx --no-tls-get-addr-optimize
8523 These options control how PowerPC64 @command{ld} uses a special
8524 stub to call __tls_get_addr.  PowerPC64 glibc 2.22 and later support
8525 an optimization that allows the second and subsequent calls to
8526 @code{__tls_get_addr} for a given symbol to be resolved by the special
8527 stub without calling in to glibc.  By default the linker enables
8528 generation of the stub when glibc advertises the availability of
8529 __tls_get_addr_opt.
8530 Using @option{--tls-get-addr-optimize} with an older glibc won't do
8531 much besides slow down your applications, but may be useful if linking
8532 an application against an older glibc with the expectation that it
8533 will normally be used on systems having a newer glibc.
8534 @option{--tls-get-addr-regsave} forces generation of a stub that saves
8535 and restores volatile registers around the call into glibc.  Normally,
8536 this is done when the linker detects a call to __tls_get_addr_desc.
8537 Such calls then go via the register saving stub to __tls_get_addr_opt.
8538 @option{--no-tls-get-addr-regsave} disables generation of the
8539 register saves.
8541 @cindex PowerPC64 OPD optimization
8542 @kindex --no-opd-optimize
8543 @item --no-opd-optimize
8544 PowerPC64 @command{ld} normally removes @code{.opd} section entries
8545 corresponding to deleted link-once functions, or functions removed by
8546 the action of @samp{--gc-sections} or linker script @code{/DISCARD/}.
8547 Use this option to disable @code{.opd} optimization.
8549 @cindex PowerPC64 OPD spacing
8550 @kindex --non-overlapping-opd
8551 @item --non-overlapping-opd
8552 Some PowerPC64 compilers have an option to generate compressed
8553 @code{.opd} entries spaced 16 bytes apart, overlapping the third word,
8554 the static chain pointer (unused in C) with the first word of the next
8555 entry.  This option expands such entries to the full 24 bytes.
8557 @cindex PowerPC64 TOC optimization
8558 @kindex --no-toc-optimize
8559 @item --no-toc-optimize
8560 PowerPC64 @command{ld} normally removes unused @code{.toc} section
8561 entries.  Such entries are detected by examining relocations that
8562 reference the TOC in code sections.  A reloc in a deleted code section
8563 marks a TOC word as unneeded, while a reloc in a kept code section
8564 marks a TOC word as needed.  Since the TOC may reference itself, TOC
8565 relocs are also examined.  TOC words marked as both needed and
8566 unneeded will of course be kept.  TOC words without any referencing
8567 reloc are assumed to be part of a multi-word entry, and are kept or
8568 discarded as per the nearest marked preceding word.  This works
8569 reliably for compiler generated code, but may be incorrect if assembly
8570 code is used to insert TOC entries.  Use this option to disable the
8571 optimization.
8573 @cindex PowerPC64 inline PLT call optimization
8574 @kindex --no-inline-optimize
8575 @item --no-inline-optimize
8576 PowerPC64 @command{ld} normally replaces inline PLT call sequences
8577 marked with @code{R_PPC64_PLTSEQ}, @code{R_PPC64_PLTCALL},
8578 @code{R_PPC64_PLT16_HA} and @code{R_PPC64_PLT16_LO_DS} relocations by
8579 a number of @code{nop}s and a direct call when the function is defined
8580 locally and can't be overridden by some other definition.  This option
8581 disables that optimization.
8583 @cindex PowerPC64 multi-TOC
8584 @kindex --no-multi-toc
8585 @item --no-multi-toc
8586 If given any toc option besides @code{-mcmodel=medium} or
8587 @code{-mcmodel=large}, PowerPC64 GCC generates code for a TOC model
8588 where TOC
8589 entries are accessed with a 16-bit offset from r2.  This limits the
8590 total TOC size to 64K.  PowerPC64 @command{ld} extends this limit by
8591 grouping code sections such that each group uses less than 64K for its
8592 TOC entries, then inserts r2 adjusting stubs between inter-group
8593 calls.  @command{ld} does not split apart input sections, so cannot
8594 help if a single input file has a @code{.toc} section that exceeds
8595 64K, most likely from linking multiple files with @command{ld -r}.
8596 Use this option to turn off this feature.
8598 @cindex PowerPC64 TOC sorting
8599 @kindex --no-toc-sort
8600 @item --no-toc-sort
8601 By default, @command{ld} sorts TOC sections so that those whose file
8602 happens to have a section called @code{.init} or @code{.fini} are
8603 placed first, followed by TOC sections referenced by code generated
8604 with PowerPC64 gcc's @code{-mcmodel=small}, and lastly TOC sections
8605 referenced only by code generated with PowerPC64 gcc's
8606 @code{-mcmodel=medium} or @code{-mcmodel=large} options.  Doing this
8607 results in better TOC grouping for multi-TOC.  Use this option to turn
8608 off this feature.
8610 @cindex PowerPC64 PLT stub alignment
8611 @kindex --plt-align
8612 @kindex --no-plt-align
8613 @item --plt-align
8614 @itemx --no-plt-align
8615 Use these options to control whether individual PLT call stubs are
8616 aligned to a 32-byte boundary, or to the specified power of two
8617 boundary when using @code{--plt-align=}.  A negative value may be
8618 specified to pad PLT call stubs so that they do not cross the
8619 specified power of two boundary (or the minimum number of boundaries
8620 if a PLT stub is so large that it must cross a boundary).  By default
8621 PLT call stubs are aligned to 32-byte boundaries.
8623 @cindex PowerPC64 PLT call stub static chain
8624 @kindex --plt-static-chain
8625 @kindex --no-plt-static-chain
8626 @item --plt-static-chain
8627 @itemx --no-plt-static-chain
8628 Use these options to control whether PLT call stubs load the static
8629 chain pointer (r11).  @code{ld} defaults to not loading the static
8630 chain since there is never any need to do so on a PLT call.
8632 @cindex PowerPC64 PLT call stub thread safety
8633 @kindex --plt-thread-safe
8634 @kindex --no-plt-thread-safe
8635 @item --plt-thread-safe
8636 @itemx --no-plt-thread-safe
8637 With power7's weakly ordered memory model, it is possible when using
8638 lazy binding for ld.so to update a plt entry in one thread and have
8639 another thread see the individual plt entry words update in the wrong
8640 order, despite ld.so carefully writing in the correct order and using
8641 memory write barriers.  To avoid this we need some sort of read
8642 barrier in the call stub, or use LD_BIND_NOW=1.  By default, @code{ld}
8643 looks for calls to commonly used functions that create threads, and if
8644 seen, adds the necessary barriers.  Use these options to change the
8645 default behaviour.
8647 @cindex PowerPC64 ELFv2 PLT localentry optimization
8648 @kindex --plt-localentry
8649 @kindex --no-plt-localentry
8650 @item --plt-localentry
8651 @itemx --no-localentry
8652 ELFv2 functions with localentry:0 are those with a single entry point,
8653 ie. global entry == local entry, and that have no requirement on r2
8654 (the TOC/GOT pointer) or r12, and guarantee r2 is unchanged on return.
8655 Such an external function can be called via the PLT without saving r2
8656 or restoring it on return, avoiding a common load-hit-store for small
8657 functions.   The optimization is attractive, with up to 40% reduction
8658 in execution time for a small function, but can result in symbol
8659 interposition failures.  Also, minor changes in a shared library,
8660 including system libraries, can cause a function that was localentry:0
8661 to become localentry:8.  This will result in a dynamic loader
8662 complaint and failure to run.  The option is experimental, use with
8663 care.  @option{--no-plt-localentry} is the default.
8665 @cindex PowerPC64 Power10 stubs
8666 @kindex --power10-stubs
8667 @kindex --no-power10-stubs
8668 @item --power10-stubs
8669 @itemx --no-power10-stubs
8670 When PowerPC64 @command{ld} links input object files containing
8671 relocations used on power10 prefixed instructions it normally creates
8672 linkage stubs (PLT call and long branch) using power10 instructions
8673 for @code{@@notoc} PLT calls where @code{r2} is not known.  The
8674 power10 notoc stubs are smaller and faster, so are preferred for
8675 power10.  @option{--power10-stubs} and @option{--no-power10-stubs}
8676 allow you to override the linker's selection of stub instructions.
8677 @option{--power10-stubs=auto} allows the user to select the default
8678 auto mode.
8679 @end table
8681 @ifclear GENERIC
8682 @lowersections
8683 @end ifclear
8684 @end ifset
8686 @ifset S/390
8687 @ifclear GENERIC
8688 @raisesections
8689 @end ifclear
8691 @node S/390 ELF
8692 @section @command{ld} and S/390 ELF Support
8694 @cindex S/390 ELF options
8695 @table @option
8697 @cindex S/390
8698 @kindex --s390-pgste
8699 @item --s390-pgste
8700 This option marks the result file with a @code{PT_S390_PGSTE}
8701 segment.  The Linux kernel is supposed to allocate 4k page tables for
8702 binaries marked that way.
8703 @end table
8705 @ifclear GENERIC
8706 @lowersections
8707 @end ifclear
8708 @end ifset
8710 @ifset SPU
8711 @ifclear GENERIC
8712 @raisesections
8713 @end ifclear
8715 @node SPU ELF
8716 @section @command{ld} and SPU ELF Support
8718 @cindex SPU ELF options
8719 @table @option
8721 @cindex SPU plugins
8722 @kindex --plugin
8723 @item --plugin
8724 This option marks an executable as a PIC plugin module.
8726 @cindex SPU overlays
8727 @kindex --no-overlays
8728 @item --no-overlays
8729 Normally, @command{ld} recognizes calls to functions within overlay
8730 regions, and redirects such calls to an overlay manager via a stub.
8731 @command{ld} also provides a built-in overlay manager.  This option
8732 turns off all this special overlay handling.
8734 @cindex SPU overlay stub symbols
8735 @kindex --emit-stub-syms
8736 @item --emit-stub-syms
8737 This option causes @command{ld} to label overlay stubs with a local
8738 symbol that encodes the stub type and destination.
8740 @cindex SPU extra overlay stubs
8741 @kindex --extra-overlay-stubs
8742 @item --extra-overlay-stubs
8743 This option causes @command{ld} to add overlay call stubs on all
8744 function calls out of overlay regions.  Normally stubs are not added
8745 on calls to non-overlay regions.
8747 @cindex SPU local store size
8748 @kindex --local-store=lo:hi
8749 @item --local-store=lo:hi
8750 @command{ld} usually checks that a final executable for SPU fits in
8751 the address range 0 to 256k.  This option may be used to change the
8752 range.  Disable the check entirely with @option{--local-store=0:0}.
8754 @cindex SPU
8755 @kindex --stack-analysis
8756 @item --stack-analysis
8757 SPU local store space is limited.  Over-allocation of stack space
8758 unnecessarily limits space available for code and data, while
8759 under-allocation results in runtime failures.  If given this option,
8760 @command{ld} will provide an estimate of maximum stack usage.
8761 @command{ld} does this by examining symbols in code sections to
8762 determine the extents of functions, and looking at function prologues
8763 for stack adjusting instructions.  A call-graph is created by looking
8764 for relocations on branch instructions.  The graph is then searched
8765 for the maximum stack usage path.  Note that this analysis does not
8766 find calls made via function pointers, and does not handle recursion
8767 and other cycles in the call graph.  Stack usage may be
8768 under-estimated if your code makes such calls.  Also, stack usage for
8769 dynamic allocation, e.g. alloca, will not be detected.  If a link map
8770 is requested, detailed information about each function's stack usage
8771 and calls will be given.
8773 @cindex SPU
8774 @kindex --emit-stack-syms
8775 @item --emit-stack-syms
8776 This option, if given along with @option{--stack-analysis} will result
8777 in @command{ld} emitting stack sizing symbols for each function.
8778 These take the form @code{__stack_<function_name>} for global
8779 functions, and @code{__stack_<number>_<function_name>} for static
8780 functions.  @code{<number>} is the section id in hex.  The value of
8781 such symbols is the stack requirement for the corresponding function.
8782 The symbol size will be zero, type @code{STT_NOTYPE}, binding
8783 @code{STB_LOCAL}, and section @code{SHN_ABS}.
8784 @end table
8786 @ifclear GENERIC
8787 @lowersections
8788 @end ifclear
8789 @end ifset
8791 @ifset TICOFF
8792 @ifclear GENERIC
8793 @raisesections
8794 @end ifclear
8796 @node TI COFF
8797 @section @command{ld}'s Support for Various TI COFF Versions
8798 @cindex TI COFF versions
8799 @kindex --format=@var{version}
8800 The @samp{--format} switch allows selection of one of the various
8801 TI COFF versions.  The latest of this writing is 2; versions 0 and 1 are
8802 also supported.  The TI COFF versions also vary in header byte-order
8803 format; @command{ld} will read any version or byte order, but the output
8804 header format depends on the default specified by the specific target.
8806 @ifclear GENERIC
8807 @lowersections
8808 @end ifclear
8809 @end ifset
8811 @ifset WIN32
8812 @ifclear GENERIC
8813 @raisesections
8814 @end ifclear
8816 @node WIN32
8817 @section @command{ld} and WIN32 (cygwin/mingw)
8819 This section describes some of the win32 specific @command{ld} issues.
8820 See @ref{Options,,Command-line Options} for detailed description of the
8821 command-line options mentioned here.
8823 @table @emph
8824 @cindex import libraries
8825 @item import libraries
8826 The standard Windows linker creates and uses so-called import
8827 libraries, which contains information for linking to dll's.  They are
8828 regular static archives and are handled as any other static
8829 archive.  The cygwin and mingw ports of @command{ld} have specific
8830 support for creating such libraries provided with the
8831 @samp{--out-implib} command-line option.
8833 @item Resource only DLLs
8834 It is possible to create a DLL that only contains resources, ie just a
8835 @samp{.rsrc} section, but in order to do so a custom linker script
8836 must be used.  This is because the built-in default linker scripts
8837 will always create @samp{.text} and @samp{.idata} sections, even if
8838 there is no input to go into them.
8840 The script should look like this, although the @code{OUTPUT_FORMAT}
8841 should be changed to match the desired format.
8843 @example
8844 OUTPUT_FORMAT(pei-i386)
8845 SECTIONS
8847   . = SIZEOF_HEADERS;
8848   . = ALIGN(__section_alignment__);
8849   .rsrc __image_base__ + __section_alignment__ : ALIGN(4)
8850   @{
8851     KEEP (*(.rsrc))
8852     KEEP (*(.rsrc$*))
8853   @}
8854   /DISCARD/ : @{ *(*) @}
8856 @end example
8858 With this script saved to a file called, eg @file{rsrc.ld}, a command
8859 line like this can be used to create the resource only DLL
8860 @file{rsrc.dll} from an input file called @file{rsrc.o}:
8862 @smallexample
8863 ld -dll --subsystem windows -e 0 -s rsrc.o -o rsrc.dll -T rsrc.ld
8864 @end smallexample
8866 @item   exporting DLL symbols
8867 @cindex exporting DLL symbols
8868 The cygwin/mingw @command{ld} has several ways to export symbols for dll's.
8870 @table @emph
8871 @item   using auto-export functionality
8872 @cindex using auto-export functionality
8873 By default @command{ld} exports symbols with the auto-export functionality,
8874 which is controlled by the following command-line options:
8876 @itemize
8877 @item --export-all-symbols   [This is the default]
8878 @item --exclude-symbols
8879 @item --exclude-libs
8880 @item --exclude-modules-for-implib
8881 @item --version-script
8882 @end itemize
8884 When auto-export is in operation, @command{ld} will export all the non-local
8885 (global and common) symbols it finds in a DLL, with the exception of a few
8886 symbols known to belong to the system's runtime and libraries.  As it will
8887 often not be desirable to export all of a DLL's symbols, which may include
8888 private functions that are not part of any public interface, the command-line
8889 options listed above may be used to filter symbols out from the list for
8890 exporting.  The @samp{--output-def} option can be used in order to see the
8891 final list of exported symbols with all exclusions taken into effect.
8893 If @samp{--export-all-symbols} is not given explicitly on the
8894 command line, then the default auto-export behavior will be @emph{disabled}
8895 if either of the following are true:
8897 @itemize
8898 @item A DEF file is used.
8899 @item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
8900 @end itemize
8902 @item   using a DEF file
8903 @cindex using a DEF file
8904 Another way of exporting symbols is using a DEF file.  A DEF file is
8905 an ASCII file containing definitions of symbols which should be
8906 exported when a dll is created.  Usually it is named @samp{<dll
8907 name>.def} and is added as any other object file to the linker's
8908 command line.  The file's name must end in @samp{.def} or @samp{.DEF}.
8910 @example
8911 gcc -o <output> <objectfiles> <dll name>.def
8912 @end example
8914 Using a DEF file turns off the normal auto-export behavior, unless the
8915 @samp{--export-all-symbols} option is also used.
8917 Here is an example of a DEF file for a shared library called @samp{xyz.dll}:
8919 @example
8920 LIBRARY "xyz.dll" BASE=0x20000000
8922 EXPORTS
8925 _bar = bar
8926 another_foo = abc.dll.afoo
8927 var1 DATA
8928 doo = foo == foo2
8929 eoo DATA == var1
8930 @end example
8932 This example defines a DLL with a non-default base address and seven
8933 symbols in the export table. The third exported symbol @code{_bar} is an
8934 alias for the second. The fourth symbol, @code{another_foo} is resolved
8935 by "forwarding" to another module and treating it as an alias for
8936 @code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
8937 @code{var1} is declared to be a data object. The @samp{doo} symbol in
8938 export library is an alias of @samp{foo}, which gets the string name
8939 in export table @samp{foo2}. The @samp{eoo} symbol is an data export
8940 symbol, which gets in export table the name @samp{var1}.
8942 The optional @code{LIBRARY <name>} command indicates the @emph{internal}
8943 name of the output DLL. If @samp{<name>} does not include a suffix,
8944 the default library suffix, @samp{.DLL} is appended.
8946 When the .DEF file is used to build an application, rather than a
8947 library, the @code{NAME <name>} command should be used instead of
8948 @code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
8949 executable suffix, @samp{.EXE} is appended.
8951 With either @code{LIBRARY <name>} or @code{NAME <name>} the optional
8952 specification @code{BASE = <number>} may be used to specify a
8953 non-default base address for the image.
8955 If neither @code{LIBRARY <name>} nor  @code{NAME <name>} is specified,
8956 or they specify an empty string, the internal name is the same as the
8957 filename specified on the command line.
8959 The complete specification of an export symbol is:
8961 @example
8962 EXPORTS
8963   ( (  ( <name1> [ = <name2> ] )
8964      | ( <name1> = <module-name> . <external-name>))
8965   [ @@ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] [== <name3>] ) *
8966 @end example
8968 Declares @samp{<name1>} as an exported symbol from the DLL, or declares
8969 @samp{<name1>} as an exported alias for @samp{<name2>}; or declares
8970 @samp{<name1>} as a "forward" alias for the symbol
8971 @samp{<external-name>} in the DLL @samp{<module-name>}.
8972 Optionally, the symbol may be exported by the specified ordinal
8973 @samp{<integer>} alias. The optional @samp{<name3>} is the to be used
8974 string in import/export table for the symbol.
8976 The optional keywords that follow the declaration indicate:
8978 @code{NONAME}: Do not put the symbol name in the DLL's export table.  It
8979 will still be exported by its ordinal alias (either the value specified
8980 by the .def specification or, otherwise, the value assigned by the
8981 linker). The symbol name, however, does remain visible in the import
8982 library (if any), unless @code{PRIVATE} is also specified.
8984 @code{DATA}: The symbol is a variable or object, rather than a function.
8985 The import lib will export only an indirect reference to @code{foo} as
8986 the symbol @code{_imp__foo} (ie, @code{foo} must be resolved as
8987 @code{*_imp__foo}).
8989 @code{CONSTANT}: Like @code{DATA}, but put the undecorated @code{foo} as
8990 well as @code{_imp__foo} into the import library. Both refer to the
8991 read-only import address table's pointer to the variable, not to the
8992 variable itself. This can be dangerous. If the user code fails to add
8993 the @code{dllimport} attribute and also fails to explicitly add the
8994 extra indirection that the use of the attribute enforces, the
8995 application will behave unexpectedly.
8997 @code{PRIVATE}: Put the symbol in the DLL's export table, but do not put
8998 it into the static import library used to resolve imports at link time. The
8999 symbol can still be imported using the @code{LoadLibrary/GetProcAddress}
9000 API at runtime or by using the GNU ld extension of linking directly to
9001 the DLL without an import library.
9003 See ld/deffilep.y in the binutils sources for the full specification of
9004 other DEF file statements
9006 @cindex creating a DEF file
9007 While linking a shared dll, @command{ld} is able to create a DEF file
9008 with the @samp{--output-def <file>} command-line option.
9010 @item   Using decorations
9011 @cindex Using decorations
9012 Another way of marking symbols for export is to modify the source code
9013 itself, so that when building the DLL each symbol to be exported is
9014 declared as:
9016 @example
9017 __declspec(dllexport) int a_variable
9018 __declspec(dllexport) void a_function(int with_args)
9019 @end example
9021 All such symbols will be exported from the DLL.  If, however,
9022 any of the object files in the DLL contain symbols decorated in
9023 this way, then the normal auto-export behavior is disabled, unless
9024 the @samp{--export-all-symbols} option is also used.
9026 Note that object files that wish to access these symbols must @emph{not}
9027 decorate them with dllexport.  Instead, they should use dllimport,
9028 instead:
9030 @example
9031 __declspec(dllimport) int a_variable
9032 __declspec(dllimport) void a_function(int with_args)
9033 @end example
9035 This complicates the structure of library header files, because
9036 when included by the library itself the header must declare the
9037 variables and functions as dllexport, but when included by client
9038 code the header must declare them as dllimport.  There are a number
9039 of idioms that are typically used to do this; often client code can
9040 omit the __declspec() declaration completely.  See
9041 @samp{--enable-auto-import} and @samp{automatic data imports} for more
9042 information.
9043 @end table
9045 @cindex automatic data imports
9046 @item automatic data imports
9047 The standard Windows dll format supports data imports from dlls only
9048 by adding special decorations (dllimport/dllexport), which let the
9049 compiler produce specific assembler instructions to deal with this
9050 issue.  This increases the effort necessary to port existing Un*x
9051 code to these platforms, especially for large
9052 c++ libraries and applications.  The auto-import feature, which was
9053 initially provided by Paul Sokolovsky, allows one to omit the
9054 decorations to achieve a behavior that conforms to that on POSIX/Un*x
9055 platforms. This feature is enabled with the @samp{--enable-auto-import}
9056 command-line option, although it is enabled by default on cygwin/mingw.
9057 The @samp{--enable-auto-import} option itself now serves mainly to
9058 suppress any warnings that are ordinarily emitted when linked objects
9059 trigger the feature's use.
9061 auto-import of variables does not always work flawlessly without
9062 additional assistance.  Sometimes, you will see this message
9064 "variable '<var>' can't be auto-imported. Please read the
9065 documentation for ld's @code{--enable-auto-import} for details."
9067 The @samp{--enable-auto-import} documentation explains why this error
9068 occurs, and several methods that can be used to overcome this difficulty.
9069 One of these methods is the @emph{runtime pseudo-relocs} feature, described
9070 below.
9072 @cindex runtime pseudo-relocation
9073 For complex variables imported from DLLs (such as structs or classes),
9074 object files typically contain a base address for the variable and an
9075 offset (@emph{addend}) within the variable--to specify a particular
9076 field or public member, for instance.  Unfortunately, the runtime loader used
9077 in win32 environments is incapable of fixing these references at runtime
9078 without the additional information supplied by dllimport/dllexport decorations.
9079 The standard auto-import feature described above is unable to resolve these
9080 references.
9082 The @samp{--enable-runtime-pseudo-relocs} switch allows these references to
9083 be resolved without error, while leaving the task of adjusting the references
9084 themselves (with their non-zero addends) to specialized code provided by the
9085 runtime environment.  Recent versions of the cygwin and mingw environments and
9086 compilers provide this runtime support; older versions do not.  However, the
9087 support is only necessary on the developer's platform; the compiled result will
9088 run without error on an older system.
9090 @samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
9091 enabled as needed.
9093 @cindex direct linking to a dll
9094 @item direct linking to a dll
9095 The cygwin/mingw ports of @command{ld} support the direct linking,
9096 including data symbols, to a dll without the usage of any import
9097 libraries.  This is much faster and uses much less memory than does the
9098 traditional import library method, especially when linking large
9099 libraries or applications.  When @command{ld} creates an import lib, each
9100 function or variable exported from the dll is stored in its own bfd, even
9101 though a single bfd could contain many exports.  The overhead involved in
9102 storing, loading, and processing so many bfd's is quite large, and explains the
9103 tremendous time, memory, and storage needed to link against particularly
9104 large or complex libraries when using import libs.
9106 Linking directly to a dll uses no extra command-line switches other than
9107 @samp{-L} and @samp{-l}, because @command{ld} already searches for a number
9108 of names to match each library.  All that is needed from the developer's
9109 perspective is an understanding of this search, in order to force ld to
9110 select the dll instead of an import library.
9113 For instance, when ld is called with the argument @samp{-lxxx} it will attempt
9114 to find, in the first directory of its search path,
9116 @example
9117 libxxx.dll.a
9118 xxx.dll.a
9119 libxxx.a
9120 xxx.lib
9121 libxxx.lib
9122 cygxxx.dll (*)
9123 libxxx.dll
9124 xxx.dll
9125 @end example
9127 before moving on to the next directory in the search path.
9129 (*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
9130 where @samp{<prefix>} is set by the @command{ld} option
9131 @samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
9132 file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
9133 @samp{cygxxx.dll}.
9135 Other win32-based unix environments, such as mingw or pw32, may use other
9136 @samp{<prefix>}es, although at present only cygwin makes use of this feature.  It
9137 was originally intended to help avoid name conflicts among dll's built for the
9138 various win32/un*x environments, so that (for example) two versions of a zlib dll
9139 could coexist on the same machine.
9141 The generic cygwin/mingw path layout uses a @samp{bin} directory for
9142 applications and dll's and a @samp{lib} directory for the import
9143 libraries (using cygwin nomenclature):
9145 @example
9146 bin/
9147         cygxxx.dll
9148 lib/
9149         libxxx.dll.a   (in case of dll's)
9150         libxxx.a       (in case of static archive)
9151 @end example
9153 Linking directly to a dll without using the import library can be
9154 done two ways:
9156 1. Use the dll directly by adding the @samp{bin} path to the link line
9157 @example
9158 gcc -Wl,-verbose  -o a.exe -L../bin/ -lxxx
9159 @end example
9161 However, as the dll's often have version numbers appended to their names
9162 (@samp{cygncurses-5.dll}) this will often fail, unless one specifies
9163 @samp{-L../bin -lncurses-5} to include the version.  Import libs are generally
9164 not versioned, and do not have this difficulty.
9166 2. Create a symbolic link from the dll to a file in the @samp{lib}
9167 directory according to the above mentioned search pattern.  This
9168 should be used to avoid unwanted changes in the tools needed for
9169 making the app/dll.
9171 @example
9172 ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
9173 @end example
9175 Then you can link without any make environment changes.
9177 @example
9178 gcc -Wl,-verbose  -o a.exe -L../lib/ -lxxx
9179 @end example
9181 This technique also avoids the version number problems, because the following is
9182 perfectly legal
9184 @example
9185 bin/
9186         cygxxx-5.dll
9187 lib/
9188         libxxx.dll.a -> ../bin/cygxxx-5.dll
9189 @end example
9191 Linking directly to a dll without using an import lib will work
9192 even when auto-import features are exercised, and even when
9193 @samp{--enable-runtime-pseudo-relocs} is used.
9195 Given the improvements in speed and memory usage, one might justifiably
9196 wonder why import libraries are used at all.  There are three reasons:
9198 1. Until recently, the link-directly-to-dll functionality did @emph{not}
9199 work with auto-imported data.
9201 2. Sometimes it is necessary to include pure static objects within the
9202 import library (which otherwise contains only bfd's for indirection
9203 symbols that point to the exports of a dll).  Again, the import lib
9204 for the cygwin kernel makes use of this ability, and it is not
9205 possible to do this without an import lib.
9207 3. Symbol aliases can only be resolved using an import lib.  This is
9208 critical when linking against OS-supplied dll's (eg, the win32 API)
9209 in which symbols are usually exported as undecorated aliases of their
9210 stdcall-decorated assembly names.
9212 So, import libs are not going away.  But the ability to replace
9213 true import libs with a simple symbolic link to (or a copy of)
9214 a dll, in many cases, is a useful addition to the suite of tools
9215 binutils makes available to the win32 developer.  Given the
9216 massive improvements in memory requirements during linking, storage
9217 requirements, and linking speed, we expect that many developers
9218 will soon begin to use this feature whenever possible.
9220 @item symbol aliasing
9221 @table @emph
9222 @item adding additional names
9223 Sometimes, it is useful to export symbols with additional names.
9224 A symbol @samp{foo} will be exported as @samp{foo}, but it can also be
9225 exported as @samp{_foo} by using special directives in the DEF file
9226 when creating the dll.  This will affect also the optional created
9227 import library.  Consider the following DEF file:
9229 @example
9230 LIBRARY "xyz.dll" BASE=0x61000000
9232 EXPORTS
9234 _foo = foo
9235 @end example
9237 The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
9239 Another method for creating a symbol alias is to create it in the
9240 source code using the "weak" attribute:
9242 @example
9243 void foo () @{ /* Do something.  */; @}
9244 void _foo () __attribute__ ((weak, alias ("foo")));
9245 @end example
9247 See the gcc manual for more information about attributes and weak
9248 symbols.
9250 @item renaming symbols
9251 Sometimes it is useful to rename exports.  For instance, the cygwin
9252 kernel does this regularly.  A symbol @samp{_foo} can be exported as
9253 @samp{foo} but not as @samp{_foo} by using special directives in the
9254 DEF file. (This will also affect the import library, if it is
9255 created).  In the following example:
9257 @example
9258 LIBRARY "xyz.dll" BASE=0x61000000
9260 EXPORTS
9261 _foo = foo
9262 @end example
9264 The line @samp{_foo = foo} maps the exported symbol @samp{foo} to
9265 @samp{_foo}.
9266 @end table
9268 Note: using a DEF file disables the default auto-export behavior,
9269 unless the @samp{--export-all-symbols} command-line option is used.
9270 If, however, you are trying to rename symbols, then you should list
9271 @emph{all} desired exports in the DEF file, including the symbols
9272 that are not being renamed, and do @emph{not} use the
9273 @samp{--export-all-symbols} option.  If you list only the
9274 renamed symbols in the DEF file, and use @samp{--export-all-symbols}
9275 to handle the other symbols, then the both the new names @emph{and}
9276 the original names for the renamed symbols will be exported.
9277 In effect, you'd be aliasing those symbols, not renaming them,
9278 which is probably not what you wanted.
9280 @cindex weak externals
9281 @item weak externals
9282 The Windows object format, PE, specifies a form of weak symbols called
9283 weak externals.  When a weak symbol is linked and the symbol is not
9284 defined, the weak symbol becomes an alias for some other symbol.  There
9285 are three variants of weak externals:
9286 @itemize
9287 @item Definition is searched for in objects and libraries, historically
9288 called lazy externals.
9289 @item Definition is searched for only in other objects, not in libraries.
9290 This form is not presently implemented.
9291 @item No search; the symbol is an alias.  This form is not presently
9292 implemented.
9293 @end itemize
9294 As a GNU extension, weak symbols that do not specify an alternate symbol
9295 are supported.  If the symbol is undefined when linking, the symbol
9296 uses a default value.
9298 @cindex aligned common symbols
9299 @item aligned common symbols
9300 As a GNU extension to the PE file format, it is possible to specify the
9301 desired alignment for a common symbol.  This information is conveyed from
9302 the assembler or compiler to the linker by means of GNU-specific commands
9303 carried in the object file's @samp{.drectve} section, which are recognized
9304 by @command{ld} and respected when laying out the common symbols.  Native
9305 tools will be able to process object files employing this GNU extension,
9306 but will fail to respect the alignment instructions, and may issue noisy
9307 warnings about unknown linker directives.
9309 @end table
9311 @ifclear GENERIC
9312 @lowersections
9313 @end ifclear
9314 @end ifset
9316 @ifset XTENSA
9317 @ifclear GENERIC
9318 @raisesections
9319 @end ifclear
9321 @node Xtensa
9322 @section @code{ld} and Xtensa Processors
9324 @cindex Xtensa processors
9325 The default @command{ld} behavior for Xtensa processors is to interpret
9326 @code{SECTIONS} commands so that lists of explicitly named sections in a
9327 specification with a wildcard file will be interleaved when necessary to
9328 keep literal pools within the range of PC-relative load offsets.  For
9329 example, with the command:
9331 @smallexample
9332 SECTIONS
9334   .text : @{
9335     *(.literal .text)
9336   @}
9338 @end smallexample
9340 @noindent
9341 @command{ld} may interleave some of the @code{.literal}
9342 and @code{.text} sections from different object files to ensure that the
9343 literal pools are within the range of PC-relative load offsets.  A valid
9344 interleaving might place the @code{.literal} sections from an initial
9345 group of files followed by the @code{.text} sections of that group of
9346 files.  Then, the @code{.literal} sections from the rest of the files
9347 and the @code{.text} sections from the rest of the files would follow.
9349 @cindex @option{--relax} on Xtensa
9350 @cindex relaxing on Xtensa
9351 Relaxation is enabled by default for the Xtensa version of @command{ld} and
9352 provides two important link-time optimizations.  The first optimization
9353 is to combine identical literal values to reduce code size.  A redundant
9354 literal will be removed and all the @code{L32R} instructions that use it
9355 will be changed to reference an identical literal, as long as the
9356 location of the replacement literal is within the offset range of all
9357 the @code{L32R} instructions.  The second optimization is to remove
9358 unnecessary overhead from assembler-generated ``longcall'' sequences of
9359 @code{L32R}/@code{CALLX@var{n}} when the target functions are within
9360 range of direct @code{CALL@var{n}} instructions.
9362 For each of these cases where an indirect call sequence can be optimized
9363 to a direct call, the linker will change the @code{CALLX@var{n}}
9364 instruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
9365 instruction, and remove the literal referenced by the @code{L32R}
9366 instruction if it is not used for anything else.  Removing the
9367 @code{L32R} instruction always reduces code size but can potentially
9368 hurt performance by changing the alignment of subsequent branch targets.
9369 By default, the linker will always preserve alignments, either by
9370 switching some instructions between 24-bit encodings and the equivalent
9371 density instructions or by inserting a no-op in place of the @code{L32R}
9372 instruction that was removed.  If code size is more important than
9373 performance, the @option{--size-opt} option can be used to prevent the
9374 linker from widening density instructions or inserting no-ops, except in
9375 a few cases where no-ops are required for correctness.
9377 The following Xtensa-specific command-line options can be used to
9378 control the linker:
9380 @cindex Xtensa options
9381 @table @option
9382 @item --size-opt
9383 When optimizing indirect calls to direct calls, optimize for code size
9384 more than performance.  With this option, the linker will not insert
9385 no-ops or widen density instructions to preserve branch target
9386 alignment.  There may still be some cases where no-ops are required to
9387 preserve the correctness of the code.
9389 @item --abi-windowed
9390 @itemx --abi-call0
9391 Choose ABI for the output object and for the generated PLT code.
9392 PLT code inserted by the linker must match ABI of the output object
9393 because windowed and call0 ABI use incompatible function call
9394 conventions.
9395 Default ABI is chosen by the ABI tag in the @code{.xtensa.info} section
9396 of the first input object.
9397 A warning is issued if ABI tags of input objects do not match each other
9398 or the chosen output object ABI.
9399 @end table
9401 @ifclear GENERIC
9402 @lowersections
9403 @end ifclear
9404 @end ifset
9406 @ifclear SingleFormat
9407 @node BFD
9408 @chapter BFD
9410 @cindex back end
9411 @cindex object file management
9412 @cindex object formats available
9413 @kindex objdump -i
9414 The linker accesses object and archive files using the BFD libraries.
9415 These libraries allow the linker to use the same routines to operate on
9416 object files whatever the object file format.  A different object file
9417 format can be supported simply by creating a new BFD back end and adding
9418 it to the library.  To conserve runtime memory, however, the linker and
9419 associated tools are usually configured to support only a subset of the
9420 object file formats available.  You can use @code{objdump -i}
9421 (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
9422 list all the formats available for your configuration.
9424 @cindex BFD requirements
9425 @cindex requirements for BFD
9426 As with most implementations, BFD is a compromise between
9427 several conflicting requirements. The major factor influencing
9428 BFD design was efficiency: any time used converting between
9429 formats is time which would not have been spent had BFD not
9430 been involved. This is partly offset by abstraction payback; since
9431 BFD simplifies applications and back ends, more time and care
9432 may be spent optimizing algorithms for a greater speed.
9434 One minor artifact of the BFD solution which you should bear in
9435 mind is the potential for information loss.  There are two places where
9436 useful information can be lost using the BFD mechanism: during
9437 conversion and during output. @xref{BFD information loss}.
9439 @menu
9440 * BFD outline::                 How it works: an outline of BFD
9441 @end menu
9443 @node BFD outline
9444 @section How It Works: An Outline of BFD
9445 @cindex opening object files
9446 @include bfdsumm.texi
9447 @end ifclear
9449 @node Reporting Bugs
9450 @chapter Reporting Bugs
9451 @cindex bugs in @command{ld}
9452 @cindex reporting bugs in @command{ld}
9454 Your bug reports play an essential role in making @command{ld} reliable.
9456 Reporting a bug may help you by bringing a solution to your problem, or
9457 it may not.  But in any case the principal function of a bug report is
9458 to help the entire community by making the next version of @command{ld}
9459 work better.  Bug reports are your contribution to the maintenance of
9460 @command{ld}.
9462 In order for a bug report to serve its purpose, you must include the
9463 information that enables us to fix the bug.
9465 @menu
9466 * Bug Criteria::                Have you found a bug?
9467 * Bug Reporting::               How to report bugs
9468 @end menu
9470 @node Bug Criteria
9471 @section Have You Found a Bug?
9472 @cindex bug criteria
9474 If you are not sure whether you have found a bug, here are some guidelines:
9476 @itemize @bullet
9477 @cindex fatal signal
9478 @cindex linker crash
9479 @cindex crash of linker
9480 @item
9481 If the linker gets a fatal signal, for any input whatever, that is a
9482 @command{ld} bug.  Reliable linkers never crash.
9484 @cindex error on valid input
9485 @item
9486 If @command{ld} produces an error message for valid input, that is a bug.
9488 @cindex invalid input
9489 @item
9490 If @command{ld} does not produce an error message for invalid input, that
9491 may be a bug.  In the general case, the linker can not verify that
9492 object files are correct.
9494 @item
9495 If you are an experienced user of linkers, your suggestions for
9496 improvement of @command{ld} are welcome in any case.
9497 @end itemize
9499 @node Bug Reporting
9500 @section How to Report Bugs
9501 @cindex bug reports
9502 @cindex @command{ld} bugs, reporting
9504 A number of companies and individuals offer support for @sc{gnu}
9505 products.  If you obtained @command{ld} from a support organization, we
9506 recommend you contact that organization first.
9508 You can find contact information for many support companies and
9509 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
9510 distribution.
9512 @ifset BUGURL
9513 Otherwise, send bug reports for @command{ld} to
9514 @value{BUGURL}.
9515 @end ifset
9517 The fundamental principle of reporting bugs usefully is this:
9518 @strong{report all the facts}.  If you are not sure whether to state a
9519 fact or leave it out, state it!
9521 Often people omit facts because they think they know what causes the
9522 problem and assume that some details do not matter.  Thus, you might
9523 assume that the name of a symbol you use in an example does not
9524 matter.  Well, probably it does not, but one cannot be sure.  Perhaps
9525 the bug is a stray memory reference which happens to fetch from the
9526 location where that name is stored in memory; perhaps, if the name
9527 were different, the contents of that location would fool the linker
9528 into doing the right thing despite the bug.  Play it safe and give a
9529 specific, complete example.  That is the easiest thing for you to do,
9530 and the most helpful.
9532 Keep in mind that the purpose of a bug report is to enable us to fix
9533 the bug if it is new to us.  Therefore, always write your bug reports
9534 on the assumption that the bug has not been reported previously.
9536 Sometimes people give a few sketchy facts and ask, ``Does this ring a
9537 bell?''  This cannot help us fix a bug, so it is basically useless.  We
9538 respond by asking for enough details to enable us to investigate.
9539 You might as well expedite matters by sending them to begin with.
9541 To enable us to fix the bug, you should include all these things:
9543 @itemize @bullet
9544 @item
9545 The version of @command{ld}.  @command{ld} announces it if you start it with
9546 the @samp{--version} argument.
9548 Without this, we will not know whether there is any point in looking for
9549 the bug in the current version of @command{ld}.
9551 @item
9552 Any patches you may have applied to the @command{ld} source, including any
9553 patches made to the @code{BFD} library.
9555 @item
9556 The type of machine you are using, and the operating system name and
9557 version number.
9559 @item
9560 What compiler (and its version) was used to compile @command{ld}---e.g.
9561 ``@code{gcc-2.7}''.
9563 @item
9564 The command arguments you gave the linker to link your example and
9565 observe the bug.  To guarantee you will not omit something important,
9566 list them all.  A copy of the Makefile (or the output from make) is
9567 sufficient.
9569 If we were to try to guess the arguments, we would probably guess wrong
9570 and then we might not encounter the bug.
9572 @item
9573 A complete input file, or set of input files, that will reproduce the
9574 bug.  It is generally most helpful to send the actual object files
9575 provided that they are reasonably small.  Say no more than 10K.  For
9576 bigger files you can either make them available by FTP or HTTP or else
9577 state that you are willing to send the object file(s) to whomever
9578 requests them.  (Note - your email will be going to a mailing list, so
9579 we do not want to clog it up with large attachments).  But small
9580 attachments are best.
9582 If the source files were assembled using @code{gas} or compiled using
9583 @code{gcc}, then it may be OK to send the source files rather than the
9584 object files.  In this case, be sure to say exactly what version of
9585 @code{gas} or @code{gcc} was used to produce the object files.  Also say
9586 how @code{gas} or @code{gcc} were configured.
9588 @item
9589 A description of what behavior you observe that you believe is
9590 incorrect.  For example, ``It gets a fatal signal.''
9592 Of course, if the bug is that @command{ld} gets a fatal signal, then we
9593 will certainly notice it.  But if the bug is incorrect output, we might
9594 not notice unless it is glaringly wrong.  You might as well not give us
9595 a chance to make a mistake.
9597 Even if the problem you experience is a fatal signal, you should still
9598 say so explicitly.  Suppose something strange is going on, such as, your
9599 copy of @command{ld} is out of sync, or you have encountered a bug in the
9600 C library on your system.  (This has happened!)  Your copy might crash
9601 and ours would not.  If you told us to expect a crash, then when ours
9602 fails to crash, we would know that the bug was not happening for us.  If
9603 you had not told us to expect a crash, then we would not be able to draw
9604 any conclusion from our observations.
9606 @item
9607 If you wish to suggest changes to the @command{ld} source, send us context
9608 diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
9609 @samp{-p} option.  Always send diffs from the old file to the new file.
9610 If you even discuss something in the @command{ld} source, refer to it by
9611 context, not by line number.
9613 The line numbers in our development sources will not match those in your
9614 sources.  Your line numbers would convey no useful information to us.
9615 @end itemize
9617 Here are some things that are not necessary:
9619 @itemize @bullet
9620 @item
9621 A description of the envelope of the bug.
9623 Often people who encounter a bug spend a lot of time investigating
9624 which changes to the input file will make the bug go away and which
9625 changes will not affect it.
9627 This is often time consuming and not very useful, because the way we
9628 will find the bug is by running a single example under the debugger
9629 with breakpoints, not by pure deduction from a series of examples.
9630 We recommend that you save your time for something else.
9632 Of course, if you can find a simpler example to report @emph{instead}
9633 of the original one, that is a convenience for us.  Errors in the
9634 output will be easier to spot, running under the debugger will take
9635 less time, and so on.
9637 However, simplification is not vital; if you do not want to do this,
9638 report the bug anyway and send us the entire test case you used.
9640 @item
9641 A patch for the bug.
9643 A patch for the bug does help us if it is a good one.  But do not omit
9644 the necessary information, such as the test case, on the assumption that
9645 a patch is all we need.  We might see problems with your patch and decide
9646 to fix the problem another way, or we might not understand it at all.
9648 Sometimes with a program as complicated as @command{ld} it is very hard to
9649 construct an example that will make the program follow a certain path
9650 through the code.  If you do not send us the example, we will not be
9651 able to construct one, so we will not be able to verify that the bug is
9652 fixed.
9654 And if we cannot understand what bug you are trying to fix, or why your
9655 patch should be an improvement, we will not install it.  A test case will
9656 help us to understand.
9658 @item
9659 A guess about what the bug is or what it depends on.
9661 Such guesses are usually wrong.  Even we cannot guess right about such
9662 things without first using the debugger to find the facts.
9663 @end itemize
9665 @node MRI
9666 @appendix MRI Compatible Script Files
9667 @cindex MRI compatibility
9668 To aid users making the transition to @sc{gnu} @command{ld} from the MRI
9669 linker, @command{ld} can use MRI compatible linker scripts as an
9670 alternative to the more general-purpose linker scripting language
9671 described in @ref{Scripts}.  MRI compatible linker scripts have a much
9672 simpler command set than the scripting language otherwise used with
9673 @command{ld}.  @sc{gnu} @command{ld} supports the most commonly used MRI
9674 linker commands; these commands are described here.
9676 In general, MRI scripts aren't of much use with the @code{a.out} object
9677 file format, since it only has three sections and MRI scripts lack some
9678 features to make use of them.
9680 You can specify a file containing an MRI-compatible script using the
9681 @samp{-c} command-line option.
9683 Each command in an MRI-compatible script occupies its own line; each
9684 command line starts with the keyword that identifies the command (though
9685 blank lines are also allowed for punctuation).  If a line of an
9686 MRI-compatible script begins with an unrecognized keyword, @command{ld}
9687 issues a warning message, but continues processing the script.
9689 Lines beginning with @samp{*} are comments.
9691 You can write these commands using all upper-case letters, or all
9692 lower case; for example, @samp{chip} is the same as @samp{CHIP}.
9693 The following list shows only the upper-case form of each command.
9695 @table @code
9696 @cindex @code{ABSOLUTE} (MRI)
9697 @item ABSOLUTE @var{secname}
9698 @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
9699 Normally, @command{ld} includes in the output file all sections from all
9700 the input files.  However, in an MRI-compatible script, you can use the
9701 @code{ABSOLUTE} command to restrict the sections that will be present in
9702 your output program.  If the @code{ABSOLUTE} command is used at all in a
9703 script, then only the sections named explicitly in @code{ABSOLUTE}
9704 commands will appear in the linker output.  You can still use other
9705 input sections (whatever you select on the command line, or using
9706 @code{LOAD}) to resolve addresses in the output file.
9708 @cindex @code{ALIAS} (MRI)
9709 @item ALIAS @var{out-secname}, @var{in-secname}
9710 Use this command to place the data from input section @var{in-secname}
9711 in a section called @var{out-secname} in the linker output file.
9713 @var{in-secname} may be an integer.
9715 @cindex @code{ALIGN} (MRI)
9716 @item ALIGN @var{secname} = @var{expression}
9717 Align the section called @var{secname} to @var{expression}.  The
9718 @var{expression} should be a power of two.
9720 @cindex @code{BASE} (MRI)
9721 @item BASE @var{expression}
9722 Use the value of @var{expression} as the lowest address (other than
9723 absolute addresses) in the output file.
9725 @cindex @code{CHIP} (MRI)
9726 @item CHIP @var{expression}
9727 @itemx CHIP @var{expression}, @var{expression}
9728 This command does nothing; it is accepted only for compatibility.
9730 @cindex @code{END} (MRI)
9731 @item END
9732 This command does nothing whatever; it's only accepted for compatibility.
9734 @cindex @code{FORMAT} (MRI)
9735 @item FORMAT @var{output-format}
9736 Similar to the @code{OUTPUT_FORMAT} command in the more general linker
9737 language, but restricted to S-records, if @var{output-format} is @samp{S}
9739 @cindex @code{LIST} (MRI)
9740 @item LIST @var{anything}@dots{}
9741 Print (to the standard output file) a link map, as produced by the
9742 @command{ld} command-line option @samp{-M}.
9744 The keyword @code{LIST} may be followed by anything on the
9745 same line, with no change in its effect.
9747 @cindex @code{LOAD} (MRI)
9748 @item LOAD @var{filename}
9749 @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
9750 Include one or more object file @var{filename} in the link; this has the
9751 same effect as specifying @var{filename} directly on the @command{ld}
9752 command line.
9754 @cindex @code{NAME} (MRI)
9755 @item NAME @var{output-name}
9756 @var{output-name} is the name for the program produced by @command{ld}; the
9757 MRI-compatible command @code{NAME} is equivalent to the command-line
9758 option @samp{-o} or the general script language command @code{OUTPUT}.
9760 @cindex @code{ORDER} (MRI)
9761 @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
9762 @itemx ORDER @var{secname} @var{secname} @var{secname}
9763 Normally, @command{ld} orders the sections in its output file in the
9764 order in which they first appear in the input files.  In an MRI-compatible
9765 script, you can override this ordering with the @code{ORDER} command.  The
9766 sections you list with @code{ORDER} will appear first in your output
9767 file, in the order specified.
9769 @cindex @code{PUBLIC} (MRI)
9770 @item PUBLIC @var{name}=@var{expression}
9771 @itemx PUBLIC @var{name},@var{expression}
9772 @itemx PUBLIC @var{name} @var{expression}
9773 Supply a value (@var{expression}) for external symbol
9774 @var{name} used in the linker input files.
9776 @cindex @code{SECT} (MRI)
9777 @item SECT @var{secname}, @var{expression}
9778 @itemx SECT @var{secname}=@var{expression}
9779 @itemx SECT @var{secname} @var{expression}
9780 You can use any of these three forms of the @code{SECT} command to
9781 specify the start address (@var{expression}) for section @var{secname}.
9782 If you have more than one @code{SECT} statement for the same
9783 @var{secname}, only the @emph{first} sets the start address.
9784 @end table
9786 @node GNU Free Documentation License
9787 @appendix GNU Free Documentation License
9788 @include fdl.texi
9790 @node LD Index
9791 @unnumbered LD Index
9793 @printindex cp
9795 @tex
9796 % I think something like @@colophon should be in texinfo.  In the
9797 % meantime:
9798 \long\def\colophon{\hbox to0pt{}\vfill
9799 \centerline{The body of this manual is set in}
9800 \centerline{\fontname\tenrm,}
9801 \centerline{with headings in {\bf\fontname\tenbf}}
9802 \centerline{and examples in {\tt\fontname\tentt}.}
9803 \centerline{{\it\fontname\tenit\/} and}
9804 \centerline{{\sl\fontname\tensl\/}}
9805 \centerline{are used for emphasis.}\vfill}
9806 \page\colophon
9807 % Blame: doc@@cygnus.com, 28mar91.
9808 @end tex
9810 @bye