gdb/testsuite: Reduce gdb.threads/threadcrash.exp reliance on libc symbols
[binutils-gdb.git] / ld / ld.texi
blob6f234752278404defbc4165281785fe068e4de71
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 Add path @var{searchdir} to the list of paths that @command{ld} will search
762 for archive libraries and @command{ld} control scripts.  You may use this
763 option any number of times.  The directories are searched in the order
764 in which they are specified on the command line.  Directories specified
765 on the command line are searched before the default directories.  All
766 @option{-L} options apply to all @option{-l} options, regardless of the
767 order in which the options appear.  @option{-L} options do not affect
768 how @command{ld} searches for a linker script unless @option{-T}
769 option is specified.
771 If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
772 prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
773 @samp{--sysroot} option, or specified when the linker is configured.
775 @ifset UsesEnvVars
776 The default set of paths searched (without being specified with
777 @samp{-L}) depends on which emulation mode @command{ld} is using, and in
778 some cases also on how it was configured.  @xref{Environment}.
779 @end ifset
781 The paths can also be specified in a link script with the
782 @code{SEARCH_DIR} command.  Directories specified this way are searched
783 at the point in which the linker script appears in the command line.
785 @cindex emulation
786 @kindex -m @var{emulation}
787 @item -m @var{emulation}
788 Emulate the @var{emulation} linker.  You can list the available
789 emulations with the @samp{--verbose} or @samp{-V} options.
791 If the @samp{-m} option is not used, the emulation is taken from the
792 @code{LDEMULATION} environment variable, if that is defined.
794 Otherwise, the default emulation depends upon how the linker was
795 configured.
797 @cindex remapping inputs
798 @kindex --remap-inputs=@file{pattern}=@file{filename}
799 @kindex --remap-inputs-file=@file{file}
800 @item --remap-inputs=@file{pattern}=@file{filename}
801 @itemx --remap-inputs-file=@file{file}
802 These options allow the names of input files to be changed before the
803 linker attempts to open them.  The option
804 @option{--remap-inputs=foo.o=bar.o} will cause any attempt to load a
805 file called @file{foo.o} to instead try to load a file called
806 @file{bar.o}.  Wildcard patterns are permitted in the first filename,
807 so @option{--remap-inputs=foo*.o=bar.o} will rename any input file that
808 matches @file{foo*.o} to @file{bar.o}.
810 An alternative form of the option
811 @option{--remap-inputs-file=filename} allows the remappings to be read
812 from a file.  Each line in the file can contain a single remapping.
813 Blank lines are ignored.  Anything from a hash character (@samp{#}) to
814 the end of a line is considered to be a comment and is also ignored.
815 The mapping pattern can be separated from the filename by whitespace
816 or an equals (@samp{=}) character.
818 The options can be specified multiple times.  Their contents
819 accumulate.  The remappings will be processed in the order in which
820 they occur on the command line, and if they come from a file, in the
821 order in which they occur in the file.  If a match is made, no further
822 checking for that filename will be performed.
824 If the replacement filename is @file{/dev/null} or just @file{NUL}
825 then the remapping will actually cause the input file to be ignored.
826 This can be a convenient way to experiment with removing input files
827 from a complicated build environment.
829 Note that this option is position dependent and only affects filenames
830 that come after it on the command line.  Thus:
832 @smallexample
833   ld foo.o --remap-inputs=foo.o=bar.o
834 @end smallexample
836 Will have no effect, whereas:
838 @smallexample
839   ld --remap-inputs=foo.o=bar.o foo.o 
840 @end smallexample
842 Will rename the input file @file{foo.o} to @file{bar.o}.
844 Note - these options also affect files referenced by @emph{INPUT}
845 statements in linker scripts.  But since linker scripts are processed
846 after the entire command line is read, the position of the remap
847 options on the command line is not significant.
849 If the @option{verbose} option is enabled then any mappings that match
850 will be reported, although again the @option{verbose} option needs to
851 be enabled on the command line @emph{before} the remaped filenames
852 appear.
854 If the @option{-Map} or @option{--print-map} options are enabled then
855 the remapping list will be included in the map output.
857 @cindex link map
858 @kindex -M
859 @kindex --print-map
860 @item -M
861 @itemx --print-map
862 Print a link map to the standard output.  A link map provides
863 information about the link, including the following:
865 @itemize @bullet
866 @item
867 Where object files are mapped into memory.
868 @item
869 How common symbols are allocated.
870 @item
871 All archive members included in the link, with a mention of the symbol
872 which caused the archive member to be brought in.
873 @item
874 The values assigned to symbols.
876 Note - symbols whose values are computed by an expression which
877 involves a reference to a previous value of the same symbol may not
878 have correct result displayed in the link map.  This is because the
879 linker discards intermediate results and only retains the final value
880 of an expression.  Under such circumstances the linker will display
881 the final value enclosed by square brackets.  Thus for example a
882 linker script containing:
884 @smallexample
885    foo = 1
886    foo = foo * 4
887    foo = foo + 8
888 @end smallexample
890 will produce the following output in the link map if the @option{-M}
891 option is used:
893 @smallexample
894    0x00000001                foo = 0x1
895    [0x0000000c]                foo = (foo * 0x4)
896    [0x0000000c]                foo = (foo + 0x8)
897 @end smallexample
899 See @ref{Expressions} for more information about expressions in linker
900 scripts.
902 @item
903 How GNU properties are merged.
905 When the linker merges input .note.gnu.property sections into one output
906 .note.gnu.property section, some properties are removed or updated.
907 These actions are reported in the link map.  For example:
909 @smallexample
910 Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
911 @end smallexample
913 This indicates that property 0xc0000002 is removed from output when
914 merging properties in  @file{foo.o}, whose property 0xc0000002 value
915 is 0x1, and @file{bar.o}, which doesn't have property 0xc0000002.
917 @smallexample
918 Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
919 @end smallexample
921 This indicates that property 0xc0010001 value is updated to 0x1 in output
922 when merging properties in  @file{foo.o}, whose 0xc0010001 property value
923 is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1.
925 @item
926 On some ELF targets, a list of fixups inserted by @option{--relax}
928 @smallexample
929 foo.o: Adjusting branch at 0x00000008 towards "far" in section .text
930 @end smallexample
932 This indicates that the branch at 0x00000008 in foo.o, targeting
933 the symbol "far" in section .text, has been replaced by a trampoline.
935 @end itemize
937 @cindex link map discarded
938 @kindex --print-map-discarded
939 @kindex --no-print-map-discarded
940 @item --print-map-discarded
941 @itemx --no-print-map-discarded
942 Print (or do not print) the list of discarded and garbage collected sections
943 in the link map.  Enabled by default.
945 @kindex --print-map-locals
946 @kindex --no-print-map-locals
947 @item --print-map-locals
948 @itemx --no-print-map-locals
949 Print (or do not print) local symbols in the link map.  Local symbols
950 will have the text @samp{(local)} printed before their name, and will
951 be listed after all of the global symbols in a given section.
952 Temporary local symbols (typically those that start with @samp{.L})
953 will not be included in the output.  Disabled by default.
955 @kindex -n
956 @cindex read-only text
957 @cindex NMAGIC
958 @kindex --nmagic
959 @item -n
960 @itemx --nmagic
961 Turn off page alignment of sections, and disable linking against shared
962 libraries.  If the output format supports Unix style magic numbers,
963 mark the output as @code{NMAGIC}.
965 @kindex -N
966 @kindex --omagic
967 @cindex read/write from cmd line
968 @cindex OMAGIC
969 @item -N
970 @itemx --omagic
971 Set the text and data sections to be readable and writable.  Also, do
972 not page-align the data segment, and disable linking against shared
973 libraries.  If the output format supports Unix style magic numbers,
974 mark the output as @code{OMAGIC}. Note: Although a writable text section
975 is allowed for PE-COFF targets, it does not conform to the format
976 specification published by Microsoft.
978 @kindex --no-omagic
979 @cindex OMAGIC
980 @item --no-omagic
981 This option negates most of the effects of the @option{-N} option.  It
982 sets the text section to be read-only, and forces the data segment to
983 be page-aligned.  Note - this option does not enable linking against
984 shared libraries.  Use @option{-Bdynamic} for this.
986 @kindex -o @var{output}
987 @kindex --output=@var{output}
988 @cindex naming the output file
989 @item -o @var{output}
990 @itemx --output=@var{output}
991 Use @var{output} as the name for the program produced by @command{ld}; if this
992 option is not specified, the name @file{a.out} is used by default.  The
993 script command @code{OUTPUT} can also specify the output file name.
995 @kindex --dependency-file=@var{depfile}
996 @cindex dependency file
997 @item --dependency-file=@var{depfile}
998 Write a @dfn{dependency file} to @var{depfile}.  This file contains a rule
999 suitable for @code{make} describing the output file and all the input files
1000 that were read to produce it.  The output is similar to the compiler's
1001 output with @samp{-M -MP} (@pxref{Preprocessor Options,, Options
1002 Controlling the Preprocessor, gcc.info, Using the GNU Compiler
1003 Collection}).  Note that there is no option like the compiler's @samp{-MM},
1004 to exclude ``system files'' (which is not a well-specified concept in the
1005 linker, unlike ``system headers'' in the compiler).  So the output from
1006 @samp{--dependency-file} is always specific to the exact state of the
1007 installation where it was produced, and should not be copied into
1008 distributed makefiles without careful editing.
1010 @kindex -O @var{level}
1011 @cindex generating optimized output
1012 @item -O @var{level}
1013 If @var{level} is a numeric values greater than zero @command{ld} optimizes
1014 the output.  This might take significantly longer and therefore probably
1015 should only be enabled for the final binary.  At the moment this
1016 option only affects ELF shared library generation.  Future releases of
1017 the linker may make more use of this option.  Also currently there is
1018 no difference in the linker's behaviour for different non-zero values
1019 of this option.  Again this may change with future releases.
1021 @kindex -plugin @var{name}
1022 @item -plugin @var{name}
1023 Involve a plugin in the linking process.  The @var{name} parameter is
1024 the absolute filename of the plugin.  Usually this parameter is
1025 automatically added by the complier, when using link time
1026 optimization, but users can also add their own plugins if they so
1027 wish.
1029 Note that the location of the compiler originated plugins is different
1030 from the place where the @command{ar}, @command{nm} and
1031 @command{ranlib} programs search for their plugins.  In order for
1032 those commands to make use of a compiler based plugin it must first be
1033 copied into the @file{$@{libdir@}/bfd-plugins} directory.  All gcc
1034 based linker plugins are backward compatible, so it is sufficient to
1035 just copy in the newest one.
1037 @kindex --push-state
1038 @cindex push state governing input file handling
1039 @item --push-state
1040 The @option{--push-state} allows one to preserve the current state of the
1041 flags which govern the input file handling so that they can all be
1042 restored with one corresponding @option{--pop-state} option.
1044 The option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
1045 @option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
1046 @option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
1047 @option{--no-whole-archive}, @option{-r}, @option{-Ur},
1048 @option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
1049 @option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
1051 One target for this option are specifications for @file{pkg-config}.  When
1052 used with the @option{--libs} option all possibly needed libraries are
1053 listed and then possibly linked with all the time.  It is better to return
1054 something as follows:
1056 @smallexample
1057 -Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
1058 @end smallexample
1060 @kindex --pop-state
1061 @cindex pop state governing input file handling
1062 @item --pop-state
1063 Undoes the effect of --push-state, restores the previous values of the
1064 flags governing input file handling.
1066 @kindex -q
1067 @kindex --emit-relocs
1068 @cindex retain relocations in final executable
1069 @item -q
1070 @itemx --emit-relocs
1071 Leave relocation sections and contents in fully linked executables.
1072 Post link analysis and optimization tools may need this information in
1073 order to perform correct modifications of executables.  This results
1074 in larger executables.
1076 This option is currently only supported on ELF platforms.
1078 @kindex --force-dynamic
1079 @cindex forcing the creation of dynamic sections
1080 @item --force-dynamic
1081 Force the output file to have dynamic sections.  This option is specific
1082 to VxWorks targets.
1084 @cindex partial link
1085 @cindex relocatable output
1086 @kindex -r
1087 @kindex --relocatable
1088 @item -r
1089 @itemx --relocatable
1090 Generate relocatable output---i.e., generate an output file that can in
1091 turn serve as input to @command{ld}.  This is often called @dfn{partial
1092 linking}.  As a side effect, in environments that support standard Unix
1093 magic numbers, this option also sets the output file's magic number to
1094 @code{OMAGIC}.
1095 @c ; see @option{-N}.
1096 If this option is not specified, an absolute file is produced.  When
1097 linking C++ programs, this option @emph{will not} resolve references to
1098 constructors; to do that, use @samp{-Ur}.
1100 When an input file does not have the same format as the output file,
1101 partial linking is only supported if that input file does not contain any
1102 relocations.  Different output formats can have further restrictions; for
1103 example some @code{a.out}-based formats do not support partial linking
1104 with input files in other formats at all.
1106 This option does the same thing as @samp{-i}.
1108 @kindex -R @var{file}
1109 @kindex --just-symbols=@var{file}
1110 @cindex symbol-only input
1111 @item -R @var{filename}
1112 @itemx --just-symbols=@var{filename}
1113 Read symbol names and their addresses from @var{filename}, but do not
1114 relocate it or include it in the output.  This allows your output file
1115 to refer symbolically to absolute locations of memory defined in other
1116 programs.  You may use this option more than once.
1118 For compatibility with other ELF linkers, if the @option{-R} option is
1119 followed by a directory name, rather than a file name, it is treated as
1120 the @option{-rpath} option.
1122 @kindex -s
1123 @kindex --strip-all
1124 @cindex strip all symbols
1125 @item -s
1126 @itemx --strip-all
1127 Omit all symbol information from the output file.
1129 @kindex -S
1130 @kindex --strip-debug
1131 @cindex strip debugger symbols
1132 @item -S
1133 @itemx --strip-debug
1134 Omit debugger symbol information (but not all symbols) from the output file.
1136 @kindex --strip-discarded
1137 @kindex --no-strip-discarded
1138 @item --strip-discarded
1139 @itemx --no-strip-discarded
1140 Omit (or do not omit) global symbols defined in discarded sections.
1141 Enabled by default.
1143 @kindex -plugin-save-temps
1144 @item -plugin-save-temps
1145 Store the plugin ``temporary'' intermediate files permanently.
1147 @kindex -t
1148 @kindex --trace
1149 @cindex input files, displaying
1150 @item -t
1151 @itemx --trace
1152 Print the names of the input files as @command{ld} processes them.  If
1153 @samp{-t} is given twice then members within archives are also printed.
1154 @samp{-t} output is useful to generate a list of all the object files
1155 and scripts involved in linking, for example, when packaging files for
1156 a linker bug report.
1158 @kindex -T @var{script}
1159 @kindex --script=@var{script}
1160 @cindex script files
1161 @item -T @var{scriptfile}
1162 @itemx --script=@var{scriptfile}
1163 Use @var{scriptfile} as the linker script.  This script replaces
1164 @command{ld}'s default linker script (rather than adding to it),
1165 unless the script contains @code{INSERT}, so
1166 @var{commandfile} must specify everything necessary to describe the
1167 output file.  @xref{Scripts}.  If @var{scriptfile} does not exist in
1168 the current directory, @code{ld} looks for it in the directories
1169 specified by any preceding @samp{-L} options.  Multiple @samp{-T}
1170 options accumulate.
1172 @kindex -dT @var{script}
1173 @kindex --default-script=@var{script}
1174 @cindex script files
1175 @item -dT @var{scriptfile}
1176 @itemx --default-script=@var{scriptfile}
1177 Use @var{scriptfile} as the default linker script.  @xref{Scripts}.
1179 This option is similar to the @option{--script} option except that
1180 processing of the script is delayed until after the rest of the
1181 command line has been processed.  This allows options placed after the
1182 @option{--default-script} option on the command line to affect the
1183 behaviour of the linker script, which can be important when the linker
1184 command line cannot be directly controlled by the user.  (eg because
1185 the command line is being constructed by another tool, such as
1186 @samp{gcc}).
1188 @kindex -u @var{symbol}
1189 @kindex --undefined=@var{symbol}
1190 @cindex undefined symbol
1191 @item -u @var{symbol}
1192 @itemx --undefined=@var{symbol}
1193 Force @var{symbol} to be entered in the output file as an undefined
1194 symbol.  Doing this may, for example, trigger linking of additional
1195 modules from standard libraries.  @samp{-u} may be repeated with
1196 different option arguments to enter additional undefined symbols.  This
1197 option is equivalent to the @code{EXTERN} linker script command.
1199 If this option is being used to force additional modules to be pulled
1200 into the link, and if it is an error for the symbol to remain
1201 undefined, then the option @option{--require-defined} should be used
1202 instead.
1204 @kindex --require-defined=@var{symbol}
1205 @cindex symbols, require defined
1206 @cindex defined symbol
1207 @item --require-defined=@var{symbol}
1208 Require that @var{symbol} is defined in the output file.  This option
1209 is the same as option @option{--undefined} except that if @var{symbol}
1210 is not defined in the output file then the linker will issue an error
1211 and exit.  The same effect can be achieved in a linker script by using
1212 @code{EXTERN}, @code{ASSERT} and @code{DEFINED} together.  This option
1213 can be used multiple times to require additional symbols.
1215 @kindex -Ur
1216 @cindex constructors
1217 @item -Ur
1219 For programs that do not use constructors or destructors, or for ELF
1220 based systems this option is equivalent to @option{-r}:  it generates
1221 relocatable output---i.e., an output file that can in turn serve as
1222 input to @command{ld}.  For other binaries however the @option{-Ur}
1223 option is similar to @option{-r} but it also resolves references to
1224 constructors and destructors.
1226 For those systems where @option{-r} and @option{-Ur} behave
1227 differently, it does not work to use @option{-Ur} on files that were
1228 themselves linked with @option{-Ur}; once the constructor table has
1229 been built, it cannot be added to.  Use @option{-Ur} only for the last
1230 partial link, and @option{-r} for the others.
1232 @kindex --orphan-handling=@var{MODE}
1233 @cindex orphan sections
1234 @cindex sections, orphan
1235 @item --orphan-handling=@var{MODE}
1236 Control how orphan sections are handled.  An orphan section is one not
1237 specifically mentioned in a linker script.  @xref{Orphan Sections}.
1239 @var{MODE} can have any of the following values:
1241 @table @code
1242 @item place
1243 Orphan sections are placed into a suitable output section following
1244 the strategy described in @ref{Orphan Sections}.  The option
1245 @samp{--unique} also affects how sections are placed.
1247 @item discard
1248 All orphan sections are discarded, by placing them in the
1249 @samp{/DISCARD/} section (@pxref{Output Section Discarding}).
1251 @item warn
1252 The linker will place the orphan section as for @code{place} and also
1253 issue a warning.
1255 @item error
1256 The linker will exit with an error if any orphan section is found.
1257 @end table
1259 The default if @samp{--orphan-handling} is not given is @code{place}.
1261 @kindex --unique[=@var{SECTION}]
1262 @item --unique[=@var{SECTION}]
1263 Creates a separate output section for every input section matching
1264 @var{SECTION}, or if the optional wildcard @var{SECTION} argument is
1265 missing, for every orphan input section.  An orphan section is one not
1266 specifically mentioned in a linker script.  You may use this option
1267 multiple times on the command line;  It prevents the normal merging of
1268 input sections with the same name, overriding output section assignments
1269 in a linker script.
1271 @kindex -v
1272 @kindex -V
1273 @kindex --version
1274 @cindex version
1275 @item -v
1276 @itemx --version
1277 @itemx -V
1278 Display the version number for @command{ld}.  The @option{-V} option also
1279 lists the supported emulations.  See also the description of the
1280 @option{--enable-linker-version} in @ref{Options,,Command-line Options}
1281 which can be used to insert the linker version string into a binary.
1283 @kindex -x
1284 @kindex --discard-all
1285 @cindex deleting local symbols
1286 @item -x
1287 @itemx --discard-all
1288 Delete all local symbols.
1290 @kindex -X
1291 @kindex --discard-locals
1292 @cindex local symbols, deleting
1293 @item -X
1294 @itemx --discard-locals
1295 Delete all temporary local symbols.  (These symbols start with
1296 system-specific local label prefixes, typically @samp{.L} for ELF systems
1297 or @samp{L} for traditional a.out systems.)
1299 @kindex -y @var{symbol}
1300 @kindex --trace-symbol=@var{symbol}
1301 @cindex symbol tracing
1302 @item -y @var{symbol}
1303 @itemx --trace-symbol=@var{symbol}
1304 Print the name of each linked file in which @var{symbol} appears.  This
1305 option may be given any number of times.  On many systems it is necessary
1306 to prepend an underscore.
1308 This option is useful when you have an undefined symbol in your link but
1309 don't know where the reference is coming from.
1311 @kindex -Y @var{path}
1312 @item -Y @var{path}
1313 Add @var{path} to the default library search path.  This option exists
1314 for Solaris compatibility.
1316 @kindex -z @var{keyword}
1317 @item -z @var{keyword}
1318 The recognized keywords are:
1319 @table @samp
1321 @item call-nop=prefix-addr
1322 @itemx call-nop=suffix-nop
1323 @itemx call-nop=prefix-@var{byte}
1324 @itemx call-nop=suffix-@var{byte}
1325 Specify the 1-byte @code{NOP} padding when transforming indirect call
1326 to a locally defined function, foo, via its GOT slot.
1327 @option{call-nop=prefix-addr} generates @code{0x67 call foo}.
1328 @option{call-nop=suffix-nop} generates @code{call foo 0x90}.
1329 @option{call-nop=prefix-@var{byte}} generates @code{@var{byte} call foo}.
1330 @option{call-nop=suffix-@var{byte}} generates @code{call foo @var{byte}}.
1331 Supported for i386 and x86_64.
1333 @item cet-report=none
1334 @itemx cet-report=warning
1335 @itemx cet-report=error
1336 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT and
1337 GNU_PROPERTY_X86_FEATURE_1_SHSTK properties in input .note.gnu.property
1338 section.  @option{cet-report=none}, which is the default, will make the
1339 linker not report missing properties in input files.
1340 @option{cet-report=warning} will make the linker issue a warning for
1341 missing properties in input files.  @option{cet-report=error} will make
1342 the linker issue an error for missing properties in input files.
1343 Note that @option{ibt} will turn off the missing
1344 GNU_PROPERTY_X86_FEATURE_1_IBT property report and @option{shstk} will
1345 turn off the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property report.
1346 Supported for Linux/i386 and Linux/x86_64.
1348 @item combreloc
1349 @itemx nocombreloc
1350 Combine multiple dynamic relocation sections and sort to improve
1351 dynamic symbol lookup caching.  Do not do this if @samp{nocombreloc}.
1353 @item common
1354 @itemx nocommon
1355 Generate common symbols with STT_COMMON type during a relocatable
1356 link.  Use STT_OBJECT type if @samp{nocommon}.
1358 @item common-page-size=@var{value}
1359 Set the page size most commonly used to @var{value}.  Memory image
1360 layout will be optimized to minimize memory pages if the system is
1361 using pages of this size.
1363 @item defs
1364 Report unresolved symbol references from regular object files.  This
1365 is done even if the linker is creating a non-symbolic shared library.
1366 This option is the inverse of @samp{-z undefs}.
1368 @item dynamic-undefined-weak
1369 @itemx nodynamic-undefined-weak
1370 Make undefined weak symbols dynamic when building a dynamic object,
1371 if they are referenced from a regular object file and not forced local
1372 by symbol visibility or versioning.  Do not make them dynamic if
1373 @samp{nodynamic-undefined-weak}.  If neither option is given, a target
1374 may default to either option being in force, or make some other
1375 selection of undefined weak symbols dynamic.  Not all targets support
1376 these options.
1378 @item execstack
1379 Marks the object as requiring executable stack.
1381 @item global
1382 This option is only meaningful when building a shared object.  It makes
1383 the symbols defined by this shared object available for symbol resolution
1384 of subsequently loaded libraries.
1386 @item globalaudit
1387 This option is only meaningful when building a dynamic executable.
1388 This option marks the executable as requiring global auditing by
1389 setting the @code{DF_1_GLOBAUDIT} bit in the @code{DT_FLAGS_1} dynamic
1390 tag.  Global auditing requires that any auditing library defined via
1391 the @option{--depaudit} or @option{-P} command-line options be run for
1392 all dynamic objects loaded by the application.
1394 @item ibtplt
1395 Generate Intel Indirect Branch Tracking (IBT) enabled PLT entries.
1396 Supported for Linux/i386 and Linux/x86_64.
1398 @item ibt
1399 Generate GNU_PROPERTY_X86_FEATURE_1_IBT in .note.gnu.property section
1400 to indicate compatibility with IBT.  This also implies @option{ibtplt}.
1401 Supported for Linux/i386 and Linux/x86_64.
1403 @item indirect-extern-access
1404 @itemx noindirect-extern-access
1405 Generate GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS in
1406 .note.gnu.property section to indicate that object file requires
1407 canonical function pointers and cannot be used with copy relocation.
1408 This option also implies @option{noextern-protected-data} and
1409 @option{nocopyreloc}.  Supported for i386 and x86-64.
1411 @option{noindirect-extern-access} removes
1412 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS from .note.gnu.property
1413 section.
1415 @item initfirst
1416 This option is only meaningful when building a shared object.
1417 It marks the object so that its runtime initialization will occur
1418 before the runtime initialization of any other objects brought into
1419 the process at the same time.  Similarly the runtime finalization of
1420 the object will occur after the runtime finalization of any other
1421 objects.
1423 @item interpose
1424 Specify that the dynamic loader should modify its symbol search order
1425 so that symbols in this shared library interpose all other shared
1426 libraries not so marked.
1428 @item unique
1429 @itemx nounique
1430 When generating a shared library or other dynamically loadable ELF
1431 object mark it as one that should (by default) only ever be loaded once,
1432 and only in the main namespace (when using @code{dlmopen}). This is
1433 primarily used to mark fundamental libraries such as libc, libpthread et
1434 al which do not usually function correctly unless they are the sole instances
1435 of themselves. This behaviour can be overridden by the @code{dlmopen} caller
1436 and does not apply to certain loading mechanisms (such as audit libraries).
1438 @item lam-u48
1439 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U48 in .note.gnu.property section
1440 to indicate compatibility with Intel LAM_U48.  Supported for Linux/x86_64.
1442 @item lam-u57
1443 Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U57 in .note.gnu.property section
1444 to indicate compatibility with Intel LAM_U57.  Supported for Linux/x86_64.
1446 @item lam-u48-report=none
1447 @itemx lam-u48-report=warning
1448 @itemx lam-u48-report=error
1449 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48
1450 property in input .note.gnu.property section.
1451 @option{lam-u48-report=none}, which is the default, will make the
1452 linker not report missing properties in input files.
1453 @option{lam-u48-report=warning} will make the linker issue a warning for
1454 missing properties in input files.  @option{lam-u48-report=error} will
1455 make the linker issue an error for missing properties in input files.
1456 Supported for Linux/x86_64.
1458 @item lam-u57-report=none
1459 @itemx lam-u57-report=warning
1460 @itemx lam-u57-report=error
1461 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U57
1462 property in input .note.gnu.property section.
1463 @option{lam-u57-report=none}, which is the default, will make the
1464 linker not report missing properties in input files.
1465 @option{lam-u57-report=warning} will make the linker issue a warning for
1466 missing properties in input files.  @option{lam-u57-report=error} will
1467 make the linker issue an error for missing properties in input files.
1468 Supported for Linux/x86_64.
1470 @item lam-report=none
1471 @itemx lam-report=warning
1472 @itemx lam-report=error
1473 Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
1474 GNU_PROPERTY_X86_FEATURE_1_LAM_U57 properties in input .note.gnu.property
1475 section.  @option{lam-report=none}, which is the default, will make the
1476 linker not report missing properties in input files.
1477 @option{lam-report=warning} will make the linker issue a warning for
1478 missing properties in input files.  @option{lam-report=error} will make
1479 the linker issue an error for missing properties in input files.
1480 Supported for Linux/x86_64.
1482 @item lazy
1483 When generating an executable or shared library, mark it to tell the
1484 dynamic linker to defer function call resolution to the point when
1485 the function is called (lazy binding), rather than at load time.
1486 Lazy binding is the default.
1488 @item loadfltr
1489 Specify that the object's filters be processed immediately at runtime.
1491 @item max-page-size=@var{value}
1492 Set the maximum memory page size supported to @var{value}.
1494 @item mark-plt
1495 @itemx nomark-plt
1496 Mark PLT entries with dynamic tags, DT_X86_64_PLT, DT_X86_64_PLTSZ and
1497 DT_X86_64_PLTENT.  Since this option stores a non-zero value in the
1498 r_addend field of R_X86_64_JUMP_SLOT relocations, the resulting
1499 executables and shared libraries are incompatible with dynamic linkers,
1500 such as those in older versions of glibc without the change to ignore
1501 r_addend in R_X86_64_GLOB_DAT and R_X86_64_JUMP_SLOT relocations, which
1502 don't ignore the r_addend field of R_X86_64_JUMP_SLOT relocations.
1503 Supported for x86_64.
1505 @item muldefs
1506 Allow multiple definitions.
1508 @item nocopyreloc
1509 Disable linker generated .dynbss variables used in place of variables
1510 defined in shared libraries.  May result in dynamic text relocations.
1512 @item nodefaultlib
1513 Specify that the dynamic loader search for dependencies of this object
1514 should ignore any default library search paths.
1516 @item nodelete
1517 Specify that the object shouldn't be unloaded at runtime.
1519 @item nodlopen
1520 Specify that the object is not available to @code{dlopen}.
1522 @item nodump
1523 Specify that the object can not be dumped by @code{dldump}.
1525 @item noexecstack
1526 Marks the object as not requiring executable stack.
1528 @item noextern-protected-data
1529 Don't treat protected data symbols as external when building a shared
1530 library.  This option overrides the linker backend default.  It can be
1531 used to work around incorrect relocations against protected data symbols
1532 generated by compiler.  Updates on protected data symbols by another
1533 module aren't visible to the resulting shared library.  Supported for
1534 i386 and x86-64.
1536 @item noreloc-overflow
1537 Disable relocation overflow check.  This can be used to disable
1538 relocation overflow check if there will be no dynamic relocation
1539 overflow at run-time.  Supported for x86_64.
1541 @item now
1542 When generating an executable or shared library, mark it to tell the
1543 dynamic linker to resolve all symbols when the program is started, or
1544 when the shared library is loaded by dlopen, instead of deferring
1545 function call resolution to the point when the function is first
1546 called.
1548 @item origin
1549 Specify that the object requires @samp{$ORIGIN} handling in paths.
1551 @item pack-relative-relocs
1552 @itemx nopack-relative-relocs
1553 Generate compact relative relocation in position-independent executable
1554 and shared library.  It adds @code{DT_RELR}, @code{DT_RELRSZ} and
1555 @code{DT_RELRENT} entries to the dynamic section.  It is ignored when
1556 building position-dependent executable and relocatable output.
1557 @option{nopack-relative-relocs} is the default, which disables compact
1558 relative relocation.  When linked against the GNU C Library, a
1559 GLIBC_ABI_DT_RELR symbol version dependency on the shared C Library is
1560 added to the output.  Supported for i386 and x86-64.
1562 @item relro
1563 @itemx norelro
1564 Create an ELF @code{PT_GNU_RELRO} segment header in the object.  This
1565 specifies a memory segment that should be made read-only after
1566 relocation, if supported.  Specifying @samp{common-page-size} smaller
1567 than the system page size will render this protection ineffective.
1568 Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
1570 @item report-relative-reloc
1571 Report dynamic relative relocations generated by linker.  Supported for
1572 Linux/i386 and Linux/x86_64.
1574 @item sectionheader
1575 @itemx nosectionheader
1576 Generate section header.  Don't generate section header if
1577 @samp{nosectionheader} is used.  @option{sectionheader} is the default.
1579 @item separate-code
1580 @itemx noseparate-code
1581 Create separate code @code{PT_LOAD} segment header in the object.  This
1582 specifies a memory segment that should contain only instructions and must
1583 be in wholly disjoint pages from any other data.  Don't create separate
1584 code @code{PT_LOAD} segment if @samp{noseparate-code} is used.
1586 @item shstk
1587 Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
1588 to indicate compatibility with Intel Shadow Stack.  Supported for
1589 Linux/i386 and Linux/x86_64.
1591 @item stack-size=@var{value}
1592 Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
1593 Specifying zero will override any default non-zero sized
1594 @code{PT_GNU_STACK} segment creation.
1596 @item start-stop-gc
1597 @itemx nostart-stop-gc
1598 @cindex start-stop-gc
1599 When @samp{--gc-sections} is in effect, a reference from a retained
1600 section to @code{__start_SECNAME} or @code{__stop_SECNAME} causes all
1601 input sections named @code{SECNAME} to also be retained, if
1602 @code{SECNAME} is representable as a C identifier and either
1603 @code{__start_SECNAME} or @code{__stop_SECNAME} is synthesized by the
1604 linker.  @samp{-z start-stop-gc} disables this effect, allowing
1605 sections to be garbage collected as if the special synthesized symbols
1606 were not defined.  @samp{-z start-stop-gc} has no effect on a
1607 definition of @code{__start_SECNAME} or @code{__stop_SECNAME} in an
1608 object file or linker script.  Such a definition will prevent the
1609 linker providing a synthesized @code{__start_SECNAME} or
1610 @code{__stop_SECNAME} respectively, and therefore the special
1611 treatment by garbage collection for those references.
1613 @item start-stop-visibility=@var{value}
1614 @cindex visibility
1615 @cindex ELF symbol visibility
1616 Specify the ELF symbol visibility for synthesized
1617 @code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input
1618 Section Example}).  @var{value} must be exactly @samp{default},
1619 @samp{internal}, @samp{hidden}, or @samp{protected}.  If no @samp{-z
1620 start-stop-visibility} option is given, @samp{protected} is used for
1621 compatibility with historical practice.  However, it's highly
1622 recommended to use @samp{-z start-stop-visibility=hidden} in new
1623 programs and shared libraries so that these symbols are not exported
1624 between shared objects, which is not usually what's intended.
1626 @item text
1627 @itemx notext
1628 @itemx textoff
1629 Report an error if DT_TEXTREL is set, i.e., if the position-independent
1630 or shared object has dynamic relocations in read-only sections.  Don't
1631 report an error if @samp{notext} or @samp{textoff}.
1633 @item undefs
1634 Do not report unresolved symbol references from regular object files,
1635 either when creating an executable, or when creating a shared library.
1636 This option is the inverse of @samp{-z defs}.
1638 @item unique-symbol
1639 @itemx nounique-symbol
1640 Avoid duplicated local symbol names in the symbol string table.  Append
1641 ".@code{number}" to duplicated local symbol names if @samp{unique-symbol}
1642 is used.  @option{nounique-symbol} is the default.
1644 @item x86-64-baseline
1645 @item x86-64-v2
1646 @item x86-64-v3
1647 @itemx x86-64-v4
1648 Specify the x86-64 ISA level needed in .note.gnu.property section.
1649 @option{x86-64-baseline} generates @code{GNU_PROPERTY_X86_ISA_1_BASELINE}.
1650 @option{x86-64-v2} generates @code{GNU_PROPERTY_X86_ISA_1_V2}.
1651 @option{x86-64-v3} generates @code{GNU_PROPERTY_X86_ISA_1_V3}.
1652 @option{x86-64-v4} generates @code{GNU_PROPERTY_X86_ISA_1_V4}.
1653 Supported for Linux/i386 and Linux/x86_64.
1655 @end table
1657 Other keywords are ignored for Solaris compatibility.
1659 @kindex -(
1660 @cindex groups of archives
1661 @item -( @var{archives} -)
1662 @itemx --start-group @var{archives} --end-group
1663 The @var{archives} should be a list of archive files.  They may be
1664 either explicit file names, or @samp{-l} options.
1666 The specified archives are searched repeatedly until no new undefined
1667 references are created.  Normally, an archive is searched only once in
1668 the order that it is specified on the command line.  If a symbol in that
1669 archive is needed to resolve an undefined symbol referred to by an
1670 object in an archive that appears later on the command line, the linker
1671 would not be able to resolve that reference.  By grouping the archives,
1672 they will all be searched repeatedly until all possible references are
1673 resolved.
1675 Using this option has a significant performance cost.  It is best to use
1676 it only when there are unavoidable circular references between two or
1677 more archives.
1679 @kindex --accept-unknown-input-arch
1680 @kindex --no-accept-unknown-input-arch
1681 @item --accept-unknown-input-arch
1682 @itemx --no-accept-unknown-input-arch
1683 Tells the linker to accept input files whose architecture cannot be
1684 recognised.  The assumption is that the user knows what they are doing
1685 and deliberately wants to link in these unknown input files.  This was
1686 the default behaviour of the linker, before release 2.14.  The default
1687 behaviour from release 2.14 onwards is to reject such input files, and
1688 so the @samp{--accept-unknown-input-arch} option has been added to
1689 restore the old behaviour.
1691 @kindex --as-needed
1692 @kindex --no-as-needed
1693 @item --as-needed
1694 @itemx --no-as-needed
1695 This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
1696 on the command line after the @option{--as-needed} option.  Normally
1697 the linker will add a DT_NEEDED tag for each dynamic library mentioned
1698 on the command line, regardless of whether the library is actually
1699 needed or not.  @option{--as-needed} causes a DT_NEEDED tag to only be
1700 emitted for a library that @emph{at that point in the link} satisfies a
1701 non-weak undefined symbol reference from a regular object file or, if
1702 the library is not found in the DT_NEEDED lists of other needed libraries, a
1703 non-weak undefined symbol reference from another needed dynamic library.
1704 Object files or libraries appearing on the command line @emph{after}
1705 the library in question do not affect whether the library is seen as
1706 needed.  This is similar to the rules for extraction of object files
1707 from archives.  @option{--no-as-needed} restores the default behaviour.
1709 Note: On Linux based systems the @option{--as-needed} option also has
1710 an affect on the behaviour of the @option{--rpath} and
1711 @option{--rpath-link} options.  See the description of
1712 @option{--rpath-link} for more details.
1714 @kindex --add-needed
1715 @kindex --no-add-needed
1716 @item --add-needed
1717 @itemx --no-add-needed
1718 These two options have been deprecated because of the similarity of
1719 their names to the @option{--as-needed} and @option{--no-as-needed}
1720 options.  They have been replaced by @option{--copy-dt-needed-entries}
1721 and @option{--no-copy-dt-needed-entries}.
1723 @kindex -assert @var{keyword}
1724 @item -assert @var{keyword}
1725 This option is ignored for SunOS compatibility.
1727 @kindex -Bdynamic
1728 @kindex -dy
1729 @kindex -call_shared
1730 @item -Bdynamic
1731 @itemx -dy
1732 @itemx -call_shared
1733 Link against dynamic libraries.  This is only meaningful on platforms
1734 for which shared libraries are supported.  This option is normally the
1735 default on such platforms.  The different variants of this option are
1736 for compatibility with various systems.  You may use this option
1737 multiple times on the command line: it affects library searching for
1738 @option{-l} options which follow it.
1740 @kindex -Bgroup
1741 @item -Bgroup
1742 Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
1743 section.  This causes the runtime linker to handle lookups in this
1744 object and its dependencies to be performed only inside the group.
1745 @option{--unresolved-symbols=report-all} is implied.  This option is
1746 only meaningful on ELF platforms which support shared libraries.
1748 @kindex -Bstatic
1749 @kindex -dn
1750 @kindex -non_shared
1751 @kindex -static
1752 @item -Bstatic
1753 @itemx -dn
1754 @itemx -non_shared
1755 @itemx -static
1756 Do not link against shared libraries.  This is only meaningful on
1757 platforms for which shared libraries are supported.  The different
1758 variants of this option are for compatibility with various systems.  You
1759 may use this option multiple times on the command line: it affects
1760 library searching for @option{-l} options which follow it.  This
1761 option also implies @option{--unresolved-symbols=report-all}.  This
1762 option can be used with @option{-shared}.  Doing so means that a
1763 shared library is being created but that all of the library's external
1764 references must be resolved by pulling in entries from static
1765 libraries.
1767 @kindex -Bsymbolic
1768 @item -Bsymbolic
1769 When creating a shared library, bind references to global symbols to the
1770 definition within the shared library, if any.  Normally, it is possible
1771 for a program linked against a shared library to override the definition
1772 within the shared library.  This option is only meaningful on ELF
1773 platforms which support shared libraries.
1775 @kindex -Bsymbolic-functions
1776 @item -Bsymbolic-functions
1777 When creating a shared library, bind references to global function
1778 symbols to the definition within the shared library, if any.
1779 This option is only meaningful on ELF platforms which support shared
1780 libraries.
1782 @kindex -Bno-symbolic
1783 @item -Bno-symbolic
1784 This option can cancel previously specified @samp{-Bsymbolic} and
1785 @samp{-Bsymbolic-functions}.
1787 @kindex --dynamic-list=@var{dynamic-list-file}
1788 @item --dynamic-list=@var{dynamic-list-file}
1789 Specify the name of a dynamic list file to the linker.  This is
1790 typically used when creating shared libraries to specify a list of
1791 global symbols whose references shouldn't be bound to the definition
1792 within the shared library, or creating dynamically linked executables
1793 to specify a list of symbols which should be added to the symbol table
1794 in the executable.  This option is only meaningful on ELF platforms
1795 which support shared libraries.
1797 The format of the dynamic list is the same as the version node without
1798 scope and node name.  See @ref{VERSION} for more information.
1800 @kindex --dynamic-list-data
1801 @item --dynamic-list-data
1802 Include all global data symbols to the dynamic list.
1804 @kindex --dynamic-list-cpp-new
1805 @item --dynamic-list-cpp-new
1806 Provide the builtin dynamic list for C++ operator new and delete.  It
1807 is mainly useful for building shared libstdc++.
1809 @kindex --dynamic-list-cpp-typeinfo
1810 @item --dynamic-list-cpp-typeinfo
1811 Provide the builtin dynamic list for C++ runtime type identification.
1813 @kindex --check-sections
1814 @kindex --no-check-sections
1815 @item --check-sections
1816 @itemx --no-check-sections
1817 Asks the linker @emph{not} to check section addresses after they have
1818 been assigned to see if there are any overlaps.  Normally the linker will
1819 perform this check, and if it finds any overlaps it will produce
1820 suitable error messages.  The linker does know about, and does make
1821 allowances for sections in overlays.  The default behaviour can be
1822 restored by using the command-line switch @option{--check-sections}.
1823 Section overlap is not usually checked for relocatable links.  You can
1824 force checking in that case by using the @option{--check-sections}
1825 option.
1827 @kindex --copy-dt-needed-entries
1828 @kindex --no-copy-dt-needed-entries
1829 @item --copy-dt-needed-entries
1830 @itemx --no-copy-dt-needed-entries
1831 This option affects the treatment of dynamic libraries referred to
1832 by DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
1833 command line.  Normally the linker won't add a DT_NEEDED tag to the
1834 output binary for each library mentioned in a DT_NEEDED tag in an
1835 input dynamic library.  With @option{--copy-dt-needed-entries}
1836 specified on the command line however any dynamic libraries that
1837 follow it will have their DT_NEEDED entries added.  The default
1838 behaviour can be restored with @option{--no-copy-dt-needed-entries}.
1840 This option also has an effect on the resolution of symbols in dynamic
1841 libraries.  With @option{--copy-dt-needed-entries} dynamic libraries
1842 mentioned on the command line will be recursively searched, following
1843 their DT_NEEDED tags to other libraries, in order to resolve symbols
1844 required by the output binary.  With the default setting however
1845 the searching of dynamic libraries that follow it will stop with the
1846 dynamic library itself.  No DT_NEEDED links will be traversed to resolve
1847 symbols.
1849 @cindex cross reference table
1850 @kindex --cref
1851 @item --cref
1852 Output a cross reference table.  If a linker map file is being
1853 generated, the cross reference table is printed to the map file.
1854 Otherwise, it is printed on the standard output.
1856 The format of the table is intentionally simple, so that it may be
1857 easily processed by a script if necessary.  The symbols are printed out,
1858 sorted by name.  For each symbol, a list of file names is given.  If the
1859 symbol is defined, the first file listed is the location of the
1860 definition.  If the symbol is defined as a common value then any files
1861 where this happens appear next.  Finally any files that reference the
1862 symbol are listed.
1864 @cindex ctf variables
1865 @kindex --ctf-variables
1866 @kindex --no-ctf-variables
1867 @item --ctf-variables
1868 @item --no-ctf-variables
1869 The CTF debuginfo format supports a section which encodes the names and
1870 types of variables found in the program which do not appear in any symbol
1871 table. These variables clearly cannot be looked up by address by
1872 conventional debuggers, so the space used for their types and names is
1873 usually wasted: the types are usually small but the names are often not.
1874 @option{--ctf-variables} causes the generation of such a section.
1875 The default behaviour can be restored with @option{--no-ctf-variables}.
1877 @cindex ctf type sharing
1878 @kindex --ctf-share-types
1879 @item --ctf-share-types=@var{method}
1880 Adjust the method used to share types between translation units in CTF.
1882 @table @samp
1883 @item share-unconflicted
1884 Put all types that do not have ambiguous definitions into the shared dictionary,
1885 where debuggers can easily access them, even if they only occur in one
1886 translation unit.  This is the default.
1888 @item share-duplicated
1889 Put only types that occur in multiple translation units into the shared
1890 dictionary: types with only one definition go into per-translation-unit
1891 dictionaries.  Types with ambiguous definitions in multiple translation units
1892 always go into per-translation-unit dictionaries.  This tends to make the CTF
1893 larger, but may reduce the amount of CTF in the shared dictionary.  For very
1894 large projects this may speed up opening the CTF and save memory in the CTF
1895 consumer at runtime.
1896 @end table
1898 @cindex common allocation
1899 @kindex --no-define-common
1900 @item --no-define-common
1901 This option inhibits the assignment of addresses to common symbols.
1902 The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
1903 @xref{Miscellaneous Commands}.
1905 The @samp{--no-define-common} option allows decoupling
1906 the decision to assign addresses to Common symbols from the choice
1907 of the output file type; otherwise a non-Relocatable output type
1908 forces assigning addresses to Common symbols.
1909 Using @samp{--no-define-common} allows Common symbols that are referenced
1910 from a shared library to be assigned addresses only in the main program.
1911 This eliminates the unused duplicate space in the shared library,
1912 and also prevents any possible confusion over resolving to the wrong
1913 duplicate when there are many dynamic modules with specialized search
1914 paths for runtime symbol resolution.
1916 @cindex group allocation in linker script
1917 @cindex section groups
1918 @cindex COMDAT
1919 @kindex --force-group-allocation
1920 @item --force-group-allocation
1921 This option causes the linker to place section group members like
1922 normal input sections, and to delete the section groups.  This is the
1923 default behaviour for a final link but this option can be used to
1924 change the behaviour of a relocatable link (@samp{-r}).  The script
1925 command @code{FORCE_GROUP_ALLOCATION} has the same
1926 effect. @xref{Miscellaneous Commands}.
1928 @cindex symbols, from command line
1929 @kindex --defsym=@var{symbol}=@var{exp}
1930 @item --defsym=@var{symbol}=@var{expression}
1931 Create a global symbol in the output file, containing the absolute
1932 address given by @var{expression}.  You may use this option as many
1933 times as necessary to define multiple symbols in the command line.  A
1934 limited form of arithmetic is supported for the @var{expression} in this
1935 context: you may give a hexadecimal constant or the name of an existing
1936 symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
1937 constants or symbols.  If you need more elaborate expressions, consider
1938 using the linker command language from a script (@pxref{Assignments}).
1939 @emph{Note:} there should be no white space between @var{symbol}, the
1940 equals sign (``@key{=}''), and @var{expression}.
1942 The linker processes @samp{--defsym} arguments and @samp{-T} arguments
1943 in order, placing @samp{--defsym} before @samp{-T} will define the
1944 symbol before the linker script from @samp{-T} is processed, while
1945 placing @samp{--defsym} after @samp{-T} will define the symbol after
1946 the linker script has been processed.  This difference has
1947 consequences for expressions within the linker script that use the
1948 @samp{--defsym} symbols, which order is correct will depend on what
1949 you are trying to achieve.
1951 @cindex demangling, from command line
1952 @kindex --demangle[=@var{style}]
1953 @kindex --no-demangle
1954 @item --demangle[=@var{style}]
1955 @itemx --no-demangle
1956 These options control whether to demangle symbol names in error messages
1957 and other output.  When the linker is told to demangle, it tries to
1958 present symbol names in a readable fashion: it strips leading
1959 underscores if they are used by the object file format, and converts C++
1960 mangled symbol names into user readable names.  Different compilers have
1961 different mangling styles.  The optional demangling style argument can be used
1962 to choose an appropriate demangling style for your compiler.  The linker will
1963 demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
1964 is set.  These options may be used to override the default.
1966 @cindex dynamic linker, from command line
1967 @kindex -I@var{file}
1968 @kindex --dynamic-linker=@var{file}
1969 @item -I@var{file}
1970 @itemx --dynamic-linker=@var{file}
1971 Set the name of the dynamic linker.  This is only meaningful when
1972 generating dynamically linked ELF executables.  The default dynamic
1973 linker is normally correct; don't use this unless you know what you are
1974 doing.
1976 @kindex --no-dynamic-linker
1977 @item --no-dynamic-linker
1978 When producing an executable file, omit the request for a dynamic
1979 linker to be used at load-time.  This is only meaningful for ELF
1980 executables that contain dynamic relocations, and usually requires
1981 entry point code that is capable of processing these relocations.
1983 @kindex --embedded-relocs
1984 @item --embedded-relocs
1985 This option is similar to the @option{--emit-relocs} option except
1986 that the relocs are stored in a target-specific section.  This option
1987 is only supported by the @samp{BFIN}, @samp{CR16} and @emph{M68K}
1988 targets.
1990 @kindex --disable-multiple-abs-defs
1991 @item --disable-multiple-abs-defs
1992 Do not allow multiple definitions with symbols included
1993 in filename invoked by -R or --just-symbols
1995 @kindex --fatal-warnings
1996 @kindex --no-fatal-warnings
1997 @item --fatal-warnings
1998 @itemx --no-fatal-warnings
1999 Treat all warnings as errors.  The default behaviour can be restored
2000 with the option @option{--no-fatal-warnings}.
2002 @kindex -w
2003 @kindex --no-warnings
2004 @item -w
2005 @itemx --no-warnings
2006 Do not display any warning or error messages.  This overrides
2007 @option{--fatal-warnings} if it has been enabled.  This option can be
2008 used when it is known that the output binary will not work, but there
2009 is still a need to create it.
2011 @kindex --force-exe-suffix
2012 @item  --force-exe-suffix
2013 Make sure that an output file has a .exe suffix.
2015 If a successfully built fully linked output file does not have a
2016 @code{.exe} or @code{.dll} suffix, this option forces the linker to copy
2017 the output file to one of the same name with a @code{.exe} suffix. This
2018 option is useful when using unmodified Unix makefiles on a Microsoft
2019 Windows host, since some versions of Windows won't run an image unless
2020 it ends in a @code{.exe} suffix.
2022 @kindex --gc-sections
2023 @kindex --no-gc-sections
2024 @cindex garbage collection
2025 @item --gc-sections
2026 @itemx --no-gc-sections
2027 Enable garbage collection of unused input sections.  It is ignored on
2028 targets that do not support this option.  The default behaviour (of not
2029 performing this garbage collection) can be restored by specifying
2030 @samp{--no-gc-sections} on the command line.  Note that garbage
2031 collection for COFF and PE format targets is supported, but the
2032 implementation is currently considered to be experimental.
2034 @samp{--gc-sections} decides which input sections are used by
2035 examining symbols and relocations.  The section containing the entry
2036 symbol and all sections containing symbols undefined on the
2037 command-line will be kept, as will sections containing symbols
2038 referenced by dynamic objects.  Note that when building shared
2039 libraries, the linker must assume that any visible symbol is
2040 referenced.  Once this initial set of sections has been determined,
2041 the linker recursively marks as used any section referenced by their
2042 relocations.  See @samp{--entry}, @samp{--undefined}, and
2043 @samp{--gc-keep-exported}.
2045 This option can be set when doing a partial link (enabled with option
2046 @samp{-r}).  In this case the root of symbols kept must be explicitly
2047 specified either by one of the options @samp{--entry},
2048 @samp{--undefined}, or @samp{--gc-keep-exported} or by a @code{ENTRY}
2049 command in the linker script.
2051 As a GNU extension, ELF input sections marked with the
2052 @code{SHF_GNU_RETAIN} flag will not be garbage collected.
2054 @kindex --print-gc-sections
2055 @kindex --no-print-gc-sections
2056 @cindex garbage collection
2057 @item --print-gc-sections
2058 @itemx --no-print-gc-sections
2059 List all sections removed by garbage collection.  The listing is
2060 printed on stderr.  This option is only effective if garbage
2061 collection has been enabled via the @samp{--gc-sections}) option.  The
2062 default behaviour (of not listing the sections that are removed) can
2063 be restored by specifying @samp{--no-print-gc-sections} on the command
2064 line.
2066 @kindex --gc-keep-exported
2067 @cindex garbage collection
2068 @item --gc-keep-exported
2069 When @samp{--gc-sections} is enabled, this option prevents garbage
2070 collection of unused input sections that contain global symbols having
2071 default or protected visibility.  This option is intended to be used for
2072 executables where unreferenced sections would otherwise be garbage
2073 collected regardless of the external visibility of contained symbols.
2074 Note that this option has no effect when linking shared objects since
2075 it is already the default behaviour.  This option is only supported for
2076 ELF format targets.
2078 @kindex --print-output-format
2079 @cindex output format
2080 @item --print-output-format
2081 Print the name of the default output format (perhaps influenced by
2082 other command-line options).  This is the string that would appear
2083 in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
2085 @kindex --print-memory-usage
2086 @cindex memory usage
2087 @item --print-memory-usage
2088 Print used size, total size and used size of memory regions created with
2089 the @ref{MEMORY} command.  This is useful on embedded targets to have a
2090 quick view of amount of free memory.  The format of the output has one
2091 headline and one line per region.  It is both human readable and easily
2092 parsable by tools.  Here is an example of an output:
2094 @smallexample
2095 Memory region         Used Size  Region Size  %age Used
2096              ROM:        256 KB         1 MB     25.00%
2097              RAM:          32 B         2 GB      0.00%
2098 @end smallexample
2100 @cindex help
2101 @cindex usage
2102 @kindex --help
2103 @item --help
2104 Print a summary of the command-line options on the standard output and exit.
2106 @kindex --target-help
2107 @item --target-help
2108 Print a summary of all target-specific options on the standard output and exit.
2110 @kindex -Map=@var{mapfile}
2111 @item -Map=@var{mapfile}
2112 Print a link map to the file @var{mapfile}.  See the description of the
2113 @option{-M} option, above.  If @var{mapfile} is just the character
2114 @code{-} then the map will be written to stdout.
2116 Specifying a directory as @var{mapfile} causes the linker map to be
2117 written as a file inside the directory.  Normally name of the file
2118 inside the directory is computed as the basename of the @var{output}
2119 file with @code{.map} appended.   If however the special character
2120 @code{%} is used then this will be replaced by the full path of the
2121 output file.  Additionally if there are any characters after the
2122 @var{%} symbol then @code{.map} will no longer be appended.
2124 @smallexample
2125  -o foo.exe -Map=bar                  [Creates ./bar]
2126  -o ../dir/foo.exe -Map=bar           [Creates ./bar]
2127  -o foo.exe -Map=../dir               [Creates ../dir/foo.exe.map]
2128  -o ../dir2/foo.exe -Map=../dir       [Creates ../dir/foo.exe.map]
2129  -o foo.exe -Map=%                    [Creates ./foo.exe.map]
2130  -o ../dir/foo.exe -Map=%             [Creates ../dir/foo.exe.map]
2131  -o foo.exe -Map=%.bar                [Creates ./foo.exe.bar]
2132  -o ../dir/foo.exe -Map=%.bar         [Creates ../dir/foo.exe.bar]
2133  -o ../dir2/foo.exe -Map=../dir/%     [Creates ../dir/../dir2/foo.exe.map]
2134  -o ../dir2/foo.exe -Map=../dir/%.bar [Creates ../dir/../dir2/foo.exe.bar]
2135 @end smallexample
2137 It is an error to specify more than one @code{%} character.
2139 If the map file already exists then it will be overwritten by this
2140 operation.
2142 @cindex memory usage
2143 @kindex --no-keep-memory
2144 @item --no-keep-memory
2145 @command{ld} normally optimizes for speed over memory usage by caching the
2146 symbol tables of input files in memory.  This option tells @command{ld} to
2147 instead optimize for memory usage, by rereading the symbol tables as
2148 necessary.  This may be required if @command{ld} runs out of memory space
2149 while linking a large executable.
2151 @kindex --no-undefined
2152 @kindex -z defs
2153 @kindex -z undefs
2154 @item --no-undefined
2155 @itemx -z defs
2156 Report unresolved symbol references from regular object files.  This
2157 is done even if the linker is creating a non-symbolic shared library.
2158 The switch @option{--[no-]allow-shlib-undefined} controls the
2159 behaviour for reporting unresolved references found in shared
2160 libraries being linked in.
2162 The effects of this option can be reverted by using @code{-z undefs}.
2164 @kindex --allow-multiple-definition
2165 @kindex -z muldefs
2166 @item --allow-multiple-definition
2167 @itemx -z muldefs
2168 Normally when a symbol is defined multiple times, the linker will
2169 report a fatal error. These options allow multiple definitions and the
2170 first definition will be used.
2172 @kindex --allow-shlib-undefined
2173 @kindex --no-allow-shlib-undefined
2174 @item --allow-shlib-undefined
2175 @itemx --no-allow-shlib-undefined
2176 Allows or disallows undefined symbols in shared libraries.
2177 This switch is similar to @option{--no-undefined} except that it
2178 determines the behaviour when the undefined symbols are in a
2179 shared library rather than a regular object file.  It does not affect
2180 how undefined symbols in regular object files are handled.
2182 The default behaviour is to report errors for any undefined symbols
2183 referenced in shared libraries if the linker is being used to create
2184 an executable, but to allow them if the linker is being used to create
2185 a shared library.
2187 The reasons for allowing undefined symbol references in shared
2188 libraries specified at link time are that:
2190 @itemize @bullet
2191 @item
2192 A shared library specified at link time may not be the same as the one
2193 that is available at load time, so the symbol might actually be
2194 resolvable at load time.
2195 @item
2196 There are some operating systems, eg BeOS and HPPA, where undefined
2197 symbols in shared libraries are normal.
2199 The BeOS kernel for example patches shared libraries at load time to
2200 select whichever function is most appropriate for the current
2201 architecture.  This is used, for example, to dynamically select an
2202 appropriate memset function.
2203 @end itemize
2205 @kindex --error-handling-script=@var{scriptname}
2206 @item --error-handling-script=@var{scriptname}
2207 If this option is provided then the linker will invoke
2208 @var{scriptname} whenever an error is encountered.  Currently however
2209 only two kinds of error are supported: missing symbols and missing
2210 libraries.  Two arguments will be passed to script: the keyword
2211 ``undefined-symbol'' or `missing-lib'' and the @var{name} of the
2212 undefined symbol or missing library.  The intention is that the script
2213 will provide suggestions to the user as to where the symbol or library
2214 might be found.  After the script has finished then the normal linker
2215 error message will be displayed.
2217 The availability of this option is controlled by a configure time
2218 switch, so it may not be present in specific implementations.
2220 @kindex --no-undefined-version
2221 @item --no-undefined-version
2222 Normally when a symbol has an undefined version, the linker will ignore
2223 it. This option disallows symbols with undefined version and a fatal error
2224 will be issued instead.
2226 @kindex --default-symver
2227 @item --default-symver
2228 Create and use a default symbol version (the soname) for unversioned
2229 exported symbols.
2231 @kindex --default-imported-symver
2232 @item --default-imported-symver
2233 Create and use a default symbol version (the soname) for unversioned
2234 imported symbols.
2236 @kindex --no-warn-mismatch
2237 @item --no-warn-mismatch
2238 Normally @command{ld} will give an error if you try to link together input
2239 files that are mismatched for some reason, perhaps because they have
2240 been compiled for different processors or for different endiannesses.
2241 This option tells @command{ld} that it should silently permit such possible
2242 errors.  This option should only be used with care, in cases when you
2243 have taken some special action that ensures that the linker errors are
2244 inappropriate.
2246 @kindex --no-warn-search-mismatch
2247 @item --no-warn-search-mismatch
2248 Normally @command{ld} will give a warning if it finds an incompatible
2249 library during a library search.  This option silences the warning.
2251 @kindex --no-whole-archive
2252 @item --no-whole-archive
2253 Turn off the effect of the @option{--whole-archive} option for subsequent
2254 archive files.
2256 @cindex output file after errors
2257 @kindex --noinhibit-exec
2258 @item --noinhibit-exec
2259 Retain the executable output file whenever it is still usable.
2260 Normally, the linker will not produce an output file if it encounters
2261 errors during the link process; it exits without writing an output file
2262 when it issues any error whatsoever.
2264 @kindex -nostdlib
2265 @item -nostdlib
2266 Only search library directories explicitly specified on the
2267 command line.  Library directories specified in linker scripts
2268 (including linker scripts specified on the command line) are ignored.
2270 @ifclear SingleFormat
2271 @kindex --oformat=@var{output-format}
2272 @item --oformat=@var{output-format}
2273 @command{ld} may be configured to support more than one kind of object
2274 file.  If your @command{ld} is configured this way, you can use the
2275 @samp{--oformat} option to specify the binary format for the output
2276 object file.  Even when @command{ld} is configured to support alternative
2277 object formats, you don't usually need to specify this, as @command{ld}
2278 should be configured to produce as a default output format the most
2279 usual format on each machine.  @var{output-format} is a text string, the
2280 name of a particular format supported by the BFD libraries.  (You can
2281 list the available binary formats with @samp{objdump -i}.)  The script
2282 command @code{OUTPUT_FORMAT} can also specify the output format, but
2283 this option overrides it.  @xref{BFD}.
2284 @end ifclear
2286 @kindex --out-implib
2287 @item --out-implib @var{file}
2288 Create an import library in @var{file} corresponding to the executable
2289 the linker is generating (eg. a DLL or ELF program).  This import
2290 library (which should be called @code{*.dll.a} or @code{*.a} for DLLs)
2291 may be used to link clients against the generated executable; this
2292 behaviour makes it possible to skip a separate import library creation
2293 step (eg. @code{dlltool} for DLLs).  This option is only available for
2294 the i386 PE and ELF targetted ports of the linker.
2296 @kindex -pie
2297 @kindex --pic-executable
2298 @item -pie
2299 @itemx --pic-executable
2300 @cindex position independent executables
2301 Create a position independent executable.  This is currently only
2302 supported on ELF platforms.  Position independent executables are
2303 relocated by the dynamic linker to the virtual address the OS chooses
2304 for them, which can vary between invocations.  They are marked ET_DYN
2305 in the ELF file header, but differ from shared libraries in a number
2306 of ways.  In particular, defined symbols in a PIE by default can not
2307 be overridden by another object as they can be in a shared library.
2309 @kindex -no-pie
2310 @item -no-pie
2311 @cindex position dependent executables
2312 Create a position dependent executable.  This is the default.
2314 @kindex -qmagic
2315 @item -qmagic
2316 This option is ignored for Linux compatibility.
2318 @kindex -Qy
2319 @item -Qy
2320 This option is ignored for SVR4 compatibility.
2322 @kindex --relax
2323 @cindex synthesizing linker
2324 @cindex relaxing addressing modes
2325 @cindex --no-relax
2326 @item --relax
2327 @itemx --no-relax
2328 An option with machine dependent effects.
2329 @ifset GENERIC
2330 This option is only supported on a few targets.
2331 @end ifset
2332 @ifset H8300
2333 @xref{H8/300,,@command{ld} and the H8/300}.
2334 @end ifset
2335 @ifset XTENSA
2336 @xref{Xtensa,, @command{ld} and Xtensa Processors}.
2337 @end ifset
2338 @ifset M68HC11
2339 @xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
2340 @end ifset
2341 @ifset NIOSII
2342 @xref{Nios II,,@command{ld} and the Altera Nios II}.
2343 @end ifset
2344 @ifset POWERPC
2345 @xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}.
2346 @end ifset
2348 On some platforms the @option{--relax} option performs target specific,
2349 global optimizations that become possible when the linker resolves
2350 addressing in the program, such as relaxing address modes,
2351 synthesizing new instructions, selecting shorter version of current
2352 instructions, and combining constant values.
2354 On some platforms these link time global optimizations may make symbolic
2355 debugging of the resulting executable impossible.
2356 @ifset GENERIC
2357 This is known to be the case for the Matsushita MN10200 and MN10300
2358 family of processors.
2359 @end ifset
2361 On platforms where the feature is supported, the option
2362 @option{--no-relax} will disable it.
2364 On platforms where the feature is not supported, both @option{--relax}
2365 and @option{--no-relax} are accepted, but ignored.
2367 @cindex retaining specified symbols
2368 @cindex stripping all but some symbols
2369 @cindex symbols, retaining selectively
2370 @kindex --retain-symbols-file=@var{filename}
2371 @item --retain-symbols-file=@var{filename}
2372 Retain @emph{only} the symbols listed in the file @var{filename},
2373 discarding all others.  @var{filename} is simply a flat file, with one
2374 symbol name per line.  This option is especially useful in environments
2375 @ifset GENERIC
2376 (such as VxWorks)
2377 @end ifset
2378 where a large global symbol table is accumulated gradually, to conserve
2379 run-time memory.
2381 @samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
2382 or symbols needed for relocations.
2384 You may only specify @samp{--retain-symbols-file} once in the command
2385 line.  It overrides @samp{-s} and @samp{-S}.
2387 @ifset GENERIC
2388 @item -rpath=@var{dir}
2389 @cindex runtime library search path
2390 @kindex -rpath=@var{dir}
2391 Add a directory to the runtime library search path.  This is used when
2392 linking an ELF executable with shared objects.  All @option{-rpath}
2393 arguments are concatenated and passed to the runtime linker, which uses
2394 them to locate shared objects at runtime.
2396 The @option{-rpath} option is also used when locating shared objects which
2397 are needed by shared objects explicitly included in the link; see the
2398 description of the @option{-rpath-link} option.  Searching @option{-rpath}
2399 in this way is only supported by native linkers and cross linkers which
2400 have been configured with the @option{--with-sysroot} option.
2402 If @option{-rpath} is not used when linking an ELF executable, the
2403 contents of the environment variable @code{LD_RUN_PATH} will be used if it
2404 is defined.
2406 The @option{-rpath} option may also be used on SunOS.  By default, on
2407 SunOS, the linker will form a runtime search path out of all the
2408 @option{-L} options it is given.  If a @option{-rpath} option is used, the
2409 runtime search path will be formed exclusively using the @option{-rpath}
2410 options, ignoring the @option{-L} options.  This can be useful when using
2411 gcc, which adds many @option{-L} options which may be on NFS mounted
2412 file systems.
2414 For compatibility with other ELF linkers, if the @option{-R} option is
2415 followed by a directory name, rather than a file name, it is treated as
2416 the @option{-rpath} option.
2417 @end ifset
2419 @ifset GENERIC
2420 @cindex link-time runtime library search path
2421 @kindex -rpath-link=@var{dir}
2422 @item -rpath-link=@var{dir}
2423 When using ELF or SunOS, one shared library may require another.  This
2424 happens when an @code{ld -shared} link includes a shared library as one
2425 of the input files.
2427 When the linker encounters such a dependency when doing a non-shared,
2428 non-relocatable link, it will automatically try to locate the required
2429 shared library and include it in the link, if it is not included
2430 explicitly.  In such a case, the @option{-rpath-link} option
2431 specifies the first set of directories to search.  The
2432 @option{-rpath-link} option may specify a sequence of directory names
2433 either by specifying a list of names separated by colons, or by
2434 appearing multiple times.
2436 The tokens @var{$ORIGIN} and @var{$LIB} can appear in these search
2437 directories.  They will be replaced by the full path to the directory
2438 containing the program or shared object in the case of @var{$ORIGIN}
2439 and either @samp{lib} - for 32-bit binaries - or @samp{lib64} - for
2440 64-bit binaries - in the case of @var{$LIB}.
2442 The alternative form of these tokens - @var{$@{ORIGIN@}} and
2443 @var{$@{LIB@}} can also be used.  The token @var{$PLATFORM} is not
2444 supported.
2446 This option should be used with caution as it overrides the search path
2447 that may have been hard compiled into a shared library. In such a case it
2448 is possible to use unintentionally a different search path than the
2449 runtime linker would do.
2451 The linker uses the following search paths to locate required shared
2452 libraries:
2454 @enumerate
2455 @item
2456 Any directories specified by @option{-rpath-link} options.
2457 @item
2458 Any directories specified by @option{-rpath} options.  The difference
2459 between @option{-rpath} and @option{-rpath-link} is that directories
2460 specified by @option{-rpath} options are included in the executable and
2461 used at runtime, whereas the @option{-rpath-link} option is only effective
2462 at link time. Searching @option{-rpath} in this way is only supported
2463 by native linkers and cross linkers which have been configured with
2464 the @option{--with-sysroot} option.
2465 @item
2466 On an ELF system, for native linkers, if the @option{-rpath} and
2467 @option{-rpath-link} options were not used, search the contents of the
2468 environment variable @code{LD_RUN_PATH}.
2469 @item
2470 On SunOS, if the @option{-rpath} option was not used, search any
2471 directories specified using @option{-L} options.
2472 @item
2473 For a native linker, search the contents of the environment
2474 variable @code{LD_LIBRARY_PATH}.
2475 @item
2476 For a native ELF linker, the directories in @code{DT_RUNPATH} or
2477 @code{DT_RPATH} of a shared library are searched for shared
2478 libraries needed by it. The @code{DT_RPATH} entries are ignored if
2479 @code{DT_RUNPATH} entries exist.
2480 @item
2481 For a linker for a Linux system, if the file @file{/etc/ld.so.conf}
2482 exists, the list of directories found in that file.  Note: the path
2483 to this file is prefixed with the @code{sysroot} value, if that is
2484 defined, and then any @code{prefix} string if the linker was
2485 configured with the @command{--prefix=<path>} option.
2486 @item
2487 For a native linker on a FreeBSD system, any directories specified by
2488 the @code{_PATH_ELF_HINTS} macro defined in the @file{elf-hints.h}
2489 header file.
2490 @item
2491 Any directories specified by a @code{SEARCH_DIR} command in a
2492 linker script given on the command line, including scripts specified
2493 by @option{-T} (but not @option{-dT}).
2494 @item
2495 The default directories, normally @file{/lib} and @file{/usr/lib}.
2496 @item
2497 Any directories specified by a plugin LDPT_SET_EXTRA_LIBRARY_PATH.
2498 @item
2499 Any directories specified by a @code{SEARCH_DIR} command in a default
2500 linker script.
2501 @end enumerate
2503 Note however on Linux based systems there is an additional caveat:  If
2504 the @option{--as-needed} option is active @emph{and} a shared library
2505 is located which would normally satisfy the search @emph{and} this
2506 library does not have DT_NEEDED tag for @file{libc.so}
2507 @emph{and} there is a shared library later on in the set of search
2508 directories which also satisfies the search @emph{and}
2509 this second shared library does have a DT_NEEDED tag for
2510 @file{libc.so} @emph{then} the second library will be selected instead
2511 of the first.
2513 If the required shared library is not found, the linker will issue a
2514 warning and continue with the link.
2516 @end ifset
2518 @kindex -shared
2519 @kindex -Bshareable
2520 @item -shared
2521 @itemx -Bshareable
2522 @cindex shared libraries
2523 Create a shared library.  This is currently only supported on ELF, XCOFF
2524 and SunOS platforms.  On SunOS, the linker will automatically create a
2525 shared library if the @option{-e} option is not used and there are
2526 undefined symbols in the link.
2528 @kindex --sort-common
2529 @item --sort-common
2530 @itemx --sort-common=ascending
2531 @itemx --sort-common=descending
2532 This option tells @command{ld} to sort the common symbols by alignment in
2533 ascending or descending order when it places them in the appropriate output
2534 sections.  The symbol alignments considered are sixteen-byte or larger,
2535 eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
2536 between symbols due to alignment constraints.  If no sorting order is
2537 specified, then descending order is assumed.
2539 @kindex --sort-section=name
2540 @item --sort-section=name
2541 This option will apply @code{SORT_BY_NAME} to all wildcard section
2542 patterns in the linker script.
2544 @kindex --sort-section=alignment
2545 @item --sort-section=alignment
2546 This option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
2547 patterns in the linker script.
2549 @kindex --spare-dynamic-tags
2550 @item --spare-dynamic-tags=@var{count}
2551 This option specifies the number of empty slots to leave in the
2552 .dynamic section of ELF shared objects.  Empty slots may be needed by
2553 post processing tools, such as the prelinker.  The default is 5.
2555 @kindex --split-by-file
2556 @item --split-by-file[=@var{size}]
2557 Similar to @option{--split-by-reloc} but creates a new output section for
2558 each input file when @var{size} is reached.  @var{size} defaults to a
2559 size of 1 if not given.
2561 @kindex --split-by-reloc
2562 @item --split-by-reloc[=@var{count}]
2563 Tries to creates extra sections in the output file so that no single
2564 output section in the file contains more than @var{count} relocations.
2565 This is useful when generating huge relocatable files for downloading into
2566 certain real time kernels with the COFF object file format; since COFF
2567 cannot represent more than 65535 relocations in a single section.  Note
2568 that this will fail to work with object file formats which do not
2569 support arbitrary sections.  The linker will not split up individual
2570 input sections for redistribution, so if a single input section contains
2571 more than @var{count} relocations one output section will contain that
2572 many relocations.  @var{count} defaults to a value of 32768.
2574 @kindex --stats
2575 @item --stats
2576 Compute and display statistics about the operation of the linker, such
2577 as execution time and memory usage.
2579 @kindex --sysroot=@var{directory}
2580 @item --sysroot=@var{directory}
2581 Use @var{directory} as the location of the sysroot, overriding the
2582 configure-time default.  This option is only supported by linkers
2583 that were configured using @option{--with-sysroot}.
2585 @kindex --task-link
2586 @item --task-link
2587 This is used by COFF/PE based targets to create a task-linked object
2588 file where all of the global symbols have been converted to statics.
2590 @kindex --traditional-format
2591 @cindex traditional format
2592 @item --traditional-format
2593 For some targets, the output of @command{ld} is different in some ways from
2594 the output of some existing linker.  This switch requests @command{ld} to
2595 use the traditional format instead.
2597 @cindex dbx
2598 For example, on SunOS, @command{ld} combines duplicate entries in the
2599 symbol string table.  This can reduce the size of an output file with
2600 full debugging information by over 30 percent.  Unfortunately, the SunOS
2601 @code{dbx} program can not read the resulting program (@code{gdb} has no
2602 trouble).  The @samp{--traditional-format} switch tells @command{ld} to not
2603 combine duplicate entries.
2605 @kindex --section-start=@var{sectionname}=@var{org}
2606 @item --section-start=@var{sectionname}=@var{org}
2607 Locate a section in the output file at the absolute
2608 address given by @var{org}.  You may use this option as many
2609 times as necessary to locate multiple sections in the command
2610 line.
2611 @var{org} must be a single hexadecimal integer;
2612 for compatibility with other linkers, you may omit the leading
2613 @samp{0x} usually associated with hexadecimal values.  @emph{Note:} there
2614 should be no white space between @var{sectionname}, the equals
2615 sign (``@key{=}''), and @var{org}.
2617 @kindex -Tbss=@var{org}
2618 @kindex -Tdata=@var{org}
2619 @kindex -Ttext=@var{org}
2620 @cindex segment origins, cmd line
2621 @item -Tbss=@var{org}
2622 @itemx -Tdata=@var{org}
2623 @itemx -Ttext=@var{org}
2624 Same as @option{--section-start}, with @code{.bss}, @code{.data} or
2625 @code{.text} as the @var{sectionname}.
2627 @kindex -Ttext-segment=@var{org}
2628 @item -Ttext-segment=@var{org}
2629 @cindex text segment origin, cmd line
2630 When creating an ELF executable, it will set the address of the first
2631 byte of the text segment.
2633 @kindex -Trodata-segment=@var{org}
2634 @item -Trodata-segment=@var{org}
2635 @cindex rodata segment origin, cmd line
2636 When creating an ELF executable or shared object for a target where
2637 the read-only data is in its own segment separate from the executable
2638 text, it will set the address of the first byte of the read-only data segment.
2640 @kindex -Tldata-segment=@var{org}
2641 @item -Tldata-segment=@var{org}
2642 @cindex ldata segment origin, cmd line
2643 When creating an ELF executable or shared object for x86-64 medium memory
2644 model, it will set the address of the first byte of the ldata segment.
2646 @kindex --unresolved-symbols
2647 @item --unresolved-symbols=@var{method}
2648 Determine how to handle unresolved symbols.  There are four possible
2649 values for @samp{method}:
2651 @table @samp
2652 @item ignore-all
2653 Do not report any unresolved symbols.
2655 @item report-all
2656 Report all unresolved symbols.  This is the default.
2658 @item ignore-in-object-files
2659 Report unresolved symbols that are contained in shared libraries, but
2660 ignore them if they come from regular object files.
2662 @item ignore-in-shared-libs
2663 Report unresolved symbols that come from regular object files, but
2664 ignore them if they come from shared libraries.  This can be useful
2665 when creating a dynamic binary and it is known that all the shared
2666 libraries that it should be referencing are included on the linker's
2667 command line.
2668 @end table
2670 The behaviour for shared libraries on their own can also be controlled
2671 by the @option{--[no-]allow-shlib-undefined} option.
2673 Normally the linker will generate an error message for each reported
2674 unresolved symbol but the option @option{--warn-unresolved-symbols}
2675 can change this to a warning.
2677 @kindex --verbose[=@var{NUMBER}]
2678 @cindex verbose[=@var{NUMBER}]
2679 @item --dll-verbose
2680 @itemx --verbose[=@var{NUMBER}]
2681 Display the version number for @command{ld} and list the linker emulations
2682 supported.  Display which input files can and cannot be opened.  Display
2683 the linker script being used by the linker. If the optional @var{NUMBER}
2684 argument > 1, plugin symbol status will also be displayed.
2686 @kindex --version-script=@var{version-scriptfile}
2687 @cindex version script, symbol versions
2688 @item --version-script=@var{version-scriptfile}
2689 Specify the name of a version script to the linker.  This is typically
2690 used when creating shared libraries to specify additional information
2691 about the version hierarchy for the library being created.  This option
2692 is only fully supported on ELF platforms which support shared libraries;
2693 see @ref{VERSION}.  It is partially supported on PE platforms, which can
2694 use version scripts to filter symbol visibility in auto-export mode: any
2695 symbols marked @samp{local} in the version script will not be exported.
2696 @xref{WIN32}.
2698 @kindex --warn-common
2699 @cindex warnings, on combining symbols
2700 @cindex combining symbols, warnings on
2701 @item --warn-common
2702 Warn when a common symbol is combined with another common symbol or with
2703 a symbol definition.  Unix linkers allow this somewhat sloppy practice,
2704 but linkers on some other operating systems do not.  This option allows
2705 you to find potential problems from combining global symbols.
2706 Unfortunately, some C libraries use this practice, so you may get some
2707 warnings about symbols in the libraries as well as in your programs.
2709 There are three kinds of global symbols, illustrated here by C examples:
2711 @table @samp
2712 @item int i = 1;
2713 A definition, which goes in the initialized data section of the output
2714 file.
2716 @item extern int i;
2717 An undefined reference, which does not allocate space.
2718 There must be either a definition or a common symbol for the
2719 variable somewhere.
2721 @item int i;
2722 A common symbol.  If there are only (one or more) common symbols for a
2723 variable, it goes in the uninitialized data area of the output file.
2724 The linker merges multiple common symbols for the same variable into a
2725 single symbol.  If they are of different sizes, it picks the largest
2726 size.  The linker turns a common symbol into a declaration, if there is
2727 a definition of the same variable.
2728 @end table
2730 The @samp{--warn-common} option can produce five kinds of warnings.
2731 Each warning consists of a pair of lines: the first describes the symbol
2732 just encountered, and the second describes the previous symbol
2733 encountered with the same name.  One or both of the two symbols will be
2734 a common symbol.
2736 @enumerate
2737 @item
2738 Turning a common symbol into a reference, because there is already a
2739 definition for the symbol.
2740 @smallexample
2741 @var{file}(@var{section}): warning: common of `@var{symbol}'
2742    overridden by definition
2743 @var{file}(@var{section}): warning: defined here
2744 @end smallexample
2746 @item
2747 Turning a common symbol into a reference, because a later definition for
2748 the symbol is encountered.  This is the same as the previous case,
2749 except that the symbols are encountered in a different order.
2750 @smallexample
2751 @var{file}(@var{section}): warning: definition of `@var{symbol}'
2752    overriding common
2753 @var{file}(@var{section}): warning: common is here
2754 @end smallexample
2756 @item
2757 Merging a common symbol with a previous same-sized common symbol.
2758 @smallexample
2759 @var{file}(@var{section}): warning: multiple common
2760    of `@var{symbol}'
2761 @var{file}(@var{section}): warning: previous common is here
2762 @end smallexample
2764 @item
2765 Merging a common symbol with a previous larger common symbol.
2766 @smallexample
2767 @var{file}(@var{section}): warning: common of `@var{symbol}'
2768    overridden by larger common
2769 @var{file}(@var{section}): warning: larger common is here
2770 @end smallexample
2772 @item
2773 Merging a common symbol with a previous smaller common symbol.  This is
2774 the same as the previous case, except that the symbols are
2775 encountered in a different order.
2776 @smallexample
2777 @var{file}(@var{section}): warning: common of `@var{symbol}'
2778    overriding smaller common
2779 @var{file}(@var{section}): warning: smaller common is here
2780 @end smallexample
2781 @end enumerate
2783 @kindex --warn-constructors
2784 @item --warn-constructors
2785 Warn if any global constructors are used.  This is only useful for a few
2786 object file formats.  For formats like COFF or ELF, the linker can not
2787 detect the use of global constructors.
2789 @kindex --warn-execstack
2790 @cindex warnings, on executable stack
2791 @cindex executable stack, warnings on
2792 @item --warn-execstack
2793 @itemx --warn-execstack-objects
2794 @itemx --no-warn-execstack
2795 On ELF platforms the linker may generate warning messages if it is
2796 asked to create an output file that contains an executable stack.
2797 There are three possible states:
2798 @enumerate
2799 @item
2800 Do not generate any warnings.
2801 @item
2802 Always generate warnings, even if the executable stack is requested
2803 via the @option{-z execstack} command line option.
2804 @item
2805 Only generate a warning if an object file requests an executable
2806 stack, but not if the @option{-z execstack} option is used.
2807 @end enumerate
2809 The default state depends upon how the linker was configured when it
2810 was built.  The @option{--no-warn-execstack} option always puts the
2811 linker into the no-warnings state.  The @option{--warn-execstack}
2812 option puts the linker into the warn-always state.  The
2813 @option{--warn-execstack-objects} option puts the linker into the
2814 warn-for-object-files-only state.
2816 Note: ELF format input files can specify that they need an executable
2817 stack by having a @var{.note.GNU-stack} section with the executable
2818 bit set in its section flags.  They can specify that they do not need
2819 an executable stack by having the same section, but without the
2820 executable flag bit set.  If an input file does not have a
2821 @var{.note.GNU-stack} section then the default behaviour is target
2822 specific.  For some targets, then absence of such a section implies
2823 that an executable stack @emph{is} required.  This is often a problem
2824 for hand crafted assembler files.
2826 @kindex --error-execstack
2827 @item --error-execstack
2828 @itemx --no-error-execstack
2829 If the linker is going to generate a warning message about an
2830 executable stack then the @option{--error-execstack} option will
2831 instead change that warning into an error.  Note - this option does
2832 not change the linker's execstack warning generation state.  Use
2833 @option{--warn-execstack} or @option{--warn-execstack-objects} to set
2834 a specific warning state.
2836 The @option{--no-error-execstack} option will restore the default
2837 behaviour of generating warning messages.
2839 @kindex --warn-multiple-gp
2840 @item --warn-multiple-gp
2841 Warn if multiple global pointer values are required in the output file.
2842 This is only meaningful for certain processors, such as the Alpha.
2843 Specifically, some processors put large-valued constants in a special
2844 section.  A special register (the global pointer) points into the middle
2845 of this section, so that constants can be loaded efficiently via a
2846 base-register relative addressing mode.  Since the offset in
2847 base-register relative mode is fixed and relatively small (e.g., 16
2848 bits), this limits the maximum size of the constant pool.  Thus, in
2849 large programs, it is often necessary to use multiple global pointer
2850 values in order to be able to address all possible constants.  This
2851 option causes a warning to be issued whenever this case occurs.
2853 @kindex --warn-once
2854 @cindex warnings, on undefined symbols
2855 @cindex undefined symbols, warnings on
2856 @item --warn-once
2857 Only warn once for each undefined symbol, rather than once per module
2858 which refers to it.
2860 @kindex --warn-rwx-segments
2861 @cindex warnings, on writeable and exectuable segments
2862 @cindex executable segments, warnings on
2863 @item --warn-rwx-segments
2864 @itemx --no-warn-rwx-segments
2865 Warn if the linker creates a loadable, non-zero sized segment that has
2866 all three of the read, write and execute permission flags set.  Such a
2867 segment represents a potential security vulnerability.  In addition
2868 warnings will be generated if a thread local storage segment is
2869 created with the execute permission flag set, regardless of whether or
2870 not it has the read and/or write flags set.
2872 These warnings are enabled by default.  They can be disabled via the
2873 @option{--no-warn-rwx-segments} option and re-enabled via the
2874 @option{--warn-rwx-segments} option.
2876 @kindex --error-rwx-segments
2877 @item --error-rwx-segments
2878 @itemx --no-error-rwx-segments
2879 If the linker is going to generate a warning message about an
2880 executable, writeable segment, or an executable TLS segment, then the
2881 @option{--error-rwx-segments} option will turn this warning into an
2882 error instead.  The @option{--no-error-rwx-segments} option will
2883 restore the default behaviour of just generating a warning message.
2885 Note - the @option{--error-rwx-segments} option does not by itself
2886 turn on warnings about these segments.  These warnings are either
2887 enabled by default, if the linker was configured that way, or via the
2888 @option{--warn-rwx-segments} command line option.
2890 @kindex --warn-section-align
2891 @cindex warnings, on section alignment
2892 @cindex section alignment, warnings on
2893 @item --warn-section-align
2894 Warn if the address of an output section is changed because of
2895 alignment.  Typically, the alignment will be set by an input section.
2896 The address will only be changed if it not explicitly specified; that
2897 is, if the @code{SECTIONS} command does not specify a start address for
2898 the section (@pxref{SECTIONS}).
2900 @kindex --warn-textrel
2901 @item --warn-textrel
2902 Warn if the linker adds DT_TEXTREL to a position-independent executable
2903 or shared object.
2905 @kindex --warn-alternate-em
2906 @item --warn-alternate-em
2907 Warn if an object has alternate ELF machine code.
2909 @kindex --warn-unresolved-symbols
2910 @item --warn-unresolved-symbols
2911 If the linker is going to report an unresolved symbol (see the option
2912 @option{--unresolved-symbols}) it will normally generate an error.
2913 This option makes it generate a warning instead.
2915 @kindex --error-unresolved-symbols
2916 @item --error-unresolved-symbols
2917 This restores the linker's default behaviour of generating errors when
2918 it is reporting unresolved symbols.
2920 @kindex --whole-archive
2921 @cindex including an entire archive
2922 @item --whole-archive
2923 For each archive mentioned on the command line after the
2924 @option{--whole-archive} option, include every object file in the archive
2925 in the link, rather than searching the archive for the required object
2926 files.  This is normally used to turn an archive file into a shared
2927 library, forcing every object to be included in the resulting shared
2928 library.  This option may be used more than once.
2930 Two notes when using this option from gcc: First, gcc doesn't know
2931 about this option, so you have to use @option{-Wl,-whole-archive}.
2932 Second, don't forget to use @option{-Wl,-no-whole-archive} after your
2933 list of archives, because gcc will add its own list of archives to
2934 your link and you may not want this flag to affect those as well.
2936 @kindex --wrap=@var{symbol}
2937 @item --wrap=@var{symbol}
2938 Use a wrapper function for @var{symbol}.  Any undefined reference to
2939 @var{symbol} will be resolved to @code{__wrap_@var{symbol}}.  Any
2940 undefined reference to @code{__real_@var{symbol}} will be resolved to
2941 @var{symbol}.
2943 This can be used to provide a wrapper for a system function.  The
2944 wrapper function should be called @code{__wrap_@var{symbol}}.  If it
2945 wishes to call the system function, it should call
2946 @code{__real_@var{symbol}}.
2948 Here is a trivial example:
2950 @smallexample
2951 void *
2952 __wrap_malloc (size_t c)
2954   printf ("malloc called with %zu\n", c);
2955   return __real_malloc (c);
2957 @end smallexample
2959 If you link other code with this file using @option{--wrap malloc}, then
2960 all calls to @code{malloc} will call the function @code{__wrap_malloc}
2961 instead.  The call to @code{__real_malloc} in @code{__wrap_malloc} will
2962 call the real @code{malloc} function.
2964 You may wish to provide a @code{__real_malloc} function as well, so that
2965 links without the @option{--wrap} option will succeed.  If you do this,
2966 you should not put the definition of @code{__real_malloc} in the same
2967 file as @code{__wrap_malloc}; if you do, the assembler may resolve the
2968 call before the linker has a chance to wrap it to @code{malloc}.
2970 Only undefined references are replaced by the linker.  So, translation unit
2971 internal references to @var{symbol} are not resolved to
2972 @code{__wrap_@var{symbol}}.  In the next example, the call to @code{f} in
2973 @code{g} is not resolved to @code{__wrap_f}.
2975 @smallexample
2977 f (void)
2979   return 123;
2983 g (void)
2985   return f();
2987 @end smallexample
2989 @kindex --eh-frame-hdr
2990 @kindex --no-eh-frame-hdr
2991 @item --eh-frame-hdr
2992 @itemx --no-eh-frame-hdr
2993 Request (@option{--eh-frame-hdr}) or suppress
2994 (@option{--no-eh-frame-hdr}) the creation of @code{.eh_frame_hdr}
2995 section and ELF @code{PT_GNU_EH_FRAME} segment header.
2997 @kindex --ld-generated-unwind-info
2998 @item --no-ld-generated-unwind-info
2999 Request creation of @code{.eh_frame} unwind info for linker
3000 generated code sections like PLT.  This option is on by default
3001 if linker generated unwind info is supported.  This option also
3002 controls the generation of @code{.sframe} stack trace info for linker
3003 generated code sections like PLT.
3005 @kindex --enable-new-dtags
3006 @kindex --disable-new-dtags
3007 @item --enable-new-dtags
3008 @itemx --disable-new-dtags
3009 This linker can create the new dynamic tags in ELF. But the older ELF
3010 systems may not understand them. If you specify
3011 @option{--enable-new-dtags}, the new dynamic tags will be created as needed
3012 and older dynamic tags will be omitted.
3013 If you specify @option{--disable-new-dtags}, no new dynamic tags will be
3014 created. By default, the new dynamic tags are not created. Note that
3015 those options are only available for ELF systems.
3017 @kindex --hash-size=@var{number}
3018 @item --hash-size=@var{number}
3019 Set the default size of the linker's hash tables to a prime number
3020 close to @var{number}.  Increasing this value can reduce the length of
3021 time it takes the linker to perform its tasks, at the expense of
3022 increasing the linker's memory requirements.  Similarly reducing this
3023 value can reduce the memory requirements at the expense of speed.
3025 @kindex --hash-style=@var{style}
3026 @item --hash-style=@var{style}
3027 Set the type of linker's hash table(s).  @var{style} can be either
3028 @code{sysv} for classic ELF @code{.hash} section, @code{gnu} for
3029 new style GNU @code{.gnu.hash} section or @code{both} for both
3030 the classic ELF @code{.hash} and new style GNU @code{.gnu.hash}
3031 hash tables.  The default depends upon how the linker was configured,
3032 but for most Linux based systems it will be @code{both}.
3034 @kindex --compress-debug-sections=none
3035 @kindex --compress-debug-sections=zlib
3036 @kindex --compress-debug-sections=zlib-gnu
3037 @kindex --compress-debug-sections=zlib-gabi
3038 @kindex --compress-debug-sections=zstd
3039 @item --compress-debug-sections=none
3040 @itemx --compress-debug-sections=zlib
3041 @itemx --compress-debug-sections=zlib-gnu
3042 @itemx --compress-debug-sections=zlib-gabi
3043 @itemx --compress-debug-sections=zstd
3044 On ELF platforms, these options control how DWARF debug sections are
3045 compressed using zlib.
3047 @option{--compress-debug-sections=none} doesn't compress DWARF debug
3048 sections.  @option{--compress-debug-sections=zlib-gnu} compresses
3049 DWARF debug sections and renames them to begin with @samp{.zdebug}
3050 instead of @samp{.debug}.  @option{--compress-debug-sections=zlib-gabi}
3051 also compresses DWARF debug sections, but rather than renaming them it
3052 sets the SHF_COMPRESSED flag in the sections' headers.
3054 The @option{--compress-debug-sections=zlib} option is an alias for
3055 @option{--compress-debug-sections=zlib-gabi}.
3057 @option{--compress-debug-sections=zstd} compresses DWARF debug sections using
3058 zstd.
3060 Note that this option overrides any compression in input debug
3061 sections, so if a binary is linked with @option{--compress-debug-sections=none}
3062 for example, then any compressed debug sections in input files will be
3063 uncompressed before they are copied into the output binary.
3065 The default compression behaviour varies depending upon the target
3066 involved and the configure options used to build the toolchain.  The
3067 default can be determined by examining the output from the linker's
3068 @option{--help} option.
3070 @kindex --reduce-memory-overheads
3071 @item --reduce-memory-overheads
3072 This option reduces memory requirements at ld runtime, at the expense of
3073 linking speed.  This was introduced to select the old O(n^2) algorithm
3074 for link map file generation, rather than the new O(n) algorithm which uses
3075 about 40% more memory for symbol storage.
3077 Another effect of the switch is to set the default hash table size to
3078 1021, which again saves memory at the cost of lengthening the linker's
3079 run time.  This is not done however if the @option{--hash-size} switch
3080 has been used.
3082 The @option{--reduce-memory-overheads} switch may be also be used to
3083 enable other tradeoffs in future versions of the linker.
3085 @kindex --max-cache-size=@var{size}
3086 @item --max-cache-size=@var{size}
3087 @command{ld} normally caches the relocation information and symbol tables
3088 of input files in memory with the unlimited size.  This option sets the
3089 maximum cache size to @var{size}.
3091 @kindex --build-id
3092 @kindex --build-id=@var{style}
3093 @item --build-id
3094 @itemx --build-id=@var{style}
3095 Request the creation of a @code{.note.gnu.build-id} ELF note section
3096 or a @code{.buildid} COFF section.  The contents of the note are
3097 unique bits identifying this linked file.  @var{style} can be
3098 @code{uuid} to use 128 random bits, @code{sha1} to use a 160-bit
3099 @sc{SHA1} hash on the normative parts of the output contents,
3100 @code{md5} to use a 128-bit @sc{MD5} hash on the normative parts of
3101 the output contents, or @code{0x@var{hexstring}} to use a chosen bit
3102 string specified as an even number of hexadecimal digits (@code{-} and
3103 @code{:} characters between digit pairs are ignored).  If @var{style}
3104 is omitted, @code{sha1} is used.
3106 The @code{md5} and @code{sha1} styles produces an identifier
3107 that is always the same in an identical output file, but will be
3108 unique among all nonidentical output files.  It is not intended
3109 to be compared as a checksum for the file's contents.  A linked
3110 file may be changed later by other tools, but the build ID bit
3111 string identifying the original linked file does not change.
3113 Passing @code{none} for @var{style} disables the setting from any
3114 @code{--build-id} options earlier on the command line.
3116 @kindex --package-metadata=@var{JSON}
3117 @item --package-metadata=@var{JSON}
3118 Request the creation of a @code{.note.package} ELF note section.  The
3119 contents of the note are in JSON format, as per the package metadata
3120 specification.  For more information see:
3121 https://systemd.io/ELF_PACKAGE_METADATA/
3122 If the JSON argument is missing/empty then this will disable the
3123 creation of the metadata note, if one had been enabled by an earlier
3124 occurrence of the --package-metadata option.
3125 If the linker has been built with libjansson, then the JSON string
3126 will be validated.
3127 @end table
3129 @c man end
3131 @subsection Options Specific to i386 PE Targets
3133 @c man begin OPTIONS
3135 The i386 PE linker supports the @option{-shared} option, which causes
3136 the output to be a dynamically linked library (DLL) instead of a
3137 normal executable.  You should name the output @code{*.dll} when you
3138 use this option.  In addition, the linker fully supports the standard
3139 @code{*.def} files, which may be specified on the linker command line
3140 like an object file (in fact, it should precede archives it exports
3141 symbols from, to ensure that they get linked in, just like a normal
3142 object file).
3144 In addition to the options common to all targets, the i386 PE linker
3145 support additional command-line options that are specific to the i386
3146 PE target.  Options that take values may be separated from their
3147 values by either a space or an equals sign.
3149 @table @gcctabopt
3151 @kindex --add-stdcall-alias
3152 @item --add-stdcall-alias
3153 If given, symbols with a stdcall suffix (@@@var{nn}) will be exported
3154 as-is and also with the suffix stripped.
3155 [This option is specific to the i386 PE targeted port of the linker]
3157 @kindex --base-file
3158 @item --base-file @var{file}
3159 Use @var{file} as the name of a file in which to save the base
3160 addresses of all the relocations needed for generating DLLs with
3161 @file{dlltool}.
3162 [This is an i386 PE specific option]
3164 @kindex --dll
3165 @item --dll
3166 Create a DLL instead of a regular executable.  You may also use
3167 @option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
3168 file.
3169 [This option is specific to the i386 PE targeted port of the linker]
3171 @kindex --enable-long-section-names
3172 @kindex --disable-long-section-names
3173 @item --enable-long-section-names
3174 @itemx --disable-long-section-names
3175 The PE variants of the COFF object format add an extension that permits
3176 the use of section names longer than eight characters, the normal limit
3177 for COFF.  By default, these names are only allowed in object files, as
3178 fully-linked executable images do not carry the COFF string table required
3179 to support the longer names.  As a GNU extension, it is possible to
3180 allow their use in executable images as well, or to (probably pointlessly!)
3181 disallow it in object files, by using these two options.  Executable images
3182 generated with these long section names are slightly non-standard, carrying
3183 as they do a string table, and may generate confusing output when examined
3184 with non-GNU PE-aware tools, such as file viewers and dumpers.  However,
3185 GDB relies on the use of PE long section names to find Dwarf-2 debug
3186 information sections in an executable image at runtime, and so if neither
3187 option is specified on the command-line, @command{ld} will enable long
3188 section names, overriding the default and technically correct behaviour,
3189 when it finds the presence of debug information while linking an executable
3190 image and not stripping symbols.
3191 [This option is valid for all PE targeted ports of the linker]
3193 @kindex --enable-stdcall-fixup
3194 @kindex --disable-stdcall-fixup
3195 @item --enable-stdcall-fixup
3196 @itemx --disable-stdcall-fixup
3197 If the link finds a symbol that it cannot resolve, it will attempt to
3198 do ``fuzzy linking'' by looking for another defined symbol that differs
3199 only in the format of the symbol name (cdecl vs stdcall) and will
3200 resolve that symbol by linking to the match.  For example, the
3201 undefined symbol @code{_foo} might be linked to the function
3202 @code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
3203 to the function @code{_bar}.  When the linker does this, it prints a
3204 warning, since it normally should have failed to link, but sometimes
3205 import libraries generated from third-party dlls may need this feature
3206 to be usable.  If you specify @option{--enable-stdcall-fixup}, this
3207 feature is fully enabled and warnings are not printed.  If you specify
3208 @option{--disable-stdcall-fixup}, this feature is disabled and such
3209 mismatches are considered to be errors.
3210 [This option is specific to the i386 PE targeted port of the linker]
3212 @kindex --leading-underscore
3213 @kindex --no-leading-underscore
3214 @item --leading-underscore
3215 @itemx --no-leading-underscore
3216 For most targets default symbol-prefix is an underscore and is defined
3217 in target's description. By this option it is possible to
3218 disable/enable the default underscore symbol-prefix.
3220 @cindex DLLs, creating
3221 @kindex --export-all-symbols
3222 @item --export-all-symbols
3223 If given, all global symbols in the objects used to build a DLL will
3224 be exported by the DLL.  Note that this is the default if there
3225 otherwise wouldn't be any exported symbols.  When symbols are
3226 explicitly exported via DEF files or implicitly exported via function
3227 attributes, the default is to not export anything else unless this
3228 option is given.  Note that the symbols @code{DllMain@@12},
3229 @code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
3230 @code{impure_ptr} will not be automatically
3231 exported.  Also, symbols imported from other DLLs will not be
3232 re-exported, nor will symbols specifying the DLL's internal layout
3233 such as those beginning with @code{_head_} or ending with
3234 @code{_iname}.  In addition, no symbols from @code{libgcc},
3235 @code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
3236 Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will
3237 not be exported, to help with C++ DLLs.  Finally, there is an
3238 extensive list of cygwin-private symbols that are not exported
3239 (obviously, this applies on when building DLLs for cygwin targets).
3240 These cygwin-excludes are: @code{_cygwin_dll_entry@@12},
3241 @code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
3242 @code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
3243 @code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
3244 @code{cygwin_premain3}, and @code{environ}.
3245 [This option is specific to the i386 PE targeted port of the linker]
3247 @kindex --exclude-symbols
3248 @item --exclude-symbols @var{symbol},@var{symbol},...
3249 Specifies a list of symbols which should not be automatically
3250 exported.  The symbol names may be delimited by commas or colons.
3251 [This option is specific to the i386 PE targeted port of the linker]
3253 @kindex --exclude-all-symbols
3254 @item --exclude-all-symbols
3255 Specifies no symbols should be automatically exported.
3256 [This option is specific to the i386 PE targeted port of the linker]
3258 @kindex --file-alignment
3259 @item --file-alignment
3260 Specify the file alignment.  Sections in the file will always begin at
3261 file offsets which are multiples of this number.  This defaults to
3262 512.
3263 [This option is specific to the i386 PE targeted port of the linker]
3265 @cindex heap size
3266 @kindex --heap
3267 @item --heap @var{reserve}
3268 @itemx --heap @var{reserve},@var{commit}
3269 Specify the number of bytes of memory to reserve (and optionally commit)
3270 to be used as heap for this program.  The default is 1MB reserved, 4K
3271 committed.
3272 [This option is specific to the i386 PE targeted port of the linker]
3274 @cindex image base
3275 @kindex --image-base
3276 @item --image-base @var{value}
3277 Use @var{value} as the base address of your program or dll.  This is
3278 the lowest memory location that will be used when your program or dll
3279 is loaded.  To reduce the need to relocate and improve performance of
3280 your dlls, each should have a unique base address and not overlap any
3281 other dlls.  The default is 0x400000 for executables, and 0x10000000
3282 for dlls.
3283 [This option is specific to the i386 PE targeted port of the linker]
3285 @kindex --kill-at
3286 @item --kill-at
3287 If given, the stdcall suffixes (@@@var{nn}) will be stripped from
3288 symbols before they are exported.
3289 [This option is specific to the i386 PE targeted port of the linker]
3291 @kindex --large-address-aware
3292 @item --large-address-aware
3293 If given, the appropriate bit in the ``Characteristics'' field of the COFF
3294 header is set to indicate that this executable supports virtual addresses
3295 greater than 2 gigabytes.  This should be used in conjunction with the /3GB
3296 or /USERVA=@var{value} megabytes switch in the ``[operating systems]''
3297 section of the BOOT.INI.  Otherwise, this bit has no effect.
3298 [This option is specific to PE targeted ports of the linker]
3300 @kindex --disable-large-address-aware
3301 @item --disable-large-address-aware
3302 Reverts the effect of a previous @samp{--large-address-aware} option.
3303 This is useful if @samp{--large-address-aware} is always set by the compiler
3304 driver (e.g. Cygwin gcc) and the executable does not support virtual
3305 addresses greater than 2 gigabytes.
3306 [This option is specific to PE targeted ports of the linker]
3308 @kindex --major-image-version
3309 @item --major-image-version @var{value}
3310 Sets the major number of the ``image version''.  Defaults to 1.
3311 [This option is specific to the i386 PE targeted port of the linker]
3313 @kindex --major-os-version
3314 @item --major-os-version @var{value}
3315 Sets the major number of the ``os version''.  Defaults to 4.
3316 [This option is specific to the i386 PE targeted port of the linker]
3318 @kindex --major-subsystem-version
3319 @item --major-subsystem-version @var{value}
3320 Sets the major number of the ``subsystem version''.  Defaults to 4.
3321 [This option is specific to the i386 PE targeted port of the linker]
3323 @kindex --minor-image-version
3324 @item --minor-image-version @var{value}
3325 Sets the minor number of the ``image version''.  Defaults to 0.
3326 [This option is specific to the i386 PE targeted port of the linker]
3328 @kindex --minor-os-version
3329 @item --minor-os-version @var{value}
3330 Sets the minor number of the ``os version''.  Defaults to 0.
3331 [This option is specific to the i386 PE targeted port of the linker]
3333 @kindex --minor-subsystem-version
3334 @item --minor-subsystem-version @var{value}
3335 Sets the minor number of the ``subsystem version''.  Defaults to 0.
3336 [This option is specific to the i386 PE targeted port of the linker]
3338 @cindex DEF files, creating
3339 @cindex DLLs, creating
3340 @kindex --output-def
3341 @item --output-def @var{file}
3342 The linker will create the file @var{file} which will contain a DEF
3343 file corresponding to the DLL the linker is generating.  This DEF file
3344 (which should be called @code{*.def}) may be used to create an import
3345 library with @code{dlltool} or may be used as a reference to
3346 automatically or implicitly exported symbols.
3347 [This option is specific to the i386 PE targeted port of the linker]
3349 @cindex DLLs, creating
3350 @kindex --enable-auto-image-base
3351 @item --enable-auto-image-base
3352 @itemx --enable-auto-image-base=@var{value}
3353 Automatically choose the image base for DLLs, optionally starting with base
3354 @var{value}, unless one is specified using the @code{--image-base} argument.
3355 By using a hash generated from the dllname to create unique image bases
3356 for each DLL, in-memory collisions and relocations which can delay program
3357 execution are avoided.
3358 [This option is specific to the i386 PE targeted port of the linker]
3360 @kindex --disable-auto-image-base
3361 @item --disable-auto-image-base
3362 Do not automatically generate a unique image base.  If there is no
3363 user-specified image base (@code{--image-base}) then use the platform
3364 default.
3365 [This option is specific to the i386 PE targeted port of the linker]
3367 @cindex DLLs, linking to
3368 @kindex --dll-search-prefix
3369 @item --dll-search-prefix @var{string}
3370 When linking dynamically to a dll without an import library,
3371 search for @code{<string><basename>.dll} in preference to
3372 @code{lib<basename>.dll}. This behaviour allows easy distinction
3373 between DLLs built for the various "subplatforms": native, cygwin,
3374 uwin, pw, etc.  For instance, cygwin DLLs typically use
3375 @code{--dll-search-prefix=cyg}.
3376 [This option is specific to the i386 PE targeted port of the linker]
3378 @kindex --enable-auto-import
3379 @item --enable-auto-import
3380 Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
3381 DATA imports from DLLs, thus making it possible to bypass the dllimport
3382 mechanism on the user side and to reference unmangled symbol names.
3383 [This option is specific to the i386 PE targeted port of the linker]
3385 The following remarks pertain to the original implementation of the
3386 feature and are obsolete nowadays for Cygwin and MinGW targets.
3388 Note: Use of the 'auto-import' extension will cause the text section
3389 of the image file to be made writable. This does not conform to the
3390 PE-COFF format specification published by Microsoft.
3392 Note - use of the 'auto-import' extension will also cause read only
3393 data which would normally be placed into the .rdata section to be
3394 placed into the .data section instead.  This is in order to work
3395 around a problem with consts that is described here:
3396 http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
3398 Using 'auto-import' generally will 'just work' -- but sometimes you may
3399 see this message:
3401 "variable '<var>' can't be auto-imported. Please read the
3402 documentation for ld's @code{--enable-auto-import} for details."
3404 This message occurs when some (sub)expression accesses an address
3405 ultimately given by the sum of two constants (Win32 import tables only
3406 allow one).  Instances where this may occur include accesses to member
3407 fields of struct variables imported from a DLL, as well as using a
3408 constant index into an array variable imported from a DLL.  Any
3409 multiword variable (arrays, structs, long long, etc) may trigger
3410 this error condition.  However, regardless of the exact data type
3411 of the offending exported variable, ld will always detect it, issue
3412 the warning, and exit.
3414 There are several ways to address this difficulty, regardless of the
3415 data type of the exported variable:
3417 One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
3418 of adjusting references in your client code for runtime environment, so
3419 this method works only when runtime environment supports this feature.
3421 A second solution is to force one of the 'constants' to be a variable --
3422 that is, unknown and un-optimizable at compile time.  For arrays,
3423 there are two possibilities: a) make the indexee (the array's address)
3424 a variable, or b) make the 'constant' index a variable.  Thus:
3426 @example
3427 extern type extern_array[];
3428 extern_array[1] -->
3429    @{ volatile type *t=extern_array; t[1] @}
3430 @end example
3434 @example
3435 extern type extern_array[];
3436 extern_array[1] -->
3437    @{ volatile int t=1; extern_array[t] @}
3438 @end example
3440 For structs (and most other multiword data types) the only option
3441 is to make the struct itself (or the long long, or the ...) variable:
3443 @example
3444 extern struct s extern_struct;
3445 extern_struct.field -->
3446    @{ volatile struct s *t=&extern_struct; t->field @}
3447 @end example
3451 @example
3452 extern long long extern_ll;
3453 extern_ll -->
3454   @{ volatile long long * local_ll=&extern_ll; *local_ll @}
3455 @end example
3457 A third method of dealing with this difficulty is to abandon
3458 'auto-import' for the offending symbol and mark it with
3459 @code{__declspec(dllimport)}.  However, in practice that
3460 requires using compile-time #defines to indicate whether you are
3461 building a DLL, building client code that will link to the DLL, or
3462 merely building/linking to a static library.   In making the choice
3463 between the various methods of resolving the 'direct address with
3464 constant offset' problem, you should consider typical real-world usage:
3466 Original:
3467 @example
3468 --foo.h
3469 extern int arr[];
3470 --foo.c
3471 #include "foo.h"
3472 void main(int argc, char **argv)@{
3473   printf("%d\n",arr[1]);
3475 @end example
3477 Solution 1:
3478 @example
3479 --foo.h
3480 extern int arr[];
3481 --foo.c
3482 #include "foo.h"
3483 void main(int argc, char **argv)@{
3484   /* This workaround is for win32 and cygwin; do not "optimize" */
3485   volatile int *parr = arr;
3486   printf("%d\n",parr[1]);
3488 @end example
3490 Solution 2:
3491 @example
3492 --foo.h
3493 /* Note: auto-export is assumed (no __declspec(dllexport)) */
3494 #if (defined(_WIN32) || defined(__CYGWIN__)) && \
3495   !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
3496 #define FOO_IMPORT __declspec(dllimport)
3497 #else
3498 #define FOO_IMPORT
3499 #endif
3500 extern FOO_IMPORT int arr[];
3501 --foo.c
3502 #include "foo.h"
3503 void main(int argc, char **argv)@{
3504   printf("%d\n",arr[1]);
3506 @end example
3508 A fourth way to avoid this problem is to re-code your
3509 library to use a functional interface rather than a data interface
3510 for the offending variables (e.g. set_foo() and get_foo() accessor
3511 functions).
3513 @kindex --disable-auto-import
3514 @item --disable-auto-import
3515 Do not attempt to do sophisticated linking of @code{_symbol} to
3516 @code{__imp__symbol} for DATA imports from DLLs.
3517 [This option is specific to the i386 PE targeted port of the linker]
3519 @kindex --enable-runtime-pseudo-reloc
3520 @item --enable-runtime-pseudo-reloc
3521 If your code contains expressions described in --enable-auto-import section,
3522 that is, DATA imports from DLL with non-zero offset, this switch will create
3523 a vector of 'runtime pseudo relocations' which can be used by runtime
3524 environment to adjust references to such data in your client code.
3525 [This option is specific to the i386 PE targeted port of the linker]
3527 @kindex --disable-runtime-pseudo-reloc
3528 @item --disable-runtime-pseudo-reloc
3529 Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
3530 [This option is specific to the i386 PE targeted port of the linker]
3532 @kindex --enable-extra-pe-debug
3533 @item --enable-extra-pe-debug
3534 Show additional debug info related to auto-import symbol thunking.
3535 [This option is specific to the i386 PE targeted port of the linker]
3537 @kindex --section-alignment
3538 @item --section-alignment
3539 Sets the section alignment.  Sections in memory will always begin at
3540 addresses which are a multiple of this number.  Defaults to 0x1000.
3541 [This option is specific to the i386 PE targeted port of the linker]
3543 @cindex stack size
3544 @kindex --stack
3545 @item --stack @var{reserve}
3546 @itemx --stack @var{reserve},@var{commit}
3547 Specify the number of bytes of memory to reserve (and optionally commit)
3548 to be used as stack for this program.  The default is 2MB reserved, 4K
3549 committed.
3550 [This option is specific to the i386 PE targeted port of the linker]
3552 @kindex --subsystem
3553 @item --subsystem @var{which}
3554 @itemx --subsystem @var{which}:@var{major}
3555 @itemx --subsystem @var{which}:@var{major}.@var{minor}
3556 Specifies the subsystem under which your program will execute.  The
3557 legal values for @var{which} are @code{native}, @code{windows},
3558 @code{console}, @code{posix}, and @code{xbox}.  You may optionally set
3559 the subsystem version also.  Numeric values are also accepted for
3560 @var{which}.
3561 [This option is specific to the i386 PE targeted port of the linker]
3563 The following options set flags in the @code{DllCharacteristics} field
3564 of the PE file header:
3565 [These options are specific to PE targeted ports of the linker]
3567 @kindex --high-entropy-va
3568 @item --high-entropy-va
3569 @itemx --disable-high-entropy-va
3570 Image is compatible with 64-bit address space layout randomization
3571 (ASLR).  This option is enabled by default for 64-bit PE images.
3573 This option also implies @option{--dynamicbase} and
3574 @option{--enable-reloc-section}.
3576 @kindex --dynamicbase
3577 @item --dynamicbase
3578 @itemx --disable-dynamicbase
3579 The image base address may be relocated using address space layout
3580 randomization (ASLR).  This feature was introduced with MS Windows
3581 Vista for i386 PE targets.  This option is enabled by default but
3582 can be disabled via the @option{--disable-dynamicbase} option.
3583 This option also implies @option{--enable-reloc-section}.
3585 @kindex --forceinteg
3586 @item --forceinteg
3587 @itemx --disable-forceinteg
3588 Code integrity checks are enforced.  This option is disabled by
3589 default.
3591 @kindex --nxcompat
3592 @item --nxcompat
3593 @item --disable-nxcompat
3594 The image is compatible with the Data Execution Prevention.
3595 This feature was introduced with MS Windows XP SP2 for i386 PE
3596 targets.  The option is enabled by default.
3598 @kindex --no-isolation
3599 @item --no-isolation
3600 @itemx --disable-no-isolation
3601 Although the image understands isolation, do not isolate the image.
3602 This option is disabled by default.
3604 @kindex --no-seh
3605 @item --no-seh
3606 @itemx --disable-no-seh
3607 The image does not use SEH. No SE handler may be called from
3608 this image.  This option is disabled by default.
3610 @kindex --no-bind
3611 @item --no-bind
3612 @itemx --disable-no-bind
3613 Do not bind this image.  This option is disabled by default.
3615 @kindex --wdmdriver
3616 @item --wdmdriver
3617 @itemx --disable-wdmdriver
3618 The driver uses the MS Windows Driver Model.  This option is disabled
3619 by default.
3621 @kindex --tsaware
3622 @item --tsaware
3623 @itemx --disable-tsaware
3624 The image is Terminal Server aware.  This option is disabled by
3625 default.
3627 @kindex --insert-timestamp
3628 @item --insert-timestamp
3629 @itemx --no-insert-timestamp
3630 Insert a real timestamp into the image.  This is the default behaviour
3631 as it matches legacy code and it means that the image will work with
3632 other, proprietary tools.  The problem with this default is that it
3633 will result in slightly different images being produced each time the
3634 same sources are linked.  The option @option{--no-insert-timestamp}
3635 can be used to insert a zero value for the timestamp, this ensuring
3636 that binaries produced from identical sources will compare
3637 identically.
3639 If @option{--insert-timestamp} is active then the time inserted is
3640 either the time that the linking takes place or, if the
3641 @code{SOURCE_DATE_EPOCH} environment variable is defined, the number
3642 of seconds since Unix epoch as specified by that variable.
3644 @kindex --enable-reloc-section
3645 @item --enable-reloc-section
3646 @itemx --disable-reloc-section
3647 Create the base relocation table, which is necessary if the image
3648 is loaded at a different image base than specified in the PE header.
3649 This option is enabled by default.
3650 @end table
3652 @c man end
3654 @ifset C6X
3655 @subsection Options specific to C6X uClinux targets
3657 @c man begin OPTIONS
3659 The C6X uClinux target uses a binary format called DSBT to support shared
3660 libraries.  Each shared library in the system needs to have a unique index;
3661 all executables use an index of 0.
3663 @table @gcctabopt
3665 @kindex --dsbt-size
3666 @item --dsbt-size @var{size}
3667 This option sets the number of entries in the DSBT of the current executable
3668 or shared library to @var{size}.  The default is to create a table with 64
3669 entries.
3671 @kindex --dsbt-index
3672 @item --dsbt-index @var{index}
3673 This option sets the DSBT index of the current executable or shared library
3674 to @var{index}.  The default is 0, which is appropriate for generating
3675 executables.  If a shared library is generated with a DSBT index of 0, the
3676 @code{R_C6000_DSBT_INDEX} relocs are copied into the output file.
3678 @kindex --no-merge-exidx-entries
3679 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent
3680 exidx entries in frame unwind info.
3682 @end table
3684 @c man end
3685 @end ifset
3687 @ifset CSKY
3688 @subsection Options specific to C-SKY targets
3690 @c man begin OPTIONS
3692 @table @gcctabopt
3694 @kindex --branch-stub on C-SKY
3695 @item --branch-stub
3696 This option enables linker branch relaxation by inserting branch stub
3697 sections when needed to extend the range of branches.  This option is
3698 usually not required since C-SKY supports branch and call instructions that
3699 can access the full memory range and branch relaxation is normally handled by
3700 the compiler or assembler.
3702 @kindex --stub-group-size on C-SKY
3703 @item --stub-group-size=@var{N}
3704 This option allows finer control of linker branch stub creation.
3705 It sets the maximum size of a group of input sections that can
3706 be handled by one stub section.  A negative value of @var{N} locates
3707 stub sections after their branches, while a positive value allows stub
3708 sections to appear either before or after the branches.  Values of
3709 @samp{1} or @samp{-1} indicate that the
3710 linker should choose suitable defaults.
3712 @end table
3714 @c man end
3715 @end ifset
3717 @ifset M68HC11
3718 @subsection Options specific to Motorola 68HC11 and 68HC12 targets
3720 @c man begin OPTIONS
3722 The 68HC11 and 68HC12 linkers support specific options to control the
3723 memory bank switching mapping and trampoline code generation.
3725 @table @gcctabopt
3727 @kindex --no-trampoline
3728 @item --no-trampoline
3729 This option disables the generation of trampoline. By default a trampoline
3730 is generated for each far function which is called using a @code{jsr}
3731 instruction (this happens when a pointer to a far function is taken).
3733 @kindex --bank-window
3734 @item --bank-window @var{name}
3735 This option indicates to the linker the name of the memory region in
3736 the @samp{MEMORY} specification that describes the memory bank window.
3737 The definition of such region is then used by the linker to compute
3738 paging and addresses within the memory window.
3740 @end table
3742 @c man end
3743 @end ifset
3745 @ifset M68K
3746 @subsection Options specific to Motorola 68K target
3748 @c man begin OPTIONS
3750 The following options are supported to control handling of GOT generation
3751 when linking for 68K targets.
3753 @table @gcctabopt
3755 @kindex --got
3756 @item --got=@var{type}
3757 This option tells the linker which GOT generation scheme to use.
3758 @var{type} should be one of @samp{single}, @samp{negative},
3759 @samp{multigot} or @samp{target}.  For more information refer to the
3760 Info entry for @file{ld}.
3762 @end table
3764 @c man end
3765 @end ifset
3767 @ifset MIPS
3768 @subsection Options specific to MIPS targets
3770 @c man begin OPTIONS
3772 The following options are supported to control microMIPS instruction
3773 generation and branch relocation checks for ISA mode transitions when
3774 linking for MIPS targets.
3776 @table @gcctabopt
3778 @kindex --insn32
3779 @item --insn32
3780 @kindex --no-insn32
3781 @itemx --no-insn32
3782 These options control the choice of microMIPS instructions used in code
3783 generated by the linker, such as that in the PLT or lazy binding stubs,
3784 or in relaxation.  If @samp{--insn32} is used, then the linker only uses
3785 32-bit instruction encodings.  By default or if @samp{--no-insn32} is
3786 used, all instruction encodings are used, including 16-bit ones where
3787 possible.
3789 @kindex --ignore-branch-isa
3790 @item --ignore-branch-isa
3791 @kindex --no-ignore-branch-isa
3792 @itemx --no-ignore-branch-isa
3793 These options control branch relocation checks for invalid ISA mode
3794 transitions.  If @samp{--ignore-branch-isa} is used, then the linker
3795 accepts any branch relocations and any ISA mode transition required
3796 is lost in relocation calculation, except for some cases of @code{BAL}
3797 instructions which meet relaxation conditions and are converted to
3798 equivalent @code{JALX} instructions as the associated relocation is
3799 calculated.  By default or if @samp{--no-ignore-branch-isa} is used
3800 a check is made causing the loss of an ISA mode transition to produce
3801 an error.
3803 @kindex --compact-branches
3804 @item --compact-branches
3805 @kindex --no-compact-branches
3806 @itemx --no-compact-branches
3807 These options control the generation of compact instructions by the linker
3808 in the PLT entries for MIPS R6.
3810 @end table
3812 @c man end
3813 @end ifset
3816 @ifset PDP11
3817 @subsection Options specific to PDP11 targets
3819 @c man begin OPTIONS
3821 For the pdp11-aout target, three variants of the output format can be
3822 produced as selected by the following options.  The default variant
3823 for pdp11-aout is the @samp{--omagic} option, whereas for other
3824 targets @samp{--nmagic} is the default.  The @samp{--imagic} option is
3825 defined only for the pdp11-aout target, while the others are described
3826 here as they apply to the pdp11-aout target.
3828 @table @gcctabopt
3830 @kindex -N
3831 @item -N
3832 @kindex --omagic
3833 @itemx --omagic
3835 Mark the output as @code{OMAGIC} (0407) in the @file{a.out} header to
3836 indicate that the text segment is not to be write-protected and
3837 shared.  Since the text and data sections are both readable and
3838 writable, the data section is allocated immediately contiguous after
3839 the text segment.  This is the oldest format for PDP11 executable
3840 programs and is the default for @command{ld} on PDP11 Unix systems
3841 from the beginning through 2.11BSD.
3843 @kindex -n
3844 @item -n
3845 @kindex --nmagic
3846 @itemx --nmagic
3848 Mark the output as @code{NMAGIC} (0410) in the @file{a.out} header to
3849 indicate that when the output file is executed, the text portion will
3850 be read-only and shareable among all processes executing the same
3851 file.  This involves moving the data areas up to the first possible 8K
3852 byte page boundary following the end of the text.  This option creates
3853 a @emph{pure executable} format.
3855 @kindex -z
3856 @item -z
3857 @kindex --imagic
3858 @itemx --imagic
3860 Mark the output as @code{IMAGIC} (0411) in the @file{a.out} header to
3861 indicate that when the output file is executed, the program text and
3862 data areas will be loaded into separate address spaces using the split
3863 instruction and data space feature of the memory management unit in
3864 larger models of the PDP11.  This doubles the address space available
3865 to the program.  The text segment is again pure, write-protected, and
3866 shareable.  The only difference in the output format between this
3867 option and the others, besides the magic number, is that both the text
3868 and data sections start at location 0.  The @samp{-z} option selected
3869 this format in 2.11BSD.  This option creates a @emph{separate
3870 executable} format.
3872 @kindex --no-omagic
3873 @item --no-omagic
3875 Equivalent to @samp{--nmagic} for pdp11-aout.
3877 @end table
3879 @c man end
3880 @end ifset
3882 @ifset UsesEnvVars
3883 @node Environment
3884 @section Environment Variables
3886 @c man begin ENVIRONMENT
3888 You can change the behaviour of @command{ld} with the environment variables
3889 @ifclear SingleFormat
3890 @code{GNUTARGET},
3891 @end ifclear
3892 @code{LDEMULATION} and @code{COLLECT_NO_DEMANGLE}.
3894 @ifclear SingleFormat
3895 @kindex GNUTARGET
3896 @cindex default input format
3897 @code{GNUTARGET} determines the input-file object format if you don't
3898 use @samp{-b} (or its synonym @samp{--format}).  Its value should be one
3899 of the BFD names for an input format (@pxref{BFD}).  If there is no
3900 @code{GNUTARGET} in the environment, @command{ld} uses the natural format
3901 of the target. If @code{GNUTARGET} is set to @code{default} then BFD
3902 attempts to discover the input format by examining binary input files;
3903 this method often succeeds, but there are potential ambiguities, since
3904 there is no method of ensuring that the magic number used to specify
3905 object-file formats is unique.  However, the configuration procedure for
3906 BFD on each system places the conventional format for that system first
3907 in the search-list, so ambiguities are resolved in favor of convention.
3908 @end ifclear
3910 @kindex LDEMULATION
3911 @cindex default emulation
3912 @cindex emulation, default
3913 @code{LDEMULATION} determines the default emulation if you don't use the
3914 @samp{-m} option.  The emulation can affect various aspects of linker
3915 behaviour, particularly the default linker script.  You can list the
3916 available emulations with the @samp{--verbose} or @samp{-V} options.  If
3917 the @samp{-m} option is not used, and the @code{LDEMULATION} environment
3918 variable is not defined, the default emulation depends upon how the
3919 linker was configured.
3921 @kindex COLLECT_NO_DEMANGLE
3922 @cindex demangling, default
3923 Normally, the linker will default to demangling symbols.  However, if
3924 @code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
3925 default to not demangling symbols.  This environment variable is used in
3926 a similar fashion by the @code{gcc} linker wrapper program.  The default
3927 may be overridden by the @samp{--demangle} and @samp{--no-demangle}
3928 options.
3930 @c man end
3931 @end ifset
3933 @node Scripts
3934 @chapter Linker Scripts
3936 @cindex scripts
3937 @cindex linker scripts
3938 @cindex command files
3939 Every link is controlled by a @dfn{linker script}.  This script is
3940 written in the linker command language.
3942 The main purpose of the linker script is to describe how the sections in
3943 the input files should be mapped into the output file, and to control
3944 the memory layout of the output file.  Most linker scripts do nothing
3945 more than this.  However, when necessary, the linker script can also
3946 direct the linker to perform many other operations, using the commands
3947 described below.
3949 The linker always uses a linker script.  If you do not supply one
3950 yourself, the linker will use a default script that is compiled into the
3951 linker executable.  You can use the @samp{--verbose} command-line option
3952 to display the default linker script.  Certain command-line options,
3953 such as @samp{-r} or @samp{-N}, will affect the default linker script.
3955 You may supply your own linker script by using the @samp{-T} command
3956 line option.  When you do this, your linker script will replace the
3957 default linker script.
3959 You may also use linker scripts implicitly by naming them as input files
3960 to the linker, as though they were files to be linked.  @xref{Implicit
3961 Linker Scripts}.
3963 @menu
3964 * Basic Script Concepts::       Basic Linker Script Concepts
3965 * Script Format::               Linker Script Format
3966 * Simple Example::              Simple Linker Script Example
3967 * Simple Commands::             Simple Linker Script Commands
3968 * Assignments::                 Assigning Values to Symbols
3969 * SECTIONS::                    SECTIONS Command
3970 * MEMORY::                      MEMORY Command
3971 * PHDRS::                       PHDRS Command
3972 * VERSION::                     VERSION Command
3973 * Expressions::                 Expressions in Linker Scripts
3974 * Implicit Linker Scripts::     Implicit Linker Scripts
3975 @end menu
3977 @node Basic Script Concepts
3978 @section Basic Linker Script Concepts
3979 @cindex linker script concepts
3980 We need to define some basic concepts and vocabulary in order to
3981 describe the linker script language.
3983 The linker combines input files into a single output file.  The output
3984 file and each input file are in a special data format known as an
3985 @dfn{object file format}.  Each file is called an @dfn{object file}.
3986 The output file is often called an @dfn{executable}, but for our
3987 purposes we will also call it an object file.  Each object file has,
3988 among other things, a list of @dfn{sections}.  We sometimes refer to a
3989 section in an input file as an @dfn{input section}; similarly, a section
3990 in the output file is an @dfn{output section}.
3992 Each section in an object file has a name and a size.  Most sections
3993 also have an associated block of data, known as the @dfn{section
3994 contents}.  A section may be marked as @dfn{loadable}, which means that
3995 the contents should be loaded into memory when the output file is run.
3996 A section with no contents may be @dfn{allocatable}, which means that an
3997 area in memory should be set aside, but nothing in particular should be
3998 loaded there (in some cases this memory must be zeroed out).  A section
3999 which is neither loadable nor allocatable typically contains some sort
4000 of debugging information.
4002 Every loadable or allocatable output section has two addresses.  The
4003 first is the @dfn{VMA}, or virtual memory address.  This is the address
4004 the section will have when the output file is run.  The second is the
4005 @dfn{LMA}, or load memory address.  This is the address at which the
4006 section will be loaded.  In most cases the two addresses will be the
4007 same.  An example of when they might be different is when a data section
4008 is loaded into ROM, and then copied into RAM when the program starts up
4009 (this technique is often used to initialize global variables in a ROM
4010 based system).  In this case the ROM address would be the LMA, and the
4011 RAM address would be the VMA.
4013 You can see the sections in an object file by using the @code{objdump}
4014 program with the @samp{-h} option.
4016 Every object file also has a list of @dfn{symbols}, known as the
4017 @dfn{symbol table}.  A symbol may be defined or undefined.  Each symbol
4018 has a name, and each defined symbol has an address, among other
4019 information.  If you compile a C or C++ program into an object file, you
4020 will get a defined symbol for every defined function and global or
4021 static variable.  Every undefined function or global variable which is
4022 referenced in the input file will become an undefined symbol.
4024 You can see the symbols in an object file by using the @code{nm}
4025 program, or by using the @code{objdump} program with the @samp{-t}
4026 option.
4028 @node Script Format
4029 @section Linker Script Format
4030 @cindex linker script format
4031 Linker scripts are text files.
4033 You write a linker script as a series of commands.  Each command is
4034 either a keyword, possibly followed by arguments, or an assignment to a
4035 symbol.  You may separate commands using semicolons.  Whitespace is
4036 generally ignored.
4038 Strings such as file or format names can normally be entered directly.
4039 If the file name contains a character such as a comma which would
4040 otherwise serve to separate file names, you may put the file name in
4041 double quotes.  There is no way to use a double quote character in a
4042 file name.
4044 You may include comments in linker scripts just as in C, delimited by
4045 @samp{/*} and @samp{*/}.  As in C, comments are syntactically equivalent
4046 to whitespace.
4048 @node Simple Example
4049 @section Simple Linker Script Example
4050 @cindex linker script example
4051 @cindex example of linker script
4052 Many linker scripts are fairly simple.
4054 The simplest possible linker script has just one command:
4055 @samp{SECTIONS}.  You use the @samp{SECTIONS} command to describe the
4056 memory layout of the output file.
4058 The @samp{SECTIONS} command is a powerful command.  Here we will
4059 describe a simple use of it.  Let's assume your program consists only of
4060 code, initialized data, and uninitialized data.  These will be in the
4061 @samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
4062 Let's assume further that these are the only sections which appear in
4063 your input files.
4065 For this example, let's say that the code should be loaded at address
4066 0x10000, and that the data should start at address 0x8000000.  Here is a
4067 linker script which will do that:
4068 @smallexample
4069 SECTIONS
4071   . = 0x10000;
4072   .text : @{ *(.text) @}
4073   . = 0x8000000;
4074   .data : @{ *(.data) @}
4075   .bss : @{ *(.bss) @}
4077 @end smallexample
4079 You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
4080 followed by a series of symbol assignments and output section
4081 descriptions enclosed in curly braces.
4083 The first line inside the @samp{SECTIONS} command of the above example
4084 sets the value of the special symbol @samp{.}, which is the location
4085 counter.  If you do not specify the address of an output section in some
4086 other way (other ways are described later), the address is set from the
4087 current value of the location counter.  The location counter is then
4088 incremented by the size of the output section.  At the start of the
4089 @samp{SECTIONS} command, the location counter has the value @samp{0}.
4091 The second line defines an output section, @samp{.text}.  The colon is
4092 required syntax which may be ignored for now.  Within the curly braces
4093 after the output section name, you list the names of the input sections
4094 which should be placed into this output section.  The @samp{*} is a
4095 wildcard which matches any file name.  The expression @samp{*(.text)}
4096 means all @samp{.text} input sections in all input files.
4098 Since the location counter is @samp{0x10000} when the output section
4099 @samp{.text} is defined, the linker will set the address of the
4100 @samp{.text} section in the output file to be @samp{0x10000}.
4102 The remaining lines define the @samp{.data} and @samp{.bss} sections in
4103 the output file.  The linker will place the @samp{.data} output section
4104 at address @samp{0x8000000}.  After the linker places the @samp{.data}
4105 output section, the value of the location counter will be
4106 @samp{0x8000000} plus the size of the @samp{.data} output section.  The
4107 effect is that the linker will place the @samp{.bss} output section
4108 immediately after the @samp{.data} output section in memory.
4110 The linker will ensure that each output section has the required
4111 alignment, by increasing the location counter if necessary.  In this
4112 example, the specified addresses for the @samp{.text} and @samp{.data}
4113 sections will probably satisfy any alignment constraints, but the linker
4114 may have to create a small gap between the @samp{.data} and @samp{.bss}
4115 sections.
4117 That's it!  That's a simple and complete linker script.
4119 @node Simple Commands
4120 @section Simple Linker Script Commands
4121 @cindex linker script simple commands
4122 In this section we describe the simple linker script commands.
4124 @menu
4125 * Entry Point::                 Setting the entry point
4126 * File Commands::               Commands dealing with files
4127 @ifclear SingleFormat
4128 * Format Commands::             Commands dealing with object file formats
4129 @end ifclear
4131 * REGION_ALIAS::                Assign alias names to memory regions
4132 * Miscellaneous Commands::      Other linker script commands
4133 @end menu
4135 @node Entry Point
4136 @subsection Setting the Entry Point
4137 @kindex ENTRY(@var{symbol})
4138 @cindex start of execution
4139 @cindex first instruction
4140 @cindex entry point
4141 The first instruction to execute in a program is called the @dfn{entry
4142 point}.  You can use the @code{ENTRY} linker script command to set the
4143 entry point.  The argument is a symbol name:
4144 @smallexample
4145 ENTRY(@var{symbol})
4146 @end smallexample
4148 There are several ways to set the entry point.  The linker will set the
4149 entry point by trying each of the following methods in order, and
4150 stopping when one of them succeeds:
4151 @itemize @bullet
4152 @item
4153 the @samp{-e} @var{entry} command-line option;
4154 @item
4155 the @code{ENTRY(@var{symbol})} command in a linker script;
4156 @item
4157 the value of a target-specific symbol, if it is defined;  For many
4158 targets this is @code{start}, but PE- and BeOS-based systems for example
4159 check a list of possible entry symbols, matching the first one found.
4160 @item
4161 the address of the first byte of the code section, if present and an
4162 executable is being created - the code section is usually
4163 @samp{.text}, but can be something else;
4164 @item
4165 The address @code{0}.
4166 @end itemize
4168 @node File Commands
4169 @subsection Commands Dealing with Files
4170 @cindex linker script file commands
4171 Several linker script commands deal with files.
4173 @table @code
4174 @item INCLUDE @var{filename}
4175 @kindex INCLUDE @var{filename}
4176 @cindex including a linker script
4177 Include the linker script @var{filename} at this point.  The file will
4178 be searched for in the current directory, and in any directory specified
4179 with the @option{-L} option.  You can nest calls to @code{INCLUDE} up to
4180 10 levels deep.
4182 You can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or
4183 @code{SECTIONS} commands, or in output section descriptions.
4185 @item INPUT(@var{file}, @var{file}, @dots{})
4186 @itemx INPUT(@var{file} @var{file} @dots{})
4187 @kindex INPUT(@var{files})
4188 @cindex input files in linker scripts
4189 @cindex input object files in linker scripts
4190 @cindex linker script input object files
4191 The @code{INPUT} command directs the linker to include the named files
4192 in the link, as though they were named on the command line.
4194 For example, if you always want to include @file{subr.o} any time you do
4195 a link, but you can't be bothered to put it on every link command line,
4196 then you can put @samp{INPUT (subr.o)} in your linker script.
4198 In fact, if you like, you can list all of your input files in the linker
4199 script, and then invoke the linker with nothing but a @samp{-T} option.
4201 In case a @dfn{sysroot prefix} is configured, and the filename starts
4202 with the @samp{/} character, and the script being processed was
4203 located inside the @dfn{sysroot prefix}, the filename will be looked
4204 for in the @dfn{sysroot prefix}.  The @dfn{sysroot prefix} can also be forced by specifying
4205 @code{=} as the first character in the filename path, or prefixing the
4206 filename path with @code{$SYSROOT}. See also the description of
4207 @samp{-L} in @ref{Options,,Command-line Options}.
4209 If a @dfn{sysroot prefix} is not used then the linker will try to open
4210 the file in the directory containing the linker script.  If it is not
4211 found the linker will then search the current directory.  If it is still
4212 not found the linker will search through the archive library search
4213 path.
4215 If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
4216 name to @code{lib@var{file}.a}, as with the command-line argument
4217 @samp{-l}.
4219 When you use the @code{INPUT} command in an implicit linker script, the
4220 files will be included in the link at the point at which the linker
4221 script file is included.  This can affect archive searching.
4223 @item GROUP(@var{file}, @var{file}, @dots{})
4224 @itemx GROUP(@var{file} @var{file} @dots{})
4225 @kindex GROUP(@var{files})
4226 @cindex grouping input files
4227 The @code{GROUP} command is like @code{INPUT}, except that the named
4228 files should all be archives, and they are searched repeatedly until no
4229 new undefined references are created.  See the description of @samp{-(}
4230 in @ref{Options,,Command-line Options}.
4232 @item AS_NEEDED(@var{file}, @var{file}, @dots{})
4233 @itemx AS_NEEDED(@var{file} @var{file} @dots{})
4234 @kindex AS_NEEDED(@var{files})
4235 This construct can appear only inside of the @code{INPUT} or @code{GROUP}
4236 commands, among other filenames.  The files listed will be handled
4237 as if they appear directly in the @code{INPUT} or @code{GROUP} commands,
4238 with the exception of ELF shared libraries, that will be added only
4239 when they are actually needed.  This construct essentially enables
4240 @option{--as-needed} option for all the files listed inside of it
4241 and restores previous @option{--as-needed} resp. @option{--no-as-needed}
4242 setting afterwards.
4244 @item OUTPUT(@var{filename})
4245 @kindex OUTPUT(@var{filename})
4246 @cindex output file name in linker script
4247 The @code{OUTPUT} command names the output file.  Using
4248 @code{OUTPUT(@var{filename})} in the linker script is exactly like using
4249 @samp{-o @var{filename}} on the command line (@pxref{Options,,Command
4250 Line Options}).  If both are used, the command-line option takes
4251 precedence.
4253 You can use the @code{OUTPUT} command to define a default name for the
4254 output file other than the usual default of @file{a.out}.
4256 @item SEARCH_DIR(@var{path})
4257 @kindex SEARCH_DIR(@var{path})
4258 @cindex library search path in linker script
4259 @cindex archive search path in linker script
4260 @cindex search path in linker script
4261 The @code{SEARCH_DIR} command adds @var{path} to the list of paths where
4262 @command{ld} looks for archive libraries.  Using
4263 @code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
4264 on the command line (@pxref{Options,,Command-line Options}).  If both
4265 are used, then the linker will search both paths.  Paths specified using
4266 the command-line option are searched first.
4268 @item STARTUP(@var{filename})
4269 @kindex STARTUP(@var{filename})
4270 @cindex first input file
4271 The @code{STARTUP} command is just like the @code{INPUT} command, except
4272 that @var{filename} will become the first input file to be linked, as
4273 though it were specified first on the command line.  This may be useful
4274 when using a system in which the entry point is always the start of the
4275 first file.
4276 @end table
4278 @ifclear SingleFormat
4279 @node Format Commands
4280 @subsection Commands Dealing with Object File Formats
4281 A couple of linker script commands deal with object file formats.
4283 @table @code
4284 @item OUTPUT_FORMAT(@var{bfdname})
4285 @itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
4286 @kindex OUTPUT_FORMAT(@var{bfdname})
4287 @cindex output file format in linker script
4288 The @code{OUTPUT_FORMAT} command names the BFD format to use for the
4289 output file (@pxref{BFD}).  Using @code{OUTPUT_FORMAT(@var{bfdname})} is
4290 exactly like using @samp{--oformat @var{bfdname}} on the command line
4291 (@pxref{Options,,Command-line Options}).  If both are used, the command
4292 line option takes precedence.
4294 You can use @code{OUTPUT_FORMAT} with three arguments to use different
4295 formats based on the @samp{-EB} and @samp{-EL} command-line options.
4296 This permits the linker script to set the output format based on the
4297 desired endianness.
4299 If neither @samp{-EB} nor @samp{-EL} are used, then the output format
4300 will be the first argument, @var{default}.  If @samp{-EB} is used, the
4301 output format will be the second argument, @var{big}.  If @samp{-EL} is
4302 used, the output format will be the third argument, @var{little}.
4304 For example, the default linker script for the MIPS ELF target uses this
4305 command:
4306 @smallexample
4307 OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
4308 @end smallexample
4309 This says that the default format for the output file is
4310 @samp{elf32-bigmips}, but if the user uses the @samp{-EL} command-line
4311 option, the output file will be created in the @samp{elf32-littlemips}
4312 format.
4314 @item TARGET(@var{bfdname})
4315 @kindex TARGET(@var{bfdname})
4316 @cindex input file format in linker script
4317 The @code{TARGET} command names the BFD format to use when reading input
4318 files.  It affects subsequent @code{INPUT} and @code{GROUP} commands.
4319 This command is like using @samp{-b @var{bfdname}} on the command line
4320 (@pxref{Options,,Command-line Options}).  If the @code{TARGET} command
4321 is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
4322 command is also used to set the format for the output file.  @xref{BFD}.
4323 @end table
4324 @end ifclear
4326 @node REGION_ALIAS
4327 @subsection Assign alias names to memory regions
4328 @kindex REGION_ALIAS(@var{alias}, @var{region})
4329 @cindex region alias
4330 @cindex region names
4332 Alias names can be added to existing memory regions created with the
4333 @ref{MEMORY} command.  Each name corresponds to at most one memory region.
4335 @smallexample
4336 REGION_ALIAS(@var{alias}, @var{region})
4337 @end smallexample
4339 The @code{REGION_ALIAS} function creates an alias name @var{alias} for the
4340 memory region @var{region}.  This allows a flexible mapping of output sections
4341 to memory regions.  An example follows.
4343 Suppose we have an application for embedded systems which come with various
4344 memory storage devices.  All have a general purpose, volatile memory @code{RAM}
4345 that allows code execution or data storage.  Some may have a read-only,
4346 non-volatile memory @code{ROM} that allows code execution and read-only data
4347 access.  The last variant is a read-only, non-volatile memory @code{ROM2} with
4348 read-only data access and no code execution capability.  We have four output
4349 sections:
4351 @itemize @bullet
4352 @item
4353 @code{.text} program code;
4354 @item
4355 @code{.rodata} read-only data;
4356 @item
4357 @code{.data} read-write initialized data;
4358 @item
4359 @code{.bss} read-write zero initialized data.
4360 @end itemize
4362 The goal is to provide a linker command file that contains a system independent
4363 part defining the output sections and a system dependent part mapping the
4364 output sections to the memory regions available on the system.  Our embedded
4365 systems come with three different memory setups @code{A}, @code{B} and
4366 @code{C}:
4367 @multitable @columnfractions .25 .25 .25 .25
4368 @item Section @tab Variant A @tab Variant B @tab Variant C
4369 @item .text @tab RAM @tab ROM @tab ROM
4370 @item .rodata @tab RAM @tab ROM @tab ROM2
4371 @item .data @tab RAM @tab RAM/ROM @tab RAM/ROM2
4372 @item .bss @tab RAM @tab RAM @tab RAM
4373 @end multitable
4374 The notation @code{RAM/ROM} or @code{RAM/ROM2} means that this section is
4375 loaded into region @code{ROM} or @code{ROM2} respectively.  Please note that
4376 the load address of the @code{.data} section starts in all three variants at
4377 the end of the @code{.rodata} section.
4379 The base linker script that deals with the output sections follows.  It
4380 includes the system dependent @code{linkcmds.memory} file that describes the
4381 memory layout:
4382 @smallexample
4383 INCLUDE linkcmds.memory
4385 SECTIONS
4386   @{
4387     .text :
4388       @{
4389         *(.text)
4390       @} > REGION_TEXT
4391     .rodata :
4392       @{
4393         *(.rodata)
4394         rodata_end = .;
4395       @} > REGION_RODATA
4396     .data : AT (rodata_end)
4397       @{
4398         data_start = .;
4399         *(.data)
4400       @} > REGION_DATA
4401     data_size = SIZEOF(.data);
4402     data_load_start = LOADADDR(.data);
4403     .bss :
4404       @{
4405         *(.bss)
4406       @} > REGION_BSS
4407   @}
4408 @end smallexample
4410 Now we need three different @code{linkcmds.memory} files to define memory
4411 regions and alias names.  The content of @code{linkcmds.memory} for the three
4412 variants @code{A}, @code{B} and @code{C}:
4413 @table @code
4414 @item A
4415 Here everything goes into the @code{RAM}.
4416 @smallexample
4417 MEMORY
4418   @{
4419     RAM : ORIGIN = 0, LENGTH = 4M
4420   @}
4422 REGION_ALIAS("REGION_TEXT", RAM);
4423 REGION_ALIAS("REGION_RODATA", RAM);
4424 REGION_ALIAS("REGION_DATA", RAM);
4425 REGION_ALIAS("REGION_BSS", RAM);
4426 @end smallexample
4427 @item B
4428 Program code and read-only data go into the @code{ROM}.  Read-write data goes
4429 into the @code{RAM}.  An image of the initialized data is loaded into the
4430 @code{ROM} and will be copied during system start into the @code{RAM}.
4431 @smallexample
4432 MEMORY
4433   @{
4434     ROM : ORIGIN = 0, LENGTH = 3M
4435     RAM : ORIGIN = 0x10000000, LENGTH = 1M
4436   @}
4438 REGION_ALIAS("REGION_TEXT", ROM);
4439 REGION_ALIAS("REGION_RODATA", ROM);
4440 REGION_ALIAS("REGION_DATA", RAM);
4441 REGION_ALIAS("REGION_BSS", RAM);
4442 @end smallexample
4443 @item C
4444 Program code goes into the @code{ROM}.  Read-only data goes into the
4445 @code{ROM2}.  Read-write data goes into the @code{RAM}.  An image of the
4446 initialized data is loaded into the @code{ROM2} and will be copied during
4447 system start into the @code{RAM}.
4448 @smallexample
4449 MEMORY
4450   @{
4451     ROM : ORIGIN = 0, LENGTH = 2M
4452     ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
4453     RAM : ORIGIN = 0x20000000, LENGTH = 1M
4454   @}
4456 REGION_ALIAS("REGION_TEXT", ROM);
4457 REGION_ALIAS("REGION_RODATA", ROM2);
4458 REGION_ALIAS("REGION_DATA", RAM);
4459 REGION_ALIAS("REGION_BSS", RAM);
4460 @end smallexample
4461 @end table
4463 It is possible to write a common system initialization routine to copy the
4464 @code{.data} section from @code{ROM} or @code{ROM2} into the @code{RAM} if
4465 necessary:
4466 @smallexample
4467 #include <string.h>
4469 extern char data_start [];
4470 extern char data_size [];
4471 extern char data_load_start [];
4473 void copy_data(void)
4475   if (data_start != data_load_start)
4476     @{
4477       memcpy(data_start, data_load_start, (size_t) data_size);
4478     @}
4480 @end smallexample
4482 @node Miscellaneous Commands
4483 @subsection Other Linker Script Commands
4484 There are a few other linker scripts commands.
4486 @table @code
4487 @item ASSERT(@var{exp}, @var{message})
4488 @kindex ASSERT
4489 @cindex assertion in linker script
4490 Ensure that @var{exp} is non-zero.  If it is zero, then exit the linker
4491 with an error code, and print @var{message}.
4493 Note that assertions are checked before the final stages of linking
4494 take place.  This means that expressions involving symbols PROVIDEd
4495 inside section definitions will fail if the user has not set values
4496 for those symbols.  The only exception to this rule is PROVIDEd
4497 symbols that just reference dot.  Thus an assertion like this:
4499 @smallexample
4500   .stack :
4501   @{
4502     PROVIDE (__stack = .);
4503     PROVIDE (__stack_size = 0x100);
4504     ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4505   @}
4506 @end smallexample
4508 will fail if @code{__stack_size} is not defined elsewhere.  Symbols
4509 PROVIDEd outside of section definitions are evaluated earlier, so they
4510 can be used inside ASSERTions.  Thus:
4512 @smallexample
4513   PROVIDE (__stack_size = 0x100);
4514   .stack :
4515   @{
4516     PROVIDE (__stack = .);
4517     ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
4518   @}
4519 @end smallexample
4521 will work.
4523 @item EXTERN(@var{symbol} @var{symbol} @dots{})
4524 @kindex EXTERN
4525 @cindex undefined symbol in linker script
4526 Force @var{symbol} to be entered in the output file as an undefined
4527 symbol.  Doing this may, for example, trigger linking of additional
4528 modules from standard libraries.  You may list several @var{symbol}s for
4529 each @code{EXTERN}, and you may use @code{EXTERN} multiple times.  This
4530 command has the same effect as the @samp{-u} command-line option.
4532 @item FORCE_COMMON_ALLOCATION
4533 @kindex FORCE_COMMON_ALLOCATION
4534 @cindex common allocation in linker script
4535 This command has the same effect as the @samp{-d} command-line option:
4536 to make @command{ld} assign space to common symbols even if a relocatable
4537 output file is specified (@samp{-r}).
4539 @item INHIBIT_COMMON_ALLOCATION
4540 @kindex INHIBIT_COMMON_ALLOCATION
4541 @cindex common allocation in linker script
4542 This command has the same effect as the @samp{--no-define-common}
4543 command-line option: to make @code{ld} omit the assignment of addresses
4544 to common symbols even for a non-relocatable output file.
4546 @item FORCE_GROUP_ALLOCATION
4547 @kindex FORCE_GROUP_ALLOCATION
4548 @cindex group allocation in linker script
4549 @cindex section groups
4550 @cindex COMDAT
4551 This command has the same effect as the
4552 @samp{--force-group-allocation} command-line option: to make
4553 @command{ld} place section group members like normal input sections,
4554 and to delete the section groups even if a relocatable output file is
4555 specified (@samp{-r}).
4557 @item INSERT [ AFTER | BEFORE ] @var{output_section}
4558 @kindex INSERT
4559 @cindex insert user script into default script
4560 This command is typically used in a script specified by @samp{-T} to
4561 augment the default @code{SECTIONS} with, for example, overlays.  It
4562 inserts all prior linker script statements after (or before)
4563 @var{output_section}, and also causes @samp{-T} to not override the
4564 default linker script.  The exact insertion point is as for orphan
4565 sections.  @xref{Location Counter}.  The insertion happens after the
4566 linker has mapped input sections to output sections.  Prior to the
4567 insertion, since @samp{-T} scripts are parsed before the default
4568 linker script, statements in the @samp{-T} script occur before the
4569 default linker script statements in the internal linker representation
4570 of the script.  In particular, input section assignments will be made
4571 to @samp{-T} output sections before those in the default script.  Here
4572 is an example of how a @samp{-T} script using @code{INSERT} might look:
4574 @smallexample
4575 SECTIONS
4577   OVERLAY :
4578   @{
4579     .ov1 @{ ov1*(.text) @}
4580     .ov2 @{ ov2*(.text) @}
4581   @}
4583 INSERT AFTER .text;
4584 @end smallexample
4586 Note that when @samp{-T} is used twice, once to override the default
4587 script and once to augment that script using @code{INSERT} the order
4588 of parsing and section assignments apply as for the default script.
4589 The script with @code{INSERT} should be specified @emph{first} on the
4590 command line.
4592 @item NOCROSSREFS(@var{section} @var{section} @dots{})
4593 @kindex NOCROSSREFS(@var{sections})
4594 @cindex cross references
4595 This command may be used to tell @command{ld} to issue an error about any
4596 references among certain output sections.
4598 In certain types of programs, particularly on embedded systems when
4599 using overlays, when one section is loaded into memory, another section
4600 will not be.  Any direct references between the two sections would be
4601 errors.  For example, it would be an error if code in one section called
4602 a function defined in the other section.
4604 The @code{NOCROSSREFS} command takes a list of output section names.  If
4605 @command{ld} detects any cross references between the sections, it reports
4606 an error and returns a non-zero exit status.  Note that the
4607 @code{NOCROSSREFS} command uses output section names, not input section
4608 names.
4610 @item NOCROSSREFS_TO(@var{tosection} @var{fromsection} @dots{})
4611 @kindex NOCROSSREFS_TO(@var{tosection} @var{fromsections})
4612 @cindex cross references
4613 This command may be used to tell @command{ld} to issue an error about any
4614 references to one section from a list of other sections.
4616 The @code{NOCROSSREFS} command is useful when ensuring that two or more
4617 output sections are entirely independent but there are situations where
4618 a one-way dependency is needed. For example, in a multi-core application
4619 there may be shared code that can be called from each core but for safety
4620 must never call back.
4622 The @code{NOCROSSREFS_TO} command takes a list of output section names.
4623 The first section can not be referenced from any of the other sections.
4624 If @command{ld} detects any references to the first section from any of
4625 the other sections, it reports an error and returns a non-zero exit
4626 status.  Note that the @code{NOCROSSREFS_TO} command uses output section
4627 names, not input section names.
4629 @ifclear SingleFormat
4630 @item OUTPUT_ARCH(@var{bfdarch})
4631 @kindex OUTPUT_ARCH(@var{bfdarch})
4632 @cindex machine architecture
4633 @cindex architecture
4634 Specify a particular output machine architecture.  The argument is one
4635 of the names used by the BFD library (@pxref{BFD}).  You can see the
4636 architecture of an object file by using the @code{objdump} program with
4637 the @samp{-f} option.
4638 @end ifclear
4640 @item LD_FEATURE(@var{string})
4641 @kindex LD_FEATURE(@var{string})
4642 This command may be used to modify @command{ld} behavior.  If
4643 @var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
4644 in a script are simply treated as numbers everywhere.
4645 @xref{Expression Section}.
4646 @end table
4648 @node Assignments
4649 @section Assigning Values to Symbols
4650 @cindex assignment in scripts
4651 @cindex symbol definition, scripts
4652 @cindex variables, defining
4653 You may assign a value to a symbol in a linker script.  This will define
4654 the symbol and place it into the symbol table with a global scope.
4656 @menu
4657 * Simple Assignments::          Simple Assignments
4658 * HIDDEN::                      HIDDEN
4659 * PROVIDE::                     PROVIDE
4660 * PROVIDE_HIDDEN::              PROVIDE_HIDDEN
4661 * Source Code Reference::       How to use a linker script defined symbol in source code
4662 @end menu
4664 @node Simple Assignments
4665 @subsection Simple Assignments
4667 You may assign to a symbol using any of the C assignment operators:
4669 @table @code
4670 @item @var{symbol} = @var{expression} ;
4671 @itemx @var{symbol} += @var{expression} ;
4672 @itemx @var{symbol} -= @var{expression} ;
4673 @itemx @var{symbol} *= @var{expression} ;
4674 @itemx @var{symbol} /= @var{expression} ;
4675 @itemx @var{symbol} <<= @var{expression} ;
4676 @itemx @var{symbol} >>= @var{expression} ;
4677 @itemx @var{symbol} &= @var{expression} ;
4678 @itemx @var{symbol} |= @var{expression} ;
4679 @end table
4681 The first case will define @var{symbol} to the value of
4682 @var{expression}.  In the other cases, @var{symbol} must already be
4683 defined, and the value will be adjusted accordingly.
4685 The special symbol name @samp{.} indicates the location counter.  You
4686 may only use this within a @code{SECTIONS} command.  @xref{Location Counter}.
4688 The semicolon after @var{expression} is required.
4690 Expressions are defined below; see @ref{Expressions}.
4692 You may write symbol assignments as commands in their own right, or as
4693 statements within a @code{SECTIONS} command, or as part of an output
4694 section description in a @code{SECTIONS} command.
4696 The section of the symbol will be set from the section of the
4697 expression; for more information, see @ref{Expression Section}.
4699 Here is an example showing the three different places that symbol
4700 assignments may be used:
4702 @smallexample
4703 floating_point = 0;
4704 SECTIONS
4706   .text :
4707     @{
4708       *(.text)
4709       _etext = .;
4710     @}
4711   _bdata = (. + 3) & ~ 3;
4712   .data : @{ *(.data) @}
4714 @end smallexample
4715 @noindent
4716 In this example, the symbol @samp{floating_point} will be defined as
4717 zero.  The symbol @samp{_etext} will be defined as the address following
4718 the last @samp{.text} input section.  The symbol @samp{_bdata} will be
4719 defined as the address following the @samp{.text} output section aligned
4720 upward to a 4 byte boundary.
4722 @node HIDDEN
4723 @subsection HIDDEN
4724 @cindex HIDDEN
4725 For ELF targeted ports, define a symbol that will be hidden and won't be
4726 exported.  The syntax is @code{HIDDEN(@var{symbol} = @var{expression})}.
4728 Here is the example from @ref{Simple Assignments}, rewritten to use
4729 @code{HIDDEN}:
4731 @smallexample
4732 HIDDEN(floating_point = 0);
4733 SECTIONS
4735   .text :
4736     @{
4737       *(.text)
4738       HIDDEN(_etext = .);
4739     @}
4740   HIDDEN(_bdata = (. + 3) & ~ 3);
4741   .data : @{ *(.data) @}
4743 @end smallexample
4744 @noindent
4745 In this case none of the three symbols will be visible outside this module.
4747 @node PROVIDE
4748 @subsection PROVIDE
4749 @cindex PROVIDE
4750 In some cases, it is desirable for a linker script to define a symbol
4751 only if it is referenced and is not defined by any object included in
4752 the link.  For example, traditional linkers defined the symbol
4753 @samp{etext}.  However, ANSI C requires that the user be able to use
4754 @samp{etext} as a function name without encountering an error.  The
4755 @code{PROVIDE} keyword may be used to define a symbol, such as
4756 @samp{etext}, only if it is referenced but not defined.  The syntax is
4757 @code{PROVIDE(@var{symbol} = @var{expression})}.
4759 Here is an example of using @code{PROVIDE} to define @samp{etext}:
4760 @smallexample
4761 SECTIONS
4763   .text :
4764     @{
4765       *(.text)
4766       _etext = .;
4767       PROVIDE(etext = .);
4768     @}
4770 @end smallexample
4772 In this example, if the program defines @samp{_etext} (with a leading
4773 underscore), the linker will give a multiple definition diagnostic.  If,
4774 on the other hand, the program defines @samp{etext} (with no leading
4775 underscore), the linker will silently use the definition in the program.
4776 If the program references @samp{etext} but does not define it, the
4777 linker will use the definition in the linker script.
4779 Note - the @code{PROVIDE} directive considers a common symbol to be
4780 defined, even though such a symbol could be combined with the symbol
4781 that the @code{PROVIDE} would create.  This is particularly important
4782 when considering constructor and destructor list symbols such as
4783 @samp{__CTOR_LIST__} as these are often defined as common symbols.
4785 @node PROVIDE_HIDDEN
4786 @subsection PROVIDE_HIDDEN
4787 @cindex PROVIDE_HIDDEN
4788 Similar to @code{PROVIDE}.  For ELF targeted ports, the symbol will be
4789 hidden and won't be exported.
4791 @node Source Code Reference
4792 @subsection Source Code Reference
4794 Accessing a linker script defined variable from source code is not
4795 intuitive.  In particular a linker script symbol is not equivalent to
4796 a variable declaration in a high level language, it is instead a
4797 symbol that does not have a value.
4799 Before going further, it is important to note that compilers often
4800 transform names in the source code into different names when they are
4801 stored in the symbol table.  For example, Fortran compilers commonly
4802 prepend or append an underscore, and C++ performs extensive @samp{name
4803 mangling}.  Therefore there might be a discrepancy between the name
4804 of a variable as it is used in source code and the name of the same
4805 variable as it is defined in a linker script.  For example in C a
4806 linker script variable might be referred to as:
4808 @smallexample
4809   extern int foo;
4810 @end smallexample
4812 But in the linker script it might be defined as:
4814 @smallexample
4815   _foo = 1000;
4816 @end smallexample
4818 In the remaining examples however it is assumed that no name
4819 transformation has taken place.
4821 When a symbol is declared in a high level language such as C, two
4822 things happen.  The first is that the compiler reserves enough space
4823 in the program's memory to hold the @emph{value} of the symbol.  The
4824 second is that the compiler creates an entry in the program's symbol
4825 table which holds the symbol's @emph{address}.  ie the symbol table
4826 contains the address of the block of memory holding the symbol's
4827 value.  So for example the following C declaration, at file scope:
4829 @smallexample
4830   int foo = 1000;
4831 @end smallexample
4833 creates an entry called @samp{foo} in the symbol table.  This entry
4834 holds the address of an @samp{int} sized block of memory where the
4835 number 1000 is initially stored.
4837 When a program references a symbol the compiler generates code that
4838 first accesses the symbol table to find the address of the symbol's
4839 memory block and then code to read the value from that memory block.
4842 @smallexample
4843   foo = 1;
4844 @end smallexample
4846 looks up the symbol @samp{foo} in the symbol table, gets the address
4847 associated with this symbol and then writes the value 1 into that
4848 address.  Whereas:
4850 @smallexample
4851   int * a = & foo;
4852 @end smallexample
4854 looks up the symbol @samp{foo} in the symbol table, gets its address
4855 and then copies this address into the block of memory associated with
4856 the variable @samp{a}.
4858 Linker scripts symbol declarations, by contrast, create an entry in
4859 the symbol table but do not assign any memory to them.  Thus they are
4860 an address without a value.  So for example the linker script definition:
4862 @smallexample
4863   foo = 1000;
4864 @end smallexample
4866 creates an entry in the symbol table called @samp{foo} which holds
4867 the address of memory location 1000, but nothing special is stored at
4868 address 1000.  This means that you cannot access the @emph{value} of a
4869 linker script defined symbol - it has no value - all you can do is
4870 access the @emph{address} of a linker script defined symbol.
4872 Hence when you are using a linker script defined symbol in source code
4873 you should always take the address of the symbol, and never attempt to
4874 use its value.  For example suppose you want to copy the contents of a
4875 section of memory called .ROM into a section called .FLASH and the
4876 linker script contains these declarations:
4878 @smallexample
4879 @group
4880   start_of_ROM   = .ROM;
4881   end_of_ROM     = .ROM + sizeof (.ROM);
4882   start_of_FLASH = .FLASH;
4883 @end group
4884 @end smallexample
4886 Then the C source code to perform the copy would be:
4888 @smallexample
4889 @group
4890   extern char start_of_ROM, end_of_ROM, start_of_FLASH;
4892   memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
4893 @end group
4894 @end smallexample
4896 Note the use of the @samp{&} operators.  These are correct.
4897 Alternatively the symbols can be treated as the names of vectors or
4898 arrays and then the code will again work as expected:
4900 @smallexample
4901 @group
4902   extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
4904   memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
4905 @end group
4906 @end smallexample
4908 Note how using this method does not require the use of @samp{&}
4909 operators.
4911 @node SECTIONS
4912 @section SECTIONS Command
4913 @kindex SECTIONS
4914 The @code{SECTIONS} command tells the linker how to map input sections
4915 into output sections, and how to place the output sections in memory.
4917 The format of the @code{SECTIONS} command is:
4918 @smallexample
4919 SECTIONS
4921   @var{sections-command}
4922   @var{sections-command}
4923   @dots{}
4925 @end smallexample
4927 Each @var{sections-command} may of be one of the following:
4929 @itemize @bullet
4930 @item
4931 an @code{ENTRY} command (@pxref{Entry Point,,Entry command})
4932 @item
4933 a symbol assignment (@pxref{Assignments})
4934 @item
4935 an output section description
4936 @item
4937 an overlay description
4938 @end itemize
4940 The @code{ENTRY} command and symbol assignments are permitted inside the
4941 @code{SECTIONS} command for convenience in using the location counter in
4942 those commands.  This can also make the linker script easier to
4943 understand because you can use those commands at meaningful points in
4944 the layout of the output file.
4946 Output section descriptions and overlay descriptions are described
4947 below.
4949 If you do not use a @code{SECTIONS} command in your linker script, the
4950 linker will place each input section into an identically named output
4951 section in the order that the sections are first encountered in the
4952 input files.  If all input sections are present in the first file, for
4953 example, the order of sections in the output file will match the order
4954 in the first input file.  The first section will be at address zero.
4956 @menu
4957 * Output Section Description::  Output section description
4958 * Output Section Name::         Output section name
4959 * Output Section Address::      Output section address
4960 * Input Section::               Input section description
4961 * Output Section Data::         Output section data
4962 * Output Section Keywords::     Output section keywords
4963 * Output Section Discarding::   Output section discarding
4964 * Output Section Attributes::   Output section attributes
4965 * Overlay Description::         Overlay description
4966 @end menu
4968 @node Output Section Description
4969 @subsection Output Section Description
4970 The full description of an output section looks like this:
4971 @smallexample
4972 @group
4973 @var{section} [@var{address}] [(@var{type})] :
4974   [AT(@var{lma})]
4975   [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
4976   [SUBALIGN(@var{subsection_align})]
4977   [@var{constraint}]
4978   @{
4979     @var{output-section-command}
4980     @var{output-section-command}
4981     @dots{}
4982   @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] [,]
4983 @end group
4984 @end smallexample
4986 Most output sections do not use most of the optional section attributes.
4988 The whitespace around @var{section} is required, so that the section
4989 name is unambiguous.  The colon and the curly braces are also required.
4990 The comma at the end may be required if a @var{fillexp} is used and
4991 the next @var{sections-command} looks like a continuation of the expression.
4992 The line breaks and other white space are optional.
4994 Each @var{output-section-command} may be one of the following:
4996 @itemize @bullet
4997 @item
4998 a symbol assignment (@pxref{Assignments})
4999 @item
5000 an input section description (@pxref{Input Section})
5001 @item
5002 data values to include directly (@pxref{Output Section Data})
5003 @item
5004 a special output section keyword (@pxref{Output Section Keywords})
5005 @end itemize
5007 @node Output Section Name
5008 @subsection Output Section Name
5009 @cindex name, section
5010 @cindex section name
5011 The name of the output section is @var{section}.  @var{section} must
5012 meet the constraints of your output format.  In formats which only
5013 support a limited number of sections, such as @code{a.out}, the name
5014 must be one of the names supported by the format (@code{a.out}, for
5015 example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
5016 output format supports any number of sections, but with numbers and not
5017 names (as is the case for Oasys), the name should be supplied as a
5018 quoted numeric string.  A section name may consist of any sequence of
5019 characters, but a name which contains any unusual characters such as
5020 commas must be quoted.
5022 The output section name @samp{/DISCARD/} is special; @ref{Output Section
5023 Discarding}.
5025 @node Output Section Address
5026 @subsection Output Section Address
5027 @cindex address, section
5028 @cindex section address
5029 The @var{address} is an expression for the VMA (the virtual memory
5030 address) of the output section.  This address is optional, but if it
5031 is provided then the output address will be set exactly as specified.
5033 If the output address is not specified then one will be chosen for the
5034 section, based on the heuristic below.  This address will be adjusted
5035 to fit the alignment requirement of the output section.  The
5036 alignment requirement is the strictest alignment of any input section
5037 contained within the output section.
5039 The output section address heuristic is as follows:
5041 @itemize @bullet
5042 @item
5043 If an output memory @var{region} is set for the section then it
5044 is added to this region and its address will be the next free address
5045 in that region.
5047 @item
5048 If the MEMORY command has been used to create a list of memory
5049 regions then the first region which has attributes compatible with the
5050 section is selected to contain it.  The section's output address will
5051 be the next free address in that region; @ref{MEMORY}.
5053 @item
5054 If no memory regions were specified, or none match the section then
5055 the output address will be based on the current value of the location
5056 counter.
5057 @end itemize
5059 @noindent
5060 For example:
5062 @smallexample
5063 .text . : @{ *(.text) @}
5064 @end smallexample
5066 @noindent
5069 @smallexample
5070 .text : @{ *(.text) @}
5071 @end smallexample
5073 @noindent
5074 are subtly different.  The first will set the address of the
5075 @samp{.text} output section to the current value of the location
5076 counter.  The second will set it to the current value of the location
5077 counter aligned to the strictest alignment of any of the @samp{.text}
5078 input sections.
5080 The @var{address} may be an arbitrary expression; @ref{Expressions}.
5081 For example, if you want to align the section on a 0x10 byte boundary,
5082 so that the lowest four bits of the section address are zero, you could
5083 do something like this:
5084 @smallexample
5085 .text ALIGN(0x10) : @{ *(.text) @}
5086 @end smallexample
5087 @noindent
5088 This works because @code{ALIGN} returns the current location counter
5089 aligned upward to the specified value.
5091 Specifying @var{address} for a section will change the value of the
5092 location counter, provided that the section is non-empty.  (Empty
5093 sections are ignored).
5095 @node Input Section
5096 @subsection Input Section Description
5097 @cindex input sections
5098 @cindex mapping input sections to output sections
5099 The most common output section command is an input section description.
5101 The input section description is the most basic linker script operation.
5102 You use output sections to tell the linker how to lay out your program
5103 in memory.  You use input section descriptions to tell the linker how to
5104 map the input files into your memory layout.
5106 @menu
5107 * Input Section Basics::        Input section basics
5108 * Input Section Wildcards::     Input section wildcard patterns
5109 * Input Section Common::        Input section for common symbols
5110 * Input Section Keep::          Input section and garbage collection
5111 * Input Section Example::       Input section example
5112 @end menu
5114 @node Input Section Basics
5115 @subsubsection Input Section Basics
5116 @cindex input section basics
5117 An input section description consists of a file name optionally followed
5118 by a list of section names in parentheses.
5120 The file name and the section name may be wildcard patterns, which we
5121 describe further below (@pxref{Input Section Wildcards}).
5123 The most common input section description is to include all input
5124 sections with a particular name in the output section.  For example, to
5125 include all input @samp{.text} sections, you would write:
5126 @smallexample
5127 *(.text)
5128 @end smallexample
5129 @noindent
5130 Here the @samp{*} is a wildcard which matches any file name.  To exclude a list
5131 @cindex EXCLUDE_FILE
5132 of files from matching the file name wildcard, EXCLUDE_FILE may be used to
5133 match all files except the ones specified in the EXCLUDE_FILE list.  For
5134 example:
5135 @smallexample
5136 EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
5137 @end smallexample
5138 @noindent
5139 will cause all .ctors sections from all files except @file{crtend.o}
5140 and @file{otherfile.o} to be included.  The EXCLUDE_FILE can also be
5141 placed inside the section list, for example:
5142 @smallexample
5143 *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
5144 @end smallexample
5145 @noindent
5146 The result of this is identically to the previous example.  Supporting
5147 two syntaxes for EXCLUDE_FILE is useful if the section list contains
5148 more than one section, as described below.
5150 There are two ways to include more than one section:
5151 @smallexample
5152 *(.text .rdata)
5153 *(.text) *(.rdata)
5154 @end smallexample
5155 @noindent
5156 The difference between these is the order in which the @samp{.text} and
5157 @samp{.rdata} input sections will appear in the output section.  In the
5158 first example, they will be intermingled, appearing in the same order as
5159 they are found in the linker input.  In the second example, all
5160 @samp{.text} input sections will appear first, followed by all
5161 @samp{.rdata} input sections.
5163 When using EXCLUDE_FILE with more than one section, if the exclusion
5164 is within the section list then the exclusion only applies to the
5165 immediately following section, for example:
5166 @smallexample
5167 *(EXCLUDE_FILE (*somefile.o) .text .rdata)
5168 @end smallexample
5169 @noindent
5170 will cause all @samp{.text} sections from all files except
5171 @file{somefile.o} to be included, while all @samp{.rdata} sections
5172 from all files, including @file{somefile.o}, will be included.  To
5173 exclude the @samp{.rdata} sections from @file{somefile.o} the example
5174 could be modified to:
5175 @smallexample
5176 *(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
5177 @end smallexample
5178 @noindent
5179 Alternatively, placing the EXCLUDE_FILE outside of the section list,
5180 before the input file selection, will cause the exclusion to apply for
5181 all sections.  Thus the previous example can be rewritten as:
5182 @smallexample
5183 EXCLUDE_FILE (*somefile.o) *(.text .rdata)
5184 @end smallexample
5186 You can specify a file name to include sections from a particular file.
5187 You would do this if one or more of your files contain special data that
5188 needs to be at a particular location in memory.  For example:
5189 @smallexample
5190 data.o(.data)
5191 @end smallexample
5193 To refine the sections that are included based on the section flags
5194 of an input section, INPUT_SECTION_FLAGS may be used.
5196 Here is a simple example for using Section header flags for ELF sections:
5198 @smallexample
5199 @group
5200 SECTIONS @{
5201   .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @}
5202   .text2 :  @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @}
5204 @end group
5205 @end smallexample
5207 In this example, the output section @samp{.text} will be comprised of any
5208 input section matching the name *(.text) whose section header flags
5209 @code{SHF_MERGE} and @code{SHF_STRINGS} are set.  The output section
5210 @samp{.text2} will be comprised of any input section matching the name *(.text)
5211 whose section header flag @code{SHF_WRITE} is clear.
5213 You can also specify files within archives by writing a pattern
5214 matching the archive, a colon, then the pattern matching the file,
5215 with no whitespace around the colon.
5217 @table @samp
5218 @item archive:file
5219 matches file within archive
5220 @item archive:
5221 matches the whole archive
5222 @item :file
5223 matches file but not one in an archive
5224 @end table
5226 Either one or both of @samp{archive} and @samp{file} can contain shell
5227 wildcards.  On DOS based file systems, the linker will assume that a
5228 single letter followed by a colon is a drive specifier, so
5229 @samp{c:myfile.o} is a simple file specification, not @samp{myfile.o}
5230 within an archive called @samp{c}.  @samp{archive:file} filespecs may
5231 also be used within an @code{EXCLUDE_FILE} list, but may not appear in
5232 other linker script contexts.  For instance, you cannot extract a file
5233 from an archive by using @samp{archive:file} in an @code{INPUT}
5234 command.
5236 If you use a file name without a list of sections, then all sections in
5237 the input file will be included in the output section.  This is not
5238 commonly done, but it may by useful on occasion.  For example:
5239 @smallexample
5240 data.o
5241 @end smallexample
5243 When you use a file name which is not an @samp{archive:file} specifier
5244 and does not contain any wild card
5245 characters, the linker will first see if you also specified the file
5246 name on the linker command line or in an @code{INPUT} command.  If you
5247 did not, the linker will attempt to open the file as an input file, as
5248 though it appeared on the command line.  Note that this differs from an
5249 @code{INPUT} command, because the linker will not search for the file in
5250 the archive search path.
5252 @node Input Section Wildcards
5253 @subsubsection Input Section Wildcard Patterns
5254 @cindex input section wildcards
5255 @cindex wildcard file name patterns
5256 @cindex file name wildcard patterns
5257 @cindex section name wildcard patterns
5258 In an input section description, either the file name or the section
5259 name or both may be wildcard patterns.
5261 The file name of @samp{*} seen in many examples is a simple wildcard
5262 pattern for the file name.
5264 The wildcard patterns are like those used by the Unix shell.
5266 @table @samp
5267 @item *
5268 matches any number of characters
5269 @item ?
5270 matches any single character
5271 @item [@var{chars}]
5272 matches a single instance of any of the @var{chars}; the @samp{-}
5273 character may be used to specify a range of characters, as in
5274 @samp{[a-z]} to match any lower case letter
5275 @item \
5276 quotes the following character
5277 @end table
5279 File name wildcard patterns only match files which are explicitly
5280 specified on the command line or in an @code{INPUT} command.  The linker
5281 does not search directories to expand wildcards.
5283 If a file name matches more than one wildcard pattern, or if a file name
5284 appears explicitly and is also matched by a wildcard pattern, the linker
5285 will use the first match in the linker script.  For example, this
5286 sequence of input section descriptions is probably in error, because the
5287 @file{data.o} rule will not be used:
5288 @smallexample
5289 .data : @{ *(.data) @}
5290 .data1 : @{ data.o(.data) @}
5291 @end smallexample
5293 @cindex SORT_BY_NAME
5294 Normally, the linker will place files and sections matched by wildcards
5295 in the order in which they are seen during the link.  You can change
5296 this by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
5297 pattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}).  When the
5298 @code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
5299 into ascending order by name before placing them in the output file.
5301 @cindex SORT_BY_ALIGNMENT
5302 @code{SORT_BY_ALIGNMENT} is similar to @code{SORT_BY_NAME}.
5303 @code{SORT_BY_ALIGNMENT} will sort sections into descending order of
5304 alignment before placing them in the output file.  Placing larger
5305 alignments before smaller alignments can reduce the amount of padding
5306 needed.
5308 @cindex SORT_BY_INIT_PRIORITY
5309 @code{SORT_BY_INIT_PRIORITY} is also similar to @code{SORT_BY_NAME}.
5310 @code{SORT_BY_INIT_PRIORITY} will sort sections into ascending
5311 numerical order of the GCC init_priority attribute encoded in the
5312 section name before placing them in the output file.  In
5313 @code{.init_array.NNNNN} and @code{.fini_array.NNNNN}, @code{NNNNN} is
5314 the init_priority.  In @code{.ctors.NNNNN} and @code{.dtors.NNNNN},
5315 @code{NNNNN} is 65535 minus the init_priority.
5317 @cindex SORT
5318 @code{SORT} is an alias for @code{SORT_BY_NAME}.
5320 @cindex REVERSE
5321 @code{REVERSE} indicates that the sorting should be reversed.  If used
5322 on its own then @code{REVERSE} implies @code{SORT_BY_NAME}, otherwise
5323 it reverses the enclosed @code{SORT..} command.  Note - reverse
5324 sorting of alignment is not currently supported.
5326 Note - the sorting commands only accept a single wildcard pattern.  So
5327 for example the following will not work:
5328 @smallexample
5329   *(REVERSE(.text* .init*))
5330 @end smallexample
5331 To resolve this problem list the patterns individually, like this:
5332 @smallexample
5333   *(REVERSE(.text*))
5334   *(REVERSE(.init*))
5335 @end smallexample
5337 Note - you can put the @code{EXCLUDE_FILE} command inside a sorting
5338 command, but not the other way around.  So for example:
5339 @smallexample
5340   *(SORT_BY_NAME(EXCLUDE_FILE(foo) .text*))
5341 @end smallexample
5342 will work, but:
5343 @smallexample
5344   *(EXCLUDE_FILE(foo) SORT_BY_NAME(.text*))
5345 @end smallexample
5346 will not.
5349 When there are nested section sorting commands in linker script, there
5350 can be at most 1 level of nesting for section sorting commands.
5352 @enumerate
5353 @item
5354 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5355 It will sort the input sections by name first, then by alignment if two
5356 sections have the same name.
5357 @item
5358 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5359 It will sort the input sections by alignment first, then by name if two
5360 sections have the same alignment.
5361 @item
5362 @code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is
5363 treated the same as @code{SORT_BY_NAME} (wildcard section pattern).
5364 @item
5365 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
5366 is treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
5367 @item
5368 @code{SORT_BY_NAME} (@code{REVERSE} (wildcard section pattern))
5369 reverse sorts by name.
5370 @item
5371 @code{REVERSE} (@code{SORT_BY_NAME} (wildcard section pattern))
5372 reverse sorts by name.
5373 @item
5374 @code{SORT_BY_INIT_PRIORITY} (@code{REVERSE} (wildcard section pattern))
5375 reverse sorts by init priority.
5376 @item
5377 All other nested section sorting commands are invalid.
5378 @end enumerate
5380 When both command-line section sorting option and linker script
5381 section sorting command are used, section sorting command always
5382 takes precedence over the command-line option.
5384 If the section sorting command in linker script isn't nested, the
5385 command-line option will make the section sorting command to be
5386 treated as nested sorting command.
5388 @enumerate
5389 @item
5390 @code{SORT_BY_NAME} (wildcard section pattern ) with
5391 @option{--sort-sections alignment} is equivalent to
5392 @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
5393 @item
5394 @code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
5395 @option{--sort-section name} is equivalent to
5396 @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
5397 @end enumerate
5399 If the section sorting command in linker script is nested, the
5400 command-line option will be ignored.
5402 @cindex SORT_NONE
5403 @code{SORT_NONE} disables section sorting by ignoring the command-line
5404 section sorting option.
5406 If you ever get confused about where input sections are going, use the
5407 @samp{-M} linker option to generate a map file.  The map file shows
5408 precisely how input sections are mapped to output sections.
5410 This example shows how wildcard patterns might be used to partition
5411 files.  This linker script directs the linker to place all @samp{.text}
5412 sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
5413 The linker will place the @samp{.data} section from all files beginning
5414 with an upper case character in @samp{.DATA}; for all other files, the
5415 linker will place the @samp{.data} section in @samp{.data}.
5416 @smallexample
5417 @group
5418 SECTIONS @{
5419   .text : @{ *(.text) @}
5420   .DATA : @{ [A-Z]*(.data) @}
5421   .data : @{ *(.data) @}
5422   .bss : @{ *(.bss) @}
5424 @end group
5425 @end smallexample
5427 @node Input Section Common
5428 @subsubsection Input Section for Common Symbols
5429 @cindex common symbol placement
5430 @cindex uninitialized data placement
5431 A special notation is needed for common symbols, because in many object
5432 file formats common symbols do not have a particular input section.  The
5433 linker treats common symbols as though they are in an input section
5434 named @samp{COMMON}.
5436 You may use file names with the @samp{COMMON} section just as with any
5437 other input sections.  You can use this to place common symbols from a
5438 particular input file in one section while common symbols from other
5439 input files are placed in another section.
5441 In most cases, common symbols in input files will be placed in the
5442 @samp{.bss} section in the output file.  For example:
5443 @smallexample
5444 .bss @{ *(.bss) *(COMMON) @}
5445 @end smallexample
5447 @cindex scommon section
5448 @cindex small common symbols
5449 Some object file formats have more than one type of common symbol.  For
5450 example, the MIPS ELF object file format distinguishes standard common
5451 symbols and small common symbols.  In this case, the linker will use a
5452 different special section name for other types of common symbols.  In
5453 the case of MIPS ELF, the linker uses @samp{COMMON} for standard common
5454 symbols and @samp{.scommon} for small common symbols.  This permits you
5455 to map the different types of common symbols into memory at different
5456 locations.
5458 @cindex [COMMON]
5459 You will sometimes see @samp{[COMMON]} in old linker scripts.  This
5460 notation is now considered obsolete.  It is equivalent to
5461 @samp{*(COMMON)}.
5463 @node Input Section Keep
5464 @subsubsection Input Section and Garbage Collection
5465 @cindex KEEP
5466 @cindex garbage collection
5467 When link-time garbage collection is in use (@samp{--gc-sections}),
5468 it is often useful to mark sections that should not be eliminated.
5469 This is accomplished by surrounding an input section's wildcard entry
5470 with @code{KEEP()}, as in @code{KEEP(*(.init))} or
5471 @code{KEEP(SORT_BY_NAME(*)(.ctors))}.
5473 @node Input Section Example
5474 @subsubsection Input Section Example
5475 The following example is a complete linker script.  It tells the linker
5476 to read all of the sections from file @file{all.o} and place them at the
5477 start of output section @samp{outputa} which starts at location
5478 @samp{0x10000}.  All of section @samp{.input1} from file @file{foo.o}
5479 follows immediately, in the same output section.  All of section
5480 @samp{.input2} from @file{foo.o} goes into output section
5481 @samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
5482 All of the remaining @samp{.input1} and @samp{.input2} sections from any
5483 files are written to output section @samp{outputc}.
5485 @smallexample
5486 @group
5487 SECTIONS @{
5488   outputa 0x10000 :
5489     @{
5490     all.o
5491     foo.o (.input1)
5492     @}
5493 @end group
5494 @group
5495   outputb :
5496     @{
5497     foo.o (.input2)
5498     foo1.o (.input1)
5499     @}
5500 @end group
5501 @group
5502   outputc :
5503     @{
5504     *(.input1)
5505     *(.input2)
5506     @}
5508 @end group
5509 @end smallexample
5511 If an output section's name is the same as the input section's name
5512 and is representable as a C identifier, then the linker will
5513 automatically @pxref{PROVIDE} two symbols: __start_SECNAME and
5514 __stop_SECNAME, where SECNAME is the name of the section.  These
5515 indicate the start address and end address of the output section
5516 respectively.  Note: most section names are not representable as
5517 C identifiers because they contain a @samp{.} character.
5519 @node Output Section Data
5520 @subsection Output Section Data
5521 @cindex data
5522 @cindex section data
5523 @cindex output section data
5524 @kindex ASCIZ ``@var{string}''
5525 @kindex BYTE(@var{expression})
5526 @kindex SHORT(@var{expression})
5527 @kindex LONG(@var{expression})
5528 @kindex QUAD(@var{expression})
5529 @kindex SQUAD(@var{expression})
5530 You can include explicit bytes of data in an output section by using
5531 @code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
5532 an output section command.  Each keyword is followed by an expression in
5533 parentheses providing the value to store (@pxref{Expressions}).  The
5534 value of the expression is stored at the current value of the location
5535 counter.
5537 The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
5538 store one, two, four, and eight bytes (respectively).  After storing the
5539 bytes, the location counter is incremented by the number of bytes
5540 stored.
5542 For example, this will store the byte 1 followed by the four byte value
5543 of the symbol @samp{addr}:
5544 @smallexample
5545 BYTE(1)
5546 LONG(addr)
5547 @end smallexample
5549 When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
5550 same; they both store an 8 byte, or 64 bit, value.  When both host and
5551 target are 32 bits, an expression is computed as 32 bits.  In this case
5552 @code{QUAD} stores a 32 bit value zero extended to 64 bits, and
5553 @code{SQUAD} stores a 32 bit value sign extended to 64 bits.
5555 If the object file format of the output file has an explicit endianness,
5556 which is the normal case, the value will be stored in that endianness.
5557 When the object file format does not have an explicit endianness, as is
5558 true of, for example, S-records, the value will be stored in the
5559 endianness of the first input object file.
5561 You can include a zero-terminated string in an output section by using
5562 @code{ASCIZ}.  The keyword is followed by a string which is stored at
5563 the current value of the location counter adding a zero byte at the
5564 end.  If the string includes spaces it must be enclosed in double
5565 quotes.  The string may contain '\n', '\r', '\t' and octal numbers.
5566 Hex numbers are not supported.
5568 For example, this string of 16 characters will create a 17 byte area
5569 @smallexample
5570   ASCIZ "This is 16 bytes"
5571 @end smallexample
5573 Note---these commands only work inside a section description and not
5574 between them, so the following will produce an error from the linker:
5575 @smallexample
5576 SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
5577 @end smallexample
5578 whereas this will work:
5579 @smallexample
5580 SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
5581 @end smallexample
5583 @kindex FILL(@var{expression})
5584 @cindex holes, filling
5585 @cindex unspecified memory
5586 You may use the @code{FILL} command to set the fill pattern for the
5587 current section.  It is followed by an expression in parentheses.  Any
5588 otherwise unspecified regions of memory within the section (for example,
5589 gaps left due to the required alignment of input sections) are filled
5590 with the value of the expression, repeated as
5591 necessary.  A @code{FILL} statement covers memory locations after the
5592 point at which it occurs in the section definition; by including more
5593 than one @code{FILL} statement, you can have different fill patterns in
5594 different parts of an output section.
5596 This example shows how to fill unspecified regions of memory with the
5597 value @samp{0x90}:
5598 @smallexample
5599 FILL(0x90909090)
5600 @end smallexample
5602 The @code{FILL} command is similar to the @samp{=@var{fillexp}} output
5603 section attribute, but it only affects the
5604 part of the section following the @code{FILL} command, rather than the
5605 entire section.  If both are used, the @code{FILL} command takes
5606 precedence.  @xref{Output Section Fill}, for details on the fill
5607 expression.
5609 Note - normally the value of @code{expression} is zero extended to 4
5610 bytes when used to fill gaps.  Thus @samp{FILL(144)} will fill a
5611 region with repeats of the pattern @samp{0 0 0 144}.  The value is
5612 treated as a big-endian number, so for example
5613 @samp{FILL(22 * 256 + 23)} will fill the region with repeats of the
5614 pattern @samp{0 0 22 23}.  If the expression results in a value with
5615 more than 4 significant bytes only the least 4 bytes of the value will
5616 be used.
5618 The above rules do not apply when the @code{expression} is a simple
5619 hexadecimal number.  In this case zero extension is not performed and
5620 all bytes are significant.  So @samp{FILL(0x90)} will fill a region with
5621 repeats of @samp{0x90} with no zero bytes, and @samp{FILL(0x9192)}
5622 will fill the region with repeats of @samp{0x91 0x92}.  Zero bytes
5623 in a hexadecimal expression are significant even at the start, so
5624 @samp{FILL(0x0090)} will fill a region with repeats of @samp{0x00 0x90}.
5626 Hexadecimal numbers can be longer than 4 bytes, and all of the bytes
5627 are significant, so @samp{FILL(0x123456789a)} will fill a region with
5628 repeats of the 5 byte sequence @samp{0x12 0x34 0x56 0x78 0x9a}.
5629 Excess bytes in a hexadecimal value beyond the size of a region will 
5630 be silently ignored.
5632 The above only applies to hexadecimal numbers specified as
5633 @samp{0x[0-9][a-f][A-F]}.  Hexadecimal numbers specified with a
5634 @samp{$} prefix, or a @samp{h}, @samp{H}, @samp{x} or @samp{X} suffix
5635 will follow the normal fill value rules.  This also applies to
5636 expressions that involve hexadecimal numbers, and hexadecimal numbers
5637 that have a magnitude suffix.
5639 @kindex LINKER_VERSION
5640 @cindex LINKER_VERSION
5641 The @code{LINKER_VERSION} command inserts a string containing the
5642 version of the linker at the current point.  Note - by default this
5643 directive is disabled and will do nothing.  It only becomes active if
5644 the @option{--enable-linker-version} command line option is used.
5646 Built-in linker scripts for ELF based targets already include this
5647 directive in their @samp{.comment} section.
5649 @node Output Section Keywords
5650 @subsection Output Section Keywords
5651 There are a couple of keywords which can appear as output section
5652 commands.
5654 @table @code
5655 @kindex CREATE_OBJECT_SYMBOLS
5656 @cindex input filename symbols
5657 @cindex filename symbols
5658 @item CREATE_OBJECT_SYMBOLS
5659 The command tells the linker to create a symbol for each input file.
5660 The name of each symbol will be the name of the corresponding input
5661 file.  The section of each symbol will be the output section in which
5662 the @code{CREATE_OBJECT_SYMBOLS} command appears.
5664 This is conventional for the a.out object file format.  It is not
5665 normally used for any other object file format.
5667 @kindex CONSTRUCTORS
5668 @cindex C++ constructors, arranging in link
5669 @cindex constructors, arranging in link
5670 @item CONSTRUCTORS
5671 When linking using the a.out object file format, the linker uses an
5672 unusual set construct to support C++ global constructors and
5673 destructors.  When linking object file formats which do not support
5674 arbitrary sections, such as ECOFF and XCOFF, the linker will
5675 automatically recognize C++ global constructors and destructors by name.
5676 For these object file formats, the @code{CONSTRUCTORS} command tells the
5677 linker to place constructor information in the output section where the
5678 @code{CONSTRUCTORS} command appears.  The @code{CONSTRUCTORS} command is
5679 ignored for other object file formats.
5681 The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
5682 constructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
5683 Similarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
5684 the start and end of the global destructors.  The
5685 first word in the list is the number of entries, followed by the address
5686 of each constructor or destructor, followed by a zero word.  The
5687 compiler must arrange to actually run the code.  For these object file
5688 formats @sc{gnu} C++ normally calls constructors from a subroutine
5689 @code{__main}; a call to @code{__main} is automatically inserted into
5690 the startup code for @code{main}.  @sc{gnu} C++ normally runs
5691 destructors either by using @code{atexit}, or directly from the function
5692 @code{exit}.
5694 For object file formats such as @code{COFF} or @code{ELF} which support
5695 arbitrary section names, @sc{gnu} C++ will normally arrange to put the
5696 addresses of global constructors and destructors into the @code{.ctors}
5697 and @code{.dtors} sections.  Placing the following sequence into your
5698 linker script will build the sort of table which the @sc{gnu} C++
5699 runtime code expects to see.
5701 @smallexample
5702       __CTOR_LIST__ = .;
5703       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
5704       *(.ctors)
5705       LONG(0)
5706       __CTOR_END__ = .;
5707       __DTOR_LIST__ = .;
5708       LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
5709       *(.dtors)
5710       LONG(0)
5711       __DTOR_END__ = .;
5712 @end smallexample
5714 If you are using the @sc{gnu} C++ support for initialization priority,
5715 which provides some control over the order in which global constructors
5716 are run, you must sort the constructors at link time to ensure that they
5717 are executed in the correct order.  When using the @code{CONSTRUCTORS}
5718 command, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead.  When using the
5719 @code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
5720 @samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
5721 @samp{*(.dtors)}.
5723 Normally the compiler and linker will handle these issues automatically,
5724 and you will not need to concern yourself with them.  However, you may
5725 need to consider this if you are using C++ and writing your own linker
5726 scripts.
5728 @end table
5730 @node Output Section Discarding
5731 @subsection Output Section Discarding
5732 @cindex discarding sections
5733 @cindex sections, discarding
5734 @cindex removing sections
5735 The linker will not normally create output sections with no contents.
5736 This is for convenience when referring to input sections that may or
5737 may not be present in any of the input files.  For example:
5738 @smallexample
5739 .foo : @{ *(.foo) @}
5740 @end smallexample
5741 @noindent
5742 will only create a @samp{.foo} section in the output file if there is a
5743 @samp{.foo} section in at least one input file, and if the input
5744 sections are not all empty.  Other link script directives that allocate
5745 space in an output section will also create the output section.  So
5746 too will assignments to dot even if the assignment does not create
5747 space, except for @samp{. = 0}, @samp{. = . + 0}, @samp{. = sym},
5748 @samp{. = . + sym} and @samp{. = ALIGN (. != 0, expr, 1)} when
5749 @samp{sym} is an absolute symbol of value 0 defined in the script.
5750 This allows you to force output of an empty section with @samp{. = .}.
5752 The linker will ignore address assignments (@pxref{Output Section Address})
5753 on discarded output sections, except when the linker script defines
5754 symbols in the output section.  In that case the linker will obey
5755 the address assignments, possibly advancing dot even though the
5756 section is discarded.
5758 @cindex /DISCARD/
5759 The special output section name @samp{/DISCARD/} may be used to discard
5760 input sections.  Any input sections which are assigned to an output
5761 section named @samp{/DISCARD/} are not included in the output file.
5763 This can be used to discard input sections marked with the ELF flag
5764 @code{SHF_GNU_RETAIN}, which would otherwise have been saved from linker
5765 garbage collection.
5767 Note, sections that match the @samp{/DISCARD/} output section will be
5768 discarded even if they are in an ELF section group which has other
5769 members which are not being discarded.  This is deliberate.
5770 Discarding takes precedence over grouping.
5772 @node Output Section Attributes
5773 @subsection Output Section Attributes
5774 @cindex output section attributes
5775 We showed above that the full description of an output section looked
5776 like this:
5778 @smallexample
5779 @group
5780 @var{section} [@var{address}] [(@var{type})] :
5781   [AT(@var{lma})]
5782   [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
5783   [SUBALIGN(@var{subsection_align})]
5784   [@var{constraint}]
5785   @{
5786     @var{output-section-command}
5787     @var{output-section-command}
5788     @dots{}
5789   @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
5790 @end group
5791 @end smallexample
5793 We've already described @var{section}, @var{address}, and
5794 @var{output-section-command}.  In this section we will describe the
5795 remaining section attributes.
5797 @menu
5798 * Output Section Type::         Output section type
5799 * Output Section LMA::          Output section LMA
5800 * Forced Output Alignment::     Forced Output Alignment
5801 * Forced Input Alignment::      Forced Input Alignment
5802 * Output Section Constraint::   Output section constraint
5803 * Output Section Region::       Output section region
5804 * Output Section Phdr::         Output section phdr
5805 * Output Section Fill::         Output section fill
5806 @end menu
5808 @node Output Section Type
5809 @subsubsection Output Section Type
5810 Each output section may have a type.  The type is a keyword in
5811 parentheses.  The following types are defined:
5813 @table @code
5815 @item NOLOAD
5816 The section should be marked as not loadable, so that it will not be
5817 loaded into memory when the program is run.
5819 @item READONLY
5820 The section should be marked as read-only.
5822 @item DSECT
5823 @item COPY
5824 @item INFO
5825 @item OVERLAY
5826 These type names are supported for backward compatibility, and are
5827 rarely used.  They all have the same effect: the section should be
5828 marked as not allocatable, so that no memory is allocated for the
5829 section when the program is run.
5831 @item TYPE = @var{type}
5832 Set the section type to the integer @var{type}. When generating an ELF
5833 output file, type names @code{SHT_PROGBITS}, @code{SHT_STRTAB},
5834 @code{SHT_NOTE}, @code{SHT_NOBITS}, @code{SHT_INIT_ARRAY},
5835 @code{SHT_FINI_ARRAY}, and @code{SHT_PREINIT_ARRAY} are also allowed
5836 for @var{type}.  It is the user's responsibility to ensure that any
5837 special requirements of the section type are met.
5839 Note - the TYPE only is used if some or all of the contents of the
5840 section do not have an implicit type of their own.  So for example:
5841 @smallexample
5842   .foo . TYPE = SHT_PROGBITS @{ *(.bar) @}
5843 @end smallexample
5844 will set the type of section @samp{.foo} to the type of the section
5845 @samp{.bar} in the input files, which may not be the SHT_PROGBITS
5846 type.  Whereas:
5847 @smallexample
5848   .foo . TYPE = SHT_PROGBITS @{ BYTE(1) @}
5849 @end smallexample
5850 will set the type of @samp{.foo} to SHT_PROGBBITS.  If it is necessary
5851 to override the type of incoming sections and force the output section
5852 type then an extra piece of untyped data will be needed:
5853 @smallexample
5854   .foo . TYPE = SHT_PROGBITS @{ BYTE(1); *(.bar) @}
5855 @end smallexample
5857 @item READONLY ( TYPE = @var{type} )
5858 This form of the syntax combines the @var{READONLY} type with the
5859 type specified by @var{type}.
5861 @end table
5863 @kindex NOLOAD
5864 @cindex prevent unnecessary loading
5865 @cindex loading, preventing
5866 The linker normally sets the attributes of an output section based on
5867 the input sections which map into it.  You can override this by using
5868 the section type.  For example, in the script sample below, the
5869 @samp{ROM} section is addressed at memory location @samp{0} and does not
5870 need to be loaded when the program is run.
5871 @smallexample
5872 @group
5873 SECTIONS @{
5874   ROM 0 (NOLOAD) : @{ @dots{} @}
5875   @dots{}
5877 @end group
5878 @end smallexample
5880 @node Output Section LMA
5881 @subsubsection Output Section LMA
5882 @kindex AT>@var{lma_region}
5883 @kindex AT(@var{lma})
5884 @cindex load address
5885 @cindex section load address
5886 Every section has a virtual address (VMA) and a load address (LMA); see
5887 @ref{Basic Script Concepts}.  The virtual address is specified by the
5888 @pxref{Output Section Address} described earlier.  The load address is
5889 specified by the @code{AT} or @code{AT>} keywords.  Specifying a load
5890 address is optional.
5892 The @code{AT} keyword takes an expression as an argument.  This
5893 specifies the exact load address of the section.  The @code{AT>} keyword
5894 takes the name of a memory region as an argument.  @xref{MEMORY}.  The
5895 load address of the section is set to the next free address in the
5896 region, aligned to the section's alignment requirements.
5898 If neither @code{AT} nor @code{AT>} is specified for an allocatable
5899 section, the linker will use the following heuristic to determine the
5900 load address:
5902 @itemize @bullet
5903 @item
5904 If the section has a specific VMA address, then this is used as
5905 the LMA address as well.
5907 @item
5908 If the section is not allocatable then its LMA is set to its VMA.
5910 @item
5911 Otherwise if a memory region can be found that is compatible
5912 with the current section, and this region contains at least one
5913 section, then the LMA is set so the difference between the
5914 VMA and LMA is the same as the difference between the VMA and LMA of
5915 the last section in the located region.
5917 @item
5918 If no memory regions have been declared then a default region
5919 that covers the entire address space is used in the previous step.
5921 @item
5922 If no suitable region could be found, or there was no previous
5923 section then the LMA is set equal to the VMA.
5924 @end itemize
5926 @cindex ROM initialized data
5927 @cindex initialized data in ROM
5928 This feature is designed to make it easy to build a ROM image.  For
5929 example, the following linker script creates three output sections: one
5930 called @samp{.text}, which starts at @code{0x1000}, one called
5931 @samp{.mdata}, which is loaded at the end of the @samp{.text} section
5932 even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
5933 uninitialized data at address @code{0x3000}.  The symbol @code{_data} is
5934 defined with the value @code{0x2000}, which shows that the location
5935 counter holds the VMA value, not the LMA value.
5937 @smallexample
5938 @group
5939 SECTIONS
5940   @{
5941   .text 0x1000 : @{ *(.text) _etext = . ; @}
5942   .mdata 0x2000 :
5943     AT ( ADDR (.text) + SIZEOF (.text) )
5944     @{ _data = . ; *(.data); _edata = . ;  @}
5945   .bss 0x3000 :
5946     @{ _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;@}
5948 @end group
5949 @end smallexample
5951 The run-time initialization code for use with a program generated with
5952 this linker script would include something like the following, to copy
5953 the initialized data from the ROM image to its runtime address.  Notice
5954 how this code takes advantage of the symbols defined by the linker
5955 script.
5957 @smallexample
5958 @group
5959 extern char _etext, _data, _edata, _bstart, _bend;
5960 char *src = &_etext;
5961 char *dst = &_data;
5963 /* ROM has data at end of text; copy it.  */
5964 while (dst < &_edata)
5965   *dst++ = *src++;
5967 /* Zero bss.  */
5968 for (dst = &_bstart; dst< &_bend; dst++)
5969   *dst = 0;
5970 @end group
5971 @end smallexample
5973 @node Forced Output Alignment
5974 @subsubsection Forced Output Alignment
5975 @kindex ALIGN(@var{section_align})
5976 @cindex forcing output section alignment
5977 @cindex output section alignment
5978 You can increase an output section's alignment by using ALIGN.  As an
5979 alternative you can enforce that the difference between the VMA and LMA remains
5980 intact throughout this output section with the ALIGN_WITH_INPUT attribute.
5982 @node Forced Input Alignment
5983 @subsubsection Forced Input Alignment
5984 @kindex SUBALIGN(@var{subsection_align})
5985 @cindex forcing input section alignment
5986 @cindex input section alignment
5987 You can force input section alignment within an output section by using
5988 SUBALIGN.  The value specified overrides any alignment given by input
5989 sections, whether larger or smaller.
5991 @node Output Section Constraint
5992 @subsubsection Output Section Constraint
5993 @kindex ONLY_IF_RO
5994 @kindex ONLY_IF_RW
5995 @cindex constraints on output sections
5996 You can specify that an output section should only be created if all
5997 of its input sections are read-only or all of its input sections are
5998 read-write by using the keyword @code{ONLY_IF_RO} and
5999 @code{ONLY_IF_RW} respectively.
6001 @node Output Section Region
6002 @subsubsection Output Section Region
6003 @kindex >@var{region}
6004 @cindex section, assigning to memory region
6005 @cindex memory regions and sections
6006 You can assign a section to a previously defined region of memory by
6007 using @samp{>@var{region}}.  @xref{MEMORY}.
6009 Here is a simple example:
6010 @smallexample
6011 @group
6012 MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
6013 SECTIONS @{ ROM : @{ *(.text) @} >rom @}
6014 @end group
6015 @end smallexample
6017 @node Output Section Phdr
6018 @subsubsection Output Section Phdr
6019 @kindex :@var{phdr}
6020 @cindex section, assigning to program header
6021 @cindex program headers and sections
6022 You can assign a section to a previously defined program segment by
6023 using @samp{:@var{phdr}}.  @xref{PHDRS}.  If a section is assigned to
6024 one or more segments, then all subsequent allocated sections will be
6025 assigned to those segments as well, unless they use an explicitly
6026 @code{:@var{phdr}} modifier.  You can use @code{:NONE} to tell the
6027 linker to not put the section in any segment at all.
6029 Here is a simple example:
6030 @smallexample
6031 @group
6032 PHDRS @{ text PT_LOAD ; @}
6033 SECTIONS @{ .text : @{ *(.text) @} :text @}
6034 @end group
6035 @end smallexample
6037 @node Output Section Fill
6038 @subsubsection Output Section Fill
6039 @kindex =@var{fillexp}
6040 @cindex section fill pattern
6041 @cindex fill pattern, entire section
6042 You can set the fill pattern for an entire section by using
6043 @samp{=@var{fillexp}}.  @var{fillexp} is an expression
6044 (@pxref{Expressions}).  Any otherwise unspecified regions of memory
6045 within the output section (for example, gaps left due to the required
6046 alignment of input sections) will be filled with the value, repeated as
6047 necessary.  If the fill expression is a simple hex number, ie. a string
6048 of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
6049 an arbitrarily long sequence of hex digits can be used to specify the
6050 fill pattern;  Leading zeros become part of the pattern too.  For all
6051 other cases, including extra parentheses or a unary @code{+}, the fill
6052 pattern is the four least significant bytes of the value of the
6053 expression.  If the value is less than four bytes in size then it will
6054 be zero extended to four bytes.  In all cases, the number is big-endian.
6056 @smallexample
6057 Fill Value     Fill Pattern
6058 0x90           90 90 90 90
6059 0x0090         00 90 00 90
6060 144            00 00 00 90
6061 @end smallexample
6063 You can also change the fill value with a @code{FILL} command in the
6064 output section commands; (@pxref{Output Section Data}).
6066 Here is a simple example:
6067 @smallexample
6068 @group
6069 SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
6070 @end group
6071 @end smallexample
6073 @node Overlay Description
6074 @subsection Overlay Description
6075 @kindex OVERLAY
6076 @cindex overlays
6077 An overlay description provides an easy way to describe sections which
6078 are to be loaded as part of a single memory image but are to be run at
6079 the same memory address.  At run time, some sort of overlay manager will
6080 copy the overlaid sections in and out of the runtime memory address as
6081 required, perhaps by simply manipulating addressing bits.  This approach
6082 can be useful, for example, when a certain region of memory is faster
6083 than another.
6085 Overlays are described using the @code{OVERLAY} command.  The
6086 @code{OVERLAY} command is used within a @code{SECTIONS} command, like an
6087 output section description.  The full syntax of the @code{OVERLAY}
6088 command is as follows:
6089 @smallexample
6090 @group
6091 OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
6092   @{
6093     @var{secname1}
6094       @{
6095         @var{output-section-command}
6096         @var{output-section-command}
6097         @dots{}
6098       @} [:@var{phdr}@dots{}] [=@var{fill}]
6099     @var{secname2}
6100       @{
6101         @var{output-section-command}
6102         @var{output-section-command}
6103         @dots{}
6104       @} [:@var{phdr}@dots{}] [=@var{fill}]
6105     @dots{}
6106   @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] [,]
6107 @end group
6108 @end smallexample
6110 Everything is optional except @code{OVERLAY} (a keyword), and each
6111 section must have a name (@var{secname1} and @var{secname2} above).  The
6112 section definitions within the @code{OVERLAY} construct are identical to
6113 those within the general @code{SECTIONS} construct (@pxref{SECTIONS}),
6114 except that no addresses and no memory regions may be defined for
6115 sections within an @code{OVERLAY}.
6117 The comma at the end may be required if a @var{fill} is used and
6118 the next @var{sections-command} looks like a continuation of the expression.
6120 The sections are all defined with the same starting address.  The load
6121 addresses of the sections are arranged such that they are consecutive in
6122 memory starting at the load address used for the @code{OVERLAY} as a
6123 whole (as with normal section definitions, the load address is optional,
6124 and defaults to the start address; the start address is also optional,
6125 and defaults to the current value of the location counter).
6127 If the @code{NOCROSSREFS} keyword is used, and there are any
6128 references among the sections, the linker will report an error.  Since
6129 the sections all run at the same address, it normally does not make
6130 sense for one section to refer directly to another.
6131 @xref{Miscellaneous Commands, NOCROSSREFS}.
6133 For each section within the @code{OVERLAY}, the linker automatically
6134 provides two symbols.  The symbol @code{__load_start_@var{secname}} is
6135 defined as the starting load address of the section.  The symbol
6136 @code{__load_stop_@var{secname}} is defined as the final load address of
6137 the section.  Any characters within @var{secname} which are not legal
6138 within C identifiers are removed.  C (or assembler) code may use these
6139 symbols to move the overlaid sections around as necessary.
6141 At the end of the overlay, the value of the location counter is set to
6142 the start address of the overlay plus the size of the largest section.
6144 Here is an example.  Remember that this would appear inside a
6145 @code{SECTIONS} construct.
6146 @smallexample
6147 @group
6148   OVERLAY 0x1000 : AT (0x4000)
6149    @{
6150      .text0 @{ o1/*.o(.text) @}
6151      .text1 @{ o2/*.o(.text) @}
6152    @}
6153 @end group
6154 @end smallexample
6155 @noindent
6156 This will define both @samp{.text0} and @samp{.text1} to start at
6157 address 0x1000.  @samp{.text0} will be loaded at address 0x4000, and
6158 @samp{.text1} will be loaded immediately after @samp{.text0}.  The
6159 following symbols will be defined if referenced: @code{__load_start_text0},
6160 @code{__load_stop_text0}, @code{__load_start_text1},
6161 @code{__load_stop_text1}.
6163 C code to copy overlay @code{.text1} into the overlay area might look
6164 like the following.
6166 @smallexample
6167 @group
6168   extern char __load_start_text1, __load_stop_text1;
6169   memcpy ((char *) 0x1000, &__load_start_text1,
6170           &__load_stop_text1 - &__load_start_text1);
6171 @end group
6172 @end smallexample
6174 Note that the @code{OVERLAY} command is just syntactic sugar, since
6175 everything it does can be done using the more basic commands.  The above
6176 example could have been written identically as follows.
6178 @smallexample
6179 @group
6180   .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
6181   PROVIDE (__load_start_text0 = LOADADDR (.text0));
6182   PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
6183   .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
6184   PROVIDE (__load_start_text1 = LOADADDR (.text1));
6185   PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
6186   . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
6187 @end group
6188 @end smallexample
6190 @node MEMORY
6191 @section MEMORY Command
6192 @kindex MEMORY
6193 @cindex memory regions
6194 @cindex regions of memory
6195 @cindex allocating memory
6196 @cindex discontinuous memory
6197 The linker's default configuration permits allocation of all available
6198 memory.  You can override this by using the @code{MEMORY} command.
6200 The @code{MEMORY} command describes the location and size of blocks of
6201 memory in the target.  You can use it to describe which memory regions
6202 may be used by the linker, and which memory regions it must avoid.  You
6203 can then assign sections to particular memory regions.  The linker will
6204 set section addresses based on the memory regions, and will warn about
6205 regions that become too full.  The linker will not shuffle sections
6206 around to fit into the available regions.
6208 A linker script may contain many uses of the @code{MEMORY} command,
6209 however, all memory blocks defined are treated as if they were
6210 specified inside a single @code{MEMORY} command.  The syntax for
6211 @code{MEMORY} is:
6212 @smallexample
6213 @group
6214 MEMORY
6215   @{
6216     @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
6217     @dots{}
6218   @}
6219 @end group
6220 @end smallexample
6222 The @var{name} is a name used in the linker script to refer to the
6223 region.  The region name has no meaning outside of the linker script.
6224 Region names are stored in a separate name space, and will not conflict
6225 with symbol names, file names, or section names.  Each memory region
6226 must have a distinct name within the @code{MEMORY} command.  However you can
6227 add later alias names to existing memory regions with the @ref{REGION_ALIAS}
6228 command.
6230 @cindex memory region attributes
6231 The @var{attr} string is an optional list of attributes that specify
6232 whether to use a particular memory region for an input section which is
6233 not explicitly mapped in the linker script.  As described in
6234 @ref{SECTIONS}, if you do not specify an output section for some input
6235 section, the linker will create an output section with the same name as
6236 the input section.  If you define region attributes, the linker will use
6237 them to select the memory region for the output section that it creates.
6239 The @var{attr} string must consist only of the following characters:
6240 @table @samp
6241 @item R
6242 Read-only section
6243 @item W
6244 Read/write section
6245 @item X
6246 Executable section
6247 @item A
6248 Allocatable section
6249 @item I
6250 Initialized section
6251 @item L
6252 Same as @samp{I}
6253 @item !
6254 Invert the sense of any of the attributes that follow
6255 @end table
6257 If an unmapped section matches any of the listed attributes other than
6258 @samp{!}, it will be placed in the memory region.  The @samp{!}
6259 attribute reverses the test for the characters that follow, so that an
6260 unmapped section will be placed in the memory region only if it does
6261 not match any of the attributes listed afterwards.  Thus an attribute
6262 string of @samp{RW!X} will match any unmapped section that has either
6263 or both of the @samp{R} and @samp{W} attributes, but only as long as
6264 the section does not also have the @samp{X} attribute.
6266 @kindex ORIGIN =
6267 @kindex o =
6268 @kindex org =
6269 The @var{origin} is an numerical expression for the start address of
6270 the memory region.  The expression must evaluate to a constant and it
6271 cannot involve any symbols.  The keyword @code{ORIGIN} may be
6272 abbreviated to @code{org} or @code{o} (but not, for example,
6273 @code{ORG}).
6275 @kindex LENGTH =
6276 @kindex len =
6277 @kindex l =
6278 The @var{len} is an expression for the size in bytes of the memory
6279 region.  As with the @var{origin} expression, the expression must
6280 be numerical only and must evaluate to a constant.  The keyword
6281 @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
6283 In the following example, we specify that there are two memory regions
6284 available for allocation: one starting at @samp{0} for 256 kilobytes,
6285 and the other starting at @samp{0x40000000} for four megabytes.  The
6286 linker will place into the @samp{rom} memory region every section which
6287 is not explicitly mapped into a memory region, and is either read-only
6288 or executable.  The linker will place other sections which are not
6289 explicitly mapped into a memory region into the @samp{ram} memory
6290 region.
6292 @smallexample
6293 @group
6294 MEMORY
6295   @{
6296     rom (rx)  : ORIGIN = 0, LENGTH = 256K
6297     ram (!rx) : org = 0x40000000, l = 4M
6298   @}
6299 @end group
6300 @end smallexample
6302 Once you define a memory region, you can direct the linker to place
6303 specific output sections into that memory region by using the
6304 @samp{>@var{region}} output section attribute.  For example, if you have
6305 a memory region named @samp{mem}, you would use @samp{>mem} in the
6306 output section definition.  @xref{Output Section Region}.  If no address
6307 was specified for the output section, the linker will set the address to
6308 the next available address within the memory region.  If the combined
6309 output sections directed to a memory region are too large for the
6310 region, the linker will issue an error message.
6312 It is possible to access the origin and length of a memory in an
6313 expression via the @code{ORIGIN(@var{memory})} and
6314 @code{LENGTH(@var{memory})} functions:
6316 @smallexample
6317 @group
6318   _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
6319 @end group
6320 @end smallexample
6322 @node PHDRS
6323 @section PHDRS Command
6324 @kindex PHDRS
6325 @cindex program headers
6326 @cindex ELF program headers
6327 @cindex program segments
6328 @cindex segments, ELF
6329 The ELF object file format uses @dfn{program headers}, also knows as
6330 @dfn{segments}.  The program headers describe how the program should be
6331 loaded into memory.  You can print them out by using the @code{objdump}
6332 program with the @samp{-p} option.
6334 When you run an ELF program on a native ELF system, the system loader
6335 reads the program headers in order to figure out how to load the
6336 program.  This will only work if the program headers are set correctly.
6337 This manual does not describe the details of how the system loader
6338 interprets program headers; for more information, see the ELF ABI.
6340 The linker will create reasonable program headers by default.  However,
6341 in some cases, you may need to specify the program headers more
6342 precisely.  You may use the @code{PHDRS} command for this purpose.  When
6343 the linker sees the @code{PHDRS} command in the linker script, it will
6344 not create any program headers other than the ones specified.
6346 The linker only pays attention to the @code{PHDRS} command when
6347 generating an ELF output file.  In other cases, the linker will simply
6348 ignore @code{PHDRS}.
6350 This is the syntax of the @code{PHDRS} command.  The words @code{PHDRS},
6351 @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
6353 @smallexample
6354 @group
6355 PHDRS
6357   @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
6358         [ FLAGS ( @var{flags} ) ] ;
6360 @end group
6361 @end smallexample
6363 The @var{name} is used only for reference in the @code{SECTIONS} command
6364 of the linker script.  It is not put into the output file.  Program
6365 header names are stored in a separate name space, and will not conflict
6366 with symbol names, file names, or section names.  Each program header
6367 must have a distinct name.  The headers are processed in order and it
6368 is usual for them to map to sections in ascending load address order.
6370 Certain program header types describe segments of memory which the
6371 system loader will load from the file.  In the linker script, you
6372 specify the contents of these segments by placing allocatable output
6373 sections in the segments.  You use the @samp{:@var{phdr}} output section
6374 attribute to place a section in a particular segment.  @xref{Output
6375 Section Phdr}.
6377 It is normal to put certain sections in more than one segment.  This
6378 merely implies that one segment of memory contains another.  You may
6379 repeat @samp{:@var{phdr}}, using it once for each segment which should
6380 contain the section.
6382 If you place a section in one or more segments using @samp{:@var{phdr}},
6383 then the linker will place all subsequent allocatable sections which do
6384 not specify @samp{:@var{phdr}} in the same segments.  This is for
6385 convenience, since generally a whole set of contiguous sections will be
6386 placed in a single segment.  You can use @code{:NONE} to override the
6387 default segment and tell the linker to not put the section in any
6388 segment at all.
6390 @kindex FILEHDR
6391 @kindex PHDRS
6392 You may use the @code{FILEHDR} and @code{PHDRS} keywords after
6393 the program header type to further describe the contents of the segment.
6394 The @code{FILEHDR} keyword means that the segment should include the ELF
6395 file header.  The @code{PHDRS} keyword means that the segment should
6396 include the ELF program headers themselves.  If applied to a loadable
6397 segment (@code{PT_LOAD}), all prior loadable segments must have one of
6398 these keywords.
6400 The @var{type} may be one of the following.  The numbers indicate the
6401 value of the keyword.
6403 @table @asis
6404 @item @code{PT_NULL} (0)
6405 Indicates an unused program header.
6407 @item @code{PT_LOAD} (1)
6408 Indicates that this program header describes a segment to be loaded from
6409 the file.
6411 @item @code{PT_DYNAMIC} (2)
6412 Indicates a segment where dynamic linking information can be found.
6414 @item @code{PT_INTERP} (3)
6415 Indicates a segment where the name of the program interpreter may be
6416 found.
6418 @item @code{PT_NOTE} (4)
6419 Indicates a segment holding note information.
6421 @item @code{PT_SHLIB} (5)
6422 A reserved program header type, defined but not specified by the ELF
6423 ABI.
6425 @item @code{PT_PHDR} (6)
6426 Indicates a segment where the program headers may be found.
6428 @item @code{PT_TLS} (7)
6429 Indicates a segment containing thread local storage.
6431 @item @var{expression}
6432 An expression giving the numeric type of the program header.  This may
6433 be used for types not defined above.
6434 @end table
6436 You can specify that a segment should be loaded at a particular address
6437 in memory by using an @code{AT} expression.  This is identical to the
6438 @code{AT} command used as an output section attribute (@pxref{Output
6439 Section LMA}).  The @code{AT} command for a program header overrides the
6440 output section attribute.
6442 The linker will normally set the segment flags based on the sections
6443 which comprise the segment.  You may use the @code{FLAGS} keyword to
6444 explicitly specify the segment flags.  The value of @var{flags} must be
6445 an integer.  It is used to set the @code{p_flags} field of the program
6446 header.
6448 Here is an example of @code{PHDRS}.  This shows a typical set of program
6449 headers used on a native ELF system.
6451 @example
6452 @group
6453 PHDRS
6455   headers PT_PHDR PHDRS ;
6456   interp PT_INTERP ;
6457   text PT_LOAD FILEHDR PHDRS ;
6458   data PT_LOAD ;
6459   dynamic PT_DYNAMIC ;
6462 SECTIONS
6464   . = SIZEOF_HEADERS;
6465   .interp : @{ *(.interp) @} :text :interp
6466   .text : @{ *(.text) @} :text
6467   .rodata : @{ *(.rodata) @} /* defaults to :text */
6468   @dots{}
6469   . = . + 0x1000; /* move to a new page in memory */
6470   .data : @{ *(.data) @} :data
6471   .dynamic : @{ *(.dynamic) @} :data :dynamic
6472   @dots{}
6474 @end group
6475 @end example
6477 @node VERSION
6478 @section VERSION Command
6479 @kindex VERSION @{script text@}
6480 @cindex symbol versions
6481 @cindex version script
6482 @cindex versions of symbols
6483 The linker supports symbol versions when using ELF.  Symbol versions are
6484 only useful when using shared libraries.  The dynamic linker can use
6485 symbol versions to select a specific version of a function when it runs
6486 a program that may have been linked against an earlier version of the
6487 shared library.
6489 You can include a version script directly in the main linker script, or
6490 you can supply the version script as an implicit linker script.  You can
6491 also use the @samp{--version-script} linker option.
6493 The syntax of the @code{VERSION} command is simply
6494 @smallexample
6495 VERSION @{ version-script-commands @}
6496 @end smallexample
6498 The format of the version script commands is identical to that used by
6499 Sun's linker in Solaris 2.5.  The version script defines a tree of
6500 version nodes.  You specify the node names and interdependencies in the
6501 version script.  You can specify which symbols are bound to which
6502 version nodes, and you can reduce a specified set of symbols to local
6503 scope so that they are not globally visible outside of the shared
6504 library.
6506 The easiest way to demonstrate the version script language is with a few
6507 examples.
6509 @smallexample
6510 VERS_1.1 @{
6511          global:
6512                  foo1;
6513          local:
6514                  old*;
6515                  original*;
6516                  new*;
6519 VERS_1.2 @{
6520                  foo2;
6521 @} VERS_1.1;
6523 VERS_2.0 @{
6524                  bar1; bar2;
6525          extern "C++" @{
6526                  ns::*;
6527                  "f(int, double)";
6528          @};
6529 @} VERS_1.2;
6530 @end smallexample
6532 This example version script defines three version nodes.  The first
6533 version node defined is @samp{VERS_1.1}; it has no other dependencies.
6534 The script binds the symbol @samp{foo1} to @samp{VERS_1.1}.  It reduces
6535 a number of symbols to local scope so that they are not visible outside
6536 of the shared library; this is done using wildcard patterns, so that any
6537 symbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
6538 is matched.  The wildcard patterns available are the same as those used
6539 in the shell when matching filenames (also known as ``globbing'').
6540 However, if you specify the symbol name inside double quotes, then the
6541 name is treated as literal, rather than as a glob pattern.
6543 Next, the version script defines node @samp{VERS_1.2}.  This node
6544 depends upon @samp{VERS_1.1}.  The script binds the symbol @samp{foo2}
6545 to the version node @samp{VERS_1.2}.
6547 Finally, the version script defines node @samp{VERS_2.0}.  This node
6548 depends upon @samp{VERS_1.2}.  The scripts binds the symbols @samp{bar1}
6549 and @samp{bar2} are bound to the version node @samp{VERS_2.0}.
6551 When the linker finds a symbol defined in a library which is not
6552 specifically bound to a version node, it will effectively bind it to an
6553 unspecified base version of the library.  You can bind all otherwise
6554 unspecified symbols to a given version node by using @samp{global: *;}
6555 somewhere in the version script.  Note that it's slightly crazy to use
6556 wildcards in a global spec except on the last version node.  Global
6557 wildcards elsewhere run the risk of accidentally adding symbols to the
6558 set exported for an old version.  That's wrong since older versions
6559 ought to have a fixed set of symbols.
6561 The names of the version nodes have no specific meaning other than what
6562 they might suggest to the person reading them.  The @samp{2.0} version
6563 could just as well have appeared in between @samp{1.1} and @samp{1.2}.
6564 However, this would be a confusing way to write a version script.
6566 Node name can be omitted, provided it is the only version node
6567 in the version script.  Such version script doesn't assign any versions to
6568 symbols, only selects which symbols will be globally visible out and which
6569 won't.
6571 @smallexample
6572 @{ global: foo; bar; local: *; @};
6573 @end smallexample
6575 When you link an application against a shared library that has versioned
6576 symbols, the application itself knows which version of each symbol it
6577 requires, and it also knows which version nodes it needs from each
6578 shared library it is linked against.  Thus at runtime, the dynamic
6579 loader can make a quick check to make sure that the libraries you have
6580 linked against do in fact supply all of the version nodes that the
6581 application will need to resolve all of the dynamic symbols.  In this
6582 way it is possible for the dynamic linker to know with certainty that
6583 all external symbols that it needs will be resolvable without having to
6584 search for each symbol reference.
6586 The symbol versioning is in effect a much more sophisticated way of
6587 doing minor version checking that SunOS does.  The fundamental problem
6588 that is being addressed here is that typically references to external
6589 functions are bound on an as-needed basis, and are not all bound when
6590 the application starts up.  If a shared library is out of date, a
6591 required interface may be missing; when the application tries to use
6592 that interface, it may suddenly and unexpectedly fail.  With symbol
6593 versioning, the user will get a warning when they start their program if
6594 the libraries being used with the application are too old.
6596 There are several GNU extensions to Sun's versioning approach.  The
6597 first of these is the ability to bind a symbol to a version node in the
6598 source file where the symbol is defined instead of in the versioning
6599 script.  This was done mainly to reduce the burden on the library
6600 maintainer.  You can do this by putting something like:
6601 @smallexample
6602 __asm__(".symver original_foo,foo@@VERS_1.1");
6603 @end smallexample
6604 @noindent
6605 in the C source file.  This renames the function @samp{original_foo} to
6606 be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
6607 The @samp{local:} directive can be used to prevent the symbol
6608 @samp{original_foo} from being exported. A @samp{.symver} directive
6609 takes precedence over a version script.
6611 The second GNU extension is to allow multiple versions of the same
6612 function to appear in a given shared library.  In this way you can make
6613 an incompatible change to an interface without increasing the major
6614 version number of the shared library, while still allowing applications
6615 linked against the old interface to continue to function.
6617 To do this, you must use multiple @samp{.symver} directives in the
6618 source file.  Here is an example:
6620 @smallexample
6621 __asm__(".symver original_foo,foo@@");
6622 __asm__(".symver old_foo,foo@@VERS_1.1");
6623 __asm__(".symver old_foo1,foo@@VERS_1.2");
6624 __asm__(".symver new_foo,foo@@@@VERS_2.0");
6625 @end smallexample
6627 In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
6628 unspecified base version of the symbol.  The source file that contains this
6629 example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
6630 @samp{old_foo1}, and @samp{new_foo}.
6632 When you have multiple definitions of a given symbol, there needs to be
6633 some way to specify a default version to which external references to
6634 this symbol will be bound.  You can do this with the
6635 @samp{foo@@@@VERS_2.0} type of @samp{.symver} directive.  You can only
6636 declare one version of a symbol as the default in this manner; otherwise
6637 you would effectively have multiple definitions of the same symbol.
6639 If you wish to bind a reference to a specific version of the symbol
6640 within the shared library, you can use the aliases of convenience
6641 (i.e., @samp{old_foo}), or you can use the @samp{.symver} directive to
6642 specifically bind to an external version of the function in question.
6644 You can also specify the language in the version script:
6646 @smallexample
6647 VERSION extern "lang" @{ version-script-commands @}
6648 @end smallexample
6650 The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
6651 The linker will iterate over the list of symbols at the link time and
6652 demangle them according to @samp{lang} before matching them to the
6653 patterns specified in @samp{version-script-commands}.  The default
6654 @samp{lang} is @samp{C}.
6656 Demangled names may contains spaces and other special characters.  As
6657 described above, you can use a glob pattern to match demangled names,
6658 or you can use a double-quoted string to match the string exactly.  In
6659 the latter case, be aware that minor differences (such as differing
6660 whitespace) between the version script and the demangler output will
6661 cause a mismatch.  As the exact string generated by the demangler
6662 might change in the future, even if the mangled name does not, you
6663 should check that all of your version directives are behaving as you
6664 expect when you upgrade.
6666 @node Expressions
6667 @section Expressions in Linker Scripts
6668 @cindex expressions
6669 @cindex arithmetic
6670 The syntax for expressions in the linker script language is identical to
6671 that of C expressions, except that whitespace is required in some
6672 places to resolve syntactic ambiguities.  All expressions are
6673 evaluated as integers.  All expressions are evaluated in the same
6674 size, which is 32 bits if both the host and target are 32 bits, and is
6675 otherwise 64 bits.
6677 You can use and set symbol values in expressions.
6679 The linker defines several special purpose builtin functions for use in
6680 expressions.
6682 @menu
6683 * Constants::                   Constants
6684 * Symbolic Constants::          Symbolic constants
6685 * Symbols::                     Symbol Names
6686 * Orphan Sections::             Orphan Sections
6687 * Location Counter::            The Location Counter
6688 * Operators::                   Operators
6689 * Evaluation::                  Evaluation
6690 * Expression Section::          The Section of an Expression
6691 * Builtin Functions::           Builtin Functions
6692 @end menu
6694 @node Constants
6695 @subsection Constants
6696 @cindex integer notation
6697 @cindex constants in linker scripts
6698 All constants are integers.
6700 As in C, the linker considers an integer beginning with @samp{0} to be
6701 octal, and an integer beginning with @samp{0x} or @samp{0X} to be
6702 hexadecimal.  Alternatively the linker accepts suffixes of @samp{h} or
6703 @samp{H} for hexadecimal, @samp{o} or @samp{O} for octal, @samp{b} or
6704 @samp{B} for binary and @samp{d} or @samp{D} for decimal.  Any integer
6705 value without a prefix or a suffix is considered to be decimal.
6707 @cindex scaled integers
6708 @cindex K and M integer suffixes
6709 @cindex M and K integer suffixes
6710 @cindex suffixes for integers
6711 @cindex integer suffixes
6712 In addition, you can use the suffixes @code{K} and @code{M} to scale a
6713 constant by
6714 @c TEXI2ROFF-KILL
6715 @ifnottex
6716 @c END TEXI2ROFF-KILL
6717 @code{1024} or @code{1024*1024}
6718 @c TEXI2ROFF-KILL
6719 @end ifnottex
6720 @tex
6721 ${\rm 1024}$ or ${\rm 1024}^2$
6722 @end tex
6723 @c END TEXI2ROFF-KILL
6724 respectively.  For example, the following
6725 all refer to the same quantity:
6727 @smallexample
6728 _fourk_1 = 4K;
6729 _fourk_2 = 4096;
6730 _fourk_3 = 0x1000;
6731 _fourk_4 = 10000o;
6732 @end smallexample
6734 Note - the @code{K} and @code{M} suffixes cannot be used in
6735 conjunction with the base suffixes mentioned above.
6737 @node Symbolic Constants
6738 @subsection Symbolic Constants
6739 @cindex symbolic constants
6740 @kindex CONSTANT
6741 It is possible to refer to target-specific constants via the use of
6742 the @code{CONSTANT(@var{name})} operator, where @var{name} is one of:
6744 @table @code
6745 @item MAXPAGESIZE
6746 @kindex MAXPAGESIZE
6747 The target's maximum page size.
6749 @item COMMONPAGESIZE
6750 @kindex COMMONPAGESIZE
6751 The target's default page size.
6752 @end table
6754 So for example:
6756 @smallexample
6757   .text ALIGN (CONSTANT (MAXPAGESIZE)) : @{ *(.text) @}
6758 @end smallexample
6760 will create a text section aligned to the largest page boundary
6761 supported by the target.
6763 @node Symbols
6764 @subsection Symbol Names
6765 @cindex symbol names
6766 @cindex names
6767 @cindex quoted symbol names
6768 @kindex "
6769 Unless quoted, symbol names start with a letter, underscore, or period
6770 and may include letters, digits, underscores, periods, and hyphens.
6771 Unquoted symbol names must not conflict with any keywords.  You can
6772 specify a symbol which contains odd characters or has the same name as a
6773 keyword by surrounding the symbol name in double quotes:
6774 @smallexample
6775 "SECTION" = 9;
6776 "with a space" = "also with a space" + 10;
6777 @end smallexample
6779 Since symbols can contain many non-alphabetic characters, it is safest
6780 to delimit symbols with spaces.  For example, @samp{A-B} is one symbol,
6781 whereas @samp{A - B} is an expression involving subtraction.
6783 @node Orphan Sections
6784 @subsection Orphan Sections
6785 @cindex orphan
6786 Orphan sections are sections present in the input files which
6787 are not explicitly placed into the output file by the linker
6788 script.  The linker will still copy these sections into the
6789 output file by either finding, or creating a suitable output section
6790 in which to place the orphaned input section.
6792 If the name of an orphaned input section exactly matches the name of
6793 an existing output section, then the orphaned input section will be
6794 placed at the end of that output section.
6796 If there is no output section with a matching name then new output
6797 sections will be created.  Each new output section will have the same
6798 name as the orphan section placed within it.  If there are multiple
6799 orphan sections with the same name, these will all be combined into
6800 one new output section.
6802 If new output sections are created to hold orphaned input sections,
6803 then the linker must decide where to place these new output sections
6804 in relation to existing output sections.  On most modern targets, the
6805 linker attempts to place orphan sections after sections of the same
6806 attribute, such as code vs data, loadable vs non-loadable, etc.  If no
6807 sections with matching attributes are found, or your target lacks this
6808 support, the orphan section is placed at the end of the file.
6810 The command-line options @samp{--orphan-handling} and @samp{--unique}
6811 (@pxref{Options,,Command-line Options}) can be used to control which
6812 output sections an orphan is placed in.
6814 @node Location Counter
6815 @subsection The Location Counter
6816 @kindex .
6817 @cindex dot
6818 @cindex location counter
6819 @cindex current output location
6820 The special linker variable @dfn{dot} @samp{.} always contains the
6821 current output location counter.  Since the @code{.} always refers to a
6822 location in an output section, it may only appear in an expression
6823 within a @code{SECTIONS} command.  The @code{.} symbol may appear
6824 anywhere that an ordinary symbol is allowed in an expression.
6826 @cindex holes
6827 Assigning a value to @code{.} will cause the location counter to be
6828 moved.  This may be used to create holes in the output section.  The
6829 location counter may not be moved backwards inside an output section,
6830 and may not be moved backwards outside of an output section if so
6831 doing creates areas with overlapping LMAs.
6833 @smallexample
6834 SECTIONS
6836   output :
6837     @{
6838       file1(.text)
6839       . = . + 1000;
6840       file2(.text)
6841       . += 1000;
6842       file3(.text)
6843     @} = 0x12345678;
6845 @end smallexample
6846 @noindent
6847 In the previous example, the @samp{.text} section from @file{file1} is
6848 located at the beginning of the output section @samp{output}.  It is
6849 followed by a 1000 byte gap.  Then the @samp{.text} section from
6850 @file{file2} appears, also with a 1000 byte gap following before the
6851 @samp{.text} section from @file{file3}.  The notation @samp{= 0x12345678}
6852 specifies what data to write in the gaps (@pxref{Output Section Fill}).
6854 @cindex dot inside sections
6855 Note: @code{.} actually refers to the byte offset from the start of the
6856 current containing object.  Normally this is the @code{SECTIONS}
6857 statement, whose start address is 0, hence @code{.} can be used as an
6858 absolute address.  If @code{.} is used inside a section description
6859 however, it refers to the byte offset from the start of that section,
6860 not an absolute address.  Thus in a script like this:
6862 @smallexample
6863 SECTIONS
6865     . = 0x100
6866     .text: @{
6867       *(.text)
6868       . = 0x200
6869     @}
6870     . = 0x500
6871     .data: @{
6872       *(.data)
6873       . += 0x600
6874     @}
6876 @end smallexample
6878 The @samp{.text} section will be assigned a starting address of 0x100
6879 and a size of exactly 0x200 bytes, even if there is not enough data in
6880 the @samp{.text} input sections to fill this area.  (If there is too
6881 much data, an error will be produced because this would be an attempt to
6882 move @code{.} backwards).  The @samp{.data} section will start at 0x500
6883 and it will have an extra 0x600 bytes worth of space after the end of
6884 the values from the @samp{.data} input sections and before the end of
6885 the @samp{.data} output section itself.
6887 @cindex dot outside sections
6888 Setting symbols to the value of the location counter outside of an
6889 output section statement can result in unexpected values if the linker
6890 needs to place orphan sections.  For example, given the following:
6892 @smallexample
6893 SECTIONS
6895     start_of_text = . ;
6896     .text: @{ *(.text) @}
6897     end_of_text = . ;
6899     start_of_data = . ;
6900     .data: @{ *(.data) @}
6901     end_of_data = . ;
6903 @end smallexample
6905 If the linker needs to place some input section, e.g. @code{.rodata},
6906 not mentioned in the script, it might choose to place that section
6907 between @code{.text} and @code{.data}.  You might think the linker
6908 should place @code{.rodata} on the blank line in the above script, but
6909 blank lines are of no particular significance to the linker.  As well,
6910 the linker doesn't associate the above symbol names with their
6911 sections.  Instead, it assumes that all assignments or other
6912 statements belong to the previous output section, except for the
6913 special case of an assignment to @code{.}.  I.e., the linker will
6914 place the orphan @code{.rodata} section as if the script was written
6915 as follows:
6917 @smallexample
6918 SECTIONS
6920     start_of_text = . ;
6921     .text: @{ *(.text) @}
6922     end_of_text = . ;
6924     start_of_data = . ;
6925     .rodata: @{ *(.rodata) @}
6926     .data: @{ *(.data) @}
6927     end_of_data = . ;
6929 @end smallexample
6931 This may or may not be the script author's intention for the value of
6932 @code{start_of_data}.  One way to influence the orphan section
6933 placement is to assign the location counter to itself, as the linker
6934 assumes that an assignment to @code{.} is setting the start address of
6935 a following output section and thus should be grouped with that
6936 section.  So you could write:
6938 @smallexample
6939 SECTIONS
6941     start_of_text = . ;
6942     .text: @{ *(.text) @}
6943     end_of_text = . ;
6945     . = . ;
6946     start_of_data = . ;
6947     .data: @{ *(.data) @}
6948     end_of_data = . ;
6950 @end smallexample
6952 Now, the orphan @code{.rodata} section will be placed between
6953 @code{end_of_text} and @code{start_of_data}.
6955 @need 2000
6956 @node Operators
6957 @subsection Operators
6958 @cindex operators for arithmetic
6959 @cindex arithmetic operators
6960 @cindex precedence in expressions
6961 The linker recognizes the standard C set of arithmetic operators, with
6962 the standard bindings and precedence levels:
6963 @c TEXI2ROFF-KILL
6964 @ifnottex
6965 @c END TEXI2ROFF-KILL
6966 @smallexample
6967 precedence      associativity   Operators                           Notes
6968 (highest)
6969 1               left            !  -  ~                             (1)
6970 2               left            *  /  %
6971 3               left            +  -
6972 4               left            >>  <<
6973 5               left            >  <  <=  >=
6974 6               left            ==  !=
6975 7               left            &
6976 8               left            ^
6977 9               left            |
6978 10              left            &&
6979 11              left            ||
6980 12              right           ? :
6981 13              right           +=  -=  *=  /=  <<=  >>=  &=  |= ^= (2)
6982 (lowest)
6983 @end smallexample
6984 Notes:
6985 (1) Prefix operators
6986 (2) @xref{Assignments}.
6987 @c TEXI2ROFF-KILL
6988 @end ifnottex
6989 @tex
6990 \vskip \baselineskip
6991 %"lispnarrowing" is the extra indent used generally for smallexample
6992 \hskip\lispnarrowing\vbox{\offinterlineskip
6993 \hrule
6994 \halign
6995 {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
6996 height2pt&\omit&&\omit&&\omit&\cr
6997 &Precedence&&  Associativity  &&{\rm Operators}&\cr
6998 height2pt&\omit&&\omit&&\omit&\cr
6999 \noalign{\hrule}
7000 height2pt&\omit&&\omit&&\omit&\cr
7001 &highest&&&&&\cr
7002 % '176 is tilde, '~' in tt font
7003 &1&&left&&\qquad-          \char'176\      !\qquad\dag&\cr
7004 &2&&left&&*          /        \%&\cr
7005 &3&&left&&+          -&\cr
7006 &4&&left&&>>         <<&\cr
7007 &5&&left&& >      <      <=      >=&\cr
7008 &6&&left&&==         !=&\cr
7009 &7&&left&&\&&\cr
7010 &8&&left&&\^{}&\cr
7011 &9&&left&&|&\cr
7012 &10&&left&&{\&\&}&\cr
7013 &11&&left&&||&\cr
7014 &12&&right&&?        :&\cr
7015 &13&&right&&\qquad +=       -=     *=     /= <<= >>= \&= |= \^{}=\qquad\ddag&\cr
7016 &lowest&&&&&\cr
7017 height2pt&\omit&&\omit&&\omit&\cr}
7018 \hrule}
7019 @end tex
7020 @iftex
7022 @obeylines@parskip=0pt@parindent=0pt
7023 @dag@quad Prefix operators.
7024 @ddag@quad @xref{Assignments}.
7026 @end iftex
7027 @c END TEXI2ROFF-KILL
7029 @node Evaluation
7030 @subsection Evaluation
7031 @cindex lazy evaluation
7032 @cindex expression evaluation order
7033 The linker evaluates expressions lazily.  It only computes the value of
7034 an expression when absolutely necessary.
7036 The linker needs some information, such as the value of the start
7037 address of the first section, and the origins and lengths of memory
7038 regions, in order to do any linking at all.  These values are computed
7039 as soon as possible when the linker reads in the linker script.
7041 However, other values (such as symbol values) are not known or needed
7042 until after storage allocation.  Such values are evaluated later, when
7043 other information (such as the sizes of output sections) is available
7044 for use in the symbol assignment expression.
7046 The sizes of sections cannot be known until after allocation, so
7047 assignments dependent upon these are not performed until after
7048 allocation.
7050 Some expressions, such as those depending upon the location counter
7051 @samp{.}, must be evaluated during section allocation.
7053 If the result of an expression is required, but the value is not
7054 available, then an error results.  For example, a script like the
7055 following
7056 @smallexample
7057 @group
7058 SECTIONS
7059   @{
7060     .text 9+this_isnt_constant :
7061       @{ *(.text) @}
7062   @}
7063 @end group
7064 @end smallexample
7065 @noindent
7066 will cause the error message @samp{non constant expression for initial
7067 address}.
7069 @node Expression Section
7070 @subsection The Section of an Expression
7071 @cindex expression sections
7072 @cindex absolute expressions
7073 @cindex relative expressions
7074 @cindex absolute and relocatable symbols
7075 @cindex relocatable and absolute symbols
7076 @cindex symbols, relocatable and absolute
7077 Addresses and symbols may be section relative, or absolute.  A section
7078 relative symbol is relocatable.  If you request relocatable output
7079 using the @samp{-r} option, a further link operation may change the
7080 value of a section relative symbol.  On the other hand, an absolute
7081 symbol will retain the same value throughout any further link
7082 operations.
7084 Some terms in linker expressions are addresses.  This is true of
7085 section relative symbols and for builtin functions that return an
7086 address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
7087 @code{SEGMENT_START}.  Other terms are simply numbers, or are builtin
7088 functions that return a non-address value, such as @code{LENGTH}.
7089 One complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
7090 (@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
7091 differently depending on their location, for compatibility with older
7092 versions of @code{ld}.  Expressions appearing outside an output
7093 section definition treat all numbers as absolute addresses.
7094 Expressions appearing inside an output section definition treat
7095 absolute symbols as numbers.  If @code{LD_FEATURE ("SANE_EXPR")} is
7096 given, then absolute symbols and numbers are simply treated as numbers
7097 everywhere.
7099 In the following simple example,
7101 @smallexample
7102 @group
7103 SECTIONS
7104   @{
7105     . = 0x100;
7106     __executable_start = 0x100;
7107     .data :
7108     @{
7109       . = 0x10;
7110       __data_start = 0x10;
7111       *(.data)
7112     @}
7113     @dots{}
7114   @}
7115 @end group
7116 @end smallexample
7118 both @code{.} and @code{__executable_start} are set to the absolute
7119 address 0x100 in the first two assignments, then both @code{.} and
7120 @code{__data_start} are set to 0x10 relative to the @code{.data}
7121 section in the second two assignments.
7123 For expressions involving numbers, relative addresses and absolute
7124 addresses, ld follows these rules to evaluate terms:
7126 @itemize @bullet
7127 @item
7128 Unary operations on an absolute address or number, and binary
7129 operations on two absolute addresses or two numbers, or between one
7130 absolute address and a number, apply the operator to the value(s).
7131 @item
7132 Unary operations on a relative address, and binary operations on two
7133 relative addresses in the same section or between one relative address
7134 and a number, apply the operator to the offset part of the address(es).
7135 @item
7136 Other binary operations, that is, between two relative addresses not
7137 in the same section, or between a relative address and an absolute
7138 address, first convert any non-absolute term to an absolute address
7139 before applying the operator.
7140 @end itemize
7142 The result section of each sub-expression is as follows:
7144 @itemize @bullet
7145 @item
7146 An operation involving only numbers results in a number.
7147 @item
7148 The result of comparisons, @samp{&&} and @samp{||} is also a number.
7149 @item
7150 The result of other binary arithmetic and logical operations on two
7151 relative addresses in the same section or two absolute addresses
7152 (after above conversions) is also a number when
7153 @code{LD_FEATURE ("SANE_EXPR")} or inside an output section definition
7154 but an absolute address otherwise.
7155 @item
7156 The result of other operations on relative addresses or one
7157 relative address and a number, is a relative address in the same
7158 section as the relative operand(s).
7159 @item
7160 The result of other operations on absolute addresses (after above
7161 conversions) is an absolute address.
7162 @end itemize
7164 You can use the builtin function @code{ABSOLUTE} to force an expression
7165 to be absolute when it would otherwise be relative.  For example, to
7166 create an absolute symbol set to the address of the end of the output
7167 section @samp{.data}:
7168 @smallexample
7169 SECTIONS
7170   @{
7171     .data : @{ *(.data) _edata = ABSOLUTE(.); @}
7172   @}
7173 @end smallexample
7174 @noindent
7175 If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
7176 @samp{.data} section.
7178 Using @code{LOADADDR} also forces an expression absolute, since this
7179 particular builtin function returns an absolute address.
7181 @node Builtin Functions
7182 @subsection Builtin Functions
7183 @cindex functions in expressions
7184 The linker script language includes a number of builtin functions for
7185 use in linker script expressions.
7187 @table @code
7188 @item ABSOLUTE(@var{exp})
7189 @kindex ABSOLUTE(@var{exp})
7190 @cindex expression, absolute
7191 Return the absolute (non-relocatable, as opposed to non-negative) value
7192 of the expression @var{exp}.  Primarily useful to assign an absolute
7193 value to a symbol within a section definition, where symbol values are
7194 normally section relative.  @xref{Expression Section}.
7196 @item ADDR(@var{section})
7197 @kindex ADDR(@var{section})
7198 @cindex section address in expression
7199 Return the address (VMA) of the named @var{section}.  Your
7200 script must previously have defined the location of that section.  In
7201 the following example, @code{start_of_output_1}, @code{symbol_1} and
7202 @code{symbol_2} are assigned equivalent values, except that
7203 @code{symbol_1} will be relative to the @code{.output1} section while
7204 the other two will be absolute:
7205 @smallexample
7206 @group
7207 SECTIONS @{ @dots{}
7208   .output1 :
7209     @{
7210     start_of_output_1 = ABSOLUTE(.);
7211     @dots{}
7212     @}
7213   .output :
7214     @{
7215     symbol_1 = ADDR(.output1);
7216     symbol_2 = start_of_output_1;
7217     @}
7218 @dots{} @}
7219 @end group
7220 @end smallexample
7222 @item ALIGN(@var{align})
7223 @itemx ALIGN(@var{exp},@var{align})
7224 @kindex ALIGN(@var{align})
7225 @kindex ALIGN(@var{exp},@var{align})
7226 @cindex round up location counter
7227 @cindex align location counter
7228 @cindex round up expression
7229 @cindex align expression
7230 Return the location counter (@code{.}) or arbitrary expression aligned
7231 to the next @var{align} boundary.  The single operand @code{ALIGN}
7232 doesn't change the value of the location counter---it just does
7233 arithmetic on it.  The two operand @code{ALIGN} allows an arbitrary
7234 expression to be aligned upwards (@code{ALIGN(@var{align})} is
7235 equivalent to @code{ALIGN(ABSOLUTE(.), @var{align})}).
7237 Here is an example which aligns the output @code{.data} section to the
7238 next @code{0x2000} byte boundary after the preceding section and sets a
7239 variable within the section to the next @code{0x8000} boundary after the
7240 input sections:
7241 @smallexample
7242 @group
7243 SECTIONS @{ @dots{}
7244   .data ALIGN(0x2000): @{
7245     *(.data)
7246     variable = ALIGN(0x8000);
7247   @}
7248 @dots{} @}
7249 @end group
7250 @end smallexample
7251 @noindent
7252 The first use of @code{ALIGN} in this example specifies the location of
7253 a section because it is used as the optional @var{address} attribute of
7254 a section definition (@pxref{Output Section Address}).  The second use
7255 of @code{ALIGN} is used to defines the value of a symbol.
7257 The builtin function @code{NEXT} is closely related to @code{ALIGN}.
7259 @item ALIGNOF(@var{section})
7260 @kindex ALIGNOF(@var{section})
7261 @cindex section alignment
7262 Return the alignment in bytes of the named @var{section}, if that section has
7263 been allocated, or zero if the section has not been allocated.  If the
7264 section does not exist in the linker script the linker will report an
7265 error.  If @var{section} is @code{NEXT_SECTION} then @code{ALIGNOF} will
7266 return the alignment of the next allocated section specified in the
7267 linker script, or zero if there is no such section.  In the following
7268 example, the alignment of the @code{.output} section is stored as the
7269 first value in that section.
7270 @smallexample
7271 @group
7272 SECTIONS@{ @dots{}
7273   .output @{
7274     LONG (ALIGNOF (.output))
7275     @dots{}
7276     @}
7277 @dots{} @}
7278 @end group
7279 @end smallexample
7281 @item BLOCK(@var{exp})
7282 @kindex BLOCK(@var{exp})
7283 This is a synonym for @code{ALIGN}, for compatibility with older linker
7284 scripts.  It is most often seen when setting the address of an output
7285 section.
7287 @item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7288 @kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
7289 This is equivalent to either
7290 @smallexample
7291 (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
7292 @end smallexample
7294 @smallexample
7295 (ALIGN(@var{maxpagesize})
7296  + ((. + @var{commonpagesize} - 1) & (@var{maxpagesize} - @var{commonpagesize})))
7297 @end smallexample
7298 @noindent
7299 depending on whether the latter uses fewer @var{commonpagesize} sized pages
7300 for the data segment (area between the result of this expression and
7301 @code{DATA_SEGMENT_END}) than the former or not.
7302 If the latter form is used, it means @var{commonpagesize} bytes of runtime
7303 memory will be saved at the expense of up to @var{commonpagesize} wasted
7304 bytes in the on-disk file.
7306 This expression can only be used directly in @code{SECTIONS} commands, not in
7307 any output section descriptions and only once in the linker script.
7308 @var{commonpagesize} should be less or equal to @var{maxpagesize} and should
7309 be the system page size the object wants to be optimized for while still
7310 running on system page sizes up to @var{maxpagesize}.  Note however
7311 that @samp{-z relro} protection will not be effective if the system
7312 page size is larger than @var{commonpagesize}.
7314 @noindent
7315 Example:
7316 @smallexample
7317   . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
7318 @end smallexample
7320 @item DATA_SEGMENT_END(@var{exp})
7321 @kindex DATA_SEGMENT_END(@var{exp})
7322 This defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
7323 evaluation purposes.
7325 @smallexample
7326   . = DATA_SEGMENT_END(.);
7327 @end smallexample
7329 @item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7330 @kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
7331 This defines the end of the @code{PT_GNU_RELRO} segment when
7332 @samp{-z relro} option is used.
7333 When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
7334 does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
7335 @var{exp} + @var{offset} is aligned to the @var{commonpagesize}
7336 argument given to @code{DATA_SEGMENT_ALIGN}.  If present in the linker
7337 script, it must be placed between @code{DATA_SEGMENT_ALIGN} and
7338 @code{DATA_SEGMENT_END}.  Evaluates to the second argument plus any
7339 padding needed at the end of the @code{PT_GNU_RELRO} segment due to
7340 section alignment.
7342 @smallexample
7343   . = DATA_SEGMENT_RELRO_END(24, .);
7344 @end smallexample
7346 @item DEFINED(@var{symbol})
7347 @kindex DEFINED(@var{symbol})
7348 @cindex symbol defaults
7349 Return 1 if @var{symbol} is in the linker global symbol table and is
7350 defined before the statement using DEFINED in the script, otherwise
7351 return 0.  You can use this function to provide
7352 default values for symbols.  For example, the following script fragment
7353 shows how to set a global symbol @samp{begin} to the first location in
7354 the @samp{.text} section---but if a symbol called @samp{begin} already
7355 existed, its value is preserved:
7357 @smallexample
7358 @group
7359 SECTIONS @{ @dots{}
7360   .text : @{
7361     begin = DEFINED(begin) ? begin : . ;
7362     @dots{}
7363   @}
7364   @dots{}
7366 @end group
7367 @end smallexample
7369 @item LENGTH(@var{memory})
7370 @kindex LENGTH(@var{memory})
7371 Return the length of the memory region named @var{memory}.
7373 @item LOADADDR(@var{section})
7374 @kindex LOADADDR(@var{section})
7375 @cindex section load address in expression
7376 Return the absolute LMA of the named @var{section}.  (@pxref{Output
7377 Section LMA}).
7379 @item LOG2CEIL(@var{exp})
7380 @kindex LOG2CEIL(@var{exp})
7381 Return the binary logarithm of @var{exp} rounded towards infinity.
7382 @code{LOG2CEIL(0)} returns 0.
7384 @kindex MAX
7385 @item MAX(@var{exp1}, @var{exp2})
7386 Returns the maximum of @var{exp1} and @var{exp2}.
7388 @kindex MIN
7389 @item MIN(@var{exp1}, @var{exp2})
7390 Returns the minimum of @var{exp1} and @var{exp2}.
7392 @item NEXT(@var{exp})
7393 @kindex NEXT(@var{exp})
7394 @cindex unallocated address, next
7395 Return the next unallocated address that is a multiple of @var{exp}.
7396 This function is closely related to @code{ALIGN(@var{exp})}; unless you
7397 use the @code{MEMORY} command to define discontinuous memory for the
7398 output file, the two functions are equivalent.
7400 @item ORIGIN(@var{memory})
7401 @kindex ORIGIN(@var{memory})
7402 Return the origin of the memory region named @var{memory}.
7404 @item SEGMENT_START(@var{segment}, @var{default})
7405 @kindex SEGMENT_START(@var{segment}, @var{default})
7406 Return the base address of the named @var{segment}.  If an explicit
7407 value has already been given for this segment (with a command-line
7408 @samp{-T} option) then that value will be returned otherwise the value
7409 will be @var{default}.  At present, the @samp{-T} command-line option
7410 can only be used to set the base address for the ``text'', ``data'', and
7411 ``bss'' sections, but you can use @code{SEGMENT_START} with any segment
7412 name.
7414 @item SIZEOF(@var{section})
7415 @kindex SIZEOF(@var{section})
7416 @cindex section size
7417 Return the size in bytes of the named @var{section}, if that section has
7418 been allocated, or zero if the section has not been allocated.  If the
7419 section does not exist in the linker script the linker will report an
7420 error.  If @var{section} is @code{NEXT_SECTION} then @code{SIZEOF} will
7421 return the alignment of the next allocated section specified in the
7422 linker script, or zero if there is no such section.  In the following
7423 example, @code{symbol_1} and @code{symbol_2} are assigned identical
7424 values:
7425 @smallexample
7426 @group
7427 SECTIONS@{ @dots{}
7428   .output @{
7429     .start = . ;
7430     @dots{}
7431     .end = . ;
7432     @}
7433   symbol_1 = .end - .start ;
7434   symbol_2 = SIZEOF(.output);
7435 @dots{} @}
7436 @end group
7437 @end smallexample
7439 @item SIZEOF_HEADERS
7440 @kindex SIZEOF_HEADERS
7441 @cindex header size
7442 Return the size in bytes of the output file's headers.  This is
7443 information which appears at the start of the output file.  You can use
7444 this number when setting the start address of the first section, if you
7445 choose, to facilitate paging.
7447 @cindex not enough room for program headers
7448 @cindex program headers, not enough room
7449 When producing an ELF output file, if the linker script uses the
7450 @code{SIZEOF_HEADERS} builtin function, the linker must compute the
7451 number of program headers before it has determined all the section
7452 addresses and sizes.  If the linker later discovers that it needs
7453 additional program headers, it will report an error @samp{not enough
7454 room for program headers}.  To avoid this error, you must avoid using
7455 the @code{SIZEOF_HEADERS} function, or you must rework your linker
7456 script to avoid forcing the linker to use additional program headers, or
7457 you must define the program headers yourself using the @code{PHDRS}
7458 command (@pxref{PHDRS}).
7459 @end table
7461 @node Implicit Linker Scripts
7462 @section Implicit Linker Scripts
7463 @cindex implicit linker scripts
7464 If you specify a linker input file which the linker can not recognize as
7465 an object file or an archive file, it will try to read the file as a
7466 linker script.  If the file can not be parsed as a linker script, the
7467 linker will report an error.
7469 An implicit linker script will not replace the default linker script.
7471 Typically an implicit linker script would contain only symbol
7472 assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
7473 commands.
7475 Any input files read because of an implicit linker script will be read
7476 at the position in the command line where the implicit linker script was
7477 read.  This can affect archive searching.
7479 @node Plugins
7480 @chapter Linker Plugins
7482 @cindex plugins
7483 @cindex linker plugins
7484 The linker can use dynamically loaded plugins to modify its behavior.
7485 For example, the link-time optimization feature that some compilers
7486 support is implemented with a linker plugin.
7488 Currently there is only one plugin shipped by default, but more may
7489 be added here later.
7491 Plugins are enabled via the use of the @option{-plugin @var{name}}
7492 command line option. @xref{Options}.
7494 @menu
7495 * libdep Plugin::       Static Library Dependencies Plugin
7496 @end menu
7498 @node libdep Plugin
7499 @section Static Library Dependencies Plugin
7500 @cindex static library dependencies
7501 Originally, static libraries were contained in an archive file consisting
7502 just of a collection of relocatable object files.  Later they evolved to
7503 optionally include a symbol table, to assist in finding the needed objects
7504 within a library.  There their evolution ended, and dynamic libraries
7505 rose to ascendance.
7507 One useful feature of dynamic libraries was that, more than just collecting
7508 multiple objects into a single file, they also included a list of their
7509 dependencies, such that one could specify just the name of a single dynamic
7510 library at link time, and all of its dependencies would be implicitly
7511 referenced as well.  But static libraries lacked this feature, so if a
7512 link invocation was switched from using dynamic libraries to static
7513 libraries, the link command would usually fail unless it was rewritten to
7514 explicitly list the dependencies of the static library.
7516 The GNU @command{ar} utility now supports a @option{--record-libdeps} option
7517 to embed dependency lists into static libraries as well, and the @file{libdep}
7518 plugin may be used to read this dependency information at link time.  The
7519 dependency information is stored as a single string, carrying @option{-l}
7520 and @option{-L} arguments as they would normally appear in a linker
7521 command line.  As such, the information can be written with any text
7522 utility and stored into any archive, even if GNU @command{ar} is not
7523 being used to create the archive.  The information is stored in an
7524 archive member named @samp{__.LIBDEP}.
7526 For example, given a library @file{libssl.a} that depends on another
7527 library @file{libcrypto.a} which may be found in @file{/usr/local/lib},
7528 the @samp{__.LIBDEP} member of @file{libssl.a} would contain
7530 @smallexample
7531 -L/usr/local/lib -lcrypto
7532 @end smallexample
7534 @node Special Sections
7535 @chapter Special Sections
7536 When linking ELF format object files @command{ld} treats some sections
7537 in a special, non standard manner.  This part of the manual describes
7538 these sections.
7540 @table @gcctabopt
7541 @item .gnu.warning
7542 The contents of any section with this name are assumed to be an ascii
7543 format warning message.  The contents will be displayed to the user if
7544 the sections appears in any input file, but the section will not be
7545 copied into the output image.  If the @option{--fatal-warnings} option
7546 is enabled then the warnings - if any are encountered - will also stop
7547 the link from completing.
7549 Note - the @samp{.gnu.warning} section is not subject to linker
7550 garbage collection or orphan handling.
7552 @item .gnu.warning.@var{SYM}
7553 The contents of any section whoes name starts with the prefix
7554 @samp{.gnu.warning.} and then finishes with the name of a symbol is
7555 treated in a similar fashion to the @samp{.gnu.warning} section, but
7556 only if the named symbol is referenced.  So for example the contents
7557 of a section called @samp{.gnu.warning.foo} will be displayed as
7558 warning message if, and only if, the symbol @samp{foo} is referenced
7559 by one or more of the input files.  This includes object files pulled
7560 in from static libraries, shared objects needed to complete the link
7561 and so on.
7563 Note - because these warning messages are generated before the linker
7564 performs garbage collection (if enabled) it is possible for a warning
7565 to be displayed for a symbol that is later removed and then never
7566 appears in the final output.
7568 @item .note.gnu.property
7569 When the linker combines sections of this name it will merge them
7570 together according to various rules encoded into the notes
7571 themselves.  Therefore the contents of the output .note.gnu.property
7572 section may not correspond to a simple concatenation of the input
7573 sections.  If the @option{-Map} option has been used to request a
7574 linker map then details of any property merging will be included in
7575 the map.
7577 @end table
7579 @ifset GENERIC
7580 @node Machine Dependent
7581 @chapter Machine Dependent Features
7583 @cindex machine dependencies
7584 @command{ld} has additional features on some platforms; the following
7585 sections describe them.  Machines where @command{ld} has no additional
7586 functionality are not listed.
7588 @menu
7589 @ifset H8300
7590 * H8/300::                      @command{ld} and the H8/300
7591 @end ifset
7592 @ifset M68HC11
7593 * M68HC11/68HC12::              @code{ld} and the Motorola 68HC11 and 68HC12 families
7594 @end ifset
7595 @ifset ARM
7596 * ARM::                         @command{ld} and the ARM family
7597 @end ifset
7598 @ifset HPPA
7599 * HPPA ELF32::                  @command{ld} and HPPA 32-bit ELF
7600 @end ifset
7601 @ifset M68K
7602 * M68K::                        @command{ld} and the Motorola 68K family
7603 @end ifset
7604 @ifset MIPS
7605 * MIPS::                        @command{ld} and the MIPS family
7606 @end ifset
7607 @ifset MMIX
7608 * MMIX::                        @command{ld} and MMIX
7609 @end ifset
7610 @ifset MSP430
7611 * MSP430::                      @command{ld} and MSP430
7612 @end ifset
7613 @ifset NDS32
7614 * NDS32::                       @command{ld} and NDS32
7615 @end ifset
7616 @ifset NIOSII
7617 * Nios II::                     @command{ld} and the Altera Nios II
7618 @end ifset
7619 @ifset POWERPC
7620 * PowerPC ELF32::               @command{ld} and PowerPC 32-bit ELF Support
7621 @end ifset
7622 @ifset POWERPC64
7623 * PowerPC64 ELF64::             @command{ld} and PowerPC64 64-bit ELF Support
7624 @end ifset
7625 @ifset S/390
7626 * S/390 ELF::                   @command{ld} and S/390 ELF Support
7627 @end ifset
7628 @ifset SPU
7629 * SPU ELF::                     @command{ld} and SPU ELF Support
7630 @end ifset
7631 @ifset TICOFF
7632 * TI COFF::                     @command{ld} and TI COFF
7633 @end ifset
7634 @ifset WIN32
7635 * WIN32::                       @command{ld} and WIN32 (cygwin/mingw)
7636 @end ifset
7637 @ifset XTENSA
7638 * Xtensa::                      @command{ld} and Xtensa Processors
7639 @end ifset
7640 @end menu
7641 @end ifset
7643 @ifset H8300
7644 @ifclear GENERIC
7645 @raisesections
7646 @end ifclear
7648 @node H8/300
7649 @section @command{ld} and the H8/300
7651 @cindex H8/300 support
7652 For the H8/300, @command{ld} can perform these global optimizations when
7653 you specify the @samp{--relax} command-line option.
7655 @table @emph
7656 @cindex relaxing on H8/300
7657 @item relaxing address modes
7658 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7659 targets are within eight bits, and turns them into eight-bit
7660 program-counter relative @code{bsr} and @code{bra} instructions,
7661 respectively.
7663 @cindex synthesizing on H8/300
7664 @item synthesizing instructions
7665 @c FIXME: specifically mov.b, or any mov instructions really? -> mov.b only, at least on H8, H8H, H8S
7666 @command{ld} finds all @code{mov.b} instructions which use the
7667 sixteen-bit absolute address form, but refer to the top
7668 page of memory, and changes them to use the eight-bit address form.
7669 (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
7670 @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
7671 top page of memory).
7673 @command{ld} finds all @code{mov} instructions which use the register
7674 indirect with 32-bit displacement addressing mode, but use a small
7675 displacement inside 16-bit displacement range, and changes them to use
7676 the 16-bit displacement form.  (That is: the linker turns @samp{mov.b
7677 @code{@@}@var{d}:32,ERx} into @samp{mov.b @code{@@}@var{d}:16,ERx}
7678 whenever the displacement @var{d} is in the 16 bit signed integer
7679 range. Only implemented in ELF-format ld).
7681 @item bit manipulation instructions
7682 @command{ld} finds all bit manipulation instructions like @code{band, bclr,
7683 biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor}
7684 which use 32 bit and 16 bit absolute address form, but refer to the top
7685 page of memory, and changes them to use the 8 bit address form.
7686 (That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into
7687 @samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in
7688 the top page of memory).
7690 @item system control instructions
7691 @command{ld} finds all @code{ldc.w, stc.w} instructions which use the
7692 32 bit absolute address form, but refer to the top page of memory, and
7693 changes them to use 16 bit address form.
7694 (That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into
7695 @samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in
7696 the top page of memory).
7697 @end table
7699 @ifclear GENERIC
7700 @lowersections
7701 @end ifclear
7702 @end ifset
7704 @ifclear GENERIC
7705 @ifset Renesas
7706 @c This stuff is pointless to say unless you're especially concerned
7707 @c with Renesas chips; don't enable it for generic case, please.
7708 @node Renesas
7709 @chapter @command{ld} and Other Renesas Chips
7711 @command{ld} also supports the Renesas (formerly Hitachi) H8/300H,
7712 H8/500, and SH chips.  No special features, commands, or command-line
7713 options are required for these chips.
7714 @end ifset
7715 @end ifclear
7717 @ifset ARM
7718 @ifclear GENERIC
7719 @raisesections
7720 @end ifclear
7722 @ifset M68HC11
7723 @ifclear GENERIC
7724 @raisesections
7725 @end ifclear
7727 @node M68HC11/68HC12
7728 @section @command{ld} and the Motorola 68HC11 and 68HC12 families
7730 @cindex M68HC11 and 68HC12 support
7732 @subsection Linker Relaxation
7734 For the Motorola 68HC11, @command{ld} can perform these global
7735 optimizations when you specify the @samp{--relax} command-line option.
7737 @table @emph
7738 @cindex relaxing on M68HC11
7739 @item relaxing address modes
7740 @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
7741 targets are within eight bits, and turns them into eight-bit
7742 program-counter relative @code{bsr} and @code{bra} instructions,
7743 respectively.
7745 @command{ld} also looks at all 16-bit extended addressing modes and
7746 transforms them in a direct addressing mode when the address is in
7747 page 0 (between 0 and 0x0ff).
7749 @item relaxing gcc instruction group
7750 When @command{gcc} is called with @option{-mrelax}, it can emit group
7751 of instructions that the linker can optimize to use a 68HC11 direct
7752 addressing mode. These instructions consists of @code{bclr} or
7753 @code{bset} instructions.
7755 @end table
7757 @subsection Trampoline Generation
7759 @cindex trampoline generation on M68HC11
7760 @cindex trampoline generation on M68HC12
7761 For 68HC11 and 68HC12, @command{ld} can generate trampoline code to
7762 call a far function using a normal @code{jsr} instruction. The linker
7763 will also change the relocation to some far function to use the
7764 trampoline address instead of the function address. This is typically the
7765 case when a pointer to a function is taken. The pointer will in fact
7766 point to the function trampoline.
7768 @ifclear GENERIC
7769 @lowersections
7770 @end ifclear
7771 @end ifset
7773 @node ARM
7774 @section @command{ld} and the ARM family
7776 @cindex ARM interworking support
7777 @kindex --support-old-code
7778 For the ARM, @command{ld} will generate code stubs to allow functions calls
7779 between ARM and Thumb code.  These stubs only work with code that has
7780 been compiled and assembled with the @samp{-mthumb-interwork} command
7781 line option.  If it is necessary to link with old ARM object files or
7782 libraries, which have not been compiled with the -mthumb-interwork
7783 option then the @samp{--support-old-code} command-line switch should be
7784 given to the linker.  This will make it generate larger stub functions
7785 which will work with non-interworking aware ARM code.  Note, however,
7786 the linker does not support generating stubs for function calls to
7787 non-interworking aware Thumb code.
7789 @cindex thumb entry point
7790 @cindex entry point, thumb
7791 @kindex --thumb-entry=@var{entry}
7792 The @samp{--thumb-entry} switch is a duplicate of the generic
7793 @samp{--entry} switch, in that it sets the program's starting address.
7794 But it also sets the bottom bit of the address, so that it can be
7795 branched to using a BX instruction, and the program will start
7796 executing in Thumb mode straight away.
7798 @cindex PE import table prefixing
7799 @kindex --use-nul-prefixed-import-tables
7800 The @samp{--use-nul-prefixed-import-tables} switch is specifying, that
7801 the import tables idata4 and idata5 have to be generated with a zero
7802 element prefix for import libraries. This is the old style to generate
7803 import tables. By default this option is turned off.
7805 @cindex BE8
7806 @kindex --be8
7807 The @samp{--be8} switch instructs @command{ld} to generate BE8 format
7808 executables.  This option is only valid when linking big-endian
7809 objects - ie ones which have been assembled with the @option{-EB}
7810 option.  The resulting image will contain big-endian data and
7811 little-endian code.
7813 @cindex TARGET1
7814 @kindex --target1-rel
7815 @kindex --target1-abs
7816 The @samp{R_ARM_TARGET1} relocation is typically used for entries in the
7817 @samp{.init_array} section.  It is interpreted as either @samp{R_ARM_REL32}
7818 or @samp{R_ARM_ABS32}, depending on the target.  The @samp{--target1-rel}
7819 and @samp{--target1-abs} switches override the default.
7821 @cindex TARGET2
7822 @kindex --target2=@var{type}
7823 The @samp{--target2=type} switch overrides the default definition of the
7824 @samp{R_ARM_TARGET2} relocation.  Valid values for @samp{type}, their
7825 meanings, and target defaults are as follows:
7826 @table @samp
7827 @item rel
7828 @samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
7829 @item abs
7830 @samp{R_ARM_ABS32}
7831 @item got-rel
7832 @samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
7833 @end table
7835 @cindex FIX_V4BX
7836 @kindex --fix-v4bx
7837 The @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
7838 specification) enables objects compiled for the ARMv4 architecture to be
7839 interworking-safe when linked with other objects compiled for ARMv4t, but
7840 also allows pure ARMv4 binaries to be built from the same ARMv4 objects.
7842 In the latter case, the switch @option{--fix-v4bx} must be passed to the
7843 linker, which causes v4t @code{BX rM} instructions to be rewritten as
7844 @code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
7846 In the former case, the switch should not be used, and @samp{R_ARM_V4BX}
7847 relocations are ignored.
7849 @cindex FIX_V4BX_INTERWORKING
7850 @kindex --fix-v4bx-interworking
7851 Replace @code{BX rM} instructions identified by @samp{R_ARM_V4BX}
7852 relocations with a branch to the following veneer:
7854 @smallexample
7855 TST rM, #1
7856 MOVEQ PC, rM
7857 BX Rn
7858 @end smallexample
7860 This allows generation of libraries/applications that work on ARMv4 cores
7861 and are still interworking safe.  Note that the above veneer clobbers the
7862 condition flags, so may cause incorrect program behavior in rare cases.
7864 @cindex USE_BLX
7865 @kindex --use-blx
7866 The @samp{--use-blx} switch enables the linker to use ARM/Thumb
7867 BLX instructions (available on ARMv5t and above) in various
7868 situations. Currently it is used to perform calls via the PLT from Thumb
7869 code using BLX rather than using BX and a mode-switching stub before
7870 each PLT entry. This should lead to such calls executing slightly faster.
7872 @cindex VFP11_DENORM_FIX
7873 @kindex --vfp11-denorm-fix
7874 The @samp{--vfp11-denorm-fix} switch enables a link-time workaround for a
7875 bug in certain VFP11 coprocessor hardware, which sometimes allows
7876 instructions with denorm operands (which must be handled by support code)
7877 to have those operands overwritten by subsequent instructions before
7878 the support code can read the intended values.
7880 The bug may be avoided in scalar mode if you allow at least one
7881 intervening instruction between a VFP11 instruction which uses a register
7882 and another instruction which writes to the same register, or at least two
7883 intervening instructions if vector mode is in use. The bug only affects
7884 full-compliance floating-point mode: you do not need this workaround if
7885 you are using "runfast" mode. Please contact ARM for further details.
7887 If you know you are using buggy VFP11 hardware, you can
7888 enable this workaround by specifying the linker option
7889 @samp{--vfp-denorm-fix=scalar} if you are using the VFP11 scalar
7890 mode only, or @samp{--vfp-denorm-fix=vector} if you are using
7891 vector mode (the latter also works for scalar code). The default is
7892 @samp{--vfp-denorm-fix=none}.
7894 If the workaround is enabled, instructions are scanned for
7895 potentially-troublesome sequences, and a veneer is created for each
7896 such sequence which may trigger the erratum. The veneer consists of the
7897 first instruction of the sequence and a branch back to the subsequent
7898 instruction. The original instruction is then replaced with a branch to
7899 the veneer. The extra cycles required to call and return from the veneer
7900 are sufficient to avoid the erratum in both the scalar and vector cases.
7902 @cindex ARM1176 erratum workaround
7903 @kindex --fix-arm1176
7904 @kindex --no-fix-arm1176
7905 The @samp{--fix-arm1176} switch enables a link-time workaround for an erratum
7906 in certain ARM1176 processors.  The workaround is enabled by default if you
7907 are targeting ARM v6 (excluding ARM v6T2) or earlier.  It can be disabled
7908 unconditionally by specifying @samp{--no-fix-arm1176}.
7910 Further information is available in the ``ARM1176JZ-S and ARM1176JZF-S
7911 Programmer Advice Notice'' available on the ARM documentation website at:
7912 http://infocenter.arm.com/.
7914 @cindex STM32L4xx erratum workaround
7915 @kindex --fix-stm32l4xx-629360
7917 The @samp{--fix-stm32l4xx-629360} switch enables a link-time
7918 workaround for a bug in the bus matrix / memory controller for some of
7919 the STM32 Cortex-M4 based products (STM32L4xx).  When accessing
7920 off-chip memory via the affected bus for bus reads of 9 words or more,
7921 the bus can generate corrupt data and/or abort.  These are only
7922 core-initiated accesses (not DMA), and might affect any access:
7923 integer loads such as LDM, POP and floating-point loads such as VLDM,
7924 VPOP.  Stores are not affected.
7926 The bug can be avoided by splitting memory accesses into the
7927 necessary chunks to keep bus reads below 8 words.
7929 The workaround is not enabled by default, this is equivalent to use
7930 @samp{--fix-stm32l4xx-629360=none}.  If you know you are using buggy
7931 STM32L4xx hardware, you can enable the workaround by specifying the
7932 linker option @samp{--fix-stm32l4xx-629360}, or the equivalent
7933 @samp{--fix-stm32l4xx-629360=default}.
7935 If the workaround is enabled, instructions are scanned for
7936 potentially-troublesome sequences, and a veneer is created for each
7937 such sequence which may trigger the erratum.  The veneer consists in a
7938 replacement sequence emulating the behaviour of the original one and a
7939 branch back to the subsequent instruction.  The original instruction is
7940 then replaced with a branch to the veneer.
7942 The workaround does not always preserve the memory access order for
7943 the LDMDB instruction, when the instruction loads the PC.
7945 The workaround is not able to handle problematic instructions when
7946 they are in the middle of an IT block, since a branch is not allowed
7947 there.  In that case, the linker reports a warning and no replacement
7948 occurs.
7950 The workaround is not able to replace problematic instructions with a
7951 PC-relative branch instruction if the @samp{.text} section is too
7952 large.  In that case, when the branch that replaces the original code
7953 cannot be encoded, the linker reports a warning and no replacement
7954 occurs.
7956 @cindex NO_ENUM_SIZE_WARNING
7957 @kindex --no-enum-size-warning
7958 The @option{--no-enum-size-warning} switch prevents the linker from
7959 warning when linking object files that specify incompatible EABI
7960 enumeration size attributes.  For example, with this switch enabled,
7961 linking of an object file using 32-bit enumeration values with another
7962 using enumeration values fitted into the smallest possible space will
7963 not be diagnosed.
7965 @cindex NO_WCHAR_SIZE_WARNING
7966 @kindex --no-wchar-size-warning
7967 The @option{--no-wchar-size-warning} switch prevents the linker from
7968 warning when linking object files that specify incompatible EABI
7969 @code{wchar_t} size attributes.  For example, with this switch enabled,
7970 linking of an object file using 32-bit @code{wchar_t} values with another
7971 using 16-bit @code{wchar_t} values will not be diagnosed.
7973 @cindex PIC_VENEER
7974 @kindex --pic-veneer
7975 The @samp{--pic-veneer} switch makes the linker use PIC sequences for
7976 ARM/Thumb interworking veneers, even if the rest of the binary
7977 is not PIC.  This avoids problems on uClinux targets where
7978 @samp{--emit-relocs} is used to generate relocatable binaries.
7980 @cindex STUB_GROUP_SIZE
7981 @kindex --stub-group-size=@var{N}
7982 The linker will automatically generate and insert small sequences of
7983 code into a linked ARM ELF executable whenever an attempt is made to
7984 perform a function call to a symbol that is too far away.  The
7985 placement of these sequences of instructions - called stubs - is
7986 controlled by the command-line option @option{--stub-group-size=N}.
7987 The placement is important because a poor choice can create a need for
7988 duplicate stubs, increasing the code size.  The linker will try to
7989 group stubs together in order to reduce interruptions to the flow of
7990 code, but it needs guidance as to how big these groups should be and
7991 where they should be placed.
7993 The value of @samp{N}, the parameter to the
7994 @option{--stub-group-size=} option controls where the stub groups are
7995 placed.  If it is negative then all stubs are placed after the first
7996 branch that needs them.  If it is positive then the stubs can be
7997 placed either before or after the branches that need them.  If the
7998 value of @samp{N} is 1 (either +1 or -1) then the linker will choose
7999 exactly where to place groups of stubs, using its built in heuristics.
8000 A value of @samp{N} greater than 1 (or smaller than -1) tells the
8001 linker that a single group of stubs can service at most @samp{N} bytes
8002 from the input sections.
8004 The default, if @option{--stub-group-size=} is not specified, is
8005 @samp{N = +1}.
8007 Farcalls stubs insertion is fully supported for the ARM-EABI target
8008 only, because it relies on object files properties not present
8009 otherwise.
8011 @cindex Cortex-A8 erratum workaround
8012 @kindex --fix-cortex-a8
8013 @kindex --no-fix-cortex-a8
8014 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}.
8016 The erratum only affects Thumb-2 code.  Please contact ARM for further details.
8018 @cindex Cortex-A53 erratum 835769 workaround
8019 @kindex --fix-cortex-a53-835769
8020 @kindex --no-fix-cortex-a53-835769
8021 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}.
8023 Please contact ARM for further details.
8025 @kindex --merge-exidx-entries
8026 @kindex --no-merge-exidx-entries
8027 @cindex Merging exidx entries
8028 The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent exidx entries in debuginfo.
8030 @kindex --long-plt
8031 @cindex 32-bit PLT entries
8032 The @samp{--long-plt} option enables the use of 16 byte PLT entries
8033 which support up to 4Gb of code.  The default is to use 12 byte PLT
8034 entries which only support 512Mb of code.
8036 @kindex --no-apply-dynamic-relocs
8037 @cindex AArch64 rela addend
8038 The @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
8039 link-time values for dynamic relocations.
8041 @cindex Placement of SG veneers
8042 All SG veneers are placed in the special output section @code{.gnu.sgstubs}.
8043 Its start address must be set, either with the command-line option
8044 @samp{--section-start} or in a linker script, to indicate where to place these
8045 veneers in memory.
8047 @kindex --cmse-implib
8048 @cindex Secure gateway import library
8049 The @samp{--cmse-implib} option requests that the import libraries
8050 specified by the @samp{--out-implib} and @samp{--in-implib} options are
8051 secure gateway import libraries, suitable for linking a non-secure
8052 executable against secure code as per ARMv8-M Security Extensions.
8054 @kindex --in-implib=@var{file}
8055 @cindex Input import library
8056 The @samp{--in-implib=file} specifies an input import library whose symbols
8057 must keep the same address in the executable being produced.  A warning is
8058 given if no @samp{--out-implib} is given but new symbols have been introduced
8059 in the executable that should be listed in its import library.  Otherwise, if
8060 @samp{--out-implib} is specified, the symbols are added to the output import
8061 library.  A warning is also given if some symbols present in the input import
8062 library have disappeared from the executable.  This option is only effective
8063 for Secure Gateway import libraries, ie. when @samp{--cmse-implib} is
8064 specified.
8066 @ifclear GENERIC
8067 @lowersections
8068 @end ifclear
8069 @end ifset
8071 @ifset HPPA
8072 @ifclear GENERIC
8073 @raisesections
8074 @end ifclear
8076 @node HPPA ELF32
8077 @section @command{ld} and HPPA 32-bit ELF Support
8078 @cindex HPPA multiple sub-space stubs
8079 @kindex --multi-subspace
8080 When generating a shared library, @command{ld} will by default generate
8081 import stubs suitable for use with a single sub-space application.
8082 The @samp{--multi-subspace} switch causes @command{ld} to generate export
8083 stubs, and different (larger) import stubs suitable for use with
8084 multiple sub-spaces.
8086 @cindex HPPA stub grouping
8087 @kindex --stub-group-size=@var{N}
8088 Long branch stubs and import/export stubs are placed by @command{ld} in
8089 stub sections located between groups of input sections.
8090 @samp{--stub-group-size} specifies the maximum size of a group of input
8091 sections handled by one stub section.  Since branch offsets are signed,
8092 a stub section may serve two groups of input sections, one group before
8093 the stub section, and one group after it.  However, when using
8094 conditional branches that require stubs, it may be better (for branch
8095 prediction) that stub sections only serve one group of input sections.
8096 A negative value for @samp{N} chooses this scheme, ensuring that
8097 branches to stubs always use a negative offset.  Two special values of
8098 @samp{N} are recognized, @samp{1} and @samp{-1}.  These both instruct
8099 @command{ld} to automatically size input section groups for the branch types
8100 detected, with the same behaviour regarding stub placement as other
8101 positive or negative values of @samp{N} respectively.
8103 Note that @samp{--stub-group-size} does not split input sections.  A
8104 single input section larger than the group size specified will of course
8105 create a larger group (of one section).  If input sections are too
8106 large, it may not be possible for a branch to reach its stub.
8108 @ifclear GENERIC
8109 @lowersections
8110 @end ifclear
8111 @end ifset
8113 @ifset M68K
8114 @ifclear GENERIC
8115 @raisesections
8116 @end ifclear
8118 @node M68K
8119 @section @command{ld} and the Motorola 68K family
8121 @cindex Motorola 68K GOT generation
8122 @kindex --got=@var{type}
8123 The @samp{--got=@var{type}} option lets you choose the GOT generation scheme.
8124 The choices are @samp{single}, @samp{negative}, @samp{multigot} and
8125 @samp{target}.  When @samp{target} is selected the linker chooses
8126 the default GOT generation scheme for the current target.
8127 @samp{single} tells the linker to generate a single GOT with
8128 entries only at non-negative offsets.
8129 @samp{negative} instructs the linker to generate a single GOT with
8130 entries at both negative and positive offsets.  Not all environments
8131 support such GOTs.
8132 @samp{multigot} allows the linker to generate several GOTs in the
8133 output file.  All GOT references from a single input object
8134 file access the same GOT, but references from different input object
8135 files might access different GOTs.  Not all environments support such GOTs.
8137 @ifclear GENERIC
8138 @lowersections
8139 @end ifclear
8140 @end ifset
8142 @ifset MIPS
8143 @ifclear GENERIC
8144 @raisesections
8145 @end ifclear
8147 @node MIPS
8148 @section @command{ld} and the MIPS family
8150 @cindex MIPS microMIPS instruction choice selection
8151 @kindex --insn32
8152 @kindex --no-insn32
8153 The @samp{--insn32} and @samp{--no-insn32} options control the choice of
8154 microMIPS instructions used in code generated by the linker, such as that
8155 in the PLT or lazy binding stubs, or in relaxation.  If @samp{--insn32} is
8156 used, then the linker only uses 32-bit instruction encodings.  By default
8157 or if @samp{--no-insn32} is used, all instruction encodings are used,
8158 including 16-bit ones where possible.
8160 @cindex MIPS branch relocation check control
8161 @kindex --ignore-branch-isa
8162 @kindex --no-ignore-branch-isa
8163 The @samp{--ignore-branch-isa} and @samp{--no-ignore-branch-isa} options
8164 control branch relocation checks for invalid ISA mode transitions.  If
8165 @samp{--ignore-branch-isa} is used, then the linker accepts any branch
8166 relocations and any ISA mode transition required is lost in relocation
8167 calculation, except for some cases of @code{BAL} instructions which meet
8168 relaxation conditions and are converted to equivalent @code{JALX}
8169 instructions as the associated relocation is calculated.  By default
8170 or if @samp{--no-ignore-branch-isa} is used a check is made causing
8171 the loss of an ISA mode transition to produce an error.
8173 @ifclear GENERIC
8174 @lowersections
8175 @end ifclear
8176 @end ifset
8178 @ifset MMIX
8179 @ifclear GENERIC
8180 @raisesections
8181 @end ifclear
8183 @node MMIX
8184 @section @code{ld} and MMIX
8185 For MMIX, there is a choice of generating @code{ELF} object files or
8186 @code{mmo} object files when linking.  The simulator @code{mmix}
8187 understands the @code{mmo} format.  The binutils @code{objcopy} utility
8188 can translate between the two formats.
8190 There is one special section, the @samp{.MMIX.reg_contents} section.
8191 Contents in this section is assumed to correspond to that of global
8192 registers, and symbols referring to it are translated to special symbols,
8193 equal to registers.  In a final link, the start address of the
8194 @samp{.MMIX.reg_contents} section corresponds to the first allocated
8195 global register multiplied by 8.  Register @code{$255} is not included in
8196 this section; it is always set to the program entry, which is at the
8197 symbol @code{Main} for @code{mmo} files.
8199 Global symbols with the prefix @code{__.MMIX.start.}, for example
8200 @code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special.
8201 The default linker script uses these to set the default start address
8202 of a section.
8204 Initial and trailing multiples of zero-valued 32-bit words in a section,
8205 are left out from an mmo file.
8207 @ifclear GENERIC
8208 @lowersections
8209 @end ifclear
8210 @end ifset
8212 @ifset MSP430
8213 @ifclear GENERIC
8214 @raisesections
8215 @end ifclear
8217 @node  MSP430
8218 @section @code{ld} and MSP430
8219 For the MSP430 it is possible to select the MPU architecture.  The flag @samp{-m [mpu type]}
8220 will select an appropriate linker script for selected MPU type.  (To get a list of known MPUs
8221 just pass @samp{-m help} option to the linker).
8223 @cindex MSP430 extra sections
8224 The linker will recognize some extra sections which are MSP430 specific:
8226 @table @code
8227 @item @samp{.vectors}
8228 Defines a portion of ROM where interrupt vectors located.
8230 @item @samp{.bootloader}
8231 Defines the bootloader portion of the ROM (if applicable).  Any code
8232 in this section will be uploaded to the MPU.
8234 @item @samp{.infomem}
8235 Defines an information memory section (if applicable).  Any code in
8236 this section will be uploaded to the MPU.
8238 @item @samp{.infomemnobits}
8239 This is the same as the @samp{.infomem} section except that any code
8240 in this section will not be uploaded to the MPU.
8242 @item @samp{.noinit}
8243 Denotes a portion of RAM located above @samp{.bss} section.
8245 The last two sections are used by gcc.
8246 @end table
8248 @table @option
8249 @cindex MSP430 Options
8250 @kindex --code-region
8251 @item --code-region=[either,lower,upper,none]
8252 This will transform .text* sections to [either,lower,upper].text* sections. The
8253 argument passed to GCC for -mcode-region is propagated to the linker
8254 using this option.
8256 @kindex --data-region
8257 @item --data-region=[either,lower,upper,none]
8258 This will transform .data*, .bss* and .rodata* sections to
8259 [either,lower,upper].[data,bss,rodata]* sections. The argument passed to GCC
8260 for -mdata-region is propagated to the linker using this option.
8262 @kindex --disable-sec-transformation
8263 @item --disable-sec-transformation
8264 Prevent the transformation of sections as specified by the @code{--code-region}
8265 and @code{--data-region} options.
8266 This is useful if you are compiling and linking using a single call to the GCC
8267 wrapper, and want to compile the source files using -m[code,data]-region but
8268 not transform the sections for prebuilt libraries and objects.
8269 @end table
8271 @ifclear GENERIC
8272 @lowersections
8273 @end ifclear
8274 @end ifset
8276 @ifset NDS32
8277 @ifclear GENERIC
8278 @raisesections
8279 @end ifclear
8281 @node NDS32
8282 @section @code{ld} and NDS32
8283 @kindex relaxing on NDS32
8284 For NDS32, there are some options to select relaxation behavior.  The linker
8285 relaxes objects according to these options.
8287 @table @code
8288 @item @samp{--m[no-]fp-as-gp}
8289 Disable/enable fp-as-gp relaxation.
8291 @item @samp{--mexport-symbols=FILE}
8292 Exporting symbols and their address into FILE as linker script.
8294 @item @samp{--m[no-]ex9}
8295 Disable/enable link-time EX9 relaxation.
8297 @item @samp{--mexport-ex9=FILE}
8298 Export the EX9 table after linking.
8300 @item @samp{--mimport-ex9=FILE}
8301 Import the Ex9 table for EX9 relaxation.
8303 @item @samp{--mupdate-ex9}
8304 Update the existing EX9 table.
8306 @item @samp{--mex9-limit=NUM}
8307 Maximum number of entries in the ex9 table.
8309 @item @samp{--mex9-loop-aware}
8310 Avoid generating the EX9 instruction inside the loop.
8312 @item @samp{--m[no-]ifc}
8313 Disable/enable the link-time IFC optimization.
8315 @item @samp{--mifc-loop-aware}
8316 Avoid generating the IFC instruction inside the loop.
8317 @end table
8319 @ifclear GENERIC
8320 @lowersections
8321 @end ifclear
8322 @end ifset
8324 @ifset NIOSII
8325 @ifclear GENERIC
8326 @raisesections
8327 @end ifclear
8329 @node Nios II
8330 @section @command{ld} and the Altera Nios II
8331 @cindex Nios II call relaxation
8332 @kindex --relax on Nios II
8334 Call and immediate jump instructions on Nios II processors are limited to
8335 transferring control to addresses in the same 256MB memory segment,
8336 which may result in @command{ld} giving
8337 @samp{relocation truncated to fit} errors with very large programs.
8338 The command-line option @option{--relax} enables the generation of
8339 trampolines that can access the entire 32-bit address space for calls
8340 outside the normal @code{call} and @code{jmpi} address range.  These
8341 trampolines are inserted at section boundaries, so may not themselves
8342 be reachable if an input section and its associated call trampolines are
8343 larger than 256MB.
8345 The @option{--relax} option is enabled by default unless @option{-r}
8346 is also specified.  You can disable trampoline generation by using the
8347 @option{--no-relax} linker option.  You can also disable this optimization
8348 locally by using the @samp{set .noat} directive in assembly-language
8349 source files, as the linker-inserted trampolines use the @code{at}
8350 register as a temporary.
8352 Note that the linker @option{--relax} option is independent of assembler
8353 relaxation options, and that using the GNU assembler's @option{-relax-all}
8354 option interferes with the linker's more selective call instruction relaxation.
8356 @ifclear GENERIC
8357 @lowersections
8358 @end ifclear
8359 @end ifset
8361 @ifset POWERPC
8362 @ifclear GENERIC
8363 @raisesections
8364 @end ifclear
8366 @node PowerPC ELF32
8367 @section @command{ld} and PowerPC 32-bit ELF Support
8368 @cindex PowerPC long branches
8369 @kindex --relax on PowerPC
8370 Branches on PowerPC processors are limited to a signed 26-bit
8371 displacement, which may result in @command{ld} giving
8372 @samp{relocation truncated to fit} errors with very large programs.
8373 @samp{--relax} enables the generation of trampolines that can access
8374 the entire 32-bit address space.  These trampolines are inserted at
8375 section boundaries, so may not themselves be reachable if an input
8376 section exceeds 33M in size.  You may combine @samp{-r} and
8377 @samp{--relax} to add trampolines in a partial link.  In that case
8378 both branches to undefined symbols and inter-section branches are also
8379 considered potentially out of range, and trampolines inserted.
8381 @cindex PowerPC ELF32 options
8382 @table @option
8383 @cindex PowerPC PLT
8384 @kindex --bss-plt
8385 @item --bss-plt
8386 Current PowerPC GCC accepts a @samp{-msecure-plt} option that
8387 generates code capable of using a newer PLT and GOT layout that has
8388 the security advantage of no executable section ever needing to be
8389 writable and no writable section ever being executable.  PowerPC
8390 @command{ld} will generate this layout, including stubs to access the
8391 PLT, if all input files (including startup and static libraries) were
8392 compiled with @samp{-msecure-plt}.  @samp{--bss-plt} forces the old
8393 BSS PLT (and GOT layout) which can give slightly better performance.
8395 @kindex --secure-plt
8396 @item --secure-plt
8397 @command{ld} will use the new PLT and GOT layout if it is linking new
8398 @samp{-fpic} or @samp{-fPIC} code, but does not do so automatically
8399 when linking non-PIC code.  This option requests the new PLT and GOT
8400 layout.  A warning will be given if some object file requires the old
8401 style BSS PLT.
8403 @cindex PowerPC GOT
8404 @kindex --sdata-got
8405 @item --sdata-got
8406 The new secure PLT and GOT are placed differently relative to other
8407 sections compared to older BSS PLT and GOT placement.  The location of
8408 @code{.plt} must change because the new secure PLT is an initialized
8409 section while the old PLT is uninitialized.  The reason for the
8410 @code{.got} change is more subtle:  The new placement allows
8411 @code{.got} to be read-only in applications linked with
8412 @samp{-z relro -z now}.  However, this placement means that
8413 @code{.sdata} cannot always be used in shared libraries, because the
8414 PowerPC ABI accesses @code{.sdata} in shared libraries from the GOT
8415 pointer.  @samp{--sdata-got} forces the old GOT placement.  PowerPC
8416 GCC doesn't use @code{.sdata} in shared libraries, so this option is
8417 really only useful for other compilers that may do so.
8419 @cindex PowerPC stub symbols
8420 @kindex --emit-stub-syms
8421 @item --emit-stub-syms
8422 This option causes @command{ld} to label linker stubs with a local
8423 symbol that encodes the stub type and destination.
8425 @cindex PowerPC TLS optimization
8426 @kindex --no-tls-optimize
8427 @item --no-tls-optimize
8428 PowerPC @command{ld} normally performs some optimization of code
8429 sequences used to access Thread-Local Storage.  Use this option to
8430 disable the optimization.
8431 @end table
8433 @ifclear GENERIC
8434 @lowersections
8435 @end ifclear
8436 @end ifset
8438 @ifset POWERPC64
8439 @ifclear GENERIC
8440 @raisesections
8441 @end ifclear
8443 @node PowerPC64 ELF64
8444 @section @command{ld} and PowerPC64 64-bit ELF Support
8446 @cindex PowerPC64 ELF64 options
8447 @table @option
8448 @cindex PowerPC64 stub grouping
8449 @kindex --stub-group-size
8450 @item --stub-group-size
8451 Long branch stubs, PLT call stubs  and TOC adjusting stubs are placed
8452 by @command{ld} in stub sections located between groups of input sections.
8453 @samp{--stub-group-size} specifies the maximum size of a group of input
8454 sections handled by one stub section.  Since branch offsets are signed,
8455 a stub section may serve two groups of input sections, one group before
8456 the stub section, and one group after it.  However, when using
8457 conditional branches that require stubs, it may be better (for branch
8458 prediction) that stub sections only serve one group of input sections.
8459 A negative value for @samp{N} chooses this scheme, ensuring that
8460 branches to stubs always use a negative offset.  Two special values of
8461 @samp{N} are recognized, @samp{1} and @samp{-1}.  These both instruct
8462 @command{ld} to automatically size input section groups for the branch types
8463 detected, with the same behaviour regarding stub placement as other
8464 positive or negative values of @samp{N} respectively.
8466 Note that @samp{--stub-group-size} does not split input sections.  A
8467 single input section larger than the group size specified will of course
8468 create a larger group (of one section).  If input sections are too
8469 large, it may not be possible for a branch to reach its stub.
8471 @cindex PowerPC64 stub symbols
8472 @kindex --emit-stub-syms
8473 @item --emit-stub-syms
8474 This option causes @command{ld} to label linker stubs with a local
8475 symbol that encodes the stub type and destination.
8477 @cindex PowerPC64 dot symbols
8478 @kindex --dotsyms
8479 @kindex --no-dotsyms
8480 @item --dotsyms
8481 @itemx --no-dotsyms
8482 These two options control how @command{ld} interprets version patterns
8483 in a version script.  Older PowerPC64 compilers emitted both a
8484 function descriptor symbol with the same name as the function, and a
8485 code entry symbol with the name prefixed by a dot (@samp{.}).  To
8486 properly version a function @samp{foo}, the version script thus needs
8487 to control both @samp{foo} and @samp{.foo}.  The option
8488 @samp{--dotsyms}, on by default, automatically adds the required
8489 dot-prefixed patterns.  Use @samp{--no-dotsyms} to disable this
8490 feature.
8492 @cindex PowerPC64 register save/restore functions
8493 @kindex --save-restore-funcs
8494 @kindex --no-save-restore-funcs
8495 @item --save-restore-funcs
8496 @itemx --no-save-restore-funcs
8497 These two options control whether PowerPC64 @command{ld} automatically
8498 provides out-of-line register save and restore functions used by
8499 @samp{-Os} code.  The default is to provide any such referenced
8500 function for a normal final link, and to not do so for a relocatable
8501 link.
8503 @cindex PowerPC64 TLS optimization
8504 @kindex --no-tls-optimize
8505 @item --no-tls-optimize
8506 PowerPC64 @command{ld} normally performs some optimization of code
8507 sequences used to access Thread-Local Storage.  Use this option to
8508 disable the optimization.
8510 @cindex PowerPC64 __tls_get_addr optimization
8511 @kindex --tls-get-addr-optimize
8512 @kindex --no-tls-get-addr-optimize
8513 @kindex --tls-get-addr-regsave
8514 @kindex --no-tls-get-addr-regsave
8515 @item --tls-get-addr-optimize
8516 @itemx --no-tls-get-addr-optimize
8517 These options control how PowerPC64 @command{ld} uses a special
8518 stub to call __tls_get_addr.  PowerPC64 glibc 2.22 and later support
8519 an optimization that allows the second and subsequent calls to
8520 @code{__tls_get_addr} for a given symbol to be resolved by the special
8521 stub without calling in to glibc.  By default the linker enables
8522 generation of the stub when glibc advertises the availability of
8523 __tls_get_addr_opt.
8524 Using @option{--tls-get-addr-optimize} with an older glibc won't do
8525 much besides slow down your applications, but may be useful if linking
8526 an application against an older glibc with the expectation that it
8527 will normally be used on systems having a newer glibc.
8528 @option{--tls-get-addr-regsave} forces generation of a stub that saves
8529 and restores volatile registers around the call into glibc.  Normally,
8530 this is done when the linker detects a call to __tls_get_addr_desc.
8531 Such calls then go via the register saving stub to __tls_get_addr_opt.
8532 @option{--no-tls-get-addr-regsave} disables generation of the
8533 register saves.
8535 @cindex PowerPC64 OPD optimization
8536 @kindex --no-opd-optimize
8537 @item --no-opd-optimize
8538 PowerPC64 @command{ld} normally removes @code{.opd} section entries
8539 corresponding to deleted link-once functions, or functions removed by
8540 the action of @samp{--gc-sections} or linker script @code{/DISCARD/}.
8541 Use this option to disable @code{.opd} optimization.
8543 @cindex PowerPC64 OPD spacing
8544 @kindex --non-overlapping-opd
8545 @item --non-overlapping-opd
8546 Some PowerPC64 compilers have an option to generate compressed
8547 @code{.opd} entries spaced 16 bytes apart, overlapping the third word,
8548 the static chain pointer (unused in C) with the first word of the next
8549 entry.  This option expands such entries to the full 24 bytes.
8551 @cindex PowerPC64 TOC optimization
8552 @kindex --no-toc-optimize
8553 @item --no-toc-optimize
8554 PowerPC64 @command{ld} normally removes unused @code{.toc} section
8555 entries.  Such entries are detected by examining relocations that
8556 reference the TOC in code sections.  A reloc in a deleted code section
8557 marks a TOC word as unneeded, while a reloc in a kept code section
8558 marks a TOC word as needed.  Since the TOC may reference itself, TOC
8559 relocs are also examined.  TOC words marked as both needed and
8560 unneeded will of course be kept.  TOC words without any referencing
8561 reloc are assumed to be part of a multi-word entry, and are kept or
8562 discarded as per the nearest marked preceding word.  This works
8563 reliably for compiler generated code, but may be incorrect if assembly
8564 code is used to insert TOC entries.  Use this option to disable the
8565 optimization.
8567 @cindex PowerPC64 inline PLT call optimization
8568 @kindex --no-inline-optimize
8569 @item --no-inline-optimize
8570 PowerPC64 @command{ld} normally replaces inline PLT call sequences
8571 marked with @code{R_PPC64_PLTSEQ}, @code{R_PPC64_PLTCALL},
8572 @code{R_PPC64_PLT16_HA} and @code{R_PPC64_PLT16_LO_DS} relocations by
8573 a number of @code{nop}s and a direct call when the function is defined
8574 locally and can't be overridden by some other definition.  This option
8575 disables that optimization.
8577 @cindex PowerPC64 multi-TOC
8578 @kindex --no-multi-toc
8579 @item --no-multi-toc
8580 If given any toc option besides @code{-mcmodel=medium} or
8581 @code{-mcmodel=large}, PowerPC64 GCC generates code for a TOC model
8582 where TOC
8583 entries are accessed with a 16-bit offset from r2.  This limits the
8584 total TOC size to 64K.  PowerPC64 @command{ld} extends this limit by
8585 grouping code sections such that each group uses less than 64K for its
8586 TOC entries, then inserts r2 adjusting stubs between inter-group
8587 calls.  @command{ld} does not split apart input sections, so cannot
8588 help if a single input file has a @code{.toc} section that exceeds
8589 64K, most likely from linking multiple files with @command{ld -r}.
8590 Use this option to turn off this feature.
8592 @cindex PowerPC64 TOC sorting
8593 @kindex --no-toc-sort
8594 @item --no-toc-sort
8595 By default, @command{ld} sorts TOC sections so that those whose file
8596 happens to have a section called @code{.init} or @code{.fini} are
8597 placed first, followed by TOC sections referenced by code generated
8598 with PowerPC64 gcc's @code{-mcmodel=small}, and lastly TOC sections
8599 referenced only by code generated with PowerPC64 gcc's
8600 @code{-mcmodel=medium} or @code{-mcmodel=large} options.  Doing this
8601 results in better TOC grouping for multi-TOC.  Use this option to turn
8602 off this feature.
8604 @cindex PowerPC64 PLT stub alignment
8605 @kindex --plt-align
8606 @kindex --no-plt-align
8607 @item --plt-align
8608 @itemx --no-plt-align
8609 Use these options to control whether individual PLT call stubs are
8610 aligned to a 32-byte boundary, or to the specified power of two
8611 boundary when using @code{--plt-align=}.  A negative value may be
8612 specified to pad PLT call stubs so that they do not cross the
8613 specified power of two boundary (or the minimum number of boundaries
8614 if a PLT stub is so large that it must cross a boundary).  By default
8615 PLT call stubs are aligned to 32-byte boundaries.
8617 @cindex PowerPC64 PLT call stub static chain
8618 @kindex --plt-static-chain
8619 @kindex --no-plt-static-chain
8620 @item --plt-static-chain
8621 @itemx --no-plt-static-chain
8622 Use these options to control whether PLT call stubs load the static
8623 chain pointer (r11).  @code{ld} defaults to not loading the static
8624 chain since there is never any need to do so on a PLT call.
8626 @cindex PowerPC64 PLT call stub thread safety
8627 @kindex --plt-thread-safe
8628 @kindex --no-plt-thread-safe
8629 @item --plt-thread-safe
8630 @itemx --no-plt-thread-safe
8631 With power7's weakly ordered memory model, it is possible when using
8632 lazy binding for ld.so to update a plt entry in one thread and have
8633 another thread see the individual plt entry words update in the wrong
8634 order, despite ld.so carefully writing in the correct order and using
8635 memory write barriers.  To avoid this we need some sort of read
8636 barrier in the call stub, or use LD_BIND_NOW=1.  By default, @code{ld}
8637 looks for calls to commonly used functions that create threads, and if
8638 seen, adds the necessary barriers.  Use these options to change the
8639 default behaviour.
8641 @cindex PowerPC64 ELFv2 PLT localentry optimization
8642 @kindex --plt-localentry
8643 @kindex --no-plt-localentry
8644 @item --plt-localentry
8645 @itemx --no-localentry
8646 ELFv2 functions with localentry:0 are those with a single entry point,
8647 ie. global entry == local entry, and that have no requirement on r2
8648 (the TOC/GOT pointer) or r12, and guarantee r2 is unchanged on return.
8649 Such an external function can be called via the PLT without saving r2
8650 or restoring it on return, avoiding a common load-hit-store for small
8651 functions.   The optimization is attractive, with up to 40% reduction
8652 in execution time for a small function, but can result in symbol
8653 interposition failures.  Also, minor changes in a shared library,
8654 including system libraries, can cause a function that was localentry:0
8655 to become localentry:8.  This will result in a dynamic loader
8656 complaint and failure to run.  The option is experimental, use with
8657 care.  @option{--no-plt-localentry} is the default.
8659 @cindex PowerPC64 Power10 stubs
8660 @kindex --power10-stubs
8661 @kindex --no-power10-stubs
8662 @item --power10-stubs
8663 @itemx --no-power10-stubs
8664 When PowerPC64 @command{ld} links input object files containing
8665 relocations used on power10 prefixed instructions it normally creates
8666 linkage stubs (PLT call and long branch) using power10 instructions
8667 for @code{@@notoc} PLT calls where @code{r2} is not known.  The
8668 power10 notoc stubs are smaller and faster, so are preferred for
8669 power10.  @option{--power10-stubs} and @option{--no-power10-stubs}
8670 allow you to override the linker's selection of stub instructions.
8671 @option{--power10-stubs=auto} allows the user to select the default
8672 auto mode.
8673 @end table
8675 @ifclear GENERIC
8676 @lowersections
8677 @end ifclear
8678 @end ifset
8680 @ifset S/390
8681 @ifclear GENERIC
8682 @raisesections
8683 @end ifclear
8685 @node S/390 ELF
8686 @section @command{ld} and S/390 ELF Support
8688 @cindex S/390 ELF options
8689 @table @option
8691 @cindex S/390
8692 @kindex --s390-pgste
8693 @item --s390-pgste
8694 This option marks the result file with a @code{PT_S390_PGSTE}
8695 segment.  The Linux kernel is supposed to allocate 4k page tables for
8696 binaries marked that way.
8697 @end table
8699 @ifclear GENERIC
8700 @lowersections
8701 @end ifclear
8702 @end ifset
8704 @ifset SPU
8705 @ifclear GENERIC
8706 @raisesections
8707 @end ifclear
8709 @node SPU ELF
8710 @section @command{ld} and SPU ELF Support
8712 @cindex SPU ELF options
8713 @table @option
8715 @cindex SPU plugins
8716 @kindex --plugin
8717 @item --plugin
8718 This option marks an executable as a PIC plugin module.
8720 @cindex SPU overlays
8721 @kindex --no-overlays
8722 @item --no-overlays
8723 Normally, @command{ld} recognizes calls to functions within overlay
8724 regions, and redirects such calls to an overlay manager via a stub.
8725 @command{ld} also provides a built-in overlay manager.  This option
8726 turns off all this special overlay handling.
8728 @cindex SPU overlay stub symbols
8729 @kindex --emit-stub-syms
8730 @item --emit-stub-syms
8731 This option causes @command{ld} to label overlay stubs with a local
8732 symbol that encodes the stub type and destination.
8734 @cindex SPU extra overlay stubs
8735 @kindex --extra-overlay-stubs
8736 @item --extra-overlay-stubs
8737 This option causes @command{ld} to add overlay call stubs on all
8738 function calls out of overlay regions.  Normally stubs are not added
8739 on calls to non-overlay regions.
8741 @cindex SPU local store size
8742 @kindex --local-store=lo:hi
8743 @item --local-store=lo:hi
8744 @command{ld} usually checks that a final executable for SPU fits in
8745 the address range 0 to 256k.  This option may be used to change the
8746 range.  Disable the check entirely with @option{--local-store=0:0}.
8748 @cindex SPU
8749 @kindex --stack-analysis
8750 @item --stack-analysis
8751 SPU local store space is limited.  Over-allocation of stack space
8752 unnecessarily limits space available for code and data, while
8753 under-allocation results in runtime failures.  If given this option,
8754 @command{ld} will provide an estimate of maximum stack usage.
8755 @command{ld} does this by examining symbols in code sections to
8756 determine the extents of functions, and looking at function prologues
8757 for stack adjusting instructions.  A call-graph is created by looking
8758 for relocations on branch instructions.  The graph is then searched
8759 for the maximum stack usage path.  Note that this analysis does not
8760 find calls made via function pointers, and does not handle recursion
8761 and other cycles in the call graph.  Stack usage may be
8762 under-estimated if your code makes such calls.  Also, stack usage for
8763 dynamic allocation, e.g. alloca, will not be detected.  If a link map
8764 is requested, detailed information about each function's stack usage
8765 and calls will be given.
8767 @cindex SPU
8768 @kindex --emit-stack-syms
8769 @item --emit-stack-syms
8770 This option, if given along with @option{--stack-analysis} will result
8771 in @command{ld} emitting stack sizing symbols for each function.
8772 These take the form @code{__stack_<function_name>} for global
8773 functions, and @code{__stack_<number>_<function_name>} for static
8774 functions.  @code{<number>} is the section id in hex.  The value of
8775 such symbols is the stack requirement for the corresponding function.
8776 The symbol size will be zero, type @code{STT_NOTYPE}, binding
8777 @code{STB_LOCAL}, and section @code{SHN_ABS}.
8778 @end table
8780 @ifclear GENERIC
8781 @lowersections
8782 @end ifclear
8783 @end ifset
8785 @ifset TICOFF
8786 @ifclear GENERIC
8787 @raisesections
8788 @end ifclear
8790 @node TI COFF
8791 @section @command{ld}'s Support for Various TI COFF Versions
8792 @cindex TI COFF versions
8793 @kindex --format=@var{version}
8794 The @samp{--format} switch allows selection of one of the various
8795 TI COFF versions.  The latest of this writing is 2; versions 0 and 1 are
8796 also supported.  The TI COFF versions also vary in header byte-order
8797 format; @command{ld} will read any version or byte order, but the output
8798 header format depends on the default specified by the specific target.
8800 @ifclear GENERIC
8801 @lowersections
8802 @end ifclear
8803 @end ifset
8805 @ifset WIN32
8806 @ifclear GENERIC
8807 @raisesections
8808 @end ifclear
8810 @node WIN32
8811 @section @command{ld} and WIN32 (cygwin/mingw)
8813 This section describes some of the win32 specific @command{ld} issues.
8814 See @ref{Options,,Command-line Options} for detailed description of the
8815 command-line options mentioned here.
8817 @table @emph
8818 @cindex import libraries
8819 @item import libraries
8820 The standard Windows linker creates and uses so-called import
8821 libraries, which contains information for linking to dll's.  They are
8822 regular static archives and are handled as any other static
8823 archive.  The cygwin and mingw ports of @command{ld} have specific
8824 support for creating such libraries provided with the
8825 @samp{--out-implib} command-line option.
8827 @item Resource only DLLs
8828 It is possible to create a DLL that only contains resources, ie just a
8829 @samp{.rsrc} section, but in order to do so a custom linker script
8830 must be used.  This is because the built-in default linker scripts
8831 will always create @samp{.text} and @samp{.idata} sections, even if
8832 there is no input to go into them.
8834 The script should look like this, although the @code{OUTPUT_FORMAT}
8835 should be changed to match the desired format.
8837 @example
8838 OUTPUT_FORMAT(pei-i386)
8839 SECTIONS
8841   . = SIZEOF_HEADERS;
8842   . = ALIGN(__section_alignment__);
8843   .rsrc __image_base__ + __section_alignment__ : ALIGN(4)
8844   @{
8845     KEEP (*(.rsrc))
8846     KEEP (*(.rsrc$*))
8847   @}
8848   /DISCARD/ : @{ *(*) @}
8850 @end example
8852 With this script saved to a file called, eg @file{rsrc.ld}, a command
8853 line like this can be used to create the resource only DLL
8854 @file{rsrc.dll} from an input file called @file{rsrc.o}:
8856 @smallexample
8857 ld -dll --subsystem windows -e 0 -s rsrc.o -o rsrc.dll -T rsrc.ld
8858 @end smallexample
8860 @item   exporting DLL symbols
8861 @cindex exporting DLL symbols
8862 The cygwin/mingw @command{ld} has several ways to export symbols for dll's.
8864 @table @emph
8865 @item   using auto-export functionality
8866 @cindex using auto-export functionality
8867 By default @command{ld} exports symbols with the auto-export functionality,
8868 which is controlled by the following command-line options:
8870 @itemize
8871 @item --export-all-symbols   [This is the default]
8872 @item --exclude-symbols
8873 @item --exclude-libs
8874 @item --exclude-modules-for-implib
8875 @item --version-script
8876 @end itemize
8878 When auto-export is in operation, @command{ld} will export all the non-local
8879 (global and common) symbols it finds in a DLL, with the exception of a few
8880 symbols known to belong to the system's runtime and libraries.  As it will
8881 often not be desirable to export all of a DLL's symbols, which may include
8882 private functions that are not part of any public interface, the command-line
8883 options listed above may be used to filter symbols out from the list for
8884 exporting.  The @samp{--output-def} option can be used in order to see the
8885 final list of exported symbols with all exclusions taken into effect.
8887 If @samp{--export-all-symbols} is not given explicitly on the
8888 command line, then the default auto-export behavior will be @emph{disabled}
8889 if either of the following are true:
8891 @itemize
8892 @item A DEF file is used.
8893 @item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
8894 @end itemize
8896 @item   using a DEF file
8897 @cindex using a DEF file
8898 Another way of exporting symbols is using a DEF file.  A DEF file is
8899 an ASCII file containing definitions of symbols which should be
8900 exported when a dll is created.  Usually it is named @samp{<dll
8901 name>.def} and is added as any other object file to the linker's
8902 command line.  The file's name must end in @samp{.def} or @samp{.DEF}.
8904 @example
8905 gcc -o <output> <objectfiles> <dll name>.def
8906 @end example
8908 Using a DEF file turns off the normal auto-export behavior, unless the
8909 @samp{--export-all-symbols} option is also used.
8911 Here is an example of a DEF file for a shared library called @samp{xyz.dll}:
8913 @example
8914 LIBRARY "xyz.dll" BASE=0x20000000
8916 EXPORTS
8919 _bar = bar
8920 another_foo = abc.dll.afoo
8921 var1 DATA
8922 doo = foo == foo2
8923 eoo DATA == var1
8924 @end example
8926 This example defines a DLL with a non-default base address and seven
8927 symbols in the export table. The third exported symbol @code{_bar} is an
8928 alias for the second. The fourth symbol, @code{another_foo} is resolved
8929 by "forwarding" to another module and treating it as an alias for
8930 @code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
8931 @code{var1} is declared to be a data object. The @samp{doo} symbol in
8932 export library is an alias of @samp{foo}, which gets the string name
8933 in export table @samp{foo2}. The @samp{eoo} symbol is an data export
8934 symbol, which gets in export table the name @samp{var1}.
8936 The optional @code{LIBRARY <name>} command indicates the @emph{internal}
8937 name of the output DLL. If @samp{<name>} does not include a suffix,
8938 the default library suffix, @samp{.DLL} is appended.
8940 When the .DEF file is used to build an application, rather than a
8941 library, the @code{NAME <name>} command should be used instead of
8942 @code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
8943 executable suffix, @samp{.EXE} is appended.
8945 With either @code{LIBRARY <name>} or @code{NAME <name>} the optional
8946 specification @code{BASE = <number>} may be used to specify a
8947 non-default base address for the image.
8949 If neither @code{LIBRARY <name>} nor  @code{NAME <name>} is specified,
8950 or they specify an empty string, the internal name is the same as the
8951 filename specified on the command line.
8953 The complete specification of an export symbol is:
8955 @example
8956 EXPORTS
8957   ( (  ( <name1> [ = <name2> ] )
8958      | ( <name1> = <module-name> . <external-name>))
8959   [ @@ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] [== <name3>] ) *
8960 @end example
8962 Declares @samp{<name1>} as an exported symbol from the DLL, or declares
8963 @samp{<name1>} as an exported alias for @samp{<name2>}; or declares
8964 @samp{<name1>} as a "forward" alias for the symbol
8965 @samp{<external-name>} in the DLL @samp{<module-name>}.
8966 Optionally, the symbol may be exported by the specified ordinal
8967 @samp{<integer>} alias. The optional @samp{<name3>} is the to be used
8968 string in import/export table for the symbol.
8970 The optional keywords that follow the declaration indicate:
8972 @code{NONAME}: Do not put the symbol name in the DLL's export table.  It
8973 will still be exported by its ordinal alias (either the value specified
8974 by the .def specification or, otherwise, the value assigned by the
8975 linker). The symbol name, however, does remain visible in the import
8976 library (if any), unless @code{PRIVATE} is also specified.
8978 @code{DATA}: The symbol is a variable or object, rather than a function.
8979 The import lib will export only an indirect reference to @code{foo} as
8980 the symbol @code{_imp__foo} (ie, @code{foo} must be resolved as
8981 @code{*_imp__foo}).
8983 @code{CONSTANT}: Like @code{DATA}, but put the undecorated @code{foo} as
8984 well as @code{_imp__foo} into the import library. Both refer to the
8985 read-only import address table's pointer to the variable, not to the
8986 variable itself. This can be dangerous. If the user code fails to add
8987 the @code{dllimport} attribute and also fails to explicitly add the
8988 extra indirection that the use of the attribute enforces, the
8989 application will behave unexpectedly.
8991 @code{PRIVATE}: Put the symbol in the DLL's export table, but do not put
8992 it into the static import library used to resolve imports at link time. The
8993 symbol can still be imported using the @code{LoadLibrary/GetProcAddress}
8994 API at runtime or by using the GNU ld extension of linking directly to
8995 the DLL without an import library.
8997 See ld/deffilep.y in the binutils sources for the full specification of
8998 other DEF file statements
9000 @cindex creating a DEF file
9001 While linking a shared dll, @command{ld} is able to create a DEF file
9002 with the @samp{--output-def <file>} command-line option.
9004 @item   Using decorations
9005 @cindex Using decorations
9006 Another way of marking symbols for export is to modify the source code
9007 itself, so that when building the DLL each symbol to be exported is
9008 declared as:
9010 @example
9011 __declspec(dllexport) int a_variable
9012 __declspec(dllexport) void a_function(int with_args)
9013 @end example
9015 All such symbols will be exported from the DLL.  If, however,
9016 any of the object files in the DLL contain symbols decorated in
9017 this way, then the normal auto-export behavior is disabled, unless
9018 the @samp{--export-all-symbols} option is also used.
9020 Note that object files that wish to access these symbols must @emph{not}
9021 decorate them with dllexport.  Instead, they should use dllimport,
9022 instead:
9024 @example
9025 __declspec(dllimport) int a_variable
9026 __declspec(dllimport) void a_function(int with_args)
9027 @end example
9029 This complicates the structure of library header files, because
9030 when included by the library itself the header must declare the
9031 variables and functions as dllexport, but when included by client
9032 code the header must declare them as dllimport.  There are a number
9033 of idioms that are typically used to do this; often client code can
9034 omit the __declspec() declaration completely.  See
9035 @samp{--enable-auto-import} and @samp{automatic data imports} for more
9036 information.
9037 @end table
9039 @cindex automatic data imports
9040 @item automatic data imports
9041 The standard Windows dll format supports data imports from dlls only
9042 by adding special decorations (dllimport/dllexport), which let the
9043 compiler produce specific assembler instructions to deal with this
9044 issue.  This increases the effort necessary to port existing Un*x
9045 code to these platforms, especially for large
9046 c++ libraries and applications.  The auto-import feature, which was
9047 initially provided by Paul Sokolovsky, allows one to omit the
9048 decorations to achieve a behavior that conforms to that on POSIX/Un*x
9049 platforms. This feature is enabled with the @samp{--enable-auto-import}
9050 command-line option, although it is enabled by default on cygwin/mingw.
9051 The @samp{--enable-auto-import} option itself now serves mainly to
9052 suppress any warnings that are ordinarily emitted when linked objects
9053 trigger the feature's use.
9055 auto-import of variables does not always work flawlessly without
9056 additional assistance.  Sometimes, you will see this message
9058 "variable '<var>' can't be auto-imported. Please read the
9059 documentation for ld's @code{--enable-auto-import} for details."
9061 The @samp{--enable-auto-import} documentation explains why this error
9062 occurs, and several methods that can be used to overcome this difficulty.
9063 One of these methods is the @emph{runtime pseudo-relocs} feature, described
9064 below.
9066 @cindex runtime pseudo-relocation
9067 For complex variables imported from DLLs (such as structs or classes),
9068 object files typically contain a base address for the variable and an
9069 offset (@emph{addend}) within the variable--to specify a particular
9070 field or public member, for instance.  Unfortunately, the runtime loader used
9071 in win32 environments is incapable of fixing these references at runtime
9072 without the additional information supplied by dllimport/dllexport decorations.
9073 The standard auto-import feature described above is unable to resolve these
9074 references.
9076 The @samp{--enable-runtime-pseudo-relocs} switch allows these references to
9077 be resolved without error, while leaving the task of adjusting the references
9078 themselves (with their non-zero addends) to specialized code provided by the
9079 runtime environment.  Recent versions of the cygwin and mingw environments and
9080 compilers provide this runtime support; older versions do not.  However, the
9081 support is only necessary on the developer's platform; the compiled result will
9082 run without error on an older system.
9084 @samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
9085 enabled as needed.
9087 @cindex direct linking to a dll
9088 @item direct linking to a dll
9089 The cygwin/mingw ports of @command{ld} support the direct linking,
9090 including data symbols, to a dll without the usage of any import
9091 libraries.  This is much faster and uses much less memory than does the
9092 traditional import library method, especially when linking large
9093 libraries or applications.  When @command{ld} creates an import lib, each
9094 function or variable exported from the dll is stored in its own bfd, even
9095 though a single bfd could contain many exports.  The overhead involved in
9096 storing, loading, and processing so many bfd's is quite large, and explains the
9097 tremendous time, memory, and storage needed to link against particularly
9098 large or complex libraries when using import libs.
9100 Linking directly to a dll uses no extra command-line switches other than
9101 @samp{-L} and @samp{-l}, because @command{ld} already searches for a number
9102 of names to match each library.  All that is needed from the developer's
9103 perspective is an understanding of this search, in order to force ld to
9104 select the dll instead of an import library.
9107 For instance, when ld is called with the argument @samp{-lxxx} it will attempt
9108 to find, in the first directory of its search path,
9110 @example
9111 libxxx.dll.a
9112 xxx.dll.a
9113 libxxx.a
9114 xxx.lib
9115 libxxx.lib
9116 cygxxx.dll (*)
9117 libxxx.dll
9118 xxx.dll
9119 @end example
9121 before moving on to the next directory in the search path.
9123 (*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
9124 where @samp{<prefix>} is set by the @command{ld} option
9125 @samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
9126 file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
9127 @samp{cygxxx.dll}.
9129 Other win32-based unix environments, such as mingw or pw32, may use other
9130 @samp{<prefix>}es, although at present only cygwin makes use of this feature.  It
9131 was originally intended to help avoid name conflicts among dll's built for the
9132 various win32/un*x environments, so that (for example) two versions of a zlib dll
9133 could coexist on the same machine.
9135 The generic cygwin/mingw path layout uses a @samp{bin} directory for
9136 applications and dll's and a @samp{lib} directory for the import
9137 libraries (using cygwin nomenclature):
9139 @example
9140 bin/
9141         cygxxx.dll
9142 lib/
9143         libxxx.dll.a   (in case of dll's)
9144         libxxx.a       (in case of static archive)
9145 @end example
9147 Linking directly to a dll without using the import library can be
9148 done two ways:
9150 1. Use the dll directly by adding the @samp{bin} path to the link line
9151 @example
9152 gcc -Wl,-verbose  -o a.exe -L../bin/ -lxxx
9153 @end example
9155 However, as the dll's often have version numbers appended to their names
9156 (@samp{cygncurses-5.dll}) this will often fail, unless one specifies
9157 @samp{-L../bin -lncurses-5} to include the version.  Import libs are generally
9158 not versioned, and do not have this difficulty.
9160 2. Create a symbolic link from the dll to a file in the @samp{lib}
9161 directory according to the above mentioned search pattern.  This
9162 should be used to avoid unwanted changes in the tools needed for
9163 making the app/dll.
9165 @example
9166 ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
9167 @end example
9169 Then you can link without any make environment changes.
9171 @example
9172 gcc -Wl,-verbose  -o a.exe -L../lib/ -lxxx
9173 @end example
9175 This technique also avoids the version number problems, because the following is
9176 perfectly legal
9178 @example
9179 bin/
9180         cygxxx-5.dll
9181 lib/
9182         libxxx.dll.a -> ../bin/cygxxx-5.dll
9183 @end example
9185 Linking directly to a dll without using an import lib will work
9186 even when auto-import features are exercised, and even when
9187 @samp{--enable-runtime-pseudo-relocs} is used.
9189 Given the improvements in speed and memory usage, one might justifiably
9190 wonder why import libraries are used at all.  There are three reasons:
9192 1. Until recently, the link-directly-to-dll functionality did @emph{not}
9193 work with auto-imported data.
9195 2. Sometimes it is necessary to include pure static objects within the
9196 import library (which otherwise contains only bfd's for indirection
9197 symbols that point to the exports of a dll).  Again, the import lib
9198 for the cygwin kernel makes use of this ability, and it is not
9199 possible to do this without an import lib.
9201 3. Symbol aliases can only be resolved using an import lib.  This is
9202 critical when linking against OS-supplied dll's (eg, the win32 API)
9203 in which symbols are usually exported as undecorated aliases of their
9204 stdcall-decorated assembly names.
9206 So, import libs are not going away.  But the ability to replace
9207 true import libs with a simple symbolic link to (or a copy of)
9208 a dll, in many cases, is a useful addition to the suite of tools
9209 binutils makes available to the win32 developer.  Given the
9210 massive improvements in memory requirements during linking, storage
9211 requirements, and linking speed, we expect that many developers
9212 will soon begin to use this feature whenever possible.
9214 @item symbol aliasing
9215 @table @emph
9216 @item adding additional names
9217 Sometimes, it is useful to export symbols with additional names.
9218 A symbol @samp{foo} will be exported as @samp{foo}, but it can also be
9219 exported as @samp{_foo} by using special directives in the DEF file
9220 when creating the dll.  This will affect also the optional created
9221 import library.  Consider the following DEF file:
9223 @example
9224 LIBRARY "xyz.dll" BASE=0x61000000
9226 EXPORTS
9228 _foo = foo
9229 @end example
9231 The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
9233 Another method for creating a symbol alias is to create it in the
9234 source code using the "weak" attribute:
9236 @example
9237 void foo () @{ /* Do something.  */; @}
9238 void _foo () __attribute__ ((weak, alias ("foo")));
9239 @end example
9241 See the gcc manual for more information about attributes and weak
9242 symbols.
9244 @item renaming symbols
9245 Sometimes it is useful to rename exports.  For instance, the cygwin
9246 kernel does this regularly.  A symbol @samp{_foo} can be exported as
9247 @samp{foo} but not as @samp{_foo} by using special directives in the
9248 DEF file. (This will also affect the import library, if it is
9249 created).  In the following example:
9251 @example
9252 LIBRARY "xyz.dll" BASE=0x61000000
9254 EXPORTS
9255 _foo = foo
9256 @end example
9258 The line @samp{_foo = foo} maps the exported symbol @samp{foo} to
9259 @samp{_foo}.
9260 @end table
9262 Note: using a DEF file disables the default auto-export behavior,
9263 unless the @samp{--export-all-symbols} command-line option is used.
9264 If, however, you are trying to rename symbols, then you should list
9265 @emph{all} desired exports in the DEF file, including the symbols
9266 that are not being renamed, and do @emph{not} use the
9267 @samp{--export-all-symbols} option.  If you list only the
9268 renamed symbols in the DEF file, and use @samp{--export-all-symbols}
9269 to handle the other symbols, then the both the new names @emph{and}
9270 the original names for the renamed symbols will be exported.
9271 In effect, you'd be aliasing those symbols, not renaming them,
9272 which is probably not what you wanted.
9274 @cindex weak externals
9275 @item weak externals
9276 The Windows object format, PE, specifies a form of weak symbols called
9277 weak externals.  When a weak symbol is linked and the symbol is not
9278 defined, the weak symbol becomes an alias for some other symbol.  There
9279 are three variants of weak externals:
9280 @itemize
9281 @item Definition is searched for in objects and libraries, historically
9282 called lazy externals.
9283 @item Definition is searched for only in other objects, not in libraries.
9284 This form is not presently implemented.
9285 @item No search; the symbol is an alias.  This form is not presently
9286 implemented.
9287 @end itemize
9288 As a GNU extension, weak symbols that do not specify an alternate symbol
9289 are supported.  If the symbol is undefined when linking, the symbol
9290 uses a default value.
9292 @cindex aligned common symbols
9293 @item aligned common symbols
9294 As a GNU extension to the PE file format, it is possible to specify the
9295 desired alignment for a common symbol.  This information is conveyed from
9296 the assembler or compiler to the linker by means of GNU-specific commands
9297 carried in the object file's @samp{.drectve} section, which are recognized
9298 by @command{ld} and respected when laying out the common symbols.  Native
9299 tools will be able to process object files employing this GNU extension,
9300 but will fail to respect the alignment instructions, and may issue noisy
9301 warnings about unknown linker directives.
9303 @end table
9305 @ifclear GENERIC
9306 @lowersections
9307 @end ifclear
9308 @end ifset
9310 @ifset XTENSA
9311 @ifclear GENERIC
9312 @raisesections
9313 @end ifclear
9315 @node Xtensa
9316 @section @code{ld} and Xtensa Processors
9318 @cindex Xtensa processors
9319 The default @command{ld} behavior for Xtensa processors is to interpret
9320 @code{SECTIONS} commands so that lists of explicitly named sections in a
9321 specification with a wildcard file will be interleaved when necessary to
9322 keep literal pools within the range of PC-relative load offsets.  For
9323 example, with the command:
9325 @smallexample
9326 SECTIONS
9328   .text : @{
9329     *(.literal .text)
9330   @}
9332 @end smallexample
9334 @noindent
9335 @command{ld} may interleave some of the @code{.literal}
9336 and @code{.text} sections from different object files to ensure that the
9337 literal pools are within the range of PC-relative load offsets.  A valid
9338 interleaving might place the @code{.literal} sections from an initial
9339 group of files followed by the @code{.text} sections of that group of
9340 files.  Then, the @code{.literal} sections from the rest of the files
9341 and the @code{.text} sections from the rest of the files would follow.
9343 @cindex @option{--relax} on Xtensa
9344 @cindex relaxing on Xtensa
9345 Relaxation is enabled by default for the Xtensa version of @command{ld} and
9346 provides two important link-time optimizations.  The first optimization
9347 is to combine identical literal values to reduce code size.  A redundant
9348 literal will be removed and all the @code{L32R} instructions that use it
9349 will be changed to reference an identical literal, as long as the
9350 location of the replacement literal is within the offset range of all
9351 the @code{L32R} instructions.  The second optimization is to remove
9352 unnecessary overhead from assembler-generated ``longcall'' sequences of
9353 @code{L32R}/@code{CALLX@var{n}} when the target functions are within
9354 range of direct @code{CALL@var{n}} instructions.
9356 For each of these cases where an indirect call sequence can be optimized
9357 to a direct call, the linker will change the @code{CALLX@var{n}}
9358 instruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
9359 instruction, and remove the literal referenced by the @code{L32R}
9360 instruction if it is not used for anything else.  Removing the
9361 @code{L32R} instruction always reduces code size but can potentially
9362 hurt performance by changing the alignment of subsequent branch targets.
9363 By default, the linker will always preserve alignments, either by
9364 switching some instructions between 24-bit encodings and the equivalent
9365 density instructions or by inserting a no-op in place of the @code{L32R}
9366 instruction that was removed.  If code size is more important than
9367 performance, the @option{--size-opt} option can be used to prevent the
9368 linker from widening density instructions or inserting no-ops, except in
9369 a few cases where no-ops are required for correctness.
9371 The following Xtensa-specific command-line options can be used to
9372 control the linker:
9374 @cindex Xtensa options
9375 @table @option
9376 @item --size-opt
9377 When optimizing indirect calls to direct calls, optimize for code size
9378 more than performance.  With this option, the linker will not insert
9379 no-ops or widen density instructions to preserve branch target
9380 alignment.  There may still be some cases where no-ops are required to
9381 preserve the correctness of the code.
9383 @item --abi-windowed
9384 @itemx --abi-call0
9385 Choose ABI for the output object and for the generated PLT code.
9386 PLT code inserted by the linker must match ABI of the output object
9387 because windowed and call0 ABI use incompatible function call
9388 conventions.
9389 Default ABI is chosen by the ABI tag in the @code{.xtensa.info} section
9390 of the first input object.
9391 A warning is issued if ABI tags of input objects do not match each other
9392 or the chosen output object ABI.
9393 @end table
9395 @ifclear GENERIC
9396 @lowersections
9397 @end ifclear
9398 @end ifset
9400 @ifclear SingleFormat
9401 @node BFD
9402 @chapter BFD
9404 @cindex back end
9405 @cindex object file management
9406 @cindex object formats available
9407 @kindex objdump -i
9408 The linker accesses object and archive files using the BFD libraries.
9409 These libraries allow the linker to use the same routines to operate on
9410 object files whatever the object file format.  A different object file
9411 format can be supported simply by creating a new BFD back end and adding
9412 it to the library.  To conserve runtime memory, however, the linker and
9413 associated tools are usually configured to support only a subset of the
9414 object file formats available.  You can use @code{objdump -i}
9415 (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
9416 list all the formats available for your configuration.
9418 @cindex BFD requirements
9419 @cindex requirements for BFD
9420 As with most implementations, BFD is a compromise between
9421 several conflicting requirements. The major factor influencing
9422 BFD design was efficiency: any time used converting between
9423 formats is time which would not have been spent had BFD not
9424 been involved. This is partly offset by abstraction payback; since
9425 BFD simplifies applications and back ends, more time and care
9426 may be spent optimizing algorithms for a greater speed.
9428 One minor artifact of the BFD solution which you should bear in
9429 mind is the potential for information loss.  There are two places where
9430 useful information can be lost using the BFD mechanism: during
9431 conversion and during output. @xref{BFD information loss}.
9433 @menu
9434 * BFD outline::                 How it works: an outline of BFD
9435 @end menu
9437 @node BFD outline
9438 @section How It Works: An Outline of BFD
9439 @cindex opening object files
9440 @include bfdsumm.texi
9441 @end ifclear
9443 @node Reporting Bugs
9444 @chapter Reporting Bugs
9445 @cindex bugs in @command{ld}
9446 @cindex reporting bugs in @command{ld}
9448 Your bug reports play an essential role in making @command{ld} reliable.
9450 Reporting a bug may help you by bringing a solution to your problem, or
9451 it may not.  But in any case the principal function of a bug report is
9452 to help the entire community by making the next version of @command{ld}
9453 work better.  Bug reports are your contribution to the maintenance of
9454 @command{ld}.
9456 In order for a bug report to serve its purpose, you must include the
9457 information that enables us to fix the bug.
9459 @menu
9460 * Bug Criteria::                Have you found a bug?
9461 * Bug Reporting::               How to report bugs
9462 @end menu
9464 @node Bug Criteria
9465 @section Have You Found a Bug?
9466 @cindex bug criteria
9468 If you are not sure whether you have found a bug, here are some guidelines:
9470 @itemize @bullet
9471 @cindex fatal signal
9472 @cindex linker crash
9473 @cindex crash of linker
9474 @item
9475 If the linker gets a fatal signal, for any input whatever, that is a
9476 @command{ld} bug.  Reliable linkers never crash.
9478 @cindex error on valid input
9479 @item
9480 If @command{ld} produces an error message for valid input, that is a bug.
9482 @cindex invalid input
9483 @item
9484 If @command{ld} does not produce an error message for invalid input, that
9485 may be a bug.  In the general case, the linker can not verify that
9486 object files are correct.
9488 @item
9489 If you are an experienced user of linkers, your suggestions for
9490 improvement of @command{ld} are welcome in any case.
9491 @end itemize
9493 @node Bug Reporting
9494 @section How to Report Bugs
9495 @cindex bug reports
9496 @cindex @command{ld} bugs, reporting
9498 A number of companies and individuals offer support for @sc{gnu}
9499 products.  If you obtained @command{ld} from a support organization, we
9500 recommend you contact that organization first.
9502 You can find contact information for many support companies and
9503 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
9504 distribution.
9506 @ifset BUGURL
9507 Otherwise, send bug reports for @command{ld} to
9508 @value{BUGURL}.
9509 @end ifset
9511 The fundamental principle of reporting bugs usefully is this:
9512 @strong{report all the facts}.  If you are not sure whether to state a
9513 fact or leave it out, state it!
9515 Often people omit facts because they think they know what causes the
9516 problem and assume that some details do not matter.  Thus, you might
9517 assume that the name of a symbol you use in an example does not
9518 matter.  Well, probably it does not, but one cannot be sure.  Perhaps
9519 the bug is a stray memory reference which happens to fetch from the
9520 location where that name is stored in memory; perhaps, if the name
9521 were different, the contents of that location would fool the linker
9522 into doing the right thing despite the bug.  Play it safe and give a
9523 specific, complete example.  That is the easiest thing for you to do,
9524 and the most helpful.
9526 Keep in mind that the purpose of a bug report is to enable us to fix
9527 the bug if it is new to us.  Therefore, always write your bug reports
9528 on the assumption that the bug has not been reported previously.
9530 Sometimes people give a few sketchy facts and ask, ``Does this ring a
9531 bell?''  This cannot help us fix a bug, so it is basically useless.  We
9532 respond by asking for enough details to enable us to investigate.
9533 You might as well expedite matters by sending them to begin with.
9535 To enable us to fix the bug, you should include all these things:
9537 @itemize @bullet
9538 @item
9539 The version of @command{ld}.  @command{ld} announces it if you start it with
9540 the @samp{--version} argument.
9542 Without this, we will not know whether there is any point in looking for
9543 the bug in the current version of @command{ld}.
9545 @item
9546 Any patches you may have applied to the @command{ld} source, including any
9547 patches made to the @code{BFD} library.
9549 @item
9550 The type of machine you are using, and the operating system name and
9551 version number.
9553 @item
9554 What compiler (and its version) was used to compile @command{ld}---e.g.
9555 ``@code{gcc-2.7}''.
9557 @item
9558 The command arguments you gave the linker to link your example and
9559 observe the bug.  To guarantee you will not omit something important,
9560 list them all.  A copy of the Makefile (or the output from make) is
9561 sufficient.
9563 If we were to try to guess the arguments, we would probably guess wrong
9564 and then we might not encounter the bug.
9566 @item
9567 A complete input file, or set of input files, that will reproduce the
9568 bug.  It is generally most helpful to send the actual object files
9569 provided that they are reasonably small.  Say no more than 10K.  For
9570 bigger files you can either make them available by FTP or HTTP or else
9571 state that you are willing to send the object file(s) to whomever
9572 requests them.  (Note - your email will be going to a mailing list, so
9573 we do not want to clog it up with large attachments).  But small
9574 attachments are best.
9576 If the source files were assembled using @code{gas} or compiled using
9577 @code{gcc}, then it may be OK to send the source files rather than the
9578 object files.  In this case, be sure to say exactly what version of
9579 @code{gas} or @code{gcc} was used to produce the object files.  Also say
9580 how @code{gas} or @code{gcc} were configured.
9582 @item
9583 A description of what behavior you observe that you believe is
9584 incorrect.  For example, ``It gets a fatal signal.''
9586 Of course, if the bug is that @command{ld} gets a fatal signal, then we
9587 will certainly notice it.  But if the bug is incorrect output, we might
9588 not notice unless it is glaringly wrong.  You might as well not give us
9589 a chance to make a mistake.
9591 Even if the problem you experience is a fatal signal, you should still
9592 say so explicitly.  Suppose something strange is going on, such as, your
9593 copy of @command{ld} is out of sync, or you have encountered a bug in the
9594 C library on your system.  (This has happened!)  Your copy might crash
9595 and ours would not.  If you told us to expect a crash, then when ours
9596 fails to crash, we would know that the bug was not happening for us.  If
9597 you had not told us to expect a crash, then we would not be able to draw
9598 any conclusion from our observations.
9600 @item
9601 If you wish to suggest changes to the @command{ld} source, send us context
9602 diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
9603 @samp{-p} option.  Always send diffs from the old file to the new file.
9604 If you even discuss something in the @command{ld} source, refer to it by
9605 context, not by line number.
9607 The line numbers in our development sources will not match those in your
9608 sources.  Your line numbers would convey no useful information to us.
9609 @end itemize
9611 Here are some things that are not necessary:
9613 @itemize @bullet
9614 @item
9615 A description of the envelope of the bug.
9617 Often people who encounter a bug spend a lot of time investigating
9618 which changes to the input file will make the bug go away and which
9619 changes will not affect it.
9621 This is often time consuming and not very useful, because the way we
9622 will find the bug is by running a single example under the debugger
9623 with breakpoints, not by pure deduction from a series of examples.
9624 We recommend that you save your time for something else.
9626 Of course, if you can find a simpler example to report @emph{instead}
9627 of the original one, that is a convenience for us.  Errors in the
9628 output will be easier to spot, running under the debugger will take
9629 less time, and so on.
9631 However, simplification is not vital; if you do not want to do this,
9632 report the bug anyway and send us the entire test case you used.
9634 @item
9635 A patch for the bug.
9637 A patch for the bug does help us if it is a good one.  But do not omit
9638 the necessary information, such as the test case, on the assumption that
9639 a patch is all we need.  We might see problems with your patch and decide
9640 to fix the problem another way, or we might not understand it at all.
9642 Sometimes with a program as complicated as @command{ld} it is very hard to
9643 construct an example that will make the program follow a certain path
9644 through the code.  If you do not send us the example, we will not be
9645 able to construct one, so we will not be able to verify that the bug is
9646 fixed.
9648 And if we cannot understand what bug you are trying to fix, or why your
9649 patch should be an improvement, we will not install it.  A test case will
9650 help us to understand.
9652 @item
9653 A guess about what the bug is or what it depends on.
9655 Such guesses are usually wrong.  Even we cannot guess right about such
9656 things without first using the debugger to find the facts.
9657 @end itemize
9659 @node MRI
9660 @appendix MRI Compatible Script Files
9661 @cindex MRI compatibility
9662 To aid users making the transition to @sc{gnu} @command{ld} from the MRI
9663 linker, @command{ld} can use MRI compatible linker scripts as an
9664 alternative to the more general-purpose linker scripting language
9665 described in @ref{Scripts}.  MRI compatible linker scripts have a much
9666 simpler command set than the scripting language otherwise used with
9667 @command{ld}.  @sc{gnu} @command{ld} supports the most commonly used MRI
9668 linker commands; these commands are described here.
9670 In general, MRI scripts aren't of much use with the @code{a.out} object
9671 file format, since it only has three sections and MRI scripts lack some
9672 features to make use of them.
9674 You can specify a file containing an MRI-compatible script using the
9675 @samp{-c} command-line option.
9677 Each command in an MRI-compatible script occupies its own line; each
9678 command line starts with the keyword that identifies the command (though
9679 blank lines are also allowed for punctuation).  If a line of an
9680 MRI-compatible script begins with an unrecognized keyword, @command{ld}
9681 issues a warning message, but continues processing the script.
9683 Lines beginning with @samp{*} are comments.
9685 You can write these commands using all upper-case letters, or all
9686 lower case; for example, @samp{chip} is the same as @samp{CHIP}.
9687 The following list shows only the upper-case form of each command.
9689 @table @code
9690 @cindex @code{ABSOLUTE} (MRI)
9691 @item ABSOLUTE @var{secname}
9692 @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
9693 Normally, @command{ld} includes in the output file all sections from all
9694 the input files.  However, in an MRI-compatible script, you can use the
9695 @code{ABSOLUTE} command to restrict the sections that will be present in
9696 your output program.  If the @code{ABSOLUTE} command is used at all in a
9697 script, then only the sections named explicitly in @code{ABSOLUTE}
9698 commands will appear in the linker output.  You can still use other
9699 input sections (whatever you select on the command line, or using
9700 @code{LOAD}) to resolve addresses in the output file.
9702 @cindex @code{ALIAS} (MRI)
9703 @item ALIAS @var{out-secname}, @var{in-secname}
9704 Use this command to place the data from input section @var{in-secname}
9705 in a section called @var{out-secname} in the linker output file.
9707 @var{in-secname} may be an integer.
9709 @cindex @code{ALIGN} (MRI)
9710 @item ALIGN @var{secname} = @var{expression}
9711 Align the section called @var{secname} to @var{expression}.  The
9712 @var{expression} should be a power of two.
9714 @cindex @code{BASE} (MRI)
9715 @item BASE @var{expression}
9716 Use the value of @var{expression} as the lowest address (other than
9717 absolute addresses) in the output file.
9719 @cindex @code{CHIP} (MRI)
9720 @item CHIP @var{expression}
9721 @itemx CHIP @var{expression}, @var{expression}
9722 This command does nothing; it is accepted only for compatibility.
9724 @cindex @code{END} (MRI)
9725 @item END
9726 This command does nothing whatever; it's only accepted for compatibility.
9728 @cindex @code{FORMAT} (MRI)
9729 @item FORMAT @var{output-format}
9730 Similar to the @code{OUTPUT_FORMAT} command in the more general linker
9731 language, but restricted to S-records, if @var{output-format} is @samp{S}
9733 @cindex @code{LIST} (MRI)
9734 @item LIST @var{anything}@dots{}
9735 Print (to the standard output file) a link map, as produced by the
9736 @command{ld} command-line option @samp{-M}.
9738 The keyword @code{LIST} may be followed by anything on the
9739 same line, with no change in its effect.
9741 @cindex @code{LOAD} (MRI)
9742 @item LOAD @var{filename}
9743 @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
9744 Include one or more object file @var{filename} in the link; this has the
9745 same effect as specifying @var{filename} directly on the @command{ld}
9746 command line.
9748 @cindex @code{NAME} (MRI)
9749 @item NAME @var{output-name}
9750 @var{output-name} is the name for the program produced by @command{ld}; the
9751 MRI-compatible command @code{NAME} is equivalent to the command-line
9752 option @samp{-o} or the general script language command @code{OUTPUT}.
9754 @cindex @code{ORDER} (MRI)
9755 @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
9756 @itemx ORDER @var{secname} @var{secname} @var{secname}
9757 Normally, @command{ld} orders the sections in its output file in the
9758 order in which they first appear in the input files.  In an MRI-compatible
9759 script, you can override this ordering with the @code{ORDER} command.  The
9760 sections you list with @code{ORDER} will appear first in your output
9761 file, in the order specified.
9763 @cindex @code{PUBLIC} (MRI)
9764 @item PUBLIC @var{name}=@var{expression}
9765 @itemx PUBLIC @var{name},@var{expression}
9766 @itemx PUBLIC @var{name} @var{expression}
9767 Supply a value (@var{expression}) for external symbol
9768 @var{name} used in the linker input files.
9770 @cindex @code{SECT} (MRI)
9771 @item SECT @var{secname}, @var{expression}
9772 @itemx SECT @var{secname}=@var{expression}
9773 @itemx SECT @var{secname} @var{expression}
9774 You can use any of these three forms of the @code{SECT} command to
9775 specify the start address (@var{expression}) for section @var{secname}.
9776 If you have more than one @code{SECT} statement for the same
9777 @var{secname}, only the @emph{first} sets the start address.
9778 @end table
9780 @node GNU Free Documentation License
9781 @appendix GNU Free Documentation License
9782 @include fdl.texi
9784 @node LD Index
9785 @unnumbered LD Index
9787 @printindex cp
9789 @tex
9790 % I think something like @@colophon should be in texinfo.  In the
9791 % meantime:
9792 \long\def\colophon{\hbox to0pt{}\vfill
9793 \centerline{The body of this manual is set in}
9794 \centerline{\fontname\tenrm,}
9795 \centerline{with headings in {\bf\fontname\tenbf}}
9796 \centerline{and examples in {\tt\fontname\tentt}.}
9797 \centerline{{\it\fontname\tenit\/} and}
9798 \centerline{{\sl\fontname\tensl\/}}
9799 \centerline{are used for emphasis.}\vfill}
9800 \page\colophon
9801 % Blame: doc@@cygnus.com, 28mar91.
9802 @end tex
9804 @bye