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