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