MAN page from Trustix binutils-


Section: GNU Development Tools (1)
Updated: 17 August 1992



ld - the GNU linker



[-ooutput] objfile...
[-Aarchitecture] [-b input-format] [-Bstatic][-Bdynamic][-Bsymbolic][-c commandfile] [--cref][-d|-dc|-dp]
[-defsym symbol=expression][--demangle][--no-demangle][-e entry] [-embedded-relocs][-E][-export-dynamic][-f name][--auxiliary name][-F name][--filter name][-format input-format] [-g][-Gsize][-h name][-soname name][--help][-i][-lar] [-Lsearchdir] [-M][-Mapmapfile] [-memulation] [-n|-N][-noinhibit-exec][-no-keep-memory][-no-warn-mismatch][-Olevel][-oformat output-format] [-R filename][-relax][-r|-Ur][-rpath directory][-rpath-link directory][-S][-s][-shared][-sort-common][-split-by-reloc count][-split-by-file][-T commandfile] [--section-start sectionname=sectionorg][-Ttext textorg] [-Tdata dataorg] [-Tbss bssorg][-t][-u sym][-V][-v][--verbose][--version][-warn-common][-warn-constructors][-warn-multiple-gp][-warn-once][-warn-section-align][--whole-archive][--no-whole-archive][--wrap symbol][-X][-x]


ld combines a number of object and archive files, relocatestheir data and ties up symbol references. Often the last step inbuilding a new compiled program to run is a call to ld.

ld accepts Linker Command Language files to provide explicit and total control over the linking process.This man page does not describe the command language; see the `ld' entry in `info', or the manualld: the GNU linker, for full details on the command language and on other aspects ofthe GNU linker.

This version of ld uses the general purpose BFD librariesto operate on object files. This allows ld to read, combine, andwrite object files in many different formats---for example, COFF ora.out. Different formats may be linked together to produce anyavailable kind of object file. You can use `objdump -i' to get a list of formats supported on various architectures; see objdump(1).

Aside from its flexibility, the GNU linker is more helpful than otherlinkers in providing diagnostic information. Many linkers abandonexecution immediately upon encountering an error; whenever possible,ld continues executing, allowing you to identify other errors(or, in some cases, to get an output file in spite of the error).

The GNU linker ld is meant to cover a broad range of situations,and to be as compatible as possible with other linkers. As a result,you have many choices to control its behavior through the command line,and through environment variables.



The plethora of command-line options may seem intimidating, but inactual practice few of them are used in any particular context.For instance, a frequent use of ld is to link standard Unixobject files on a standard, supported Unix system. On such a system, tolink a file hello.o:

$ ld -o output /lib/crt0.o hello.o -lc

This tells ld to produce a file called output as theresult of linking the file /lib/crt0.o with hello.o andthe library libc.a which will come from the standard searchdirectories.

The command-line options to ld may be specified in any order, andmay be repeated at will. For the most part, repeating an option with adifferent argument will either have no further effect, or override prioroccurrences (those further to the left on the command line) of anoption.

The exceptions---which may meaningfully be used more than once---are-A, -b (or its synonym -format), -defsym, --section-start, -L, -l, -R, and -u.

The list of object files to be linked together, shown as objfile,may follow, precede, or be mixed in with command-line options; save thatan objfile argument may not be placed between an option flag andits argument.

Usually the linker is invoked with at least one object file, but otherforms of binary input files can also be specified with -l,-R, and the script command language. If no binary inputfiles at all are specified, the linker does not produce any output, andissues the message `No input files'.

Option arguments must either follow the option letter without interveningwhitespace, or be given as separate arguments immediately following theoption that requires them.

In the current release of ld, this option is useful only for theIntel 960 family of architectures. In that ld configuration, thearchitecture argument is one of the two-letter names identifyingmembers of the 960 family; the option specifies the desired outputtarget, and warns of any incompatible instructions in the input files.It also modifies the linker's search strategy for archive libraries, tosupport the use of libraries specific to each particulararchitecture, by including in the search loop names suffixed with thestring identifying the architecture.

For example, if your ld command line included `-ACA' aswell as `-ltry', the linker would look (in its built-in searchpaths, and in any paths you specify with -L) for a library withthe names


The first two possibilities would be considered in any event; the lasttwo are due to the use of `-ACA'.

Future releases of ld may support similar functionality forother architecture families.

You can meaningfully use -A more than once on a command line, ifan architecture family allows combination of target architectures; eachuse will add another pair of name variants to search for when -lspecifies a library.

-b input-format
Specify the binary format for input object files that follow this optionon the command line. You don't usually need to specify this, asld is configured to expect as a default input format the mostusual format on each machine. input-format is a text string, thename of a particular format supported by the BFD libraries. -format input-format has the same effect, as does the script commandTARGET.

You may want to use this option if you are linking files with an unusualbinary format. You can also use -b to switch formats explicitly (whenlinking object files of different formats), by including-b input-format before each group of object files in aparticular format.

The default format is taken from the environment variableGNUTARGET. You can also define the inputformat from a script, using the command TARGET.

Do not link against shared libraries. This is only meaningful onplatforms for which shared libraries are supported.

Link against dynamic libraries. This is only meaningful on platformsfor which shared libraries are supported. This option is normally thedefault on such platforms.

When creating a shared library, bind references to global symbols tothe definition within the shared library, if any. Normally, it ispossible for a program linked against a shared library to override thedefinition within the shared library. This option is only meaningfulon ELF platforms which support shared libraries.

-c commandfile
Directs ld to read link commands from the filecommandfile. These commands will completely override ld'sdefault link format (rather than adding to it); commandfile mustspecify everything necessary to describe the target format.

You may also include a script of link commands directly in the commandline by bracketing it between `{' and `}' characters.

Output a cross reference table. If a linker map file is beinggenerated, the cross reference table is printed to the map file.Otherwise, it is printed on the standard output.

These three options are equivalent; multiple forms are supported forcompatibility with other linkers. Use any of them to make ldassign space to common symbols even if a relocatable output file isspecified (-r). The script commandFORCE_COMMON_ALLOCATION has the same effect.

-defsym symbol=expression
Create a global symbol in the output file, containing the absoluteaddress given by expression. You may use this option as manytimes as necessary to define multiple symbols in the command line. Alimited form of arithmetic is supported for the expression in thiscontext: you may give a hexadecimal constant or the name of an existingsymbol, or use + and - to add or subtract hexadecimalconstants or symbols. If you need more elaborate expressions, considerusing the linker command language from a script.

These options control whether to demangle symbol names in errormessages and other output. When the linker is told to demangle, ittries to present symbol names in a readable fashion: it strips leadingunderscores if they are used by the object file format, and convertsC++ mangled symbol names into user readable names. The linker willdemangle by default unless the environment variableCOLLECT_NO_DEMANGLEis set. These options may be used to override the default.

-e entry
Use entry as the explicit symbol for beginning execution of yourprogram, rather than the default entry point. See the `ld' entry in `info' for adiscussion of defaults and other ways of specifying theentry point.

This option is only meaningful when linking MIPS embedded PIC code,generated by the-membedded-picoption to the GNU compiler and assembler. It causes the linker tocreate a table which may be used at runtime to relocate any data whichwas statically initialized to pointer values. See the code intestsuite/ld-empic for details.

When creating an ELF file, add all symbols to the dynamic symbol table.Normally, the dynamic symbol table contains only symbols which are usedby a dynamic object. This option is needed for some uses ofdlopen.

-f name
--auxiliary name
When creating an ELF shared object, set the internal DT_AUXILIARY fieldto the specified name. This tells the dynamic linker that the symboltable of the shared object should be used as an auxiliary filter on thesymbol table of the shared objectname.

-F name
--filter name
When creating an ELF shared object, set the internal DT_FILTER field tothe specified name. This tells the dynamic linker that the symbol tableof the shared object should be used as a filter on the symbol table ofthe shared objectname.

-format input-format
Synonym for -b input-format.

Accepted, but ignored; provided for compatibility with other tools.

-G size
Set the maximum size of objects to be optimized using the GP registertosizeunder MIPS ECOFF. Ignored for other object file formats.

-h name
-soname name
When creating an ELF shared object, set the internal DT_SONAME field tothe specified name. When an executable is linked with a shared objectwhich has a DT_SONAME field, then when the executable is run the dynamiclinker will attempt to load the shared object specified by the DT_SONAMEfield rather than the using the file name given to the linker.

Print a summary of the command-line options on the standard output and exit.This option and--versionbegin with two dashes instead of onefor compatibility with other GNU programs. The other options start withonly one dash for compatibility with other linkers.

Perform an incremental link (same as option -r).

Add an archive file ar to the list of files to link. This option may be used any number of times. ld will search itspath-list for occurrences of libar.a for every arspecified.

This command adds path searchdir to the list of paths thatld will search for archive libraries. You may use this optionany number of times.

The default set of paths searched (without being specified with-L) depends on what emulation mode ld is using, and insome cases also on how it was configured. Thepaths can also be specified in a link script with the SEARCH_DIRcommand.

Print (to the standard output file) a link map---diagnostic informationabout where symbols are mapped by ld, and information on globalcommon storage allocation.

-Map mapfile
Print to the filemapfilea link map---diagnostic informationabout where symbols are mapped by ld, and information on globalcommon storage allocation.

-m emulation
Emulate theemulationlinker. You can list the available emulations with the--verboseor-Voptions. This option overrides the compiled-in default, which is thesystem for which you configuredld.

specifies readable and writable text and data sections. Ifthe output format supports Unix style magic numbers, the output ismarked as OMAGIC.

When you use the `-N' option, the linker does not page-align thedata segment.

sets the text segment to be read only, and NMAGIC is writtenif possible.

Normally, the linker will not produce an output file if it encounterserrors during the link process. With this flag, you can specify thatyou wish the output file retained even after non-fatal errors.

The linker normally optimizes for speed over memory usage by cachingthe symbol tables of input files in memory. This option tells thelinker to instead optimize for memory usage, by rereading the symboltables as necessary. This may be required if the linker runs out ofmemory space while linking a large executable.

Normally the linker will give an error if you try to link togetherinput files that are mismatched for some reason, perhaps because theyhave been compiled for different processors or for differentendiannesses. This option tells the linker that it should silentlypermit such possible errors. This option should only be used withcare, in cases when you have taken some special action that ensuresthat the linker errors are inappropriate.

-o output
output is a name for the program produced by ld; if thisoption is not specified, the name `a.out' is used by default. Thescript command OUTPUT can also specify the output file name.

Generate optimized output files. This might use significantly moretime and therefore probably should be enabled only for generating thefinal binary.level is supposed to be a numeric value. Any value greater than zero enablesthe optimizations.

-oformat output-format
Specify the binary format for the output object file.You don't usually need to specify this, asld is configured to produce as a default output format the mostusual format on each machine. output-format is a text string, thename of a particular format supported by the BFD libraries. The script commandOUTPUT_FORMATcan also specify the output format, but this option overrides it.

-R filename
Read symbol names and their addresses from filename, but do notrelocate it or include it in the output. This allows your output fileto refer symbolically to absolute locations of memory defined in otherprograms.

An option with machine dependent effects. Currently this option is onlysupported on the H8/300.

On some platforms, use this option to perform global optimizations thatbecome possible when the linker resolves addressing in your program, suchas relaxing address modes and synthesizing new instructions in theoutput object file.

On platforms where this is not supported, `-relax' is accepted, but has no effect.

Generates relocatable output---i.e., generate an output file that can inturn serve as input to ld. This is often called partiallinking. As a side effect, in environments that support standard Unixmagic numbers, this option also sets the output file's magic number toOMAGIC.If this option is not specified, an absolute file is produced. Whenlinking C++ programs, this option will not resolve references toconstructors; -Ur is an alternative.

This option does the same as -i.

-rpath directory
Add a directory to the runtime library search path. This is used whenlinking an ELF executable with shared objects. All -rpatharguments are concatenated and passed to the runtime linker, which usesthem to locate shared objects at runtime. The-rpathoption is also used when locating shared objects which are needed byshared objects explicitly included in the link; see the description ofthe-rpath-linkoption. If-rpathis not used when linking an ELF executable, the contents of theenvironment variableLD_RUN_PATHwill be used if it is defined.

The-rpathoption may also be used on SunOS. By default, on SunOS, the linkerwill form a runtime search path out of all the-Loptions it is given. If a-rpathoption is used, the runtime search path will be formed exclusivelyusing the-rpathoptions, ignoringthe-Loptions. This can be useful when using gcc, which adds many-Loptions which may be on NFS mounted filesystems.

-rpath-link directory
When using ELF or SunOS, one shared library may require another. Thishappens when anld -sharedlink includes a shared library as one of the input files.

When the linker encounters such a dependency when doing a non-shared,non-relocateable link, it will automatically try to locate the requiredshared library and include it in the link, if it is not includedexplicitly. In such a case, the-rpath-linkoption specifies the first set of directories to search. The-rpath-linkoption may specify a sequence of directory names either by specifyinga list of names separated by colons, or by appearing multiple times.

If the required shared library is not found, the linker will issue awarning and continue with the link.

Omits debugger symbol information (but not all symbols) from the output file.

Omits all symbol information from the output file.

Create a shared library. This is currently only supported on ELF andSunOS platforms (on SunOS it is not required, as the linker willautomatically create a shared library when there are undefined symbolsand the-eoption is not used).

Normally, whenldplaces the global common symbols in the appropriate output sections,it sorts them by size. First come all the one byte symbols, then allthe two bytes, then all the four bytes, and then everything else.This is to prevent gaps between symbols due toalignment constraints. This option disables that sorting.

-split-by-reloc count
Trys to creates extra sections in the output file so that no singleoutput section in the file contains more thancountrelocations.This is useful when generating huge relocatable for downloading intocertain real time kernels with the COFF object file format; since COFFcannot represent more than 65535 relocations in a single section.Note that this will fail to work with object file formats which do notsupport arbitrary sections. The linker will not split up individualinput sections for redistribution, so if a single input sectioncontains more thancountrelocations one output section will contain that many relocations.

Similar to-split-by-relocbut creates a new output section for each input file.

--section-start sectionname=org
Locate a section in the output file at the absoluteaddress given by org. org must be a hexadecimal integer.You may use this option as manytimes as necessary to locate multiple sections in the commandline. If you need more elaborate expressions, considerusing the linker command language from a script.

-Tbss org
-Tdata org
-Ttext org
Use org as the starting address for---respectively---thebss, data, or the text segment of the output must be a hexadecimal integer.

-T commandfile
Equivalent to -c commandfile; supported for compatibility withother tools.

Prints names of input files as ld processes them.

-u sym
Forces sym to be entered in the output file as an undefined symbol.This may, for example, trigger linking of additional modules fromstandard libraries. -u may be repeated with different optionarguments to enter additional undefined symbols.

For anything other than C++ programs, this option is equivalent to-r: it generates relocatable output---i.e., an output file that can inturn serve as input to ld. When linking C++ programs, -Urwill resolve references to constructors, unlike -r.

Display the version number for ldand list the supported emulations.Display which input files can and can not be opened.

-v, -V
Display the version number for ld.The-Voption also lists the supported emulations.

Display the version number for ldand exit.

Warn when a common symbol is combined with another common symbol or witha symbol definition. Unix linkers allow this somewhat sloppy practice,but linkers on some other operating systems do not. This option allowsyou to find potential problems from combining global symbols.

Warn if any global constructors are used. This is only useful for afew object file formats. For formats like COFF or ELF, the linker cannot detect the use of global constructors.

Warn if the output file requires multiple global-pointer values. Thisoption is only meaningful for certain processors, such as the Alpha.

Only warn once for each undefined symbol, rather than once per modulewhich refers to it.

Warn if the address of an output section is changed because ofalignment. Typically, the alignment will be set by an input section.The address will only be changed if it not explicitly specified; thatis, if the SECTIONS command does not specify a start address for thesection.

For each archive mentioned on the command line after the--whole-archiveoption, include every object file in the archive in the link, ratherthan searching the archive for the required object files. This isnormally used to turn an archive file into a shared library, forcingevery object to be included in the resulting shared library.

Turn off the effect of the--whole-archiveoption for archives which appear later on the command line.

--wrap symbol
Use a wrapper function for symbol.Any undefined reference tosymbolwill be resolved to__wrap_symbol.Any undefined reference to__real_symbolwill be resolved tosymbol.

Delete all temporary local symbols. For most targets, this is all localsymbols whose names begin with `L'.

Delete all local symbols.



You can change the behavior ofld with the environment variable GNUTARGET.

GNUTARGET determines the input-file object format if you don'tuse -b (or its synonym -format). Its value should be oneof the BFD names for an input format. If there is noGNUTARGET in the environment, ld uses the natural formatof the host. If GNUTARGET is set to default then BFD attempts to discover theinput format by examining binary input files; this method oftensucceeds, but there are potential ambiguities, since there is no methodof ensuring that the magic number used to flag object-file formats isunique. However, the configuration procedure for BFD on each systemplaces the conventional format for that system first in the search-list,so ambiguities are resolved in favor of convention.




`ld' and `binutils'entries ininfo
ld: the GNU linker, Steve Chamberlain and Roland Pesch;The GNU Binary Utilities, Roland H. Pesch.



Copyright (c) 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.

Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided that theentire resulting derived work is distributed under the terms of apermission notice identical to this one.

Permission is granted to copy and distribute translations of thismanual into another language, under the above conditions for modifiedversions, except that this permission notice may be included intranslations approved by the Free Software Foundation instead of inthe original English.




This document was created byman2html,using the manual pages.