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 "[\|" \-d | \-dc | \-dp\c
39 .RB "[\|" "\-defsym\ "\c
47 .RB "[\|" \-embedded\-relocs "\|]"
48 .RB "[\|" \-export\-dynamic "\|]"
53 .RB "[\|" "\-format\ "\c
60 .RB "[\|" \-\-help "\|]"
75 .RB "[\|" \-n | \-N "\|]"
76 .RB "[\|" \-noinhibit-exec "\|]"
77 .RB "[\|" \-no\-keep\-memory "\|]"
78 .RB "[\|" "\-oformat\ "\c
84 .RB "[\|" \-relax "\|]"
85 .RB "[\|" \-r | \-Ur "\|]"
86 .RB "[\|" "\-rpath\ "\c
89 .RB "[\|" "\-rpath\-link\ "\c
94 .RB "[\|" \-shared "\|]"
95 .RB "[\|" \-sort\-common "\|]"
96 .RB "[\|" "\-split\-by\-reloc\ "\c
99 .RB "[\|" \-split\-by\-file "\|]"
103 .RB "[\|" "\-Ttext\ "\c
106 .RB "[\|" "\-Tdata\ "\c
109 .RB "[\|" "\-Tbss\ "\c
118 .RB "[\|" \-\-verbose "\|]"
119 .RB "[\|" \-\-version "\|]"
120 .RB "[\|" \-warn\-common "\|]"
121 .RB "[\|" \-warn\-constructors "\|]"
122 .RB "[\|" \-warn\-multiple\-gp "\|]"
123 .RB "[\|" \-warn\-once "\|]"
124 .RB "[\|" \-\-whole\-archive "\|]"
125 .RB "[\|" \-\-no\-whole\-archive "\|]"
126 .RB "[\|" "\-\-wrap\ "\c
136 \& combines a number of object and archive files, relocates
137 their data and ties up symbol references. Often the last step in
138 building a new compiled program to run is a call to \c
144 \& accepts Linker Command Language files
145 to provide explicit and total control over the linking process.
146 This man page does not describe the command language; see the `\|\c
153 \&, for full details on the command language and on other aspects of
158 \& uses the general purpose BFD libraries
159 to operate on object files. This allows \c
161 \& to read, combine, and
162 write object files in many different formats\(em\&for example, COFF or
165 \&. Different formats may be linked together to produce any
166 available kind of object file. You can use `\|\c
168 \|' to get a list of formats supported on various architectures; see
171 Aside from its flexibility, the GNU linker is more helpful than other
172 linkers in providing diagnostic information. Many linkers abandon
173 execution immediately upon encountering an error; whenever possible,
176 \& continues executing, allowing you to identify other errors
177 (or, in some cases, to get an output file in spite of the error).
181 \& is meant to cover a broad range of situations,
182 and to be as compatible as possible with other linkers. As a result,
183 you have many choices to control its behavior through the command line,
184 and through environment variables.
187 The plethora of command-line options may seem intimidating, but in
188 actual practice few of them are used in any particular context.
189 For instance, a frequent use of \c
191 \& is to link standard Unix
192 object files on a standard, supported Unix system. On such a system, to
198 $\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
203 \& to produce a file called \c
206 result of linking the file \c
213 \& which will come from the standard search
216 The command-line options to \c
218 \& may be specified in any order, and
219 may be repeated at will. For the most part, repeating an option with a
220 different argument will either have no further effect, or override prior
221 occurrences (those further to the left on the command line) of an
224 The exceptions\(em\&which may meaningfully be used more than once\(em\&are
229 \& (or its synonym \c
244 The list of object files to be linked together, shown as \c
247 may follow, precede, or be mixed in with command-line options; save that
250 \& argument may not be placed between an option flag and
253 Usually the linker is invoked with at least one object file, but other
254 forms of binary input files can also be specified with \c
259 \&, and the script command language. If \c
262 files at all are specified, the linker does not produce any output, and
263 issues the message `\|\c
267 Option arguments must either follow the option letter without intervening
268 whitespace, or be given as separate arguments immediately following the
269 option that requires them.
272 .BI "-A" "architecture"
273 In the current release of \c
275 \&, this option is useful only for the
276 Intel 960 family of architectures. In that \c
278 \& configuration, the
281 \& argument is one of the two-letter names identifying
282 members of the 960 family; the option specifies the desired output
283 target, and warns of any incompatible instructions in the input files.
284 It also modifies the linker's search strategy for archive libraries, to
285 support the use of libraries specific to each particular
286 architecture, by including in the search loop names suffixed with the
287 string identifying the architecture.
289 For example, if your \c
291 \& command line included `\|\c
296 \|', the linker would look (in its built-in search
297 paths, and in any paths you specify with \c
299 \&) for a library with
313 The first two possibilities would be considered in any event; the last
314 two are due to the use of `\|\c
318 Future releases of \c
320 \& may support similar functionality for
321 other architecture families.
323 You can meaningfully use \c
325 \& more than once on a command line, if
326 an architecture family allows combination of target architectures; each
327 use will add another pair of name variants to search for when \c
332 .BI "\-b " "input-format"
333 Specify the binary format for input object files that follow this option
334 on the command line. You don't usually need to specify this, as
337 \& is configured to expect as a default input format the most
338 usual format on each machine. \c
340 \& is a text string, the
341 name of a particular format supported by the BFD libraries.
346 \& has the same effect, as does the script command
349 You may want to use this option if you are linking files with an unusual
350 binary format. You can also use \c
352 \& to switch formats explicitly (when
353 linking object files of different formats), by including
358 \& before each group of object files in a
361 The default format is taken from the environment variable
363 \&. You can also define the input
364 format from a script, using the command \c
370 Do not link against shared libraries. This is only meaningful on
371 platforms for which shared libraries are supported.
375 Link against dynamic libraries. This is only meaningful on platforms
376 for which shared libraries are supported. This option is normally the
377 default on such platforms.
381 When creating a shared library, bind references to global symbols to
382 the definition within the shared library, if any. Normally, it is
383 possible for a program linked against a shared library to override the
384 definition within the shared library. This option is only meaningful
385 on ELF platforms which support shared libraries.
388 .BI "\-c " "commandfile"
391 \& to read link commands from the file
394 \&. These commands will completely override \c
397 default link format (rather than adding to it); \c
400 specify everything necessary to describe the target format.
403 You may also include a script of link commands directly in the command
404 line by bracketing it between `\|\c
416 These three options are equivalent; multiple forms are supported for
417 compatibility with other linkers. Use any of them to make \c
419 assign space to common symbols even if a relocatable output file is
422 \&). The script command
424 .B FORCE_COMMON_ALLOCATION\c
425 \& has the same effect.
428 .BI "-defsym " "symbol" "\fR = \fP" expression
429 Create a global symbol in the output file, containing the absolute
432 \&. You may use this option as many
433 times as necessary to define multiple symbols in the command line. A
434 limited form of arithmetic is supported for the \c
437 context: you may give a hexadecimal constant or the name of an existing
442 \& to add or subtract hexadecimal
443 constants or symbols. If you need more elaborate expressions, consider
444 using the linker command language from a script.
451 \& as the explicit symbol for beginning execution of your
452 program, rather than the default entry point. for a
453 discussion of defaults and other ways of specifying the
457 .B \-embedded\-relocs
458 This option is only meaningful when linking MIPS embedded PIC code,
461 option to the GNU compiler and assembler. It causes the linker to
462 create a table which may be used at runtime to relocate any data which
463 was statically initialized to pointer values. See the code in
464 testsuite/ld-empic for details.
468 When creating an ELF file, add all symbols to the dynamic symbol table.
469 Normally, the dynamic symbol table contains only symbols which are used
470 by a dynamic object. This option is needed for some uses of
477 Some older linkers used this option throughout a compilation toolchain
478 for specifying object-file format for both input and output object
481 \&'s mechanisms (the \c
486 for input files, the \c
488 \& command in linker scripts for output
491 \& environment variable) are more flexible, but
492 but it accepts (and ignores) the \c
494 \& option flag for compatibility
495 with scripts written to call the old linker.
498 .BI "\-format " "input\-format"
507 Accepted, but ignored; provided for compatibility with other tools.
511 Set the maximum size of objects to be optimized using the GP register
514 under MIPS ECOFF. Ignored for other object file formats.
518 Print a summary of the command-line options on the standard output and exit.
521 begin with two dashes instead of one
522 for compatibility with other GNU programs. The other options start with
523 only one dash for compatibility with other linkers.
527 Perform an incremental link (same as option \c
534 Add an archive file \c
536 \& to the list of files to link. This
537 option may be used any number of times. \c
540 path-list for occurrences of \c
549 .BI "\-L" "searchdir"
550 This command adds path \c
552 \& to the list of paths that
555 \& will search for archive libraries. You may use this option
558 The default set of paths searched (without being specified with
561 \&) depends on what emulation mode \c
564 some cases also on how it was configured. The
565 paths can also be specified in a link script with the \c
571 Print (to the standard output file) a link map\(em\&diagnostic information
572 about where symbols are mapped by \c
574 \&, and information on global
575 common storage allocation.
578 .BI "\-Map " "mapfile"\c
581 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 "\-m " "emulation"\c
591 linker. You can list the available emulations with the
595 options. This option overrides the compiled-in default, which is the
596 system for which you configured
601 specifies readable and writable \c
606 the output format supports Unix style magic numbers, the output is
611 When you use the `\|\c
613 \&\|' option, the linker does not page-align the
618 sets the text segment to be read only, and \c
625 Normally, the linker will not produce an output file if it encounters
626 errors during the link process. With this flag, you can specify that
627 you wish the output file retained even after non-fatal errors.
630 .B \-no\-keep\-memory
631 The linker normally optimizes for speed over memory usage by caching
632 the symbol tables of input files in memory. This option tells the
633 linker to instead optimize for memory usage, by rereading the symbol
634 tables as necessary. This may be required if the linker runs out of
635 memory space while linking a large executable.
640 \& is a name for the program produced by \c
643 option is not specified, the name `\|\c
645 \|' is used by default. The
648 \& can also specify the output file name.
651 .BI "\-oformat " "output\-format"
652 Specify the binary format for the output object file.
653 You don't usually need to specify this, as
656 \& is configured to produce as a default output format the most
657 usual format on each machine. \c
659 \& is a text string, the
660 name of a particular format supported by the BFD libraries.
663 can also specify the output format, but this option overrides it.
666 .BI "\-R " "filename"
667 Read symbol names and their addresses from \c
670 relocate it or include it in the output. This allows your output file
671 to refer symbolically to absolute locations of memory defined in other
676 An option with machine dependent effects. Currently this option is only
677 supported on the H8/300.
679 On some platforms, use this option to perform global optimizations that
680 become possible when the linker resolves addressing in your program, such
681 as relaxing address modes and synthesizing new instructions in the
684 On platforms where this is not supported, `\|\c
686 \&\|' is accepted, but has no effect.
690 Generates relocatable output\(em\&i.e., generate an output file that can in
691 turn serve as input to \c
693 \&. This is often called \c
696 \&. As a side effect, in environments that support standard Unix
697 magic numbers, this option also sets the output file's magic number to
701 If this option is not specified, an absolute file is produced. When
702 linking C++ programs, this option \c
704 \& resolve references to
707 \& is an alternative.
709 This option does the same as \c
714 .B \-rpath\ \fIdirectory
715 Add a directory to the runtime library search path. This is used when
716 linking an ELF executable with shared objects. All
718 arguments are concatenated and passed to the runtime linker, which uses
719 them to locate shared objects at runtime. The
721 option is also used when locating shared objects which are needed by
722 shared objects explicitly included in the link; see the description of
727 is not used when linking an ELF executable, the contents of the
730 will be used if it is defined.
734 option may also be used on SunOS. By default, on SunOS, the linker
735 will form a runtime search patch out of all the
737 options it is given. If a
739 option is used, the runtime search path will be formed exclusively
745 options. This can be useful when using gcc, which adds many
747 options which may be on NFS mounted filesystems.
750 .B \-rpath\-link\ \fIdirectory
751 When using ELF or SunOS, one shared library may require another. This
754 link includes a shared library as one of the input files.
756 When the linker encounters such a dependency when doing a non-shared,
757 non-relocateable link, it will automatically try to locate the required
758 shared library and include it in the link, if it is not included
759 explicitly. In such a case, the
761 option specifies the first set of directories to search. The
763 option may specify a sequence of directory names either by specifying
764 a list of names separated by colons, or by appearing multiple times.
766 If the required shared library is not found, the linker will issue a
767 warning and continue with the link.
771 Omits debugger symbol information (but not all symbols) from the output file.
775 Omits all symbol information from the output file.
779 Create a shared library. This is currently only supported on ELF and
780 SunOS platforms (on SunOS it is not required, as the linker will
781 automatically create a shared library when there are undefined symbols
790 places the global common symbols in the appropriate output sections,
791 it sorts them by size. First come all the one byte symbols, then all
792 the two bytes, then all the four bytes, and then everything else.
793 This is to prevent gaps between symbols due to
794 alignment constraints. This option disables that sorting.
797 .B \-split\-by\-reloc\ \fIcount
798 Trys to creates extra sections in the output file so that no single
799 output section in the file contains more than
802 This is useful when generating huge relocatable for downloading into
803 certain real time kernels with the COFF object file format; since COFF
804 cannot represent more than 65535 relocations in a single section.
805 Note that this will fail to work with object file formats which do not
806 support arbitrary sections. The linker will not split up individual
807 input sections for redistribution, so if a single input section
810 relocations one output section will contain that many relocations.
815 .B \-split\-by\-reloc
816 but creates a new output section for each input file.
819 .BI "\-Tbss " "org"\c
821 .BI "\-Tdata " "org"\c
823 .BI "\-Ttext " "org"\c
826 \& as the starting address for\(em\&respectively\(em\&the
833 \& segment of the output file.
836 \& must be a hexadecimal integer.
839 .BI "\-T " "commandfile"
844 \&; supported for compatibility with
849 Prints names of input files as \c
857 \& to be entered in the output file as an undefined symbol.
858 This may, for example, trigger linking of additional modules from
859 standard libraries. \c
861 \& may be repeated with different option
862 arguments to enter additional undefined symbols.
866 For anything other than C++ programs, this option is equivalent to
869 \&: it generates relocatable output\(em\&i.e., an output file that can in
870 turn serve as input to \c
872 \&. When linking C++ programs, \c
875 \& resolve references to constructors, unlike \c
881 Display the version number for \c
883 and list the supported emulations.
884 Display which input files can and can not be opened.
888 Display the version number for \c
893 option also lists the supported emulations.
897 Display the version number for \c
903 Warn when a common symbol is combined with another common symbol or with
904 a symbol definition. Unix linkers allow this somewhat sloppy practice,
905 but linkers on some other operating systems do not. This option allows
906 you to find potential problems from combining global symbols.
909 .B \-warn\-constructors
910 Warn if any global constructors are used. This is only useful for a
911 few object file formats. For formats like COFF or ELF, the linker can
912 not detect the use of global constructors.
915 .B \-warn\-multiple\-gp
916 Warn if the output file requires multiple global-pointer values. This
917 option is only meaningful for certain processors, such as the Alpha.
921 Only warn once for each undefined symbol, rather than once per module
925 .B \-\-whole\-archive
926 For each archive mentioned on the command line after the
927 .B \-\-whole\-archive
928 option, include every object file in the archive in the link, rather
929 than searching the archive for the required object files. This is
930 normally used to turn an archive file into a shared library, forcing
931 every object to be included in the resulting shared library.
934 .B \-\-no\-whole\-archive
935 Turn off the effect of the
936 .B \-\-whole\-archive
937 option for archives which appear later on the command line.
940 .BI "--wrap " "symbol"
941 Use a wrapper function for
943 Any undefined reference to
946 .BI "__wrap_" "symbol".
947 Any undefined reference to
948 .BI "__real_" "symbol"
954 Delete all temporary local symbols. For most targets, this is all local
955 symbols whose names begin with `\|\c
961 Delete all local symbols.
967 You can change the behavior of
969 \& with the environment variable \c
975 \& determines the input-file object format if you don't
978 \& (or its synonym \c
980 \&). Its value should be one
981 of the BFD names for an input format. If there is no
984 \& in the environment, \c
986 \& uses the natural format
991 \& then BFD attempts to discover the
992 input format by examining binary input files; this method often
993 succeeds, but there are potential ambiguities, since there is no method
994 of ensuring that the magic number used to flag object-file formats is
995 unique. However, the configuration procedure for BFD on each system
996 places the conventional format for that system first in the search-list,
997 so ambiguities are resolved in favor of convention.
1006 .RB "`\|" ld "\|' and `\|" binutils "\|'"
1011 ld: the GNU linker\c
1012 , Steve Chamberlain and Roland Pesch;
1014 The GNU Binary Utilities\c
1018 Copyright (c) 1991, 1992 Free Software Foundation, Inc.
1020 Permission is granted to make and distribute verbatim copies of
1021 this manual provided the copyright notice and this permission notice
1022 are preserved on all copies.
1024 Permission is granted to copy and distribute modified versions of this
1025 manual under the conditions for verbatim copying, provided that the
1026 entire resulting derived work is distributed under the terms of a
1027 permission notice identical to this one.
1029 Permission is granted to copy and distribute translations of this
1030 manual into another language, under the above conditions for modified
1031 versions, except that this permission notice may be included in
1032 translations approved by the Free Software Foundation instead of in
1033 the original English.