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