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