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