* aoutx.h (hash, compare, struct stringtab_entry, add_to_stringtab):
[deliverable/binutils-gdb.git] / ld / ld.1
CommitLineData
0e166a63
RP
1.\" Copyright (c) 1991, 1992 Free Software Foundation
2.\" See section COPYING for conditions for redistribution
3.TH ld 1 "17 August 1992" "cygnus support" "GNU Development Tools"
4.de BP
5.sp
6.ti \-.2i
7\(**
8..
9
10.SH NAME
11ld \- the GNU linker
12
13.SH SYNOPSIS
14.hy 0
15.na
16.TP
17.B ld
18.RB "[\|" \-o "
19.I output\c
20\&\|] \c
8ddef552 21.I objfile\c
0e166a63
RP
22\&.\|.\|.
23.br
24.RB "[\|" \-A\c
25.I architecture\c
26\&\|]
27.RB "[\|" "\-b\ "\c
28.I input-format\c
29\&\|]
30.RB "[\|" \-Bstatic "\|]"
31.RB "[\|" "\-c\ "\c
32.I commandfile\c
33\&\|]
34.RB "[\|" \-d | \-dc | \-dp\c
35\|]
36.br
37.RB "[\|" "\-defsym\ "\c
38.I symbol\c
39\& = \c
40.I expression\c
41\&\|]
42.RB "[\|" "\-e\ "\c
43.I entry\c
44\&\|]
45.RB "[\|" \-F "\|]"
46.RB "[\|" "\-F\ "\c
47.I format\c
48\&\|]
49.RB "[\|" "\-format\ "\c
50.I input-format\c
51\&\|]
52.RB "[\|" \-g "\|]"
8ddef552
DM
53.RB "[\|" \-G\c
54.I size\c
55\&\|]
0e166a63
RP
56.RB "[\|" \-i "\|]"
57.RB "[\|" \-l\c
58.I ar\c
59\&\|]
60.RB "[\|" \-L\c
61.I searchdir\c
62\&\|]
8ddef552 63.RB "[\|" \-M "\|]"
d18a4527
DM
64.RB "[\|" \-Map\c
65.I mapfile\c
66\&\|]
8ddef552
DM
67.RB "[\|" \-m\c
68.I emulation\c
69\&\|]
0e166a63
RP
70.RB "[\|" \-n | \-N "\|]"
71.RB "[\|" \-noinhibit-exec "\|]"
346535cc
DM
72.RB "[\|" "\-oformat\ "\c
73.I output-format\c
74\&\|]
0e166a63
RP
75.RB "[\|" "\-R\ "\c
76.I filename\c
77\&\|]
78.RB "[\|" \-relax "\|]"
79.RB "[\|" \-r | \-Ur "\|]"
80.RB "[\|" \-S "\|]"
81.RB "[\|" \-s "\|]"
82.RB "[\|" "\-T\ "\c
83.I commandfile\c
84\&\|]
85.RB "[\|" "\-Ttext\ "\c
86.I textorg\c
87\&\|]
88.RB "[\|" "\-Tdata\ "\c
89.I dataorg\c
90\&\|]
91.RB "[\|" "\-Tbss\ "\c
92.I bssorg\c
93\&\|]
94.RB "[\|" \-t "\|]"
95.RB "[\|" "\-u\ "\c
96.I sym\c
97\&]
8ddef552 98.RB "[\|" \-V "\|]"
0e166a63
RP
99.RB "[\|" \-v "\|]"
100.RB "[\|" \-X "\|]"
101.RB "[\|" \-x "\|]"
0e166a63
RP
102.ad b
103.hy 1
104.SH DESCRIPTION
105\c
106.B ld\c
107\& combines a number of object and archive files, relocates
108their data and ties up symbol references. Often the last step in
109building a new compiled program to run is a call to \c
110.B ld\c
111\&.
112
113\c
114.B ld\c
115\& accepts Linker Command Language files
116to provide explicit and total control over the linking process.
117This man page does not describe the command language; see the `\|\c
118.B ld\c
119\|' entry in `\|\c
120.B info\c
121\|', or the manual
122.I
123ld: the GNU linker
124\&, for full details on the command language and on other aspects of
125the GNU linker.
126
127This version of \c
128.B ld\c
129\& uses the general purpose BFD libraries
130to operate on object files. This allows \c
131.B ld\c
132\& to read, combine, and
133write object files in many different formats\(em\&for example, COFF or
134\c
135.B a.out\c
136\&. Different formats may be linked together to produce any
137available kind of object file. You can use `\|\c
138.B objdump \-i\c
139\|' to get a list of formats supported on various architectures; see
140.BR objdump ( 1 ).
141
142Aside from its flexibility, the GNU linker is more helpful than other
143linkers in providing diagnostic information. Many linkers abandon
144execution immediately upon encountering an error; whenever possible,
145\c
146.B ld\c
147\& continues executing, allowing you to identify other errors
148(or, in some cases, to get an output file in spite of the error).
149
150The GNU linker \c
151.B ld\c
152\& is meant to cover a broad range of situations,
153and to be as compatible as possible with other linkers. As a result,
154you have many choices to control its behavior through the command line,
155and through environment variables.
156
157.SH OPTIONS
158The plethora of command-line options may seem intimidating, but in
159actual practice few of them are used in any particular context.
160For instance, a frequent use of \c
161.B ld\c
162\& is to link standard Unix
163object files on a standard, supported Unix system. On such a system, to
164link a file \c
165.B hello.o\c
166\&:
167.sp
168.br
169$\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
170.br
171.sp
172This tells \c
173.B ld\c
174\& to produce a file called \c
175.B output\c
176\& as the
177result of linking the file \c
178.B /lib/crt0.o\c
179\& with \c
180.B hello.o\c
181\& and
182the library \c
183.B libc.a\c
184\& which will come from the standard search
185directories.
186
187The command-line options to \c
188.B ld\c
189\& may be specified in any order, and
190may be repeated at will. For the most part, repeating an option with a
191different argument will either have no further effect, or override prior
192occurrences (those further to the left on the command line) of an
193option.
194
195The exceptions\(em\&which may meaningfully be used more than once\(em\&are
196\c
197.B \-A\c
198\&, \c
199.B \-b\c
200\& (or its synonym \c
201.B \-format\c
202\&), \c
203.B \-defsym\c
204\&,
205\c
206.B \-L\c
207\&, \c
208.B \-l\c
209\&, \c
210.B \-R\c
211\&, and \c
212.B \-u\c
213\&.
214
215The list of object files to be linked together, shown as \c
8ddef552 216.I objfile\c
0e166a63
RP
217\&,
218may follow, precede, or be mixed in with command-line options; save that
219an \c
8ddef552 220.I objfile\c
0e166a63
RP
221\& argument may not be placed between an option flag and
222its argument.
223
224Usually the linker is invoked with at least one object file, but other
225forms of binary input files can also be specified with \c
226.B \-l\c
227\&,
228\c
229.B \-R\c
230\&, and the script command language. If \c
231.I no\c
232\& binary input
233files at all are specified, the linker does not produce any output, and
234issues the message `\|\c
235.B No input files\c
236\|'.
237
238Option arguments must either follow the option letter without intervening
239whitespace, or be given as separate arguments immediately following the
240option that requires them.
241
0e166a63
RP
242.TP
243.BI "-A" "architecture"\c
244\&
245In the current release of \c
246.B ld\c
247\&, this option is useful only for the
248Intel 960 family of architectures. In that \c
249.B ld\c
250\& configuration, the
251\c
252.I architecture\c
253\& argument is one of the two-letter names identifying
254members of the 960 family; the option specifies the desired output
255target, and warns of any incompatible instructions in the input files.
256It also modifies the linker's search strategy for archive libraries, to
257support the use of libraries specific to each particular
258architecture, by including in the search loop names suffixed with the
259string identifying the architecture.
260
261For example, if your \c
262.B ld\c
263\& command line included `\|\c
264.B \-ACA\c
265\|' as
266well as `\|\c
267.B \-ltry\c
268\|', the linker would look (in its built-in search
269paths, and in any paths you specify with \c
270.B \-L\c
271\&) for a library with
272the names
273.sp
274.br
275try
276.br
277libtry.a
278.br
279tryca
280.br
281libtryca.a
282.br
283.sp
284
285The first two possibilities would be considered in any event; the last
286two are due to the use of `\|\c
287.B \-ACA\c
288\|'.
289
290Future releases of \c
291.B ld\c
292\& may support similar functionality for
293other architecture families.
294
295You can meaningfully use \c
296.B \-A\c
297\& more than once on a command line, if
298an architecture family allows combination of target architectures; each
299use will add another pair of name variants to search for when \c
300.B \-l\c
301\&
302specifies a library.
303
304.TP
305.BI "-b " "input-format"\c
306\&
307Specify the binary format for input object files that follow this option
308on the command line. You don't usually need to specify this, as
309\c
310.B ld\c
311\& is configured to expect as a default input format the most
312usual format on each machine. \c
313.I input-format\c
314\& is a text string, the
315name of a particular format supported by the BFD libraries.
316\c
317.B \-format \c
318.I input-format\c
319\&\c
346535cc
DM
320\& has the same effect, as does the script command
321.BR TARGET .
0e166a63
RP
322
323You may want to use this option if you are linking files with an unusual
324binary format. You can also use \c
325.B \-b\c
326\& to switch formats explicitly (when
327linking object files of different formats), by including
328\c
329.B \-b \c
330.I input-format\c
331\&\c
332\& before each group of object files in a
333particular format.
334
335The default format is taken from the environment variable
336.B GNUTARGET\c
337\&. You can also define the input
338format from a script, using the command \c
339.B TARGET\c
340\&.
341
342.TP
343.B \-Bstatic
344This flag is accepted for command-line compatibility with the SunOS linker,
345but has no effect on \c
346.B ld\c
347\&.
348
349.TP
350.BI "-c " "commandfile"\c
351\&
352Directs \c
353.B ld\c
354\& to read link commands from the file
355\c
356.I commandfile\c
357\&. These commands will completely override \c
358.B ld\c
359\&'s
360default link format (rather than adding to it); \c
361.I commandfile\c
362\& must
363specify everything necessary to describe the target format.
364
365
366You may also include a script of link commands directly in the command
367line by bracketing it between `\|\c
368.B {\c
369\|' and `\|\c
370.B }\c
371\|' characters.
372
373.TP
374.B \-d
375.TP
376.B \-dc
377.TP
378.B \-dp
379These three options are equivalent; multiple forms are supported for
380compatibility with other linkers. Use any of them to make \c
381.B ld\c
382\&
383assign space to common symbols even if a relocatable output file is
384specified (\c
385.B \-r\c
386\&). The script command
387\c
388.B FORCE_COMMON_ALLOCATION\c
389\& has the same effect.
390
391.TP
392.BI "-defsym " "symbol"\c
393\& = \c
394.I expression\c
395\&
396Create a global symbol in the output file, containing the absolute
397address given by \c
398.I expression\c
399\&. You may use this option as many
400times as necessary to define multiple symbols in the command line. A
401limited form of arithmetic is supported for the \c
402.I expression\c
403\& in this
404context: you may give a hexadecimal constant or the name of an existing
405symbol, or use \c
406.B +\c
407\& and \c
408.B \-\c
409\& to add or subtract hexadecimal
410constants or symbols. If you need more elaborate expressions, consider
411using the linker command language from a script.
412
413.TP
414.BI "-e " "entry"\c
415\&
416Use \c
417.I entry\c
418\& as the explicit symbol for beginning execution of your
419program, rather than the default entry point. for a
420discussion of defaults and other ways of specifying the
421entry point.
422
423.TP
424.B \-F
425.TP
426.BI "-F" "format"\c
427\&
428Some older linkers used this option throughout a compilation toolchain
429for specifying object-file format for both input and output object
430files. \c
431.B ld\c
432\&'s mechanisms (the \c
433.B \-b\c
434\& or \c
435.B \-format\c
436\& options
437for input files, the \c
438.B TARGET\c
439\& command in linker scripts for output
440files, the \c
441.B GNUTARGET\c
442\& environment variable) are more flexible, but
443but it accepts (and ignores) the \c
444.B \-F\c
445\& option flag for compatibility
446with scripts written to call the old linker.
447
448.TP
449.BI "-format " "input-format"\c
450\&
451Synonym for \c
452.B \-b\c
453\& \c
454.I input-format\c
455\&.
456
457.TP
458.B \-g
459Accepted, but ignored; provided for compatibility with other tools.
460
8ddef552
DM
461.TP
462.BI "\-G " "size"\c
463Set the maximum size of objects to be optimized using the GP register
464to
465.I size
466under MIPS ECOFF. Ignored for other object file formats.
467
0e166a63
RP
468.TP
469.B \-i
470Perform an incremental link (same as option \c
471.B \-r\c
472\&).
473
474.TP
475.BI "-l" "ar"\c
476\&
477Add an archive file \c
478.I ar\c
479\& to the list of files to link. This
480option may be used any number of times. \c
481.B ld\c
482\& will search its
483path-list for occurrences of \c
484.B lib\c
485.I ar\c
486\&.a\c
487\& for every \c
488.I ar\c
489\&
490specified.
491
492.TP
493.BI "-L" "searchdir"\c
494\&
495This command adds path \c
496.I searchdir\c
497\& to the list of paths that
498\c
499.B ld\c
500\& will search for archive libraries. You may use this option
501any number of times.
502
503The default set of paths searched (without being specified with
504\c
505.B \-L\c
506\&) depends on what emulation mode \c
507.B ld\c
508\& is using, and in
509some cases also on how it was configured. The
510paths can also be specified in a link script with the \c
511.B SEARCH_DIR\c
512\&
513command.
514
515.TP
516.B \-M
0e166a63
RP
517Print (to the standard output file) a link map\(em\&diagnostic information
518about where symbols are mapped by \c
519.B ld\c
520\&, and information on global
521common storage allocation.
522
d18a4527
DM
523.TP
524.BI "\-Map " "mapfile"\c
525Print to the file
526.I mapfile
527a link map\(em\&diagnostic information
528about where symbols are mapped by \c
529.B ld\c
530\&, and information on global
531common storage allocation.
532
8ddef552
DM
533.TP
534.BI "\-m " "emulation"\c
535Emulate the
536.I emulation
537linker. You can list the available emulations with the
538.I \-V
539option. This option overrides the compiled-in default, which is the
540system for which you configured
541.BR ld .
542
0e166a63
RP
543.TP
544.B \-N
545specifies readable and writable \c
546.B text\c
547\& and \c
548.B data\c
549\& sections. If
550the output format supports Unix style magic numbers, the output is
551marked as \c
552.B OMAGIC\c
553\&.
554
555When you use the `\|\c
556.B \-N\c
557\&\|' option, the linker does not page-align the
558data segment.
559
560.TP
561.B \-n
562sets the text segment to be read only, and \c
563.B NMAGIC\c
564\& is written
565if possible.
566
567.TP
568.B \-noinhibit-exec
569Normally, the linker will not produce an output file if it encounters
570errors during the link process. With this flag, you can specify that
571you wish the output file retained even after non-fatal errors.
572
573.TP
574.BI "-o " "output"\c
575\&
576.I output\c
577\&
578\c
579.I output\c
580\& is a name for the program produced by \c
581.B ld\c
582\&; if this
583option is not specified, the name `\|\c
584.B a.out\c
585\|' is used by default. The
586script command \c
587.B OUTPUT\c
588\& can also specify the output file name.
589
346535cc
DM
590.TP
591.BI "-oformat " "output-format"\c
592\&
593Specify the binary format for the output object file.
594You don't usually need to specify this, as
595\c
596.B ld\c
597\& is configured to produce as a default output format the most
598usual format on each machine. \c
599.I output-format\c
600\& is a text string, the
601name of a particular format supported by the BFD libraries.
602The script command
603.B OUTPUT_FORMAT
604can also specify the output format, but this option overrides it.
605
0e166a63
RP
606.TP
607.BI "-R " "filename"\c
608\&
609.I file\c
610\&
611Read symbol names and their addresses from \c
612.I filename\c
613\&, but do not
614relocate it or include it in the output. This allows your output file
615to refer symbolically to absolute locations of memory defined in other
616programs.
617
618.TP
619.B \-relax
620An option with machine dependent effects. Currently this option is only
621supported on the H8/300.
622
623On some platforms, use this option to perform global optimizations that
624become possible when the linker resolves addressing in your program, such
625as relaxing address modes and synthesizing new instructions in the
626output object file.
627
628On platforms where this is not supported, `\|\c
629.B \-relax\c
630\&\|' is accepted, but has no effect.
631
632.TP
633.B \-r
634Generates relocatable output\(em\&i.e., generate an output file that can in
635turn serve as input to \c
636.B ld\c
637\&. This is often called \c
638.I partial
639linking\c
640\&. As a side effect, in environments that support standard Unix
641magic numbers, this option also sets the output file's magic number to
642\c
643.B OMAGIC\c
644\&.
645If this option is not specified, an absolute file is produced. When
646linking C++ programs, this option \c
647.I will not\c
648\& resolve references to
649constructors; \c
650.B \-Ur\c
651\& is an alternative.
652
653This option does the same as \c
654.B \-i\c
655\&.
656
657.TP
658.B \-S
659Omits debugger symbol information (but not all symbols) from the output file.
660
661.TP
662.B \-s
663Omits all symbol information from the output file.
664
0e166a63
RP
665.TP
666.BI "-Tbss " "org"\c
667.TP
668.BI "-Tdata " "org"\c
669.TP
670.BI "-Ttext " "org"\c
671Use \c
672.I org\c
673\& as the starting address for\(em\&respectively\(em\&the
674\c
675.B bss\c
676\&, \c
677.B data\c
678\&, or the \c
679.B text\c
680\& segment of the output file.
681\c
682.I textorg\c
683\& must be a hexadecimal integer.
684
685.TP
686.BI "-T " "commandfile"\c
687\&
688.TP
689.BI "-T" "commandfile"\c
690Equivalent to \c
691.B \-c \c
692.I commandfile\c
693\&\c
694\&; supported for compatibility with
695other tools.
696
697.TP
698.B \-t
699Prints names of input files as \c
700.B ld\c
701\& processes them.
702
703.TP
704.BI "-u " "sym"
705Forces \c
706.I sym\c
707\& to be entered in the output file as an undefined symbol.
708This may, for example, trigger linking of additional modules from
709standard libraries. \c
710.B \-u\c
711\& may be repeated with different option
712arguments to enter additional undefined symbols.
713
714.TP
715.B \-Ur
716For anything other than C++ programs, this option is equivalent to
717\c
718.B \-r\c
719\&: it generates relocatable output\(em\&i.e., an output file that can in
720turn serve as input to \c
721.B ld\c
722\&. When linking C++ programs, \c
723.B \-Ur\c
724\&
725\c
726.I will\c
727\& resolve references to constructors, unlike \c
728.B \-r\c
729\&.
730
8ddef552
DM
731.TP
732.B \-V
733Display the version number for \c
734.B ld
735and list the supported emulations.
736Print which input files can and can not be opened.
737
0e166a63
RP
738.TP
739.B \-v
740Display the version number for \c
741.B ld\c
742\&.
8ddef552 743Print which input files can and can not be opened.
0e166a63
RP
744
745.TP
746.B \-X
747If \c
748.B \-s\c
749\& or \c
750.B \-S\c
751\& is also specified, delete only local symbols
752beginning with `\|\c
753.B L\c
754\|'.
755
756.TP
757.B \-x
758If \c
759.B \-s\c
760\& or \c
761.B \-S\c
762\& is also specified, delete all local symbols,
763not just those beginning with `\|\c
764.B L\c
765\|'.
766
767.PP
768
769.SH ENVIRONMENT
770\c
8ddef552 771You can change the behavior of
0e166a63 772.B ld\c
8ddef552 773\& with the environment variable \c
0e166a63 774.B GNUTARGET\c
8ddef552 775\&.
0e166a63
RP
776
777\c
778.B GNUTARGET\c
779\& determines the input-file object format if you don't
780use \c
781.B \-b\c
782\& (or its synonym \c
783.B \-format\c
784\&). Its value should be one
785of the BFD names for an input format. If there is no
786\c
787.B GNUTARGET\c
788\& in the environment, \c
789.B ld\c
790\& uses the natural format
791of the host. If \c
792.B GNUTARGET\c
793\& is set to \c
794.B default\c
795\& then BFD attempts to discover the
796input format by examining binary input files; this method often
797succeeds, but there are potential ambiguities, since there is no method
798of ensuring that the magic number used to flag object-file formats is
799unique. However, the configuration procedure for BFD on each system
800places the conventional format for that system first in the search-list,
801so ambiguities are resolved in favor of convention.
802
0e166a63
RP
803.PP
804
805.SH "SEE ALSO"
806
807.BR objdump ( 1 )
808.br
809.br
810.RB "`\|" ld "\|' and `\|" binutils "\|'"
811entries in
812.B info\c
813.br
814.I
815ld: the GNU linker\c
816, Steve Chamberlain and Roland Pesch;
817.I
818The GNU Binary Utilities\c
819, Roland H. Pesch.
820
821.SH COPYING
822Copyright (c) 1991, 1992 Free Software Foundation, Inc.
823.PP
824Permission is granted to make and distribute verbatim copies of
825this manual provided the copyright notice and this permission notice
826are preserved on all copies.
827.PP
828Permission is granted to copy and distribute modified versions of this
829manual under the conditions for verbatim copying, provided that the
830entire resulting derived work is distributed under the terms of a
831permission notice identical to this one.
832.PP
833Permission is granted to copy and distribute translations of this
834manual into another language, under the above conditions for modified
835versions, except that this permission notice may be included in
836translations approved by the Free Software Foundation instead of in
837the original English.
This page took 0.076576 seconds and 4 git commands to generate.