forked from bsdjhb/gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathld.texi
8798 lines (7548 loc) · 332 KB
/
ld.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo
@setfilename ld.info
@c Copyright (C) 1991-2019 Free Software Foundation, Inc.
@syncodeindex ky cp
@c man begin INCLUDE
@include configdoc.texi
@c (configdoc.texi is generated by the Makefile)
@include bfdver.texi
@c man end
@c @smallbook
@macro gcctabopt{body}
@code{\body\}
@end macro
@c man begin NAME
@ifset man
@c Configure for the generation of man pages
@set UsesEnvVars
@set GENERIC
@set ARM
@set C6X
@set CSKY
@set H8300
@set HPPA
@set M68HC11
@set M68K
@set MIPS
@set MMIX
@set MSP430
@set NDS32
@set NIOSII
@set POWERPC
@set POWERPC64
@set Renesas
@set S/390
@set SPU
@set TICOFF
@set WIN32
@set XTENSA
@end ifset
@c man end
@ifnottex
@dircategory Software development
@direntry
* Ld: (ld). The GNU linker.
@end direntry
@end ifnottex
@copying
This file documents the @sc{gnu} linker LD
@ifset VERSION_PACKAGE
@value{VERSION_PACKAGE}
@end ifset
version @value{VERSION}.
Copyright @copyright{} 1991-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts. A copy of the license is included in the
section entitled ``GNU Free Documentation License''.
@end copying
@iftex
@finalout
@setchapternewpage odd
@settitle The GNU linker
@titlepage
@title The GNU linker
@sp 1
@subtitle @code{ld}
@ifset VERSION_PACKAGE
@subtitle @value{VERSION_PACKAGE}
@end ifset
@subtitle Version @value{VERSION}
@author Steve Chamberlain
@author Ian Lance Taylor
@page
@tex
{\parskip=0pt
\hfill Red Hat Inc\par
\hfill nickc\@credhat.com, doc\@redhat.com\par
\hfill {\it The GNU linker}\par
\hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
}
\global\parindent=0pt % Steve likes it this way.
@end tex
@vskip 0pt plus 1filll
@c man begin COPYRIGHT
Copyright @copyright{} 1991-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, with no Front-Cover Texts, and with no
Back-Cover Texts. A copy of the license is included in the
section entitled ``GNU Free Documentation License''.
@c man end
@end titlepage
@end iftex
@contents
@c FIXME: Talk about importance of *order* of args, cmds to linker!
@ifnottex
@node Top
@top LD
This file documents the @sc{gnu} linker ld
@ifset VERSION_PACKAGE
@value{VERSION_PACKAGE}
@end ifset
version @value{VERSION}.
This document is distributed under the terms of the GNU Free
Documentation License version 1.3. A copy of the license is included
in the section entitled ``GNU Free Documentation License''.
@menu
* Overview:: Overview
* Invocation:: Invocation
* Scripts:: Linker Scripts
@ifset GENERIC
* Machine Dependent:: Machine Dependent Features
@end ifset
@ifclear GENERIC
@ifset H8300
* H8/300:: ld and the H8/300
@end ifset
@ifset Renesas
* Renesas:: ld and other Renesas micros
@end ifset
@ifset ARM
* ARM:: ld and the ARM family
@end ifset
@ifset M68HC11
* M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families
@end ifset
@ifset HPPA
* HPPA ELF32:: ld and HPPA 32-bit ELF
@end ifset
@ifset M68K
* M68K:: ld and Motorola 68K family
@end ifset
@ifset MIPS
* MIPS:: ld and MIPS family
@end ifset
@ifset POWERPC
* PowerPC ELF32:: ld and PowerPC 32-bit ELF Support
@end ifset
@ifset POWERPC64
* PowerPC64 ELF64:: ld and PowerPC64 64-bit ELF Support
@end ifset
@ifset S/390
* S/390 ELF:: ld and S/390 ELF Support
@end ifset
@ifset SPU
* SPU ELF:: ld and SPU ELF Support
@end ifset
@ifset TICOFF
* TI COFF:: ld and the TI COFF
@end ifset
@ifset WIN32
* Win32:: ld and WIN32 (cygwin/mingw)
@end ifset
@ifset XTENSA
* Xtensa:: ld and Xtensa Processors
@end ifset
@end ifclear
@ifclear SingleFormat
* BFD:: BFD
@end ifclear
@c Following blank line required for remaining bug in makeinfo conds/menus
* Reporting Bugs:: Reporting Bugs
* MRI:: MRI Compatible Script Files
* GNU Free Documentation License:: GNU Free Documentation License
* LD Index:: LD Index
@end menu
@end ifnottex
@node Overview
@chapter Overview
@cindex @sc{gnu} linker
@cindex what is this?
@ifset man
@c man begin SYNOPSIS
ld [@b{options}] @var{objfile} @dots{}
@c man end
@c man begin SEEALSO
ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
the Info entries for @file{binutils} and
@file{ld}.
@c man end
@end ifset
@c man begin DESCRIPTION
@command{ld} combines a number of object and archive files, relocates
their data and ties up symbol references. Usually the last step in
compiling a program is to run @command{ld}.
@command{ld} accepts Linker Command Language files written in
a superset of AT&T's Link Editor Command Language syntax,
to provide explicit and total control over the linking process.
@ifset man
@c For the man only
This man page does not describe the command language; see the
@command{ld} entry in @code{info} for full details on the command
language and on other aspects of the GNU linker.
@end ifset
@ifclear SingleFormat
This version of @command{ld} uses the general purpose BFD libraries
to operate on object files. This allows @command{ld} to read, combine, and
write object files in many different formats---for example, COFF or
@code{a.out}. Different formats may be linked together to produce any
available kind of object file. @xref{BFD}, for more information.
@end ifclear
Aside from its flexibility, the @sc{gnu} linker is more helpful than other
linkers in providing diagnostic information. Many linkers abandon
execution immediately upon encountering an error; whenever possible,
@command{ld} continues executing, allowing you to identify other errors
(or, in some cases, to get an output file in spite of the error).
@c man end
@node Invocation
@chapter Invocation
@c man begin DESCRIPTION
The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
and to be as compatible as possible with other linkers. As a result,
you have many choices to control its behavior.
@c man end
@ifset UsesEnvVars
@menu
* Options:: Command-line Options
* Environment:: Environment Variables
@end menu
@node Options
@section Command-line Options
@end ifset
@cindex command line
@cindex options
@c man begin OPTIONS
The linker supports a plethora of command-line options, but in actual
practice few of them are used in any particular context.
@cindex standard Unix system
For instance, a frequent use of @command{ld} is to link standard Unix
object files on a standard, supported Unix system. On such a system, to
link a file @code{hello.o}:
@smallexample
ld -o @var{output} /lib/crt0.o hello.o -lc
@end smallexample
This tells @command{ld} to produce a file called @var{output} as the
result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
the library @code{libc.a}, which will come from the standard search
directories. (See the discussion of the @samp{-l} option below.)
Some of the command-line options to @command{ld} may be specified at any
point in the command line. However, options which refer to files, such
as @samp{-l} or @samp{-T}, cause the file to be read at the point at
which the option appears in the command line, relative to the object
files and other file options. Repeating non-file options with a
different argument will either have no further effect, or override prior
occurrences (those further to the left on the command line) of that
option. Options which may be meaningfully specified more than once are
noted in the descriptions below.
@cindex object files
Non-option arguments are object files or archives which are to be linked
together. They may follow, precede, or be mixed in with command-line
options, except that an object file argument may not be placed between
an option and its argument.
Usually the linker is invoked with at least one object file, but you can
specify other forms of binary input files using @samp{-l}, @samp{-R},
and the script command language. If @emph{no} binary input files at all
are specified, the linker does not produce any output, and issues the
message @samp{No input files}.
If the linker cannot recognize the format of an object file, it will
assume that it is a linker script. A script specified in this way
augments the main linker script used for the link (either the default
linker script or the one specified by using @samp{-T}). This feature
permits the linker to link against a file which appears to be an object
or an archive, but actually merely defines some symbol values, or uses
@code{INPUT} or @code{GROUP} to load other objects. Specifying a
script in this way merely augments the main linker script, with the
extra commands placed after the main script; use the @samp{-T} option
to replace the default linker script entirely, but note the effect of
the @code{INSERT} command. @xref{Scripts}.
For options whose names are a single letter,
option arguments must either follow the option letter without intervening
whitespace, or be given as separate arguments immediately following the
option that requires them.
For options whose names are multiple letters, either one dash or two can
precede the option name; for example, @samp{-trace-symbol} and
@samp{--trace-symbol} are equivalent. Note---there is one exception to
this rule. Multiple letter options that start with a lower case 'o' can
only be preceded by two dashes. This is to reduce confusion with the
@samp{-o} option. So for example @samp{-omagic} sets the output file
name to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the
output.
Arguments to multiple-letter options must either be separated from the
option name by an equals sign, or be given as separate arguments
immediately following the option that requires them. For example,
@samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent.
Unique abbreviations of the names of multiple-letter options are
accepted.
Note---if the linker is being invoked indirectly, via a compiler driver
(e.g. @samp{gcc}) then all the linker command-line options should be
prefixed by @samp{-Wl,} (or whatever is appropriate for the particular
compiler driver) like this:
@smallexample
gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
@end smallexample
This is important, because otherwise the compiler driver program may
silently drop the linker options, resulting in a bad link. Confusion
may also arise when passing options that require values through a
driver, as the use of a space between option and argument acts as
a separator, and causes the driver to pass only the option to the linker
and the argument to the compiler. In this case, it is simplest to use
the joined forms of both single- and multiple-letter options, such as:
@smallexample
gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
@end smallexample
Here is a table of the generic command-line switches accepted by the GNU
linker:
@table @gcctabopt
@include at-file.texi
@kindex -a @var{keyword}
@item -a @var{keyword}
This option is supported for HP/UX compatibility. The @var{keyword}
argument must be one of the strings @samp{archive}, @samp{shared}, or
@samp{default}. @samp{-aarchive} is functionally equivalent to
@samp{-Bstatic}, and the other two keywords are functionally equivalent
to @samp{-Bdynamic}. This option may be used any number of times.
@kindex --audit @var{AUDITLIB}
@item --audit @var{AUDITLIB}
Adds @var{AUDITLIB} to the @code{DT_AUDIT} entry of the dynamic section.
@var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
specified in the library. If specified multiple times @code{DT_AUDIT}
will contain a colon separated list of audit interfaces to use. If the linker
finds an object with an audit entry while searching for shared libraries,
it will add a corresponding @code{DT_DEPAUDIT} entry in the output file.
This option is only meaningful on ELF platforms supporting the rtld-audit
interface.
@ifclear SingleFormat
@cindex binary input format
@kindex -b @var{format}
@kindex --format=@var{format}
@cindex input format
@cindex input format
@item -b @var{input-format}
@itemx --format=@var{input-format}
@command{ld} may be configured to support more than one kind of object
file. If your @command{ld} is configured this way, you can use the
@samp{-b} option to specify the binary format for input object files
that follow this option on the command line. Even when @command{ld} is
configured to support alternative object formats, you don't usually need
to specify this, as @command{ld} should be configured to expect as a
default input format the most usual format on each machine.
@var{input-format} is a text string, the name of a particular format
supported by the BFD libraries. (You can list the available binary
formats with @samp{objdump -i}.)
@xref{BFD}.
You may want to use this option if you are linking files with an unusual
binary format. You can also use @samp{-b} to switch formats explicitly (when
linking object files of different formats), by including
@samp{-b @var{input-format}} before each group of object files in a
particular format.
The default format is taken from the environment variable
@code{GNUTARGET}.
@ifset UsesEnvVars
@xref{Environment}.
@end ifset
You can also define the input format from a script, using the command
@code{TARGET};
@ifclear man
see @ref{Format Commands}.
@end ifclear
@end ifclear
@kindex -c @var{MRI-cmdfile}
@kindex --mri-script=@var{MRI-cmdfile}
@cindex compatibility, MRI
@item -c @var{MRI-commandfile}
@itemx --mri-script=@var{MRI-commandfile}
For compatibility with linkers produced by MRI, @command{ld} accepts script
files written in an alternate, restricted command language, described in
@ifclear man
@ref{MRI,,MRI Compatible Script Files}.
@end ifclear
@ifset man
the MRI Compatible Script Files section of GNU ld documentation.
@end ifset
Introduce MRI script files with
the option @samp{-c}; use the @samp{-T} option to run linker
scripts written in the general-purpose @command{ld} scripting language.
If @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories
specified by any @samp{-L} options.
@cindex common allocation
@kindex -d
@kindex -dc
@kindex -dp
@item -d
@itemx -dc
@itemx -dp
These three options are equivalent; multiple forms are supported for
compatibility with other linkers. They assign space to common symbols
even if a relocatable output file is specified (with @samp{-r}). The
script command @code{FORCE_COMMON_ALLOCATION} has the same effect.
@xref{Miscellaneous Commands}.
@kindex --depaudit @var{AUDITLIB}
@kindex -P @var{AUDITLIB}
@item --depaudit @var{AUDITLIB}
@itemx -P @var{AUDITLIB}
Adds @var{AUDITLIB} to the @code{DT_DEPAUDIT} entry of the dynamic section.
@var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
specified in the library. If specified multiple times @code{DT_DEPAUDIT}
will contain a colon separated list of audit interfaces to use. This
option is only meaningful on ELF platforms supporting the rtld-audit interface.
The -P option is provided for Solaris compatibility.
@cindex entry point, from command line
@kindex -e @var{entry}
@kindex --entry=@var{entry}
@item -e @var{entry}
@itemx --entry=@var{entry}
Use @var{entry} as the explicit symbol for beginning execution of your
program, rather than the default entry point. If there is no symbol
named @var{entry}, the linker will try to parse @var{entry} as a number,
and use that as the entry address (the number will be interpreted in
base 10; you may use a leading @samp{0x} for base 16, or a leading
@samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults
and other ways of specifying the entry point.
@kindex --exclude-libs
@item --exclude-libs @var{lib},@var{lib},...
Specifies a list of archive libraries from which symbols should not be automatically
exported. The library names may be delimited by commas or colons. Specifying
@code{--exclude-libs ALL} excludes symbols in all archive libraries from
automatic export. This option is available only for the i386 PE targeted
port of the linker and for ELF targeted ports. For i386 PE, symbols
explicitly listed in a .def file are still exported, regardless of this
option. For ELF targeted ports, symbols affected by this option will
be treated as hidden.
@kindex --exclude-modules-for-implib
@item --exclude-modules-for-implib @var{module},@var{module},...
Specifies a list of object files or archive members, from which symbols
should not be automatically exported, but which should be copied wholesale
into the import library being generated during the link. The module names
may be delimited by commas or colons, and must match exactly the filenames
used by @command{ld} to open the files; for archive members, this is simply
the member name, but for object files the name listed must include and
match precisely any path used to specify the input file on the linker's
command-line. This option is available only for the i386 PE targeted port
of the linker. Symbols explicitly listed in a .def file are still exported,
regardless of this option.
@cindex dynamic symbol table
@kindex -E
@kindex --export-dynamic
@kindex --no-export-dynamic
@item -E
@itemx --export-dynamic
@itemx --no-export-dynamic
When creating a dynamically linked executable, using the @option{-E}
option or the @option{--export-dynamic} option causes the linker to add
all symbols to the dynamic symbol table. The dynamic symbol table is the
set of symbols which are visible from dynamic objects at run time.
If you do not use either of these options (or use the
@option{--no-export-dynamic} option to restore the default behavior), the
dynamic symbol table will normally contain only those symbols which are
referenced by some dynamic object mentioned in the link.
If you use @code{dlopen} to load a dynamic object which needs to refer
back to the symbols defined by the program, rather than some other
dynamic object, then you will probably need to use this option when
linking the program itself.
You can also use the dynamic list to control what symbols should
be added to the dynamic symbol table if the output format supports it.
See the description of @samp{--dynamic-list}.
Note that this option is specific to ELF targeted ports. PE targets
support a similar function to export all symbols from a DLL or EXE; see
the description of @samp{--export-all-symbols} below.
@ifclear SingleFormat
@cindex big-endian objects
@cindex endianness
@kindex -EB
@item -EB
Link big-endian objects. This affects the default output format.
@cindex little-endian objects
@kindex -EL
@item -EL
Link little-endian objects. This affects the default output format.
@end ifclear
@kindex -f @var{name}
@kindex --auxiliary=@var{name}
@item -f @var{name}
@itemx --auxiliary=@var{name}
When creating an ELF shared object, set the internal DT_AUXILIARY field
to the specified name. This tells the dynamic linker that the symbol
table of the shared object should be used as an auxiliary filter on the
symbol table of the shared object @var{name}.
If you later link a program against this filter object, then, when you
run the program, the dynamic linker will see the DT_AUXILIARY field. If
the dynamic linker resolves any symbols from the filter object, it will
first check whether there is a definition in the shared object
@var{name}. If there is one, it will be used instead of the definition
in the filter object. The shared object @var{name} need not exist.
Thus the shared object @var{name} may be used to provide an alternative
implementation of certain functions, perhaps for debugging or for
machine-specific performance.
This option may be specified more than once. The DT_AUXILIARY entries
will be created in the order in which they appear on the command line.
@kindex -F @var{name}
@kindex --filter=@var{name}
@item -F @var{name}
@itemx --filter=@var{name}
When creating an ELF shared object, set the internal DT_FILTER field to
the specified name. This tells the dynamic linker that the symbol table
of the shared object which is being created should be used as a filter
on the symbol table of the shared object @var{name}.
If you later link a program against this filter object, then, when you
run the program, the dynamic linker will see the DT_FILTER field. The
dynamic linker will resolve symbols according to the symbol table of the
filter object as usual, but it will actually link to the definitions
found in the shared object @var{name}. Thus the filter object can be
used to select a subset of the symbols provided by the object
@var{name}.
Some older linkers used the @option{-F} option throughout a compilation
toolchain for specifying object-file format for both input and output
object files.
@ifclear SingleFormat
The @sc{gnu} linker uses other mechanisms for this purpose: the
@option{-b}, @option{--format}, @option{--oformat} options, the
@code{TARGET} command in linker scripts, and the @code{GNUTARGET}
environment variable.
@end ifclear
The @sc{gnu} linker will ignore the @option{-F} option when not
creating an ELF shared object.
@cindex finalization function
@kindex -fini=@var{name}
@item -fini=@var{name}
When creating an ELF executable or shared object, call NAME when the
executable or shared object is unloaded, by setting DT_FINI to the
address of the function. By default, the linker uses @code{_fini} as
the function to call.
@kindex -g
@item -g
Ignored. Provided for compatibility with other tools.
@kindex -G @var{value}
@kindex --gpsize=@var{value}
@cindex object size
@item -G @var{value}
@itemx --gpsize=@var{value}
Set the maximum size of objects to be optimized using the GP register to
@var{size}. This is only meaningful for object file formats such as
MIPS ELF that support putting large and small objects into different
sections. This is ignored for other object file formats.
@cindex runtime library name
@kindex -h @var{name}
@kindex -soname=@var{name}
@item -h @var{name}
@itemx -soname=@var{name}
When creating an ELF shared object, set the internal DT_SONAME field to
the specified name. When an executable is linked with a shared object
which has a DT_SONAME field, then when the executable is run the dynamic
linker will attempt to load the shared object specified by the DT_SONAME
field rather than the using the file name given to the linker.
@kindex -i
@cindex incremental link
@item -i
Perform an incremental link (same as option @samp{-r}).
@cindex initialization function
@kindex -init=@var{name}
@item -init=@var{name}
When creating an ELF executable or shared object, call NAME when the
executable or shared object is loaded, by setting DT_INIT to the address
of the function. By default, the linker uses @code{_init} as the
function to call.
@cindex archive files, from cmd line
@kindex -l @var{namespec}
@kindex --library=@var{namespec}
@item -l @var{namespec}
@itemx --library=@var{namespec}
Add the archive or object file specified by @var{namespec} to the
list of files to link. This option may be used any number of times.
If @var{namespec} is of the form @file{:@var{filename}}, @command{ld}
will search the library path for a file called @var{filename}, otherwise it
will search the library path for a file called @file{lib@var{namespec}.a}.
On systems which support shared libraries, @command{ld} may also search for
files other than @file{lib@var{namespec}.a}. Specifically, on ELF
and SunOS systems, @command{ld} will search a directory for a library
called @file{lib@var{namespec}.so} before searching for one called
@file{lib@var{namespec}.a}. (By convention, a @code{.so} extension
indicates a shared library.) Note that this behavior does not apply
to @file{:@var{filename}}, which always specifies a file called
@var{filename}.
The linker will search an archive only once, at the location where it is
specified on the command line. If the archive defines a symbol which
was undefined in some object which appeared before the archive on the
command line, the linker will include the appropriate file(s) from the
archive. However, an undefined symbol in an object appearing later on
the command line will not cause the linker to search the archive again.
See the @option{-(} option for a way to force the linker to search
archives multiple times.
You may list the same archive multiple times on the command line.
@ifset GENERIC
This type of archive searching is standard for Unix linkers. However,
if you are using @command{ld} on AIX, note that it is different from the
behaviour of the AIX linker.
@end ifset
@cindex search directory, from cmd line
@kindex -L @var{dir}
@kindex --library-path=@var{dir}
@item -L @var{searchdir}
@itemx --library-path=@var{searchdir}
Add path @var{searchdir} to the list of paths that @command{ld} will search
for archive libraries and @command{ld} control scripts. You may use this
option any number of times. The directories are searched in the order
in which they are specified on the command line. Directories specified
on the command line are searched before the default directories. All
@option{-L} options apply to all @option{-l} options, regardless of the
order in which the options appear. @option{-L} options do not affect
how @command{ld} searches for a linker script unless @option{-T}
option is specified.
If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
@samp{--sysroot} option, or specified when the linker is configured.
@ifset UsesEnvVars
The default set of paths searched (without being specified with
@samp{-L}) depends on which emulation mode @command{ld} is using, and in
some cases also on how it was configured. @xref{Environment}.
@end ifset
The paths can also be specified in a link script with the
@code{SEARCH_DIR} command. Directories specified this way are searched
at the point in which the linker script appears in the command line.
@cindex emulation
@kindex -m @var{emulation}
@item -m @var{emulation}
Emulate the @var{emulation} linker. You can list the available
emulations with the @samp{--verbose} or @samp{-V} options.
If the @samp{-m} option is not used, the emulation is taken from the
@code{LDEMULATION} environment variable, if that is defined.
Otherwise, the default emulation depends upon how the linker was
configured.
@cindex link map
@kindex -M
@kindex --print-map
@item -M
@itemx --print-map
Print a link map to the standard output. A link map provides
information about the link, including the following:
@itemize @bullet
@item
Where object files are mapped into memory.
@item
How common symbols are allocated.
@item
All archive members included in the link, with a mention of the symbol
which caused the archive member to be brought in.
@item
The values assigned to symbols.
Note - symbols whose values are computed by an expression which
involves a reference to a previous value of the same symbol may not
have correct result displayed in the link map. This is because the
linker discards intermediate results and only retains the final value
of an expression. Under such circumstances the linker will display
the final value enclosed by square brackets. Thus for example a
linker script containing:
@smallexample
foo = 1
foo = foo * 4
foo = foo + 8
@end smallexample
will produce the following output in the link map if the @option{-M}
option is used:
@smallexample
0x00000001 foo = 0x1
[0x0000000c] foo = (foo * 0x4)
[0x0000000c] foo = (foo + 0x8)
@end smallexample
See @ref{Expressions} for more information about expressions in linker
scripts.
@item
How GNU properties are merged.
When the linker merges input .note.gnu.property sections into one output
.note.gnu.property section, some properties are removed or updated.
These actions are reported in the link map. For example:
@smallexample
Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
@end smallexample
This indicates that property 0xc0000002 is removed from output when
merging properties in @file{foo.o}, whose property 0xc0000002 value
is 0x1, and @file{bar.o}, which doesn't have property 0xc0000002.
@smallexample
Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
@end smallexample
This indicates that property 0xc0010001 value is updated to 0x1 in output
when merging properties in @file{foo.o}, whose 0xc0010001 property value
is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1.
@end itemize
@cindex link map discarded
@kindex --print-map-discarded
@kindex --no-print-map-discarded
@item --print-map-discarded
@itemx --no-print-map-discarded
Print (or do not print) the list of discarded and garbage collected sections
in the link map. Enabled by default.
@kindex -n
@cindex read-only text
@cindex NMAGIC
@kindex --nmagic
@item -n
@itemx --nmagic
Turn off page alignment of sections, and disable linking against shared
libraries. If the output format supports Unix style magic numbers,
mark the output as @code{NMAGIC}.
@kindex -N
@kindex --omagic
@cindex read/write from cmd line
@cindex OMAGIC
@item -N
@itemx --omagic
Set the text and data sections to be readable and writable. Also, do
not page-align the data segment, and disable linking against shared
libraries. If the output format supports Unix style magic numbers,
mark the output as @code{OMAGIC}. Note: Although a writable text section
is allowed for PE-COFF targets, it does not conform to the format
specification published by Microsoft.
@kindex --no-omagic
@cindex OMAGIC
@item --no-omagic
This option negates most of the effects of the @option{-N} option. It
sets the text section to be read-only, and forces the data segment to
be page-aligned. Note - this option does not enable linking against
shared libraries. Use @option{-Bdynamic} for this.
@kindex -o @var{output}
@kindex --output=@var{output}
@cindex naming the output file
@item -o @var{output}
@itemx --output=@var{output}
Use @var{output} as the name for the program produced by @command{ld}; if this
option is not specified, the name @file{a.out} is used by default. The
script command @code{OUTPUT} can also specify the output file name.
@kindex -O @var{level}
@cindex generating optimized output
@item -O @var{level}
If @var{level} is a numeric values greater than zero @command{ld} optimizes
the output. This might take significantly longer and therefore probably
should only be enabled for the final binary. At the moment this
option only affects ELF shared library generation. Future releases of
the linker may make more use of this option. Also currently there is
no difference in the linker's behaviour for different non-zero values
of this option. Again this may change with future releases.
@kindex -plugin @var{name}
@item -plugin @var{name}
Involve a plugin in the linking process. The @var{name} parameter is
the absolute filename of the plugin. Usually this parameter is
automatically added by the complier, when using link time
optimization, but users can also add their own plugins if they so
wish.
Note that the location of the compiler originated plugins is different
from the place where the @command{ar}, @command{nm} and
@command{ranlib} programs search for their plugins. In order for
those commands to make use of a compiler based plugin it must first be
copied into the @file{$@{libdir@}/bfd-plugins} directory. All gcc
based linker plugins are backward compatible, so it is sufficient to
just copy in the newest one.
@kindex --push-state
@cindex push state governing input file handling
@item --push-state
The @option{--push-state} allows to preserve the current state of the
flags which govern the input file handling so that they can all be
restored with one corresponding @option{--pop-state} option.
The option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
@option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
@option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
@option{--no-whole-archive}, @option{-r}, @option{-Ur},
@option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
@option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
One target for this option are specifications for @file{pkg-config}. When
used with the @option{--libs} option all possibly needed libraries are
listed and then possibly linked with all the time. It is better to return
something as follows:
@smallexample
-Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
@end smallexample
@kindex --pop-state
@cindex pop state governing input file handling
@item --pop-state
Undoes the effect of --push-state, restores the previous values of the
flags governing input file handling.
@kindex -q
@kindex --emit-relocs
@cindex retain relocations in final executable
@item -q
@itemx --emit-relocs
Leave relocation sections and contents in fully linked executables.
Post link analysis and optimization tools may need this information in
order to perform correct modifications of executables. This results
in larger executables.
This option is currently only supported on ELF platforms.
@kindex --force-dynamic
@cindex forcing the creation of dynamic sections
@item --force-dynamic
Force the output file to have dynamic sections. This option is specific
to VxWorks targets.
@cindex partial link
@cindex relocatable output
@kindex -r
@kindex --relocatable
@item -r
@itemx --relocatable
Generate relocatable output---i.e., generate an output file that can in
turn serve as input to @command{ld}. This is often called @dfn{partial
linking}. As a side effect, in environments that support standard Unix
magic numbers, this option also sets the output file's magic number to
@code{OMAGIC}.
@c ; see @option{-N}.
If this option is not specified, an absolute file is produced. When
linking C++ programs, this option @emph{will not} resolve references to
constructors; to do that, use @samp{-Ur}.
When an input file does not have the same format as the output file,
partial linking is only supported if that input file does not contain any
relocations. Different output formats can have further restrictions; for
example some @code{a.out}-based formats do not support partial linking
with input files in other formats at all.
This option does the same thing as @samp{-i}.
@kindex -R @var{file}
@kindex --just-symbols=@var{file}
@cindex symbol-only input
@item -R @var{filename}
@itemx --just-symbols=@var{filename}
Read symbol names and their addresses from @var{filename}, but do not
relocate it or include it in the output. This allows your output file
to refer symbolically to absolute locations of memory defined in other
programs. You may use this option more than once.
For compatibility with other ELF linkers, if the @option{-R} option is
followed by a directory name, rather than a file name, it is treated as
the @option{-rpath} option.
@kindex -s
@kindex --strip-all
@cindex strip all symbols
@item -s
@itemx --strip-all
Omit all symbol information from the output file.
@kindex -S
@kindex --strip-debug
@cindex strip debugger symbols
@item -S
@itemx --strip-debug
Omit debugger symbol information (but not all symbols) from the output file.
@kindex --strip-discarded
@kindex --no-strip-discarded
@item --strip-discarded
@itemx --no-strip-discarded
Omit (or do not omit) global symbols defined in discarded sections.
Enabled by default.
@kindex -t
@kindex --trace
@cindex input files, displaying
@item -t
@itemx --trace
Print the names of the input files as @command{ld} processes them. If
@samp{-t} is given twice then members within archives are also printed.
@samp{-t} output is useful to generate a list of all the object files
and scripts involved in linking, for example, when packaging files for
a linker bug report.
@kindex -T @var{script}
@kindex --script=@var{script}
@cindex script files
@item -T @var{scriptfile}
@itemx --script=@var{scriptfile}
Use @var{scriptfile} as the linker script. This script replaces
@command{ld}'s default linker script (rather than adding to it), so
@var{commandfile} must specify everything necessary to describe the
output file. @xref{Scripts}. If @var{scriptfile} does not exist in
the current directory, @code{ld} looks for it in the directories
specified by any preceding @samp{-L} options. Multiple @samp{-T}
options accumulate.
@kindex -dT @var{script}
@kindex --default-script=@var{script}
@cindex script files
@item -dT @var{scriptfile}
@itemx --default-script=@var{scriptfile}
Use @var{scriptfile} as the default linker script. @xref{Scripts}.
This option is similar to the @option{--script} option except that
processing of the script is delayed until after the rest of the