1 .\" Copyright (c) 1991, 92, 93, 94, 95, 1996 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 "[\|" \-\-cref "\|]"
37 .RB "[\|" \-d | \-dc | \-dp\c
40 .RB "[\|" "\-defsym\ "\c
48 .RB "[\|" \-embedded\-relocs "\|]"
50 .RB "[\|" \-export\-dynamic "\|]"
55 .RB "[\|" "\-format\ "\c
62 .RB "[\|" \-\-help "\|]"
77 .RB "[\|" \-n | \-N "\|]"
78 .RB "[\|" \-noinhibit-exec "\|]"
79 .RB "[\|" \-no\-keep\-memory "\|]"
80 .RB "[\|" "\-oformat\ "\c
86 .RB "[\|" \-relax "\|]"
87 .RB "[\|" \-r | \-Ur "\|]"
88 .RB "[\|" "\-rpath\ "\c
91 .RB "[\|" "\-rpath\-link\ "\c
96 .RB "[\|" \-shared "\|]"
97 .RB "[\|" \-sort\-common "\|]"
98 .RB "[\|" "\-split\-by\-reloc\ "\c
101 .RB "[\|" \-split\-by\-file "\|]"
105 .RB "[\|" "\-Ttext\ "\c
108 .RB "[\|" "\-Tdata\ "\c
111 .RB "[\|" "\-Tbss\ "\c
120 .RB "[\|" \-\-verbose "\|]"
121 .RB "[\|" \-\-version "\|]"
122 .RB "[\|" \-warn\-common "\|]"
123 .RB "[\|" \-warn\-constructors "\|]"
124 .RB "[\|" \-warn\-multiple\-gp "\|]"
125 .RB "[\|" \-warn\-once "\|]"
126 .RB "[\|" \-\-whole\-archive "\|]"
127 .RB "[\|" \-\-no\-whole\-archive "\|]"
128 .RB "[\|" "\-\-wrap\ "\c
138 \& combines a number of object and archive files, relocates
139 their data and ties up symbol references. Often the last step in
140 building a new compiled program to run is a call to \c
146 \& accepts Linker Command Language files
147 to provide explicit and total control over the linking process.
148 This man page does not describe the command language; see the `\|\c
155 \&, for full details on the command language and on other aspects of
160 \& uses the general purpose BFD libraries
161 to operate on object files. This allows \c
163 \& to read, combine, and
164 write object files in many different formats\(em\&for example, COFF or
167 \&. Different formats may be linked together to produce any
168 available kind of object file. You can use `\|\c
170 \|' to get a list of formats supported on various architectures; see
173 Aside from its flexibility, the GNU linker is more helpful than other
174 linkers in providing diagnostic information. Many linkers abandon
175 execution immediately upon encountering an error; whenever possible,
178 \& continues executing, allowing you to identify other errors
179 (or, in some cases, to get an output file in spite of the error).
183 \& is meant to cover a broad range of situations,
184 and to be as compatible as possible with other linkers. As a result,
185 you have many choices to control its behavior through the command line,
186 and through environment variables.
189 The plethora of command-line options may seem intimidating, but in
190 actual practice few of them are used in any particular context.
191 For instance, a frequent use of \c
193 \& is to link standard Unix
194 object files on a standard, supported Unix system. On such a system, to
200 $\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
205 \& to produce a file called \c
208 result of linking the file \c
215 \& which will come from the standard search
218 The command-line options to \c
220 \& may be specified in any order, and
221 may be repeated at will. For the most part, repeating an option with a
222 different argument will either have no further effect, or override prior
223 occurrences (those further to the left on the command line) of an
226 The exceptions\(em\&which may meaningfully be used more than once\(em\&are
231 \& (or its synonym \c
246 The list of object files to be linked together, shown as \c
249 may follow, precede, or be mixed in with command-line options; save that
252 \& argument may not be placed between an option flag and
255 Usually the linker is invoked with at least one object file, but other
256 forms of binary input files can also be specified with \c
261 \&, and the script command language. If \c
264 files at all are specified, the linker does not produce any output, and
265 issues the message `\|\c
269 Option arguments must either follow the option letter without intervening
270 whitespace, or be given as separate arguments immediately following the
271 option that requires them.
274 .BI "-A" "architecture"
275 In the current release of \c
277 \&, this option is useful only for the
278 Intel 960 family of architectures. In that \c
280 \& configuration, the
283 \& argument is one of the two-letter names identifying
284 members of the 960 family; the option specifies the desired output
285 target, and warns of any incompatible instructions in the input files.
286 It also modifies the linker's search strategy for archive libraries, to
287 support the use of libraries specific to each particular
288 architecture, by including in the search loop names suffixed with the
289 string identifying the architecture.
291 For example, if your \c
293 \& command line included `\|\c
298 \|', the linker would look (in its built-in search
299 paths, and in any paths you specify with \c
301 \&) for a library with
315 The first two possibilities would be considered in any event; the last
316 two are due to the use of `\|\c
320 Future releases of \c
322 \& may support similar functionality for
323 other architecture families.
325 You can meaningfully use \c
327 \& more than once on a command line, if
328 an architecture family allows combination of target architectures; each
329 use will add another pair of name variants to search for when \c
334 .BI "\-b " "input-format"
335 Specify the binary format for input object files that follow this option
336 on the command line. You don't usually need to specify this, as
339 \& is configured to expect as a default input format the most
340 usual format on each machine. \c
342 \& is a text string, the
343 name of a particular format supported by the BFD libraries.
348 \& has the same effect, as does the script command
351 You may want to use this option if you are linking files with an unusual
352 binary format. You can also use \c
354 \& to switch formats explicitly (when
355 linking object files of different formats), by including
360 \& before each group of object files in a
363 The default format is taken from the environment variable
365 \&. You can also define the input
366 format from a script, using the command \c
372 Do not link against shared libraries. This is only meaningful on
373 platforms for which shared libraries are supported.
377 Link against dynamic libraries. This is only meaningful on platforms
378 for which shared libraries are supported. This option is normally the
379 default on such platforms.
383 When creating a shared library, bind references to global symbols to
384 the definition within the shared library, if any. Normally, it is
385 possible for a program linked against a shared library to override the
386 definition within the shared library. This option is only meaningful
387 on ELF platforms which support shared libraries.
390 .BI "\-c " "commandfile"
393 \& to read link commands from the file
396 \&. These commands will completely override \c
399 default link format (rather than adding to it); \c
402 specify everything necessary to describe the target format.
405 You may also include a script of link commands directly in the command
406 line by bracketing it between `\|\c
414 Output a cross reference table. If a linker map file is being
415 generated, the cross reference table is printed to the map file.
416 Otherwise, it is printed on the standard output.
424 These three options are equivalent; multiple forms are supported for
425 compatibility with other linkers. Use any of them to make \c
427 assign space to common symbols even if a relocatable output file is
430 \&). The script command
432 .B FORCE_COMMON_ALLOCATION\c
433 \& has the same effect.
436 .BI "-defsym " "symbol" "\fR = \fP" expression
437 Create a global symbol in the output file, containing the absolute
440 \&. You may use this option as many
441 times as necessary to define multiple symbols in the command line. A
442 limited form of arithmetic is supported for the \c
445 context: you may give a hexadecimal constant or the name of an existing
450 \& to add or subtract hexadecimal
451 constants or symbols. If you need more elaborate expressions, consider
452 using the linker command language from a script.
459 \& as the explicit symbol for beginning execution of your
460 program, rather than the default entry point. for a
461 discussion of defaults and other ways of specifying the
465 .B \-embedded\-relocs
466 This option is only meaningful when linking MIPS embedded PIC code,
469 option to the GNU compiler and assembler. It causes the linker to
470 create a table which may be used at runtime to relocate any data which
471 was statically initialized to pointer values. See the code in
472 testsuite/ld-empic for details.
478 When creating an ELF file, add all symbols to the dynamic symbol table.
479 Normally, the dynamic symbol table contains only symbols which are used
480 by a dynamic object. This option is needed for some uses of
487 Some older linkers used this option throughout a compilation toolchain
488 for specifying object-file format for both input and output object
491 \&'s mechanisms (the \c
496 for input files, the \c
498 \& command in linker scripts for output
501 \& environment variable) are more flexible, but
502 but it accepts (and ignores) the \c
504 \& option flag for compatibility
505 with scripts written to call the old linker.
508 .BI "\-format " "input\-format"
517 Accepted, but ignored; provided for compatibility with other tools.
521 Set the maximum size of objects to be optimized using the GP register
524 under MIPS ECOFF. Ignored for other object file formats.
528 Print a summary of the command-line options on the standard output and exit.
531 begin with two dashes instead of one
532 for compatibility with other GNU programs. The other options start with
533 only one dash for compatibility with other linkers.
537 Perform an incremental link (same as option \c
544 Add an archive file \c
546 \& to the list of files to link. This
547 option may be used any number of times. \c
550 path-list for occurrences of \c
559 .BI "\-L" "searchdir"
560 This command adds path \c
562 \& to the list of paths that
565 \& will search for archive libraries. You may use this option
568 The default set of paths searched (without being specified with
571 \&) depends on what emulation mode \c
574 some cases also on how it was configured. The
575 paths can also be specified in a link script with the \c
581 Print (to the standard output file) a link map\(em\&diagnostic information
582 about where symbols are mapped by \c
584 \&, and information on global
585 common storage allocation.
588 .BI "\-Map " "mapfile"\c
591 a link map\(em\&diagnostic information
592 about where symbols are mapped by \c
594 \&, and information on global
595 common storage allocation.
598 .BI "\-m " "emulation"\c
601 linker. You can list the available emulations with the
605 options. This option overrides the compiled-in default, which is the
606 system for which you configured
611 specifies readable and writable \c
616 the output format supports Unix style magic numbers, the output is
621 When you use the `\|\c
623 \&\|' option, the linker does not page-align the
628 sets the text segment to be read only, and \c
635 Normally, the linker will not produce an output file if it encounters
636 errors during the link process. With this flag, you can specify that
637 you wish the output file retained even after non-fatal errors.
640 .B \-no\-keep\-memory
641 The linker normally optimizes for speed over memory usage by caching
642 the symbol tables of input files in memory. This option tells the
643 linker to instead optimize for memory usage, by rereading the symbol
644 tables as necessary. This may be required if the linker runs out of
645 memory space while linking a large executable.
650 \& is a name for the program produced by \c
653 option is not specified, the name `\|\c
655 \|' is used by default. The
658 \& can also specify the output file name.
661 .BI "\-oformat " "output\-format"
662 Specify the binary format for the output object file.
663 You don't usually need to specify this, as
666 \& is configured to produce as a default output format the most
667 usual format on each machine. \c
669 \& is a text string, the
670 name of a particular format supported by the BFD libraries.
673 can also specify the output format, but this option overrides it.
676 .BI "\-R " "filename"
677 Read symbol names and their addresses from \c
680 relocate it or include it in the output. This allows your output file
681 to refer symbolically to absolute locations of memory defined in other
686 An option with machine dependent effects. Currently this option is only
687 supported on the H8/300.
689 On some platforms, use this option to perform global optimizations that
690 become possible when the linker resolves addressing in your program, such
691 as relaxing address modes and synthesizing new instructions in the
694 On platforms where this is not supported, `\|\c
696 \&\|' is accepted, but has no effect.
700 Generates relocatable output\(em\&i.e., generate an output file that can in
701 turn serve as input to \c
703 \&. This is often called \c
706 \&. As a side effect, in environments that support standard Unix
707 magic numbers, this option also sets the output file's magic number to
711 If this option is not specified, an absolute file is produced. When
712 linking C++ programs, this option \c
714 \& resolve references to
717 \& is an alternative.
719 This option does the same as \c
724 .B \-rpath\ \fIdirectory
725 Add a directory to the runtime library search path. This is used when
726 linking an ELF executable with shared objects. All
728 arguments are concatenated and passed to the runtime linker, which uses
729 them to locate shared objects at runtime. The
731 option is also used when locating shared objects which are needed by
732 shared objects explicitly included in the link; see the description of
737 is not used when linking an ELF executable, the contents of the
740 will be used if it is defined.
744 option may also be used on SunOS. By default, on SunOS, the linker
745 will form a runtime search patch out of all the
747 options it is given. If a
749 option is used, the runtime search path will be formed exclusively
755 options. This can be useful when using gcc, which adds many
757 options which may be on NFS mounted filesystems.
760 .B \-rpath\-link\ \fIdirectory
761 When using ELF or SunOS, one shared library may require another. This
764 link includes a shared library as one of the input files.
766 When the linker encounters such a dependency when doing a non-shared,
767 non-relocateable link, it will automatically try to locate the required
768 shared library and include it in the link, if it is not included
769 explicitly. In such a case, the
771 option specifies the first set of directories to search. The
773 option may specify a sequence of directory names either by specifying
774 a list of names separated by colons, or by appearing multiple times.
776 If the required shared library is not found, the linker will issue a
777 warning and continue with the link.
781 Omits debugger symbol information (but not all symbols) from the output file.
785 Omits all symbol information from the output file.
789 Create a shared library. This is currently only supported on ELF and
790 SunOS platforms (on SunOS it is not required, as the linker will
791 automatically create a shared library when there are undefined symbols
800 places the global common symbols in the appropriate output sections,
801 it sorts them by size. First come all the one byte symbols, then all
802 the two bytes, then all the four bytes, and then everything else.
803 This is to prevent gaps between symbols due to
804 alignment constraints. This option disables that sorting.
807 .B \-split\-by\-reloc\ \fIcount
808 Trys to creates extra sections in the output file so that no single
809 output section in the file contains more than
812 This is useful when generating huge relocatable for downloading into
813 certain real time kernels with the COFF object file format; since COFF
814 cannot represent more than 65535 relocations in a single section.
815 Note that this will fail to work with object file formats which do not
816 support arbitrary sections. The linker will not split up individual
817 input sections for redistribution, so if a single input section
820 relocations one output section will contain that many relocations.
825 .B \-split\-by\-reloc
826 but creates a new output section for each input file.
829 .BI "\-Tbss " "org"\c
831 .BI "\-Tdata " "org"\c
833 .BI "\-Ttext " "org"\c
836 \& as the starting address for\(em\&respectively\(em\&the
843 \& segment of the output file.
846 \& must be a hexadecimal integer.
849 .BI "\-T " "commandfile"
854 \&; supported for compatibility with
859 Prints names of input files as \c
867 \& to be entered in the output file as an undefined symbol.
868 This may, for example, trigger linking of additional modules from
869 standard libraries. \c
871 \& may be repeated with different option
872 arguments to enter additional undefined symbols.
876 For anything other than C++ programs, this option is equivalent to
879 \&: it generates relocatable output\(em\&i.e., an output file that can in
880 turn serve as input to \c
882 \&. When linking C++ programs, \c
885 \& resolve references to constructors, unlike \c
891 Display the version number for \c
893 and list the supported emulations.
894 Display which input files can and can not be opened.
898 Display the version number for \c
903 option also lists the supported emulations.
907 Display the version number for \c
913 Warn when a common symbol is combined with another common symbol or with
914 a symbol definition. Unix linkers allow this somewhat sloppy practice,
915 but linkers on some other operating systems do not. This option allows
916 you to find potential problems from combining global symbols.
919 .B \-warn\-constructors
920 Warn if any global constructors are used. This is only useful for a
921 few object file formats. For formats like COFF or ELF, the linker can
922 not detect the use of global constructors.
925 .B \-warn\-multiple\-gp
926 Warn if the output file requires multiple global-pointer values. This
927 option is only meaningful for certain processors, such as the Alpha.
931 Only warn once for each undefined symbol, rather than once per module
935 .B \-\-whole\-archive
936 For each archive mentioned on the command line after the
937 .B \-\-whole\-archive
938 option, include every object file in the archive in the link, rather
939 than searching the archive for the required object files. This is
940 normally used to turn an archive file into a shared library, forcing
941 every object to be included in the resulting shared library.
944 .B \-\-no\-whole\-archive
945 Turn off the effect of the
946 .B \-\-whole\-archive
947 option for archives which appear later on the command line.
950 .BI "--wrap " "symbol"
951 Use a wrapper function for
953 Any undefined reference to
956 .BI "__wrap_" "symbol".
957 Any undefined reference to
958 .BI "__real_" "symbol"
964 Delete all temporary local symbols. For most targets, this is all local
965 symbols whose names begin with `\|\c
971 Delete all local symbols.
977 You can change the behavior of
979 \& with the environment variable \c
985 \& determines the input-file object format if you don't
988 \& (or its synonym \c
990 \&). Its value should be one
991 of the BFD names for an input format. If there is no
994 \& in the environment, \c
996 \& uses the natural format
1001 \& then BFD attempts to discover the
1002 input format by examining binary input files; this method often
1003 succeeds, but there are potential ambiguities, since there is no method
1004 of ensuring that the magic number used to flag object-file formats is
1005 unique. However, the configuration procedure for BFD on each system
1006 places the conventional format for that system first in the search-list,
1007 so ambiguities are resolved in favor of convention.
1016 .RB "`\|" ld "\|' and `\|" binutils "\|'"
1021 ld: the GNU linker\c
1022 , Steve Chamberlain and Roland Pesch;
1024 The GNU Binary Utilities\c
1028 Copyright (c) 1991, 1992 Free Software Foundation, Inc.
1030 Permission is granted to make and distribute verbatim copies of
1031 this manual provided the copyright notice and this permission notice
1032 are preserved on all copies.
1034 Permission is granted to copy and distribute modified versions of this
1035 manual under the conditions for verbatim copying, provided that the
1036 entire resulting derived work is distributed under the terms of a
1037 permission notice identical to this one.
1039 Permission is granted to copy and distribute translations of this
1040 manual into another language, under the above conditions for modified
1041 versions, except that this permission notice may be included in
1042 translations approved by the Free Software Foundation instead of in
1043 the original English.