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 "\|]"
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\-once "\|]"
123 .RB "[\|" \-\-whole\-archive "\|]"
131 \& combines a number of object and archive files, relocates
132 their data and ties up symbol references. Often the last step in
133 building a new compiled program to run is a call to \c
139 \& accepts Linker Command Language files
140 to provide explicit and total control over the linking process.
141 This man page does not describe the command language; see the `\|\c
148 \&, for full details on the command language and on other aspects of
153 \& uses the general purpose BFD libraries
154 to operate on object files. This allows \c
156 \& to read, combine, and
157 write object files in many different formats\(em\&for example, COFF or
160 \&. Different formats may be linked together to produce any
161 available kind of object file. You can use `\|\c
163 \|' to get a list of formats supported on various architectures; see
166 Aside from its flexibility, the GNU linker is more helpful than other
167 linkers in providing diagnostic information. Many linkers abandon
168 execution immediately upon encountering an error; whenever possible,
171 \& continues executing, allowing you to identify other errors
172 (or, in some cases, to get an output file in spite of the error).
176 \& is meant to cover a broad range of situations,
177 and to be as compatible as possible with other linkers. As a result,
178 you have many choices to control its behavior through the command line,
179 and through environment variables.
182 The plethora of command-line options may seem intimidating, but in
183 actual practice few of them are used in any particular context.
184 For instance, a frequent use of \c
186 \& is to link standard Unix
187 object files on a standard, supported Unix system. On such a system, to
193 $\ ld\ \-o\ output\ /lib/crt0.o\ hello.o\ \-lc
198 \& to produce a file called \c
201 result of linking the file \c
208 \& which will come from the standard search
211 The command-line options to \c
213 \& may be specified in any order, and
214 may be repeated at will. For the most part, repeating an option with a
215 different argument will either have no further effect, or override prior
216 occurrences (those further to the left on the command line) of an
219 The exceptions\(em\&which may meaningfully be used more than once\(em\&are
224 \& (or its synonym \c
239 The list of object files to be linked together, shown as \c
242 may follow, precede, or be mixed in with command-line options; save that
245 \& argument may not be placed between an option flag and
248 Usually the linker is invoked with at least one object file, but other
249 forms of binary input files can also be specified with \c
254 \&, and the script command language. If \c
257 files at all are specified, the linker does not produce any output, and
258 issues the message `\|\c
262 Option arguments must either follow the option letter without intervening
263 whitespace, or be given as separate arguments immediately following the
264 option that requires them.
267 .BI "-A" "architecture"
268 In the current release of \c
270 \&, this option is useful only for the
271 Intel 960 family of architectures. In that \c
273 \& configuration, the
276 \& argument is one of the two-letter names identifying
277 members of the 960 family; the option specifies the desired output
278 target, and warns of any incompatible instructions in the input files.
279 It also modifies the linker's search strategy for archive libraries, to
280 support the use of libraries specific to each particular
281 architecture, by including in the search loop names suffixed with the
282 string identifying the architecture.
284 For example, if your \c
286 \& command line included `\|\c
291 \|', the linker would look (in its built-in search
292 paths, and in any paths you specify with \c
294 \&) for a library with
308 The first two possibilities would be considered in any event; the last
309 two are due to the use of `\|\c
313 Future releases of \c
315 \& may support similar functionality for
316 other architecture families.
318 You can meaningfully use \c
320 \& more than once on a command line, if
321 an architecture family allows combination of target architectures; each
322 use will add another pair of name variants to search for when \c
327 .BI "\-b " "input-format"
328 Specify the binary format for input object files that follow this option
329 on the command line. You don't usually need to specify this, as
332 \& is configured to expect as a default input format the most
333 usual format on each machine. \c
335 \& is a text string, the
336 name of a particular format supported by the BFD libraries.
341 \& has the same effect, as does the script command
344 You may want to use this option if you are linking files with an unusual
345 binary format. You can also use \c
347 \& to switch formats explicitly (when
348 linking object files of different formats), by including
353 \& before each group of object files in a
356 The default format is taken from the environment variable
358 \&. You can also define the input
359 format from a script, using the command \c
365 Do not link against shared libraries. This is only meaningful on
366 platforms for which shared libraries are supported.
370 Link against dynamic libraries. This is only meaningful on platforms
371 for which shared libraries are supported. This option is normally the
372 default on such platforms.
376 When creating a shared library, bind references to global symbols to
377 the definition within the shared library, if any. Normally, it is
378 possible for a program linked against a shared library to override the
379 definition within the shared library. This option is only meaningful
380 on ELF platforms which support shared libraries.
383 .BI "\-c " "commandfile"
386 \& to read link commands from the file
389 \&. These commands will completely override \c
392 default link format (rather than adding to it); \c
395 specify everything necessary to describe the target format.
398 You may also include a script of link commands directly in the command
399 line by bracketing it between `\|\c
411 These three options are equivalent; multiple forms are supported for
412 compatibility with other linkers. Use any of them to make \c
414 assign space to common symbols even if a relocatable output file is
417 \&). The script command
419 .B FORCE_COMMON_ALLOCATION\c
420 \& has the same effect.
423 .BI "-defsym " "symbol" "\fR = \fP" expression
424 Create a global symbol in the output file, containing the absolute
427 \&. You may use this option as many
428 times as necessary to define multiple symbols in the command line. A
429 limited form of arithmetic is supported for the \c
432 context: you may give a hexadecimal constant or the name of an existing
437 \& to add or subtract hexadecimal
438 constants or symbols. If you need more elaborate expressions, consider
439 using the linker command language from a script.
446 \& as the explicit symbol for beginning execution of your
447 program, rather than the default entry point. for a
448 discussion of defaults and other ways of specifying the
452 .B \-embedded\-relocs
453 This option is only meaningful when linking MIPS embedded PIC code,
456 option to the GNU compiler and assembler. It causes the linker to
457 create a table which may be used at runtime to relocate any data which
458 was statically initialized to pointer values. See the code in
459 testsuite/ld-empic for details.
463 When creating an ELF file, add all symbols to the dynamic symbol table.
464 Normally, the dynamic symbol table contains only symbols which are used
465 by a dynamic object. This option is needed for some uses of
472 Some older linkers used this option throughout a compilation toolchain
473 for specifying object-file format for both input and output object
476 \&'s mechanisms (the \c
481 for input files, the \c
483 \& command in linker scripts for output
486 \& environment variable) are more flexible, but
487 but it accepts (and ignores) the \c
489 \& option flag for compatibility
490 with scripts written to call the old linker.
493 .BI "\-format " "input\-format"
502 Accepted, but ignored; provided for compatibility with other tools.
506 Set the maximum size of objects to be optimized using the GP register
509 under MIPS ECOFF. Ignored for other object file formats.
513 Print a summary of the command-line options on the standard output and exit.
516 begin with two dashes instead of one
517 for compatibility with other GNU programs. The other options start with
518 only one dash for compatibility with other linkers.
522 Perform an incremental link (same as option \c
529 Add an archive file \c
531 \& to the list of files to link. This
532 option may be used any number of times. \c
535 path-list for occurrences of \c
544 .BI "\-L" "searchdir"
545 This command adds path \c
547 \& to the list of paths that
550 \& will search for archive libraries. You may use this option
553 The default set of paths searched (without being specified with
556 \&) depends on what emulation mode \c
559 some cases also on how it was configured. The
560 paths can also be specified in a link script with the \c
566 Print (to the standard output file) a link map\(em\&diagnostic information
567 about where symbols are mapped by \c
569 \&, and information on global
570 common storage allocation.
573 .BI "\-Map " "mapfile"\c
576 a link map\(em\&diagnostic information
577 about where symbols are mapped by \c
579 \&, and information on global
580 common storage allocation.
583 .BI "\-m " "emulation"\c
586 linker. You can list the available emulations with the
590 options. This option overrides the compiled-in default, which is the
591 system for which you configured
596 specifies readable and writable \c
601 the output format supports Unix style magic numbers, the output is
606 When you use the `\|\c
608 \&\|' option, the linker does not page-align the
613 sets the text segment to be read only, and \c
620 Normally, the linker will not produce an output file if it encounters
621 errors during the link process. With this flag, you can specify that
622 you wish the output file retained even after non-fatal errors.
625 .B \-no\-keep\-memory
626 The linker normally optimizes for speed over memory usage by caching
627 the symbol tables of input files in memory. This option tells the
628 linker to instead optimize for memory usage, by rereading the symbol
629 tables as necessary. This may be required if the linker runs out of
630 memory space while linking a large executable.
635 \& is a name for the program produced by \c
638 option is not specified, the name `\|\c
640 \|' is used by default. The
643 \& can also specify the output file name.
646 .BI "\-oformat " "output\-format"
647 Specify the binary format for the output object file.
648 You don't usually need to specify this, as
651 \& is configured to produce as a default output format the most
652 usual format on each machine. \c
654 \& is a text string, the
655 name of a particular format supported by the BFD libraries.
658 can also specify the output format, but this option overrides it.
661 .BI "\-R " "filename"
662 Read symbol names and their addresses from \c
665 relocate it or include it in the output. This allows your output file
666 to refer symbolically to absolute locations of memory defined in other
671 An option with machine dependent effects. Currently this option is only
672 supported on the H8/300.
674 On some platforms, use this option to perform global optimizations that
675 become possible when the linker resolves addressing in your program, such
676 as relaxing address modes and synthesizing new instructions in the
679 On platforms where this is not supported, `\|\c
681 \&\|' is accepted, but has no effect.
685 Generates relocatable output\(em\&i.e., generate an output file that can in
686 turn serve as input to \c
688 \&. This is often called \c
691 \&. As a side effect, in environments that support standard Unix
692 magic numbers, this option also sets the output file's magic number to
696 If this option is not specified, an absolute file is produced. When
697 linking C++ programs, this option \c
699 \& resolve references to
702 \& is an alternative.
704 This option does the same as \c
709 .B \-rpath\ \fIdirectory
710 Add a directory to the runtime library search path. This is used when
711 linking an ELF executable with shared objects. All
713 arguments are concatenated and passed to the runtime linker, which uses
714 them to locate shared objects at runtime. The
716 option is also used when locating shared objects which are needed by
717 shared objects explicitly included in the link; see the description of
722 is not used when linking an ELF executable, the contents of the
725 will be used if it is defined.
729 option may also be used on SunOS. By default, on SunOS, the linker
730 will form a runtime search patch out of all the
732 options it is given. If a
734 option is used, the runtime search path will be formed exclusively
740 options. This can be useful when using gcc, which adds many
742 options which may be on NFS mounted filesystems.
745 .B \-rpath\-link\ \fIdirectory
746 When using ELF or SunOS, one shared library may require another. This
749 link includes a shared library as one of the input files.
751 When the linker encounters such a dependency when doing a non-shared,
752 non-relocateable link, it will automatically try to locate the required
753 shared library and include it in the link, if it is not included
754 explicitly. In such a case, the
756 option specifies the first set of directories to search. The
758 option may specify a sequence of directory names either by specifying
759 a list of names separated by colons, or by appearing multiple times.
761 If the required shared library is not found, the linker will issue a
762 warning and continue with the link.
766 Omits debugger symbol information (but not all symbols) from the output file.
770 Omits all symbol information from the output file.
774 Create a shared library. This is currently only supported on ELF and
775 SunOS platforms (on SunOS it is not required, as the linker will
776 automatically create a shared library when there are undefined symbols
785 places the global common symbols in the appropriate output sections,
786 it sorts them by size. First come all the one byte symbols, then all
787 the two bytes, then all the four bytes, and then everything else.
788 This is to prevent gaps between symbols due to
789 alignment constraints. This option disables that sorting.
792 .B \-split\-by\-reloc\ \fIcount
793 Trys to creates extra sections in the output file so that no single
794 output section in the file contains more than
797 This is useful when generating huge relocatable for downloading into
798 certain real time kernels with the COFF object file format; since COFF
799 cannot represent more than 65535 relocations in a single section.
800 Note that this will fail to work with object file formats which do not
801 support arbitrary sections. The linker will not split up individual
802 input sections for redistribution, so if a single input section
805 relocations one output section will contain that many relocations.
810 .B \-split\-by\-reloc
811 but creates a new output section for each input file.
814 .BI "\-Tbss " "org"\c
816 .BI "\-Tdata " "org"\c
818 .BI "\-Ttext " "org"\c
821 \& as the starting address for\(em\&respectively\(em\&the
828 \& segment of the output file.
831 \& must be a hexadecimal integer.
834 .BI "\-T " "commandfile"
839 \&; supported for compatibility with
844 Prints names of input files as \c
852 \& to be entered in the output file as an undefined symbol.
853 This may, for example, trigger linking of additional modules from
854 standard libraries. \c
856 \& may be repeated with different option
857 arguments to enter additional undefined symbols.
861 For anything other than C++ programs, this option is equivalent to
864 \&: it generates relocatable output\(em\&i.e., an output file that can in
865 turn serve as input to \c
867 \&. When linking C++ programs, \c
870 \& resolve references to constructors, unlike \c
876 Display the version number for \c
878 and list the supported emulations.
879 Display which input files can and can not be opened.
883 Display the version number for \c
888 option also lists the supported emulations.
892 Display the version number for \c
898 Warn when a common symbol is combined with another common symbol or with
899 a symbol definition. Unix linkers allow this somewhat sloppy practice,
900 but linkers on some other operating systems do not. This option allows
901 you to find potential problems from combining global symbols.
904 .B \-warn\-constructors
905 Warn if any global constructors are used. This is only useful for a
906 few object file formats. For formats like COFF or ELF, the linker can
907 not detect the use of global constructors.
911 Only warn once for each undefined symbol, rather than once per module
915 .B \-\-whole\-archive
916 For each archive mentioned on the command line, include every object
917 file in the archive in the link, rather than searching the archive for
918 the required object files. This is normally used to turn an archive
919 file into a shared library, forcing every object to be included in the
920 resulting shared library.
924 Delete all temporary local symbols. For most targets, this is all local
925 symbols whose names begin with `\|\c
931 Delete all local symbols.
937 You can change the behavior of
939 \& with the environment variable \c
945 \& determines the input-file object format if you don't
948 \& (or its synonym \c
950 \&). Its value should be one
951 of the BFD names for an input format. If there is no
954 \& in the environment, \c
956 \& uses the natural format
961 \& then BFD attempts to discover the
962 input format by examining binary input files; this method often
963 succeeds, but there are potential ambiguities, since there is no method
964 of ensuring that the magic number used to flag object-file formats is
965 unique. However, the configuration procedure for BFD on each system
966 places the conventional format for that system first in the search-list,
967 so ambiguities are resolved in favor of convention.
976 .RB "`\|" ld "\|' and `\|" binutils "\|'"
982 , Steve Chamberlain and Roland Pesch;
984 The GNU Binary Utilities\c
988 Copyright (c) 1991, 1992 Free Software Foundation, Inc.
990 Permission is granted to make and distribute verbatim copies of
991 this manual provided the copyright notice and this permission notice
992 are preserved on all copies.
994 Permission is granted to copy and distribute modified versions of this
995 manual under the conditions for verbatim copying, provided that the
996 entire resulting derived work is distributed under the terms of a
997 permission notice identical to this one.
999 Permission is granted to copy and distribute translations of this
1000 manual into another language, under the above conditions for modified
1001 versions, except that this permission notice may be included in
1002 translations approved by the Free Software Foundation instead of in
1003 the original English.