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