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