1 .\" Copyright (c) 1991, 92, 93, 94, 1995 Free Software Foundation
2 .\" See section COPYING for conditions for redistribution
3 .TH ld 1 "17 August 1992" "cygnus support" "GNU Development Tools"
30 .RB "[\|" \-Bstatic "\|]"
31 .RB "[\|" \-Bdynamic "\|]"
32 .RB "[\|" \-Bsymbolic "\|]"
36 .RB "[\|" \-d | \-dc | \-dp\c
39 .RB "[\|" "\-defsym\ "\c
47 .RB "[\|" \-embedded\-relocs "\|]"
52 .RB "[\|" "\-format\ "\c
59 .RB "[\|" \-\-help "\|]"
74 .RB "[\|" \-n | \-N "\|]"
75 .RB "[\|" \-noinhibit-exec "\|]"
76 .RB "[\|" \-no\-keep\-memory "\|]"
77 .RB "[\|" "\-oformat\ "\c
83 .RB "[\|" \-relax "\|]"
84 .RB "[\|" \-r | \-Ur "\|]"
85 .RB "[\|" "\-rpath\ "\c
88 .RB "[\|" "\-rpath\-link\ "\c
93 .RB "[\|" \-shared "\|]"
94 .RB "[\|" \-sort\-common "\|]"
95 .RB "[\|" "\-split\-by\-reloc\ "\c
98 .RB "[\|" \-split\-by\-file "\|]"
102 .RB "[\|" "\-Ttext\ "\c
105 .RB "[\|" "\-Tdata\ "\c
108 .RB "[\|" "\-Tbss\ "\c
117 .RB "[\|" \-\-verbose "\|]"
118 .RB "[\|" \-\-version "\|]"
119 .RB "[\|" \-warn\-common "\|]"
120 .RB "[\|" \-warn\-constructors "\|]"
121 .RB "[\|" \-warn\-once "\|]"
122 .RB "[\|" \-\-whole\-archive "\|]"
130 \& combines a number of object and archive files, relocates
131 their data and ties up symbol references. Often the last step in
132 building a new compiled program to run is a call to \c
138 \& accepts Linker Command Language files
139 to provide explicit and total control over the linking process.
140 This man page does not describe the command language; see the `\|\c
147 \&, for full details on the command language and on other aspects of
152 \& uses the general purpose BFD libraries
153 to operate on object files. This allows \c
155 \& to read, combine, and
156 write object files in many different formats\(em\&for example, COFF or
159 \&. Different formats may be linked together to produce any
160 available kind of object file. You can use `\|\c
162 \|' to get a list of formats supported on various architectures; see
165 Aside from its flexibility, the GNU linker is more helpful than other
166 linkers in providing diagnostic information. Many linkers abandon
167 execution immediately upon encountering an error; whenever possible,
170 \& continues executing, allowing you to identify other errors
171 (or, in some cases, to get an output file in spite of the error).
175 \& is meant to cover a broad range of situations,
176 and to be as compatible as possible with other linkers. As a result,
177 you have many choices to control its behavior through the command line,
178 and through environment variables.
181 The plethora of command-line options may seem intimidating, but in
182 actual practice few of them are used in any particular context.
183 For instance, a frequent use of \c
185 \& is to link standard Unix
186 object files on a standard, supported Unix system. On such a system, to
192 $\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
197 \& to produce a file called \c
200 result of linking the file \c
207 \& which will come from the standard search
210 The command-line options to \c
212 \& may be specified in any order, and
213 may be repeated at will. For the most part, repeating an option with a
214 different argument will either have no further effect, or override prior
215 occurrences (those further to the left on the command line) of an
218 The exceptions\(em\&which may meaningfully be used more than once\(em\&are
223 \& (or its synonym \c
238 The list of object files to be linked together, shown as \c
241 may follow, precede, or be mixed in with command-line options; save that
244 \& argument may not be placed between an option flag and
247 Usually the linker is invoked with at least one object file, but other
248 forms of binary input files can also be specified with \c
253 \&, and the script command language. If \c
256 files at all are specified, the linker does not produce any output, and
257 issues the message `\|\c
261 Option arguments must either follow the option letter without intervening
262 whitespace, or be given as separate arguments immediately following the
263 option that requires them.
266 .BI "-A" "architecture"
267 In the current release of \c
269 \&, this option is useful only for the
270 Intel 960 family of architectures. In that \c
272 \& configuration, the
275 \& argument is one of the two-letter names identifying
276 members of the 960 family; the option specifies the desired output
277 target, and warns of any incompatible instructions in the input files.
278 It also modifies the linker's search strategy for archive libraries, to
279 support the use of libraries specific to each particular
280 architecture, by including in the search loop names suffixed with the
281 string identifying the architecture.
283 For example, if your \c
285 \& command line included `\|\c
290 \|', the linker would look (in its built-in search
291 paths, and in any paths you specify with \c
293 \&) for a library with
307 The first two possibilities would be considered in any event; the last
308 two are due to the use of `\|\c
312 Future releases of \c
314 \& may support similar functionality for
315 other architecture families.
317 You can meaningfully use \c
319 \& more than once on a command line, if
320 an architecture family allows combination of target architectures; each
321 use will add another pair of name variants to search for when \c
326 .BI "\-b " "input-format"
327 Specify the binary format for input object files that follow this option
328 on the command line. You don't usually need to specify this, as
331 \& is configured to expect as a default input format the most
332 usual format on each machine. \c
334 \& is a text string, the
335 name of a particular format supported by the BFD libraries.
340 \& has the same effect, as does the script command
343 You may want to use this option if you are linking files with an unusual
344 binary format. You can also use \c
346 \& to switch formats explicitly (when
347 linking object files of different formats), by including
352 \& before each group of object files in a
355 The default format is taken from the environment variable
357 \&. You can also define the input
358 format from a script, using the command \c
364 Do not link against shared libraries. This is only meaningful on
365 platforms for which shared libraries are supported.
369 Link against dynamic libraries. This is only meaningful on platforms
370 for which shared libraries are supported. This option is normally the
371 default on such platforms.
375 When creating a shared library, bind references to global symbols to
376 the definition within the shared library, if any. Normally, it is
377 possible for a program linked against a shared library to override the
378 definition within the shared library. This option is only meaningful
379 on ELF platforms which support shared libraries.
382 .BI "\-c " "commandfile"
385 \& to read link commands from the file
388 \&. These commands will completely override \c
391 default link format (rather than adding to it); \c
394 specify everything necessary to describe the target format.
397 You may also include a script of link commands directly in the command
398 line by bracketing it between `\|\c
410 These three options are equivalent; multiple forms are supported for
411 compatibility with other linkers. Use any of them to make \c
413 assign space to common symbols even if a relocatable output file is
416 \&). The script command
418 .B FORCE_COMMON_ALLOCATION\c
419 \& has the same effect.
422 .BI "-defsym " "symbol" "\fR = \fP" expression
423 Create a global symbol in the output file, containing the absolute
426 \&. You may use this option as many
427 times as necessary to define multiple symbols in the command line. A
428 limited form of arithmetic is supported for the \c
431 context: you may give a hexadecimal constant or the name of an existing
436 \& to add or subtract hexadecimal
437 constants or symbols. If you need more elaborate expressions, consider
438 using the linker command language from a script.
445 \& as the explicit symbol for beginning execution of your
446 program, rather than the default entry point. for a
447 discussion of defaults and other ways of specifying the
451 .B \-embedded\-relocs
452 This option is only meaningful when linking MIPS embedded PIC code,
455 option to the GNU compiler and assembler. It causes the linker to
456 create a table which may be used at runtime to relocate any data which
457 was statically initialized to pointer values. See the code in
458 testsuite/ld-empic for details.
464 Some older linkers used this option throughout a compilation toolchain
465 for specifying object-file format for both input and output object
468 \&'s mechanisms (the \c
473 for input files, the \c
475 \& command in linker scripts for output
478 \& environment variable) are more flexible, but
479 but it accepts (and ignores) the \c
481 \& option flag for compatibility
482 with scripts written to call the old linker.
485 .BI "\-format " "input\-format"
494 Accepted, but ignored; provided for compatibility with other tools.
498 Set the maximum size of objects to be optimized using the GP register
501 under MIPS ECOFF. Ignored for other object file formats.
505 Print a summary of the command-line options on the standard output and exit.
508 begin with two dashes instead of one
509 for compatibility with other GNU programs. The other options start with
510 only one dash for compatibility with other linkers.
514 Perform an incremental link (same as option \c
521 Add an archive file \c
523 \& to the list of files to link. This
524 option may be used any number of times. \c
527 path-list for occurrences of \c
536 .BI "\-L" "searchdir"
537 This command adds path \c
539 \& to the list of paths that
542 \& will search for archive libraries. You may use this option
545 The default set of paths searched (without being specified with
548 \&) depends on what emulation mode \c
551 some cases also on how it was configured. The
552 paths can also be specified in a link script with the \c
558 Print (to the standard output file) a link map\(em\&diagnostic information
559 about where symbols are mapped by \c
561 \&, and information on global
562 common storage allocation.
565 .BI "\-Map " "mapfile"\c
568 a link map\(em\&diagnostic information
569 about where symbols are mapped by \c
571 \&, and information on global
572 common storage allocation.
575 .BI "\-m " "emulation"\c
578 linker. You can list the available emulations with the
582 options. This option overrides the compiled-in default, which is the
583 system for which you configured
588 specifies readable and writable \c
593 the output format supports Unix style magic numbers, the output is
598 When you use the `\|\c
600 \&\|' option, the linker does not page-align the
605 sets the text segment to be read only, and \c
612 Normally, the linker will not produce an output file if it encounters
613 errors during the link process. With this flag, you can specify that
614 you wish the output file retained even after non-fatal errors.
617 .B \-no\-keep\-memory
618 The linker normally optimizes for speed over memory usage by caching
619 the symbol tables of input files in memory. This option tells the
620 linker to instead optimize for memory usage, by rereading the symbol
621 tables as necessary. This may be required if the linker runs out of
622 memory space while linking a large executable.
627 \& is a name for the program produced by \c
630 option is not specified, the name `\|\c
632 \|' is used by default. The
635 \& can also specify the output file name.
638 .BI "\-oformat " "output\-format"
639 Specify the binary format for the output object file.
640 You don't usually need to specify this, as
643 \& is configured to produce as a default output format the most
644 usual format on each machine. \c
646 \& is a text string, the
647 name of a particular format supported by the BFD libraries.
650 can also specify the output format, but this option overrides it.
653 .BI "\-R " "filename"
654 Read symbol names and their addresses from \c
657 relocate it or include it in the output. This allows your output file
658 to refer symbolically to absolute locations of memory defined in other
663 An option with machine dependent effects. Currently this option is only
664 supported on the H8/300.
666 On some platforms, use this option to perform global optimizations that
667 become possible when the linker resolves addressing in your program, such
668 as relaxing address modes and synthesizing new instructions in the
671 On platforms where this is not supported, `\|\c
673 \&\|' is accepted, but has no effect.
677 Generates relocatable output\(em\&i.e., generate an output file that can in
678 turn serve as input to \c
680 \&. This is often called \c
683 \&. As a side effect, in environments that support standard Unix
684 magic numbers, this option also sets the output file's magic number to
688 If this option is not specified, an absolute file is produced. When
689 linking C++ programs, this option \c
691 \& resolve references to
694 \& is an alternative.
696 This option does the same as \c
701 .B \-rpath\ \fIdirectory
702 Add a directory to the runtime library search path. This is used when
703 linking an ELF executable with shared objects. All
705 arguments are concatenated and passed to the runtime linker, which uses
706 them to locate shared objects at runtime. The
708 option is also used when locating shared objects which are needed by
709 shared objects explicitly included in the link; see the description of
716 option may also be used on SunOS. By default, on SunOS, the linker
717 will form a runtime search patch out of all the
719 options it is given. If a
720 .B \-rpath option is used, the runtime search path
721 will be formed exclusively using the
726 options. This can be useful when using gcc, which adds many
728 options which may be on NFS mounted filesystems.
731 .B \-rpath\-link\ \fIdirectory
732 When using ELF or SunOS, one shared library may require another. This
735 link includes a shared library as one of the input files.
737 When the linker encounters such a dependency when doing a non-shared,
738 non-relocateable link, it will automatically try to locate the required
739 shared library and include it in the link, if it is not included
740 explicitly. In such a case, the
742 option specifies the first set of directories to search. The
744 option may specify a sequence of directory names either by specifying
745 a list of names separated by colons, or by appearing multiple times.
747 If the required shared library is not found, the linker will issue a
748 warning and continue with the link.
752 Omits debugger symbol information (but not all symbols) from the output file.
756 Omits all symbol information from the output file.
760 Create a shared library. This is currently only supported on ELF and
761 SunOS platforms (on SunOS it is not required, as the linker will
762 automatically create a shared library when there are undefined symbols
771 places the global common symbols in the appropriate output sections,
772 it sorts them by size. First come all the one byte symbols, then all
773 the two bytes, then all the four bytes, and then everything else.
774 This is to prevent gaps between symbols due to
775 alignment constraints. This option disables that sorting.
778 .B \-split\-by\-reloc\ \fIcount
779 Trys to creates extra sections in the output file so that no single
780 output section in the file contains more than
783 This is useful when generating huge relocatable for downloading into
784 certain real time kernels with the COFF object file format; since COFF
785 cannot represent more than 65535 relocations in a single section.
786 Note that this will fail to work with object file formats which do not
787 support arbitrary sections. The linker will not split up individual
788 input sections for redistribution, so if a single input section
791 relocations one output section will contain that many relocations.
796 .B \-split\-by\-reloc
797 but creates a new output section for each input file.
800 .BI "\-Tbss " "org"\c
802 .BI "\-Tdata " "org"\c
804 .BI "\-Ttext " "org"\c
807 \& as the starting address for\(em\&respectively\(em\&the
814 \& segment of the output file.
817 \& must be a hexadecimal integer.
820 .BI "\-T " "commandfile"
825 \&; supported for compatibility with
830 Prints names of input files as \c
838 \& to be entered in the output file as an undefined symbol.
839 This may, for example, trigger linking of additional modules from
840 standard libraries. \c
842 \& may be repeated with different option
843 arguments to enter additional undefined symbols.
847 For anything other than C++ programs, this option is equivalent to
850 \&: it generates relocatable output\(em\&i.e., an output file that can in
851 turn serve as input to \c
853 \&. When linking C++ programs, \c
856 \& resolve references to constructors, unlike \c
862 Display the version number for \c
864 and list the supported emulations.
865 Display which input files can and can not be opened.
869 Display the version number for \c
874 option also lists the supported emulations.
878 Display the version number for \c
884 Warn when a common symbol is combined with another common symbol or with
885 a symbol definition. Unix linkers allow this somewhat sloppy practice,
886 but linkers on some other operating systems do not. This option allows
887 you to find potential problems from combining global symbols.
890 .B \-warn\-constructors
891 Warn if any global constructors are used. This is only useful for a
892 few object file formats. For formats like COFF or ELF, the linker can
893 not detect the use of global constructors.
897 Only warn once for each undefined symbol, rather than once per module
901 .B \-\-whole\-archive
902 For each archive mentioned on the command line, include every object
903 file in the archive in the link, rather than searching the archive for
904 the required object files. This is normally used to turn an archive
905 file into a shared library, forcing every object to be included in the
906 resulting shared library.
910 Delete all temporary local symbols. For most targets, this is all local
911 symbols whose names begin with `\|\c
917 Delete all local symbols.
923 You can change the behavior of
925 \& with the environment variable \c
931 \& determines the input-file object format if you don't
934 \& (or its synonym \c
936 \&). Its value should be one
937 of the BFD names for an input format. If there is no
940 \& in the environment, \c
942 \& uses the natural format
947 \& then BFD attempts to discover the
948 input format by examining binary input files; this method often
949 succeeds, but there are potential ambiguities, since there is no method
950 of ensuring that the magic number used to flag object-file formats is
951 unique. However, the configuration procedure for BFD on each system
952 places the conventional format for that system first in the search-list,
953 so ambiguities are resolved in favor of convention.
962 .RB "`\|" ld "\|' and `\|" binutils "\|'"
968 , Steve Chamberlain and Roland Pesch;
970 The GNU Binary Utilities\c
974 Copyright (c) 1991, 1992 Free Software Foundation, Inc.
976 Permission is granted to make and distribute verbatim copies of
977 this manual provided the copyright notice and this permission notice
978 are preserved on all copies.
980 Permission is granted to copy and distribute modified versions of this
981 manual under the conditions for verbatim copying, provided that the
982 entire resulting derived work is distributed under the terms of a
983 permission notice identical to this one.
985 Permission is granted to copy and distribute translations of this
986 manual into another language, under the above conditions for modified
987 versions, except that this permission notice may be included in
988 translations approved by the Free Software Foundation instead of in
989 the original English.