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