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