]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/binutils/ld/ld.7
src.conf.5: regen after r368667, GDB retirement
[FreeBSD/FreeBSD.git] / contrib / binutils / ld / ld.7
1 .Dd 2015-03-02
2 .Dt LD 7
3 .Os
4 .Sh NAME
5 .Nm ld
6 .Nd The GNU Linker
7 .Sh  LD
8 This file documents the GNU linker ld version "2.17.50 [FreeBSD] 2007-07-03".
9 .Pp
10 This document is distributed under the terms of the GNU Free Documentation
11 License. A copy of the license is included in the section entitled \(lqGNU Free
12 Documentation License\(rq.
13 .Pp
14 .Sh  Overview
15 .Xr ld
16 combines a number of object and archive files, relocates their data and ties
17 up symbol references. Usually the last step in compiling a program is to run
18 .Xr ld .
19 .Pp
20 .Xr ld
21 accepts Linker Command Language files written in a superset of AT&T's Link
22 Editor Command Language syntax, to provide explicit and total control over
23 the linking process.
24 .Pp
25 This version of
26 .Xr ld
27 uses the general purpose BFD libraries to operate on object files. This allows
28 .Xr ld
29 to read, combine, and write object files in many different formats---for example,
30 COFF or
31 .Li a.out .
32 Different formats may be linked together to produce any available kind of
33 object file.See Section
34 .Dq BFD ,
35 for more information.
36 .Pp
37 Aside from its flexibility, the GNU linker is more helpful than other linkers
38 in providing diagnostic information. Many linkers abandon execution immediately
39 upon encountering an error; whenever possible,
40 .Xr ld
41 continues executing, allowing you to identify other errors (or, in some cases,
42 to get an output file in spite of the error).
43 .Pp
44 .Sh  Invocation
45 The GNU linker
46 .Xr ld
47 is meant to cover a broad range of situations, and to be as compatible as
48 possible with other linkers. As a result, you have many choices to control
49 its behavior.
50 .Pp
51 .Ss  Command Line Options
52 The linker supports a plethora of command-line options, but in actual practice
53 few of them are used in any particular context. For instance, a frequent use
54 of
55 .Xr ld
56 is to link standard Unix object files on a standard, supported Unix system.
57 On such a system, to link a file
58 .Li hello.o :
59 .Pp
60 .Bd -literal -offset indent
61 ld -o output /lib/crt0.o hello.o -lc
62 .Ed
63 .Pp
64 This tells
65 .Xr ld
66 to produce a file called
67 .Va output
68 as the result of linking the file
69 .Li /lib/crt0.o
70 with
71 .Li hello.o
72 and the library
73 .Li libc.a ,
74 which will come from the standard search directories. (See the discussion
75 of the
76 .Li -l
77 option below.)
78 .Pp
79 Some of the command-line options to
80 .Xr ld
81 may be specified at any point in the command line. However, options which
82 refer to files, such as
83 .Li -l
84 or
85 .Li -T ,
86 cause the file to be read at the point at which the option appears in the
87 command line, relative to the object files and other file options. Repeating
88 non-file options with a different argument will either have no further effect,
89 or override prior occurrences (those further to the left on the command line)
90 of that option. Options which may be meaningfully specified more than once
91 are noted in the descriptions below.
92 .Pp
93 Non-option arguments are object files or archives which are to be linked together.
94 They may follow, precede, or be mixed in with command-line options, except
95 that an object file argument may not be placed between an option and its argument.
96 .Pp
97 Usually the linker is invoked with at least one object file, but you can specify
98 other forms of binary input files using
99 .Li -l ,
100 .Li -R ,
101 and the script command language. If
102 .Em no
103 binary input files at all are specified, the linker does not produce any output,
104 and issues the message
105 .Li No input files .
106 .Pp
107 If the linker cannot recognize the format of an object file, it will assume
108 that it is a linker script. A script specified in this way augments the main
109 linker script used for the link (either the default linker script or the one
110 specified by using
111 .Li -T ) .
112 This feature permits the linker to link against a file which appears to be
113 an object or an archive, but actually merely defines some symbol values, or
114 uses
115 .Li INPUT
116 or
117 .Li GROUP
118 to load other objects. Note that specifying a script in this way merely augments
119 the main linker script; use the
120 .Li -T
121 option to replace the default linker script entirely.See Section
122 .Dq Scripts .
123 .Pp
124 For options whose names are a single letter, option arguments must either
125 follow the option letter without intervening whitespace, or be given as separate
126 arguments immediately following the option that requires them.
127 .Pp
128 For options whose names are multiple letters, either one dash or two can precede
129 the option name; for example,
130 .Li -trace-symbol
131 and
132 .Li --trace-symbol
133 are equivalent. Note---there is one exception to this rule. Multiple letter
134 options that start with a lower case 'o' can only be preceded by two dashes.
135 This is to reduce confusion with the
136 .Li -o
137 option. So for example
138 .Li -omagic
139 sets the output file name to
140 .Li magic
141 whereas
142 .Li --omagic
143 sets the NMAGIC flag on the output.
144 .Pp
145 Arguments to multiple-letter options must either be separated from the option
146 name by an equals sign, or be given as separate arguments immediately following
147 the option that requires them. For example,
148 .Li --trace-symbol foo
149 and
150 .Li --trace-symbol=foo
151 are equivalent. Unique abbreviations of the names of multiple-letter options
152 are accepted.
153 .Pp
154 Note---if the linker is being invoked indirectly, via a compiler driver (e.g.
155 .Li gcc )
156 then all the linker command line options should be prefixed by
157 .Li -Wl,
158 (or whatever is appropriate for the particular compiler driver) like this:
159 .Pp
160 .Bd -literal -offset indent
161   gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
162 .Ed
163 .Pp
164 This is important, because otherwise the compiler driver program may silently
165 drop the linker options, resulting in a bad link.
166 .Pp
167 Here is a table of the generic command line switches accepted by the GNU linker:
168 .Pp
169 .Bl -tag -width Ds
170 .It  @ Va file
171 Read command-line options from
172 .Va file .
173 The options read are inserted in place of the original @
174 .Va file
175 option. If
176 .Va file
177 does not exist, or cannot be read, then the option will be treated literally,
178 and not removed.
179 .Pp
180 Options in
181 .Va file
182 are separated by whitespace. A whitespace character may be included in an
183 option by surrounding the entire option in either single or double quotes.
184 Any character (including a backslash) may be included by prefixing the character
185 to be included with a backslash. The
186 .Va file
187 may itself contain additional @
188 .Va file
189 options; any such options will be processed recursively.
190 .Pp
191 .It  -a Va keyword
192 This option is supported for HP/UX compatibility. The
193 .Va keyword
194 argument must be one of the strings
195 .Li archive ,
196 .Li shared ,
197 or
198 .Li default .
199 .Li -aarchive
200 is functionally equivalent to
201 .Li -Bstatic ,
202 and the other two keywords are functionally equivalent to
203 .Li -Bdynamic .
204 This option may be used any number of times.
205 .Pp
206 .It  -A Va architecture
207 .It  --architecture= Va architecture
208 In the current release of
209 .Xr ld ,
210 this option is useful only for the Intel 960 family of architectures. In that
211 .Xr ld
212 configuration, the
213 .Va architecture
214 argument identifies the particular architecture in the 960 family, enabling
215 some safeguards and modifying the archive-library search path.See Section
216 .Dq i960 ,
217 for details.
218 .Pp
219 Future releases of
220 .Xr ld
221 may support similar functionality for other architecture families.
222 .Pp
223 .It  -b Va input-format
224 .It  --format= Va input-format
225 .Xr ld
226 may be configured to support more than one kind of object file. If your
227 .Xr ld
228 is configured this way, you can use the
229 .Li -b
230 option to specify the binary format for input object files that follow this
231 option on the command line. Even when
232 .Xr ld
233 is configured to support alternative object formats, you don't usually need
234 to specify this, as
235 .Xr ld
236 should be configured to expect as a default input format the most usual format
237 on each machine.
238 .Va input-format
239 is a text string, the name of a particular format supported by the BFD libraries.
240 (You can list the available binary formats with
241 .Li objdump -i . )
242 See Section.Dq BFD .
243 .Pp
244 You may want to use this option if you are linking files with an unusual binary
245 format. You can also use
246 .Li -b
247 to switch formats explicitly (when linking object files of different formats),
248 by including
249 .Li -b Va input-format
250 before each group of object files in a particular format.
251 .Pp
252 The default format is taken from the environment variable
253 .Li GNUTARGET .
254 See Section.Dq Environment .
255 You can also define the input format from a script, using the command
256 .Li TARGET ;
257 see Format Commands.
258 .Pp
259 .It  -c Va MRI-commandfile
260 .It  --mri-script= Va MRI-commandfile
261 For compatibility with linkers produced by MRI,
262 .Xr ld
263 accepts script files written in an alternate, restricted command language,
264 described in MRI,,MRI Compatible Script Files. Introduce MRI script files
265 with the option
266 .Li -c ;
267 use the
268 .Li -T
269 option to run linker scripts written in the general-purpose
270 .Xr ld
271 scripting language. If
272 .Va MRI-cmdfile
273 does not exist,
274 .Xr ld
275 looks for it in the directories specified by any
276 .Li -L
277 options.
278 .Pp
279 .It  -d
280 .It  -dc
281 .It  -dp
282 These three options are equivalent; multiple forms are supported for compatibility
283 with other linkers. They assign space to common symbols even if a relocatable
284 output file is specified (with
285 .Li -r ) .
286 The script command
287 .Li FORCE_COMMON_ALLOCATION
288 has the same effect.See Section
289 .Dq Miscellaneous Commands .
290 .Pp
291 .It  -e Va entry
292 .It  --entry= Va entry
293 Use
294 .Va entry
295 as the explicit symbol for beginning execution of your program, rather than
296 the default entry point. If there is no symbol named
297 .Va entry ,
298 the linker will try to parse
299 .Va entry
300 as a number, and use that as the entry address (the number will be interpreted
301 in base 10; you may use a leading
302 .Li 0x
303 for base 16, or a leading
304 .Li 0
305 for base 8).See Section
306 .Dq Entry Point ,
307 for a discussion of defaults and other ways of specifying the entry point.
308 .Pp
309 .It  --exclude-libs Va lib, Va lib,...
310 Specifies a list of archive libraries from which symbols should not be automatically
311 exported. The library names may be delimited by commas or colons. Specifying
312 .Li --exclude-libs ALL
313 excludes symbols in all archive libraries from automatic export. This option
314 is available only for the i386 PE targeted port of the linker and for ELF
315 targeted ports. For i386 PE, symbols explicitly listed in a .def file are
316 still exported, regardless of this option. For ELF targeted ports, symbols
317 affected by this option will be treated as hidden.
318 .Pp
319 .It  -E
320 .It  --export-dynamic
321 When creating a dynamically linked executable, add all symbols to the dynamic
322 symbol table. The dynamic symbol table is the set of symbols which are visible
323 from dynamic objects at run time.
324 .Pp
325 If you do not use this option, the dynamic symbol table will normally contain
326 only those symbols which are referenced by some dynamic object mentioned in
327 the link.
328 .Pp
329 If you use
330 .Li dlopen
331 to load a dynamic object which needs to refer back to the symbols defined
332 by the program, rather than some other dynamic object, then you will probably
333 need to use this option when linking the program itself.
334 .Pp
335 You can also use the dynamic list to control what symbols should be added
336 to the dynamic symbol table if the output format supports it. See the description
337 of
338 .Li --dynamic-list .
339 .Pp
340 .It  -EB
341 Link big-endian objects. This affects the default output format.
342 .Pp
343 .It  -EL
344 Link little-endian objects. This affects the default output format.
345 .Pp
346 .It  -f
347 .It  --auxiliary Va name
348 When creating an ELF shared object, set the internal DT_AUXILIARY field to
349 the specified name. This tells the dynamic linker that the symbol table of
350 the shared object should be used as an auxiliary filter on the symbol table
351 of the shared object
352 .Va name .
353 .Pp
354 If you later link a program against this filter object, then, when you run
355 the program, the dynamic linker will see the DT_AUXILIARY field. If the dynamic
356 linker resolves any symbols from the filter object, it will first check whether
357 there is a definition in the shared object
358 .Va name .
359 If there is one, it will be used instead of the definition in the filter object.
360 The shared object
361 .Va name
362 need not exist. Thus the shared object
363 .Va name
364 may be used to provide an alternative implementation of certain functions,
365 perhaps for debugging or for machine specific performance.
366 .Pp
367 This option may be specified more than once. The DT_AUXILIARY entries will
368 be created in the order in which they appear on the command line.
369 .Pp
370 .It  -F Va name
371 .It  --filter Va name
372 When creating an ELF shared object, set the internal DT_FILTER field to the
373 specified name. This tells the dynamic linker that the symbol table of the
374 shared object which is being created should be used as a filter on the symbol
375 table of the shared object
376 .Va name .
377 .Pp
378 If you later link a program against this filter object, then, when you run
379 the program, the dynamic linker will see the DT_FILTER field. The dynamic
380 linker will resolve symbols according to the symbol table of the filter object
381 as usual, but it will actually link to the definitions found in the shared
382 object
383 .Va name .
384 Thus the filter object can be used to select a subset of the symbols provided
385 by the object
386 .Va name .
387 .Pp
388 Some older linkers used the
389 .Op -F
390 option throughout a compilation toolchain for specifying object-file format
391 for both input and output object files. The GNU linker uses other mechanisms
392 for this purpose: the
393 .Op -b ,
394 .Op --format ,
395 .Op --oformat
396 options, the
397 .Li TARGET
398 command in linker scripts, and the
399 .Li GNUTARGET
400 environment variable. The GNU linker will ignore the
401 .Op -F
402 option when not creating an ELF shared object.
403 .Pp
404 .It  -fini Va name
405 When creating an ELF executable or shared object, call NAME when the executable
406 or shared object is unloaded, by setting DT_FINI to the address of the function.
407 By default, the linker uses
408 .Li _fini
409 as the function to call.
410 .Pp
411 .It  -g
412 Ignored. Provided for compatibility with other tools.
413 .Pp
414 .It  -G Va value
415 .It  --gpsize= Va value
416 Set the maximum size of objects to be optimized using the GP register to
417 .Va size .
418 This is only meaningful for object file formats such as MIPS ECOFF which supports
419 putting large and small objects into different sections. This is ignored for
420 other object file formats.
421 .Pp
422 .It  -h Va name
423 .It  -soname= Va name
424 When creating an ELF shared object, set the internal DT_SONAME field to the
425 specified name. When an executable is linked with a shared object which has
426 a DT_SONAME field, then when the executable is run the dynamic linker will
427 attempt to load the shared object specified by the DT_SONAME field rather
428 than the using the file name given to the linker.
429 .Pp
430 .It  -i
431 Perform an incremental link (same as option
432 .Li -r ) .
433 .Pp
434 .It  -init Va name
435 When creating an ELF executable or shared object, call NAME when the executable
436 or shared object is loaded, by setting DT_INIT to the address of the function.
437 By default, the linker uses
438 .Li _init
439 as the function to call.
440 .Pp
441 .It  -l Va namespec
442 .It  --library= Va namespec
443 Add the archive or object file specified by
444 .Va namespec
445 to the list of files to link. This option may be used any number of times.
446 If
447 .Va namespec
448 is of the form
449 .Pa : Va filename ,
450 .Xr ld
451 will search the library path for a file called
452 .Va filename ,
453 otherise it will search the library path for a file called
454 .Pa lib Va namespec.a .
455 .Pp
456 On systems which support shared libraries,
457 .Xr ld
458 may also search for files other than
459 .Pa lib Va namespec.a .
460 Specifically, on ELF and SunOS systems,
461 .Xr ld
462 will search a directory for a library called
463 .Pa lib Va namespec.so
464 before searching for one called
465 .Pa lib Va namespec.a .
466 (By convention, a
467 .Li .so
468 extension indicates a shared library.) Note that this behavior does not apply
469 to
470 .Pa : Va filename ,
471 which always specifies a file called
472 .Va filename .
473 .Pp
474 The linker will search an archive only once, at the location where it is specified
475 on the command line. If the archive defines a symbol which was undefined in
476 some object which appeared before the archive on the command line, the linker
477 will include the appropriate file(s) from the archive. However, an undefined
478 symbol in an object appearing later on the command line will not cause the
479 linker to search the archive again.
480 .Pp
481 See the
482 .Op -(
483 option for a way to force the linker to search archives multiple times.
484 .Pp
485 You may list the same archive multiple times on the command line.
486 .Pp
487 This type of archive searching is standard for Unix linkers. However, if you
488 are using
489 .Xr ld
490 on AIX, note that it is different from the behaviour of the AIX linker.
491 .Pp
492 .It  -L Va searchdir
493 .It  --library-path= Va searchdir
494 Add path
495 .Va searchdir
496 to the list of paths that
497 .Xr ld
498 will search for archive libraries and
499 .Xr ld
500 control scripts. You may use this option any number of times. The directories
501 are searched in the order in which they are specified on the command line.
502 Directories specified on the command line are searched before the default
503 directories. All
504 .Op -L
505 options apply to all
506 .Op -l
507 options, regardless of the order in which the options appear.
508 .Pp
509 If
510 .Va searchdir
511 begins with
512 .Li = ,
513 then the
514 .Li =
515 will be replaced by the
516 .Em sysroot prefix ,
517 a path specified when the linker is configured.
518 .Pp
519 The default set of paths searched (without being specified with
520 .Li -L )
521 depends on which emulation mode
522 .Xr ld
523 is using, and in some cases also on how it was configured.See Section
524 .Dq Environment .
525 .Pp
526 The paths can also be specified in a link script with the
527 .Li SEARCH_DIR
528 command. Directories specified this way are searched at the point in which
529 the linker script appears in the command line.
530 .Pp
531 .It  -m Va emulation
532 Emulate the
533 .Va emulation
534 linker. You can list the available emulations with the
535 .Li --verbose
536 or
537 .Li -V
538 options.
539 .Pp
540 If the
541 .Li -m
542 option is not used, the emulation is taken from the
543 .Li LDEMULATION
544 environment variable, if that is defined.
545 .Pp
546 Otherwise, the default emulation depends upon how the linker was configured.
547 .Pp
548 .It  -M
549 .It  --print-map
550 Print a link map to the standard output. A link map provides information about
551 the link, including the following:
552 .Pp
553 .Bl -bullet
554 .It
555 Where object files are mapped into memory.
556 .It
557 How common symbols are allocated.
558 .It
559 All archive members included in the link, with a mention of the symbol which
560 caused the archive member to be brought in.
561 .It
562 The values assigned to symbols.
563 .Pp
564 Note - symbols whose values are computed by an expression which involves a
565 reference to a previous value of the same symbol may not have correct result
566 displayed in the link map. This is because the linker discards intermediate
567 results and only retains the final value of an expression. Under such circumstances
568 the linker will display the final value enclosed by square brackets. Thus
569 for example a linker script containing:
570 .Pp
571 .Bd -literal -offset indent
572    foo = 1
573    foo = foo * 4
574    foo = foo + 8
575 .Ed
576 .Pp
577 will produce the following output in the link map if the
578 .Op -M
579 option is used:
580 .Pp
581 .Bd -literal -offset indent
582    0x00000001                foo = 0x1
583    [0x0000000c]                foo = (foo * 0x4)
584    [0x0000000c]                foo = (foo + 0x8)
585 .Ed
586 .Pp
587 See Expressions for more information about expressions in linker scripts.
588 .El
589 .Pp
590 .It  -n
591 .It  --nmagic
592 Turn off page alignment of sections, and mark the output as
593 .Li NMAGIC
594 if possible.
595 .Pp
596 .It  -N
597 .It  --omagic
598 Set the text and data sections to be readable and writable. Also, do not page-align
599 the data segment, and disable linking against shared libraries. If the output
600 format supports Unix style magic numbers, mark the output as
601 .Li OMAGIC .
602 Note: Although a writable text section is allowed for PE-COFF targets, it
603 does not conform to the format specification published by Microsoft.
604 .Pp
605 .It  --no-omagic
606 This option negates most of the effects of the
607 .Op -N
608 option. It sets the text section to be read-only, and forces the data segment
609 to be page-aligned. Note - this option does not enable linking against shared
610 libraries. Use
611 .Op -Bdynamic
612 for this.
613 .Pp
614 .It  -o Va output
615 .It  --output= Va output
616 Use
617 .Va output
618 as the name for the program produced by
619 .Xr ld ;
620 if this option is not specified, the name
621 .Pa a.out
622 is used by default. The script command
623 .Li OUTPUT
624 can also specify the output file name.
625 .Pp
626 .It  -O Va level
627 If
628 .Va level
629 is a numeric values greater than zero
630 .Xr ld
631 optimizes the output. This might take significantly longer and therefore probably
632 should only be enabled for the final binary.
633 .Pp
634 .It  -q
635 .It  --emit-relocs
636 Leave relocation sections and contents in fully linked executables. Post link
637 analysis and optimization tools may need this information in order to perform
638 correct modifications of executables. This results in larger executables.
639 .Pp
640 This option is currently only supported on ELF platforms.
641 .Pp
642 .It  --force-dynamic
643 Force the output file to have dynamic sections. This option is specific to
644 VxWorks targets.
645 .Pp
646 .It  -r
647 .It  --relocatable
648 Generate relocatable output---i.e., generate an output file that can in turn
649 serve as input to
650 .Xr ld .
651 This is often called
652 .Em partial linking .
653 As a side effect, in environments that support standard Unix magic numbers,
654 this option also sets the output file's magic number to
655 .Li OMAGIC .
656 If this option is not specified, an absolute file is produced. When linking
657 C++ programs, this option
658 .Em will not
659 resolve references to constructors; to do that, use
660 .Li -Ur .
661 .Pp
662 When an input file does not have the same format as the output file, partial
663 linking is only supported if that input file does not contain any relocations.
664 Different output formats can have further restrictions; for example some
665 .Li a.out
666 -based formats do not support partial linking with input files in other formats
667 at all.
668 .Pp
669 This option does the same thing as
670 .Li -i .
671 .Pp
672 .It  -R Va filename
673 .It  --just-symbols= Va filename
674 Read symbol names and their addresses from
675 .Va filename ,
676 but do not relocate it or include it in the output. This allows your output
677 file to refer symbolically to absolute locations of memory defined in other
678 programs. You may use this option more than once.
679 .Pp
680 For compatibility with other ELF linkers, if the
681 .Op -R
682 option is followed by a directory name, rather than a file name, it is treated
683 as the
684 .Op -rpath
685 option.
686 .Pp
687 .It  -s
688 .It  --strip-all
689 Omit all symbol information from the output file.
690 .Pp
691 .It  -S
692 .It  --strip-debug
693 Omit debugger symbol information (but not all symbols) from the output file.
694 .Pp
695 .It  -t
696 .It  --trace
697 Print the names of the input files as
698 .Xr ld
699 processes them.
700 .Pp
701 .It  -T Va scriptfile
702 .It  --script= Va scriptfile
703 Use
704 .Va scriptfile
705 as the linker script. This script replaces
706 .Xr ld
707 \&'s default linker script (rather than adding to it), so
708 .Va commandfile
709 must specify everything necessary to describe the output file.See Section
710 .Dq Scripts .
711 If
712 .Va scriptfile
713 does not exist in the current directory,
714 .Li ld
715 looks for it in the directories specified by any preceding
716 .Li -L
717 options. Multiple
718 .Li -T
719 options accumulate.
720 .Pp
721 .It  -dT Va scriptfile
722 .It  --default-script= Va scriptfile
723 Use
724 .Va scriptfile
725 as the default linker script.See Section
726 .Dq Scripts .
727 .Pp
728 This option is similar to the
729 .Op --script
730 option except that processing of the script is delayed until after the rest
731 of the command line has been processed. This allows options placed after the
732 .Op --default-script
733 option on the command line to affect the behaviour of the linker script, which
734 can be important when the linker command line cannot be directly controlled
735 by the user. (eg because the command line is being constructed by another
736 tool, such as
737 .Li gcc ) .
738 .Pp
739 .It  -u Va symbol
740 .It  --undefined= Va symbol
741 Force
742 .Va symbol
743 to be entered in the output file as an undefined symbol. Doing this may, for
744 example, trigger linking of additional modules from standard libraries.
745 .Li -u
746 may be repeated with different option arguments to enter additional undefined
747 symbols. This option is equivalent to the
748 .Li EXTERN
749 linker script command.
750 .Pp
751 .It  -Ur
752 For anything other than C++ programs, this option is equivalent to
753 .Li -r :
754 it generates relocatable output---i.e., an output file that can in turn serve
755 as input to
756 .Xr ld .
757 When linking C++ programs,
758 .Li -Ur
759 .Em does
760 resolve references to constructors, unlike
761 .Li -r .
762 It does not work to use
763 .Li -Ur
764 on files that were themselves linked with
765 .Li -Ur ;
766 once the constructor table has been built, it cannot be added to. Use
767 .Li -Ur
768 only for the last partial link, and
769 .Li -r
770 for the others.
771 .Pp
772 .It  --unique[= Va SECTION]
773 Creates a separate output section for every input section matching
774 .Va SECTION ,
775 or if the optional wildcard
776 .Va SECTION
777 argument is missing, for every orphan input section. An orphan section is
778 one not specifically mentioned in a linker script. You may use this option
779 multiple times on the command line; It prevents the normal merging of input
780 sections with the same name, overriding output section assignments in a linker
781 script.
782 .Pp
783 .It  -v
784 .It  --version
785 .It  -V
786 Display the version number for
787 .Xr ld .
788 The
789 .Op -V
790 option also lists the supported emulations.
791 .Pp
792 .It  -x
793 .It  --discard-all
794 Delete all local symbols.
795 .Pp
796 .It  -X
797 .It  --discard-locals
798 Delete all temporary local symbols. (These symbols start with system-specific
799 local label prefixes, typically
800 .Li .L
801 for ELF systems or
802 .Li L
803 for traditional a.out systems.)
804 .Pp
805 .It  -y Va symbol
806 .It  --trace-symbol= Va symbol
807 Print the name of each linked file in which
808 .Va symbol
809 appears. This option may be given any number of times. On many systems it
810 is necessary to prepend an underscore.
811 .Pp
812 This option is useful when you have an undefined symbol in your link but don't
813 know where the reference is coming from.
814 .Pp
815 .It  -Y Va path
816 Add
817 .Va path
818 to the default library search path. This option exists for Solaris compatibility.
819 .Pp
820 .It  -z Va keyword
821 The recognized keywords are:
822 .Bl -tag -width Ds
823 .It  combreloc
824 Combines multiple reloc sections and sorts them to make dynamic symbol lookup
825 caching possible.
826 .Pp
827 .It  defs
828 Disallows undefined symbols in object files. Undefined symbols in shared libraries
829 are still allowed.
830 .Pp
831 .It  execstack
832 Marks the object as requiring executable stack.
833 .Pp
834 .It  initfirst
835 This option is only meaningful when building a shared object. It marks the
836 object so that its runtime initialization will occur before the runtime initialization
837 of any other objects brought into the process at the same time. Similarly
838 the runtime finalization of the object will occur after the runtime finalization
839 of any other objects.
840 .Pp
841 .It  interpose
842 Marks the object that its symbol table interposes before all symbols but the
843 primary executable.
844 .Pp
845 .It  lazy
846 When generating an executable or shared library, mark it to tell the dynamic
847 linker to defer function call resolution to the point when the function is
848 called (lazy binding), rather than at load time. Lazy binding is the default.
849 .Pp
850 .It  loadfltr
851 Marks the object that its filters be processed immediately at runtime.
852 .Pp
853 .It  muldefs
854 Allows multiple definitions.
855 .Pp
856 .It  nocombreloc
857 Disables multiple reloc sections combining.
858 .Pp
859 .It  nocopyreloc
860 Disables production of copy relocs.
861 .Pp
862 .It  nodefaultlib
863 Marks the object that the search for dependencies of this object will ignore
864 any default library search paths.
865 .Pp
866 .It  nodelete
867 Marks the object shouldn't be unloaded at runtime.
868 .Pp
869 .It  nodlopen
870 Marks the object not available to
871 .Li dlopen .
872 .Pp
873 .It  nodump
874 Marks the object can not be dumped by
875 .Li dldump .
876 .Pp
877 .It  noexecstack
878 Marks the object as not requiring executable stack.
879 .Pp
880 .It  norelro
881 Don't create an ELF
882 .Li PT_GNU_RELRO
883 segment header in the object.
884 .Pp
885 .It  now
886 When generating an executable or shared library, mark it to tell the dynamic
887 linker to resolve all symbols when the program is started, or when the shared
888 library is linked to using dlopen, instead of deferring function call resolution
889 to the point when the function is first called.
890 .Pp
891 .It  origin
892 Marks the object may contain $ORIGIN.
893 .Pp
894 .It  relro
895 Create an ELF
896 .Li PT_GNU_RELRO
897 segment header in the object.
898 .Pp
899 .It  max-page-size= Va value
900 Set the emulation maximum page size to
901 .Va value .
902 .Pp
903 .It  common-page-size= Va value
904 Set the emulation common page size to
905 .Va value .
906 .Pp
907 .El
908 Other keywords are ignored for Solaris compatibility.
909 .Pp
910 .It  -( Va archives -)
911 .It  --start-group Va archives --end-group
912 The
913 .Va archives
914 should be a list of archive files. They may be either explicit file names,
915 or
916 .Li -l
917 options.
918 .Pp
919 The specified archives are searched repeatedly until no new undefined references
920 are created. Normally, an archive is searched only once in the order that
921 it is specified on the command line. If a symbol in that archive is needed
922 to resolve an undefined symbol referred to by an object in an archive that
923 appears later on the command line, the linker would not be able to resolve
924 that reference. By grouping the archives, they all be searched repeatedly
925 until all possible references are resolved.
926 .Pp
927 Using this option has a significant performance cost. It is best to use it
928 only when there are unavoidable circular references between two or more archives.
929 .Pp
930 .It  --accept-unknown-input-arch
931 .It  --no-accept-unknown-input-arch
932 Tells the linker to accept input files whose architecture cannot be recognised.
933 The assumption is that the user knows what they are doing and deliberately
934 wants to link in these unknown input files. This was the default behaviour
935 of the linker, before release 2.14. The default behaviour from release 2.14
936 onwards is to reject such input files, and so the
937 .Li --accept-unknown-input-arch
938 option has been added to restore the old behaviour.
939 .Pp
940 .It  --as-needed
941 .It  --no-as-needed
942 This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on
943 the command line after the
944 .Op --as-needed
945 option. Normally, the linker will add a DT_NEEDED tag for each dynamic library
946 mentioned on the command line, regardless of whether the library is actually
947 needed.
948 .Op --as-needed
949 causes DT_NEEDED tags to only be emitted for libraries that satisfy some symbol
950 reference from regular objects which is undefined at the point that the library
951 was linked.
952 .Op --no-as-needed
953 restores the default behaviour.
954 .Pp
955 .It  --add-needed
956 .It  --no-add-needed
957 This option affects the treatment of dynamic libraries from ELF DT_NEEDED
958 tags in dynamic libraries mentioned on the command line after the
959 .Op --no-add-needed
960 option. Normally, the linker will add a DT_NEEDED tag for each dynamic library
961 from DT_NEEDED tags.
962 .Op --no-add-needed
963 causes DT_NEEDED tags will never be emitted for those libraries from DT_NEEDED
964 tags.
965 .Op --add-needed
966 restores the default behaviour.
967 .Pp
968 .It  -assert Va keyword
969 This option is ignored for SunOS compatibility.
970 .Pp
971 .It  -Bdynamic
972 .It  -dy
973 .It  -call_shared
974 Link against dynamic libraries. This is only meaningful on platforms for which
975 shared libraries are supported. This option is normally the default on such
976 platforms. The different variants of this option are for compatibility with
977 various systems. You may use this option multiple times on the command line:
978 it affects library searching for
979 .Op -l
980 options which follow it.
981 .Pp
982 .It  -Bgroup
983 Set the
984 .Li DF_1_GROUP
985 flag in the
986 .Li DT_FLAGS_1
987 entry in the dynamic section. This causes the runtime linker to handle lookups
988 in this object and its dependencies to be performed only inside the group.
989 .Op --unresolved-symbols=report-all
990 is implied. This option is only meaningful on ELF platforms which support
991 shared libraries.
992 .Pp
993 .It  -Bstatic
994 .It  -dn
995 .It  -non_shared
996 .It  -static
997 Do not link against shared libraries. This is only meaningful on platforms
998 for which shared libraries are supported. The different variants of this option
999 are for compatibility with various systems. You may use this option multiple
1000 times on the command line: it affects library searching for
1001 .Op -l
1002 options which follow it. This option also implies
1003 .Op --unresolved-symbols=report-all .
1004 This option can be used with
1005 .Op -shared .
1006 Doing so means that a shared library is being created but that all of the
1007 library's external references must be resolved by pulling in entries from
1008 static libraries.
1009 .Pp
1010 .It  -Bsymbolic
1011 When creating a shared library, bind references to global symbols to the definition
1012 within the shared library, if any. Normally, it is possible for a program
1013 linked against a shared library to override the definition within the shared
1014 library. This option is only meaningful on ELF platforms which support shared
1015 libraries.
1016 .Pp
1017 .It  -Bsymbolic-functions
1018 When creating a shared library, bind references to global function symbols
1019 to the definition within the shared library, if any. This option is only meaningful
1020 on ELF platforms which support shared libraries.
1021 .Pp
1022 .It  --dynamic-list= Va dynamic-list-file
1023 Specify the name of a dynamic list file to the linker. This is typically used
1024 when creating shared libraries to specify a list of global symbols whose references
1025 shouldn't be bound to the definition within the shared library, or creating
1026 dynamically linked executables to specify a list of symbols which should be
1027 added to the symbol table in the executable. This option is only meaningful
1028 on ELF platforms which support shared libraries.
1029 .Pp
1030 The format of the dynamic list is the same as the version node without scope
1031 and node name. See VERSION for more information.
1032 .Pp
1033 .It  --dynamic-list-data
1034 Include all global data symbols to the dynamic list.
1035 .Pp
1036 .It  --dynamic-list-cpp-new
1037 Provide the builtin dynamic list for C++ operator new and delete. It is mainly
1038 useful for building shared libstdc++.
1039 .Pp
1040 .It  --dynamic-list-cpp-typeinfo
1041 Provide the builtin dynamic list for C++ runtime type identification.
1042 .Pp
1043 .It  --check-sections
1044 .It  --no-check-sections
1045 Asks the linker
1046 .Em not
1047 to check section addresses after they have been assigned to see if there are
1048 any overlaps. Normally the linker will perform this check, and if it finds
1049 any overlaps it will produce suitable error messages. The linker does know
1050 about, and does make allowances for sections in overlays. The default behaviour
1051 can be restored by using the command line switch
1052 .Op --check-sections .
1053 .Pp
1054 .It  --cref
1055 Output a cross reference table. If a linker map file is being generated, the
1056 cross reference table is printed to the map file. Otherwise, it is printed
1057 on the standard output.
1058 .Pp
1059 The format of the table is intentionally simple, so that it may be easily
1060 processed by a script if necessary. The symbols are printed out, sorted by
1061 name. For each symbol, a list of file names is given. If the symbol is defined,
1062 the first file listed is the location of the definition. The remaining files
1063 contain references to the symbol.
1064 .Pp
1065 .It  --no-define-common
1066 This option inhibits the assignment of addresses to common symbols. The script
1067 command
1068 .Li INHIBIT_COMMON_ALLOCATION
1069 has the same effect.See Section
1070 .Dq Miscellaneous Commands .
1071 .Pp
1072 The
1073 .Li --no-define-common
1074 option allows decoupling the decision to assign addresses to Common symbols
1075 from the choice of the output file type; otherwise a non-Relocatable output
1076 type forces assigning addresses to Common symbols. Using
1077 .Li --no-define-common
1078 allows Common symbols that are referenced from a shared library to be assigned
1079 addresses only in the main program. This eliminates the unused duplicate space
1080 in the shared library, and also prevents any possible confusion over resolving
1081 to the wrong duplicate when there are many dynamic modules with specialized
1082 search paths for runtime symbol resolution.
1083 .Pp
1084 .It  --defsym Va symbol= Va expression
1085 Create a global symbol in the output file, containing the absolute address
1086 given by
1087 .Va expression .
1088 You may use this option as many times as necessary to define multiple symbols
1089 in the command line. A limited form of arithmetic is supported for the
1090 .Va expression
1091 in this context: you may give a hexadecimal constant or the name of an existing
1092 symbol, or use
1093 .Li +
1094 and
1095 .Li -
1096 to add or subtract hexadecimal constants or symbols. If you need more elaborate
1097 expressions, consider using the linker command language from a script (see Section
1098 .Dq Assignments ) .
1099 .Em Note:
1100 there should be no white space between
1101 .Va symbol ,
1102 the equals sign (\(lq=\(rq), and
1103 .Va expression .
1104 .Pp
1105 .It  --demangle[= Va style]
1106 .It  --no-demangle
1107 These options control whether to demangle symbol names in error messages and
1108 other output. When the linker is told to demangle, it tries to present symbol
1109 names in a readable fashion: it strips leading underscores if they are used
1110 by the object file format, and converts C++ mangled symbol names into user
1111 readable names. Different compilers have different mangling styles. The optional
1112 demangling style argument can be used to choose an appropriate demangling
1113 style for your compiler. The linker will demangle by default unless the environment
1114 variable
1115 .Li COLLECT_NO_DEMANGLE
1116 is set. These options may be used to override the default.
1117 .Pp
1118 .It  --dynamic-linker Va file
1119 Set the name of the dynamic linker. This is only meaningful when generating
1120 dynamically linked ELF executables. The default dynamic linker is normally
1121 correct; don't use this unless you know what you are doing.
1122 .Pp
1123 .It  --fatal-warnings
1124 Treat all warnings as errors.
1125 .Pp
1126 .It  --force-exe-suffix
1127 Make sure that an output file has a .exe suffix.
1128 .Pp
1129 If a successfully built fully linked output file does not have a
1130 .Li .exe
1131 or
1132 .Li .dll
1133 suffix, this option forces the linker to copy the output file to one of the
1134 same name with a
1135 .Li .exe
1136 suffix. This option is useful when using unmodified Unix makefiles on a Microsoft
1137 Windows host, since some versions of Windows won't run an image unless it
1138 ends in a
1139 .Li .exe
1140 suffix.
1141 .Pp
1142 .It  --gc-sections
1143 .It  --no-gc-sections
1144 Enable garbage collection of unused input sections. It is ignored on targets
1145 that do not support this option. This option is not compatible with
1146 .Li -r
1147 or
1148 .Li --emit-relocs .
1149 The default behaviour (of not performing this garbage collection) can be restored
1150 by specifying
1151 .Li --no-gc-sections
1152 on the command line.
1153 .Pp
1154 .It  --print-gc-sections
1155 .It  --no-print-gc-sections
1156 List all sections removed by garbage collection. The listing is printed on
1157 stderr. This option is only effective if garbage collection has been enabled
1158 via the
1159 .Li --gc-sections )
1160 option. The default behaviour (of not listing the sections that are removed)
1161 can be restored by specifying
1162 .Li --no-print-gc-sections
1163 on the command line.
1164 .Pp
1165 .It  --help
1166 Print a summary of the command-line options on the standard output and exit.
1167 .Pp
1168 .It  --target-help
1169 Print a summary of all target specific options on the standard output and
1170 exit.
1171 .Pp
1172 .It  -Map Va mapfile
1173 Print a link map to the file
1174 .Va mapfile .
1175 See the description of the
1176 .Op -M
1177 option, above.
1178 .Pp
1179 .It  --no-keep-memory
1180 .Xr ld
1181 normally optimizes for speed over memory usage by caching the symbol tables
1182 of input files in memory. This option tells
1183 .Xr ld
1184 to instead optimize for memory usage, by rereading the symbol tables as necessary.
1185 This may be required if
1186 .Xr ld
1187 runs out of memory space while linking a large executable.
1188 .Pp
1189 .It  --no-undefined
1190 .It  -z defs
1191 Report unresolved symbol references from regular object files. This is done
1192 even if the linker is creating a non-symbolic shared library. The switch
1193 .Op --[no-]allow-shlib-undefined
1194 controls the behaviour for reporting unresolved references found in shared
1195 libraries being linked in.
1196 .Pp
1197 .It  --allow-multiple-definition
1198 .It  -z muldefs
1199 Normally when a symbol is defined multiple times, the linker will report a
1200 fatal error. These options allow multiple definitions and the first definition
1201 will be used.
1202 .Pp
1203 .It  --allow-shlib-undefined
1204 .It  --no-allow-shlib-undefined
1205 Allows (the default) or disallows undefined symbols in shared libraries. This
1206 switch is similar to
1207 .Op --no-undefined
1208 except that it determines the behaviour when the undefined symbols are in
1209 a shared library rather than a regular object file. It does not affect how
1210 undefined symbols in regular object files are handled.
1211 .Pp
1212 The reason that
1213 .Op --allow-shlib-undefined
1214 is the default is that the shared library being specified at link time may
1215 not be the same as the one that is available at load time, so the symbols
1216 might actually be resolvable at load time. Plus there are some systems, (eg
1217 BeOS) where undefined symbols in shared libraries is normal. (The kernel patches
1218 them at load time to select which function is most appropriate for the current
1219 architecture. This is used for example to dynamically select an appropriate
1220 memset function). Apparently it is also normal for HPPA shared libraries to
1221 have undefined symbols.
1222 .Pp
1223 .It  --no-undefined-version
1224 Normally when a symbol has an undefined version, the linker will ignore it.
1225 This option disallows symbols with undefined version and a fatal error will
1226 be issued instead.
1227 .Pp
1228 .It  --default-symver
1229 Create and use a default symbol version (the soname) for unversioned exported
1230 symbols.
1231 .Pp
1232 .It  --default-imported-symver
1233 Create and use a default symbol version (the soname) for unversioned imported
1234 symbols.
1235 .Pp
1236 .It  --no-warn-mismatch
1237 Normally
1238 .Xr ld
1239 will give an error if you try to link together input files that are mismatched
1240 for some reason, perhaps because they have been compiled for different processors
1241 or for different endiannesses. This option tells
1242 .Xr ld
1243 that it should silently permit such possible errors. This option should only
1244 be used with care, in cases when you have taken some special action that ensures
1245 that the linker errors are inappropriate.
1246 .Pp
1247 .It  --no-warn-search-mismatch
1248 Normally
1249 .Xr ld
1250 will give a warning if it finds an incompatible library during a library search.
1251 This option silences the warning.
1252 .Pp
1253 .It  --no-whole-archive
1254 Turn off the effect of the
1255 .Op --whole-archive
1256 option for subsequent archive files.
1257 .Pp
1258 .It  --noinhibit-exec
1259 Retain the executable output file whenever it is still usable. Normally, the
1260 linker will not produce an output file if it encounters errors during the
1261 link process; it exits without writing an output file when it issues any error
1262 whatsoever.
1263 .Pp
1264 .It  -nostdlib
1265 Only search library directories explicitly specified on the command line.
1266 Library directories specified in linker scripts (including linker scripts
1267 specified on the command line) are ignored.
1268 .Pp
1269 .It  --oformat Va output-format
1270 .Xr ld
1271 may be configured to support more than one kind of object file. If your
1272 .Xr ld
1273 is configured this way, you can use the
1274 .Li --oformat
1275 option to specify the binary format for the output object file. Even when
1276 .Xr ld
1277 is configured to support alternative object formats, you don't usually need
1278 to specify this, as
1279 .Xr ld
1280 should be configured to produce as a default output format the most usual
1281 format on each machine.
1282 .Va output-format
1283 is a text string, the name of a particular format supported by the BFD libraries.
1284 (You can list the available binary formats with
1285 .Li objdump -i . )
1286 The script command
1287 .Li OUTPUT_FORMAT
1288 can also specify the output format, but this option overrides it.See Section
1289 .Dq BFD .
1290 .Pp
1291 .It  -pie
1292 .It  --pic-executable
1293 Create a position independent executable. This is currently only supported
1294 on ELF platforms. Position independent executables are similar to shared libraries
1295 in that they are relocated by the dynamic linker to the virtual address the
1296 OS chooses for them (which can vary between invocations). Like normal dynamically
1297 linked executables they can be executed and symbols defined in the executable
1298 cannot be overridden by shared libraries.
1299 .Pp
1300 .It  -qmagic
1301 This option is ignored for Linux compatibility.
1302 .Pp
1303 .It  -Qy
1304 This option is ignored for SVR4 compatibility.
1305 .Pp
1306 .It  --relax
1307 An option with machine dependent effects. This option is only supported on
1308 a few targets.See Section
1309 .Dq H8/300 .
1310 See Section.Dq i960 .
1311 See Section.Dq Xtensa .
1312 See Section.Dq M68HC11/68HC12 .
1313 See Section.Dq PowerPC ELF32 .
1314 .Pp
1315 On some platforms, the
1316 .Li --relax
1317 option performs global optimizations that become possible when the linker
1318 resolves addressing in the program, such as relaxing address modes and synthesizing
1319 new instructions in the output object file.
1320 .Pp
1321 On some platforms these link time global optimizations may make symbolic debugging
1322 of the resulting executable impossible. This is known to be the case for the
1323 Matsushita MN10200 and MN10300 family of processors.
1324 .Pp
1325 On platforms where this is not supported,
1326 .Li --relax
1327 is accepted, but ignored.
1328 .Pp
1329 .It  --retain-symbols-file Va filename
1330 Retain
1331 .Em only
1332 the symbols listed in the file
1333 .Va filename ,
1334 discarding all others.
1335 .Va filename
1336 is simply a flat file, with one symbol name per line. This option is especially
1337 useful in environments (such as VxWorks) where a large global symbol table
1338 is accumulated gradually, to conserve run-time memory.
1339 .Pp
1340 .Li --retain-symbols-file
1341 does
1342 .Em not
1343 discard undefined symbols, or symbols needed for relocations.
1344 .Pp
1345 You may only specify
1346 .Li --retain-symbols-file
1347 once in the command line. It overrides
1348 .Li -s
1349 and
1350 .Li -S .
1351 .Pp
1352 .It  -rpath Va dir
1353 Add a directory to the runtime library search path. This is used when linking
1354 an ELF executable with shared objects. All
1355 .Op -rpath
1356 arguments are concatenated and passed to the runtime linker, which uses them
1357 to locate shared objects at runtime. The
1358 .Op -rpath
1359 option is also used when locating shared objects which are needed by shared
1360 objects explicitly included in the link; see the description of the
1361 .Op -rpath-link
1362 option. If
1363 .Op -rpath
1364 is not used when linking an ELF executable, the contents of the environment
1365 variable
1366 .Li LD_RUN_PATH
1367 will be used if it is defined.
1368 .Pp
1369 The
1370 .Op -rpath
1371 option may also be used on SunOS. By default, on SunOS, the linker will form
1372 a runtime search patch out of all the
1373 .Op -L
1374 options it is given. If a
1375 .Op -rpath
1376 option is used, the runtime search path will be formed exclusively using the
1377 .Op -rpath
1378 options, ignoring the
1379 .Op -L
1380 options. This can be useful when using gcc, which adds many
1381 .Op -L
1382 options which may be on NFS mounted file systems.
1383 .Pp
1384 For compatibility with other ELF linkers, if the
1385 .Op -R
1386 option is followed by a directory name, rather than a file name, it is treated
1387 as the
1388 .Op -rpath
1389 option.
1390 .Pp
1391 .It  -rpath-link Va DIR
1392 When using ELF or SunOS, one shared library may require another. This happens
1393 when an
1394 .Li ld -shared
1395 link includes a shared library as one of the input files.
1396 .Pp
1397 When the linker encounters such a dependency when doing a non-shared, non-relocatable
1398 link, it will automatically try to locate the required shared library and
1399 include it in the link, if it is not included explicitly. In such a case,
1400 the
1401 .Op -rpath-link
1402 option specifies the first set of directories to search. The
1403 .Op -rpath-link
1404 option may specify a sequence of directory names either by specifying a list
1405 of names separated by colons, or by appearing multiple times.
1406 .Pp
1407 This option should be used with caution as it overrides the search path that
1408 may have been hard compiled into a shared library. In such a case it is possible
1409 to use unintentionally a different search path than the runtime linker would
1410 do.
1411 .Pp
1412 The linker uses the following search paths to locate required shared libraries:
1413 .Bl -enum
1414 .It
1415 Any directories specified by
1416 .Op -rpath-link
1417 options.
1418 .It
1419 Any directories specified by
1420 .Op -rpath
1421 options. The difference between
1422 .Op -rpath
1423 and
1424 .Op -rpath-link
1425 is that directories specified by
1426 .Op -rpath
1427 options are included in the executable and used at runtime, whereas the
1428 .Op -rpath-link
1429 option is only effective at link time. Searching
1430 .Op -rpath
1431 in this way is only supported by native linkers and cross linkers which have
1432 been configured with the
1433 .Op --with-sysroot
1434 option.
1435 .It
1436 On an ELF system, if the
1437 .Op -rpath
1438 and
1439 .Li rpath-link
1440 options were not used, search the contents of the environment variable
1441 .Li LD_RUN_PATH .
1442 It is for the native linker only.
1443 .It
1444 On SunOS, if the
1445 .Op -rpath
1446 option was not used, search any directories specified using
1447 .Op -L
1448 options.
1449 .It
1450 For a native linker, the contents of the environment variable
1451 .Li LD_LIBRARY_PATH .
1452 .It
1453 For a native ELF linker, the directories in
1454 .Li DT_RUNPATH
1455 or
1456 .Li DT_RPATH
1457 of a shared library are searched for shared libraries needed by it. The
1458 .Li DT_RPATH
1459 entries are ignored if
1460 .Li DT_RUNPATH
1461 entries exist.
1462 .It
1463 The default directories, normally
1464 .Pa /lib
1465 and
1466 .Pa /usr/lib .
1467 .It
1468 For a native linker on an ELF system, if the file
1469 .Pa /etc/ld.so.conf
1470 exists, the list of directories found in that file.
1471 .El
1472 .Pp
1473 If the required shared library is not found, the linker will issue a warning
1474 and continue with the link.
1475 .Pp
1476 .It  -shared
1477 .It  -Bshareable
1478 Create a shared library. This is currently only supported on ELF, XCOFF and
1479 SunOS platforms. On SunOS, the linker will automatically create a shared library
1480 if the
1481 .Op -e
1482 option is not used and there are undefined symbols in the link.
1483 .Pp
1484 .It  --sort-common
1485 This option tells
1486 .Xr ld
1487 to sort the common symbols by size when it places them in the appropriate
1488 output sections. First come all the one byte symbols, then all the two byte,
1489 then all the four byte, and then everything else. This is to prevent gaps
1490 between symbols due to alignment constraints.
1491 .Pp
1492 .It  --sort-section name
1493 This option will apply
1494 .Li SORT_BY_NAME
1495 to all wildcard section patterns in the linker script.
1496 .Pp
1497 .It  --sort-section alignment
1498 This option will apply
1499 .Li SORT_BY_ALIGNMENT
1500 to all wildcard section patterns in the linker script.
1501 .Pp
1502 .It  --split-by-file [ Va size]
1503 Similar to
1504 .Op --split-by-reloc
1505 but creates a new output section for each input file when
1506 .Va size
1507 is reached.
1508 .Va size
1509 defaults to a size of 1 if not given.
1510 .Pp
1511 .It  --split-by-reloc [ Va count]
1512 Tries to creates extra sections in the output file so that no single output
1513 section in the file contains more than
1514 .Va count
1515 relocations. This is useful when generating huge relocatable files for downloading
1516 into certain real time kernels with the COFF object file format; since COFF
1517 cannot represent more than 65535 relocations in a single section. Note that
1518 this will fail to work with object file formats which do not support arbitrary
1519 sections. The linker will not split up individual input sections for redistribution,
1520 so if a single input section contains more than
1521 .Va count
1522 relocations one output section will contain that many relocations.
1523 .Va count
1524 defaults to a value of 32768.
1525 .Pp
1526 .It  --stats
1527 Compute and display statistics about the operation of the linker, such as
1528 execution time and memory usage.
1529 .Pp
1530 .It  --sysroot= Va directory
1531 Use
1532 .Va directory
1533 as the location of the sysroot, overriding the configure-time default. This
1534 option is only supported by linkers that were configured using
1535 .Op --with-sysroot .
1536 .Pp
1537 .It  --traditional-format
1538 For some targets, the output of
1539 .Xr ld
1540 is different in some ways from the output of some existing linker. This switch
1541 requests
1542 .Xr ld
1543 to use the traditional format instead.
1544 .Pp
1545 For example, on SunOS,
1546 .Xr ld
1547 combines duplicate entries in the symbol string table. This can reduce the
1548 size of an output file with full debugging information by over 30 percent.
1549 Unfortunately, the SunOS
1550 .Li dbx
1551 program can not read the resulting program (
1552 .Li gdb
1553 has no trouble). The
1554 .Li --traditional-format
1555 switch tells
1556 .Xr ld
1557 to not combine duplicate entries.
1558 .Pp
1559 .It  --section-start Va sectionname= Va org
1560 Locate a section in the output file at the absolute address given by
1561 .Va org .
1562 You may use this option as many times as necessary to locate multiple sections
1563 in the command line.
1564 .Va org
1565 must be a single hexadecimal integer; for compatibility with other linkers,
1566 you may omit the leading
1567 .Li 0x
1568 usually associated with hexadecimal values.
1569 .Em Note:
1570 there should be no white space between
1571 .Va sectionname ,
1572 the equals sign (\(lq=\(rq), and
1573 .Va org .
1574 .Pp
1575 .It  -Tbss Va org
1576 .It  -Tdata Va org
1577 .It  -Ttext Va org
1578 Same as --section-start, with
1579 .Li .bss ,
1580 .Li .data
1581 or
1582 .Li .text
1583 as the
1584 .Va sectionname .
1585 .Pp
1586 .It  --unresolved-symbols= Va method
1587 Determine how to handle unresolved symbols. There are four possible values
1588 for
1589 .Li method :
1590 .Pp
1591 .Bl -tag -width Ds
1592 .It  ignore-all
1593 Do not report any unresolved symbols.
1594 .Pp
1595 .It  report-all
1596 Report all unresolved symbols. This is the default.
1597 .Pp
1598 .It  ignore-in-object-files
1599 Report unresolved symbols that are contained in shared libraries, but ignore
1600 them if they come from regular object files.
1601 .Pp
1602 .It  ignore-in-shared-libs
1603 Report unresolved symbols that come from regular object files, but ignore
1604 them if they come from shared libraries. This can be useful when creating
1605 a dynamic binary and it is known that all the shared libraries that it should
1606 be referencing are included on the linker's command line.
1607 .El
1608 .Pp
1609 The behaviour for shared libraries on their own can also be controlled by
1610 the
1611 .Op --[no-]allow-shlib-undefined
1612 option.
1613 .Pp
1614 Normally the linker will generate an error message for each reported unresolved
1615 symbol but the option
1616 .Op --warn-unresolved-symbols
1617 can change this to a warning.
1618 .Pp
1619 .It  --dll-verbose
1620 .It  --verbose
1621 Display the version number for
1622 .Xr ld
1623 and list the linker emulations supported. Display which input files can and
1624 cannot be opened. Display the linker script being used by the linker.
1625 .Pp
1626 .It  --version-script= Va version-scriptfile
1627 Specify the name of a version script to the linker. This is typically used
1628 when creating shared libraries to specify additional information about the
1629 version hierarchy for the library being created. This option is only meaningful
1630 on ELF platforms which support shared libraries.See Section
1631 .Dq VERSION .
1632 .Pp
1633 .It  --warn-common
1634 Warn when a common symbol is combined with another common symbol or with a
1635 symbol definition. Unix linkers allow this somewhat sloppy practise, but linkers
1636 on some other operating systems do not. This option allows you to find potential
1637 problems from combining global symbols. Unfortunately, some C libraries use
1638 this practise, so you may get some warnings about symbols in the libraries
1639 as well as in your programs.
1640 .Pp
1641 There are three kinds of global symbols, illustrated here by C examples:
1642 .Pp
1643 .Bl -tag -width Ds
1644 .It  int i = 1;
1645 A definition, which goes in the initialized data section of the output file.
1646 .Pp
1647 .It  extern int i;
1648 An undefined reference, which does not allocate space. There must be either
1649 a definition or a common symbol for the variable somewhere.
1650 .Pp
1651 .It  int i;
1652 A common symbol. If there are only (one or more) common symbols for a variable,
1653 it goes in the uninitialized data area of the output file. The linker merges
1654 multiple common symbols for the same variable into a single symbol. If they
1655 are of different sizes, it picks the largest size. The linker turns a common
1656 symbol into a declaration, if there is a definition of the same variable.
1657 .El
1658 .Pp
1659 The
1660 .Li --warn-common
1661 option can produce five kinds of warnings. Each warning consists of a pair
1662 of lines: the first describes the symbol just encountered, and the second
1663 describes the previous symbol encountered with the same name. One or both
1664 of the two symbols will be a common symbol.
1665 .Pp
1666 .Bl -enum
1667 .It
1668 Turning a common symbol into a reference, because there is already a definition
1669 for the symbol.
1670 .Bd -literal -offset indent
1671 file(section): warning: common of `symbol'
1672    overridden by definition
1673 file(section): warning: defined here
1674 .Ed
1675 .Pp
1676 .It
1677 Turning a common symbol into a reference, because a later definition for the
1678 symbol is encountered. This is the same as the previous case, except that
1679 the symbols are encountered in a different order.
1680 .Bd -literal -offset indent
1681 file(section): warning: definition of `symbol'
1682    overriding common
1683 file(section): warning: common is here
1684 .Ed
1685 .Pp
1686 .It
1687 Merging a common symbol with a previous same-sized common symbol.
1688 .Bd -literal -offset indent
1689 file(section): warning: multiple common
1690    of `symbol'
1691 file(section): warning: previous common is here
1692 .Ed
1693 .Pp
1694 .It
1695 Merging a common symbol with a previous larger common symbol.
1696 .Bd -literal -offset indent
1697 file(section): warning: common of `symbol'
1698    overridden by larger common
1699 file(section): warning: larger common is here
1700 .Ed
1701 .Pp
1702 .It
1703 Merging a common symbol with a previous smaller common symbol. This is the
1704 same as the previous case, except that the symbols are encountered in a different
1705 order.
1706 .Bd -literal -offset indent
1707 file(section): warning: common of `symbol'
1708    overriding smaller common
1709 file(section): warning: smaller common is here
1710 .Ed
1711 .El
1712 .Pp
1713 .It  --warn-constructors
1714 Warn if any global constructors are used. This is only useful for a few object
1715 file formats. For formats like COFF or ELF, the linker can not detect the
1716 use of global constructors.
1717 .Pp
1718 .It  --warn-multiple-gp
1719 Warn if multiple global pointer values are required in the output file. This
1720 is only meaningful for certain processors, such as the Alpha. Specifically,
1721 some processors put large-valued constants in a special section. A special
1722 register (the global pointer) points into the middle of this section, so that
1723 constants can be loaded efficiently via a base-register relative addressing
1724 mode. Since the offset in base-register relative mode is fixed and relatively
1725 small (e.g., 16 bits), this limits the maximum size of the constant pool.
1726 Thus, in large programs, it is often necessary to use multiple global pointer
1727 values in order to be able to address all possible constants. This option
1728 causes a warning to be issued whenever this case occurs.
1729 .Pp
1730 .It  --warn-once
1731 Only warn once for each undefined symbol, rather than once per module which
1732 refers to it.
1733 .Pp
1734 .It  --warn-section-align
1735 Warn if the address of an output section is changed because of alignment.
1736 Typically, the alignment will be set by an input section. The address will
1737 only be changed if it not explicitly specified; that is, if the
1738 .Li SECTIONS
1739 command does not specify a start address for the section (see Section
1740 .Dq SECTIONS ) .
1741 .Pp
1742 .It  --warn-shared-textrel
1743 Warn if the linker adds a DT_TEXTREL to a shared object.
1744 .Pp
1745 .It  --warn-unresolved-symbols
1746 If the linker is going to report an unresolved symbol (see the option
1747 .Op --unresolved-symbols )
1748 it will normally generate an error. This option makes it generate a warning
1749 instead.
1750 .Pp
1751 .It  --error-unresolved-symbols
1752 This restores the linker's default behaviour of generating errors when it
1753 is reporting unresolved symbols.
1754 .Pp
1755 .It  --whole-archive
1756 For each archive mentioned on the command line after the
1757 .Op --whole-archive
1758 option, include every object file in the archive in the link, rather than
1759 searching the archive for the required object files. This is normally used
1760 to turn an archive file into a shared library, forcing every object to be
1761 included in the resulting shared library. This option may be used more than
1762 once.
1763 .Pp
1764 Two notes when using this option from gcc: First, gcc doesn't know about this
1765 option, so you have to use
1766 .Op -Wl,-whole-archive .
1767 Second, don't forget to use
1768 .Op -Wl,-no-whole-archive
1769 after your list of archives, because gcc will add its own list of archives
1770 to your link and you may not want this flag to affect those as well.
1771 .Pp
1772 .It  --wrap Va symbol
1773 Use a wrapper function for
1774 .Va symbol .
1775 Any undefined reference to
1776 .Va symbol
1777 will be resolved to
1778 .Li __wrap_ Va symbol .
1779 Any undefined reference to
1780 .Li __real_ Va symbol
1781 will be resolved to
1782 .Va symbol .
1783 .Pp
1784 This can be used to provide a wrapper for a system function. The wrapper function
1785 should be called
1786 .Li __wrap_ Va symbol .
1787 If it wishes to call the system function, it should call
1788 .Li __real_ Va symbol .
1789 .Pp
1790 Here is a trivial example:
1791 .Pp
1792 .Bd -literal -offset indent
1793 void *
1794 __wrap_malloc (size_t c)
1795 {
1796   printf ("malloc called with %zu\en", c);
1797   return __real_malloc (c);
1798 }
1799 .Ed
1800 .Pp
1801 If you link other code with this file using
1802 .Op --wrap malloc ,
1803 then all calls to
1804 .Li malloc
1805 will call the function
1806 .Li __wrap_malloc
1807 instead. The call to
1808 .Li __real_malloc
1809 in
1810 .Li __wrap_malloc
1811 will call the real
1812 .Li malloc
1813 function.
1814 .Pp
1815 You may wish to provide a
1816 .Li __real_malloc
1817 function as well, so that links without the
1818 .Op --wrap
1819 option will succeed. If you do this, you should not put the definition of
1820 .Li __real_malloc
1821 in the same file as
1822 .Li __wrap_malloc ;
1823 if you do, the assembler may resolve the call before the linker has a chance
1824 to wrap it to
1825 .Li malloc .
1826 .Pp
1827 .It  --eh-frame-hdr
1828 Request creation of
1829 .Li .eh_frame_hdr
1830 section and ELF
1831 .Li PT_GNU_EH_FRAME
1832 segment header.
1833 .Pp
1834 .It  --enable-new-dtags
1835 .It  --disable-new-dtags
1836 This linker can create the new dynamic tags in ELF. But the older ELF systems
1837 may not understand them. If you specify
1838 .Op --enable-new-dtags ,
1839 the dynamic tags will be created as needed. If you specify
1840 .Op --disable-new-dtags ,
1841 no new dynamic tags will be created. By default, the new dynamic tags are
1842 not created. Note that those options are only available for ELF systems.
1843 .Pp
1844 .It  --hash-size= Va number
1845 Set the default size of the linker's hash tables to a prime number close to
1846 .Va number .
1847 Increasing this value can reduce the length of time it takes the linker to
1848 perform its tasks, at the expense of increasing the linker's memory requirements.
1849 Similarly reducing this value can reduce the memory requirements at the expense
1850 of speed.
1851 .Pp
1852 .It  --hash-style= Va style
1853 Set the type of linker's hash table(s).
1854 .Va style
1855 can be either
1856 .Li sysv
1857 for classic ELF
1858 .Li .hash
1859 section,
1860 .Li GNU
1861 for new style GNU
1862 .Li .GNU.hash
1863 section or
1864 .Li both
1865 for both the classic ELF
1866 .Li .hash
1867 and new style GNU
1868 .Li .GNU.hash
1869 hash tables. The default is
1870 .Li sysv .
1871 .Pp
1872 .It  --reduce-memory-overheads
1873 This option reduces memory requirements at ld runtime, at the expense of linking
1874 speed. This was introduced to select the old O(n^2) algorithm for link map
1875 file generation, rather than the new O(n) algorithm which uses about 40% more
1876 memory for symbol storage.
1877 .Pp
1878 Another effect of the switch is to set the default hash table size to 1021,
1879 which again saves memory at the cost of lengthening the linker's run time.
1880 This is not done however if the
1881 .Op --hash-size
1882 switch has been used.
1883 .Pp
1884 The
1885 .Op --reduce-memory-overheads
1886 switch may be also be used to enable other tradeoffs in future versions of
1887 the linker.
1888 .Pp
1889 .El
1890 .Em  Options Specific to i386 PE Targets
1891 .Pp
1892 The i386 PE linker supports the
1893 .Op -shared
1894 option, which causes the output to be a dynamically linked library (DLL) instead
1895 of a normal executable. You should name the output
1896 .Li *.dll
1897 when you use this option. In addition, the linker fully supports the standard
1898 .Li *.def
1899 files, which may be specified on the linker command line like an object file
1900 (in fact, it should precede archives it exports symbols from, to ensure that
1901 they get linked in, just like a normal object file).
1902 .Pp
1903 In addition to the options common to all targets, the i386 PE linker support
1904 additional command line options that are specific to the i386 PE target. Options
1905 that take values may be separated from their values by either a space or an
1906 equals sign.
1907 .Pp
1908 .Bl -tag -width Ds
1909 .It  --add-stdcall-alias
1910 If given, symbols with a stdcall suffix (@
1911 .Va nn )
1912 will be exported as-is and also with the suffix stripped. [This option is
1913 specific to the i386 PE targeted port of the linker]
1914 .Pp
1915 .It  --base-file Va file
1916 Use
1917 .Va file
1918 as the name of a file in which to save the base addresses of all the relocations
1919 needed for generating DLLs with
1920 .Pa dlltool .
1921 [This is an i386 PE specific option]
1922 .Pp
1923 .It  --dll
1924 Create a DLL instead of a regular executable. You may also use
1925 .Op -shared
1926 or specify a
1927 .Li LIBRARY
1928 in a given
1929 .Li .def
1930 file. [This option is specific to the i386 PE targeted port of the linker]
1931 .Pp
1932 .It  --enable-stdcall-fixup
1933 .It  --disable-stdcall-fixup
1934 If the link finds a symbol that it cannot resolve, it will attempt to do \(lqfuzzy
1935 linking\(rq by looking for another defined symbol that differs only in the format
1936 of the symbol name (cdecl vs stdcall) and will resolve that symbol by linking
1937 to the match. For example, the undefined symbol
1938 .Li _foo
1939 might be linked to the function
1940 .Li _foo@12 ,
1941 or the undefined symbol
1942 .Li _bar@16
1943 might be linked to the function
1944 .Li _bar .
1945 When the linker does this, it prints a warning, since it normally should have
1946 failed to link, but sometimes import libraries generated from third-party
1947 dlls may need this feature to be usable. If you specify
1948 .Op --enable-stdcall-fixup ,
1949 this feature is fully enabled and warnings are not printed. If you specify
1950 .Op --disable-stdcall-fixup ,
1951 this feature is disabled and such mismatches are considered to be errors.
1952 [This option is specific to the i386 PE targeted port of the linker]
1953 .Pp
1954 .It  --export-all-symbols
1955 If given, all global symbols in the objects used to build a DLL will be exported
1956 by the DLL. Note that this is the default if there otherwise wouldn't be any
1957 exported symbols. When symbols are explicitly exported via DEF files or implicitly
1958 exported via function attributes, the default is to not export anything else
1959 unless this option is given. Note that the symbols
1960 .Li DllMain@12 ,
1961 .Li DllEntryPoint@0 ,
1962 .Li DllMainCRTStartup@12 ,
1963 and
1964 .Li impure_ptr
1965 will not be automatically exported. Also, symbols imported from other DLLs
1966 will not be re-exported, nor will symbols specifying the DLL's internal layout
1967 such as those beginning with
1968 .Li _head_
1969 or ending with
1970 .Li _iname .
1971 In addition, no symbols from
1972 .Li libgcc ,
1973 .Li libstd++ ,
1974 .Li libmingw32 ,
1975 or
1976 .Li crtX.o
1977 will be exported. Symbols whose names begin with
1978 .Li __rtti_
1979 or
1980 .Li __builtin_
1981 will not be exported, to help with C++ DLLs. Finally, there is an extensive
1982 list of cygwin-private symbols that are not exported (obviously, this applies
1983 on when building DLLs for cygwin targets). These cygwin-excludes are:
1984 .Li _cygwin_dll_entry@12 ,
1985 .Li _cygwin_crt0_common@8 ,
1986 .Li _cygwin_noncygwin_dll_entry@12 ,
1987 .Li _fmode ,
1988 .Li _impure_ptr ,
1989 .Li cygwin_attach_dll ,
1990 .Li cygwin_premain0 ,
1991 .Li cygwin_premain1 ,
1992 .Li cygwin_premain2 ,
1993 .Li cygwin_premain3 ,
1994 and
1995 .Li environ .
1996 [This option is specific to the i386 PE targeted port of the linker]
1997 .Pp
1998 .It  --exclude-symbols Va symbol, Va symbol,...
1999 Specifies a list of symbols which should not be automatically exported. The
2000 symbol names may be delimited by commas or colons. [This option is specific
2001 to the i386 PE targeted port of the linker]
2002 .Pp
2003 .It  --file-alignment
2004 Specify the file alignment. Sections in the file will always begin at file
2005 offsets which are multiples of this number. This defaults to 512. [This option
2006 is specific to the i386 PE targeted port of the linker]
2007 .Pp
2008 .It  --heap Va reserve
2009 .It  --heap Va reserve, Va commit
2010 Specify the amount of memory to reserve (and optionally commit) to be used
2011 as heap for this program. The default is 1Mb reserved, 4K committed. [This
2012 option is specific to the i386 PE targeted port of the linker]
2013 .Pp
2014 .It  --image-base Va value
2015 Use
2016 .Va value
2017 as the base address of your program or dll. This is the lowest memory location
2018 that will be used when your program or dll is loaded. To reduce the need to
2019 relocate and improve performance of your dlls, each should have a unique base
2020 address and not overlap any other dlls. The default is 0x400000 for executables,
2021 and 0x10000000 for dlls. [This option is specific to the i386 PE targeted
2022 port of the linker]
2023 .Pp
2024 .It  --kill-at
2025 If given, the stdcall suffixes (@
2026 .Va nn )
2027 will be stripped from symbols before they are exported. [This option is specific
2028 to the i386 PE targeted port of the linker]
2029 .Pp
2030 .It  --large-address-aware
2031 If given, the appropriate bit in the \(lqCharacteristics\(rq field of the COFF header
2032 is set to indicate that this executable supports virtual addresses greater
2033 than 2 gigabytes. This should be used in conjunction with the /3GB or /USERVA=
2034 .Va value
2035 megabytes switch in the \(lq[operating systems]\(rq section of the BOOT.INI. Otherwise,
2036 this bit has no effect. [This option is specific to PE targeted ports of the
2037 linker]
2038 .Pp
2039 .It  --major-image-version Va value
2040 Sets the major number of the \(lqimage version\(rq. Defaults to 1. [This option is
2041 specific to the i386 PE targeted port of the linker]
2042 .Pp
2043 .It  --major-os-version Va value
2044 Sets the major number of the \(lqos version\(rq. Defaults to 4. [This option is specific
2045 to the i386 PE targeted port of the linker]
2046 .Pp
2047 .It  --major-subsystem-version Va value
2048 Sets the major number of the \(lqsubsystem version\(rq. Defaults to 4. [This option
2049 is specific to the i386 PE targeted port of the linker]
2050 .Pp
2051 .It  --minor-image-version Va value
2052 Sets the minor number of the \(lqimage version\(rq. Defaults to 0. [This option is
2053 specific to the i386 PE targeted port of the linker]
2054 .Pp
2055 .It  --minor-os-version Va value
2056 Sets the minor number of the \(lqos version\(rq. Defaults to 0. [This option is specific
2057 to the i386 PE targeted port of the linker]
2058 .Pp
2059 .It  --minor-subsystem-version Va value
2060 Sets the minor number of the \(lqsubsystem version\(rq. Defaults to 0. [This option
2061 is specific to the i386 PE targeted port of the linker]
2062 .Pp
2063 .It  --output-def Va file
2064 The linker will create the file
2065 .Va file
2066 which will contain a DEF file corresponding to the DLL the linker is generating.
2067 This DEF file (which should be called
2068 .Li *.def )
2069 may be used to create an import library with
2070 .Li dlltool
2071 or may be used as a reference to automatically or implicitly exported symbols.
2072 [This option is specific to the i386 PE targeted port of the linker]
2073 .Pp
2074 .It  --out-implib Va file
2075 The linker will create the file
2076 .Va file
2077 which will contain an import lib corresponding to the DLL the linker is generating.
2078 This import lib (which should be called
2079 .Li *.dll.a
2080 or
2081 .Li *.a
2082 may be used to link clients against the generated DLL; this behaviour makes
2083 it possible to skip a separate
2084 .Li dlltool
2085 import library creation step. [This option is specific to the i386 PE targeted
2086 port of the linker]
2087 .Pp
2088 .It  --enable-auto-image-base
2089 Automatically choose the image base for DLLs, unless one is specified using
2090 the
2091 .Li --image-base
2092 argument. By using a hash generated from the dllname to create unique image
2093 bases for each DLL, in-memory collisions and relocations which can delay program
2094 execution are avoided. [This option is specific to the i386 PE targeted port
2095 of the linker]
2096 .Pp
2097 .It  --disable-auto-image-base
2098 Do not automatically generate a unique image base. If there is no user-specified
2099 image base (
2100 .Li --image-base )
2101 then use the platform default. [This option is specific to the i386 PE targeted
2102 port of the linker]
2103 .Pp
2104 .It  --dll-search-prefix Va string
2105 When linking dynamically to a dll without an import library, search for
2106 .Li <string><basename>.dll
2107 in preference to
2108 .Li lib<basename>.dll .
2109 This behaviour allows easy distinction between DLLs built for the various
2110 "subplatforms": native, cygwin, uwin, pw, etc. For instance, cygwin DLLs typically
2111 use
2112 .Li --dll-search-prefix=cyg .
2113 [This option is specific to the i386 PE targeted port of the linker]
2114 .Pp
2115 .It  --enable-auto-import
2116 Do sophisticated linking of
2117 .Li _symbol
2118 to
2119 .Li __imp__symbol
2120 for DATA imports from DLLs, and create the necessary thunking symbols when
2121 building the import libraries with those DATA exports. Note: Use of the 'auto-import'
2122 extension will cause the text section of the image file to be made writable.
2123 This does not conform to the PE-COFF format specification published by Microsoft.
2124 .Pp
2125 Using 'auto-import' generally will 'just work' -- but sometimes you may see
2126 this message:
2127 .Pp
2128 "variable '<var>' can't be auto-imported. Please read the documentation for
2129 ld's
2130 .Li --enable-auto-import
2131 for details."
2132 .Pp
2133 This message occurs when some (sub)expression accesses an address ultimately
2134 given by the sum of two constants (Win32 import tables only allow one). Instances
2135 where this may occur include accesses to member fields of struct variables
2136 imported from a DLL, as well as using a constant index into an array variable
2137 imported from a DLL. Any multiword variable (arrays, structs, long long, etc)
2138 may trigger this error condition. However, regardless of the exact data type
2139 of the offending exported variable, ld will always detect it, issue the warning,
2140 and exit.
2141 .Pp
2142 There are several ways to address this difficulty, regardless of the data
2143 type of the exported variable:
2144 .Pp
2145 One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
2146 of adjusting references in your client code for runtime environment, so this
2147 method works only when runtime environment supports this feature.
2148 .Pp
2149 A second solution is to force one of the 'constants' to be a variable -- that
2150 is, unknown and un-optimizable at compile time. For arrays, there are two
2151 possibilities: a) make the indexee (the array's address) a variable, or b)
2152 make the 'constant' index a variable. Thus:
2153 .Pp
2154 .Bd -literal -offset indent
2155 extern type extern_array[];
2156 extern_array[1] --> 
2157    { volatile type *t=extern_array; t[1] }
2158 .Ed
2159 .Pp
2160 or
2161 .Pp
2162 .Bd -literal -offset indent
2163 extern type extern_array[];
2164 extern_array[1] --> 
2165    { volatile int t=1; extern_array[t] }
2166 .Ed
2167 .Pp
2168 For structs (and most other multiword data types) the only option is to make
2169 the struct itself (or the long long, or the ...) variable:
2170 .Pp
2171 .Bd -literal -offset indent
2172 extern struct s extern_struct;
2173 extern_struct.field --> 
2174    { volatile struct s *t=&extern_struct; t->field }
2175 .Ed
2176 .Pp
2177 or
2178 .Pp
2179 .Bd -literal -offset indent
2180 extern long long extern_ll;
2181 extern_ll -->
2182   { volatile long long * local_ll=&extern_ll; *local_ll }
2183 .Ed
2184 .Pp
2185 A third method of dealing with this difficulty is to abandon 'auto-import'
2186 for the offending symbol and mark it with
2187 .Li __declspec(dllimport) .
2188 However, in practise that requires using compile-time #defines to indicate
2189 whether you are building a DLL, building client code that will link to the
2190 DLL, or merely building/linking to a static library. In making the choice
2191 between the various methods of resolving the 'direct address with constant
2192 offset' problem, you should consider typical real-world usage:
2193 .Pp
2194 Original:
2195 .Bd -literal -offset indent
2196 --foo.h
2197 extern int arr[];
2198 --foo.c
2199 #include "foo.h"
2200 void main(int argc, char **argv){
2201   printf("%d\en",arr[1]);
2202 }
2203 .Ed
2204 .Pp
2205 Solution 1:
2206 .Bd -literal -offset indent
2207 --foo.h
2208 extern int arr[];
2209 --foo.c
2210 #include "foo.h"
2211 void main(int argc, char **argv){
2212   /* This workaround is for win32 and cygwin; do not "optimize" */
2213   volatile int *parr = arr;
2214   printf("%d\en",parr[1]);
2215 }
2216 .Ed
2217 .Pp
2218 Solution 2:
2219 .Bd -literal -offset indent
2220 --foo.h
2221 /* Note: auto-export is assumed (no __declspec(dllexport)) */
2222 #if (defined(_WIN32) || defined(__CYGWIN__)) && \e
2223   !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
2224 #define FOO_IMPORT __declspec(dllimport)
2225 #else
2226 #define FOO_IMPORT
2227 #endif
2228 extern FOO_IMPORT int arr[];
2229 --foo.c
2230 #include "foo.h"
2231 void main(int argc, char **argv){
2232   printf("%d\en",arr[1]);
2233 }
2234 .Ed
2235 .Pp
2236 A fourth way to avoid this problem is to re-code your library to use a functional
2237 interface rather than a data interface for the offending variables (e.g. set_foo()
2238 and get_foo() accessor functions). [This option is specific to the i386 PE
2239 targeted port of the linker]
2240 .Pp
2241 .It  --disable-auto-import
2242 Do not attempt to do sophisticated linking of
2243 .Li _symbol
2244 to
2245 .Li __imp__symbol
2246 for DATA imports from DLLs. [This option is specific to the i386 PE targeted
2247 port of the linker]
2248 .Pp
2249 .It  --enable-runtime-pseudo-reloc
2250 If your code contains expressions described in --enable-auto-import section,
2251 that is, DATA imports from DLL with non-zero offset, this switch will create
2252 a vector of 'runtime pseudo relocations' which can be used by runtime environment
2253 to adjust references to such data in your client code. [This option is specific
2254 to the i386 PE targeted port of the linker]
2255 .Pp
2256 .It  --disable-runtime-pseudo-reloc
2257 Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
2258 This is the default. [This option is specific to the i386 PE targeted port
2259 of the linker]
2260 .Pp
2261 .It  --enable-extra-pe-debug
2262 Show additional debug info related to auto-import symbol thunking. [This option
2263 is specific to the i386 PE targeted port of the linker]
2264 .Pp
2265 .It  --section-alignment
2266 Sets the section alignment. Sections in memory will always begin at addresses
2267 which are a multiple of this number. Defaults to 0x1000. [This option is specific
2268 to the i386 PE targeted port of the linker]
2269 .Pp
2270 .It  --stack Va reserve
2271 .It  --stack Va reserve, Va commit
2272 Specify the amount of memory to reserve (and optionally commit) to be used
2273 as stack for this program. The default is 2Mb reserved, 4K committed. [This
2274 option is specific to the i386 PE targeted port of the linker]
2275 .Pp
2276 .It  --subsystem Va which
2277 .It  --subsystem Va which: Va major
2278 .It  --subsystem Va which: Va major. Va minor
2279 Specifies the subsystem under which your program will execute. The legal values
2280 for
2281 .Va which
2282 are
2283 .Li native ,
2284 .Li windows ,
2285 .Li console ,
2286 .Li posix ,
2287 and
2288 .Li xbox .
2289 You may optionally set the subsystem version also. Numeric values are also
2290 accepted for
2291 .Va which .
2292 [This option is specific to the i386 PE targeted port of the linker]
2293 .Pp
2294 .El
2295 .Em  Options specific to Motorola 68HC11 and 68HC12 targets
2296 .Pp
2297 The 68HC11 and 68HC12 linkers support specific options to control the memory
2298 bank switching mapping and trampoline code generation.
2299 .Pp
2300 .Bl -tag -width Ds
2301 .It  --no-trampoline
2302 This option disables the generation of trampoline. By default a trampoline
2303 is generated for each far function which is called using a
2304 .Li jsr
2305 instruction (this happens when a pointer to a far function is taken).
2306 .Pp
2307 .It  --bank-window Va name
2308 This option indicates to the linker the name of the memory region in the
2309 .Li MEMORY
2310 specification that describes the memory bank window. The definition of such
2311 region is then used by the linker to compute paging and addresses within the
2312 memory window.
2313 .Pp
2314 .El
2315 .Ss  Environment Variables
2316 You can change the behaviour of
2317 .Xr ld
2318 with the environment variables
2319 .Li GNUTARGET ,
2320 .Li LDEMULATION
2321 and
2322 .Li COLLECT_NO_DEMANGLE .
2323 .Pp
2324 .Li GNUTARGET
2325 determines the input-file object format if you don't use
2326 .Li -b
2327 (or its synonym
2328 .Li --format ) .
2329 Its value should be one of the BFD names for an input format (see Section
2330 .Dq BFD ) .
2331 If there is no
2332 .Li GNUTARGET
2333 in the environment,
2334 .Xr ld
2335 uses the natural format of the target. If
2336 .Li GNUTARGET
2337 is set to
2338 .Li default
2339 then BFD attempts to discover the input format by examining binary input files;
2340 this method often succeeds, but there are potential ambiguities, since there
2341 is no method of ensuring that the magic number used to specify object-file
2342 formats is unique. However, the configuration procedure for BFD on each system
2343 places the conventional format for that system first in the search-list, so
2344 ambiguities are resolved in favor of convention.
2345 .Pp
2346 .Li LDEMULATION
2347 determines the default emulation if you don't use the
2348 .Li -m
2349 option. The emulation can affect various aspects of linker behaviour, particularly
2350 the default linker script. You can list the available emulations with the
2351 .Li --verbose
2352 or
2353 .Li -V
2354 options. If the
2355 .Li -m
2356 option is not used, and the
2357 .Li LDEMULATION
2358 environment variable is not defined, the default emulation depends upon how
2359 the linker was configured.
2360 .Pp
2361 Normally, the linker will default to demangling symbols. However, if
2362 .Li COLLECT_NO_DEMANGLE
2363 is set in the environment, then it will default to not demangling symbols.
2364 This environment variable is used in a similar fashion by the
2365 .Li gcc
2366 linker wrapper program. The default may be overridden by the
2367 .Li --demangle
2368 and
2369 .Li --no-demangle
2370 options.
2371 .Pp
2372 .Sh  Linker Scripts
2373 Every link is controlled by a
2374 .Em linker script .
2375 This script is written in the linker command language.
2376 .Pp
2377 The main purpose of the linker script is to describe how the sections in the
2378 input files should be mapped into the output file, and to control the memory
2379 layout of the output file. Most linker scripts do nothing more than this.
2380 However, when necessary, the linker script can also direct the linker to perform
2381 many other operations, using the commands described below.
2382 .Pp
2383 The linker always uses a linker script. If you do not supply one yourself,
2384 the linker will use a default script that is compiled into the linker executable.
2385 You can use the
2386 .Li --verbose
2387 command line option to display the default linker script. Certain command
2388 line options, such as
2389 .Li -r
2390 or
2391 .Li -N ,
2392 will affect the default linker script.
2393 .Pp
2394 You may supply your own linker script by using the
2395 .Li -T
2396 command line option. When you do this, your linker script will replace the
2397 default linker script.
2398 .Pp
2399 You may also use linker scripts implicitly by naming them as input files to
2400 the linker, as though they were files to be linked.See Section
2401 .Dq Implicit Linker Scripts .
2402 .Pp
2403 .Ss  Basic Linker Script Concepts
2404 We need to define some basic concepts and vocabulary in order to describe
2405 the linker script language.
2406 .Pp
2407 The linker combines input files into a single output file. The output file
2408 and each input file are in a special data format known as an
2409 .Em object file format .
2410 Each file is called an
2411 .Em object file .
2412 The output file is often called an
2413 .Em executable ,
2414 but for our purposes we will also call it an object file. Each object file
2415 has, among other things, a list of
2416 .Em sections .
2417 We sometimes refer to a section in an input file as an
2418 .Em input section ;
2419 similarly, a section in the output file is an
2420 .Em output section .
2421 .Pp
2422 Each section in an object file has a name and a size. Most sections also have
2423 an associated block of data, known as the
2424 .Em section contents .
2425 A section may be marked as
2426 .Em loadable ,
2427 which mean that the contents should be loaded into memory when the output
2428 file is run. A section with no contents may be
2429 .Em allocatable ,
2430 which means that an area in memory should be set aside, but nothing in particular
2431 should be loaded there (in some cases this memory must be zeroed out). A section
2432 which is neither loadable nor allocatable typically contains some sort of
2433 debugging information.
2434 .Pp
2435 Every loadable or allocatable output section has two addresses. The first
2436 is the
2437 .Em VMA ,
2438 or virtual memory address. This is the address the section will have when
2439 the output file is run. The second is the
2440 .Em LMA ,
2441 or load memory address. This is the address at which the section will be loaded.
2442 In most cases the two addresses will be the same. An example of when they
2443 might be different is when a data section is loaded into ROM, and then copied
2444 into RAM when the program starts up (this technique is often used to initialize
2445 global variables in a ROM based system). In this case the ROM address would
2446 be the LMA, and the RAM address would be the VMA.
2447 .Pp
2448 You can see the sections in an object file by using the
2449 .Li objdump
2450 program with the
2451 .Li -h
2452 option.
2453 .Pp
2454 Every object file also has a list of
2455 .Em symbols ,
2456 known as the
2457 .Em symbol table .
2458 A symbol may be defined or undefined. Each symbol has a name, and each defined
2459 symbol has an address, among other information. If you compile a C or C++
2460 program into an object file, you will get a defined symbol for every defined
2461 function and global or static variable. Every undefined function or global
2462 variable which is referenced in the input file will become an undefined symbol.
2463 .Pp
2464 You can see the symbols in an object file by using the
2465 .Li nm
2466 program, or by using the
2467 .Li objdump
2468 program with the
2469 .Li -t
2470 option.
2471 .Pp
2472 .Ss  Linker Script Format
2473 Linker scripts are text files.
2474 .Pp
2475 You write a linker script as a series of commands. Each command is either
2476 a keyword, possibly followed by arguments, or an assignment to a symbol. You
2477 may separate commands using semicolons. Whitespace is generally ignored.
2478 .Pp
2479 Strings such as file or format names can normally be entered directly. If
2480 the file name contains a character such as a comma which would otherwise serve
2481 to separate file names, you may put the file name in double quotes. There
2482 is no way to use a double quote character in a file name.
2483 .Pp
2484 You may include comments in linker scripts just as in C, delimited by
2485 .Li /*
2486 and
2487 .Li */ .
2488 As in C, comments are syntactically equivalent to whitespace.
2489 .Pp
2490 .Ss  Simple Linker Script Example
2491 Many linker scripts are fairly simple.
2492 .Pp
2493 The simplest possible linker script has just one command:
2494 .Li SECTIONS .
2495 You use the
2496 .Li SECTIONS
2497 command to describe the memory layout of the output file.
2498 .Pp
2499 The
2500 .Li SECTIONS
2501 command is a powerful command. Here we will describe a simple use of it. Let's
2502 assume your program consists only of code, initialized data, and uninitialized
2503 data. These will be in the
2504 .Li .text ,
2505 .Li .data ,
2506 and
2507 .Li .bss
2508 sections, respectively. Let's assume further that these are the only sections
2509 which appear in your input files.
2510 .Pp
2511 For this example, let's say that the code should be loaded at address 0x10000,
2512 and that the data should start at address 0x8000000. Here is a linker script
2513 which will do that:
2514 .Bd -literal -offset indent
2515 SECTIONS
2516 {
2517   . = 0x10000;
2518   .text : { *(.text) }
2519   . = 0x8000000;
2520   .data : { *(.data) }
2521   .bss : { *(.bss) }
2522 }
2523 .Ed
2524 .Pp
2525 You write the
2526 .Li SECTIONS
2527 command as the keyword
2528 .Li SECTIONS ,
2529 followed by a series of symbol assignments and output section descriptions
2530 enclosed in curly braces.
2531 .Pp
2532 The first line inside the
2533 .Li SECTIONS
2534 command of the above example sets the value of the special symbol
2535 .Li . ,
2536 which is the location counter. If you do not specify the address of an output
2537 section in some other way (other ways are described later), the address is
2538 set from the current value of the location counter. The location counter is
2539 then incremented by the size of the output section. At the start of the
2540 .Li SECTIONS
2541 command, the location counter has the value
2542 .Li 0 .
2543 .Pp
2544 The second line defines an output section,
2545 .Li .text .
2546 The colon is required syntax which may be ignored for now. Within the curly
2547 braces after the output section name, you list the names of the input sections
2548 which should be placed into this output section. The
2549 .Li *
2550 is a wildcard which matches any file name. The expression
2551 .Li *(.text)
2552 means all
2553 .Li .text
2554 input sections in all input files.
2555 .Pp
2556 Since the location counter is
2557 .Li 0x10000
2558 when the output section
2559 .Li .text
2560 is defined, the linker will set the address of the
2561 .Li .text
2562 section in the output file to be
2563 .Li 0x10000 .
2564 .Pp
2565 The remaining lines define the
2566 .Li .data
2567 and
2568 .Li .bss
2569 sections in the output file. The linker will place the
2570 .Li .data
2571 output section at address
2572 .Li 0x8000000 .
2573 After the linker places the
2574 .Li .data
2575 output section, the value of the location counter will be
2576 .Li 0x8000000
2577 plus the size of the
2578 .Li .data
2579 output section. The effect is that the linker will place the
2580 .Li .bss
2581 output section immediately after the
2582 .Li .data
2583 output section in memory.
2584 .Pp
2585 The linker will ensure that each output section has the required alignment,
2586 by increasing the location counter if necessary. In this example, the specified
2587 addresses for the
2588 .Li .text
2589 and
2590 .Li .data
2591 sections will probably satisfy any alignment constraints, but the linker may
2592 have to create a small gap between the
2593 .Li .data
2594 and
2595 .Li .bss
2596 sections.
2597 .Pp
2598 That's it! That's a simple and complete linker script.
2599 .Pp
2600 .Ss  Simple Linker Script Commands
2601 In this section we describe the simple linker script commands.
2602 .Pp
2603 .Em  Setting the Entry Point
2604 .Pp
2605 The first instruction to execute in a program is called the
2606 .Em entry point .
2607 You can use the
2608 .Li ENTRY
2609 linker script command to set the entry point. The argument is a symbol name:
2610 .Bd -literal -offset indent
2611 ENTRY(symbol)
2612 .Ed
2613 .Pp
2614 There are several ways to set the entry point. The linker will set the entry
2615 point by trying each of the following methods in order, and stopping when
2616 one of them succeeds:
2617 .Bl -bullet
2618 .It
2619 the
2620 .Li -e
2621 .Va entry
2622 command-line option;
2623 .It
2624 the
2625 .Li ENTRY( Va symbol)
2626 command in a linker script;
2627 .It
2628 the value of the symbol
2629 .Li start ,
2630 if defined;
2631 .It
2632 the address of the first byte of the
2633 .Li .text
2634 section, if present;
2635 .It
2636 The address
2637 .Li 0 .
2638 .El
2639 .Pp
2640 .Em  Commands Dealing with Files
2641 .Pp
2642 Several linker script commands deal with files.
2643 .Pp
2644 .Bl -tag -width Ds
2645 .It  INCLUDE Va filename
2646 Include the linker script
2647 .Va filename
2648 at this point. The file will be searched for in the current directory, and
2649 in any directory specified with the
2650 .Op -L
2651 option. You can nest calls to
2652 .Li INCLUDE
2653 up to 10 levels deep.
2654 .Pp
2655 .It  INPUT( Va file, Va file, ...)
2656 .It  INPUT( Va file Va file ...)
2657 The
2658 .Li INPUT
2659 command directs the linker to include the named files in the link, as though
2660 they were named on the command line.
2661 .Pp
2662 For example, if you always want to include
2663 .Pa subr.o
2664 any time you do a link, but you can't be bothered to put it on every link
2665 command line, then you can put
2666 .Li INPUT (subr.o)
2667 in your linker script.
2668 .Pp
2669 In fact, if you like, you can list all of your input files in the linker script,
2670 and then invoke the linker with nothing but a
2671 .Li -T
2672 option.
2673 .Pp
2674 In case a
2675 .Em sysroot prefix
2676 is configured, and the filename starts with the
2677 .Li /
2678 character, and the script being processed was located inside the
2679 .Em sysroot prefix ,
2680 the filename will be looked for in the
2681 .Em sysroot prefix .
2682 Otherwise, the linker will try to open the file in the current directory.
2683 If it is not found, the linker will search through the archive library search
2684 path. See the description of
2685 .Li -L
2686 in Options,,Command Line Options.
2687 .Pp
2688 If you use
2689 .Li INPUT (-l Va file) ,
2690 .Xr ld
2691 will transform the name to
2692 .Li lib Va file.a ,
2693 as with the command line argument
2694 .Li -l .
2695 .Pp
2696 When you use the
2697 .Li INPUT
2698 command in an implicit linker script, the files will be included in the link
2699 at the point at which the linker script file is included. This can affect
2700 archive searching.
2701 .Pp
2702 .It  GROUP( Va file, Va file, ...)
2703 .It  GROUP( Va file Va file ...)
2704 The
2705 .Li GROUP
2706 command is like
2707 .Li INPUT ,
2708 except that the named files should all be archives, and they are searched
2709 repeatedly until no new undefined references are created. See the description
2710 of
2711 .Li -(
2712 in Options,,Command Line Options.
2713 .Pp
2714 .It  AS_NEEDED( Va file, Va file, ...)
2715 .It  AS_NEEDED( Va file Va file ...)
2716 This construct can appear only inside of the
2717 .Li INPUT
2718 or
2719 .Li GROUP
2720 commands, among other filenames. The files listed will be handled as if they
2721 appear directly in the
2722 .Li INPUT
2723 or
2724 .Li GROUP
2725 commands, with the exception of ELF shared libraries, that will be added only
2726 when they are actually needed. This construct essentially enables
2727 .Op --as-needed
2728 option for all the files listed inside of it and restores previous
2729 .Op --as-needed
2730 resp.
2731 .Op --no-as-needed
2732 setting afterwards.
2733 .Pp
2734 .It  OUTPUT( Va filename)
2735 The
2736 .Li OUTPUT
2737 command names the output file. Using
2738 .Li OUTPUT( Va filename)
2739 in the linker script is exactly like using
2740 .Li -o Va filename
2741 on the command line (see Section
2742 .Dq Options ) .
2743 If both are used, the command line option takes precedence.
2744 .Pp
2745 You can use the
2746 .Li OUTPUT
2747 command to define a default name for the output file other than the usual
2748 default of
2749 .Pa a.out .
2750 .Pp
2751 .It  SEARCH_DIR( Va path)
2752 The
2753 .Li SEARCH_DIR
2754 command adds
2755 .Va path
2756 to the list of paths where
2757 .Xr ld
2758 looks for archive libraries. Using
2759 .Li SEARCH_DIR( Va path)
2760 is exactly like using
2761 .Li -L Va path
2762 on the command line (see Section
2763 .Dq Options ) .
2764 If both are used, then the linker will search both paths. Paths specified
2765 using the command line option are searched first.
2766 .Pp
2767 .It  STARTUP( Va filename)
2768 The
2769 .Li STARTUP
2770 command is just like the
2771 .Li INPUT
2772 command, except that
2773 .Va filename
2774 will become the first input file to be linked, as though it were specified
2775 first on the command line. This may be useful when using a system in which
2776 the entry point is always the start of the first file.
2777 .El
2778 .Pp
2779 .Em  Commands Dealing with Object File Formats
2780 .Pp
2781 A couple of linker script commands deal with object file formats.
2782 .Pp
2783 .Bl -tag -width Ds
2784 .It  OUTPUT_FORMAT( Va bfdname)
2785 .It  OUTPUT_FORMAT( Va default, Va big, Va little)
2786 The
2787 .Li OUTPUT_FORMAT
2788 command names the BFD format to use for the output file (see Section
2789 .Dq BFD ) .
2790 Using
2791 .Li OUTPUT_FORMAT( Va bfdname)
2792 is exactly like using
2793 .Li --oformat Va bfdname
2794 on the command line (see Section
2795 .Dq Options ) .
2796 If both are used, the command line option takes precedence.
2797 .Pp
2798 You can use
2799 .Li OUTPUT_FORMAT
2800 with three arguments to use different formats based on the
2801 .Li -EB
2802 and
2803 .Li -EL
2804 command line options. This permits the linker script to set the output format
2805 based on the desired endianness.
2806 .Pp
2807 If neither
2808 .Li -EB
2809 nor
2810 .Li -EL
2811 are used, then the output format will be the first argument,
2812 .Va default .
2813 If
2814 .Li -EB
2815 is used, the output format will be the second argument,
2816 .Va big .
2817 If
2818 .Li -EL
2819 is used, the output format will be the third argument,
2820 .Va little .
2821 .Pp
2822 For example, the default linker script for the MIPS ELF target uses this command:
2823 .Bd -literal -offset indent
2824 OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
2825 .Ed
2826 This says that the default format for the output file is
2827 .Li elf32-bigmips ,
2828 but if the user uses the
2829 .Li -EL
2830 command line option, the output file will be created in the
2831 .Li elf32-littlemips
2832 format.
2833 .Pp
2834 .It  TARGET( Va bfdname)
2835 The
2836 .Li TARGET
2837 command names the BFD format to use when reading input files. It affects subsequent
2838 .Li INPUT
2839 and
2840 .Li GROUP
2841 commands. This command is like using
2842 .Li -b Va bfdname
2843 on the command line (see Section
2844 .Dq Options ) .
2845 If the
2846 .Li TARGET
2847 command is used but
2848 .Li OUTPUT_FORMAT
2849 is not, then the last
2850 .Li TARGET
2851 command is also used to set the format for the output file.See Section
2852 .Dq BFD .
2853 .El
2854 .Pp
2855 .Em  Other Linker Script Commands
2856 .Pp
2857 There are a few other linker scripts commands.
2858 .Pp
2859 .Bl -tag -width Ds
2860 .It  ASSERT( Va exp, Va message)
2861 Ensure that
2862 .Va exp
2863 is non-zero. If it is zero, then exit the linker with an error code, and print
2864 .Va message .
2865 .Pp
2866 .It  EXTERN( Va symbol Va symbol ...)
2867 Force
2868 .Va symbol
2869 to be entered in the output file as an undefined symbol. Doing this may, for
2870 example, trigger linking of additional modules from standard libraries. You
2871 may list several
2872 .Va symbol
2873 s for each
2874 .Li EXTERN ,
2875 and you may use
2876 .Li EXTERN
2877 multiple times. This command has the same effect as the
2878 .Li -u
2879 command-line option.
2880 .Pp
2881 .It  FORCE_COMMON_ALLOCATION
2882 This command has the same effect as the
2883 .Li -d
2884 command-line option: to make
2885 .Xr ld
2886 assign space to common symbols even if a relocatable output file is specified
2887 (
2888 .Li -r ) .
2889 .Pp
2890 .It  INHIBIT_COMMON_ALLOCATION
2891 This command has the same effect as the
2892 .Li --no-define-common
2893 command-line option: to make
2894 .Li ld
2895 omit the assignment of addresses to common symbols even for a non-relocatable
2896 output file.
2897 .Pp
2898 .It  NOCROSSREFS( Va section Va section ...)
2899 This command may be used to tell
2900 .Xr ld
2901 to issue an error about any references among certain output sections.
2902 .Pp
2903 In certain types of programs, particularly on embedded systems when using
2904 overlays, when one section is loaded into memory, another section will not
2905 be. Any direct references between the two sections would be errors. For example,
2906 it would be an error if code in one section called a function defined in the
2907 other section.
2908 .Pp
2909 The
2910 .Li NOCROSSREFS
2911 command takes a list of output section names. If
2912 .Xr ld
2913 detects any cross references between the sections, it reports an error and
2914 returns a non-zero exit status. Note that the
2915 .Li NOCROSSREFS
2916 command uses output section names, not input section names.
2917 .Pp
2918 .It  OUTPUT_ARCH( Va bfdarch)
2919 Specify a particular output machine architecture. The argument is one of the
2920 names used by the BFD library (see Section
2921 .Dq BFD ) .
2922 You can see the architecture of an object file by using the
2923 .Li objdump
2924 program with the
2925 .Li -f
2926 option.
2927 .El
2928 .Pp
2929 .Ss  Assigning Values to Symbols
2930 You may assign a value to a symbol in a linker script. This will define the
2931 symbol and place it into the symbol table with a global scope.
2932 .Pp
2933 .Em  Simple Assignments
2934 .Pp
2935 You may assign to a symbol using any of the C assignment operators:
2936 .Pp
2937 .Bl -tag -width Ds
2938 .It  Va symbol = Va expression ;
2939 .It  Va symbol += Va expression ;
2940 .It  Va symbol -= Va expression ;
2941 .It  Va symbol *= Va expression ;
2942 .It  Va symbol /= Va expression ;
2943 .It  Va symbol <<= Va expression ;
2944 .It  Va symbol >>= Va expression ;
2945 .It  Va symbol &= Va expression ;
2946 .It  Va symbol |= Va expression ;
2947 .El
2948 .Pp
2949 The first case will define
2950 .Va symbol
2951 to the value of
2952 .Va expression .
2953 In the other cases,
2954 .Va symbol
2955 must already be defined, and the value will be adjusted accordingly.
2956 .Pp
2957 The special symbol name
2958 .Li .
2959 indicates the location counter. You may only use this within a
2960 .Li SECTIONS
2961 command.See Section
2962 .Dq Location Counter .
2963 .Pp
2964 The semicolon after
2965 .Va expression
2966 is required.
2967 .Pp
2968 Expressions are defined below; see Expressions.
2969 .Pp
2970 You may write symbol assignments as commands in their own right, or as statements
2971 within a
2972 .Li SECTIONS
2973 command, or as part of an output section description in a
2974 .Li SECTIONS
2975 command.
2976 .Pp
2977 The section of the symbol will be set from the section of the expression;
2978 for more information, see Expression Section.
2979 .Pp
2980 Here is an example showing the three different places that symbol assignments
2981 may be used:
2982 .Pp
2983 .Bd -literal -offset indent
2984 floating_point = 0;
2985 SECTIONS
2986 {
2987   .text :
2988     {
2989       *(.text)
2990       _etext = .;
2991     }
2992   _bdata = (. + 3) & ~ 3;
2993   .data : { *(.data) }
2994 }
2995 .Ed
2996 In this example, the symbol
2997 .Li floating_point
2998 will be defined as zero. The symbol
2999 .Li _etext
3000 will be defined as the address following the last
3001 .Li .text
3002 input section. The symbol
3003 .Li _bdata
3004 will be defined as the address following the
3005 .Li .text
3006 output section aligned upward to a 4 byte boundary.
3007 .Pp
3008 .Em  PROVIDE
3009 .Pp
3010 In some cases, it is desirable for a linker script to define a symbol only
3011 if it is referenced and is not defined by any object included in the link.
3012 For example, traditional linkers defined the symbol
3013 .Li etext .
3014 However, ANSI C requires that the user be able to use
3015 .Li etext
3016 as a function name without encountering an error. The
3017 .Li PROVIDE
3018 keyword may be used to define a symbol, such as
3019 .Li etext ,
3020 only if it is referenced but not defined. The syntax is
3021 .Li PROVIDE( Va symbol = Va expression) .
3022 .Pp
3023 Here is an example of using
3024 .Li PROVIDE
3025 to define
3026 .Li etext :
3027 .Bd -literal -offset indent
3028 SECTIONS
3029 {
3030   .text :
3031     {
3032       *(.text)
3033       _etext = .;
3034       PROVIDE(etext = .);
3035     }
3036 }
3037 .Ed
3038 .Pp
3039 In this example, if the program defines
3040 .Li _etext
3041 (with a leading underscore), the linker will give a multiple definition error.
3042 If, on the other hand, the program defines
3043 .Li etext
3044 (with no leading underscore), the linker will silently use the definition
3045 in the program. If the program references
3046 .Li etext
3047 but does not define it, the linker will use the definition in the linker script.
3048 .Pp
3049 .Em  PROVIDE_HIDDEN
3050 .Pp
3051 Similar to
3052 .Li PROVIDE .
3053 For ELF targeted ports, the symbol will be hidden and won't be exported.
3054 .Pp
3055 .Em  Source Code Reference
3056 .Pp
3057 Accessing a linker script defined variable from source code is not intuitive.
3058 In particular a linker script symbol is not equivalent to a variable declaration
3059 in a high level language, it is instead a symbol that does not have a value.
3060 .Pp
3061 Before going further, it is important to note that compilers often transform
3062 names in the source code into different names when they are stored in the
3063 symbol table. For example, Fortran compilers commonly prepend or append an
3064 underscore, and C++ performs extensive
3065 .Li name mangling .
3066 Therefore there might be a discrepancy between the name of a variable as it
3067 is used in source code and the name of the same variable as it is defined
3068 in a linker script. For example in C a linker script variable might be referred
3069 to as:
3070 .Pp
3071 .Bd -literal -offset indent
3072   extern int foo;
3073 .Ed
3074 .Pp
3075 But in the linker script it might be defined as:
3076 .Pp
3077 .Bd -literal -offset indent
3078   _foo = 1000;
3079 .Ed
3080 .Pp
3081 In the remaining examples however it is assumed that no name transformation
3082 has taken place.
3083 .Pp
3084 When a symbol is declared in a high level language such as C, two things happen.
3085 The first is that the compiler reserves enough space in the program's memory
3086 to hold the
3087 .Em value
3088 of the symbol. The second is that the compiler creates an entry in the program's
3089 symbol table which holds the symbol's
3090 .Em address .
3091 ie the symbol table contains the address of the block of memory holding the
3092 symbol's value. So for example the following C declaration, at file scope:
3093 .Pp
3094 .Bd -literal -offset indent
3095   int foo = 1000;
3096 .Ed
3097 .Pp
3098 creates a entry called
3099 .Li foo
3100 in the symbol table. This entry holds the address of an
3101 .Li int
3102 sized block of memory where the number 1000 is initially stored.
3103 .Pp
3104 When a program references a symbol the compiler generates code that first
3105 accesses the symbol table to find the address of the symbol's memory block
3106 and then code to read the value from that memory block. So:
3107 .Pp
3108 .Bd -literal -offset indent
3109   foo = 1;
3110 .Ed
3111 .Pp
3112 looks up the symbol
3113 .Li foo
3114 in the symbol table, gets the address associated with this symbol and then
3115 writes the value 1 into that address. Whereas:
3116 .Pp
3117 .Bd -literal -offset indent
3118   int * a = & foo;
3119 .Ed
3120 .Pp
3121 looks up the symbol
3122 .Li foo
3123 in the symbol table, gets it address and then copies this address into the
3124 block of memory associated with the variable
3125 .Li a .
3126 .Pp
3127 Linker scripts symbol declarations, by contrast, create an entry in the symbol
3128 table but do not assign any memory to them. Thus they are an address without
3129 a value. So for example the linker script definition:
3130 .Pp
3131 .Bd -literal -offset indent
3132   foo = 1000;
3133 .Ed
3134 .Pp
3135 creates an entry in the symbol table called
3136 .Li foo
3137 which holds the address of memory location 1000, but nothing special is stored
3138 at address 1000. This means that you cannot access the
3139 .Em value
3140 of a linker script defined symbol - it has no value - all you can do is access
3141 the
3142 .Em address
3143 of a linker script defined symbol.
3144 .Pp
3145 Hence when you are using a linker script defined symbol in source code you
3146 should always take the address of the symbol, and never attempt to use its
3147 value. For example suppose you want to copy the contents of a section of memory
3148 called .ROM into a section called .FLASH and the linker script contains these
3149 declarations:
3150 .Pp
3151 .Bd -literal -offset indent
3152
3153   start_of_ROM   = .ROM;
3154   end_of_ROM     = .ROM + sizeof (.ROM) - 1;
3155   start_of_FLASH = .FLASH;
3156
3157 .Ed
3158 .Pp
3159 Then the C source code to perform the copy would be:
3160 .Pp
3161 .Bd -literal -offset indent
3162
3163   extern char start_of_ROM, end_of_ROM, start_of_FLASH;
3164   
3165   memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
3166
3167 .Ed
3168 .Pp
3169 Note the use of the
3170 .Li &
3171 operators. These are correct.
3172 .Pp
3173 .Ss  SECTIONS Command
3174 The
3175 .Li SECTIONS
3176 command tells the linker how to map input sections into output sections, and
3177 how to place the output sections in memory.
3178 .Pp
3179 The format of the
3180 .Li SECTIONS
3181 command is:
3182 .Bd -literal -offset indent
3183 SECTIONS
3184 {
3185   sections-command
3186   sections-command
3187   ...
3188 }
3189 .Ed
3190 .Pp
3191 Each
3192 .Va sections-command
3193 may of be one of the following:
3194 .Pp
3195 .Bl -bullet
3196 .It
3197 an
3198 .Li ENTRY
3199 command (see Section
3200 .Dq Entry Point )
3201 .It
3202 a symbol assignment (see Section
3203 .Dq Assignments )
3204 .It
3205 an output section description
3206 .It
3207 an overlay description
3208 .El
3209 .Pp
3210 The
3211 .Li ENTRY
3212 command and symbol assignments are permitted inside the
3213 .Li SECTIONS
3214 command for convenience in using the location counter in those commands. This
3215 can also make the linker script easier to understand because you can use those
3216 commands at meaningful points in the layout of the output file.
3217 .Pp
3218 Output section descriptions and overlay descriptions are described below.
3219 .Pp
3220 If you do not use a
3221 .Li SECTIONS
3222 command in your linker script, the linker will place each input section into
3223 an identically named output section in the order that the sections are first
3224 encountered in the input files. If all input sections are present in the first
3225 file, for example, the order of sections in the output file will match the
3226 order in the first input file. The first section will be at address zero.
3227 .Pp
3228 .Em  Output Section Description
3229 .Pp
3230 The full description of an output section looks like this:
3231 .Bd -literal -offset indent
3232
3233 section [address] [(type)] :
3234   [AT(lma)] [ALIGN(section_align)] [SUBALIGN(subsection_align)]
3235   {
3236     output-section-command
3237     output-section-command
3238     ...
3239   } [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp]
3240
3241 .Ed
3242 .Pp
3243 Most output sections do not use most of the optional section attributes.
3244 .Pp
3245 The whitespace around
3246 .Va section
3247 is required, so that the section name is unambiguous. The colon and the curly
3248 braces are also required. The line breaks and other white space are optional.
3249 .Pp
3250 Each
3251 .Va output-section-command
3252 may be one of the following:
3253 .Pp
3254 .Bl -bullet
3255 .It
3256 a symbol assignment (see Section
3257 .Dq Assignments )
3258 .It
3259 an input section description (see Section
3260 .Dq Input Section )
3261 .It
3262 data values to include directly (see Section
3263 .Dq Output Section Data )
3264 .It
3265 a special output section keyword (see Section
3266 .Dq Output Section Keywords )
3267 .El
3268 .Pp
3269 .Em  Output Section Name
3270 .Pp
3271 The name of the output section is
3272 .Va section .
3273 .Va section
3274 must meet the constraints of your output format. In formats which only support
3275 a limited number of sections, such as
3276 .Li a.out ,
3277 the name must be one of the names supported by the format (
3278 .Li a.out ,
3279 for example, allows only
3280 .Li .text ,
3281 .Li .data
3282 or
3283 .Li .bss ) .
3284 If the output format supports any number of sections, but with numbers and
3285 not names (as is the case for Oasys), the name should be supplied as a quoted
3286 numeric string. A section name may consist of any sequence of characters,
3287 but a name which contains any unusual characters such as commas must be quoted.
3288 .Pp
3289 The output section name
3290 .Li /DISCARD/
3291 is special; Output Section Discarding.
3292 .Pp
3293 .Em  Output Section Address
3294 .Pp
3295 The
3296 .Va address
3297 is an expression for the VMA (the virtual memory address) of the output section.
3298 If you do not provide
3299 .Va address ,
3300 the linker will set it based on
3301 .Va region
3302 if present, or otherwise based on the current value of the location counter.
3303 .Pp
3304 If you provide
3305 .Va address ,
3306 the address of the output section will be set to precisely that. If you provide
3307 neither
3308 .Va address
3309 nor
3310 .Va region ,
3311 then the address of the output section will be set to the current value of
3312 the location counter aligned to the alignment requirements of the output section.
3313 The alignment requirement of the output section is the strictest alignment
3314 of any input section contained within the output section.
3315 .Pp
3316 For example,
3317 .Bd -literal -offset indent
3318 \&.text . : { *(.text) }
3319 .Ed
3320 and
3321 .Bd -literal -offset indent
3322 \&.text : { *(.text) }
3323 .Ed
3324 are subtly different. The first will set the address of the
3325 .Li .text
3326 output section to the current value of the location counter. The second will
3327 set it to the current value of the location counter aligned to the strictest
3328 alignment of a
3329 .Li .text
3330 input section.
3331 .Pp
3332 The
3333 .Va address
3334 may be an arbitrary expression; Expressions. For example, if you want to align
3335 the section on a 0x10 byte boundary, so that the lowest four bits of the section
3336 address are zero, you could do something like this:
3337 .Bd -literal -offset indent
3338 \&.text ALIGN(0x10) : { *(.text) }
3339 .Ed
3340 This works because
3341 .Li ALIGN
3342 returns the current location counter aligned upward to the specified value.
3343 .Pp
3344 Specifying
3345 .Va address
3346 for a section will change the value of the location counter.
3347 .Pp
3348 .Em  Input Section Description
3349 .Pp
3350 The most common output section command is an input section description.
3351 .Pp
3352 The input section description is the most basic linker script operation. You
3353 use output sections to tell the linker how to lay out your program in memory.
3354 You use input section descriptions to tell the linker how to map the input
3355 files into your memory layout.
3356 .Pp
3357 .No  Input Section Basics
3358 .Pp
3359 An input section description consists of a file name optionally followed by
3360 a list of section names in parentheses.
3361 .Pp
3362 The file name and the section name may be wildcard patterns, which we describe
3363 further below (see Section
3364 .Dq Input Section Wildcards ) .
3365 .Pp
3366 The most common input section description is to include all input sections
3367 with a particular name in the output section. For example, to include all
3368 input
3369 .Li .text
3370 sections, you would write:
3371 .Bd -literal -offset indent
3372 *(.text)
3373 .Ed
3374 Here the
3375 .Li *
3376 is a wildcard which matches any file name. To exclude a list of files from
3377 matching the file name wildcard, EXCLUDE_FILE may be used to match all files
3378 except the ones specified in the EXCLUDE_FILE list. For example:
3379 .Bd -literal -offset indent
3380 (*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors))
3381 .Ed
3382 will cause all .ctors sections from all files except
3383 .Pa crtend.o
3384 and
3385 .Pa otherfile.o
3386 to be included.
3387 .Pp
3388 There are two ways to include more than one section:
3389 .Bd -literal -offset indent
3390 *(.text .rdata)
3391 *(.text) *(.rdata)
3392 .Ed
3393 The difference between these is the order in which the
3394 .Li .text
3395 and
3396 .Li .rdata
3397 input sections will appear in the output section. In the first example, they
3398 will be intermingled, appearing in the same order as they are found in the
3399 linker input. In the second example, all
3400 .Li .text
3401 input sections will appear first, followed by all
3402 .Li .rdata
3403 input sections.
3404 .Pp
3405 You can specify a file name to include sections from a particular file. You
3406 would do this if one or more of your files contain special data that needs
3407 to be at a particular location in memory. For example:
3408 .Bd -literal -offset indent
3409 data.o(.data)
3410 .Ed
3411 .Pp
3412 If you use a file name without a list of sections, then all sections in the
3413 input file will be included in the output section. This is not commonly done,
3414 but it may by useful on occasion. For example:
3415 .Bd -literal -offset indent
3416 data.o
3417 .Ed
3418 .Pp
3419 When you use a file name which does not contain any wild card characters,
3420 the linker will first see if you also specified the file name on the linker
3421 command line or in an
3422 .Li INPUT
3423 command. If you did not, the linker will attempt to open the file as an input
3424 file, as though it appeared on the command line. Note that this differs from
3425 an
3426 .Li INPUT
3427 command, because the linker will not search for the file in the archive search
3428 path.
3429 .Pp
3430 .No  Input Section Wildcard Patterns
3431 .Pp
3432 In an input section description, either the file name or the section name
3433 or both may be wildcard patterns.
3434 .Pp
3435 The file name of
3436 .Li *
3437 seen in many examples is a simple wildcard pattern for the file name.
3438 .Pp
3439 The wildcard patterns are like those used by the Unix shell.
3440 .Pp
3441 .Bl -tag -width Ds
3442 .It  *
3443 matches any number of characters
3444 .It  ?
3445 matches any single character
3446 .It  [ Va chars]
3447 matches a single instance of any of the
3448 .Va chars ;
3449 the
3450 .Li -
3451 character may be used to specify a range of characters, as in
3452 .Li [a-z]
3453 to match any lower case letter
3454 .It  \e
3455 quotes the following character
3456 .El
3457 .Pp
3458 When a file name is matched with a wildcard, the wildcard characters will
3459 not match a
3460 .Li /
3461 character (used to separate directory names on Unix). A pattern consisting
3462 of a single
3463 .Li *
3464 character is an exception; it will always match any file name, whether it
3465 contains a
3466 .Li /
3467 or not. In a section name, the wildcard characters will match a
3468 .Li /
3469 character.
3470 .Pp
3471 File name wildcard patterns only match files which are explicitly specified
3472 on the command line or in an
3473 .Li INPUT
3474 command. The linker does not search directories to expand wildcards.
3475 .Pp
3476 If a file name matches more than one wildcard pattern, or if a file name appears
3477 explicitly and is also matched by a wildcard pattern, the linker will use
3478 the first match in the linker script. For example, this sequence of input
3479 section descriptions is probably in error, because the
3480 .Pa data.o
3481 rule will not be used:
3482 .Bd -literal -offset indent
3483 \&.data : { *(.data) }
3484 \&.data1 : { data.o(.data) }
3485 .Ed
3486 .Pp
3487 Normally, the linker will place files and sections matched by wildcards in
3488 the order in which they are seen during the link. You can change this by using
3489 the
3490 .Li SORT_BY_NAME
3491 keyword, which appears before a wildcard pattern in parentheses (e.g.,
3492 .Li SORT_BY_NAME(.text*) ) .
3493 When the
3494 .Li SORT_BY_NAME
3495 keyword is used, the linker will sort the files or sections into ascending
3496 order by name before placing them in the output file.
3497 .Pp
3498 .Li SORT_BY_ALIGNMENT
3499 is very similar to
3500 .Li SORT_BY_NAME .
3501 The difference is
3502 .Li SORT_BY_ALIGNMENT
3503 will sort sections into ascending order by alignment before placing them in
3504 the output file.
3505 .Pp
3506 .Li SORT
3507 is an alias for
3508 .Li SORT_BY_NAME .
3509 .Pp
3510 When there are nested section sorting commands in linker script, there can
3511 be at most 1 level of nesting for section sorting commands.
3512 .Pp
3513 .Bl -enum
3514 .It
3515 .Li SORT_BY_NAME
3516 (
3517 .Li SORT_BY_ALIGNMENT
3518 (wildcard section pattern)). It will sort the input sections by name first,
3519 then by alignment if 2 sections have the same name.
3520 .It
3521 .Li SORT_BY_ALIGNMENT
3522 (
3523 .Li SORT_BY_NAME
3524 (wildcard section pattern)). It will sort the input sections by alignment
3525 first, then by name if 2 sections have the same alignment.
3526 .It
3527 .Li SORT_BY_NAME
3528 (
3529 .Li SORT_BY_NAME
3530 (wildcard section pattern)) is treated the same as
3531 .Li SORT_BY_NAME
3532 (wildcard section pattern).
3533 .It
3534 .Li SORT_BY_ALIGNMENT
3535 (
3536 .Li SORT_BY_ALIGNMENT
3537 (wildcard section pattern)) is treated the same as
3538 .Li SORT_BY_ALIGNMENT
3539 (wildcard section pattern).
3540 .It
3541 All other nested section sorting commands are invalid.
3542 .El
3543 .Pp
3544 When both command line section sorting option and linker script section sorting
3545 command are used, section sorting command always takes precedence over the
3546 command line option.
3547 .Pp
3548 If the section sorting command in linker script isn't nested, the command
3549 line option will make the section sorting command to be treated as nested
3550 sorting command.
3551 .Pp
3552 .Bl -enum
3553 .It
3554 .Li SORT_BY_NAME
3555 (wildcard section pattern ) with
3556 .Op --sort-sections alignment
3557 is equivalent to
3558 .Li SORT_BY_NAME
3559 (
3560 .Li SORT_BY_ALIGNMENT
3561 (wildcard section pattern)).
3562 .It
3563 .Li SORT_BY_ALIGNMENT
3564 (wildcard section pattern) with
3565 .Op --sort-section name
3566 is equivalent to
3567 .Li SORT_BY_ALIGNMENT
3568 (
3569 .Li SORT_BY_NAME
3570 (wildcard section pattern)).
3571 .El
3572 .Pp
3573 If the section sorting command in linker script is nested, the command line
3574 option will be ignored.
3575 .Pp
3576 If you ever get confused about where input sections are going, use the
3577 .Li -M
3578 linker option to generate a map file. The map file shows precisely how input
3579 sections are mapped to output sections.
3580 .Pp
3581 This example shows how wildcard patterns might be used to partition files.
3582 This linker script directs the linker to place all
3583 .Li .text
3584 sections in
3585 .Li .text
3586 and all
3587 .Li .bss
3588 sections in
3589 .Li .bss .
3590 The linker will place the
3591 .Li .data
3592 section from all files beginning with an upper case character in
3593 .Li .DATA ;
3594 for all other files, the linker will place the
3595 .Li .data
3596 section in
3597 .Li .data .
3598 .Bd -literal -offset indent
3599
3600 SECTIONS {
3601   .text : { *(.text) }
3602   .DATA : { [A-Z]*(.data) }
3603   .data : { *(.data) }
3604   .bss : { *(.bss) }
3605 }
3606
3607 .Ed
3608 .Pp
3609 .No  Input Section for Common Symbols
3610 .Pp
3611 A special notation is needed for common symbols, because in many object file
3612 formats common symbols do not have a particular input section. The linker
3613 treats common symbols as though they are in an input section named
3614 .Li COMMON .
3615 .Pp
3616 You may use file names with the
3617 .Li COMMON
3618 section just as with any other input sections. You can use this to place common
3619 symbols from a particular input file in one section while common symbols from
3620 other input files are placed in another section.
3621 .Pp
3622 In most cases, common symbols in input files will be placed in the
3623 .Li .bss
3624 section in the output file. For example:
3625 .Bd -literal -offset indent
3626 \&.bss { *(.bss) *(COMMON) }
3627 .Ed
3628 .Pp
3629 Some object file formats have more than one type of common symbol. For example,
3630 the MIPS ELF object file format distinguishes standard common symbols and
3631 small common symbols. In this case, the linker will use a different special
3632 section name for other types of common symbols. In the case of MIPS ELF, the
3633 linker uses
3634 .Li COMMON
3635 for standard common symbols and
3636 .Li .scommon
3637 for small common symbols. This permits you to map the different types of common
3638 symbols into memory at different locations.
3639 .Pp
3640 You will sometimes see
3641 .Li [COMMON]
3642 in old linker scripts. This notation is now considered obsolete. It is equivalent
3643 to
3644 .Li *(COMMON) .
3645 .Pp
3646 .No  Input Section and Garbage Collection
3647 .Pp
3648 When link-time garbage collection is in use (
3649 .Li --gc-sections ) ,
3650 it is often useful to mark sections that should not be eliminated. This is
3651 accomplished by surrounding an input section's wildcard entry with
3652 .Li KEEP() ,
3653 as in
3654 .Li KEEP(*(.init))
3655 or
3656 .Li KEEP(SORT_BY_NAME(*)(.ctors)) .
3657 .Pp
3658 .No  Input Section Example
3659 .Pp
3660 The following example is a complete linker script. It tells the linker to
3661 read all of the sections from file
3662 .Pa all.o
3663 and place them at the start of output section
3664 .Li outputa
3665 which starts at location
3666 .Li 0x10000 .
3667 All of section
3668 .Li .input1
3669 from file
3670 .Pa foo.o
3671 follows immediately, in the same output section. All of section
3672 .Li .input2
3673 from
3674 .Pa foo.o
3675 goes into output section
3676 .Li outputb ,
3677 followed by section
3678 .Li .input1
3679 from
3680 .Pa foo1.o .
3681 All of the remaining
3682 .Li .input1
3683 and
3684 .Li .input2
3685 sections from any files are written to output section
3686 .Li outputc .
3687 .Pp
3688 .Bd -literal -offset indent
3689
3690 SECTIONS {
3691   outputa 0x10000 :
3692     {
3693     all.o
3694     foo.o (.input1)
3695     }
3696
3697
3698   outputb :
3699     {
3700     foo.o (.input2)
3701     foo1.o (.input1)
3702     }
3703
3704
3705   outputc :
3706     {
3707     *(.input1)
3708     *(.input2)
3709     }
3710 }
3711
3712 .Ed
3713 .Pp
3714 .Em  Output Section Data
3715 .Pp
3716 You can include explicit bytes of data in an output section by using
3717 .Li BYTE ,
3718 .Li SHORT ,
3719 .Li LONG ,
3720 .Li QUAD ,
3721 or
3722 .Li SQUAD
3723 as an output section command. Each keyword is followed by an expression in
3724 parentheses providing the value to store (see Section
3725 .Dq Expressions ) .
3726 The value of the expression is stored at the current value of the location
3727 counter.
3728 .Pp
3729 The
3730 .Li BYTE ,
3731 .Li SHORT ,
3732 .Li LONG ,
3733 and
3734 .Li QUAD
3735 commands store one, two, four, and eight bytes (respectively). After storing
3736 the bytes, the location counter is incremented by the number of bytes stored.
3737 .Pp
3738 For example, this will store the byte 1 followed by the four byte value of
3739 the symbol
3740 .Li addr :
3741 .Bd -literal -offset indent
3742 BYTE(1)
3743 LONG(addr)
3744 .Ed
3745 .Pp
3746 When using a 64 bit host or target,
3747 .Li QUAD
3748 and
3749 .Li SQUAD
3750 are the same; they both store an 8 byte, or 64 bit, value. When both host
3751 and target are 32 bits, an expression is computed as 32 bits. In this case
3752 .Li QUAD
3753 stores a 32 bit value zero extended to 64 bits, and
3754 .Li SQUAD
3755 stores a 32 bit value sign extended to 64 bits.
3756 .Pp
3757 If the object file format of the output file has an explicit endianness, which
3758 is the normal case, the value will be stored in that endianness. When the
3759 object file format does not have an explicit endianness, as is true of, for
3760 example, S-records, the value will be stored in the endianness of the first
3761 input object file.
3762 .Pp
3763 Note---these commands only work inside a section description and not between
3764 them, so the following will produce an error from the linker:
3765 .Bd -literal -offset indent
3766 SECTIONS { .text : { *(.text) } LONG(1) .data : { *(.data) } } 
3767 .Ed
3768 whereas this will work:
3769 .Bd -literal -offset indent
3770 SECTIONS { .text : { *(.text) ; LONG(1) } .data : { *(.data) } } 
3771 .Ed
3772 .Pp
3773 You may use the
3774 .Li FILL
3775 command to set the fill pattern for the current section. It is followed by
3776 an expression in parentheses. Any otherwise unspecified regions of memory
3777 within the section (for example, gaps left due to the required alignment of
3778 input sections) are filled with the value of the expression, repeated as necessary.
3779 A
3780 .Li FILL
3781 statement covers memory locations after the point at which it occurs in the
3782 section definition; by including more than one
3783 .Li FILL
3784 statement, you can have different fill patterns in different parts of an output
3785 section.
3786 .Pp
3787 This example shows how to fill unspecified regions of memory with the value
3788 .Li 0x90 :
3789 .Bd -literal -offset indent
3790 FILL(0x90909090)
3791 .Ed
3792 .Pp
3793 The
3794 .Li FILL
3795 command is similar to the
3796 .Li = Va fillexp
3797 output section attribute, but it only affects the part of the section following
3798 the
3799 .Li FILL
3800 command, rather than the entire section. If both are used, the
3801 .Li FILL
3802 command takes precedence.See Section
3803 .Dq Output Section Fill ,
3804 for details on the fill expression.
3805 .Pp
3806 .Em  Output Section Keywords
3807 .Pp
3808 There are a couple of keywords which can appear as output section commands.
3809 .Pp
3810 .Bl -tag -width Ds
3811 .It  CREATE_OBJECT_SYMBOLS
3812 The command tells the linker to create a symbol for each input file. The name
3813 of each symbol will be the name of the corresponding input file. The section
3814 of each symbol will be the output section in which the
3815 .Li CREATE_OBJECT_SYMBOLS
3816 command appears.
3817 .Pp
3818 This is conventional for the a.out object file format. It is not normally
3819 used for any other object file format.
3820 .Pp
3821 .It  CONSTRUCTORS
3822 When linking using the a.out object file format, the linker uses an unusual
3823 set construct to support C++ global constructors and destructors. When linking
3824 object file formats which do not support arbitrary sections, such as ECOFF
3825 and XCOFF, the linker will automatically recognize C++ global constructors
3826 and destructors by name. For these object file formats, the
3827 .Li CONSTRUCTORS
3828 command tells the linker to place constructor information in the output section
3829 where the
3830 .Li CONSTRUCTORS
3831 command appears. The
3832 .Li CONSTRUCTORS
3833 command is ignored for other object file formats.
3834 .Pp
3835 The symbol
3836 .Li __CTOR_LIST__
3837 marks the start of the global constructors, and the symbol
3838 .Li __CTOR_END__
3839 marks the end. Similarly,
3840 .Li __DTOR_LIST__
3841 and
3842 .Li __DTOR_END__
3843 mark the start and end of the global destructors. The first word in the list
3844 is the number of entries, followed by the address of each constructor or destructor,
3845 followed by a zero word. The compiler must arrange to actually run the code.
3846 For these object file formats GNU C++ normally calls constructors from a subroutine
3847 .Li __main ;
3848 a call to
3849 .Li __main
3850 is automatically inserted into the startup code for
3851 .Li main .
3852 GNU C++ normally runs destructors either by using
3853 .Li atexit ,
3854 or directly from the function
3855 .Li exit .
3856 .Pp
3857 For object file formats such as
3858 .Li COFF
3859 or
3860 .Li ELF
3861 which support arbitrary section names, GNU C++ will normally arrange to put
3862 the addresses of global constructors and destructors into the
3863 .Li .ctors
3864 and
3865 .Li .dtors
3866 sections. Placing the following sequence into your linker script will build
3867 the sort of table which the GNU C++ runtime code expects to see.
3868 .Pp
3869 .Bd -literal -offset indent
3870       __CTOR_LIST__ = .;
3871       LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
3872       *(.ctors)
3873       LONG(0)
3874       __CTOR_END__ = .;
3875       __DTOR_LIST__ = .;
3876       LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
3877       *(.dtors)
3878       LONG(0)
3879       __DTOR_END__ = .;
3880 .Ed
3881 .Pp
3882 If you are using the GNU C++ support for initialization priority, which provides
3883 some control over the order in which global constructors are run, you must
3884 sort the constructors at link time to ensure that they are executed in the
3885 correct order. When using the
3886 .Li CONSTRUCTORS
3887 command, use
3888 .Li SORT_BY_NAME(CONSTRUCTORS)
3889 instead. When using the
3890 .Li .ctors
3891 and
3892 .Li .dtors
3893 sections, use
3894 .Li *(SORT_BY_NAME(.ctors))
3895 and
3896 .Li *(SORT_BY_NAME(.dtors))
3897 instead of just
3898 .Li *(.ctors)
3899 and
3900 .Li *(.dtors) .
3901 .Pp
3902 Normally the compiler and linker will handle these issues automatically, and
3903 you will not need to concern yourself with them. However, you may need to
3904 consider this if you are using C++ and writing your own linker scripts.
3905 .Pp
3906 .El
3907 .Em  Output Section Discarding
3908 .Pp
3909 The linker will not create output sections with no contents. This is for convenience
3910 when referring to input sections that may or may not be present in any of
3911 the input files. For example:
3912 .Bd -literal -offset indent
3913 \&.foo : { *(.foo) }
3914 .Ed
3915 will only create a
3916 .Li .foo
3917 section in the output file if there is a
3918 .Li .foo
3919 section in at least one input file, and if the input sections are not all
3920 empty. Other link script directives that allocate space in an output section
3921 will also create the output section.
3922 .Pp
3923 The linker will ignore address assignments (see Section
3924 .Dq Output Section Address )
3925 on discarded output sections, except when the linker script defines symbols
3926 in the output section. In that case the linker will obey the address assignments,
3927 possibly advancing dot even though the section is discarded.
3928 .Pp
3929 The special output section name
3930 .Li /DISCARD/
3931 may be used to discard input sections. Any input sections which are assigned
3932 to an output section named
3933 .Li /DISCARD/
3934 are not included in the output file.
3935 .Pp
3936 .Em  Output Section Attributes
3937 .Pp
3938 We showed above that the full description of an output section looked like
3939 this:
3940 .Bd -literal -offset indent
3941
3942 section [address] [(type)] :
3943   [AT(lma)] [ALIGN(section_align)] [SUBALIGN(subsection_align)]
3944   {
3945     output-section-command
3946     output-section-command
3947     ...
3948   } [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp]
3949
3950 .Ed
3951 We've already described
3952 .Va section ,
3953 .Va address ,
3954 and
3955 .Va output-section-command .
3956 In this section we will describe the remaining section attributes.
3957 .Pp
3958 .No  Output Section Type
3959 .Pp
3960 Each output section may have a type. The type is a keyword in parentheses.
3961 The following types are defined:
3962 .Pp
3963 .Bl -tag -width Ds
3964 .It  NOLOAD
3965 The section should be marked as not loadable, so that it will not be loaded
3966 into memory when the program is run.
3967 .It  DSECT
3968 .It  COPY
3969 .It  INFO
3970 .It  OVERLAY
3971 These type names are supported for backward compatibility, and are rarely
3972 used. They all have the same effect: the section should be marked as not allocatable,
3973 so that no memory is allocated for the section when the program is run.
3974 .El
3975 .Pp
3976 The linker normally sets the attributes of an output section based on the
3977 input sections which map into it. You can override this by using the section
3978 type. For example, in the script sample below, the
3979 .Li ROM
3980 section is addressed at memory location
3981 .Li 0
3982 and does not need to be loaded when the program is run. The contents of the
3983 .Li ROM
3984 section will appear in the linker output file as usual.
3985 .Bd -literal -offset indent
3986
3987 SECTIONS {
3988   ROM 0 (NOLOAD) : { ... }
3989   ...
3990 }
3991
3992 .Ed
3993 .Pp
3994 .No  Output Section LMA
3995 .Pp
3996 Every section has a virtual address (VMA) and a load address (LMA); see Basic
3997 Script Concepts. The address expression which may appear in an output section
3998 description sets the VMA (see Section
3999 .Dq Output Section Address ) .
4000 .Pp
4001 The expression
4002 .Va lma
4003 that follows the
4004 .Li AT
4005 keyword specifies the load address of the section.
4006 .Pp
4007 Alternatively, with
4008 .Li AT> Va lma_region
4009 expression, you may specify a memory region for the section's load address.See Section
4010 .Dq MEMORY .
4011 Note that if the section has not had a VMA assigned to it then the linker
4012 will use the
4013 .Va lma_region
4014 as the VMA region as well.
4015 .Pp
4016 If neither
4017 .Li AT
4018 nor
4019 .Li AT>
4020 is specified for an allocatable section, the linker will set the LMA such
4021 that the difference between VMA and LMA for the section is the same as the
4022 preceding output section in the same region. If there is no preceding output
4023 section or the section is not allocatable, the linker will set the LMA equal
4024 to the VMA.See Section
4025 .Dq Output Section Region .
4026 .Pp
4027 This feature is designed to make it easy to build a ROM image. For example,
4028 the following linker script creates three output sections: one called
4029 .Li .text ,
4030 which starts at
4031 .Li 0x1000 ,
4032 one called
4033 .Li .mdata ,
4034 which is loaded at the end of the
4035 .Li .text
4036 section even though its VMA is
4037 .Li 0x2000 ,
4038 and one called
4039 .Li .bss
4040 to hold uninitialized data at address
4041 .Li 0x3000 .
4042 The symbol
4043 .Li _data
4044 is defined with the value
4045 .Li 0x2000 ,
4046 which shows that the location counter holds the VMA value, not the LMA value.
4047 .Pp
4048 .Bd -literal -offset indent
4049
4050 SECTIONS
4051   {
4052   .text 0x1000 : { *(.text) _etext = . ; }
4053   .mdata 0x2000 :
4054     AT ( ADDR (.text) + SIZEOF (.text) )
4055     { _data = . ; *(.data); _edata = . ;  }
4056   .bss 0x3000 :
4057     { _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;}
4058 }
4059
4060 .Ed
4061 .Pp
4062 The run-time initialization code for use with a program generated with this
4063 linker script would include something like the following, to copy the initialized
4064 data from the ROM image to its runtime address. Notice how this code takes
4065 advantage of the symbols defined by the linker script.
4066 .Pp
4067 .Bd -literal -offset indent
4068
4069 extern char _etext, _data, _edata, _bstart, _bend;
4070 char *src = &_etext;
4071 char *dst = &_data;
4072
4073 /* ROM has data at end of text; copy it. */
4074 while (dst < &_edata) {
4075   *dst++ = *src++;
4076 }
4077
4078 /* Zero bss */
4079 for (dst = &_bstart; dst< &_bend; dst++)
4080   *dst = 0;
4081
4082 .Ed
4083 .Pp
4084 .No  Forced Output Alignment
4085 .Pp
4086 You can increase an output section's alignment by using ALIGN.
4087 .Pp
4088 .No  Forced Input Alignment
4089 .Pp
4090 You can force input section alignment within an output section by using SUBALIGN.
4091 The value specified overrides any alignment given by input sections, whether
4092 larger or smaller.
4093 .Pp
4094 .No  Output Section Region
4095 .Pp
4096 You can assign a section to a previously defined region of memory by using
4097 .Li > Va region .
4098 See Section.Dq MEMORY .
4099 .Pp
4100 Here is a simple example:
4101 .Bd -literal -offset indent
4102
4103 MEMORY { rom : ORIGIN = 0x1000, LENGTH = 0x1000 }
4104 SECTIONS { ROM : { *(.text) } >rom }
4105
4106 .Ed
4107 .Pp
4108 .No  Output Section Phdr
4109 .Pp
4110 You can assign a section to a previously defined program segment by using
4111 .Li : Va phdr .
4112 See Section.Dq PHDRS .
4113 If a section is assigned to one or more segments, then all subsequent allocated
4114 sections will be assigned to those segments as well, unless they use an explicitly
4115 .Li : Va phdr
4116 modifier. You can use
4117 .Li :NONE
4118 to tell the linker to not put the section in any segment at all.
4119 .Pp
4120 Here is a simple example:
4121 .Bd -literal -offset indent
4122
4123 PHDRS { text PT_LOAD ; }
4124 SECTIONS { .text : { *(.text) } :text }
4125
4126 .Ed
4127 .Pp
4128 .No  Output Section Fill
4129 .Pp
4130 You can set the fill pattern for an entire section by using
4131 .Li = Va fillexp .
4132 .Va fillexp
4133 is an expression (see Section
4134 .Dq Expressions ) .
4135 Any otherwise unspecified regions of memory within the output section (for
4136 example, gaps left due to the required alignment of input sections) will be
4137 filled with the value, repeated as necessary. If the fill expression is a
4138 simple hex number, ie. a string of hex digit starting with
4139 .Li 0x
4140 and without a trailing
4141 .Li k
4142 or
4143 .Li M ,
4144 then an arbitrarily long sequence of hex digits can be used to specify the
4145 fill pattern; Leading zeros become part of the pattern too. For all other
4146 cases, including extra parentheses or a unary
4147 .Li + ,
4148 the fill pattern is the four least significant bytes of the value of the expression.
4149 In all cases, the number is big-endian.
4150 .Pp
4151 You can also change the fill value with a
4152 .Li FILL
4153 command in the output section commands; (see Section
4154 .Dq Output Section Data ) .
4155 .Pp
4156 Here is a simple example:
4157 .Bd -literal -offset indent
4158
4159 SECTIONS { .text : { *(.text) } =0x90909090 }
4160
4161 .Ed
4162 .Pp
4163 .Em  Overlay Description
4164 .Pp
4165 An overlay description provides an easy way to describe sections which are
4166 to be loaded as part of a single memory image but are to be run at the same
4167 memory address. At run time, some sort of overlay manager will copy the overlaid
4168 sections in and out of the runtime memory address as required, perhaps by
4169 simply manipulating addressing bits. This approach can be useful, for example,
4170 when a certain region of memory is faster than another.
4171 .Pp
4172 Overlays are described using the
4173 .Li OVERLAY
4174 command. The
4175 .Li OVERLAY
4176 command is used within a
4177 .Li SECTIONS
4178 command, like an output section description. The full syntax of the
4179 .Li OVERLAY
4180 command is as follows:
4181 .Bd -literal -offset indent
4182
4183 OVERLAY [start] : [NOCROSSREFS] [AT ( ldaddr )]
4184   {
4185     secname1
4186       {
4187         output-section-command
4188         output-section-command
4189         ...
4190       } [:phdr...] [=fill]
4191     secname2
4192       {
4193         output-section-command
4194         output-section-command
4195         ...
4196       } [:phdr...] [=fill]
4197     ...
4198   } [>region] [:phdr...] [=fill]
4199
4200 .Ed
4201 .Pp
4202 Everything is optional except
4203 .Li OVERLAY
4204 (a keyword), and each section must have a name (
4205 .Va secname1
4206 and
4207 .Va secname2
4208 above). The section definitions within the
4209 .Li OVERLAY
4210 construct are identical to those within the general
4211 .Li SECTIONS
4212 contruct (see Section
4213 .Dq SECTIONS ) ,
4214 except that no addresses and no memory regions may be defined for sections
4215 within an
4216 .Li OVERLAY .
4217 .Pp
4218 The sections are all defined with the same starting address. The load addresses
4219 of the sections are arranged such that they are consecutive in memory starting
4220 at the load address used for the
4221 .Li OVERLAY
4222 as a whole (as with normal section definitions, the load address is optional,
4223 and defaults to the start address; the start address is also optional, and
4224 defaults to the current value of the location counter).
4225 .Pp
4226 If the
4227 .Li NOCROSSREFS
4228 keyword is used, and there any references among the sections, the linker will
4229 report an error. Since the sections all run at the same address, it normally
4230 does not make sense for one section to refer directly to another.See Section
4231 .Dq Miscellaneous Commands .
4232 .Pp
4233 For each section within the
4234 .Li OVERLAY ,
4235 the linker automatically provides two symbols. The symbol
4236 .Li __load_start_ Va secname
4237 is defined as the starting load address of the section. The symbol
4238 .Li __load_stop_ Va secname
4239 is defined as the final load address of the section. Any characters within
4240 .Va secname
4241 which are not legal within C identifiers are removed. C (or assembler) code
4242 may use these symbols to move the overlaid sections around as necessary.
4243 .Pp
4244 At the end of the overlay, the value of the location counter is set to the
4245 start address of the overlay plus the size of the largest section.
4246 .Pp
4247 Here is an example. Remember that this would appear inside a
4248 .Li SECTIONS
4249 construct.
4250 .Bd -literal -offset indent
4251
4252   OVERLAY 0x1000 : AT (0x4000)
4253    {
4254      .text0 { o1/*.o(.text) }
4255      .text1 { o2/*.o(.text) }
4256    }
4257
4258 .Ed
4259 This will define both
4260 .Li .text0
4261 and
4262 .Li .text1
4263 to start at address 0x1000.
4264 .Li .text0
4265 will be loaded at address 0x4000, and
4266 .Li .text1
4267 will be loaded immediately after
4268 .Li .text0 .
4269 The following symbols will be defined if referenced:
4270 .Li __load_start_text0 ,
4271 .Li __load_stop_text0 ,
4272 .Li __load_start_text1 ,
4273 .Li __load_stop_text1 .
4274 .Pp
4275 C code to copy overlay
4276 .Li .text1
4277 into the overlay area might look like the following.
4278 .Pp
4279 .Bd -literal -offset indent
4280
4281   extern char __load_start_text1, __load_stop_text1;
4282   memcpy ((char *) 0x1000, &__load_start_text1,
4283           &__load_stop_text1 - &__load_start_text1);
4284
4285 .Ed
4286 .Pp
4287 Note that the
4288 .Li OVERLAY
4289 command is just syntactic sugar, since everything it does can be done using
4290 the more basic commands. The above example could have been written identically
4291 as follows.
4292 .Pp
4293 .Bd -literal -offset indent
4294
4295   .text0 0x1000 : AT (0x4000) { o1/*.o(.text) }
4296   PROVIDE (__load_start_text0 = LOADADDR (.text0));
4297   PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
4298   .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) }
4299   PROVIDE (__load_start_text1 = LOADADDR (.text1));
4300   PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
4301   . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
4302
4303 .Ed
4304 .Pp
4305 .Ss  MEMORY Command
4306 The linker's default configuration permits allocation of all available memory.
4307 You can override this by using the
4308 .Li MEMORY
4309 command.
4310 .Pp
4311 The
4312 .Li MEMORY
4313 command describes the location and size of blocks of memory in the target.
4314 You can use it to describe which memory regions may be used by the linker,
4315 and which memory regions it must avoid. You can then assign sections to particular
4316 memory regions. The linker will set section addresses based on the memory
4317 regions, and will warn about regions that become too full. The linker will
4318 not shuffle sections around to fit into the available regions.
4319 .Pp
4320 A linker script may contain at most one use of the
4321 .Li MEMORY
4322 command. However, you can define as many blocks of memory within it as you
4323 wish. The syntax is:
4324 .Bd -literal -offset indent
4325
4326 MEMORY
4327   {
4328     name [(attr)] : ORIGIN = origin, LENGTH = len
4329     ...
4330   }
4331
4332 .Ed
4333 .Pp
4334 The
4335 .Va name
4336 is a name used in the linker script to refer to the region. The region name
4337 has no meaning outside of the linker script. Region names are stored in a
4338 separate name space, and will not conflict with symbol names, file names,
4339 or section names. Each memory region must have a distinct name.
4340 .Pp
4341 The
4342 .Va attr
4343 string is an optional list of attributes that specify whether to use a particular
4344 memory region for an input section which is not explicitly mapped in the linker
4345 script. As described in SECTIONS, if you do not specify an output section
4346 for some input section, the linker will create an output section with the
4347 same name as the input section. If you define region attributes, the linker
4348 will use them to select the memory region for the output section that it creates.
4349 .Pp
4350 The
4351 .Va attr
4352 string must consist only of the following characters:
4353 .Bl -tag -width Ds
4354 .It  R
4355 Read-only section
4356 .It  W
4357 Read/write section
4358 .It  X
4359 Executable section
4360 .It  A
4361 Allocatable section
4362 .It  I
4363 Initialized section
4364 .It  L
4365 Same as
4366 .Li I
4367 .It  !
4368 Invert the sense of any of the preceding attributes
4369 .El
4370 .Pp
4371 If a unmapped section matches any of the listed attributes other than
4372 .Li ! ,
4373 it will be placed in the memory region. The
4374 .Li !
4375 attribute reverses this test, so that an unmapped section will be placed in
4376 the memory region only if it does not match any of the listed attributes.
4377 .Pp
4378 The
4379 .Va origin
4380 is an numerical expression for the start address of the memory region. The
4381 expression must evaluate to a constant and it cannot involve any symbols.
4382 The keyword
4383 .Li ORIGIN
4384 may be abbreviated to
4385 .Li org
4386 or
4387 .Li o
4388 (but not, for example,
4389 .Li ORG ) .
4390 .Pp
4391 The
4392 .Va len
4393 is an expression for the size in bytes of the memory region. As with the
4394 .Va origin
4395 expression, the expression must be numerical only and must evaluate to a constant.
4396 The keyword
4397 .Li LENGTH
4398 may be abbreviated to
4399 .Li len
4400 or
4401 .Li l .
4402 .Pp
4403 In the following example, we specify that there are two memory regions available
4404 for allocation: one starting at
4405 .Li 0
4406 for 256 kilobytes, and the other starting at
4407 .Li 0x40000000
4408 for four megabytes. The linker will place into the
4409 .Li rom
4410 memory region every section which is not explicitly mapped into a memory region,
4411 and is either read-only or executable. The linker will place other sections
4412 which are not explicitly mapped into a memory region into the
4413 .Li ram
4414 memory region.
4415 .Pp
4416 .Bd -literal -offset indent
4417
4418 MEMORY
4419   {
4420     rom (rx)  : ORIGIN = 0, LENGTH = 256K
4421     ram (!rx) : org = 0x40000000, l = 4M
4422   }
4423
4424 .Ed
4425 .Pp
4426 Once you define a memory region, you can direct the linker to place specific
4427 output sections into that memory region by using the
4428 .Li > Va region
4429 output section attribute. For example, if you have a memory region named
4430 .Li mem ,
4431 you would use
4432 .Li >mem
4433 in the output section definition.See Section
4434 .Dq Output Section Region .
4435 If no address was specified for the output section, the linker will set the
4436 address to the next available address within the memory region. If the combined
4437 output sections directed to a memory region are too large for the region,
4438 the linker will issue an error message.
4439 .Pp
4440 It is possible to access the origin and length of a memory in an expression
4441 via the
4442 .Li ORIGIN( Va memory)
4443 and
4444 .Li LENGTH( Va memory)
4445 functions:
4446 .Pp
4447 .Bd -literal -offset indent
4448
4449   _fstack = ORIGIN(ram) + LENGTH(ram) - 4;  
4450
4451 .Ed
4452 .Pp
4453 .Ss  PHDRS Command
4454 The ELF object file format uses
4455 .Em program headers ,
4456 also knows as
4457 .Em segments .
4458 The program headers describe how the program should be loaded into memory.
4459 You can print them out by using the
4460 .Li objdump
4461 program with the
4462 .Li -p
4463 option.
4464 .Pp
4465 When you run an ELF program on a native ELF system, the system loader reads
4466 the program headers in order to figure out how to load the program. This will
4467 only work if the program headers are set correctly. This manual does not describe
4468 the details of how the system loader interprets program headers; for more
4469 information, see the ELF ABI.
4470 .Pp
4471 The linker will create reasonable program headers by default. However, in
4472 some cases, you may need to specify the program headers more precisely. You
4473 may use the
4474 .Li PHDRS
4475 command for this purpose. When the linker sees the
4476 .Li PHDRS
4477 command in the linker script, it will not create any program headers other
4478 than the ones specified.
4479 .Pp
4480 The linker only pays attention to the
4481 .Li PHDRS
4482 command when generating an ELF output file. In other cases, the linker will
4483 simply ignore
4484 .Li PHDRS .
4485 .Pp
4486 This is the syntax of the
4487 .Li PHDRS
4488 command. The words
4489 .Li PHDRS ,
4490 .Li FILEHDR ,
4491 .Li AT ,
4492 and
4493 .Li FLAGS
4494 are keywords.
4495 .Pp
4496 .Bd -literal -offset indent
4497
4498 PHDRS
4499 {
4500   name type [ FILEHDR ] [ PHDRS ] [ AT ( address ) ]
4501         [ FLAGS ( flags ) ] ;
4502 }
4503
4504 .Ed
4505 .Pp
4506 The
4507 .Va name
4508 is used only for reference in the
4509 .Li SECTIONS
4510 command of the linker script. It is not put into the output file. Program
4511 header names are stored in a separate name space, and will not conflict with
4512 symbol names, file names, or section names. Each program header must have
4513 a distinct name.
4514 .Pp
4515 Certain program header types describe segments of memory which the system
4516 loader will load from the file. In the linker script, you specify the contents
4517 of these segments by placing allocatable output sections in the segments.
4518 You use the
4519 .Li : Va phdr
4520 output section attribute to place a section in a particular segment.See Section
4521 .Dq Output Section Phdr .
4522 .Pp
4523 It is normal to put certain sections in more than one segment. This merely
4524 implies that one segment of memory contains another. You may repeat
4525 .Li : Va phdr ,
4526 using it once for each segment which should contain the section.
4527 .Pp
4528 If you place a section in one or more segments using
4529 .Li : Va phdr ,
4530 then the linker will place all subsequent allocatable sections which do not
4531 specify
4532 .Li : Va phdr
4533 in the same segments. This is for convenience, since generally a whole set
4534 of contiguous sections will be placed in a single segment. You can use
4535 .Li :NONE
4536 to override the default segment and tell the linker to not put the section
4537 in any segment at all.
4538 .Pp
4539 You may use the
4540 .Li FILEHDR
4541 and
4542 .Li PHDRS
4543 keywords appear after the program header type to further describe the contents
4544 of the segment. The
4545 .Li FILEHDR
4546 keyword means that the segment should include the ELF file header. The
4547 .Li PHDRS
4548 keyword means that the segment should include the ELF program headers themselves.
4549 .Pp
4550 The
4551 .Va type
4552 may be one of the following. The numbers indicate the value of the keyword.
4553 .Pp
4554 .Bl -tag -width Ds
4555 .It  Li PT_NULL (0)
4556 Indicates an unused program header.
4557 .Pp
4558 .It  Li PT_LOAD (1)
4559 Indicates that this program header describes a segment to be loaded from the
4560 file.
4561 .Pp
4562 .It  Li PT_DYNAMIC (2)
4563 Indicates a segment where dynamic linking information can be found.
4564 .Pp
4565 .It  Li PT_INTERP (3)
4566 Indicates a segment where the name of the program interpreter may be found.
4567 .Pp
4568 .It  Li PT_NOTE (4)
4569 Indicates a segment holding note information.
4570 .Pp
4571 .It  Li PT_SHLIB (5)
4572 A reserved program header type, defined but not specified by the ELF ABI.
4573 .Pp
4574 .It  Li PT_PHDR (6)
4575 Indicates a segment where the program headers may be found.
4576 .Pp
4577 .It  Va expression
4578 An expression giving the numeric type of the program header. This may be used
4579 for types not defined above.
4580 .El
4581 .Pp
4582 You can specify that a segment should be loaded at a particular address in
4583 memory by using an
4584 .Li AT
4585 expression. This is identical to the
4586 .Li AT
4587 command used as an output section attribute (see Section
4588 .Dq Output Section LMA ) .
4589 The
4590 .Li AT
4591 command for a program header overrides the output section attribute.
4592 .Pp
4593 The linker will normally set the segment flags based on the sections which
4594 comprise the segment. You may use the
4595 .Li FLAGS
4596 keyword to explicitly specify the segment flags. The value of
4597 .Va flags
4598 must be an integer. It is used to set the
4599 .Li p_flags
4600 field of the program header.
4601 .Pp
4602 Here is an example of
4603 .Li PHDRS .
4604 This shows a typical set of program headers used on a native ELF system.
4605 .Pp
4606 .Bd -literal -offset indent
4607
4608 PHDRS
4609 {
4610   headers PT_PHDR PHDRS ;
4611   interp PT_INTERP ;
4612   text PT_LOAD FILEHDR PHDRS ;
4613   data PT_LOAD ;
4614   dynamic PT_DYNAMIC ;
4615 }
4616
4617 SECTIONS
4618 {
4619   . = SIZEOF_HEADERS;
4620   .interp : { *(.interp) } :text :interp
4621   .text : { *(.text) } :text
4622   .rodata : { *(.rodata) } /* defaults to :text */
4623   ...
4624   . = . + 0x1000; /* move to a new page in memory */
4625   .data : { *(.data) } :data
4626   .dynamic : { *(.dynamic) } :data :dynamic
4627   ...
4628 }
4629
4630 .Ed
4631 .Pp
4632 .Ss  VERSION Command
4633 The linker supports symbol versions when using ELF. Symbol versions are only
4634 useful when using shared libraries. The dynamic linker can use symbol versions
4635 to select a specific version of a function when it runs a program that may
4636 have been linked against an earlier version of the shared library.
4637 .Pp
4638 You can include a version script directly in the main linker script, or you
4639 can supply the version script as an implicit linker script. You can also use
4640 the
4641 .Li --version-script
4642 linker option.
4643 .Pp
4644 The syntax of the
4645 .Li VERSION
4646 command is simply
4647 .Bd -literal -offset indent
4648 VERSION { version-script-commands }
4649 .Ed
4650 .Pp
4651 The format of the version script commands is identical to that used by Sun's
4652 linker in Solaris 2.5. The version script defines a tree of version nodes.
4653 You specify the node names and interdependencies in the version script. You
4654 can specify which symbols are bound to which version nodes, and you can reduce
4655 a specified set of symbols to local scope so that they are not globally visible
4656 outside of the shared library.
4657 .Pp
4658 The easiest way to demonstrate the version script language is with a few examples.
4659 .Pp
4660 .Bd -literal -offset indent
4661 VERS_1.1 {
4662          global:
4663                  foo1;
4664          local:
4665                  old*;
4666                  original*;
4667                  new*;
4668 };
4669
4670 VERS_1.2 {
4671                  foo2;
4672 } VERS_1.1;
4673
4674 VERS_2.0 {
4675                  bar1; bar2;
4676          extern "C++" {       
4677                  ns::*;
4678                  "int f(int, double)";
4679          }         
4680 } VERS_1.2;
4681 .Ed
4682 .Pp
4683 This example version script defines three version nodes. The first version
4684 node defined is
4685 .Li VERS_1.1 ;
4686 it has no other dependencies. The script binds the symbol
4687 .Li foo1
4688 to
4689 .Li VERS_1.1 .
4690 It reduces a number of symbols to local scope so that they are not visible
4691 outside of the shared library; this is done using wildcard patterns, so that
4692 any symbol whose name begins with
4693 .Li old ,
4694 .Li original ,
4695 or
4696 .Li new
4697 is matched. The wildcard patterns available are the same as those used in
4698 the shell when matching filenames (also known as \(lqglobbing\(rq). However, if you
4699 specify the symbol name inside double quotes, then the name is treated as
4700 literal, rather than as a glob pattern.
4701 .Pp
4702 Next, the version script defines node
4703 .Li VERS_1.2 .
4704 This node depends upon
4705 .Li VERS_1.1 .
4706 The script binds the symbol
4707 .Li foo2
4708 to the version node
4709 .Li VERS_1.2 .
4710 .Pp
4711 Finally, the version script defines node
4712 .Li VERS_2.0 .
4713 This node depends upon
4714 .Li VERS_1.2 .
4715 The scripts binds the symbols
4716 .Li bar1
4717 and
4718 .Li bar2
4719 are bound to the version node
4720 .Li VERS_2.0 .
4721 .Pp
4722 When the linker finds a symbol defined in a library which is not specifically
4723 bound to a version node, it will effectively bind it to an unspecified base
4724 version of the library. You can bind all otherwise unspecified symbols to
4725 a given version node by using
4726 .Li global: *;
4727 somewhere in the version script.
4728 .Pp
4729 The names of the version nodes have no specific meaning other than what they
4730 might suggest to the person reading them. The
4731 .Li 2.0
4732 version could just as well have appeared in between
4733 .Li 1.1
4734 and
4735 .Li 1.2 .
4736 However, this would be a confusing way to write a version script.
4737 .Pp
4738 Node name can be omitted, provided it is the only version node in the version
4739 script. Such version script doesn't assign any versions to symbols, only selects
4740 which symbols will be globally visible out and which won't.
4741 .Pp
4742 .Bd -literal -offset indent
4743 { global: foo; bar; local: *; };
4744 .Ed
4745 .Pp
4746 When you link an application against a shared library that has versioned symbols,
4747 the application itself knows which version of each symbol it requires, and
4748 it also knows which version nodes it needs from each shared library it is
4749 linked against. Thus at runtime, the dynamic loader can make a quick check
4750 to make sure that the libraries you have linked against do in fact supply
4751 all of the version nodes that the application will need to resolve all of
4752 the dynamic symbols. In this way it is possible for the dynamic linker to
4753 know with certainty that all external symbols that it needs will be resolvable
4754 without having to search for each symbol reference.
4755 .Pp
4756 The symbol versioning is in effect a much more sophisticated way of doing
4757 minor version checking that SunOS does. The fundamental problem that is being
4758 addressed here is that typically references to external functions are bound
4759 on an as-needed basis, and are not all bound when the application starts up.
4760 If a shared library is out of date, a required interface may be missing; when
4761 the application tries to use that interface, it may suddenly and unexpectedly
4762 fail. With symbol versioning, the user will get a warning when they start
4763 their program if the libraries being used with the application are too old.
4764 .Pp
4765 There are several GNU extensions to Sun's versioning approach. The first of
4766 these is the ability to bind a symbol to a version node in the source file
4767 where the symbol is defined instead of in the versioning script. This was
4768 done mainly to reduce the burden on the library maintainer. You can do this
4769 by putting something like:
4770 .Bd -literal -offset indent
4771 __asm__(".symver original_foo,foo@VERS_1.1");
4772 .Ed
4773 in the C source file. This renames the function
4774 .Li original_foo
4775 to be an alias for
4776 .Li foo
4777 bound to the version node
4778 .Li VERS_1.1 .
4779 The
4780 .Li local:
4781 directive can be used to prevent the symbol
4782 .Li original_foo
4783 from being exported. A
4784 .Li .symver
4785 directive takes precedence over a version script.
4786 .Pp
4787 The second GNU extension is to allow multiple versions of the same function
4788 to appear in a given shared library. In this way you can make an incompatible
4789 change to an interface without increasing the major version number of the
4790 shared library, while still allowing applications linked against the old interface
4791 to continue to function.
4792 .Pp
4793 To do this, you must use multiple
4794 .Li .symver
4795 directives in the source file. Here is an example:
4796 .Pp
4797 .Bd -literal -offset indent
4798 __asm__(".symver original_foo,foo@");
4799 __asm__(".symver old_foo,foo@VERS_1.1");
4800 __asm__(".symver old_foo1,foo@VERS_1.2");
4801 __asm__(".symver new_foo,foo@@VERS_2.0");
4802 .Ed
4803 .Pp
4804 In this example,
4805 .Li foo@
4806 represents the symbol
4807 .Li foo
4808 bound to the unspecified base version of the symbol. The source file that
4809 contains this example would define 4 C functions:
4810 .Li original_foo ,
4811 .Li old_foo ,
4812 .Li old_foo1 ,
4813 and
4814 .Li new_foo .
4815 .Pp
4816 When you have multiple definitions of a given symbol, there needs to be some
4817 way to specify a default version to which external references to this symbol
4818 will be bound. You can do this with the
4819 .Li foo@@VERS_2.0
4820 type of
4821 .Li .symver
4822 directive. You can only declare one version of a symbol as the default in
4823 this manner; otherwise you would effectively have multiple definitions of
4824 the same symbol.
4825 .Pp
4826 If you wish to bind a reference to a specific version of the symbol within
4827 the shared library, you can use the aliases of convenience (i.e.,
4828 .Li old_foo ) ,
4829 or you can use the
4830 .Li .symver
4831 directive to specifically bind to an external version of the function in question.
4832 .Pp
4833 You can also specify the language in the version script:
4834 .Pp
4835 .Bd -literal -offset indent
4836 VERSION extern "lang" { version-script-commands }
4837 .Ed
4838 .Pp
4839 The supported
4840 .Li lang
4841 s are
4842 .Li C ,
4843 .Li C++ ,
4844 and
4845 .Li Java .
4846 The linker will iterate over the list of symbols at the link time and demangle
4847 them according to
4848 .Li lang
4849 before matching them to the patterns specified in
4850 .Li version-script-commands .
4851 .Pp
4852 Demangled names may contains spaces and other special characters. As described
4853 above, you can use a glob pattern to match demangled names, or you can use
4854 a double-quoted string to match the string exactly. In the latter case, be
4855 aware that minor differences (such as differing whitespace) between the version
4856 script and the demangler output will cause a mismatch. As the exact string
4857 generated by the demangler might change in the future, even if the mangled
4858 name does not, you should check that all of your version directives are behaving
4859 as you expect when you upgrade.
4860 .Pp
4861 .Ss  Expressions in Linker Scripts
4862 The syntax for expressions in the linker script language is identical to that
4863 of C expressions. All expressions are evaluated as integers. All expressions
4864 are evaluated in the same size, which is 32 bits if both the host and target
4865 are 32 bits, and is otherwise 64 bits.
4866 .Pp
4867 You can use and set symbol values in expressions.
4868 .Pp
4869 The linker defines several special purpose builtin functions for use in expressions.
4870 .Pp
4871 .Em  Constants
4872 .Pp
4873 All constants are integers.
4874 .Pp
4875 As in C, the linker considers an integer beginning with
4876 .Li 0
4877 to be octal, and an integer beginning with
4878 .Li 0x
4879 or
4880 .Li 0X
4881 to be hexadecimal. The linker considers other integers to be decimal.
4882 .Pp
4883 In addition, you can use the suffixes
4884 .Li K
4885 and
4886 .Li M
4887 to scale a constant by
4888 .Li 1024
4889 or
4890 .Li 1024*1024
4891 respectively. For example, the following all refer to the same quantity:
4892 .Bd -literal -offset indent
4893 _fourk_1 = 4K;
4894 _fourk_2 = 4096;
4895 _fourk_3 = 0x1000;
4896 .Ed
4897 .Pp
4898 .Em  Symbol Names
4899 .Pp
4900 Unless quoted, symbol names start with a letter, underscore, or period and
4901 may include letters, digits, underscores, periods, and hyphens. Unquoted symbol
4902 names must not conflict with any keywords. You can specify a symbol which
4903 contains odd characters or has the same name as a keyword by surrounding the
4904 symbol name in double quotes:
4905 .Bd -literal -offset indent
4906 "SECTION" = 9;
4907 "with a space" = "also with a space" + 10;
4908 .Ed
4909 .Pp
4910 Since symbols can contain many non-alphabetic characters, it is safest to
4911 delimit symbols with spaces. For example,
4912 .Li A-B
4913 is one symbol, whereas
4914 .Li A - B
4915 is an expression involving subtraction.
4916 .Pp
4917 .Em  Orphan Sections
4918 .Pp
4919 Orphan sections are sections present in the input files which are not explicitly
4920 placed into the output file by the linker script. The linker will still copy
4921 these sections into the output file, but it has to guess as to where they
4922 should be placed. The linker uses a simple heuristic to do this. It attempts
4923 to place orphan sections after non-orphan sections of the same attribute,
4924 such as code vs data, loadable vs non-loadable, etc. If there is not enough
4925 room to do this then it places at the end of the file.
4926 .Pp
4927 For ELF targets, the attribute of the section includes section type as well
4928 as section flag.
4929 .Pp
4930 .Em  The Location Counter
4931 .Pp
4932 The special linker variable
4933 .Em dot
4934 .Li .
4935 always contains the current output location counter. Since the
4936 .Li .
4937 always refers to a location in an output section, it may only appear in an
4938 expression within a
4939 .Li SECTIONS
4940 command. The
4941 .Li .
4942 symbol may appear anywhere that an ordinary symbol is allowed in an expression.
4943 .Pp
4944 Assigning a value to
4945 .Li .
4946 will cause the location counter to be moved. This may be used to create holes
4947 in the output section. The location counter may not be moved backwards inside
4948 an output section, and may not be moved backwards outside of an output section
4949 if so doing creates areas with overlapping LMAs.
4950 .Pp
4951 .Bd -literal -offset indent
4952 SECTIONS
4953 {
4954   output :
4955     {
4956       file1(.text)
4957       . = . + 1000;
4958       file2(.text)
4959       . += 1000;
4960       file3(.text)
4961     } = 0x12345678;
4962 }
4963 .Ed
4964 In the previous example, the
4965 .Li .text
4966 section from
4967 .Pa file1
4968 is located at the beginning of the output section
4969 .Li output .
4970 It is followed by a 1000 byte gap. Then the
4971 .Li .text
4972 section from
4973 .Pa file2
4974 appears, also with a 1000 byte gap following before the
4975 .Li .text
4976 section from
4977 .Pa file3 .
4978 The notation
4979 .Li = 0x12345678
4980 specifies what data to write in the gaps (see Section
4981 .Dq Output Section Fill ) .
4982 .Pp
4983 Note:
4984 .Li .
4985 actually refers to the byte offset from the start of the current containing
4986 object. Normally this is the
4987 .Li SECTIONS
4988 statement, whose start address is 0, hence
4989 .Li .
4990 can be used as an absolute address. If
4991 .Li .
4992 is used inside a section description however, it refers to the byte offset
4993 from the start of that section, not an absolute address. Thus in a script
4994 like this:
4995 .Pp
4996 .Bd -literal -offset indent
4997 SECTIONS
4998 {
4999     . = 0x100
5000     .text: {
5001       *(.text)
5002       . = 0x200
5003     }
5004     . = 0x500
5005     .data: {
5006       *(.data)
5007       . += 0x600
5008     }
5009 }
5010 .Ed
5011 .Pp
5012 The
5013 .Li .text
5014 section will be assigned a starting address of 0x100 and a size of exactly
5015 0x200 bytes, even if there is not enough data in the
5016 .Li .text
5017 input sections to fill this area. (If there is too much data, an error will
5018 be produced because this would be an attempt to move
5019 .Li .
5020 backwards). The
5021 .Li .data
5022 section will start at 0x500 and it will have an extra 0x600 bytes worth of
5023 space after the end of the values from the
5024 .Li .data
5025 input sections and before the end of the
5026 .Li .data
5027 output section itself.
5028 .Pp
5029 Setting symbols to the value of the location counter outside of an output
5030 section statement can result in unexpected values if the linker needs to place
5031 orphan sections. For example, given the following:
5032 .Pp
5033 .Bd -literal -offset indent
5034 SECTIONS
5035 {
5036     start_of_text = . ;
5037     .text: { *(.text) }
5038     end_of_text = . ;
5039
5040     start_of_data = . ;
5041     .data: { *(.data) }
5042     end_of_data = . ;
5043 }
5044 .Ed
5045 .Pp
5046 If the linker needs to place some input section, e.g.
5047 .Li .rodata ,
5048 not mentioned in the script, it might choose to place that section between
5049 .Li .text
5050 and
5051 .Li .data .
5052 You might think the linker should place
5053 .Li .rodata
5054 on the blank line in the above script, but blank lines are of no particular
5055 significance to the linker. As well, the linker doesn't associate the above
5056 symbol names with their sections. Instead, it assumes that all assignments
5057 or other statements belong to the previous output section, except for the
5058 special case of an assignment to
5059 .Li . .
5060 I.e., the linker will place the orphan
5061 .Li .rodata
5062 section as if the script was written as follows:
5063 .Pp
5064 .Bd -literal -offset indent
5065 SECTIONS
5066 {
5067     start_of_text = . ;
5068     .text: { *(.text) }
5069     end_of_text = . ;
5070
5071     start_of_data = . ;
5072     .rodata: { *(.rodata) }
5073     .data: { *(.data) }
5074     end_of_data = . ;
5075 }
5076 .Ed
5077 .Pp
5078 This may or may not be the script author's intention for the value of
5079 .Li start_of_data .
5080 One way to influence the orphan section placement is to assign the location
5081 counter to itself, as the linker assumes that an assignment to
5082 .Li .
5083 is setting the start address of a following output section and thus should
5084 be grouped with that section. So you could write:
5085 .Pp
5086 .Bd -literal -offset indent
5087 SECTIONS
5088 {
5089     start_of_text = . ;
5090     .text: { *(.text) }
5091     end_of_text = . ;
5092
5093     . = . ;
5094     start_of_data = . ;
5095     .data: { *(.data) }
5096     end_of_data = . ;
5097 }
5098 .Ed
5099 .Pp
5100 Now, the orphan
5101 .Li .rodata
5102 section will be placed between
5103 .Li end_of_text
5104 and
5105 .Li start_of_data .
5106 .Pp
5107 .Em  Operators
5108 .Pp
5109 The linker recognizes the standard C set of arithmetic operators, with the
5110 standard bindings and precedence levels:
5111 .Bd -literal -offset indent
5112 precedence      associativity   Operators                Notes
5113 (highest)
5114 1               left            !  -  ~                  (1)
5115 2               left            *  /  %
5116 3               left            +  -
5117 4               left            >>  <<
5118 5               left            ==  !=  >  <  <=  >=
5119 6               left            &
5120 7               left            |
5121 8               left            &&
5122 9               left            ||
5123 10              right           ? :
5124 11              right           &=  +=  -=  *=  /=       (2)
5125 (lowest)
5126 .Ed
5127 Notes: (1) Prefix operators (2)See Section
5128 .Dq Assignments .
5129 .Pp
5130 .Em  Evaluation
5131 .Pp
5132 The linker evaluates expressions lazily. It only computes the value of an
5133 expression when absolutely necessary.
5134 .Pp
5135 The linker needs some information, such as the value of the start address
5136 of the first section, and the origins and lengths of memory regions, in order
5137 to do any linking at all. These values are computed as soon as possible when
5138 the linker reads in the linker script.
5139 .Pp
5140 However, other values (such as symbol values) are not known or needed until
5141 after storage allocation. Such values are evaluated later, when other information
5142 (such as the sizes of output sections) is available for use in the symbol
5143 assignment expression.
5144 .Pp
5145 The sizes of sections cannot be known until after allocation, so assignments
5146 dependent upon these are not performed until after allocation.
5147 .Pp
5148 Some expressions, such as those depending upon the location counter
5149 .Li . ,
5150 must be evaluated during section allocation.
5151 .Pp
5152 If the result of an expression is required, but the value is not available,
5153 then an error results. For example, a script like the following
5154 .Bd -literal -offset indent
5155
5156 SECTIONS
5157   {
5158     .text 9+this_isnt_constant :
5159       { *(.text) }
5160   }
5161
5162 .Ed
5163 will cause the error message
5164 .Li non constant expression for initial address .
5165 .Pp
5166 .Em  The Section of an Expression
5167 .Pp
5168 When the linker evaluates an expression, the result is either absolute or
5169 relative to some section. A relative expression is expressed as a fixed offset
5170 from the base of a section.
5171 .Pp
5172 The position of the expression within the linker script determines whether
5173 it is absolute or relative. An expression which appears within an output section
5174 definition is relative to the base of the output section. An expression which
5175 appears elsewhere will be absolute.
5176 .Pp
5177 A symbol set to a relative expression will be relocatable if you request relocatable
5178 output using the
5179 .Li -r
5180 option. That means that a further link operation may change the value of the
5181 symbol. The symbol's section will be the section of the relative expression.
5182 .Pp
5183 A symbol set to an absolute expression will retain the same value through
5184 any further link operation. The symbol will be absolute, and will not have
5185 any particular associated section.
5186 .Pp
5187 You can use the builtin function
5188 .Li ABSOLUTE
5189 to force an expression to be absolute when it would otherwise be relative.
5190 For example, to create an absolute symbol set to the address of the end of
5191 the output section
5192 .Li .data :
5193 .Bd -literal -offset indent
5194 SECTIONS
5195   {
5196     .data : { *(.data) _edata = ABSOLUTE(.); }
5197   }
5198 .Ed
5199 If
5200 .Li ABSOLUTE
5201 were not used,
5202 .Li _edata
5203 would be relative to the
5204 .Li .data
5205 section.
5206 .Pp
5207 .Em  Builtin Functions
5208 .Pp
5209 The linker script language includes a number of builtin functions for use
5210 in linker script expressions.
5211 .Pp
5212 .Bl -tag -width Ds
5213 .It  ABSOLUTE( Va exp)
5214 Return the absolute (non-relocatable, as opposed to non-negative) value of
5215 the expression
5216 .Va exp .
5217 Primarily useful to assign an absolute value to a symbol within a section
5218 definition, where symbol values are normally section relative.See Section
5219 .Dq Expression Section .
5220 .Pp
5221 .It  ADDR( Va section)
5222 Return the absolute address (the VMA) of the named
5223 .Va section .
5224 Your script must previously have defined the location of that section. In
5225 the following example,
5226 .Li symbol_1
5227 and
5228 .Li symbol_2
5229 are assigned identical values:
5230 .Bd -literal -offset indent
5231
5232 SECTIONS { ...
5233   .output1 :
5234     {
5235     start_of_output_1 = ABSOLUTE(.);
5236     ...
5237     }
5238   .output :
5239     {
5240     symbol_1 = ADDR(.output1);
5241     symbol_2 = start_of_output_1;
5242     }
5243 \&... }
5244
5245 .Ed
5246 .Pp
5247 .It  ALIGN( Va align)
5248 .It  ALIGN( Va exp, Va align)
5249 Return the location counter (
5250 .Li . )
5251 or arbitrary expression aligned to the next
5252 .Va align
5253 boundary. The single operand
5254 .Li ALIGN
5255 doesn't change the value of the location counter---it just does arithmetic
5256 on it. The two operand
5257 .Li ALIGN
5258 allows an arbitrary expression to be aligned upwards (
5259 .Li ALIGN( Va align)
5260 is equivalent to
5261 .Li ALIGN(., Va align) ) .
5262 .Pp
5263 Here is an example which aligns the output
5264 .Li .data
5265 section to the next
5266 .Li 0x2000
5267 byte boundary after the preceding section and sets a variable within the section
5268 to the next
5269 .Li 0x8000
5270 boundary after the input sections:
5271 .Bd -literal -offset indent
5272
5273 SECTIONS { ...
5274   .data ALIGN(0x2000): {
5275     *(.data)
5276     variable = ALIGN(0x8000);
5277   }
5278 \&... }
5279
5280 .Ed
5281 The first use of
5282 .Li ALIGN
5283 in this example specifies the location of a section because it is used as
5284 the optional
5285 .Va address
5286 attribute of a section definition (see Section
5287 .Dq Output Section Address ) .
5288 The second use of
5289 .Li ALIGN
5290 is used to defines the value of a symbol.
5291 .Pp
5292 The builtin function
5293 .Li NEXT
5294 is closely related to
5295 .Li ALIGN .
5296 .Pp
5297 .It  ALIGNOF( Va section)
5298 Return the alignment in bytes of the named
5299 .Va section ,
5300 if that section has been allocated. If the section has not been allocated
5301 when this is evaluated, the linker will report an error. In the following
5302 example, the alignment of the
5303 .Li .output
5304 section is stored as the first value in that section.
5305 .Bd -literal -offset indent
5306
5307 SECTIONS{ ...
5308   .output {
5309     LONG (ALIGNOF (.output))
5310     ...
5311     }
5312 \&... }
5313
5314 .Ed
5315 .Pp
5316 .It  BLOCK( Va exp)
5317 This is a synonym for
5318 .Li ALIGN ,
5319 for compatibility with older linker scripts. It is most often seen when setting
5320 the address of an output section.
5321 .Pp
5322 .It  DATA_SEGMENT_ALIGN( Va maxpagesize, Va commonpagesize)
5323 This is equivalent to either
5324 .Bd -literal -offset indent
5325 (ALIGN(maxpagesize) + (. & (maxpagesize - 1)))
5326 .Ed
5327 or
5328 .Bd -literal -offset indent
5329 (ALIGN(maxpagesize) + (. & (maxpagesize - commonpagesize)))
5330 .Ed
5331 depending on whether the latter uses fewer
5332 .Va commonpagesize
5333 sized pages for the data segment (area between the result of this expression
5334 and
5335 .Li DATA_SEGMENT_END )
5336 than the former or not. If the latter form is used, it means
5337 .Va commonpagesize
5338 bytes of runtime memory will be saved at the expense of up to
5339 .Va commonpagesize
5340 wasted bytes in the on-disk file.
5341 .Pp
5342 This expression can only be used directly in
5343 .Li SECTIONS
5344 commands, not in any output section descriptions and only once in the linker
5345 script.
5346 .Va commonpagesize
5347 should be less or equal to
5348 .Va maxpagesize
5349 and should be the system page size the object wants to be optimized for (while
5350 still working on system page sizes up to
5351 .Va maxpagesize ) .
5352 .Pp
5353 Example:
5354 .Bd -literal -offset indent
5355   . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
5356 .Ed
5357 .Pp
5358 .It  DATA_SEGMENT_END( Va exp)
5359 This defines the end of data segment for
5360 .Li DATA_SEGMENT_ALIGN
5361 evaluation purposes.
5362 .Pp
5363 .Bd -literal -offset indent
5364   . = DATA_SEGMENT_END(.);
5365 .Ed
5366 .Pp
5367 .It  DATA_SEGMENT_RELRO_END( Va offset, Va exp)
5368 This defines the end of the
5369 .Li PT_GNU_RELRO
5370 segment when
5371 .Li -z relro
5372 option is used. Second argument is returned. When
5373 .Li -z relro
5374 option is not present,
5375 .Li DATA_SEGMENT_RELRO_END
5376 does nothing, otherwise
5377 .Li DATA_SEGMENT_ALIGN
5378 is padded so that
5379 .Va exp
5380 +
5381 .Va offset
5382 is aligned to the most commonly used page boundary for particular target.
5383 If present in the linker script, it must always come in between
5384 .Li DATA_SEGMENT_ALIGN
5385 and
5386 .Li DATA_SEGMENT_END .
5387 .Pp
5388 .Bd -literal -offset indent
5389   . = DATA_SEGMENT_RELRO_END(24, .);
5390 .Ed
5391 .Pp
5392 .It  DEFINED( Va symbol)
5393 Return 1 if
5394 .Va symbol
5395 is in the linker global symbol table and is defined before the statement using
5396 DEFINED in the script, otherwise return 0. You can use this function to provide
5397 default values for symbols. For example, the following script fragment shows
5398 how to set a global symbol
5399 .Li begin
5400 to the first location in the
5401 .Li .text
5402 section---but if a symbol called
5403 .Li begin
5404 already existed, its value is preserved:
5405 .Pp
5406 .Bd -literal -offset indent
5407
5408 SECTIONS { ...
5409   .text : {
5410     begin = DEFINED(begin) ? begin : . ;
5411     ...
5412   }
5413   ...
5414 }
5415
5416 .Ed
5417 .Pp
5418 .It  LENGTH( Va memory)
5419 Return the length of the memory region named
5420 .Va memory .
5421 .Pp
5422 .It  LOADADDR( Va section)
5423 Return the absolute LMA of the named
5424 .Va section .
5425 This is normally the same as
5426 .Li ADDR ,
5427 but it may be different if the
5428 .Li AT
5429 attribute is used in the output section definition (see Section
5430 .Dq Output Section LMA ) .
5431 .Pp
5432 .It  MAX( Va exp1, Va exp2)
5433 Returns the maximum of
5434 .Va exp1
5435 and
5436 .Va exp2 .
5437 .Pp
5438 .It  MIN( Va exp1, Va exp2)
5439 Returns the minimum of
5440 .Va exp1
5441 and
5442 .Va exp2 .
5443 .Pp
5444 .It  NEXT( Va exp)
5445 Return the next unallocated address that is a multiple of
5446 .Va exp .
5447 This function is closely related to
5448 .Li ALIGN( Va exp) ;
5449 unless you use the
5450 .Li MEMORY
5451 command to define discontinuous memory for the output file, the two functions
5452 are equivalent.
5453 .Pp
5454 .It  ORIGIN( Va memory)
5455 Return the origin of the memory region named
5456 .Va memory .
5457 .Pp
5458 .It  SEGMENT_START( Va segment, Va default)
5459 Return the base address of the named
5460 .Va segment .
5461 If an explicit value has been given for this segment (with a command-line
5462 .Li -T
5463 option) that value will be returned; otherwise the value will be
5464 .Va default .
5465 At present, the
5466 .Li -T
5467 command-line option can only be used to set the base address for the \(lqtext\(rq,
5468 \(lqdata\(rq, and \(lqbss\(rq sections, but you use
5469 .Li SEGMENT_START
5470 with any segment name.
5471 .Pp
5472 .It  SIZEOF( Va section)
5473 Return the size in bytes of the named
5474 .Va section ,
5475 if that section has been allocated. If the section has not been allocated
5476 when this is evaluated, the linker will report an error. In the following
5477 example,
5478 .Li symbol_1
5479 and
5480 .Li symbol_2
5481 are assigned identical values:
5482 .Bd -literal -offset indent
5483
5484 SECTIONS{ ...
5485   .output {
5486     .start = . ;
5487     ...
5488     .end = . ;
5489     }
5490   symbol_1 = .end - .start ;
5491   symbol_2 = SIZEOF(.output);
5492 \&... }
5493
5494 .Ed
5495 .Pp
5496 .It  SIZEOF_HEADERS
5497 .It  sizeof_headers
5498 Return the size in bytes of the output file's headers. This is information
5499 which appears at the start of the output file. You can use this number when
5500 setting the start address of the first section, if you choose, to facilitate
5501 paging.
5502 .Pp
5503 When producing an ELF output file, if the linker script uses the
5504 .Li SIZEOF_HEADERS
5505 builtin function, the linker must compute the number of program headers before
5506 it has determined all the section addresses and sizes. If the linker later
5507 discovers that it needs additional program headers, it will report an error
5508 .Li not enough room for program headers .
5509 To avoid this error, you must avoid using the
5510 .Li SIZEOF_HEADERS
5511 function, or you must rework your linker script to avoid forcing the linker
5512 to use additional program headers, or you must define the program headers
5513 yourself using the
5514 .Li PHDRS
5515 command (see Section
5516 .Dq PHDRS ) .
5517 .El
5518 .Pp
5519 .Ss  Implicit Linker Scripts
5520 If you specify a linker input file which the linker can not recognize as an
5521 object file or an archive file, it will try to read the file as a linker script.
5522 If the file can not be parsed as a linker script, the linker will report an
5523 error.
5524 .Pp
5525 An implicit linker script will not replace the default linker script.
5526 .Pp
5527 Typically an implicit linker script would contain only symbol assignments,
5528 or the
5529 .Li INPUT ,
5530 .Li GROUP ,
5531 or
5532 .Li VERSION
5533 commands.
5534 .Pp
5535 Any input files read because of an implicit linker script will be read at
5536 the position in the command line where the implicit linker script was read.
5537 This can affect archive searching.
5538 .Pp
5539 .Sh  Machine Dependent Features
5540 .Xr ld
5541 has additional features on some platforms; the following sections describe
5542 them. Machines where
5543 .Xr ld
5544 has no additional functionality are not listed.
5545 .Pp
5546 .Ss  Xr ld and the H8/300
5547 For the H8/300,
5548 .Xr ld
5549 can perform these global optimizations when you specify the
5550 .Li --relax
5551 command-line option.
5552 .Pp
5553 .Bl -tag -width Ds
5554 .It  relaxing address modes
5555 .Xr ld
5556 finds all
5557 .Li jsr
5558 and
5559 .Li jmp
5560 instructions whose targets are within eight bits, and turns them into eight-bit
5561 program-counter relative
5562 .Li bsr
5563 and
5564 .Li bra
5565 instructions, respectively.
5566 .Pp
5567 .It  synthesizing instructions
5568 .Xr ld
5569 finds all
5570 .Li mov.b
5571 instructions which use the sixteen-bit absolute address form, but refer to
5572 the top page of memory, and changes them to use the eight-bit address form.
5573 (That is: the linker turns
5574 .Li mov.b Li @ Va aa:16
5575 into
5576 .Li mov.b Li @ Va aa:8
5577 whenever the address
5578 .Va aa
5579 is in the top page of memory).
5580 .Pp
5581 .It  bit manipulation instructions
5582 .Xr ld
5583 finds all bit manipulation instructions like
5584 .Li band, bclr, biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor
5585 which use 32 bit and 16 bit absolute address form, but refer to the top page
5586 of memory, and changes them to use the 8 bit address form. (That is: the linker
5587 turns
5588 .Li bset #xx:3, Li @ Va aa:32
5589 into
5590 .Li bset #xx:3, Li @ Va aa:8
5591 whenever the address
5592 .Va aa
5593 is in the top page of memory).
5594 .Pp
5595 .It  system control instructions
5596 .Xr ld
5597 finds all
5598 .Li ldc.w, stc.w
5599 instructions which use the 32 bit absolute address form, but refer to the
5600 top page of memory, and changes them to use 16 bit address form. (That is:
5601 the linker turns
5602 .Li ldc.w Li @ Va aa:32,ccr
5603 into
5604 .Li ldc.w Li @ Va aa:16,ccr
5605 whenever the address
5606 .Va aa
5607 is in the top page of memory).
5608 .El
5609 .Pp
5610 .Ss  Xr ld and the Intel 960 Family
5611 You can use the
5612 .Li -A Va architecture
5613 command line option to specify one of the two-letter names identifying members
5614 of the 960 family; the option specifies the desired output target, and warns
5615 of any incompatible instructions in the input files. It also modifies the
5616 linker's search strategy for archive libraries, to support the use of libraries
5617 specific to each particular architecture, by including in the search loop
5618 names suffixed with the string identifying the architecture.
5619 .Pp
5620 For example, if your
5621 .Xr ld
5622 command line included
5623 .Li -ACA
5624 as well as
5625 .Li -ltry
5626 , the linker would look (in its built-in search paths, and in any paths you
5627 specify with
5628 .Li -L )
5629 for a library with the names
5630 .Pp
5631 .Bd -literal -offset indent
5632
5633 try
5634 libtry.a
5635 tryca
5636 libtryca.a
5637
5638 .Ed
5639 .Pp
5640 The first two possibilities would be considered in any event; the last two
5641 are due to the use of
5642 .Li -ACA
5643 \&.
5644 .Pp
5645 You can meaningfully use
5646 .Li -A
5647 more than once on a command line, since the 960 architecture family allows
5648 combination of target architectures; each use will add another pair of name
5649 variants to search for when
5650 .Li -l
5651 specifies a library.
5652 .Pp
5653 .Xr ld
5654 supports the
5655 .Li --relax
5656 option for the i960 family. If you specify
5657 .Li --relax ,
5658 .Xr ld
5659 finds all
5660 .Li balx
5661 and
5662 .Li calx
5663 instructions whose targets are within 24 bits, and turns them into 24-bit
5664 program-counter relative
5665 .Li bal
5666 and
5667 .Li cal
5668 instructions, respectively.
5669 .Xr ld
5670 also turns
5671 .Li cal
5672 instructions into
5673 .Li bal
5674 instructions when it determines that the target subroutine is a leaf routine
5675 (that is, the target subroutine does not itself call any subroutines).
5676 .Pp
5677 .Ss  Xr ld and the Motorola 68HC11 and 68HC12 families
5678 .Em  Linker Relaxation
5679 .Pp
5680 For the Motorola 68HC11,
5681 .Xr ld
5682 can perform these global optimizations when you specify the
5683 .Li --relax
5684 command-line option.
5685 .Pp
5686 .Bl -tag -width Ds
5687 .It  relaxing address modes
5688 .Xr ld
5689 finds all
5690 .Li jsr
5691 and
5692 .Li jmp
5693 instructions whose targets are within eight bits, and turns them into eight-bit
5694 program-counter relative
5695 .Li bsr
5696 and
5697 .Li bra
5698 instructions, respectively.
5699 .Pp
5700 .Xr ld
5701 also looks at all 16-bit extended addressing modes and transforms them in
5702 a direct addressing mode when the address is in page 0 (between 0 and 0x0ff).
5703 .Pp
5704 .It  relaxing gcc instruction group
5705 When
5706 .Xr gcc
5707 is called with
5708 .Op -mrelax ,
5709 it can emit group of instructions that the linker can optimize to use a 68HC11
5710 direct addressing mode. These instructions consists of
5711 .Li bclr
5712 or
5713 .Li bset
5714 instructions.
5715 .Pp
5716 .El
5717 .Em  Trampoline Generation
5718 .Pp
5719 For 68HC11 and 68HC12,
5720 .Xr ld
5721 can generate trampoline code to call a far function using a normal
5722 .Li jsr
5723 instruction. The linker will also change the relocation to some far function
5724 to use the trampoline address instead of the function address. This is typically
5725 the case when a pointer to a function is taken. The pointer will in fact point
5726 to the function trampoline.
5727 .Pp
5728 The
5729 .Li --pic-veneer
5730 switch makes the linker use PIC sequences for ARM/Thumb interworking veneers,
5731 even if the rest of the binary is not PIC. This avoids problems on uClinux
5732 targets where
5733 .Li --emit-relocs
5734 is used to generate relocatable binaries.
5735 .Pp
5736 .Ss  Xr ld and the ARM family
5737 For the ARM,
5738 .Xr ld
5739 will generate code stubs to allow functions calls between ARM and Thumb code.
5740 These stubs only work with code that has been compiled and assembled with
5741 the
5742 .Li -mthumb-interwork
5743 command line option. If it is necessary to link with old ARM object files
5744 or libraries, which have not been compiled with the -mthumb-interwork option
5745 then the
5746 .Li --support-old-code
5747 command line switch should be given to the linker. This will make it generate
5748 larger stub functions which will work with non-interworking aware ARM code.
5749 Note, however, the linker does not support generating stubs for function calls
5750 to non-interworking aware Thumb code.
5751 .Pp
5752 The
5753 .Li --thumb-entry
5754 switch is a duplicate of the generic
5755 .Li --entry
5756 switch, in that it sets the program's starting address. But it also sets the
5757 bottom bit of the address, so that it can be branched to using a BX instruction,
5758 and the program will start executing in Thumb mode straight away.
5759 .Pp
5760 The
5761 .Li --be8
5762 switch instructs
5763 .Xr ld
5764 to generate BE8 format executables. This option is only valid when linking
5765 big-endian objects. The resulting image will contain big-endian data and little-endian
5766 code.
5767 .Pp
5768 The
5769 .Li R_ARM_TARGET1
5770 relocation is typically used for entries in the
5771 .Li .init_array
5772 section. It is interpreted as either
5773 .Li R_ARM_REL32
5774 or
5775 .Li R_ARM_ABS32 ,
5776 depending on the target. The
5777 .Li --target1-rel
5778 and
5779 .Li --target1-abs
5780 switches override the default.
5781 .Pp
5782 The
5783 .Li --target2=type
5784 switch overrides the default definition of the
5785 .Li R_ARM_TARGET2
5786 relocation. Valid values for
5787 .Li type ,
5788 their meanings, and target defaults are as follows:
5789 .Bl -tag -width Ds
5790 .It  rel
5791 .Li R_ARM_REL32
5792 (arm*-*-elf, arm*-*-eabi)
5793 .It  abs
5794 .Li R_ARM_ABS32
5795 (arm*-*-symbianelf)
5796 .It  got-rel
5797 .Li R_ARM_GOT_PREL
5798 (arm*-*-linux, arm*-*-*bsd)
5799 .El
5800 .Pp
5801 The
5802 .Li R_ARM_V4BX
5803 relocation (defined by the ARM AAELF specification) enables objects compiled
5804 for the ARMv4 architecture to be interworking-safe when linked with other
5805 objects compiled for ARMv4t, but also allows pure ARMv4 binaries to be built
5806 from the same ARMv4 objects.
5807 .Pp
5808 In the latter case, the switch
5809 .Op --fix-v4bx
5810 must be passed to the linker, which causes v4t
5811 .Li BX rM
5812 instructions to be rewritten as
5813 .Li MOV PC,rM ,
5814 since v4 processors do not have a
5815 .Li BX
5816 instruction.
5817 .Pp
5818 In the former case, the switch should not be used, and
5819 .Li R_ARM_V4BX
5820 relocations are ignored.
5821 .Pp
5822 The
5823 .Li --use-blx
5824 switch enables the linker to use ARM/Thumb BLX instructions (available on
5825 ARMv5t and above) in various situations. Currently it is used to perform calls
5826 via the PLT from Thumb code using BLX rather than using BX and a mode-switching
5827 stub before each PLT entry. This should lead to such calls executing slightly
5828 faster.
5829 .Pp
5830 This option is enabled implicitly for SymbianOS, so there is no need to specify
5831 it if you are using that target.
5832 .Pp
5833 The
5834 .Li --vfp11-denorm-fix
5835 switch enables a link-time workaround for a bug in certain VFP11 coprocessor
5836 hardware, which sometimes allows instructions with denorm operands (which
5837 must be handled by support code) to have those operands overwritten by subsequent
5838 instructions before the support code can read the intended values.
5839 .Pp
5840 The bug may be avoided in scalar mode if you allow at least one intervening
5841 instruction between a VFP11 instruction which uses a register and another
5842 instruction which writes to the same register, or at least two intervening
5843 instructions if vector mode is in use. The bug only affects full-compliance
5844 floating-point mode: you do not need this workaround if you are using "runfast"
5845 mode. Please contact ARM for further details.
5846 .Pp
5847 If you know you are using buggy VFP11 hardware, you can enable this workaround
5848 by specifying the linker option
5849 .Li --vfp-denorm-fix=scalar
5850 if you are using the VFP11 scalar mode only, or
5851 .Li --vfp-denorm-fix=vector
5852 if you are using vector mode (the latter also works for scalar code). The
5853 default is
5854 .Li --vfp-denorm-fix=none .
5855 .Pp
5856 If the workaround is enabled, instructions are scanned for potentially-troublesome
5857 sequences, and a veneer is created for each such sequence which may trigger
5858 the erratum. The veneer consists of the first instruction of the sequence
5859 and a branch back to the subsequent instruction. The original instruction
5860 is then replaced with a branch to the veneer. The extra cycles required to
5861 call and return from the veneer are sufficient to avoid the erratum in both
5862 the scalar and vector cases.
5863 .Pp
5864 The
5865 .Li --no-enum-size-warning
5866 switch prevents the linker from warning when linking object files that specify
5867 incompatible EABI enumeration size attributes. For example, with this switch
5868 enabled, linking of an object file using 32-bit enumeration values with another
5869 using enumeration values fitted into the smallest possible space will not
5870 be diagnosed.
5871 .Pp
5872 .Ss  Xr ld and HPPA 32-bit ELF Support
5873 When generating a shared library,
5874 .Xr ld
5875 will by default generate import stubs suitable for use with a single sub-space
5876 application. The
5877 .Li --multi-subspace
5878 switch causes
5879 .Xr ld
5880 to generate export stubs, and different (larger) import stubs suitable for
5881 use with multiple sub-spaces.
5882 .Pp
5883 Long branch stubs and import/export stubs are placed by
5884 .Xr ld
5885 in stub sections located between groups of input sections.
5886 .Li --stub-group-size
5887 specifies the maximum size of a group of input sections handled by one stub
5888 section. Since branch offsets are signed, a stub section may serve two groups
5889 of input sections, one group before the stub section, and one group after
5890 it. However, when using conditional branches that require stubs, it may be
5891 better (for branch prediction) that stub sections only serve one group of
5892 input sections. A negative value for
5893 .Li N
5894 chooses this scheme, ensuring that branches to stubs always use a negative
5895 offset. Two special values of
5896 .Li N
5897 are recognized,
5898 .Li 1
5899 and
5900 .Li -1 .
5901 These both instruct
5902 .Xr ld
5903 to automatically size input section groups for the branch types detected,
5904 with the same behaviour regarding stub placement as other positive or negative
5905 values of
5906 .Li N
5907 respectively.
5908 .Pp
5909 Note that
5910 .Li --stub-group-size
5911 does not split input sections. A single input section larger than the group
5912 size specified will of course create a larger group (of one section). If input
5913 sections are too large, it may not be possible for a branch to reach its stub.
5914 .Pp
5915 .Ss  Li ld and MMIX
5916 For MMIX, there is a choice of generating
5917 .Li ELF
5918 object files or
5919 .Li mmo
5920 object files when linking. The simulator
5921 .Li mmix
5922 understands the
5923 .Li mmo
5924 format. The binutils
5925 .Li objcopy
5926 utility can translate between the two formats.
5927 .Pp
5928 There is one special section, the
5929 .Li .MMIX.reg_contents
5930 section. Contents in this section is assumed to correspond to that of global
5931 registers, and symbols referring to it are translated to special symbols,
5932 equal to registers. In a final link, the start address of the
5933 .Li .MMIX.reg_contents
5934 section corresponds to the first allocated global register multiplied by 8.
5935 Register
5936 .Li $255
5937 is not included in this section; it is always set to the program entry, which
5938 is at the symbol
5939 .Li Main
5940 for
5941 .Li mmo
5942 files.
5943 .Pp
5944 Symbols with the prefix
5945 .Li __.MMIX.start. ,
5946 for example
5947 .Li __.MMIX.start..text
5948 and
5949 .Li __.MMIX.start..data
5950 are special; there must be only one each, even if they are local. The default
5951 linker script uses these to set the default start address of a section.
5952 .Pp
5953 Initial and trailing multiples of zero-valued 32-bit words in a section, are
5954 left out from an mmo file.
5955 .Pp
5956 .Ss  Li ld and MSP430
5957 For the MSP430 it is possible to select the MPU architecture. The flag
5958 .Li -m [mpu type]
5959 will select an appropriate linker script for selected MPU type. (To get a
5960 list of known MPUs just pass
5961 .Li -m help
5962 option to the linker).
5963 .Pp
5964 The linker will recognize some extra sections which are MSP430 specific:
5965 .Pp
5966 .Bl -tag -width Ds
5967 .It  Li .vectors
5968 Defines a portion of ROM where interrupt vectors located.
5969 .Pp
5970 .It  Li .bootloader
5971 Defines the bootloader portion of the ROM (if applicable). Any code in this
5972 section will be uploaded to the MPU.
5973 .Pp
5974 .It  Li .infomem
5975 Defines an information memory section (if applicable). Any code in this section
5976 will be uploaded to the MPU.
5977 .Pp
5978 .It  Li .infomemnobits 
5979 This is the same as the
5980 .Li .infomem
5981 section except that any code in this section will not be uploaded to the MPU.
5982 .Pp
5983 .It  Li .noinit
5984 Denotes a portion of RAM located above
5985 .Li .bss
5986 section.
5987 .Pp
5988 The last two sections are used by gcc.
5989 .El
5990 .Pp
5991 .Ss  Xr ld and PowerPC 32-bit ELF Support
5992 Branches on PowerPC processors are limited to a signed 26-bit displacement,
5993 which may result in
5994 .Xr ld
5995 giving
5996 .Li relocation truncated to fit
5997 errors with very large programs.
5998 .Li --relax
5999 enables the generation of trampolines that can access the entire 32-bit address
6000 space. These trampolines are inserted at section boundaries, so may not themselves
6001 be reachable if an input section exceeds 33M in size.
6002 .Pp
6003 .Bl -tag -width Ds
6004 .It  --bss-plt
6005 Current PowerPC GCC accepts a
6006 .Li -msecure-plt
6007 option that generates code capable of using a newer PLT and GOT layout that
6008 has the security advantage of no executable section ever needing to be writable
6009 and no writable section ever being executable. PowerPC
6010 .Xr ld
6011 will generate this layout, including stubs to access the PLT, if all input
6012 files (including startup and static libraries) were compiled with
6013 .Li -msecure-plt .
6014 .Li --bss-plt
6015 forces the old BSS PLT (and GOT layout) which can give slightly better performance.
6016 .Pp
6017 .It  --secure-plt
6018 .Xr ld
6019 will use the new PLT and GOT layout if it is linking new
6020 .Li -fpic
6021 or
6022 .Li -fPIC
6023 code, but does not do so automatically when linking non-PIC code. This option
6024 requests the new PLT and GOT layout. A warning will be given if some object
6025 file requires the old style BSS PLT.
6026 .Pp
6027 .It  --sdata-got
6028 The new secure PLT and GOT are placed differently relative to other sections
6029 compared to older BSS PLT and GOT placement. The location of
6030 .Li .plt
6031 must change because the new secure PLT is an initialized section while the
6032 old PLT is uninitialized. The reason for the
6033 .Li .got
6034 change is more subtle: The new placement allows
6035 .Li .got
6036 to be read-only in applications linked with
6037 .Li -z relro -z now .
6038 However, this placement means that
6039 .Li .sdata
6040 cannot always be used in shared libraries, because the PowerPC ABI accesses
6041 .Li .sdata
6042 in shared libraries from the GOT pointer.
6043 .Li --sdata-got
6044 forces the old GOT placement. PowerPC GCC doesn't use
6045 .Li .sdata
6046 in shared libraries, so this option is really only useful for other compilers
6047 that may do so.
6048 .Pp
6049 .It  --emit-stub-syms
6050 This option causes
6051 .Xr ld
6052 to label linker stubs with a local symbol that encodes the stub type and destination.
6053 .Pp
6054 .It  --no-tls-optimize
6055 PowerPC
6056 .Xr ld
6057 normally performs some optimization of code sequences used to access Thread-Local
6058 Storage. Use this option to disable the optimization.
6059 .El
6060 .Pp
6061 .Ss  Xr ld and PowerPC64 64-bit ELF Support
6062 .Bl -tag -width Ds
6063 .It  --stub-group-size
6064 Long branch stubs, PLT call stubs and TOC adjusting stubs are placed by
6065 .Xr ld
6066 in stub sections located between groups of input sections.
6067 .Li --stub-group-size
6068 specifies the maximum size of a group of input sections handled by one stub
6069 section. Since branch offsets are signed, a stub section may serve two groups
6070 of input sections, one group before the stub section, and one group after
6071 it. However, when using conditional branches that require stubs, it may be
6072 better (for branch prediction) that stub sections only serve one group of
6073 input sections. A negative value for
6074 .Li N
6075 chooses this scheme, ensuring that branches to stubs always use a negative
6076 offset. Two special values of
6077 .Li N
6078 are recognized,
6079 .Li 1
6080 and
6081 .Li -1 .
6082 These both instruct
6083 .Xr ld
6084 to automatically size input section groups for the branch types detected,
6085 with the same behaviour regarding stub placement as other positive or negative
6086 values of
6087 .Li N
6088 respectively.
6089 .Pp
6090 Note that
6091 .Li --stub-group-size
6092 does not split input sections. A single input section larger than the group
6093 size specified will of course create a larger group (of one section). If input
6094 sections are too large, it may not be possible for a branch to reach its stub.
6095 .Pp
6096 .It  --emit-stub-syms
6097 This option causes
6098 .Xr ld
6099 to label linker stubs with a local symbol that encodes the stub type and destination.
6100 .Pp
6101 .It  --dotsyms, --no-dotsyms
6102 These two options control how
6103 .Xr ld
6104 interprets version patterns in a version script. Older PowerPC64 compilers
6105 emitted both a function descriptor symbol with the same name as the function,
6106 and a code entry symbol with the name prefixed by a dot (
6107 .Li . ) .
6108 To properly version a function
6109 .Li foo ,
6110 the version script thus needs to control both
6111 .Li foo
6112 and
6113 .Li .foo .
6114 The option
6115 .Li --dotsyms ,
6116 on by default, automatically adds the required dot-prefixed patterns. Use
6117 .Li --no-dotsyms
6118 to disable this feature.
6119 .Pp
6120 .It  --no-tls-optimize
6121 PowerPC64
6122 .Xr ld
6123 normally performs some optimization of code sequences used to access Thread-Local
6124 Storage. Use this option to disable the optimization.
6125 .Pp
6126 .It  --no-opd-optimize
6127 PowerPC64
6128 .Xr ld
6129 normally removes
6130 .Li .opd
6131 section entries corresponding to deleted link-once functions, or functions
6132 removed by the action of
6133 .Li --gc-sections
6134 or linker scrip
6135 .Li /DISCARD/ .
6136 Use this option to disable
6137 .Li .opd
6138 optimization.
6139 .Pp
6140 .It  --non-overlapping-opd
6141 Some PowerPC64 compilers have an option to generate compressed
6142 .Li .opd
6143 entries spaced 16 bytes apart, overlapping the third word, the static chain
6144 pointer (unused in C) with the first word of the next entry. This option expands
6145 such entries to the full 24 bytes.
6146 .Pp
6147 .It  --no-toc-optimize
6148 PowerPC64
6149 .Xr ld
6150 normally removes unused
6151 .Li .toc
6152 section entries. Such entries are detected by examining relocations that reference
6153 the TOC in code sections. A reloc in a deleted code section marks a TOC word
6154 as unneeded, while a reloc in a kept code section marks a TOC word as needed.
6155 Since the TOC may reference itself, TOC relocs are also examined. TOC words
6156 marked as both needed and unneeded will of course be kept. TOC words without
6157 any referencing reloc are assumed to be part of a multi-word entry, and are
6158 kept or discarded as per the nearest marked preceding word. This works reliably
6159 for compiler generated code, but may be incorrect if assembly code is used
6160 to insert TOC entries. Use this option to disable the optimization.
6161 .Pp
6162 .It  --no-multi-toc
6163 By default, PowerPC64 GCC generates code for a TOC model where TOC entries
6164 are accessed with a 16-bit offset from r2. This limits the total TOC size
6165 to 64K. PowerPC64
6166 .Xr ld
6167 extends this limit by grouping code sections such that each group uses less
6168 than 64K for its TOC entries, then inserts r2 adjusting stubs between inter-group
6169 calls.
6170 .Xr ld
6171 does not split apart input sections, so cannot help if a single input file
6172 has a
6173 .Li .toc
6174 section that exceeds 64K, most likely from linking multiple files with
6175 .Xr ld -r .
6176 Use this option to turn off this feature.
6177 .El
6178 .Pp
6179 .Ss  Xr ld and SPU ELF Support
6180 .Bl -tag -width Ds
6181 .It  --plugin
6182 This option marks an executable as a PIC plugin module.
6183 .Pp
6184 .It  --no-overlays
6185 Normally,
6186 .Xr ld
6187 recognizes calls to functions within overlay regions, and redirects such calls
6188 to an overlay manager via a stub.
6189 .Xr ld
6190 also provides a built-in overlay manager. This option turns off all this special
6191 overlay handling.
6192 .Pp
6193 .It  --emit-stub-syms
6194 This option causes
6195 .Xr ld
6196 to label overlay stubs with a local symbol that encodes the stub type and
6197 destination.
6198 .Pp
6199 .It  --extra-overlay-stubs
6200 This option causes
6201 .Xr ld
6202 to add overlay call stubs on all function calls out of overlay regions. Normally
6203 stubs are not added on calls to non-overlay regions.
6204 .Pp
6205 .It  --local-store=lo:hi
6206 .Xr ld
6207 usually checks that a final executable for SPU fits in the address range 0
6208 to 256k. This option may be used to change the range. Disable the check entirely
6209 with
6210 .Op --local-store=0:0 .
6211 .Pp
6212 .It  --stack-analysis
6213 SPU local store space is limited. Over-allocation of stack space unnecessarily
6214 limits space available for code and data, while under-allocation results in
6215 runtime failures. If given this option,
6216 .Xr ld
6217 will provide an estimate of maximum stack usage.
6218 .Xr ld
6219 does this by examining symbols in code sections to determine the extents of
6220 functions, and looking at function prologues for stack adjusting instructions.
6221 A call-graph is created by looking for relocations on branch instructions.
6222 The graph is then searched for the maximum stack usage path. Note that this
6223 analysis does not find calls made via function pointers, and does not handle
6224 recursion and other cycles in the call graph. Stack usage may be under-estimated
6225 if your code makes such calls. Also, stack usage for dynamic allocation, e.g.
6226 alloca, will not be detected. If a link map is requested, detailed information
6227 about each function's stack usage and calls will be given.
6228 .Pp
6229 .It  --emit-stack-syms
6230 This option, if given along with
6231 .Op --stack-analysis
6232 will result in
6233 .Xr ld
6234 emitting stack sizing symbols for each function. These take the form
6235 .Li __stack_<function_name>
6236 for global functions, and
6237 .Li __stack_<number>_<function_name>
6238 for static functions.
6239 .Li <number>
6240 is the section id in hex. The value of such symbols is the stack requirement
6241 for the corresponding function. The symbol size will be zero, type
6242 .Li STT_NOTYPE ,
6243 binding
6244 .Li STB_LOCAL ,
6245 and section
6246 .Li SHN_ABS .
6247 .El
6248 .Pp
6249 .Ss  Xr ld's Support for Various TI COFF Versions
6250 The
6251 .Li --format
6252 switch allows selection of one of the various TI COFF versions. The latest
6253 of this writing is 2; versions 0 and 1 are also supported. The TI COFF versions
6254 also vary in header byte-order format;
6255 .Xr ld
6256 will read any version or byte order, but the output header format depends
6257 on the default specified by the specific target.
6258 .Pp
6259 .Ss  Xr ld and WIN32 (cygwin/mingw)
6260 This section describes some of the win32 specific
6261 .Xr ld
6262 issues. See Options,,Command Line Options for detailed description of the
6263 command line options mentioned here.
6264 .Pp
6265 .Bl -tag -width Ds
6266 .It  import libraries 
6267 The standard Windows linker creates and uses so-called import libraries, which
6268 contains information for linking to dll's. They are regular static archives
6269 and are handled as any other static archive. The cygwin and mingw ports of
6270 .Xr ld
6271 have specific support for creating such libraries provided with the
6272 .Li --out-implib
6273 command line option.
6274 .Pp
6275 .It  exporting DLL symbols 
6276 The cygwin/mingw
6277 .Xr ld
6278 has several ways to export symbols for dll's.
6279 .Pp
6280 .Bl -tag -width Ds
6281 .It  using auto-export functionality
6282 By default
6283 .Xr ld
6284 exports symbols with the auto-export functionality, which is controlled by
6285 the following command line options:
6286 .Pp
6287 .Bl -bullet
6288 .It
6289 --export-all-symbols [This is the default]
6290 .It
6291 --exclude-symbols
6292 .It
6293 --exclude-libs
6294 .El
6295 .Pp
6296 If, however,
6297 .Li --export-all-symbols
6298 is not given explicitly on the command line, then the default auto-export
6299 behavior will be
6300 .Em disabled
6301 if either of the following are true:
6302 .Pp
6303 .Bl -bullet
6304 .It
6305 A DEF file is used.
6306 .It
6307 Any symbol in any object file was marked with the __declspec(dllexport) attribute.
6308 .El
6309 .Pp
6310 .It  using a DEF file 
6311 Another way of exporting symbols is using a DEF file. A DEF file is an ASCII
6312 file containing definitions of symbols which should be exported when a dll
6313 is created. Usually it is named
6314 .Li <dll name>.def
6315 and is added as any other object file to the linker's command line. The file's
6316 name must end in
6317 .Li .def
6318 or
6319 .Li .DEF .
6320 .Pp
6321 .Bd -literal -offset indent
6322 gcc -o <output> <objectfiles> <dll name>.def
6323 .Ed
6324 .Pp
6325 Using a DEF file turns off the normal auto-export behavior, unless the
6326 .Li --export-all-symbols
6327 option is also used.
6328 .Pp
6329 Here is an example of a DEF file for a shared library called
6330 .Li xyz.dll :
6331 .Pp
6332 .Bd -literal -offset indent
6333 LIBRARY "xyz.dll" BASE=0x20000000
6334
6335 EXPORTS
6336 foo
6337 bar
6338 _bar = bar
6339 another_foo = abc.dll.afoo
6340 var1 DATA
6341 .Ed
6342 .Pp
6343 This example defines a DLL with a non-default base address and five symbols
6344 in the export table. The third exported symbol
6345 .Li _bar
6346 is an alias for the second. The fourth symbol,
6347 .Li another_foo
6348 is resolved by "forwarding" to another module and treating it as an alias
6349 for
6350 .Li afoo
6351 exported from the DLL
6352 .Li abc.dll .
6353 The final symbol
6354 .Li var1
6355 is declared to be a data object.
6356 .Pp
6357 The optional
6358 .Li LIBRARY <name>
6359 command indicates the
6360 .Em internal
6361 name of the output DLL. If
6362 .Li <name>
6363 does not include a suffix, the default library suffix,
6364 .Li .DLL
6365 is appended.
6366 .Pp
6367 When the .DEF file is used to build an application, rather than a library,
6368 the
6369 .Li NAME <name>
6370 command should be used instead of
6371 .Li LIBRARY .
6372 If
6373 .Li <name>
6374 does not include a suffix, the default executable suffix,
6375 .Li .EXE
6376 is appended.
6377 .Pp
6378 With either
6379 .Li LIBRARY <name>
6380 or
6381 .Li NAME <name>
6382 the optional specification
6383 .Li BASE = <number>
6384 may be used to specify a non-default base address for the image.
6385 .Pp
6386 If neither
6387 .Li LIBRARY <name>
6388 nor
6389 .Li NAME <name>
6390 is specified, or they specify an empty string, the internal name is the same
6391 as the filename specified on the command line.
6392 .Pp
6393 The complete specification of an export symbol is:
6394 .Pp
6395 .Bd -literal -offset indent
6396 EXPORTS
6397   ( (  ( <name1> [ = <name2> ] )
6398      | ( <name1> = <module-name> . <external-name>))
6399   [ @ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] ) *
6400 .Ed
6401 .Pp
6402 Declares
6403 .Li <name1>
6404 as an exported symbol from the DLL, or declares
6405 .Li <name1>
6406 as an exported alias for
6407 .Li <name2> ;
6408 or declares
6409 .Li <name1>
6410 as a "forward" alias for the symbol
6411 .Li <external-name>
6412 in the DLL
6413 .Li <module-name> .
6414 Optionally, the symbol may be exported by the specified ordinal
6415 .Li <integer>
6416 alias.
6417 .Pp
6418 The optional keywords that follow the declaration indicate:
6419 .Pp
6420 .Li NONAME :
6421 Do not put the symbol name in the DLL's export table. It will still be exported
6422 by its ordinal alias (either the value specified by the .def specification
6423 or, otherwise, the value assigned by the linker). The symbol name, however,
6424 does remain visible in the import library (if any), unless
6425 .Li PRIVATE
6426 is also specified.
6427 .Pp
6428 .Li DATA :
6429 The symbol is a variable or object, rather than a function. The import lib
6430 will export only an indirect reference to
6431 .Li foo
6432 as the symbol
6433 .Li _imp__foo
6434 (ie,
6435 .Li foo
6436 must be resolved as
6437 .Li *_imp__foo ) .
6438 .Pp
6439 .Li CONSTANT :
6440 Like
6441 .Li DATA ,
6442 but put the undecorated
6443 .Li foo
6444 as well as
6445 .Li _imp__foo
6446 into the import library. Both refer to the read-only import address table's
6447 pointer to the variable, not to the variable itself. This can be dangerous.
6448 If the user code fails to add the
6449 .Li dllimport
6450 attribute and also fails to explicitly add the extra indirection that the
6451 use of the attribute enforces, the application will behave unexpectedly.
6452 .Pp
6453 .Li PRIVATE :
6454 Put the symbol in the DLL's export table, but do not put it into the static
6455 import library used to resolve imports at link time. The symbol can still
6456 be imported using the
6457 .Li LoadLibrary/GetProcAddress
6458 API at runtime or by by using the GNU ld extension of linking directly to
6459 the DLL without an import library. See ld/deffilep.y in the binutils sources
6460 for the full specification of other DEF file statements
6461 .Pp
6462 While linking a shared dll,
6463 .Xr ld
6464 is able to create a DEF file with the
6465 .Li --output-def <file>
6466 command line option.
6467 .Pp
6468 .It  Using decorations
6469 Another way of marking symbols for export is to modify the source code itself,
6470 so that when building the DLL each symbol to be exported is declared as:
6471 .Pp
6472 .Bd -literal -offset indent
6473 __declspec(dllexport) int a_variable
6474 __declspec(dllexport) void a_function(int with_args)
6475 .Ed
6476 .Pp
6477 All such symbols will be exported from the DLL. If, however, any of the object
6478 files in the DLL contain symbols decorated in this way, then the normal auto-export
6479 behavior is disabled, unless the
6480 .Li --export-all-symbols
6481 option is also used.
6482 .Pp
6483 Note that object files that wish to access these symbols must
6484 .Em not
6485 decorate them with dllexport. Instead, they should use dllimport, instead:
6486 .Pp
6487 .Bd -literal -offset indent
6488 __declspec(dllimport) int a_variable
6489 __declspec(dllimport) void a_function(int with_args)
6490 .Ed
6491 .Pp
6492 This complicates the structure of library header files, because when included
6493 by the library itself the header must declare the variables and functions
6494 as dllexport, but when included by client code the header must declare them
6495 as dllimport. There are a number of idioms that are typically used to do this;
6496 often client code can omit the __declspec() declaration completely. See
6497 .Li --enable-auto-import
6498 and
6499 .Li automatic data imports
6500 for more information.
6501 .El
6502 .Pp
6503 .It  automatic data imports
6504 The standard Windows dll format supports data imports from dlls only by adding
6505 special decorations (dllimport/dllexport), which let the compiler produce
6506 specific assembler instructions to deal with this issue. This increases the
6507 effort necessary to port existing Un*x code to these platforms, especially
6508 for large c++ libraries and applications. The auto-import feature, which was
6509 initially provided by Paul Sokolovsky, allows one to omit the decorations
6510 to achieve a behavior that conforms to that on POSIX/Un*x platforms. This
6511 feature is enabled with the
6512 .Li --enable-auto-import
6513 command-line option, although it is enabled by default on cygwin/mingw. The
6514 .Li --enable-auto-import
6515 option itself now serves mainly to suppress any warnings that are ordinarily
6516 emitted when linked objects trigger the feature's use.
6517 .Pp
6518 auto-import of variables does not always work flawlessly without additional
6519 assistance. Sometimes, you will see this message
6520 .Pp
6521 "variable '<var>' can't be auto-imported. Please read the documentation for
6522 ld's
6523 .Li --enable-auto-import
6524 for details."
6525 .Pp
6526 The
6527 .Li --enable-auto-import
6528 documentation explains why this error occurs, and several methods that can
6529 be used to overcome this difficulty. One of these methods is the
6530 .Em runtime pseudo-relocs
6531 feature, described below.
6532 .Pp
6533 For complex variables imported from DLLs (such as structs or classes), object
6534 files typically contain a base address for the variable and an offset (
6535 .Em addend )
6536 within the variable--to specify a particular field or public member, for instance.
6537 Unfortunately, the runtime loader used in win32 environments is incapable
6538 of fixing these references at runtime without the additional information supplied
6539 by dllimport/dllexport decorations. The standard auto-import feature described
6540 above is unable to resolve these references.
6541 .Pp
6542 The
6543 .Li --enable-runtime-pseudo-relocs
6544 switch allows these references to be resolved without error, while leaving
6545 the task of adjusting the references themselves (with their non-zero addends)
6546 to specialized code provided by the runtime environment. Recent versions of
6547 the cygwin and mingw environments and compilers provide this runtime support;
6548 older versions do not. However, the support is only necessary on the developer's
6549 platform; the compiled result will run without error on an older system.
6550 .Pp
6551 .Li --enable-runtime-pseudo-relocs
6552 is not the default; it must be explicitly enabled as needed.
6553 .Pp
6554 .It  direct linking to a dll
6555 The cygwin/mingw ports of
6556 .Xr ld
6557 support the direct linking, including data symbols, to a dll without the usage
6558 of any import libraries. This is much faster and uses much less memory than
6559 does the traditional import library method, especially when linking large
6560 libraries or applications. When
6561 .Xr ld
6562 creates an import lib, each function or variable exported from the dll is
6563 stored in its own bfd, even though a single bfd could contain many exports.
6564 The overhead involved in storing, loading, and processing so many bfd's is
6565 quite large, and explains the tremendous time, memory, and storage needed
6566 to link against particularly large or complex libraries when using import
6567 libs.
6568 .Pp
6569 Linking directly to a dll uses no extra command-line switches other than
6570 .Li -L
6571 and
6572 .Li -l ,
6573 because
6574 .Xr ld
6575 already searches for a number of names to match each library. All that is
6576 needed from the developer's perspective is an understanding of this search,
6577 in order to force ld to select the dll instead of an import library.
6578 .Pp
6579 For instance, when ld is called with the argument
6580 .Li -lxxx
6581 it will attempt to find, in the first directory of its search path,
6582 .Pp
6583 .Bd -literal -offset indent
6584 libxxx.dll.a
6585 xxx.dll.a
6586 libxxx.a
6587 xxx.lib
6588 cygxxx.dll (*)
6589 libxxx.dll
6590 xxx.dll
6591 .Ed
6592 .Pp
6593 before moving on to the next directory in the search path.
6594 .Pp
6595 (*) Actually, this is not
6596 .Li cygxxx.dll
6597 but in fact is
6598 .Li <prefix>xxx.dll ,
6599 where
6600 .Li <prefix>
6601 is set by the
6602 .Xr ld
6603 option
6604 .Li --dll-search-prefix=<prefix> .
6605 In the case of cygwin, the standard gcc spec file includes
6606 .Li --dll-search-prefix=cyg ,
6607 so in effect we actually search for
6608 .Li cygxxx.dll .
6609 .Pp
6610 Other win32-based unix environments, such as mingw or pw32, may use other
6611 .Li <prefix>
6612 es, although at present only cygwin makes use of this feature. It was originally
6613 intended to help avoid name conflicts among dll's built for the various win32/un*x
6614 environments, so that (for example) two versions of a zlib dll could coexist
6615 on the same machine.
6616 .Pp
6617 The generic cygwin/mingw path layout uses a
6618 .Li bin
6619 directory for applications and dll's and a
6620 .Li lib
6621 directory for the import libraries (using cygwin nomenclature):
6622 .Pp
6623 .Bd -literal -offset indent
6624 bin/
6625         cygxxx.dll
6626 lib/
6627         libxxx.dll.a   (in case of dll's)
6628         libxxx.a       (in case of static archive) 
6629 .Ed
6630 .Pp
6631 Linking directly to a dll without using the import library can be done two
6632 ways:
6633 .Pp
6634 1. Use the dll directly by adding the
6635 .Li bin
6636 path to the link line
6637 .Bd -literal -offset indent
6638 gcc -Wl,-verbose  -o a.exe -L../bin/ -lxxx
6639 .Ed
6640 .Pp
6641 However, as the dll's often have version numbers appended to their names (
6642 .Li cygncurses-5.dll )
6643 this will often fail, unless one specifies
6644 .Li -L../bin -lncurses-5
6645 to include the version. Import libs are generally not versioned, and do not
6646 have this difficulty.
6647 .Pp
6648 2. Create a symbolic link from the dll to a file in the
6649 .Li lib
6650 directory according to the above mentioned search pattern. This should be
6651 used to avoid unwanted changes in the tools needed for making the app/dll.
6652 .Pp
6653 .Bd -literal -offset indent
6654 ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
6655 .Ed
6656 .Pp
6657 Then you can link without any make environment changes.
6658 .Pp
6659 .Bd -literal -offset indent
6660 gcc -Wl,-verbose  -o a.exe -L../lib/ -lxxx
6661 .Ed
6662 .Pp
6663 This technique also avoids the version number problems, because the following
6664 is perfectly legal
6665 .Pp
6666 .Bd -literal -offset indent
6667 bin/
6668         cygxxx-5.dll
6669 lib/
6670         libxxx.dll.a -> ../bin/cygxxx-5.dll 
6671 .Ed
6672 .Pp
6673 Linking directly to a dll without using an import lib will work even when
6674 auto-import features are exercised, and even when
6675 .Li --enable-runtime-pseudo-relocs
6676 is used.
6677 .Pp
6678 Given the improvements in speed and memory usage, one might justifiably wonder
6679 why import libraries are used at all. There are three reasons:
6680 .Pp
6681 1. Until recently, the link-directly-to-dll functionality did
6682 .Em not
6683 work with auto-imported data.
6684 .Pp
6685 2. Sometimes it is necessary to include pure static objects within the import
6686 library (which otherwise contains only bfd's for indirection symbols that
6687 point to the exports of a dll). Again, the import lib for the cygwin kernel
6688 makes use of this ability, and it is not possible to do this without an import
6689 lib.
6690 .Pp
6691 3. Symbol aliases can only be resolved using an import lib. This is critical
6692 when linking against OS-supplied dll's (eg, the win32 API) in which symbols
6693 are usually exported as undecorated aliases of their stdcall-decorated assembly
6694 names.
6695 .Pp
6696 So, import libs are not going away. But the ability to replace true import
6697 libs with a simple symbolic link to (or a copy of) a dll, in many cases, is
6698 a useful addition to the suite of tools binutils makes available to the win32
6699 developer. Given the massive improvements in memory requirements during linking,
6700 storage requirements, and linking speed, we expect that many developers will
6701 soon begin to use this feature whenever possible.
6702 .Pp
6703 .It  symbol aliasing 
6704 .Bl -tag -width Ds
6705 .It  adding additional names 
6706 Sometimes, it is useful to export symbols with additional names. A symbol
6707 .Li foo
6708 will be exported as
6709 .Li foo ,
6710 but it can also be exported as
6711 .Li _foo
6712 by using special directives in the DEF file when creating the dll. This will
6713 affect also the optional created import library. Consider the following DEF
6714 file:
6715 .Pp
6716 .Bd -literal -offset indent
6717 LIBRARY "xyz.dll" BASE=0x61000000
6718
6719 EXPORTS
6720 foo 
6721 _foo = foo
6722 .Ed
6723 .Pp
6724 The line
6725 .Li _foo = foo
6726 maps the symbol
6727 .Li foo
6728 to
6729 .Li _foo .
6730 .Pp
6731 Another method for creating a symbol alias is to create it in the source code
6732 using the "weak" attribute:
6733 .Pp
6734 .Bd -literal -offset indent
6735 void foo () { /* Do something.  */; } 
6736 void _foo () __attribute__ ((weak, alias ("foo")));
6737 .Ed
6738 .Pp
6739 See the gcc manual for more information about attributes and weak symbols.
6740 .Pp
6741 .It  renaming symbols
6742 Sometimes it is useful to rename exports. For instance, the cygwin kernel
6743 does this regularly. A symbol
6744 .Li _foo
6745 can be exported as
6746 .Li foo
6747 but not as
6748 .Li _foo
6749 by using special directives in the DEF file. (This will also affect the import
6750 library, if it is created). In the following example:
6751 .Pp
6752 .Bd -literal -offset indent
6753 LIBRARY "xyz.dll" BASE=0x61000000
6754
6755 EXPORTS
6756 _foo = foo
6757 .Ed
6758 .Pp
6759 The line
6760 .Li _foo = foo
6761 maps the exported symbol
6762 .Li foo
6763 to
6764 .Li _foo .
6765 .El
6766 .Pp
6767 Note: using a DEF file disables the default auto-export behavior, unless the
6768 .Li --export-all-symbols
6769 command line option is used. If, however, you are trying to rename symbols,
6770 then you should list
6771 .Em all
6772 desired exports in the DEF file, including the symbols that are not being
6773 renamed, and do
6774 .Em not
6775 use the
6776 .Li --export-all-symbols
6777 option. If you list only the renamed symbols in the DEF file, and use
6778 .Li --export-all-symbols
6779 to handle the other symbols, then the both the new names
6780 .Em and
6781 the original names for the renamed symbols will be exported. In effect, you'd
6782 be aliasing those symbols, not renaming them, which is probably not what you
6783 wanted.
6784 .Pp
6785 .It  weak externals
6786 The Windows object format, PE, specifies a form of weak symbols called weak
6787 externals. When a weak symbol is linked and the symbol is not defined, the
6788 weak symbol becomes an alias for some other symbol. There are three variants
6789 of weak externals:
6790 .Bl -bullet
6791 .It
6792 Definition is searched for in objects and libraries, historically
6793 called lazy externals.
6794 .It
6795 Definition is searched for only in other objects, not in libraries.
6796 This form is not presently implemented.
6797 .It
6798 No search; the symbol is an alias. This form is not presently
6799 implemented.
6800 .El
6801 As a GNU extension, weak symbols that do not specify an alternate symbol are
6802 supported. If the symbol is undefined when linking, the symbol uses a default
6803 value.
6804 .El
6805 .Pp
6806 .Ss  Li ld and Xtensa Processors
6807 The default
6808 .Xr ld
6809 behavior for Xtensa processors is to interpret
6810 .Li SECTIONS
6811 commands so that lists of explicitly named sections in a specification with
6812 a wildcard file will be interleaved when necessary to keep literal pools within
6813 the range of PC-relative load offsets. For example, with the command:
6814 .Pp
6815 .Bd -literal -offset indent
6816 SECTIONS
6817 {
6818   .text : {
6819     *(.literal .text)
6820   }
6821 }
6822 .Ed
6823 .Pp
6824 .Xr ld
6825 may interleave some of the
6826 .Li .literal
6827 and
6828 .Li .text
6829 sections from different object files to ensure that the literal pools are
6830 within the range of PC-relative load offsets. A valid interleaving might place
6831 the
6832 .Li .literal
6833 sections from an initial group of files followed by the
6834 .Li .text
6835 sections of that group of files. Then, the
6836 .Li .literal
6837 sections from the rest of the files and the
6838 .Li .text
6839 sections from the rest of the files would follow.
6840 .Pp
6841 Relaxation is enabled by default for the Xtensa version of
6842 .Xr ld
6843 and provides two important link-time optimizations. The first optimization
6844 is to combine identical literal values to reduce code size. A redundant literal
6845 will be removed and all the
6846 .Li L32R
6847 instructions that use it will be changed to reference an identical literal,
6848 as long as the location of the replacement literal is within the offset range
6849 of all the
6850 .Li L32R
6851 instructions. The second optimization is to remove unnecessary overhead from
6852 assembler-generated \(lqlongcall\(rq sequences of
6853 .Li L32R
6854 /
6855 .Li CALLX Va n
6856 when the target functions are within range of direct
6857 .Li CALL Va n
6858 instructions.
6859 .Pp
6860 For each of these cases where an indirect call sequence can be optimized to
6861 a direct call, the linker will change the
6862 .Li CALLX Va n
6863 instruction to a
6864 .Li CALL Va n
6865 instruction, remove the
6866 .Li L32R
6867 instruction, and remove the literal referenced by the
6868 .Li L32R
6869 instruction if it is not used for anything else. Removing the
6870 .Li L32R
6871 instruction always reduces code size but can potentially hurt performance
6872 by changing the alignment of subsequent branch targets. By default, the linker
6873 will always preserve alignments, either by switching some instructions between
6874 24-bit encodings and the equivalent density instructions or by inserting a
6875 no-op in place of the
6876 .Li L32R
6877 instruction that was removed. If code size is more important than performance,
6878 the
6879 .Op --size-opt
6880 option can be used to prevent the linker from widening density instructions
6881 or inserting no-ops, except in a few cases where no-ops are required for correctness.
6882 .Pp
6883 The following Xtensa-specific command-line options can be used to control
6884 the linker:
6885 .Pp
6886 .Bl -tag -width Ds
6887 .It  --no-relax
6888 Since the Xtensa version of
6889 .Li ld
6890 enables the
6891 .Op --relax
6892 option by default, the
6893 .Op --no-relax
6894 option is provided to disable relaxation.
6895 .Pp
6896 .It  --size-opt
6897 When optimizing indirect calls to direct calls, optimize for code size more
6898 than performance. With this option, the linker will not insert no-ops or widen
6899 density instructions to preserve branch target alignment. There may still
6900 be some cases where no-ops are required to preserve the correctness of the
6901 code.
6902 .El
6903 .Pp
6904 .Sh  BFD
6905 The linker accesses object and archive files using the BFD libraries. These
6906 libraries allow the linker to use the same routines to operate on object files
6907 whatever the object file format. A different object file format can be supported
6908 simply by creating a new BFD back end and adding it to the library. To conserve
6909 runtime memory, however, the linker and associated tools are usually configured
6910 to support only a subset of the object file formats available. You can use
6911 .Li objdump -i
6912 (see Section
6913 .Dq objdump )
6914 to list all the formats available for your configuration.
6915 .Pp
6916 As with most implementations, BFD is a compromise between several conflicting
6917 requirements. The major factor influencing BFD design was efficiency: any
6918 time used converting between formats is time which would not have been spent
6919 had BFD not been involved. This is partly offset by abstraction payback; since
6920 BFD simplifies applications and back ends, more time and care may be spent
6921 optimizing algorithms for a greater speed.
6922 .Pp
6923 One minor artifact of the BFD solution which you should bear in mind is the
6924 potential for information loss. There are two places where useful information
6925 can be lost using the BFD mechanism: during conversion and during output.See Section
6926 .Dq BFD information loss .
6927 .Pp
6928 .Ss  How It Works: An Outline of BFD
6929 When an object file is opened, BFD subroutines automatically determine the
6930 format of the input object file. They then build a descriptor in memory with
6931 pointers to routines that will be used to access elements of the object file's
6932 data structures.
6933 .Pp
6934 As different information from the object files is required, BFD reads from
6935 different sections of the file and processes them. For example, a very common
6936 operation for the linker is processing symbol tables. Each BFD back end provides
6937 a routine for converting between the object file's representation of symbols
6938 and an internal canonical format. When the linker asks for the symbol table
6939 of an object file, it calls through a memory pointer to the routine from the
6940 relevant BFD back end which reads and converts the table into a canonical
6941 form. The linker then operates upon the canonical form. When the link is finished
6942 and the linker writes the output file's symbol table, another BFD back end
6943 routine is called to take the newly created symbol table and convert it into
6944 the chosen output format.
6945 .Pp
6946 .Em  Information Loss
6947 .Pp
6948 .Em Information can be lost during output.
6949 The output formats supported by BFD do not provide identical facilities, and
6950 information which can be described in one form has nowhere to go in another
6951 format. One example of this is alignment information in
6952 .Li b.out .
6953 There is nowhere in an
6954 .Li a.out
6955 format file to store alignment information on the contained data, so when
6956 a file is linked from
6957 .Li b.out
6958 and an
6959 .Li a.out
6960 image is produced, alignment information will not propagate to the output
6961 file. (The linker will still use the alignment information internally, so
6962 the link is performed correctly).
6963 .Pp
6964 Another example is COFF section names. COFF files may contain an unlimited
6965 number of sections, each one with a textual section name. If the target of
6966 the link is a format which does not have many sections (e.g.,
6967 .Li a.out )
6968 or has sections without names (e.g., the Oasys format), the link cannot be
6969 done simply. You can circumvent this problem by describing the desired input-to-output
6970 section mapping with the linker command language.
6971 .Pp
6972 .Em Information can be lost during canonicalization.
6973 The BFD internal canonical form of the external formats is not exhaustive;
6974 there are structures in input formats for which there is no direct representation
6975 internally. This means that the BFD back ends cannot maintain all possible
6976 data richness through the transformation between external to internal and
6977 back to external formats.
6978 .Pp
6979 This limitation is only a problem when an application reads one format and
6980 writes another. Each BFD back end is responsible for maintaining as much data
6981 as possible, and the internal BFD canonical form has structures which are
6982 opaque to the BFD core, and exported only to the back ends. When a file is
6983 read in one format, the canonical form is generated for BFD and the application.
6984 At the same time, the back end saves away any information which may otherwise
6985 be lost. If the data is then written back in the same format, the back end
6986 routine will be able to use the canonical form provided by the BFD core as
6987 well as the information it prepared earlier. Since there is a great deal of
6988 commonality between back ends, there is no information lost when linking or
6989 copying big endian COFF to little endian COFF, or
6990 .Li a.out
6991 to
6992 .Li b.out .
6993 When a mixture of formats is linked, the information is only lost from the
6994 files whose format differs from the destination.
6995 .Pp
6996 .Em  The BFD canonical object-file format
6997 .Pp
6998 The greatest potential for loss of information occurs when there is the least
6999 overlap between the information provided by the source format, that stored
7000 by the canonical format, and that needed by the destination format. A brief
7001 description of the canonical form may help you understand which kinds of data
7002 you can count on preserving across conversions.
7003 .Pp
7004 .Bl -tag -width Ds
7005 .It  files
7006 Information stored on a per-file basis includes target machine architecture,
7007 particular implementation format type, a demand pageable bit, and a write
7008 protected bit. Information like Unix magic numbers is not stored here---only
7009 the magic numbers' meaning, so a
7010 .Li ZMAGIC
7011 file would have both the demand pageable bit and the write protected text
7012 bit set. The byte order of the target is stored on a per-file basis, so that
7013 big- and little-endian object files may be used with one another.
7014 .Pp
7015 .It  sections
7016 Each section in the input file contains the name of the section, the section's
7017 original address in the object file, size and alignment information, various
7018 flags, and pointers into other BFD data structures.
7019 .Pp
7020 .It  symbols
7021 Each symbol contains a pointer to the information for the object file which
7022 originally defined it, its name, its value, and various flag bits. When a
7023 BFD back end reads in a symbol table, it relocates all symbols to make them
7024 relative to the base of the section where they were defined. Doing this ensures
7025 that each symbol points to its containing section. Each symbol also has a
7026 varying amount of hidden private data for the BFD back end. Since the symbol
7027 points to the original file, the private data format for that symbol is accessible.
7028 .Li ld
7029 can operate on a collection of symbols of wildly different formats without
7030 problems.
7031 .Pp
7032 Normal global and simple local symbols are maintained on output, so an output
7033 file (no matter its format) will retain symbols pointing to functions and
7034 to global, static, and common variables. Some symbol information is not worth
7035 retaining; in
7036 .Li a.out ,
7037 type information is stored in the symbol table as long symbol names. This
7038 information would be useless to most COFF debuggers; the linker has command
7039 line switches to allow users to throw it away.
7040 .Pp
7041 There is one word of type information within the symbol, so if the format
7042 supports symbol type information within symbols (for example, COFF, IEEE,
7043 Oasys) and the type is simple enough to fit within one word (nearly everything
7044 but aggregates), the information will be preserved.
7045 .Pp
7046 .It  relocation level
7047 Each canonical BFD relocation record contains a pointer to the symbol to relocate
7048 to, the offset of the data to relocate, the section the data is in, and a
7049 pointer to a relocation type descriptor. Relocation is performed by passing
7050 messages through the relocation type descriptor and the symbol pointer. Therefore,
7051 relocations can be performed on output data using a relocation method that
7052 is only available in one of the input formats. For instance, Oasys provides
7053 a byte relocation format. A relocation record requesting this relocation type
7054 would point indirectly to a routine to perform this, so the relocation may
7055 be performed on a byte being written to a 68k COFF file, even though 68k COFF
7056 has no such relocation type.
7057 .Pp
7058 .It  line numbers
7059 Object formats can contain, for debugging purposes, some form of mapping between
7060 symbols, source line numbers, and addresses in the output file. These addresses
7061 have to be relocated along with the symbol information. Each symbol with an
7062 associated list of line number records points to the first record of the list.
7063 The head of a line number list consists of a pointer to the symbol, which
7064 allows finding out the address of the function whose line number is being
7065 described. The rest of the list is made up of pairs: offsets into the section
7066 and line numbers. Any format which can simply derive this information can
7067 pass it successfully between formats (COFF, IEEE and Oasys).
7068 .El
7069 .Pp
7070 .Sh  Reporting Bugs
7071 Your bug reports play an essential role in making
7072 .Xr ld
7073 reliable.
7074 .Pp
7075 Reporting a bug may help you by bringing a solution to your problem, or it
7076 may not. But in any case the principal function of a bug report is to help
7077 the entire community by making the next version of
7078 .Xr ld
7079 work better. Bug reports are your contribution to the maintenance of
7080 .Xr ld .
7081 .Pp
7082 In order for a bug report to serve its purpose, you must include the information
7083 that enables us to fix the bug.
7084 .Pp
7085 .Ss  Have You Found a Bug?
7086 If you are not sure whether you have found a bug, here are some guidelines:
7087 .Pp
7088 .Bl -bullet
7089 .It
7090 If the linker gets a fatal signal, for any input whatever, that is a
7091 .Xr ld
7092 bug. Reliable linkers never crash.
7093 .Pp
7094 .It
7095 If
7096 .Xr ld
7097 produces an error message for valid input, that is a bug.
7098 .Pp
7099 .It
7100 If
7101 .Xr ld
7102 does not produce an error message for invalid input, that may be a bug. In
7103 the general case, the linker can not verify that object files are correct.
7104 .Pp
7105 .It
7106 If you are an experienced user of linkers, your suggestions for improvement
7107 of
7108 .Xr ld
7109 are welcome in any case.
7110 .El
7111 .Pp
7112 .Ss  How to Report Bugs
7113 A number of companies and individuals offer support for GNU products. If you
7114 obtained
7115 .Xr ld
7116 from a support organization, we recommend you contact that organization first.
7117 .Pp
7118 You can find contact information for many support companies and individuals
7119 in the file
7120 .Pa etc/SERVICE
7121 in the GNU Emacs distribution.
7122 .Pp
7123 The fundamental principle of reporting bugs usefully is this:
7124 .Sy report all the facts .
7125 If you are not sure whether to state a fact or leave it out, state it!
7126 .Pp
7127 Often people omit facts because they think they know what causes the problem
7128 and assume that some details do not matter. Thus, you might assume that the
7129 name of a symbol you use in an example does not matter. Well, probably it
7130 does not, but one cannot be sure. Perhaps the bug is a stray memory reference
7131 which happens to fetch from the location where that name is stored in memory;
7132 perhaps, if the name were different, the contents of that location would fool
7133 the linker into doing the right thing despite the bug. Play it safe and give
7134 a specific, complete example. That is the easiest thing for you to do, and
7135 the most helpful.
7136 .Pp
7137 Keep in mind that the purpose of a bug report is to enable us to fix the bug
7138 if it is new to us. Therefore, always write your bug reports on the assumption
7139 that the bug has not been reported previously.
7140 .Pp
7141 Sometimes people give a few sketchy facts and ask, \(lqDoes this ring a bell?\(rq
7142 This cannot help us fix a bug, so it is basically useless. We respond by asking
7143 for enough details to enable us to investigate. You might as well expedite
7144 matters by sending them to begin with.
7145 .Pp
7146 To enable us to fix the bug, you should include all these things:
7147 .Pp
7148 .Bl -bullet
7149 .It
7150 The version of
7151 .Xr ld .
7152 .Xr ld
7153 announces it if you start it with the
7154 .Li --version
7155 argument.
7156 .Pp
7157 Without this, we will not know whether there is any point in looking for the
7158 bug in the current version of
7159 .Xr ld .
7160 .Pp
7161 .It
7162 Any patches you may have applied to the
7163 .Xr ld
7164 source, including any patches made to the
7165 .Li BFD
7166 library.
7167 .Pp
7168 .It
7169 The type of machine you are using, and the operating system name and version
7170 number.
7171 .Pp
7172 .It
7173 What compiler (and its version) was used to compile
7174 .Xr ld
7175 ---e.g. \(lq
7176 .Li gcc-2.7
7177 \(rq\&.
7178 .Pp
7179 .It
7180 The command arguments you gave the linker to link your example and observe
7181 the bug. To guarantee you will not omit something important, list them all.
7182 A copy of the Makefile (or the output from make) is sufficient.
7183 .Pp
7184 If we were to try to guess the arguments, we would probably guess wrong and
7185 then we might not encounter the bug.
7186 .Pp
7187 .It
7188 A complete input file, or set of input files, that will reproduce the bug.
7189 It is generally most helpful to send the actual object files provided that
7190 they are reasonably small. Say no more than 10K. For bigger files you can
7191 either make them available by FTP or HTTP or else state that you are willing
7192 to send the object file(s) to whomever requests them. (Note - your email will
7193 be going to a mailing list, so we do not want to clog it up with large attachments).
7194 But small attachments are best.
7195 .Pp
7196 If the source files were assembled using
7197 .Li gas
7198 or compiled using
7199 .Li gcc ,
7200 then it may be OK to send the source files rather than the object files. In
7201 this case, be sure to say exactly what version of
7202 .Li gas
7203 or
7204 .Li gcc
7205 was used to produce the object files. Also say how
7206 .Li gas
7207 or
7208 .Li gcc
7209 were configured.
7210 .Pp
7211 .It
7212 A description of what behavior you observe that you believe is incorrect.
7213 For example, \(lqIt gets a fatal signal.\(rq
7214 .Pp
7215 Of course, if the bug is that
7216 .Xr ld
7217 gets a fatal signal, then we will certainly notice it. But if the bug is incorrect
7218 output, we might not notice unless it is glaringly wrong. You might as well
7219 not give us a chance to make a mistake.
7220 .Pp
7221 Even if the problem you experience is a fatal signal, you should still say
7222 so explicitly. Suppose something strange is going on, such as, your copy of
7223 .Xr ld
7224 is out of sync, or you have encountered a bug in the C library on your system.
7225 (This has happened!) Your copy might crash and ours would not. If you told
7226 us to expect a crash, then when ours fails to crash, we would know that the
7227 bug was not happening for us. If you had not told us to expect a crash, then
7228 we would not be able to draw any conclusion from our observations.
7229 .Pp
7230 .It
7231 If you wish to suggest changes to the
7232 .Xr ld
7233 source, send us context diffs, as generated by
7234 .Li diff
7235 with the
7236 .Li -u ,
7237 .Li -c ,
7238 or
7239 .Li -p
7240 option. Always send diffs from the old file to the new file. If you even discuss
7241 something in the
7242 .Xr ld
7243 source, refer to it by context, not by line number.
7244 .Pp
7245 The line numbers in our development sources will not match those in your sources.
7246 Your line numbers would convey no useful information to us.
7247 .El
7248 .Pp
7249 Here are some things that are not necessary:
7250 .Pp
7251 .Bl -bullet
7252 .It
7253 A description of the envelope of the bug.
7254 .Pp
7255 Often people who encounter a bug spend a lot of time investigating which changes
7256 to the input file will make the bug go away and which changes will not affect
7257 it.
7258 .Pp
7259 This is often time consuming and not very useful, because the way we will
7260 find the bug is by running a single example under the debugger with breakpoints,
7261 not by pure deduction from a series of examples. We recommend that you save
7262 your time for something else.
7263 .Pp
7264 Of course, if you can find a simpler example to report
7265 .Em instead
7266 of the original one, that is a convenience for us. Errors in the output will
7267 be easier to spot, running under the debugger will take less time, and so
7268 on.
7269 .Pp
7270 However, simplification is not vital; if you do not want to do this, report
7271 the bug anyway and send us the entire test case you used.
7272 .Pp
7273 .It
7274 A patch for the bug.
7275 .Pp
7276 A patch for the bug does help us if it is a good one. But do not omit the
7277 necessary information, such as the test case, on the assumption that a patch
7278 is all we need. We might see problems with your patch and decide to fix the
7279 problem another way, or we might not understand it at all.
7280 .Pp
7281 Sometimes with a program as complicated as
7282 .Xr ld
7283 it is very hard to construct an example that will make the program follow
7284 a certain path through the code. If you do not send us the example, we will
7285 not be able to construct one, so we will not be able to verify that the bug
7286 is fixed.
7287 .Pp
7288 And if we cannot understand what bug you are trying to fix, or why your patch
7289 should be an improvement, we will not install it. A test case will help us
7290 to understand.
7291 .Pp
7292 .It
7293 A guess about what the bug is or what it depends on.
7294 .Pp
7295 Such guesses are usually wrong. Even we cannot guess right about such things
7296 without first using the debugger to find the facts.
7297 .El
7298 .Pp
7299 .Sh  MRI Compatible Script Files
7300 To aid users making the transition to GNU
7301 .Xr ld
7302 from the MRI linker,
7303 .Xr ld
7304 can use MRI compatible linker scripts as an alternative to the more general-purpose
7305 linker scripting language described in Scripts. MRI compatible linker scripts
7306 have a much simpler command set than the scripting language otherwise used
7307 with
7308 .Xr ld .
7309 GNU
7310 .Xr ld
7311 supports the most commonly used MRI linker commands; these commands are described
7312 here.
7313 .Pp
7314 In general, MRI scripts aren't of much use with the
7315 .Li a.out
7316 object file format, since it only has three sections and MRI scripts lack
7317 some features to make use of them.
7318 .Pp
7319 You can specify a file containing an MRI-compatible script using the
7320 .Li -c
7321 command-line option.
7322 .Pp
7323 Each command in an MRI-compatible script occupies its own line; each command
7324 line starts with the keyword that identifies the command (though blank lines
7325 are also allowed for punctuation). If a line of an MRI-compatible script begins
7326 with an unrecognized keyword,
7327 .Xr ld
7328 issues a warning message, but continues processing the script.
7329 .Pp
7330 Lines beginning with
7331 .Li *
7332 are comments.
7333 .Pp
7334 You can write these commands using all upper-case letters, or all lower case;
7335 for example,
7336 .Li chip
7337 is the same as
7338 .Li CHIP .
7339 The following list shows only the upper-case form of each command.
7340 .Pp
7341 .Bl -tag -width Ds
7342 .It  ABSOLUTE Va secname
7343 .It  ABSOLUTE Va secname, Va secname, ... Va secname
7344 Normally,
7345 .Xr ld
7346 includes in the output file all sections from all the input files. However,
7347 in an MRI-compatible script, you can use the
7348 .Li ABSOLUTE
7349 command to restrict the sections that will be present in your output program.
7350 If the
7351 .Li ABSOLUTE
7352 command is used at all in a script, then only the sections named explicitly
7353 in
7354 .Li ABSOLUTE
7355 commands will appear in the linker output. You can still use other input sections
7356 (whatever you select on the command line, or using
7357 .Li LOAD )
7358 to resolve addresses in the output file.
7359 .Pp
7360 .It  ALIAS Va out-secname, Va in-secname
7361 Use this command to place the data from input section
7362 .Va in-secname
7363 in a section called
7364 .Va out-secname
7365 in the linker output file.
7366 .Pp
7367 .Va in-secname
7368 may be an integer.
7369 .Pp
7370 .It  ALIGN Va secname = Va expression
7371 Align the section called
7372 .Va secname
7373 to
7374 .Va expression .
7375 The
7376 .Va expression
7377 should be a power of two.
7378 .Pp
7379 .It  BASE Va expression
7380 Use the value of
7381 .Va expression
7382 as the lowest address (other than absolute addresses) in the output file.
7383 .Pp
7384 .It  CHIP Va expression
7385 .It  CHIP Va expression, Va expression
7386 This command does nothing; it is accepted only for compatibility.
7387 .Pp
7388 .It  END
7389 This command does nothing whatever; it's only accepted for compatibility.
7390 .Pp
7391 .It  FORMAT Va output-format
7392 Similar to the
7393 .Li OUTPUT_FORMAT
7394 command in the more general linker language, but restricted to one of these
7395 output formats:
7396 .Pp
7397 .Bl -enum
7398 .It
7399 S-records, if
7400 .Va output-format
7401 is
7402 .Li S
7403 .Pp
7404 .It
7405 IEEE, if
7406 .Va output-format
7407 is
7408 .Li IEEE
7409 .Pp
7410 .It
7411 COFF (the
7412 .Li coff-m68k
7413 variant in BFD), if
7414 .Va output-format
7415 is
7416 .Li COFF
7417 .El
7418 .Pp
7419 .It  LIST Va anything...
7420 Print (to the standard output file) a link map, as produced by the
7421 .Xr ld
7422 command-line option
7423 .Li -M .
7424 .Pp
7425 The keyword
7426 .Li LIST
7427 may be followed by anything on the same line, with no change in its effect.
7428 .Pp
7429 .It  LOAD Va filename
7430 .It  LOAD Va filename, Va filename, ... Va filename
7431 Include one or more object file
7432 .Va filename
7433 in the link; this has the same effect as specifying
7434 .Va filename
7435 directly on the
7436 .Xr ld
7437 command line.
7438 .Pp
7439 .It  NAME Va output-name
7440 .Va output-name
7441 is the name for the program produced by
7442 .Xr ld ;
7443 the MRI-compatible command
7444 .Li NAME
7445 is equivalent to the command-line option
7446 .Li -o
7447 or the general script language command
7448 .Li OUTPUT .
7449 .Pp
7450 .It  ORDER Va secname, Va secname, ... Va secname
7451 .It  ORDER Va secname Va secname Va secname
7452 Normally,
7453 .Xr ld
7454 orders the sections in its output file in the order in which they first appear
7455 in the input files. In an MRI-compatible script, you can override this ordering
7456 with the
7457 .Li ORDER
7458 command. The sections you list with
7459 .Li ORDER
7460 will appear first in your output file, in the order specified.
7461 .Pp
7462 .It  PUBLIC Va name= Va expression
7463 .It  PUBLIC Va name, Va expression
7464 .It  PUBLIC Va name Va expression
7465 Supply a value (
7466 .Va expression )
7467 for external symbol
7468 .Va name
7469 used in the linker input files.
7470 .Pp
7471 .It  SECT Va secname, Va expression
7472 .It  SECT Va secname= Va expression
7473 .It  SECT Va secname Va expression
7474 You can use any of these three forms of the
7475 .Li SECT
7476 command to specify the start address (
7477 .Va expression )
7478 for section
7479 .Va secname .
7480 If you have more than one
7481 .Li SECT
7482 statement for the same
7483 .Va secname ,
7484 only the
7485 .Em first
7486 sets the start address.
7487 .El
7488 .Pp
7489 .Sh  GNU Free Documentation License
7490 .Bd -filled -offset indent
7491 Copyright (C) 2000, 2003 Free Software Foundation, Inc. 51 Franklin Street,
7492 Fifth Floor, Boston, MA 02110-1301 USA
7493 .Pp
7494 Everyone is permitted to copy and distribute verbatim copies of this license
7495 document, but changing it is not allowed.
7496 .Ed
7497 .Pp
7498 .Bl -enum
7499 .It
7500 PREAMBLE
7501 .Pp
7502 The purpose of this License is to make a manual, textbook, or other written
7503 document \(lqfree\(rq in the sense of freedom: to assure everyone the effective freedom
7504 to copy and redistribute it, with or without modifying it, either commercially
7505 or noncommercially. Secondarily, this License preserves for the author and
7506 publisher a way to get credit for their work, while not being considered responsible
7507 for modifications made by others.
7508 .Pp
7509 This License is a kind of \(lqcopyleft\(rq, which means that derivative works of the
7510 document must themselves be free in the same sense. It complements the GNU
7511 General Public License, which is a copyleft license designed for free software.
7512 .Pp
7513 We have designed this License in order to use it for manuals for free software,
7514 because free software needs free documentation: a free program should come
7515 with manuals providing the same freedoms that the software does. But this
7516 License is not limited to software manuals; it can be used for any textual
7517 work, regardless of subject matter or whether it is published as a printed
7518 book. We recommend this License principally for works whose purpose is instruction
7519 or reference.
7520 .Pp
7521 .It
7522 APPLICABILITY AND DEFINITIONS
7523 .Pp
7524 This License applies to any manual or other work that contains a notice placed
7525 by the copyright holder saying it can be distributed under the terms of this
7526 License. The \(lqDocument\(rq, below, refers to any such manual or work. Any member
7527 of the public is a licensee, and is addressed as \(lqyou.\(rq
7528 .Pp
7529 A \(lqModified Version\(rq of the Document means any work containing the Document
7530 or a portion of it, either copied verbatim, or with modifications and/or translated
7531 into another language.
7532 .Pp
7533 A \(lqSecondary Section\(rq is a named appendix or a front-matter section of the Document
7534 that deals exclusively with the relationship of the publishers or authors
7535 of the Document to the Document's overall subject (or to related matters)
7536 and contains nothing that could fall directly within that overall subject.
7537 (For example, if the Document is in part a textbook of mathematics, a Secondary
7538 Section may not explain any mathematics.) The relationship could be a matter
7539 of historical connection with the subject or with related matters, or of legal,
7540 commercial, philosophical, ethical or political position regarding them.
7541 .Pp
7542 The \(lqInvariant Sections\(rq are certain Secondary Sections whose titles are designated,
7543 as being those of Invariant Sections, in the notice that says that the Document
7544 is released under this License.
7545 .Pp
7546 The \(lqCover Texts\(rq are certain short passages of text that are listed, as Front-Cover
7547 Texts or Back-Cover Texts, in the notice that says that the Document is released
7548 under this License.
7549 .Pp
7550 A \(lqTransparent\(rq copy of the Document means a machine-readable copy, represented
7551 in a format whose specification is available to the general public, whose
7552 contents can be viewed and edited directly and straightforwardly with generic
7553 text editors or (for images composed of pixels) generic paint programs or
7554 (for drawings) some widely available drawing editor, and that is suitable
7555 for input to text formatters or for automatic translation to a variety of
7556 formats suitable for input to text formatters. A copy made in an otherwise
7557 Transparent file format whose markup has been designed to thwart or discourage
7558 subsequent modification by readers is not Transparent. A copy that is not
7559 \(lqTransparent\(rq is called \(lqOpaque.\(rq
7560 .Pp
7561 Examples of suitable formats for Transparent copies include plain ASCII without
7562 markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly
7563 available DTD, and standard-conforming simple HTML designed for human modification.
7564 Opaque formats include PostScript, PDF, proprietary formats that can be read
7565 and edited only by proprietary word processors, SGML or XML for which the
7566 DTD and/or processing tools are not generally available, and the machine-generated
7567 HTML produced by some word processors for output purposes only.
7568 .Pp
7569 The \(lqTitle Page\(rq means, for a printed book, the title page itself, plus such
7570 following pages as are needed to hold, legibly, the material this License
7571 requires to appear in the title page. For works in formats which do not have
7572 any title page as such, \(lqTitle Page\(rq means the text near the most prominent
7573 appearance of the work's title, preceding the beginning of the body of the
7574 text.
7575 .Pp
7576 .It
7577 VERBATIM COPYING
7578 .Pp
7579 You may copy and distribute the Document in any medium, either commercially
7580 or noncommercially, provided that this License, the copyright notices, and
7581 the license notice saying this License applies to the Document are reproduced
7582 in all copies, and that you add no other conditions whatsoever to those of
7583 this License. You may not use technical measures to obstruct or control the
7584 reading or further copying of the copies you make or distribute. However,
7585 you may accept compensation in exchange for copies. If you distribute a large
7586 enough number of copies you must also follow the conditions in section 3.
7587 .Pp
7588 You may also lend copies, under the same conditions stated above, and you
7589 may publicly display copies.
7590 .Pp
7591 .It
7592 COPYING IN QUANTITY
7593 .Pp
7594 If you publish printed copies of the Document numbering more than 100, and
7595 the Document's license notice requires Cover Texts, you must enclose the copies
7596 in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover
7597 Texts on the front cover, and Back-Cover Texts on the back cover. Both covers
7598 must also clearly and legibly identify you as the publisher of these copies.
7599 The front cover must present the full title with all words of the title equally
7600 prominent and visible. You may add other material on the covers in addition.
7601 Copying with changes limited to the covers, as long as they preserve the title
7602 of the Document and satisfy these conditions, can be treated as verbatim copying
7603 in other respects.
7604 .Pp
7605 If the required texts for either cover are too voluminous to fit legibly,
7606 you should put the first ones listed (as many as fit reasonably) on the actual
7607 cover, and continue the rest onto adjacent pages.
7608 .Pp
7609 If you publish or distribute Opaque copies of the Document numbering more
7610 than 100, you must either include a machine-readable Transparent copy along
7611 with each Opaque copy, or state in or with each Opaque copy a publicly-accessible
7612 computer-network location containing a complete Transparent copy of the Document,
7613 free of added material, which the general network-using public has access
7614 to download anonymously at no charge using public-standard network protocols.
7615 If you use the latter option, you must take reasonably prudent steps, when
7616 you begin distribution of Opaque copies in quantity, to ensure that this Transparent
7617 copy will remain thus accessible at the stated location until at least one
7618 year after the last time you distribute an Opaque copy (directly or through
7619 your agents or retailers) of that edition to the public.
7620 .Pp
7621 It is requested, but not required, that you contact the authors of the Document
7622 well before redistributing any large number of copies, to give them a chance
7623 to provide you with an updated version of the Document.
7624 .Pp
7625 .It
7626 MODIFICATIONS
7627 .Pp
7628 You may copy and distribute a Modified Version of the Document under the conditions
7629 of sections 2 and 3 above, provided that you release the Modified Version
7630 under precisely this License, with the Modified Version filling the role of
7631 the Document, thus licensing distribution and modification of the Modified
7632 Version to whoever possesses a copy of it. In addition, you must do these
7633 things in the Modified Version:
7634 .Pp
7635 A. Use in the Title Page (and on the covers, if any) a title distinct from
7636 that of the Document, and from those of previous versions (which should, if
7637 there were any, be listed in the History section of the Document). You may
7638 use the same title as a previous version if the original publisher of that
7639 version gives permission.  B. List on the Title Page, as authors, one or more
7640 persons or entities responsible for authorship of the modifications in the
7641 Modified Version, together with at least five of the principal authors of
7642 the Document (all of its principal authors, if it has less than five).  C.
7643 State on the Title page the name of the publisher of the Modified Version,
7644 as the publisher.  D. Preserve all the copyright notices of the Document. 
7645 E. Add an appropriate copyright notice for your modifications adjacent to
7646 the other copyright notices.  F. Include, immediately after the copyright
7647 notices, a license notice giving the public permission to use the Modified
7648 Version under the terms of this License, in the form shown in the Addendum
7649 below.  G. Preserve in that license notice the full lists of Invariant Sections
7650 and required Cover Texts given in the Document's license notice.  H. Include
7651 an unaltered copy of this License.  I. Preserve the section entitled \(lqHistory\(rq,
7652 and its title, and add to it an item stating at least the title, year, new
7653 authors, and publisher of the Modified Version as given on the Title Page.
7654 If there is no section entitled \(lqHistory\(rq in the Document, create one stating
7655 the title, year, authors, and publisher of the Document as given on its Title
7656 Page, then add an item describing the Modified Version as stated in the previous
7657 sentence.  J. Preserve the network location, if any, given in the Document
7658 for public access to a Transparent copy of the Document, and likewise the
7659 network locations given in the Document for previous versions it was based
7660 on. These may be placed in the \(lqHistory\(rq section. You may omit a network location
7661 for a work that was published at least four years before the Document itself,
7662 or if the original publisher of the version it refers to gives permission. 
7663 K. In any section entitled \(lqAcknowledgements\(rq or \(lqDedications\(rq, preserve the section's
7664 title, and preserve in the section all the substance and tone of each of the
7665 contributor acknowledgements and/or dedications given therein.  L. Preserve
7666 all the Invariant Sections of the Document, unaltered in their text and in
7667 their titles. Section numbers or the equivalent are not considered part of
7668 the section titles.  M. Delete any section entitled \(lqEndorsements.\(rq Such a section
7669 may not be included in the Modified Version.  N. Do not retitle any existing
7670 section as \(lqEndorsements\(rq or to conflict in title with any Invariant Section. 
7671 .Pp
7672 If the Modified Version includes new front-matter sections or appendices that
7673 qualify as Secondary Sections and contain no material copied from the Document,
7674 you may at your option designate some or all of these sections as invariant.
7675 To do this, add their titles to the list of Invariant Sections in the Modified
7676 Version's license notice. These titles must be distinct from any other section
7677 titles.
7678 .Pp
7679 You may add a section entitled \(lqEndorsements\(rq, provided it contains nothing
7680 but endorsements of your Modified Version by various parties--for example,
7681 statements of peer review or that the text has been approved by an organization
7682 as the authoritative definition of a standard.
7683 .Pp
7684 You may add a passage of up to five words as a Front-Cover Text, and a passage
7685 of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts
7686 in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover
7687 Text may be added by (or through arrangements made by) any one entity. If
7688 the Document already includes a cover text for the same cover, previously
7689 added by you or by arrangement made by the same entity you are acting on behalf
7690 of, you may not add another; but you may replace the old one, on explicit
7691 permission from the previous publisher that added the old one.
7692 .Pp
7693 The author(s) and publisher(s) of the Document do not by this License give
7694 permission to use their names for publicity for or to assert or imply endorsement
7695 of any Modified Version.
7696 .Pp
7697 .It
7698 COMBINING DOCUMENTS
7699 .Pp
7700 You may combine the Document with other documents released under this License,
7701 under the terms defined in section 4 above for modified versions, provided
7702 that you include in the combination all of the Invariant Sections of all of
7703 the original documents, unmodified, and list them all as Invariant Sections
7704 of your combined work in its license notice.
7705 .Pp
7706 The combined work need only contain one copy of this License, and multiple
7707 identical Invariant Sections may be replaced with a single copy. If there
7708 are multiple Invariant Sections with the same name but different contents,
7709 make the title of each such section unique by adding at the end of it, in
7710 parentheses, the name of the original author or publisher of that section
7711 if known, or else a unique number. Make the same adjustment to the section
7712 titles in the list of Invariant Sections in the license notice of the combined
7713 work.
7714 .Pp
7715 In the combination, you must combine any sections entitled \(lqHistory\(rq in the
7716 various original documents, forming one section entitled \(lqHistory\(rq; likewise
7717 combine any sections entitled \(lqAcknowledgements\(rq, and any sections entitled
7718 \(lqDedications.\(rq You must delete all sections entitled \(lqEndorsements.\(rq
7719 .Pp
7720 .It
7721 COLLECTIONS OF DOCUMENTS
7722 .Pp
7723 You may make a collection consisting of the Document and other documents released
7724 under this License, and replace the individual copies of this License in the
7725 various documents with a single copy that is included in the collection, provided
7726 that you follow the rules of this License for verbatim copying of each of
7727 the documents in all other respects.
7728 .Pp
7729 You may extract a single document from such a collection, and distribute it
7730 individually under this License, provided you insert a copy of this License
7731 into the extracted document, and follow this License in all other respects
7732 regarding verbatim copying of that document.
7733 .Pp
7734 .It
7735 AGGREGATION WITH INDEPENDENT WORKS
7736 .Pp
7737 A compilation of the Document or its derivatives with other separate and independent
7738 documents or works, in or on a volume of a storage or distribution medium,
7739 does not as a whole count as a Modified Version of the Document, provided
7740 no compilation copyright is claimed for the compilation. Such a compilation
7741 is called an \(lqaggregate\(rq, and this License does not apply to the other self-contained
7742 works thus compiled with the Document, on account of their being thus compiled,
7743 if they are not themselves derivative works of the Document.
7744 .Pp
7745 If the Cover Text requirement of section 3 is applicable to these copies of
7746 the Document, then if the Document is less than one quarter of the entire
7747 aggregate, the Document's Cover Texts may be placed on covers that surround
7748 only the Document within the aggregate. Otherwise they must appear on covers
7749 around the whole aggregate.
7750 .Pp
7751 .It
7752 TRANSLATION
7753 .Pp
7754 Translation is considered a kind of modification, so you may distribute translations
7755 of the Document under the terms of section 4. Replacing Invariant Sections
7756 with translations requires special permission from their copyright holders,
7757 but you may include translations of some or all Invariant Sections in addition
7758 to the original versions of these Invariant Sections. You may include a translation
7759 of this License provided that you also include the original English version
7760 of this License. In case of a disagreement between the translation and the
7761 original English version of this License, the original English version will
7762 prevail.
7763 .Pp
7764 .It
7765 TERMINATION
7766 .Pp
7767 You may not copy, modify, sublicense, or distribute the Document except as
7768 expressly provided for under this License. Any other attempt to copy, modify,
7769 sublicense or distribute the Document is void, and will automatically terminate
7770 your rights under this License. However, parties who have received copies,
7771 or rights, from you under this License will not have their licenses terminated
7772 so long as such parties remain in full compliance.
7773 .Pp
7774 .It
7775 FUTURE REVISIONS OF THIS LICENSE
7776 .Pp
7777 The Free Software Foundation may publish new, revised versions of the GNU
7778 Free Documentation License from time to time. Such new versions will be similar
7779 in spirit to the present version, but may differ in detail to address new
7780 problems or concerns. See http://www.gnu.org/copyleft/.
7781 .Pp
7782 Each version of the License is given a distinguishing version number. If the
7783 Document specifies that a particular numbered version of this License \(lqor any
7784 later version\(rq applies to it, you have the option of following the terms and
7785 conditions either of that specified version or of any later version that has
7786 been published (not as a draft) by the Free Software Foundation. If the Document
7787 does not specify a version number of this License, you may choose any version
7788 ever published (not as a draft) by the Free Software Foundation.
7789 .Pp
7790 .El
7791 .Ss  ADDENDUM: How to use this License for your documents
7792 To use this License in a document you have written, include a copy of the
7793 License in the document and put the following copyright and license notices
7794 just after the title page:
7795 .Pp
7796 .Bd -literal -offset indent
7797
7798 Copyright (C)  year  your name.
7799 Permission is granted to copy, distribute and/or modify this document
7800 under the terms of the GNU Free Documentation License, Version 1.1
7801 or any later version published by the Free Software Foundation;
7802 with the Invariant Sections being list their titles, with the
7803 Front-Cover Texts being list, and with the Back-Cover Texts being list.
7804 A copy of the license is included in the section entitled "GNU
7805 Free Documentation License."
7806
7807 .Ed
7808 .Pp
7809 If you have no Invariant Sections, write \(lqwith no Invariant Sections\(rq instead
7810 of saying which ones are invariant. If you have no Front-Cover Texts, write
7811 \(lqno Front-Cover Texts\(rq instead of \(lqFront-Cover Texts being
7812 .Va list
7813 \(rq; likewise for Back-Cover Texts.
7814 .Pp
7815 If your document contains nontrivial examples of program code, we recommend
7816 releasing these examples in parallel under your choice of free software license,
7817 such as the GNU General Public License, to permit their use in free software.
7818 .Pp
7819 .Sh  LD Index