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