* stabsread.c: Include <ctype.h>.
[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 "\|]"
72.RB "[\|" "\-R\ "\c
73.I filename\c
74\&\|]
75.RB "[\|" \-relax "\|]"
76.RB "[\|" \-r | \-Ur "\|]"
77.RB "[\|" \-S "\|]"
78.RB "[\|" \-s "\|]"
79.RB "[\|" "\-T\ "\c
80.I commandfile\c
81\&\|]
82.RB "[\|" "\-Ttext\ "\c
83.I textorg\c
84\&\|]
85.RB "[\|" "\-Tdata\ "\c
86.I dataorg\c
87\&\|]
88.RB "[\|" "\-Tbss\ "\c
89.I bssorg\c
90\&\|]
91.RB "[\|" \-t "\|]"
92.RB "[\|" "\-u\ "\c
93.I sym\c
94\&]
8ddef552 95.RB "[\|" \-V "\|]"
0e166a63
RP
96.RB "[\|" \-v "\|]"
97.RB "[\|" \-X "\|]"
98.RB "[\|" \-x "\|]"
99.RB "[\|" { \c
100.I script\c
101.BR } "\|]"
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
320\& has the same effect.
321
322You may want to use this option if you are linking files with an unusual
323binary format. You can also use \c
324.B \-b\c
325\& to switch formats explicitly (when
326linking object files of different formats), by including
327\c
328.B \-b \c
329.I input-format\c
330\&\c
331\& before each group of object files in a
332particular format.
333
334The default format is taken from the environment variable
335.B GNUTARGET\c
336\&. You can also define the input
337format from a script, using the command \c
338.B TARGET\c
339\&.
340
341.TP
342.B \-Bstatic
343This flag is accepted for command-line compatibility with the SunOS linker,
344but has no effect on \c
345.B ld\c
346\&.
347
348.TP
349.BI "-c " "commandfile"\c
350\&
351Directs \c
352.B ld\c
353\& to read link commands from the file
354\c
355.I commandfile\c
356\&. These commands will completely override \c
357.B ld\c
358\&'s
359default link format (rather than adding to it); \c
360.I commandfile\c
361\& must
362specify everything necessary to describe the target format.
363
364
365You may also include a script of link commands directly in the command
366line by bracketing it between `\|\c
367.B {\c
368\|' and `\|\c
369.B }\c
370\|' characters.
371
372.TP
373.B \-d
374.TP
375.B \-dc
376.TP
377.B \-dp
378These three options are equivalent; multiple forms are supported for
379compatibility with other linkers. Use any of them to make \c
380.B ld\c
381\&
382assign space to common symbols even if a relocatable output file is
383specified (\c
384.B \-r\c
385\&). The script command
386\c
387.B FORCE_COMMON_ALLOCATION\c
388\& has the same effect.
389
390.TP
391.BI "-defsym " "symbol"\c
392\& = \c
393.I expression\c
394\&
395Create a global symbol in the output file, containing the absolute
396address given by \c
397.I expression\c
398\&. You may use this option as many
399times as necessary to define multiple symbols in the command line. A
400limited form of arithmetic is supported for the \c
401.I expression\c
402\& in this
403context: you may give a hexadecimal constant or the name of an existing
404symbol, or use \c
405.B +\c
406\& and \c
407.B \-\c
408\& to add or subtract hexadecimal
409constants or symbols. If you need more elaborate expressions, consider
410using the linker command language from a script.
411
412.TP
413.BI "-e " "entry"\c
414\&
415Use \c
416.I entry\c
417\& as the explicit symbol for beginning execution of your
418program, rather than the default entry point. for a
419discussion of defaults and other ways of specifying the
420entry point.
421
422.TP
423.B \-F
424.TP
425.BI "-F" "format"\c
426\&
427Some older linkers used this option throughout a compilation toolchain
428for specifying object-file format for both input and output object
429files. \c
430.B ld\c
431\&'s mechanisms (the \c
432.B \-b\c
433\& or \c
434.B \-format\c
435\& options
436for input files, the \c
437.B TARGET\c
438\& command in linker scripts for output
439files, the \c
440.B GNUTARGET\c
441\& environment variable) are more flexible, but
442but it accepts (and ignores) the \c
443.B \-F\c
444\& option flag for compatibility
445with scripts written to call the old linker.
446
447.TP
448.BI "-format " "input-format"\c
449\&
450Synonym for \c
451.B \-b\c
452\& \c
453.I input-format\c
454\&.
455
456.TP
457.B \-g
458Accepted, but ignored; provided for compatibility with other tools.
459
8ddef552
DM
460.TP
461.BI "\-G " "size"\c
462Set the maximum size of objects to be optimized using the GP register
463to
464.I size
465under MIPS ECOFF. Ignored for other object file formats.
466
0e166a63
RP
467.TP
468.B \-i
469Perform an incremental link (same as option \c
470.B \-r\c
471\&).
472
473.TP
474.BI "-l" "ar"\c
475\&
476Add an archive file \c
477.I ar\c
478\& to the list of files to link. This
479option may be used any number of times. \c
480.B ld\c
481\& will search its
482path-list for occurrences of \c
483.B lib\c
484.I ar\c
485\&.a\c
486\& for every \c
487.I ar\c
488\&
489specified.
490
491.TP
492.BI "-L" "searchdir"\c
493\&
494This command adds path \c
495.I searchdir\c
496\& to the list of paths that
497\c
498.B ld\c
499\& will search for archive libraries. You may use this option
500any number of times.
501
502The default set of paths searched (without being specified with
503\c
504.B \-L\c
505\&) depends on what emulation mode \c
506.B ld\c
507\& is using, and in
508some cases also on how it was configured. The
509paths can also be specified in a link script with the \c
510.B SEARCH_DIR\c
511\&
512command.
513
514.TP
515.B \-M
0e166a63
RP
516Print (to the standard output file) a link map\(em\&diagnostic information
517about where symbols are mapped by \c
518.B ld\c
519\&, and information on global
520common storage allocation.
521
d18a4527
DM
522.TP
523.BI "\-Map " "mapfile"\c
524Print to the file
525.I mapfile
526a link map\(em\&diagnostic information
527about where symbols are mapped by \c
528.B ld\c
529\&, and information on global
530common storage allocation.
531
8ddef552
DM
532.TP
533.BI "\-m " "emulation"\c
534Emulate the
535.I emulation
536linker. You can list the available emulations with the
537.I \-V
538option. This option overrides the compiled-in default, which is the
539system for which you configured
540.BR ld .
541
0e166a63
RP
542.TP
543.B \-N
544specifies readable and writable \c
545.B text\c
546\& and \c
547.B data\c
548\& sections. If
549the output format supports Unix style magic numbers, the output is
550marked as \c
551.B OMAGIC\c
552\&.
553
554When you use the `\|\c
555.B \-N\c
556\&\|' option, the linker does not page-align the
557data segment.
558
559.TP
560.B \-n
561sets the text segment to be read only, and \c
562.B NMAGIC\c
563\& is written
564if possible.
565
566.TP
567.B \-noinhibit-exec
568Normally, the linker will not produce an output file if it encounters
569errors during the link process. With this flag, you can specify that
570you wish the output file retained even after non-fatal errors.
571
572.TP
573.BI "-o " "output"\c
574\&
575.I output\c
576\&
577\c
578.I output\c
579\& is a name for the program produced by \c
580.B ld\c
581\&; if this
582option is not specified, the name `\|\c
583.B a.out\c
584\|' is used by default. The
585script command \c
586.B OUTPUT\c
587\& can also specify the output file name.
588
589.TP
590.BI "-R " "filename"\c
591\&
592.I file\c
593\&
594Read symbol names and their addresses from \c
595.I filename\c
596\&, but do not
597relocate it or include it in the output. This allows your output file
598to refer symbolically to absolute locations of memory defined in other
599programs.
600
601.TP
602.B \-relax
603An option with machine dependent effects. Currently this option is only
604supported on the H8/300.
605
606On some platforms, use this option to perform global optimizations that
607become possible when the linker resolves addressing in your program, such
608as relaxing address modes and synthesizing new instructions in the
609output object file.
610
611On platforms where this is not supported, `\|\c
612.B \-relax\c
613\&\|' is accepted, but has no effect.
614
615.TP
616.B \-r
617Generates relocatable output\(em\&i.e., generate an output file that can in
618turn serve as input to \c
619.B ld\c
620\&. This is often called \c
621.I partial
622linking\c
623\&. As a side effect, in environments that support standard Unix
624magic numbers, this option also sets the output file's magic number to
625\c
626.B OMAGIC\c
627\&.
628If this option is not specified, an absolute file is produced. When
629linking C++ programs, this option \c
630.I will not\c
631\& resolve references to
632constructors; \c
633.B \-Ur\c
634\& is an alternative.
635
636This option does the same as \c
637.B \-i\c
638\&.
639
640.TP
641.B \-S
642Omits debugger symbol information (but not all symbols) from the output file.
643
644.TP
645.B \-s
646Omits all symbol information from the output file.
647
648.TP
649.BI "{ " "script" " }"
650You can, if you wish, include a script of linker commands directly in
651the command line instead of referring to it via an input file. When the
652character `\|\c
653.B {\c
654\|' occurs on the command line, the linker switches to
655interpreting the command language until the end of the list of commands
656is reached\(em\&flagged with a closing brace `\|\c
657.B }\c
658\|'. Other command-line
659options will not be recognized while parsing the script.
660See the `\|\c
661.B ld\c
662\|' entry in `\|\c
663.B info\c
664\|', or the manual
665.I
666ld: the GNU linker
667\&, for a description of the command language.
668
669.TP
670.BI "-Tbss " "org"\c
671.TP
672.BI "-Tdata " "org"\c
673.TP
674.BI "-Ttext " "org"\c
675Use \c
676.I org\c
677\& as the starting address for\(em\&respectively\(em\&the
678\c
679.B bss\c
680\&, \c
681.B data\c
682\&, or the \c
683.B text\c
684\& segment of the output file.
685\c
686.I textorg\c
687\& must be a hexadecimal integer.
688
689.TP
690.BI "-T " "commandfile"\c
691\&
692.TP
693.BI "-T" "commandfile"\c
694Equivalent to \c
695.B \-c \c
696.I commandfile\c
697\&\c
698\&; supported for compatibility with
699other tools.
700
701.TP
702.B \-t
703Prints names of input files as \c
704.B ld\c
705\& processes them.
706
707.TP
708.BI "-u " "sym"
709Forces \c
710.I sym\c
711\& to be entered in the output file as an undefined symbol.
712This may, for example, trigger linking of additional modules from
713standard libraries. \c
714.B \-u\c
715\& may be repeated with different option
716arguments to enter additional undefined symbols.
717
718.TP
719.B \-Ur
720For anything other than C++ programs, this option is equivalent to
721\c
722.B \-r\c
723\&: it generates relocatable output\(em\&i.e., an output file that can in
724turn serve as input to \c
725.B ld\c
726\&. When linking C++ programs, \c
727.B \-Ur\c
728\&
729\c
730.I will\c
731\& resolve references to constructors, unlike \c
732.B \-r\c
733\&.
734
8ddef552
DM
735.TP
736.B \-V
737Display the version number for \c
738.B ld
739and list the supported emulations.
740Print which input files can and can not be opened.
741
0e166a63
RP
742.TP
743.B \-v
744Display the version number for \c
745.B ld\c
746\&.
8ddef552 747Print which input files can and can not be opened.
0e166a63
RP
748
749.TP
750.B \-X
751If \c
752.B \-s\c
753\& or \c
754.B \-S\c
755\& is also specified, delete only local symbols
756beginning with `\|\c
757.B L\c
758\|'.
759
760.TP
761.B \-x
762If \c
763.B \-s\c
764\& or \c
765.B \-S\c
766\& is also specified, delete all local symbols,
767not just those beginning with `\|\c
768.B L\c
769\|'.
770
771.PP
772
773.SH ENVIRONMENT
774\c
8ddef552 775You can change the behavior of
0e166a63 776.B ld\c
8ddef552 777\& with the environment variable \c
0e166a63 778.B GNUTARGET\c
8ddef552 779\&.
0e166a63
RP
780
781\c
782.B GNUTARGET\c
783\& determines the input-file object format if you don't
784use \c
785.B \-b\c
786\& (or its synonym \c
787.B \-format\c
788\&). Its value should be one
789of the BFD names for an input format. If there is no
790\c
791.B GNUTARGET\c
792\& in the environment, \c
793.B ld\c
794\& uses the natural format
795of the host. If \c
796.B GNUTARGET\c
797\& is set to \c
798.B default\c
799\& then BFD attempts to discover the
800input format by examining binary input files; this method often
801succeeds, but there are potential ambiguities, since there is no method
802of ensuring that the magic number used to flag object-file formats is
803unique. However, the configuration procedure for BFD on each system
804places the conventional format for that system first in the search-list,
805so ambiguities are resolved in favor of convention.
806
0e166a63
RP
807.PP
808
809.SH "SEE ALSO"
810
811.BR objdump ( 1 )
812.br
813.br
814.RB "`\|" ld "\|' and `\|" binutils "\|'"
815entries in
816.B info\c
817.br
818.I
819ld: the GNU linker\c
820, Steve Chamberlain and Roland Pesch;
821.I
822The GNU Binary Utilities\c
823, Roland H. Pesch.
824
825.SH COPYING
826Copyright (c) 1991, 1992 Free Software Foundation, Inc.
827.PP
828Permission is granted to make and distribute verbatim copies of
829this manual provided the copyright notice and this permission notice
830are preserved on all copies.
831.PP
832Permission is granted to copy and distribute modified versions of this
833manual under the conditions for verbatim copying, provided that the
834entire resulting derived work is distributed under the terms of a
835permission notice identical to this one.
836.PP
837Permission is granted to copy and distribute translations of this
838manual into another language, under the above conditions for modified
839versions, except that this permission notice may be included in
840translations approved by the Free Software Foundation instead of in
841the original English.
This page took 0.074923 seconds and 4 git commands to generate.