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