Computer Hope

Other Pages

Home
Site map
Computer help

Dictionary
News
Q&A
What's new

Tools

E-mail this page
Print Preview
Edit this page



 

Linux / Unix ld command

Quick links

About ld
Syntax
Options no longer supported
Examples
Related commands
Linux / Unix main page

About ld

Link-editor for object files.

Syntax

ld [-a | -r ] [-b] [-G] [-i] [-m] [-s] [-t] [-V] [-B dynamic | static] [-B group] [-B local] [-B eliminate] [-B reduce] [-B symbolic] [ -dy | n] [-D token] [-e epsym] [- F name | -f name] [-h name] [-I name] [-L path] [-l x] [-M mapfile] [-N string] [-o outfile] [-Q y | n] [-R path] [-u symname] [-Y P,dirlist] [-z allextract | defaultextract | weakextract] [-z combreloc] [-z defs | nodefs] [-z ignore | record] [-z lazyload | nolazyload] [-z initfirst] [-z loadfltr] [-z muldefs] [-z nodelete] [-z nodlopen] [-z nopartial] [-z noversion] [-z now] [-z origin] [-z redlocsym] [-z text | textwarn | textoff ] filename

-a In static mode only, produce an executable object file; give errors for undefined references. This is the default behavior for static mode. -a may not be used with the -r option.
-r Combine relocatable object files to produce one relocatable object file. ld will not complain about unresolved references. This option cannot be used in dynamic mode or with -a.
-b In dynamic mode only, when creating an executable, do not do special processing for relocations that reference symbols in shared objects. Without the -b option, the link-editor creates special position-independent relocations for references to functions defined in shared objects and arranges for data objects defined in shared objects to be copied into the memory image of the executable by the runtime linker. With the -b option, the output code may be more efficient, but it will be less sharable.
-G In dynamic mode only, produce a shared object. Undefined symbols are allowed.
-i Ignore LD_LIBRARY_PATH. This option is useful when an LD_LIBRARY_PATH setting is in effect to influence the runtime library search, which would interfere with the link-editing being performed.
-m Produce a memory map or listing of the input/output sections, together with any non-fatal multiply defined symbols, on the standard output.
-s Strip symbolic information from the output file. Any debugging information, that is .debug, .line, and .stab sections, and their associated relocation entries will be removed. Except for relocatable files or shared objects, the symbol table and string table sections will also be removed from the output object file.
-t Turn off the warning about multiply defined symbols that are not the same size.
-V Output a message giving information about the version of ld being used.
-B dynamic | static Options governing library inclusion. -B dynamic is valid in dynamic mode only. These options may be specified any number of times on the command line as toggles: if the -B static option is given, no shared objects will be accepted until -B dynamic is seen. See also the -l option.
-B group Establishes a shared object and its dependencies as a group. Objects within the group will be bound to other members of the group at runtime. The runtime processing of an object containing this flag mimics that which occurs if the object is added to a process using dlopen(3X) with the RTLD_GROUP mode. As the group must be self contained, use of the -B group option also asserts the -z defs option.
-B local Cause any global symbols, not assigned to a version definition, to be reduced to local. Version definitions can be supplied via a mapfile and indicate the global symbols that should remain visible in the generated object. This option achieves the same symbol reduction as the auto-reduction directive available as part of a mapfile version definition and may be useful when combining versioned and non-versioned relocatable objects.
-B eliminate Cause any global symbols not assigned to a version definition to be eliminated from the symbol table. This option achieves the same symbol elimination as the auto-elimination directive available as part of a mapfile version definition.
-B reduce When generating a relocatable object, cause the reduction of symbolic information defined by any version definitions. Version definitions can be supplied via a mapfile to indicate the global symbols that should remain visible in the generated object. When a relocatable object is generated, by default version definitions are only recorded in the output image. The actual reduction of symbolic information will be carried out when the object itself is used in the construction of a dynamic executable or shared object. This option is applied automatically when dynamic executable or shared object is created.
-B symbolic In dynamic mode only. When building a shared object, binds references to global symbols to their definitions, if available, within the object. Normally, references to global symbols within shared objects are not bound until runtime, even if definitions are available, so that definitions of the same symbol in an executable or other shared object can override the object's own definition. ld will issue warnings for undefined symbols unless -z defs overrides.
-dy | n When -dy, the default, is specified, ld uses dynamic linking; when -dn is specified, ld uses
static linking. See also -B dynamic|static.
-D token Print debugging information, as specified by each token, to the standard error. The special token help indicates the full list of tokens available.
-e epsym Set the entry point address for the output file to be that of the symbol epsym.
-f name Useful only when building a shared object. Specifies that the symbol table of the shared object is used as an auxiliary filter on the symbol table of the shared object specified by name. Multiple instances of this option are allowed. This option may not be combined with the -F option.
-F name Useful only when building a shared object. Specifies that the symbol table of the shared object is used as a filter on the symbol table of the shared object specified by name. Multiple instances of this option are allowed. This option may not be combined with the -f option.
-h name In dynamic mode only, when building a shared object, record name in the object's dynamic section. name will be recorded in executables that are linked with this object rather than the object's Unix System file name. Accordingly, name will be used by the runtime linker as the name of the shared object to search for at runtime.
-I name When building an executable, use name as the path name of the interpreter to be written into the program header. The default in static mode is no interpreter; in dynamic mode, the default is the name of the runtime linker, ld.so.1. Either case may be overridden by -I name. exec will load this interpreter when it loads a.out and will pass control to the interpreter rather than to a.out directly.
-L path Add path to the library search directories. ld searches for libraries first in any directories
specified by the -L options and then in the standard directories. This option is useful only if it precedes the -l options to which it applies on the command line. The environment variable LD_LIBRARY_PATH may be used to supplement the library search path.
-l x Search a library libx.so or libx.a, the conventional names for shared object and archive libraries, respectively. In dynamic mode, unless the -B static option is in effect, ld searches each directory specified in the library search path for a libx.so or libx.a file. The directory search stops at the first directory containing either. ld chooses the file ending in .so if -lx expands to two files with names of the form libx.so and libx.a. If no libx.so is found, then ld accepts libx.a. In static mode, or when the -B static option is in effect, ld selects only the file ending in .a. ld searches a library when it encounters its name, so the placement of -l is significant.
-M mapname Read mapfile as a text file of directives to ld . This option may be specified multiple times. If mapfile is a directory, then all regular files, as defined by stat, within the directory will be processed. See Linker and Libraries Guide for description of mapfiles. There are mapfiles in /usr/lib/ld that show the default layout of programs as well as mapfiles for linking 64-bit programs above or below 4 gigabytes. See the FILES section below.
-N string This option causes a DT_NEEDED entry to be added to the .dynamic section of the object being built. The value of the DT_NEEDED string will be the string specified on the command line. This option is position dependent, and the DT_NEEDED .dynamic entry will be relative to the other dynamic dependencies discovered on the link-edit line.
-o outfile Produce an output object file named outfile. The name of the default object file is a.out.
-Q y | n Under -Qy, an ident string is added to the .comment section of the output file to identify the version of the link-editor used to create the file. This results in multiple ld idents when
there have been multiple linking steps, such as when using ld -r. This is identical with the default action of the cc command. -Qn suppresses version identification.
-R path A colon-separated list of directories used to specify library search directories to the runtime linker. If present and not NULL, it is recorded in the output object file and passed to the runtime linker. Multiple instances of this option are concatenated together with each path separated by a colon.
-u symname Enter symname as an undefined symbol in the symbol table. This is useful for loading entirely from an archive library, since initially the symbol table is empty, and an unresolved reference is needed to force the loading of the first routine. The placement of this option on the command line is significant; it must be placed before the library that will define the symbol.
-Y P,dirlist Change the default directories used for finding libraries. dirlist is a colon-separated path list.
-z allextext | defaultextract | weakextract Alter the extraction criteria of objects from any archives that follow. By default archive members are extracted to satisfy undefined references and to promote tentative definitions with data definitions. Weak symbol references do not trigger extraction. Under -z allextract, all archive members are extracted from the archive. Under -z weakextract, weak references trigger archive extraction. -z defaultextract provides a means of returning to the default following use of the former extract options.
-z combreloc Combine multiple relocation sections. Reduces overhead when objects are loaded into memory.
-z defs Force a fatal error if any undefined symbols remain at the end of the link. This is the default when an executable is built. It is also useful when building a shared object to assure that the object is self-contained, that is, that all its symbolic references are resolved internally.
-z nodefs Allow undefined symbols. This is the default when a shared object is built. When used with executables, the behavior of references to such undefined symbols is unspecified.
-z ignore | record Ignore, or record, dynamic dependencies that are not referenced as part of the link-edit. By default, -z record is in effect.
-z lazyload | nolazyload nable or disable the marking of dynamic dependencies to be lazily loaded. Dynamic dependencies which are marked lazyload will not be loaded at initial process startup, but instead will be delayed until the first binding to the object is made.
-z initfirst Marks the object so that its runtime initialization occurs before the runtime initialization of
any other objects brought into the process at the same time. In addition, the object runtime finalization will occur after the runtime finalization of any other objects removed from the process at the same time. This option is only meaningful when building a shared object.
-z loadfltr Marks the object to require that when building a filter, its filtees be processed immediately at runtime. Normally, filter processing is delayed until a symbol reference is bound to the filter. The runtime processing of an object that contains this flag mimics that which occurs if the LD_LOADFLTR environment variable is in effect..
-z muldefs Allows multiple symbol definitions. By default, multiple symbol definitions that occur between relocatable objects will result in a fatal error condition. This option suppresses the error condition and allows the first symbol definition to be taken.
-z nodelete Marks the object as non-deletable at runtime. The runtime processing of an object that contains this flag mimics that which occurs if the object is added to a process using dlopen(3X) with the RTLD_NODELETE mode.
-z nodlopen Marks the object as not available to dlopen(3X), either as the object specified by the dlopen(), or as any form of dependency required by the object specified by the dlopen(). This option is only meaningful when building a shared object.
-z nopartial If there are any partially initialized symbols in the input relocatable object files, the partially initialized symbols are expanded when the output file is generated.
-z noversion Do not record any versioning sections. Any version sections or associated .dynamic section entries will not be generated in the output image.
-z now Marks the object to override the runtime linker's default mode and require non-lazy runtime binding. This is similar to adding the object to the process by using dlopen(3X) with the RTLD_NOW mode, or setting the LD_BIND_NOW environment variable in effect.
-z origin Marks the object as requiring immediate $ORIGIN processing at runtime.
-z redlocsym Eliminates all local symbols except for the SECT symbols from the symbol table SHT_SYMTAB. All relocations that refer to local symbols will be updated to refer to the corresponding SECT symbol.
-z text In dynamic mode only, force a fatal error if any relocations against non-writable, allocatable sections remain.
-z textoff In dynamic mode only, allow relocations against all allocatable sections, including non-writable ones. This is the default when building a shared object.
-z textwarn In dynamic mode only, list a warning if any relocations against non-writable, allocatable sections remain. This is the default when building an executable.
filename

Options no longer supported

The following SunOS 4.x.y options do not have any replacement in this release: -B nosymbolic (this is now the default if -B symbolic is not used), -d, -dc, and -dp (these are now the default; see -b above to override the default), -M, -S, -t, -x, -X, and -ysym. 

The following SunOS 4.x.y options are not supported: -align datum, -A name, -D hex, -p, -T[text] hex, -T data hex. Much of the functionality of these options can be achieved using the -M mapfile option. 

The following SunOS 4.x.y options are obsolete in this release: -n, -N, and -z.

Examples

ld -r file1.o -o prog.o - Link part of the C program (file1.o) for later processing with the output file being prog.o.

Related commands

as
gprof
pvs

Index

Category:
Linux / Unix

Companies:
Click here

Related Pages:

Resolved

Were you able to locate the answer to your questions?

Home - Computer help - Contact - Dictionary - Links
Link to Computer Hope - Bookmark Computer Hope