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