* ldfile.c (ldfile_open_command): Don't try .ld extension.
[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 "[\|" \-m\c
65 .I emulation\c
66 \&\|]
67 .RB "[\|" \-n | \-N "\|]"
68 .RB "[\|" \-noinhibit-exec "\|]"
69 .RB "[\|" "\-R\ "\c
70 .I filename\c
71 \&\|]
72 .RB "[\|" \-relax "\|]"
73 .RB "[\|" \-r | \-Ur "\|]"
74 .RB "[\|" \-S "\|]"
75 .RB "[\|" \-s "\|]"
76 .RB "[\|" "\-T\ "\c
77 .I commandfile\c
78 \&\|]
79 .RB "[\|" "\-Ttext\ "\c
80 .I textorg\c
81 \&\|]
82 .RB "[\|" "\-Tdata\ "\c
83 .I dataorg\c
84 \&\|]
85 .RB "[\|" "\-Tbss\ "\c
86 .I bssorg\c
87 \&\|]
88 .RB "[\|" \-t "\|]"
89 .RB "[\|" "\-u\ "\c
90 .I sym\c
91 \&]
92 .RB "[\|" \-V "\|]"
93 .RB "[\|" \-v "\|]"
94 .RB "[\|" \-X "\|]"
95 .RB "[\|" \-x "\|]"
96 .RB "[\|" { \c
97 .I script\c
98 .BR } "\|]"
99 .ad b
100 .hy 1
101 .SH DESCRIPTION
102 \c
103 .B ld\c
104 \& combines a number of object and archive files, relocates
105 their data and ties up symbol references. Often the last step in
106 building a new compiled program to run is a call to \c
107 .B ld\c
108 \&.
109
110 \c
111 .B ld\c
112 \& accepts Linker Command Language files
113 to provide explicit and total control over the linking process.
114 This man page does not describe the command language; see the `\|\c
115 .B ld\c
116 \|' entry in `\|\c
117 .B info\c
118 \|', or the manual
119 .I
120 ld: the GNU linker
121 \&, for full details on the command language and on other aspects of
122 the GNU linker.
123
124 This version of \c
125 .B ld\c
126 \& uses the general purpose BFD libraries
127 to operate on object files. This allows \c
128 .B ld\c
129 \& to read, combine, and
130 write object files in many different formats\(em\&for example, COFF or
131 \c
132 .B a.out\c
133 \&. Different formats may be linked together to produce any
134 available kind of object file. You can use `\|\c
135 .B objdump \-i\c
136 \|' to get a list of formats supported on various architectures; see
137 .BR objdump ( 1 ).
138
139 Aside from its flexibility, the GNU linker is more helpful than other
140 linkers in providing diagnostic information. Many linkers abandon
141 execution immediately upon encountering an error; whenever possible,
142 \c
143 .B ld\c
144 \& continues executing, allowing you to identify other errors
145 (or, in some cases, to get an output file in spite of the error).
146
147 The GNU linker \c
148 .B ld\c
149 \& is meant to cover a broad range of situations,
150 and to be as compatible as possible with other linkers. As a result,
151 you have many choices to control its behavior through the command line,
152 and through environment variables.
153
154 .SH OPTIONS
155 The plethora of command-line options may seem intimidating, but in
156 actual practice few of them are used in any particular context.
157 For instance, a frequent use of \c
158 .B ld\c
159 \& is to link standard Unix
160 object files on a standard, supported Unix system. On such a system, to
161 link a file \c
162 .B hello.o\c
163 \&:
164 .sp
165 .br
166 $\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
167 .br
168 .sp
169 This tells \c
170 .B ld\c
171 \& to produce a file called \c
172 .B output\c
173 \& as the
174 result of linking the file \c
175 .B /lib/crt0.o\c
176 \& with \c
177 .B hello.o\c
178 \& and
179 the library \c
180 .B libc.a\c
181 \& which will come from the standard search
182 directories.
183
184 The command-line options to \c
185 .B ld\c
186 \& may be specified in any order, and
187 may be repeated at will. For the most part, repeating an option with a
188 different argument will either have no further effect, or override prior
189 occurrences (those further to the left on the command line) of an
190 option.
191
192 The exceptions\(em\&which may meaningfully be used more than once\(em\&are
193 \c
194 .B \-A\c
195 \&, \c
196 .B \-b\c
197 \& (or its synonym \c
198 .B \-format\c
199 \&), \c
200 .B \-defsym\c
201 \&,
202 \c
203 .B \-L\c
204 \&, \c
205 .B \-l\c
206 \&, \c
207 .B \-R\c
208 \&, and \c
209 .B \-u\c
210 \&.
211
212 The list of object files to be linked together, shown as \c
213 .I objfile\c
214 \&,
215 may follow, precede, or be mixed in with command-line options; save that
216 an \c
217 .I objfile\c
218 \& argument may not be placed between an option flag and
219 its argument.
220
221 Usually the linker is invoked with at least one object file, but other
222 forms of binary input files can also be specified with \c
223 .B \-l\c
224 \&,
225 \c
226 .B \-R\c
227 \&, and the script command language. If \c
228 .I no\c
229 \& binary input
230 files at all are specified, the linker does not produce any output, and
231 issues the message `\|\c
232 .B No input files\c
233 \|'.
234
235 Option arguments must either follow the option letter without intervening
236 whitespace, or be given as separate arguments immediately following the
237 option that requires them.
238
239 .TP
240 .BI "-A" "architecture"\c
241 \&
242 In the current release of \c
243 .B ld\c
244 \&, this option is useful only for the
245 Intel 960 family of architectures. In that \c
246 .B ld\c
247 \& configuration, the
248 \c
249 .I architecture\c
250 \& argument is one of the two-letter names identifying
251 members of the 960 family; the option specifies the desired output
252 target, and warns of any incompatible instructions in the input files.
253 It also modifies the linker's search strategy for archive libraries, to
254 support the use of libraries specific to each particular
255 architecture, by including in the search loop names suffixed with the
256 string identifying the architecture.
257
258 For example, if your \c
259 .B ld\c
260 \& command line included `\|\c
261 .B \-ACA\c
262 \|' as
263 well as `\|\c
264 .B \-ltry\c
265 \|', the linker would look (in its built-in search
266 paths, and in any paths you specify with \c
267 .B \-L\c
268 \&) for a library with
269 the names
270 .sp
271 .br
272 try
273 .br
274 libtry.a
275 .br
276 tryca
277 .br
278 libtryca.a
279 .br
280 .sp
281
282 The first two possibilities would be considered in any event; the last
283 two are due to the use of `\|\c
284 .B \-ACA\c
285 \|'.
286
287 Future releases of \c
288 .B ld\c
289 \& may support similar functionality for
290 other architecture families.
291
292 You can meaningfully use \c
293 .B \-A\c
294 \& more than once on a command line, if
295 an architecture family allows combination of target architectures; each
296 use will add another pair of name variants to search for when \c
297 .B \-l\c
298 \&
299 specifies a library.
300
301 .TP
302 .BI "-b " "input-format"\c
303 \&
304 Specify the binary format for input object files that follow this option
305 on the command line. You don't usually need to specify this, as
306 \c
307 .B ld\c
308 \& is configured to expect as a default input format the most
309 usual format on each machine. \c
310 .I input-format\c
311 \& is a text string, the
312 name of a particular format supported by the BFD libraries.
313 \c
314 .B \-format \c
315 .I input-format\c
316 \&\c
317 \& has the same effect.
318
319 You may want to use this option if you are linking files with an unusual
320 binary format. You can also use \c
321 .B \-b\c
322 \& to switch formats explicitly (when
323 linking object files of different formats), by including
324 \c
325 .B \-b \c
326 .I input-format\c
327 \&\c
328 \& before each group of object files in a
329 particular format.
330
331 The default format is taken from the environment variable
332 .B GNUTARGET\c
333 \&. You can also define the input
334 format from a script, using the command \c
335 .B TARGET\c
336 \&.
337
338 .TP
339 .B \-Bstatic
340 This flag is accepted for command-line compatibility with the SunOS linker,
341 but has no effect on \c
342 .B ld\c
343 \&.
344
345 .TP
346 .BI "-c " "commandfile"\c
347 \&
348 Directs \c
349 .B ld\c
350 \& to read link commands from the file
351 \c
352 .I commandfile\c
353 \&. These commands will completely override \c
354 .B ld\c
355 \&'s
356 default link format (rather than adding to it); \c
357 .I commandfile\c
358 \& must
359 specify everything necessary to describe the target format.
360
361
362 You may also include a script of link commands directly in the command
363 line by bracketing it between `\|\c
364 .B {\c
365 \|' and `\|\c
366 .B }\c
367 \|' characters.
368
369 .TP
370 .B \-d
371 .TP
372 .B \-dc
373 .TP
374 .B \-dp
375 These three options are equivalent; multiple forms are supported for
376 compatibility with other linkers. Use any of them to make \c
377 .B ld\c
378 \&
379 assign space to common symbols even if a relocatable output file is
380 specified (\c
381 .B \-r\c
382 \&). The script command
383 \c
384 .B FORCE_COMMON_ALLOCATION\c
385 \& has the same effect.
386
387 .TP
388 .BI "-defsym " "symbol"\c
389 \& = \c
390 .I expression\c
391 \&
392 Create a global symbol in the output file, containing the absolute
393 address given by \c
394 .I expression\c
395 \&. You may use this option as many
396 times as necessary to define multiple symbols in the command line. A
397 limited form of arithmetic is supported for the \c
398 .I expression\c
399 \& in this
400 context: you may give a hexadecimal constant or the name of an existing
401 symbol, or use \c
402 .B +\c
403 \& and \c
404 .B \-\c
405 \& to add or subtract hexadecimal
406 constants or symbols. If you need more elaborate expressions, consider
407 using the linker command language from a script.
408
409 .TP
410 .BI "-e " "entry"\c
411 \&
412 Use \c
413 .I entry\c
414 \& as the explicit symbol for beginning execution of your
415 program, rather than the default entry point. for a
416 discussion of defaults and other ways of specifying the
417 entry point.
418
419 .TP
420 .B \-F
421 .TP
422 .BI "-F" "format"\c
423 \&
424 Some older linkers used this option throughout a compilation toolchain
425 for specifying object-file format for both input and output object
426 files. \c
427 .B ld\c
428 \&'s mechanisms (the \c
429 .B \-b\c
430 \& or \c
431 .B \-format\c
432 \& options
433 for input files, the \c
434 .B TARGET\c
435 \& command in linker scripts for output
436 files, the \c
437 .B GNUTARGET\c
438 \& environment variable) are more flexible, but
439 but it accepts (and ignores) the \c
440 .B \-F\c
441 \& option flag for compatibility
442 with scripts written to call the old linker.
443
444 .TP
445 .BI "-format " "input-format"\c
446 \&
447 Synonym for \c
448 .B \-b\c
449 \& \c
450 .I input-format\c
451 \&.
452
453 .TP
454 .B \-g
455 Accepted, but ignored; provided for compatibility with other tools.
456
457 .TP
458 .BI "\-G " "size"\c
459 Set the maximum size of objects to be optimized using the GP register
460 to
461 .I size
462 under MIPS ECOFF. Ignored for other object file formats.
463
464 .TP
465 .B \-i
466 Perform an incremental link (same as option \c
467 .B \-r\c
468 \&).
469
470 .TP
471 .BI "-l" "ar"\c
472 \&
473 Add an archive file \c
474 .I ar\c
475 \& to the list of files to link. This
476 option may be used any number of times. \c
477 .B ld\c
478 \& will search its
479 path-list for occurrences of \c
480 .B lib\c
481 .I ar\c
482 \&.a\c
483 \& for every \c
484 .I ar\c
485 \&
486 specified.
487
488 .TP
489 .BI "-L" "searchdir"\c
490 \&
491 This command adds path \c
492 .I searchdir\c
493 \& to the list of paths that
494 \c
495 .B ld\c
496 \& will search for archive libraries. You may use this option
497 any number of times.
498
499 The default set of paths searched (without being specified with
500 \c
501 .B \-L\c
502 \&) depends on what emulation mode \c
503 .B ld\c
504 \& is using, and in
505 some cases also on how it was configured. The
506 paths can also be specified in a link script with the \c
507 .B SEARCH_DIR\c
508 \&
509 command.
510
511 .TP
512 .B \-M
513 Print (to the standard output file) a link map\(em\&diagnostic information
514 about where symbols are mapped by \c
515 .B ld\c
516 \&, and information on global
517 common storage allocation.
518
519 .TP
520 .BI "\-m " "emulation"\c
521 Emulate the
522 .I emulation
523 linker. You can list the available emulations with the
524 .I \-V
525 option. This option overrides the compiled-in default, which is the
526 system for which you configured
527 .BR ld .
528
529 .TP
530 .B \-N
531 specifies readable and writable \c
532 .B text\c
533 \& and \c
534 .B data\c
535 \& sections. If
536 the output format supports Unix style magic numbers, the output is
537 marked as \c
538 .B OMAGIC\c
539 \&.
540
541 When you use the `\|\c
542 .B \-N\c
543 \&\|' option, the linker does not page-align the
544 data segment.
545
546 .TP
547 .B \-n
548 sets the text segment to be read only, and \c
549 .B NMAGIC\c
550 \& is written
551 if possible.
552
553 .TP
554 .B \-noinhibit-exec
555 Normally, the linker will not produce an output file if it encounters
556 errors during the link process. With this flag, you can specify that
557 you wish the output file retained even after non-fatal errors.
558
559 .TP
560 .BI "-o " "output"\c
561 \&
562 .I output\c
563 \&
564 \c
565 .I output\c
566 \& is a name for the program produced by \c
567 .B ld\c
568 \&; if this
569 option is not specified, the name `\|\c
570 .B a.out\c
571 \|' is used by default. The
572 script command \c
573 .B OUTPUT\c
574 \& can also specify the output file name.
575
576 .TP
577 .BI "-R " "filename"\c
578 \&
579 .I file\c
580 \&
581 Read symbol names and their addresses from \c
582 .I filename\c
583 \&, but do not
584 relocate it or include it in the output. This allows your output file
585 to refer symbolically to absolute locations of memory defined in other
586 programs.
587
588 .TP
589 .B \-relax
590 An option with machine dependent effects. Currently this option is only
591 supported on the H8/300.
592
593 On some platforms, use this option to perform global optimizations that
594 become possible when the linker resolves addressing in your program, such
595 as relaxing address modes and synthesizing new instructions in the
596 output object file.
597
598 On platforms where this is not supported, `\|\c
599 .B \-relax\c
600 \&\|' is accepted, but has no effect.
601
602 .TP
603 .B \-r
604 Generates relocatable output\(em\&i.e., generate an output file that can in
605 turn serve as input to \c
606 .B ld\c
607 \&. This is often called \c
608 .I partial
609 linking\c
610 \&. As a side effect, in environments that support standard Unix
611 magic numbers, this option also sets the output file's magic number to
612 \c
613 .B OMAGIC\c
614 \&.
615 If this option is not specified, an absolute file is produced. When
616 linking C++ programs, this option \c
617 .I will not\c
618 \& resolve references to
619 constructors; \c
620 .B \-Ur\c
621 \& is an alternative.
622
623 This option does the same as \c
624 .B \-i\c
625 \&.
626
627 .TP
628 .B \-S
629 Omits debugger symbol information (but not all symbols) from the output file.
630
631 .TP
632 .B \-s
633 Omits all symbol information from the output file.
634
635 .TP
636 .BI "{ " "script" " }"
637 You can, if you wish, include a script of linker commands directly in
638 the command line instead of referring to it via an input file. When the
639 character `\|\c
640 .B {\c
641 \|' occurs on the command line, the linker switches to
642 interpreting the command language until the end of the list of commands
643 is reached\(em\&flagged with a closing brace `\|\c
644 .B }\c
645 \|'. Other command-line
646 options will not be recognized while parsing the script.
647 See the `\|\c
648 .B ld\c
649 \|' entry in `\|\c
650 .B info\c
651 \|', or the manual
652 .I
653 ld: the GNU linker
654 \&, for a description of the command language.
655
656 .TP
657 .BI "-Tbss " "org"\c
658 .TP
659 .BI "-Tdata " "org"\c
660 .TP
661 .BI "-Ttext " "org"\c
662 Use \c
663 .I org\c
664 \& as the starting address for\(em\&respectively\(em\&the
665 \c
666 .B bss\c
667 \&, \c
668 .B data\c
669 \&, or the \c
670 .B text\c
671 \& segment of the output file.
672 \c
673 .I textorg\c
674 \& must be a hexadecimal integer.
675
676 .TP
677 .BI "-T " "commandfile"\c
678 \&
679 .TP
680 .BI "-T" "commandfile"\c
681 Equivalent to \c
682 .B \-c \c
683 .I commandfile\c
684 \&\c
685 \&; supported for compatibility with
686 other tools.
687
688 .TP
689 .B \-t
690 Prints names of input files as \c
691 .B ld\c
692 \& processes them.
693
694 .TP
695 .BI "-u " "sym"
696 Forces \c
697 .I sym\c
698 \& to be entered in the output file as an undefined symbol.
699 This may, for example, trigger linking of additional modules from
700 standard libraries. \c
701 .B \-u\c
702 \& may be repeated with different option
703 arguments to enter additional undefined symbols.
704
705 .TP
706 .B \-Ur
707 For anything other than C++ programs, this option is equivalent to
708 \c
709 .B \-r\c
710 \&: it generates relocatable output\(em\&i.e., an output file that can in
711 turn serve as input to \c
712 .B ld\c
713 \&. When linking C++ programs, \c
714 .B \-Ur\c
715 \&
716 \c
717 .I will\c
718 \& resolve references to constructors, unlike \c
719 .B \-r\c
720 \&.
721
722 .TP
723 .B \-V
724 Display the version number for \c
725 .B ld
726 and list the supported emulations.
727 Print which input files can and can not be opened.
728
729 .TP
730 .B \-v
731 Display the version number for \c
732 .B ld\c
733 \&.
734 Print which input files can and can not be opened.
735
736 .TP
737 .B \-X
738 If \c
739 .B \-s\c
740 \& or \c
741 .B \-S\c
742 \& is also specified, delete only local symbols
743 beginning with `\|\c
744 .B L\c
745 \|'.
746
747 .TP
748 .B \-x
749 If \c
750 .B \-s\c
751 \& or \c
752 .B \-S\c
753 \& is also specified, delete all local symbols,
754 not just those beginning with `\|\c
755 .B L\c
756 \|'.
757
758 .PP
759
760 .SH ENVIRONMENT
761 \c
762 You can change the behavior of
763 .B ld\c
764 \& with the environment variable \c
765 .B GNUTARGET\c
766 \&.
767
768 \c
769 .B GNUTARGET\c
770 \& determines the input-file object format if you don't
771 use \c
772 .B \-b\c
773 \& (or its synonym \c
774 .B \-format\c
775 \&). Its value should be one
776 of the BFD names for an input format. If there is no
777 \c
778 .B GNUTARGET\c
779 \& in the environment, \c
780 .B ld\c
781 \& uses the natural format
782 of the host. If \c
783 .B GNUTARGET\c
784 \& is set to \c
785 .B default\c
786 \& then BFD attempts to discover the
787 input format by examining binary input files; this method often
788 succeeds, but there are potential ambiguities, since there is no method
789 of ensuring that the magic number used to flag object-file formats is
790 unique. However, the configuration procedure for BFD on each system
791 places the conventional format for that system first in the search-list,
792 so ambiguities are resolved in favor of convention.
793
794 .PP
795
796 .SH "SEE ALSO"
797
798 .BR objdump ( 1 )
799 .br
800 .br
801 .RB "`\|" ld "\|' and `\|" binutils "\|'"
802 entries in
803 .B info\c
804 .br
805 .I
806 ld: the GNU linker\c
807 , Steve Chamberlain and Roland Pesch;
808 .I
809 The GNU Binary Utilities\c
810 , Roland H. Pesch.
811
812 .SH COPYING
813 Copyright (c) 1991, 1992 Free Software Foundation, Inc.
814 .PP
815 Permission is granted to make and distribute verbatim copies of
816 this manual provided the copyright notice and this permission notice
817 are preserved on all copies.
818 .PP
819 Permission is granted to copy and distribute modified versions of this
820 manual under the conditions for verbatim copying, provided that the
821 entire resulting derived work is distributed under the terms of a
822 permission notice identical to this one.
823 .PP
824 Permission is granted to copy and distribute translations of this
825 manual into another language, under the above conditions for modified
826 versions, except that this permission notice may be included in
827 translations approved by the Free Software Foundation instead of in
828 the original English.
This page took 0.05775 seconds and 5 git commands to generate.