1LD(1) GNU Development Tools LD(1)
2
3
4
6 ld - The GNU linker
7
9 ld [options] objfile ...
10
12 ld combines a number of object and archive files, relocates their data
13 and ties up symbol references. Usually the last step in compiling a
14 program is to run ld.
15
16 ld accepts Linker Command Language files written in a superset of
17 AT&T's Link Editor Command Language syntax, to provide explicit and
18 total control over the linking process.
19
20 This man page does not describe the command language; see the ld entry
21 in "info" for full details on the command language and on other aspects
22 of the GNU linker.
23
24 This version of ld uses the general purpose BFD libraries to operate on
25 object files. This allows ld to read, combine, and write object files
26 in many different formats---for example, COFF or "a.out". Different
27 formats may be linked together to produce any available kind of object
28 file.
29
30 Aside from its flexibility, the GNU linker is more helpful than other
31 linkers in providing diagnostic information. Many linkers abandon exe‐
32 cution immediately upon encountering an error; whenever possible, ld
33 continues executing, allowing you to identify other errors (or, in some
34 cases, to get an output file in spite of the error).
35
36 The GNU linker ld is meant to cover a broad range of situations, and to
37 be as compatible as possible with other linkers. As a result, you have
38 many choices to control its behavior.
39
41 The linker supports a plethora of command-line options, but in actual
42 practice few of them are used in any particular context. For instance,
43 a frequent use of ld is to link standard Unix object files on a stan‐
44 dard, supported Unix system. On such a system, to link a file
45 "hello.o":
46
47 ld -o <output> /lib/crt0.o hello.o -lc
48
49 This tells ld to produce a file called output as the result of linking
50 the file "/lib/crt0.o" with "hello.o" and the library "libc.a", which
51 will come from the standard search directories. (See the discussion of
52 the -l option below.)
53
54 Some of the command-line options to ld may be specified at any point in
55 the command line. However, options which refer to files, such as -l or
56 -T, cause the file to be read at the point at which the option appears
57 in the command line, relative to the object files and other file
58 options. Repeating non-file options with a different argument will
59 either have no further effect, or override prior occurrences (those
60 further to the left on the command line) of that option. Options which
61 may be meaningfully specified more than once are noted in the descrip‐
62 tions below.
63
64 Non-option arguments are object files or archives which are to be
65 linked together. They may follow, precede, or be mixed in with com‐
66 mand-line options, except that an object file argument may not be
67 placed between an option and its argument.
68
69 Usually the linker is invoked with at least one object file, but you
70 can specify other forms of binary input files using -l, -R, and the
71 script command language. If no binary input files at all are speci‐
72 fied, the linker does not produce any output, and issues the message No
73 input files.
74
75 If the linker cannot recognize the format of an object file, it will
76 assume that it is a linker script. A script specified in this way aug‐
77 ments the main linker script used for the link (either the default
78 linker script or the one specified by using -T). This feature permits
79 the linker to link against a file which appears to be an object or an
80 archive, but actually merely defines some symbol values, or uses
81 "INPUT" or "GROUP" to load other objects. Specifying a script in this
82 way merely augments the main linker script, with the extra commands
83 placed after the main script; use the -T option to replace the default
84 linker script entirely, but note the effect of the "INSERT" command.
85
86 For options whose names are a single letter, option arguments must
87 either follow the option letter without intervening whitespace, or be
88 given as separate arguments immediately following the option that
89 requires them.
90
91 For options whose names are multiple letters, either one dash or two
92 can precede the option name; for example, -trace-symbol and
93 --trace-symbol are equivalent. Note---there is one exception to this
94 rule. Multiple letter options that start with a lower case 'o' can
95 only be preceded by two dashes. This is to reduce confusion with the
96 -o option. So for example -omagic sets the output file name to magic
97 whereas --omagic sets the NMAGIC flag on the output.
98
99 Arguments to multiple-letter options must either be separated from the
100 option name by an equals sign, or be given as separate arguments imme‐
101 diately following the option that requires them. For example,
102 --trace-symbol foo and --trace-symbol=foo are equivalent. Unique
103 abbreviations of the names of multiple-letter options are accepted.
104
105 Note---if the linker is being invoked indirectly, via a compiler driver
106 (e.g. gcc) then all the linker command line options should be prefixed
107 by -Wl, (or whatever is appropriate for the particular compiler driver)
108 like this:
109
110 gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
111
112 This is important, because otherwise the compiler driver program may
113 silently drop the linker options, resulting in a bad link.
114
115 Here is a table of the generic command line switches accepted by the
116 GNU linker:
117
118 @file
119 Read command-line options from file. The options read are inserted
120 in place of the original @file option. If file does not exist, or
121 cannot be read, then the option will be treated literally, and not
122 removed.
123
124 Options in file are separated by whitespace. A whitespace charac‐
125 ter may be included in an option by surrounding the entire option
126 in either single or double quotes. Any character (including a
127 backslash) may be included by prefixing the character to be
128 included with a backslash. The file may itself contain additional
129 @file options; any such options will be processed recursively.
130
131 -akeyword
132 This option is supported for HP/UX compatibility. The keyword
133 argument must be one of the strings archive, shared, or default.
134 -aarchive is functionally equivalent to -Bstatic, and the other two
135 keywords are functionally equivalent to -Bdynamic. This option may
136 be used any number of times.
137
138 -Aarchitecture
139 --architecture=architecture
140 In the current release of ld, this option is useful only for the
141 Intel 960 family of architectures. In that ld configuration, the
142 architecture argument identifies the particular architecture in the
143 960 family, enabling some safeguards and modifying the archive-
144 library search path.
145
146 Future releases of ld may support similar functionality for other
147 architecture families.
148
149 -b input-format
150 --format=input-format
151 ld may be configured to support more than one kind of object file.
152 If your ld is configured this way, you can use the -b option to
153 specify the binary format for input object files that follow this
154 option on the command line. Even when ld is configured to support
155 alternative object formats, you don't usually need to specify this,
156 as ld should be configured to expect as a default input format the
157 most usual format on each machine. input-format is a text string,
158 the name of a particular format supported by the BFD libraries.
159 (You can list the available binary formats with objdump -i.)
160
161 You may want to use this option if you are linking files with an
162 unusual binary format. You can also use -b to switch formats
163 explicitly (when linking object files of different formats), by
164 including -b input-format before each group of object files in a
165 particular format.
166
167 The default format is taken from the environment variable "GNUTAR‐
168 GET".
169
170 You can also define the input format from a script, using the com‐
171 mand "TARGET";
172
173 -c MRI-commandfile
174 --mri-script=MRI-commandfile
175 For compatibility with linkers produced by MRI, ld accepts script
176 files written in an alternate, restricted command language,
177 described in the MRI Compatible Script Files section of GNU ld doc‐
178 umentation. Introduce MRI script files with the option -c; use the
179 -T option to run linker scripts written in the general-purpose ld
180 scripting language. If MRI-cmdfile does not exist, ld looks for it
181 in the directories specified by any -L options.
182
183 -d
184 -dc
185 -dp These three options are equivalent; multiple forms are supported
186 for compatibility with other linkers. They assign space to common
187 symbols even if a relocatable output file is specified (with -r).
188 The script command "FORCE_COMMON_ALLOCATION" has the same effect.
189
190 -e entry
191 --entry=entry
192 Use entry as the explicit symbol for beginning execution of your
193 program, rather than the default entry point. If there is no sym‐
194 bol named entry, the linker will try to parse entry as a number,
195 and use that as the entry address (the number will be interpreted
196 in base 10; you may use a leading 0x for base 16, or a leading 0
197 for base 8).
198
199 --exclude-libs lib,lib,...
200 Specifies a list of archive libraries from which symbols should not
201 be automatically exported. The library names may be delimited by
202 commas or colons. Specifying "--exclude-libs ALL" excludes symbols
203 in all archive libraries from automatic export. This option is
204 available only for the i386 PE targeted port of the linker and for
205 ELF targeted ports. For i386 PE, symbols explicitly listed in a
206 .def file are still exported, regardless of this option. For ELF
207 targeted ports, symbols affected by this option will be treated as
208 hidden.
209
210 -E
211 --export-dynamic
212 When creating a dynamically linked executable, add all symbols to
213 the dynamic symbol table. The dynamic symbol table is the set of
214 symbols which are visible from dynamic objects at run time.
215
216 If you do not use this option, the dynamic symbol table will nor‐
217 mally contain only those symbols which are referenced by some
218 dynamic object mentioned in the link.
219
220 If you use "dlopen" to load a dynamic object which needs to refer
221 back to the symbols defined by the program, rather than some other
222 dynamic object, then you will probably need to use this option when
223 linking the program itself.
224
225 You can also use the dynamic list to control what symbols should be
226 added to the dynamic symbol table if the output format supports it.
227 See the description of --dynamic-list.
228
229 -EB Link big-endian objects. This affects the default output format.
230
231 -EL Link little-endian objects. This affects the default output for‐
232 mat.
233
234 -f
235 --auxiliary name
236 When creating an ELF shared object, set the internal DT_AUXILIARY
237 field to the specified name. This tells the dynamic linker that
238 the symbol table of the shared object should be used as an auxil‐
239 iary filter on the symbol table of the shared object name.
240
241 If you later link a program against this filter object, then, when
242 you run the program, the dynamic linker will see the DT_AUXILIARY
243 field. If the dynamic linker resolves any symbols from the filter
244 object, it will first check whether there is a definition in the
245 shared object name. If there is one, it will be used instead of
246 the definition in the filter object. The shared object name need
247 not exist. Thus the shared object name may be used to provide an
248 alternative implementation of certain functions, perhaps for debug‐
249 ging or for machine specific performance.
250
251 This option may be specified more than once. The DT_AUXILIARY
252 entries will be created in the order in which they appear on the
253 command line.
254
255 -F name
256 --filter name
257 When creating an ELF shared object, set the internal DT_FILTER
258 field to the specified name. This tells the dynamic linker that
259 the symbol table of the shared object which is being created should
260 be used as a filter on the symbol table of the shared object name.
261
262 If you later link a program against this filter object, then, when
263 you run the program, the dynamic linker will see the DT_FILTER
264 field. The dynamic linker will resolve symbols according to the
265 symbol table of the filter object as usual, but it will actually
266 link to the definitions found in the shared object name. Thus the
267 filter object can be used to select a subset of the symbols pro‐
268 vided by the object name.
269
270 Some older linkers used the -F option throughout a compilation
271 toolchain for specifying object-file format for both input and out‐
272 put object files. The GNU linker uses other mechanisms for this
273 purpose: the -b, --format, --oformat options, the "TARGET" command
274 in linker scripts, and the "GNUTARGET" environment variable. The
275 GNU linker will ignore the -F option when not creating an ELF
276 shared object.
277
278 -fini name
279 When creating an ELF executable or shared object, call NAME when
280 the executable or shared object is unloaded, by setting DT_FINI to
281 the address of the function. By default, the linker uses "_fini"
282 as the function to call.
283
284 -g Ignored. Provided for compatibility with other tools.
285
286 -Gvalue
287 --gpsize=value
288 Set the maximum size of objects to be optimized using the GP regis‐
289 ter to size. This is only meaningful for object file formats such
290 as MIPS ECOFF which supports putting large and small objects into
291 different sections. This is ignored for other object file formats.
292
293 -hname
294 -soname=name
295 When creating an ELF shared object, set the internal DT_SONAME
296 field to the specified name. When an executable is linked with a
297 shared object which has a DT_SONAME field, then when the executable
298 is run the dynamic linker will attempt to load the shared object
299 specified by the DT_SONAME field rather than the using the file
300 name given to the linker.
301
302 -i Perform an incremental link (same as option -r).
303
304 -init name
305 When creating an ELF executable or shared object, call NAME when
306 the executable or shared object is loaded, by setting DT_INIT to
307 the address of the function. By default, the linker uses "_init"
308 as the function to call.
309
310 -lnamespec
311 --library=namespec
312 Add the archive or object file specified by namespec to the list of
313 files to link. This option may be used any number of times. If
314 namespec is of the form :filename, ld will search the library path
315 for a file called filename, otherise it will search the library
316 path for a file called libnamespec.a.
317
318 On systems which support shared libraries, ld may also search for
319 files other than libnamespec.a. Specifically, on ELF and SunOS
320 systems, ld will search a directory for a library called libname‐
321 spec.so before searching for one called libnamespec.a. (By conven‐
322 tion, a ".so" extension indicates a shared library.) Note that
323 this behavior does not apply to :filename, which always specifies a
324 file called filename.
325
326 The linker will search an archive only once, at the location where
327 it is specified on the command line. If the archive defines a sym‐
328 bol which was undefined in some object which appeared before the
329 archive on the command line, the linker will include the appropri‐
330 ate file(s) from the archive. However, an undefined symbol in an
331 object appearing later on the command line will not cause the
332 linker to search the archive again.
333
334 See the -( option for a way to force the linker to search archives
335 multiple times.
336
337 You may list the same archive multiple times on the command line.
338
339 This type of archive searching is standard for Unix linkers. How‐
340 ever, if you are using ld on AIX, note that it is different from
341 the behaviour of the AIX linker.
342
343 -Lsearchdir
344 --library-path=searchdir
345 Add path searchdir to the list of paths that ld will search for ar‐
346 chive libraries and ld control scripts. You may use this option
347 any number of times. The directories are searched in the order in
348 which they are specified on the command line. Directories speci‐
349 fied on the command line are searched before the default directo‐
350 ries. All -L options apply to all -l options, regardless of the
351 order in which the options appear.
352
353 If searchdir begins with "=", then the "=" will be replaced by the
354 sysroot prefix, a path specified when the linker is configured.
355
356 The default set of paths searched (without being specified with -L)
357 depends on which emulation mode ld is using, and in some cases also
358 on how it was configured.
359
360 The paths can also be specified in a link script with the
361 "SEARCH_DIR" command. Directories specified this way are searched
362 at the point in which the linker script appears in the command
363 line.
364
365 -memulation
366 Emulate the emulation linker. You can list the available emula‐
367 tions with the --verbose or -V options.
368
369 If the -m option is not used, the emulation is taken from the
370 "LDEMULATION" environment variable, if that is defined.
371
372 Otherwise, the default emulation depends upon how the linker was
373 configured.
374
375 -M
376 --print-map
377 Print a link map to the standard output. A link map provides
378 information about the link, including the following:
379
380 * Where object files are mapped into memory.
381
382 * How common symbols are allocated.
383
384 * All archive members included in the link, with a mention of the
385 symbol which caused the archive member to be brought in.
386
387 * The values assigned to symbols.
388
389 Note - symbols whose values are computed by an expression which
390 involves a reference to a previous value of the same symbol may
391 not have correct result displayed in the link map. This is
392 because the linker discards intermediate results and only
393 retains the final value of an expression. Under such circum‐
394 stances the linker will display the final value enclosed by
395 square brackets. Thus for example a linker script containing:
396
397 foo = 1
398 foo = foo * 4
399 foo = foo + 8
400
401 will produce the following output in the link map if the -M
402 option is used:
403
404 0x00000001 foo = 0x1
405 [0x0000000c] foo = (foo * 0x4)
406 [0x0000000c] foo = (foo + 0x8)
407
408 See Expressions for more information about expressions in
409 linker scripts.
410
411 -n
412 --nmagic
413 Turn off page alignment of sections, and mark the output as
414 "NMAGIC" if possible.
415
416 -N
417 --omagic
418 Set the text and data sections to be readable and writable. Also,
419 do not page-align the data segment, and disable linking against
420 shared libraries. If the output format supports Unix style magic
421 numbers, mark the output as "OMAGIC". Note: Although a writable
422 text section is allowed for PE-COFF targets, it does not conform to
423 the format specification published by Microsoft.
424
425 --no-omagic
426 This option negates most of the effects of the -N option. It sets
427 the text section to be read-only, and forces the data segment to be
428 page-aligned. Note - this option does not enable linking against
429 shared libraries. Use -Bdynamic for this.
430
431 -o output
432 --output=output
433 Use output as the name for the program produced by ld; if this
434 option is not specified, the name a.out is used by default. The
435 script command "OUTPUT" can also specify the output file name.
436
437 -O level
438 If level is a numeric values greater than zero ld optimizes the
439 output. This might take significantly longer and therefore proba‐
440 bly should only be enabled for the final binary. At the moment
441 this option only affects ELF shared library generation. Future
442 releases of the linker may make more use of this option. Also cur‐
443 rently there is no difference in the linker's behaviour for differ‐
444 ent non-zero values of this option. Again this may change with
445 future releases.
446
447 -q
448 --emit-relocs
449 Leave relocation sections and contents in fully linked executables.
450 Post link analysis and optimization tools may need this information
451 in order to perform correct modifications of executables. This
452 results in larger executables.
453
454 This option is currently only supported on ELF platforms.
455
456 --force-dynamic
457 Force the output file to have dynamic sections. This option is
458 specific to VxWorks targets.
459
460 -r
461 --relocatable
462 Generate relocatable output---i.e., generate an output file that
463 can in turn serve as input to ld. This is often called partial
464 linking. As a side effect, in environments that support standard
465 Unix magic numbers, this option also sets the output file's magic
466 number to "OMAGIC". If this option is not specified, an absolute
467 file is produced. When linking C++ programs, this option will not
468 resolve references to constructors; to do that, use -Ur.
469
470 When an input file does not have the same format as the output
471 file, partial linking is only supported if that input file does not
472 contain any relocations. Different output formats can have further
473 restrictions; for example some "a.out"-based formats do not support
474 partial linking with input files in other formats at all.
475
476 This option does the same thing as -i.
477
478 -R filename
479 --just-symbols=filename
480 Read symbol names and their addresses from filename, but do not
481 relocate it or include it in the output. This allows your output
482 file to refer symbolically to absolute locations of memory defined
483 in other programs. You may use this option more than once.
484
485 For compatibility with other ELF linkers, if the -R option is fol‐
486 lowed by a directory name, rather than a file name, it is treated
487 as the -rpath option.
488
489 -s
490 --strip-all
491 Omit all symbol information from the output file.
492
493 -S
494 --strip-debug
495 Omit debugger symbol information (but not all symbols) from the
496 output file.
497
498 -t
499 --trace
500 Print the names of the input files as ld processes them.
501
502 -T scriptfile
503 --script=scriptfile
504 Use scriptfile as the linker script. This script replaces ld's
505 default linker script (rather than adding to it), so commandfile
506 must specify everything necessary to describe the output file.
507 If scriptfile does not exist in the current directory, "ld" looks
508 for it in the directories specified by any preceding -L options.
509 Multiple -T options accumulate.
510
511 -dT scriptfile
512 --default-script=scriptfile
513 Use scriptfile as the default linker script.
514
515 This option is similar to the --script option except that process‐
516 ing of the script is delayed until after the rest of the command
517 line has been processed. This allows options placed after the
518 --default-script option on the command line to affect the behaviour
519 of the linker script, which can be important when the linker com‐
520 mand line cannot be directly controlled by the user. (eg because
521 the command line is being constructed by another tool, such as
522 gcc).
523
524 -u symbol
525 --undefined=symbol
526 Force symbol to be entered in the output file as an undefined sym‐
527 bol. Doing this may, for example, trigger linking of additional
528 modules from standard libraries. -u may be repeated with different
529 option arguments to enter additional undefined symbols. This
530 option is equivalent to the "EXTERN" linker script command.
531
532 -Ur For anything other than C++ programs, this option is equivalent to
533 -r: it generates relocatable output---i.e., an output file that can
534 in turn serve as input to ld. When linking C++ programs, -Ur does
535 resolve references to constructors, unlike -r. It does not work to
536 use -Ur on files that were themselves linked with -Ur; once the
537 constructor table has been built, it cannot be added to. Use -Ur
538 only for the last partial link, and -r for the others.
539
540 --unique[=SECTION]
541 Creates a separate output section for every input section matching
542 SECTION, or if the optional wildcard SECTION argument is missing,
543 for every orphan input section. An orphan section is one not
544 specifically mentioned in a linker script. You may use this option
545 multiple times on the command line; It prevents the normal merging
546 of input sections with the same name, overriding output section
547 assignments in a linker script.
548
549 -v
550 --version
551 -V Display the version number for ld. The -V option also lists the
552 supported emulations.
553
554 -x
555 --discard-all
556 Delete all local symbols.
557
558 -X
559 --discard-locals
560 Delete all temporary local symbols. (These symbols start with sys‐
561 tem-specific local label prefixes, typically .L for ELF systems or
562 L for traditional a.out systems.)
563
564 -y symbol
565 --trace-symbol=symbol
566 Print the name of each linked file in which symbol appears. This
567 option may be given any number of times. On many systems it is
568 necessary to prepend an underscore.
569
570 This option is useful when you have an undefined symbol in your
571 link but don't know where the reference is coming from.
572
573 -Y path
574 Add path to the default library search path. This option exists
575 for Solaris compatibility.
576
577 -z keyword
578 The recognized keywords are:
579
580 combreloc
581 Combines multiple reloc sections and sorts them to make dynamic
582 symbol lookup caching possible.
583
584 defs
585 Disallows undefined symbols in object files. Undefined symbols
586 in shared libraries are still allowed.
587
588 execstack
589 Marks the object as requiring executable stack.
590
591 initfirst
592 This option is only meaningful when building a shared object.
593 It marks the object so that its runtime initialization will
594 occur before the runtime initialization of any other objects
595 brought into the process at the same time. Similarly the run‐
596 time finalization of the object will occur after the runtime
597 finalization of any other objects.
598
599 interpose
600 Marks the object that its symbol table interposes before all
601 symbols but the primary executable.
602
603 lazy
604 When generating an executable or shared library, mark it to
605 tell the dynamic linker to defer function call resolution to
606 the point when the function is called (lazy binding), rather
607 than at load time. Lazy binding is the default.
608
609 loadfltr
610 Marks the object that its filters be processed immediately at
611 runtime.
612
613 muldefs
614 Allows multiple definitions.
615
616 nocombreloc
617 Disables multiple reloc sections combining.
618
619 nocopyreloc
620 Disables production of copy relocs.
621
622 nodefaultlib
623 Marks the object that the search for dependencies of this
624 object will ignore any default library search paths.
625
626 nodelete
627 Marks the object shouldn't be unloaded at runtime.
628
629 nodlopen
630 Marks the object not available to "dlopen".
631
632 nodump
633 Marks the object can not be dumped by "dldump".
634
635 noexecstack
636 Marks the object as not requiring executable stack.
637
638 norelro
639 Don't create an ELF "PT_GNU_RELRO" segment header in the
640 object.
641
642 now When generating an executable or shared library, mark it to
643 tell the dynamic linker to resolve all symbols when the program
644 is started, or when the shared library is linked to using
645 dlopen, instead of deferring function call resolution to the
646 point when the function is first called.
647
648 origin
649 Marks the object may contain $ORIGIN.
650
651 relro
652 Create an ELF "PT_GNU_RELRO" segment header in the object.
653
654 max-page-size=value
655 Set the emulation maximum page size to value.
656
657 common-page-size=value
658 Set the emulation common page size to value.
659
660 Other keywords are ignored for Solaris compatibility.
661
662 -( archives -)
663 --start-group archives --end-group
664 The archives should be a list of archive files. They may be either
665 explicit file names, or -l options.
666
667 The specified archives are searched repeatedly until no new unde‐
668 fined references are created. Normally, an archive is searched
669 only once in the order that it is specified on the command line.
670 If a symbol in that archive is needed to resolve an undefined sym‐
671 bol referred to by an object in an archive that appears later on
672 the command line, the linker would not be able to resolve that ref‐
673 erence. By grouping the archives, they all be searched repeatedly
674 until all possible references are resolved.
675
676 Using this option has a significant performance cost. It is best
677 to use it only when there are unavoidable circular references
678 between two or more archives.
679
680 --accept-unknown-input-arch
681 --no-accept-unknown-input-arch
682 Tells the linker to accept input files whose architecture cannot be
683 recognised. The assumption is that the user knows what they are
684 doing and deliberately wants to link in these unknown input files.
685 This was the default behaviour of the linker, before release 2.14.
686 The default behaviour from release 2.14 onwards is to reject such
687 input files, and so the --accept-unknown-input-arch option has been
688 added to restore the old behaviour.
689
690 --as-needed
691 --no-as-needed
692 This option affects ELF DT_NEEDED tags for dynamic libraries men‐
693 tioned on the command line after the --as-needed option. Normally,
694 the linker will add a DT_NEEDED tag for each dynamic library men‐
695 tioned on the command line, regardless of whether the library is
696 actually needed. --as-needed causes DT_NEEDED tags to only be
697 emitted for libraries that satisfy some symbol reference from regu‐
698 lar objects which is undefined at the point that the library was
699 linked. --no-as-needed restores the default behaviour.
700
701 --add-needed
702 --no-add-needed
703 This option affects the treatment of dynamic libraries from ELF
704 DT_NEEDED tags in dynamic libraries mentioned on the command line
705 after the --no-add-needed option. Normally, the linker will add a
706 DT_NEEDED tag for each dynamic library from DT_NEEDED tags.
707 --no-add-needed causes DT_NEEDED tags will never be emitted for
708 those libraries from DT_NEEDED tags. --add-needed restores the
709 default behaviour.
710
711 -assert keyword
712 This option is ignored for SunOS compatibility.
713
714 -Bdynamic
715 -dy
716 -call_shared
717 Link against dynamic libraries. This is only meaningful on plat‐
718 forms for which shared libraries are supported. This option is
719 normally the default on such platforms. The different variants of
720 this option are for compatibility with various systems. You may
721 use this option multiple times on the command line: it affects
722 library searching for -l options which follow it.
723
724 -Bgroup
725 Set the "DF_1_GROUP" flag in the "DT_FLAGS_1" entry in the dynamic
726 section. This causes the runtime linker to handle lookups in this
727 object and its dependencies to be performed only inside the group.
728 --unresolved-symbols=report-all is implied. This option is only
729 meaningful on ELF platforms which support shared libraries.
730
731 -Bstatic
732 -dn
733 -non_shared
734 -static
735 Do not link against shared libraries. This is only meaningful on
736 platforms for which shared libraries are supported. The different
737 variants of this option are for compatibility with various systems.
738 You may use this option multiple times on the command line: it
739 affects library searching for -l options which follow it. This
740 option also implies --unresolved-symbols=report-all. This option
741 can be used with -shared. Doing so means that a shared library is
742 being created but that all of the library's external references
743 must be resolved by pulling in entries from static libraries.
744
745 -Bsymbolic
746 When creating a shared library, bind references to global symbols
747 to the definition within the shared library, if any. Normally, it
748 is possible for a program linked against a shared library to over‐
749 ride the definition within the shared library. This option is only
750 meaningful on ELF platforms which support shared libraries.
751
752 -Bsymbolic-functions
753 When creating a shared library, bind references to global function
754 symbols to the definition within the shared library, if any. This
755 option is only meaningful on ELF platforms which support shared
756 libraries.
757
758 --dynamic-list=dynamic-list-file
759 Specify the name of a dynamic list file to the linker. This is
760 typically used when creating shared libraries to specify a list of
761 global symbols whose references shouldn't be bound to the defini‐
762 tion within the shared library, or creating dynamically linked exe‐
763 cutables to specify a list of symbols which should be added to the
764 symbol table in the executable. This option is only meaningful on
765 ELF platforms which support shared libraries.
766
767 The format of the dynamic list is the same as the version node
768 without scope and node name. See VERSION for more information.
769
770 --dynamic-list-data
771 Include all global data symbols to the dynamic list.
772
773 --dynamic-list-cpp-new
774 Provide the builtin dynamic list for C++ operator new and delete.
775 It is mainly useful for building shared libstdc++.
776
777 --dynamic-list-cpp-typeinfo
778 Provide the builtin dynamic list for C++ runtime type identifica‐
779 tion.
780
781 --check-sections
782 --no-check-sections
783 Asks the linker not to check section addresses after they have been
784 assigned to see if there are any overlaps. Normally the linker
785 will perform this check, and if it finds any overlaps it will pro‐
786 duce suitable error messages. The linker does know about, and does
787 make allowances for sections in overlays. The default behaviour
788 can be restored by using the command line switch --check-sections.
789
790 --cref
791 Output a cross reference table. If a linker map file is being gen‐
792 erated, the cross reference table is printed to the map file. Oth‐
793 erwise, it is printed on the standard output.
794
795 The format of the table is intentionally simple, so that it may be
796 easily processed by a script if necessary. The symbols are printed
797 out, sorted by name. For each symbol, a list of file names is
798 given. If the symbol is defined, the first file listed is the
799 location of the definition. The remaining files contain references
800 to the symbol.
801
802 --no-define-common
803 This option inhibits the assignment of addresses to common symbols.
804 The script command "INHIBIT_COMMON_ALLOCATION" has the same effect.
805
806 The --no-define-common option allows decoupling the decision to
807 assign addresses to Common symbols from the choice of the output
808 file type; otherwise a non-Relocatable output type forces assigning
809 addresses to Common symbols. Using --no-define-common allows Com‐
810 mon symbols that are referenced from a shared library to be
811 assigned addresses only in the main program. This eliminates the
812 unused duplicate space in the shared library, and also prevents any
813 possible confusion over resolving to the wrong duplicate when there
814 are many dynamic modules with specialized search paths for runtime
815 symbol resolution.
816
817 --defsym symbol=expression
818 Create a global symbol in the output file, containing the absolute
819 address given by expression. You may use this option as many times
820 as necessary to define multiple symbols in the command line. A
821 limited form of arithmetic is supported for the expression in this
822 context: you may give a hexadecimal constant or the name of an
823 existing symbol, or use "+" and "-" to add or subtract hexadecimal
824 constants or symbols. If you need more elaborate expressions, con‐
825 sider using the linker command language from a script. Note: there
826 should be no white space between symbol, the equals sign ("="), and
827 expression.
828
829 --demangle[=style]
830 --no-demangle
831 These options control whether to demangle symbol names in error
832 messages and other output. When the linker is told to demangle, it
833 tries to present symbol names in a readable fashion: it strips
834 leading underscores if they are used by the object file format, and
835 converts C++ mangled symbol names into user readable names. Dif‐
836 ferent compilers have different mangling styles. The optional
837 demangling style argument can be used to choose an appropriate
838 demangling style for your compiler. The linker will demangle by
839 default unless the environment variable COLLECT_NO_DEMANGLE is set.
840 These options may be used to override the default.
841
842 --dynamic-linker file
843 Set the name of the dynamic linker. This is only meaningful when
844 generating dynamically linked ELF executables. The default dynamic
845 linker is normally correct; don't use this unless you know what you
846 are doing.
847
848 --fatal-warnings
849 --no-fatal-warnings
850 Treat all warnings as errors. The default behaviour can be
851 restored with the option --no-fatal-warnings.
852
853 --force-exe-suffix
854 Make sure that an output file has a .exe suffix.
855
856 If a successfully built fully linked output file does not have a
857 ".exe" or ".dll" suffix, this option forces the linker to copy the
858 output file to one of the same name with a ".exe" suffix. This
859 option is useful when using unmodified Unix makefiles on a Micro‐
860 soft Windows host, since some versions of Windows won't run an
861 image unless it ends in a ".exe" suffix.
862
863 --gc-sections
864 --no-gc-sections
865 Enable garbage collection of unused input sections. It is ignored
866 on targets that do not support this option. The default behaviour
867 (of not performing this garbage collection) can be restored by
868 specifying --no-gc-sections on the command line.
869
870 --gc-sections decides which input sections are used by examining
871 symbols and relocations. The section containing the entry symbol
872 and all sections containing symbols undefined on the command-line
873 will be kept, as will sections containing symbols referenced by
874 dynamic objects. Note that when building shared libraries, the
875 linker must assume that any visible symbol is referenced. Once
876 this initial set of sections has been determined, the linker recur‐
877 sively marks as used any section referenced by their relocations.
878 See --entry and --undefined.
879
880 This option can be set when doing a partial link (enabled with
881 option -r). In this case the root of symbols kept must be
882 explicitely specified either by an --entry or --undefined option or
883 by a "ENTRY" command in the linker script.
884
885 --print-gc-sections
886 --no-print-gc-sections
887 List all sections removed by garbage collection. The listing is
888 printed on stderr. This option is only effective if garbage col‐
889 lection has been enabled via the --gc-sections) option. The
890 default behaviour (of not listing the sections that are removed)
891 can be restored by specifying --no-print-gc-sections on the command
892 line.
893
894 --help
895 Print a summary of the command-line options on the standard output
896 and exit.
897
898 --target-help
899 Print a summary of all target specific options on the standard out‐
900 put and exit.
901
902 -Map mapfile
903 Print a link map to the file mapfile. See the description of the
904 -M option, above.
905
906 --no-keep-memory
907 ld normally optimizes for speed over memory usage by caching the
908 symbol tables of input files in memory. This option tells ld to
909 instead optimize for memory usage, by rereading the symbol tables
910 as necessary. This may be required if ld runs out of memory space
911 while linking a large executable.
912
913 --no-undefined
914 -z defs
915 Report unresolved symbol references from regular object files.
916 This is done even if the linker is creating a non-symbolic shared
917 library. The switch --[no-]allow-shlib-undefined controls the be‐
918 haviour for reporting unresolved references found in shared
919 libraries being linked in.
920
921 --allow-multiple-definition
922 -z muldefs
923 Normally when a symbol is defined multiple times, the linker will
924 report a fatal error. These options allow multiple definitions and
925 the first definition will be used.
926
927 --allow-shlib-undefined
928 --no-allow-shlib-undefined
929 Allows (the default) or disallows undefined symbols in shared
930 libraries. This switch is similar to --no-undefined except that it
931 determines the behaviour when the undefined symbols are in a shared
932 library rather than a regular object file. It does not affect how
933 undefined symbols in regular object files are handled.
934
935 The reason that --allow-shlib-undefined is the default is that the
936 shared library being specified at link time may not be the same as
937 the one that is available at load time, so the symbols might actu‐
938 ally be resolvable at load time. Plus there are some systems, (eg
939 BeOS) where undefined symbols in shared libraries is normal. (The
940 kernel patches them at load time to select which function is most
941 appropriate for the current architecture. This is used for example
942 to dynamically select an appropriate memset function). Apparently
943 it is also normal for HPPA shared libraries to have undefined sym‐
944 bols.
945
946 --no-undefined-version
947 Normally when a symbol has an undefined version, the linker will
948 ignore it. This option disallows symbols with undefined version and
949 a fatal error will be issued instead.
950
951 --default-symver
952 Create and use a default symbol version (the soname) for unver‐
953 sioned exported symbols.
954
955 --default-imported-symver
956 Create and use a default symbol version (the soname) for unver‐
957 sioned imported symbols.
958
959 --no-warn-mismatch
960 Normally ld will give an error if you try to link together input
961 files that are mismatched for some reason, perhaps because they
962 have been compiled for different processors or for different endi‐
963 annesses. This option tells ld that it should silently permit such
964 possible errors. This option should only be used with care, in
965 cases when you have taken some special action that ensures that the
966 linker errors are inappropriate.
967
968 --no-warn-search-mismatch
969 Normally ld will give a warning if it finds an incompatible library
970 during a library search. This option silences the warning.
971
972 --no-whole-archive
973 Turn off the effect of the --whole-archive option for subsequent
974 archive files.
975
976 --noinhibit-exec
977 Retain the executable output file whenever it is still usable.
978 Normally, the linker will not produce an output file if it encoun‐
979 ters errors during the link process; it exits without writing an
980 output file when it issues any error whatsoever.
981
982 -nostdlib
983 Only search library directories explicitly specified on the command
984 line. Library directories specified in linker scripts (including
985 linker scripts specified on the command line) are ignored.
986
987 --oformat output-format
988 ld may be configured to support more than one kind of object file.
989 If your ld is configured this way, you can use the --oformat option
990 to specify the binary format for the output object file. Even when
991 ld is configured to support alternative object formats, you don't
992 usually need to specify this, as ld should be configured to produce
993 as a default output format the most usual format on each machine.
994 output-format is a text string, the name of a particular format
995 supported by the BFD libraries. (You can list the available binary
996 formats with objdump -i.) The script command "OUTPUT_FORMAT" can
997 also specify the output format, but this option overrides it.
998
999 -pie
1000 --pic-executable
1001 Create a position independent executable. This is currently only
1002 supported on ELF platforms. Position independent executables are
1003 similar to shared libraries in that they are relocated by the
1004 dynamic linker to the virtual address the OS chooses for them
1005 (which can vary between invocations). Like normal dynamically
1006 linked executables they can be executed and symbols defined in the
1007 executable cannot be overridden by shared libraries.
1008
1009 -qmagic
1010 This option is ignored for Linux compatibility.
1011
1012 -Qy This option is ignored for SVR4 compatibility.
1013
1014 --relax
1015 An option with machine dependent effects. This option is only sup‐
1016 ported on a few targets.
1017
1018 On some platforms, the --relax option performs global optimizations
1019 that become possible when the linker resolves addressing in the
1020 program, such as relaxing address modes and synthesizing new
1021 instructions in the output object file.
1022
1023 On some platforms these link time global optimizations may make
1024 symbolic debugging of the resulting executable impossible. This is
1025 known to be the case for the Matsushita MN10200 and MN10300 family
1026 of processors.
1027
1028 On platforms where this is not supported, --relax is accepted, but
1029 ignored.
1030
1031 --retain-symbols-file filename
1032 Retain only the symbols listed in the file filename, discarding all
1033 others. filename is simply a flat file, with one symbol name per
1034 line. This option is especially useful in environments (such as
1035 VxWorks) where a large global symbol table is accumulated gradu‐
1036 ally, to conserve run-time memory.
1037
1038 --retain-symbols-file does not discard undefined symbols, or sym‐
1039 bols needed for relocations.
1040
1041 You may only specify --retain-symbols-file once in the command
1042 line. It overrides -s and -S.
1043
1044 -rpath dir
1045 Add a directory to the runtime library search path. This is used
1046 when linking an ELF executable with shared objects. All -rpath
1047 arguments are concatenated and passed to the runtime linker, which
1048 uses them to locate shared objects at runtime. The -rpath option
1049 is also used when locating shared objects which are needed by
1050 shared objects explicitly included in the link; see the description
1051 of the -rpath-link option. If -rpath is not used when linking an
1052 ELF executable, the contents of the environment variable
1053 "LD_RUN_PATH" will be used if it is defined.
1054
1055 The -rpath option may also be used on SunOS. By default, on SunOS,
1056 the linker will form a runtime search patch out of all the -L
1057 options it is given. If a -rpath option is used, the runtime
1058 search path will be formed exclusively using the -rpath options,
1059 ignoring the -L options. This can be useful when using gcc, which
1060 adds many -L options which may be on NFS mounted file systems.
1061
1062 For compatibility with other ELF linkers, if the -R option is fol‐
1063 lowed by a directory name, rather than a file name, it is treated
1064 as the -rpath option.
1065
1066 -rpath-link DIR
1067 When using ELF or SunOS, one shared library may require another.
1068 This happens when an "ld -shared" link includes a shared library as
1069 one of the input files.
1070
1071 When the linker encounters such a dependency when doing a
1072 non-shared, non-relocatable link, it will automatically try to
1073 locate the required shared library and include it in the link, if
1074 it is not included explicitly. In such a case, the -rpath-link
1075 option specifies the first set of directories to search. The
1076 -rpath-link option may specify a sequence of directory names either
1077 by specifying a list of names separated by colons, or by appearing
1078 multiple times.
1079
1080 This option should be used with caution as it overrides the search
1081 path that may have been hard compiled into a shared library. In
1082 such a case it is possible to use unintentionally a different
1083 search path than the runtime linker would do.
1084
1085 The linker uses the following search paths to locate required
1086 shared libraries:
1087
1088 1. Any directories specified by -rpath-link options.
1089
1090 2. Any directories specified by -rpath options. The difference
1091 between -rpath and -rpath-link is that directories specified by
1092 -rpath options are included in the executable and used at run‐
1093 time, whereas the -rpath-link option is only effective at link
1094 time. Searching -rpath in this way is only supported by native
1095 linkers and cross linkers which have been configured with the
1096 --with-sysroot option.
1097
1098 3. On an ELF system, for native linkers, if the -rpath and
1099 -rpath-link options were not used, search the contents of the
1100 environment variable "LD_RUN_PATH".
1101
1102 4. On SunOS, if the -rpath option was not used, search any direc‐
1103 tories specified using -L options.
1104
1105 5. For a native linker, the search the contents of the environment
1106 variable "LD_LIBRARY_PATH".
1107
1108 6. For a native ELF linker, the directories in "DT_RUNPATH" or
1109 "DT_RPATH" of a shared library are searched for shared
1110 libraries needed by it. The "DT_RPATH" entries are ignored if
1111 "DT_RUNPATH" entries exist.
1112
1113 7. The default directories, normally /lib and /usr/lib.
1114
1115 8. For a native linker on an ELF system, if the file
1116 /etc/ld.so.conf exists, the list of directories found in that
1117 file.
1118
1119 If the required shared library is not found, the linker will issue
1120 a warning and continue with the link.
1121
1122 -shared
1123 -Bshareable
1124 Create a shared library. This is currently only supported on ELF,
1125 XCOFF and SunOS platforms. On SunOS, the linker will automatically
1126 create a shared library if the -e option is not used and there are
1127 undefined symbols in the link.
1128
1129 --sort-common [= ascending ⎪ descending]
1130 This option tells ld to sort the common symbols by alignment in
1131 ascending or descending order when it places them in the appropri‐
1132 ate output sections. The symbol alignments considered are sixteen-
1133 byte or larger, eight-byte, four-byte, two-byte, and one-byte. This
1134 is to prevent gaps between symbols due to alignment constraints.
1135 If no sorting order is specified, then descending order is assumed.
1136
1137 --sort-section name
1138 This option will apply "SORT_BY_NAME" to all wildcard section pat‐
1139 terns in the linker script.
1140
1141 --sort-section alignment
1142 This option will apply "SORT_BY_ALIGNMENT" to all wildcard section
1143 patterns in the linker script.
1144
1145 --split-by-file [size]
1146 Similar to --split-by-reloc but creates a new output section for
1147 each input file when size is reached. size defaults to a size of 1
1148 if not given.
1149
1150 --split-by-reloc [count]
1151 Tries to creates extra sections in the output file so that no sin‐
1152 gle output section in the file contains more than count reloca‐
1153 tions. This is useful when generating huge relocatable files for
1154 downloading into certain real time kernels with the COFF object
1155 file format; since COFF cannot represent more than 65535 reloca‐
1156 tions in a single section. Note that this will fail to work with
1157 object file formats which do not support arbitrary sections. The
1158 linker will not split up individual input sections for redistribu‐
1159 tion, so if a single input section contains more than count reloca‐
1160 tions one output section will contain that many relocations. count
1161 defaults to a value of 32768.
1162
1163 --stats
1164 Compute and display statistics about the operation of the linker,
1165 such as execution time and memory usage.
1166
1167 --sysroot=directory
1168 Use directory as the location of the sysroot, overriding the con‐
1169 figure-time default. This option is only supported by linkers that
1170 were configured using --with-sysroot.
1171
1172 --traditional-format
1173 For some targets, the output of ld is different in some ways from
1174 the output of some existing linker. This switch requests ld to use
1175 the traditional format instead.
1176
1177 For example, on SunOS, ld combines duplicate entries in the symbol
1178 string table. This can reduce the size of an output file with full
1179 debugging information by over 30 percent. Unfortunately, the SunOS
1180 "dbx" program can not read the resulting program ("gdb" has no
1181 trouble). The --traditional-format switch tells ld to not combine
1182 duplicate entries.
1183
1184 --section-start sectionname=org
1185 Locate a section in the output file at the absolute address given
1186 by org. You may use this option as many times as necessary to
1187 locate multiple sections in the command line. org must be a single
1188 hexadecimal integer; for compatibility with other linkers, you may
1189 omit the leading 0x usually associated with hexadecimal values.
1190 Note: there should be no white space between sectionname, the
1191 equals sign ("="), and org.
1192
1193 -Tbss org
1194 -Tdata org
1195 -Ttext org
1196 Same as --section-start, with ".bss", ".data" or ".text" as the
1197 sectionname.
1198
1199 --unresolved-symbols=method
1200 Determine how to handle unresolved symbols. There are four possi‐
1201 ble values for method:
1202
1203 ignore-all
1204 Do not report any unresolved symbols.
1205
1206 report-all
1207 Report all unresolved symbols. This is the default.
1208
1209 ignore-in-object-files
1210 Report unresolved symbols that are contained in shared
1211 libraries, but ignore them if they come from regular object
1212 files.
1213
1214 ignore-in-shared-libs
1215 Report unresolved symbols that come from regular object files,
1216 but ignore them if they come from shared libraries. This can
1217 be useful when creating a dynamic binary and it is known that
1218 all the shared libraries that it should be referencing are
1219 included on the linker's command line.
1220
1221 The behaviour for shared libraries on their own can also be con‐
1222 trolled by the --[no-]allow-shlib-undefined option.
1223
1224 Normally the linker will generate an error message for each
1225 reported unresolved symbol but the option --warn-unresolved-symbols
1226 can change this to a warning.
1227
1228 --dll-verbose
1229 --verbose
1230 Display the version number for ld and list the linker emulations
1231 supported. Display which input files can and cannot be opened.
1232 Display the linker script being used by the linker.
1233
1234 --version-script=version-scriptfile
1235 Specify the name of a version script to the linker. This is typi‐
1236 cally used when creating shared libraries to specify additional
1237 information about the version hierarchy for the library being cre‐
1238 ated. This option is only meaningful on ELF platforms which sup‐
1239 port shared libraries.
1240
1241 --warn-common
1242 Warn when a common symbol is combined with another common symbol or
1243 with a symbol definition. Unix linkers allow this somewhat sloppy
1244 practise, but linkers on some other operating systems do not. This
1245 option allows you to find potential problems from combining global
1246 symbols. Unfortunately, some C libraries use this practise, so you
1247 may get some warnings about symbols in the libraries as well as in
1248 your programs.
1249
1250 There are three kinds of global symbols, illustrated here by C
1251 examples:
1252
1253 int i = 1;
1254 A definition, which goes in the initialized data section of the
1255 output file.
1256
1257 extern int i;
1258 An undefined reference, which does not allocate space. There
1259 must be either a definition or a common symbol for the variable
1260 somewhere.
1261
1262 int i;
1263 A common symbol. If there are only (one or more) common sym‐
1264 bols for a variable, it goes in the uninitialized data area of
1265 the output file. The linker merges multiple common symbols for
1266 the same variable into a single symbol. If they are of differ‐
1267 ent sizes, it picks the largest size. The linker turns a com‐
1268 mon symbol into a declaration, if there is a definition of the
1269 same variable.
1270
1271 The --warn-common option can produce five kinds of warnings. Each
1272 warning consists of a pair of lines: the first describes the symbol
1273 just encountered, and the second describes the previous symbol
1274 encountered with the same name. One or both of the two symbols
1275 will be a common symbol.
1276
1277 1. Turning a common symbol into a reference, because there is
1278 already a definition for the symbol.
1279
1280 <file>(<section>): warning: common of `<symbol>'
1281 overridden by definition
1282 <file>(<section>): warning: defined here
1283
1284 2. Turning a common symbol into a reference, because a later defi‐
1285 nition for the symbol is encountered. This is the same as the
1286 previous case, except that the symbols are encountered in a
1287 different order.
1288
1289 <file>(<section>): warning: definition of `<symbol>'
1290 overriding common
1291 <file>(<section>): warning: common is here
1292
1293 3. Merging a common symbol with a previous same-sized common sym‐
1294 bol.
1295
1296 <file>(<section>): warning: multiple common
1297 of `<symbol>'
1298 <file>(<section>): warning: previous common is here
1299
1300 4. Merging a common symbol with a previous larger common symbol.
1301
1302 <file>(<section>): warning: common of `<symbol>'
1303 overridden by larger common
1304 <file>(<section>): warning: larger common is here
1305
1306 5. Merging a common symbol with a previous smaller common symbol.
1307 This is the same as the previous case, except that the symbols
1308 are encountered in a different order.
1309
1310 <file>(<section>): warning: common of `<symbol>'
1311 overriding smaller common
1312 <file>(<section>): warning: smaller common is here
1313
1314 --warn-constructors
1315 Warn if any global constructors are used. This is only useful for
1316 a few object file formats. For formats like COFF or ELF, the
1317 linker can not detect the use of global constructors.
1318
1319 --warn-multiple-gp
1320 Warn if multiple global pointer values are required in the output
1321 file. This is only meaningful for certain processors, such as the
1322 Alpha. Specifically, some processors put large-valued constants in
1323 a special section. A special register (the global pointer) points
1324 into the middle of this section, so that constants can be loaded
1325 efficiently via a base-register relative addressing mode. Since
1326 the offset in base-register relative mode is fixed and relatively
1327 small (e.g., 16 bits), this limits the maximum size of the constant
1328 pool. Thus, in large programs, it is often necessary to use multi‐
1329 ple global pointer values in order to be able to address all possi‐
1330 ble constants. This option causes a warning to be issued whenever
1331 this case occurs.
1332
1333 --warn-once
1334 Only warn once for each undefined symbol, rather than once per mod‐
1335 ule which refers to it.
1336
1337 --warn-section-align
1338 Warn if the address of an output section is changed because of
1339 alignment. Typically, the alignment will be set by an input sec‐
1340 tion. The address will only be changed if it not explicitly speci‐
1341 fied; that is, if the "SECTIONS" command does not specify a start
1342 address for the section.
1343
1344 --warn-shared-textrel
1345 Warn if the linker adds a DT_TEXTREL to a shared object.
1346
1347 --warn-unresolved-symbols
1348 If the linker is going to report an unresolved symbol (see the
1349 option --unresolved-symbols) it will normally generate an error.
1350 This option makes it generate a warning instead.
1351
1352 --error-unresolved-symbols
1353 This restores the linker's default behaviour of generating errors
1354 when it is reporting unresolved symbols.
1355
1356 --whole-archive
1357 For each archive mentioned on the command line after the
1358 --whole-archive option, include every object file in the archive in
1359 the link, rather than searching the archive for the required object
1360 files. This is normally used to turn an archive file into a shared
1361 library, forcing every object to be included in the resulting
1362 shared library. This option may be used more than once.
1363
1364 Two notes when using this option from gcc: First, gcc doesn't know
1365 about this option, so you have to use -Wl,-whole-archive. Second,
1366 don't forget to use -Wl,-no-whole-archive after your list of ar‐
1367 chives, because gcc will add its own list of archives to your link
1368 and you may not want this flag to affect those as well.
1369
1370 --wrap symbol
1371 Use a wrapper function for symbol. Any undefined reference to sym‐
1372 bol will be resolved to "__wrap_symbol". Any undefined reference
1373 to "__real_symbol" will be resolved to symbol.
1374
1375 This can be used to provide a wrapper for a system function. The
1376 wrapper function should be called "__wrap_symbol". If it wishes to
1377 call the system function, it should call "__real_symbol".
1378
1379 Here is a trivial example:
1380
1381 void *
1382 __wrap_malloc (size_t c)
1383 {
1384 printf ("malloc called with %zu\n", c);
1385 return __real_malloc (c);
1386 }
1387
1388 If you link other code with this file using --wrap malloc, then all
1389 calls to "malloc" will call the function "__wrap_malloc" instead.
1390 The call to "__real_malloc" in "__wrap_malloc" will call the real
1391 "malloc" function.
1392
1393 You may wish to provide a "__real_malloc" function as well, so that
1394 links without the --wrap option will succeed. If you do this, you
1395 should not put the definition of "__real_malloc" in the same file
1396 as "__wrap_malloc"; if you do, the assembler may resolve the call
1397 before the linker has a chance to wrap it to "malloc".
1398
1399 --eh-frame-hdr
1400 Request creation of ".eh_frame_hdr" section and ELF
1401 "PT_GNU_EH_FRAME" segment header.
1402
1403 --enable-new-dtags
1404 --disable-new-dtags
1405 This linker can create the new dynamic tags in ELF. But the older
1406 ELF systems may not understand them. If you specify
1407 --enable-new-dtags, the dynamic tags will be created as needed. If
1408 you specify --disable-new-dtags, no new dynamic tags will be cre‐
1409 ated. By default, the new dynamic tags are not created. Note that
1410 those options are only available for ELF systems.
1411
1412 --hash-size=number
1413 Set the default size of the linker's hash tables to a prime number
1414 close to number. Increasing this value can reduce the length of
1415 time it takes the linker to perform its tasks, at the expense of
1416 increasing the linker's memory requirements. Similarly reducing
1417 this value can reduce the memory requirements at the expense of
1418 speed.
1419
1420 --hash-style=style
1421 Set the type of linker's hash table(s). style can be either "sysv"
1422 for classic ELF ".hash" section, "gnu" for new style GNU
1423 ".gnu.hash" section or "both" for both the classic ELF ".hash" and
1424 new style GNU ".gnu.hash" hash tables. The default is "sysv".
1425
1426 --reduce-memory-overheads
1427 This option reduces memory requirements at ld runtime, at the
1428 expense of linking speed. This was introduced to select the old
1429 O(n^2) algorithm for link map file generation, rather than the new
1430 O(n) algorithm which uses about 40% more memory for symbol storage.
1431
1432 Another effect of the switch is to set the default hash table size
1433 to 1021, which again saves memory at the cost of lengthening the
1434 linker's run time. This is not done however if the --hash-size
1435 switch has been used.
1436
1437 The --reduce-memory-overheads switch may be also be used to enable
1438 other tradeoffs in future versions of the linker.
1439
1440 --build-id
1441 --build-id=style
1442 Request creation of ".note.gnu.build-id" ELF note section. The
1443 contents of the note are unique bits identifying this linked file.
1444 style can be "uuid" to use 128 random bits, "sha1" to use a 160-bit
1445 SHA1 hash on the normative parts of the output contents, "md5" to
1446 use a 128-bit MD5 hash on the normative parts of the output con‐
1447 tents, or "0xhexstring" to use a chosen bit string specified as an
1448 even number of hexadecimal digits ("-" and ":" characters between
1449 digit pairs are ignored). If style is omitted, "sha1" is used.
1450
1451 The "md5" and "sha1" styles produces an identifier that is always
1452 the same in an identical output file, but will be unique among all
1453 nonidentical output files. It is not intended to be compared as a
1454 checksum for the file's contents. A linked file may be changed
1455 later by other tools, but the build ID bit string identifying the
1456 original linked file does not change.
1457
1458 Passing "none" for style disables the setting from any "--build-id"
1459 options earlier on the command line.
1460
1461 The i386 PE linker supports the -shared option, which causes the output
1462 to be a dynamically linked library (DLL) instead of a normal exe‐
1463 cutable. You should name the output "*.dll" when you use this option.
1464 In addition, the linker fully supports the standard "*.def" files,
1465 which may be specified on the linker command line like an object file
1466 (in fact, it should precede archives it exports symbols from, to ensure
1467 that they get linked in, just like a normal object file).
1468
1469 In addition to the options common to all targets, the i386 PE linker
1470 support additional command line options that are specific to the i386
1471 PE target. Options that take values may be separated from their values
1472 by either a space or an equals sign.
1473
1474 --add-stdcall-alias
1475 If given, symbols with a stdcall suffix (@nn) will be exported as-
1476 is and also with the suffix stripped. [This option is specific to
1477 the i386 PE targeted port of the linker]
1478
1479 --base-file file
1480 Use file as the name of a file in which to save the base addresses
1481 of all the relocations needed for generating DLLs with dlltool.
1482 [This is an i386 PE specific option]
1483
1484 --dll
1485 Create a DLL instead of a regular executable. You may also use
1486 -shared or specify a "LIBRARY" in a given ".def" file. [This
1487 option is specific to the i386 PE targeted port of the linker]
1488
1489 --enable-stdcall-fixup
1490 --disable-stdcall-fixup
1491 If the link finds a symbol that it cannot resolve, it will attempt
1492 to do "fuzzy linking" by looking for another defined symbol that
1493 differs only in the format of the symbol name (cdecl vs stdcall)
1494 and will resolve that symbol by linking to the match. For example,
1495 the undefined symbol "_foo" might be linked to the function
1496 "_foo@12", or the undefined symbol "_bar@16" might be linked to the
1497 function "_bar". When the linker does this, it prints a warning,
1498 since it normally should have failed to link, but sometimes import
1499 libraries generated from third-party dlls may need this feature to
1500 be usable. If you specify --enable-stdcall-fixup, this feature is
1501 fully enabled and warnings are not printed. If you specify --dis‐
1502 able-stdcall-fixup, this feature is disabled and such mismatches
1503 are considered to be errors. [This option is specific to the i386
1504 PE targeted port of the linker]
1505
1506 --export-all-symbols
1507 If given, all global symbols in the objects used to build a DLL
1508 will be exported by the DLL. Note that this is the default if
1509 there otherwise wouldn't be any exported symbols. When symbols are
1510 explicitly exported via DEF files or implicitly exported via func‐
1511 tion attributes, the default is to not export anything else unless
1512 this option is given. Note that the symbols "DllMain@12", "DllEn‐
1513 tryPoint@0", "DllMainCRTStartup@12", and "impure_ptr" will not be
1514 automatically exported. Also, symbols imported from other DLLs
1515 will not be re-exported, nor will symbols specifying the DLL's
1516 internal layout such as those beginning with "_head_" or ending
1517 with "_iname". In addition, no symbols from "libgcc", "libstd++",
1518 "libmingw32", or "crtX.o" will be exported. Symbols whose names
1519 begin with "__rtti_" or "__builtin_" will not be exported, to help
1520 with C++ DLLs. Finally, there is an extensive list of cygwin-pri‐
1521 vate symbols that are not exported (obviously, this applies on when
1522 building DLLs for cygwin targets). These cygwin-excludes are:
1523 "_cygwin_dll_entry@12", "_cygwin_crt0_common@8", "_cygwin_noncyg‐
1524 win_dll_entry@12", "_fmode", "_impure_ptr", "cygwin_attach_dll",
1525 "cygwin_premain0", "cygwin_premain1", "cygwin_premain2", "cyg‐
1526 win_premain3", and "environ". [This option is specific to the i386
1527 PE targeted port of the linker]
1528
1529 --exclude-symbols symbol,symbol,...
1530 Specifies a list of symbols which should not be automatically
1531 exported. The symbol names may be delimited by commas or colons.
1532 [This option is specific to the i386 PE targeted port of the
1533 linker]
1534
1535 --file-alignment
1536 Specify the file alignment. Sections in the file will always begin
1537 at file offsets which are multiples of this number. This defaults
1538 to 512. [This option is specific to the i386 PE targeted port of
1539 the linker]
1540
1541 --heap reserve
1542 --heap reserve,commit
1543 Specify the number of bytes of memory to reserve (and optionally
1544 commit) to be used as heap for this program. The default is 1Mb
1545 reserved, 4K committed. [This option is specific to the i386 PE
1546 targeted port of the linker]
1547
1548 --image-base value
1549 Use value as the base address of your program or dll. This is the
1550 lowest memory location that will be used when your program or dll
1551 is loaded. To reduce the need to relocate and improve performance
1552 of your dlls, each should have a unique base address and not over‐
1553 lap any other dlls. The default is 0x400000 for executables, and
1554 0x10000000 for dlls. [This option is specific to the i386 PE tar‐
1555 geted port of the linker]
1556
1557 --kill-at
1558 If given, the stdcall suffixes (@nn) will be stripped from symbols
1559 before they are exported. [This option is specific to the i386 PE
1560 targeted port of the linker]
1561
1562 --large-address-aware
1563 If given, the appropriate bit in the "Characteristics" field of the
1564 COFF header is set to indicate that this executable supports vir‐
1565 tual addresses greater than 2 gigabytes. This should be used in
1566 conjunction with the /3GB or /USERVA=value megabytes switch in the
1567 "[operating systems]" section of the BOOT.INI. Otherwise, this bit
1568 has no effect. [This option is specific to PE targeted ports of
1569 the linker]
1570
1571 --major-image-version value
1572 Sets the major number of the "image version". Defaults to 1.
1573 [This option is specific to the i386 PE targeted port of the
1574 linker]
1575
1576 --major-os-version value
1577 Sets the major number of the "os version". Defaults to 4. [This
1578 option is specific to the i386 PE targeted port of the linker]
1579
1580 --major-subsystem-version value
1581 Sets the major number of the "subsystem version". Defaults to 4.
1582 [This option is specific to the i386 PE targeted port of the
1583 linker]
1584
1585 --minor-image-version value
1586 Sets the minor number of the "image version". Defaults to 0.
1587 [This option is specific to the i386 PE targeted port of the
1588 linker]
1589
1590 --minor-os-version value
1591 Sets the minor number of the "os version". Defaults to 0. [This
1592 option is specific to the i386 PE targeted port of the linker]
1593
1594 --minor-subsystem-version value
1595 Sets the minor number of the "subsystem version". Defaults to 0.
1596 [This option is specific to the i386 PE targeted port of the
1597 linker]
1598
1599 --output-def file
1600 The linker will create the file file which will contain a DEF file
1601 corresponding to the DLL the linker is generating. This DEF file
1602 (which should be called "*.def") may be used to create an import
1603 library with "dlltool" or may be used as a reference to automati‐
1604 cally or implicitly exported symbols. [This option is specific to
1605 the i386 PE targeted port of the linker]
1606
1607 --out-implib file
1608 The linker will create the file file which will contain an import
1609 lib corresponding to the DLL the linker is generating. This import
1610 lib (which should be called "*.dll.a" or "*.a" may be used to link
1611 clients against the generated DLL; this behaviour makes it possible
1612 to skip a separate "dlltool" import library creation step. [This
1613 option is specific to the i386 PE targeted port of the linker]
1614
1615 --enable-auto-image-base
1616 Automatically choose the image base for DLLs, unless one is speci‐
1617 fied using the "--image-base" argument. By using a hash generated
1618 from the dllname to create unique image bases for each DLL, in-mem‐
1619 ory collisions and relocations which can delay program execution
1620 are avoided. [This option is specific to the i386 PE targeted port
1621 of the linker]
1622
1623 --disable-auto-image-base
1624 Do not automatically generate a unique image base. If there is no
1625 user-specified image base ("--image-base") then use the platform
1626 default. [This option is specific to the i386 PE targeted port of
1627 the linker]
1628
1629 --dll-search-prefix string
1630 When linking dynamically to a dll without an import library, search
1631 for "<string><basename>.dll" in preference to "lib<basename>.dll".
1632 This behaviour allows easy distinction between DLLs built for the
1633 various "subplatforms": native, cygwin, uwin, pw, etc. For
1634 instance, cygwin DLLs typically use "--dll-search-prefix=cyg".
1635 [This option is specific to the i386 PE targeted port of the
1636 linker]
1637
1638 --enable-auto-import
1639 Do sophisticated linking of "_symbol" to "__imp__symbol" for DATA
1640 imports from DLLs, and create the necessary thunking symbols when
1641 building the import libraries with those DATA exports. Note: Use of
1642 the 'auto-import' extension will cause the text section of the
1643 image file to be made writable. This does not conform to the PE-
1644 COFF format specification published by Microsoft.
1645
1646 Note - use of the 'auto-import' extension will also cause read only
1647 data which would normally be placed into the .rdata section to be
1648 placed into the .data section instead. This is in order to work
1649 around a problem with consts that is described here:
1650 http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
1651
1652 Using 'auto-import' generally will 'just work' -- but sometimes you
1653 may see this message:
1654
1655 "variable '<var>' can't be auto-imported. Please read the documen‐
1656 tation for ld's "--enable-auto-import" for details."
1657
1658 This message occurs when some (sub)expression accesses an address
1659 ultimately given by the sum of two constants (Win32 import tables
1660 only allow one). Instances where this may occur include accesses
1661 to member fields of struct variables imported from a DLL, as well
1662 as using a constant index into an array variable imported from a
1663 DLL. Any multiword variable (arrays, structs, long long, etc) may
1664 trigger this error condition. However, regardless of the exact
1665 data type of the offending exported variable, ld will always detect
1666 it, issue the warning, and exit.
1667
1668 There are several ways to address this difficulty, regardless of
1669 the data type of the exported variable:
1670
1671 One way is to use --enable-runtime-pseudo-reloc switch. This leaves
1672 the task of adjusting references in your client code for runtime
1673 environment, so this method works only when runtime environment
1674 supports this feature.
1675
1676 A second solution is to force one of the 'constants' to be a vari‐
1677 able -- that is, unknown and un-optimizable at compile time. For
1678 arrays, there are two possibilities: a) make the indexee (the
1679 array's address) a variable, or b) make the 'constant' index a
1680 variable. Thus:
1681
1682 extern type extern_array[];
1683 extern_array[1] -->
1684 { volatile type *t=extern_array; t[1] }
1685
1686 or
1687
1688 extern type extern_array[];
1689 extern_array[1] -->
1690 { volatile int t=1; extern_array[t] }
1691
1692 For structs (and most other multiword data types) the only option
1693 is to make the struct itself (or the long long, or the ...) vari‐
1694 able:
1695
1696 extern struct s extern_struct;
1697 extern_struct.field -->
1698 { volatile struct s *t=&extern_struct; t->field }
1699
1700 or
1701
1702 extern long long extern_ll;
1703 extern_ll -->
1704 { volatile long long * local_ll=&extern_ll; *local_ll }
1705
1706 A third method of dealing with this difficulty is to abandon
1707 'auto-import' for the offending symbol and mark it with
1708 "__declspec(dllimport)". However, in practise that requires using
1709 compile-time #defines to indicate whether you are building a DLL,
1710 building client code that will link to the DLL, or merely build‐
1711 ing/linking to a static library. In making the choice between the
1712 various methods of resolving the 'direct address with constant off‐
1713 set' problem, you should consider typical real-world usage:
1714
1715 Original:
1716
1717 --foo.h
1718 extern int arr[];
1719 --foo.c
1720 #include "foo.h"
1721 void main(int argc, char **argv){
1722 printf("%d\n",arr[1]);
1723 }
1724
1725 Solution 1:
1726
1727 --foo.h
1728 extern int arr[];
1729 --foo.c
1730 #include "foo.h"
1731 void main(int argc, char **argv){
1732 /* This workaround is for win32 and cygwin; do not "optimize" */
1733 volatile int *parr = arr;
1734 printf("%d\n",parr[1]);
1735 }
1736
1737 Solution 2:
1738
1739 --foo.h
1740 /* Note: auto-export is assumed (no __declspec(dllexport)) */
1741 #if (defined(_WIN32) ⎪⎪ defined(__CYGWIN__)) && \
1742 !(defined(FOO_BUILD_DLL) ⎪⎪ defined(FOO_STATIC))
1743 #define FOO_IMPORT __declspec(dllimport)
1744 #else
1745 #define FOO_IMPORT
1746 #endif
1747 extern FOO_IMPORT int arr[];
1748 --foo.c
1749 #include "foo.h"
1750 void main(int argc, char **argv){
1751 printf("%d\n",arr[1]);
1752 }
1753
1754 A fourth way to avoid this problem is to re-code your library to
1755 use a functional interface rather than a data interface for the
1756 offending variables (e.g. set_foo() and get_foo() accessor func‐
1757 tions). [This option is specific to the i386 PE targeted port of
1758 the linker]
1759
1760 --disable-auto-import
1761 Do not attempt to do sophisticated linking of "_symbol" to
1762 "__imp__symbol" for DATA imports from DLLs. [This option is spe‐
1763 cific to the i386 PE targeted port of the linker]
1764
1765 --enable-runtime-pseudo-reloc
1766 If your code contains expressions described in --enable-auto-import
1767 section, that is, DATA imports from DLL with non-zero offset, this
1768 switch will create a vector of 'runtime pseudo relocations' which
1769 can be used by runtime environment to adjust references to such
1770 data in your client code. [This option is specific to the i386 PE
1771 targeted port of the linker]
1772
1773 --disable-runtime-pseudo-reloc
1774 Do not create pseudo relocations for non-zero offset DATA imports
1775 from DLLs. This is the default. [This option is specific to the
1776 i386 PE targeted port of the linker]
1777
1778 --enable-extra-pe-debug
1779 Show additional debug info related to auto-import symbol thunking.
1780 [This option is specific to the i386 PE targeted port of the
1781 linker]
1782
1783 --section-alignment
1784 Sets the section alignment. Sections in memory will always begin
1785 at addresses which are a multiple of this number. Defaults to
1786 0x1000. [This option is specific to the i386 PE targeted port of
1787 the linker]
1788
1789 --stack reserve
1790 --stack reserve,commit
1791 Specify the number of bytes of memory to reserve (and optionally
1792 commit) to be used as stack for this program. The default is 2Mb
1793 reserved, 4K committed. [This option is specific to the i386 PE
1794 targeted port of the linker]
1795
1796 --subsystem which
1797 --subsystem which:major
1798 --subsystem which:major.minor
1799 Specifies the subsystem under which your program will execute. The
1800 legal values for which are "native", "windows", "console", "posix",
1801 and "xbox". You may optionally set the subsystem version also.
1802 Numeric values are also accepted for which. [This option is spe‐
1803 cific to the i386 PE targeted port of the linker]
1804
1805 The 68HC11 and 68HC12 linkers support specific options to control the
1806 memory bank switching mapping and trampoline code generation.
1807
1808 --no-trampoline
1809 This option disables the generation of trampoline. By default a
1810 trampoline is generated for each far function which is called using
1811 a "jsr" instruction (this happens when a pointer to a far function
1812 is taken).
1813
1814 --bank-window name
1815 This option indicates to the linker the name of the memory region
1816 in the MEMORY specification that describes the memory bank window.
1817 The definition of such region is then used by the linker to compute
1818 paging and addresses within the memory window.
1819
1820 The following options are supported to control handling of GOT genera‐
1821 tion when linking for 68K targets.
1822
1823 --got=type
1824 This option tells the linker which GOT generation scheme to use.
1825 type should be one of single, negative, multigot or target. For
1826 more information refer to the Info entry for ld.
1827
1829 You can change the behaviour of ld with the environment variables "GNU‐
1830 TARGET", "LDEMULATION" and "COLLECT_NO_DEMANGLE".
1831
1832 "GNUTARGET" determines the input-file object format if you don't use -b
1833 (or its synonym --format). Its value should be one of the BFD names
1834 for an input format. If there is no "GNUTARGET" in the environment, ld
1835 uses the natural format of the target. If "GNUTARGET" is set to
1836 "default" then BFD attempts to discover the input format by examining
1837 binary input files; this method often succeeds, but there are potential
1838 ambiguities, since there is no method of ensuring that the magic number
1839 used to specify object-file formats is unique. However, the configura‐
1840 tion procedure for BFD on each system places the conventional format
1841 for that system first in the search-list, so ambiguities are resolved
1842 in favor of convention.
1843
1844 "LDEMULATION" determines the default emulation if you don't use the -m
1845 option. The emulation can affect various aspects of linker behaviour,
1846 particularly the default linker script. You can list the available
1847 emulations with the --verbose or -V options. If the -m option is not
1848 used, and the "LDEMULATION" environment variable is not defined, the
1849 default emulation depends upon how the linker was configured.
1850
1851 Normally, the linker will default to demangling symbols. However, if
1852 "COLLECT_NO_DEMANGLE" is set in the environment, then it will default
1853 to not demangling symbols. This environment variable is used in a sim‐
1854 ilar fashion by the "gcc" linker wrapper program. The default may be
1855 overridden by the --demangle and --no-demangle options.
1856
1858 ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and the Info entries
1859 for binutils and ld.
1860
1862 Copyright (c) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002,
1863 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
1864
1865 Permission is granted to copy, distribute and/or modify this document
1866 under the terms of the GNU Free Documentation License, Version 1.1 or
1867 any later version published by the Free Software Foundation; with no
1868 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
1869 Texts. A copy of the license is included in the section entitled "GNU
1870 Free Documentation License".
1871
1872
1873
1874binutils-2.18.90 2008-09-10 LD(1)