LD(1)

NAME
ld - link editor

SYNOPSIS
ld [-MNnrSstXxz] [-A symbol-file] [-assert keyword] [-Blinkmode] [-D datasize] [-d c] [-d p] [-e entry] [-llibrary-specifier] [-Llibrary-search-path] [-nostdlib] [-o filename] [-T address] [-u symbol] [-V shlib-version] [-y symbol]

DESCRIPTION
ld combines the object and archive files given on the command line into a new object file. The output object file is either an executable program, a shared object suitable for loading at run-time, or an object file that can once again be processed by ld. Object files and archives are processed in the order given on the command line.

The options are as follows:

-A symbol-file
    The symbol-file is taken as a base for link-editing the object files on the command line.

-assert keyword
    This option has currently no effect. It is here for compatibility with SunOS ld. All conditions which would cause a Sun assertion to fail will currently always cause error or warning messages from ld.

-Bdynamic
    Specifies that linking against dynamic libraries can take place. If a library specifier of the form -lx appears on the command line, ld searches for a library of the from libx.so.n.m (see the -l option) according to the search rules in effect. If such a file can not be found a traditional archive is looked for. This options can appear anywhere on the command line and is complementary to -Bstatic.

-Bstatic
    The counterpart of -Bdynamic. This option turns off dynamic linking for all library specifiers until a -Bdynamic is once again given. Any explicitly mentioned shared object encountered on the command line while this option is in effect is flagged as an error.

-Bshareable
    Instructs the linker to build a shared object from the object files rather than a normal executable image.

-Bsymbolic
    This option causes all symbolic references in the output to be resolved in this link-edit session. The only remaining run-time relocation requirements are base-relative relocations, ie. translation with respect to the load address. Failure to resolve any symbolic reference causes an error to be reported.

-Bforcearchive
    Force all members of archives to be loaded, whether or not such members contribute a definition to any plain object files. Useful for making a shared library from an archive of PIC objects without having to unpack the archive.

-Bsilly
    Search for .sa silly archive companions of shared objects. Useful for compatibility with version 3 shared objects.

-D data-size
    Set the size of the data segment. For sanity's sake, this should be larger than the cumulative data sizes of the input files.

-d c
    Force allocation of commons even producing relocatable output.

-d p
    Force alias definitions of procedure calls in non-PIC code. Useful to obtain shareable code in the presence of run-time relocations as such calls will be re-directed through the Procedure Linkage Table (see link(5))

-e entry-symbol
    Specifies the entry symbol for an executable.

-Lpath
    Add path to the list of directories to search for libraries specified with the -l option.

-llib-spec
    This option specifies a library to be considered for inclusion in the output. If the -Bdynamic option is in effect, a shared library of the form lib<spec>.so.m.n (where m is the major, and n is the minor version number, respectively) is searched for first. The library with the highest version found in the search path is selected. If no shared library is found or the -Bstatic option is in effect, an archive of the form lib<spec>.a is looked for in the library search path.

-M  Produce output about the mapping of segments of the input files and the values assigned to (global) symbols in the output file.

-N  Produce a OMAGIC output file.

-n  Produce a NMAGIC output file.

-nostdlib
    Do not search the built-in path ( usually “/usr/lib”) for -l specified libraries.

-o filename
    Specifies the name of the output file. Defaults to “a.out”.

-Q  Produce a QMAGIC output file.

-r  Produce relocatable object file, suitable for another pass through ld.

-R  Record the given path within the executable for run-time library search. This only applies to dynamically linked executables.

-S  Strip all debugger symbols from the output.

-s  Strip all symbols from the output.

-T  Specifies the start address of the text segment, with respect to which all input files will be relocated.

-t  Leave a trace of the input files as they are processed.

-u symbol
    Force symbol to be marked as undefined. Useful to force loading of an archive member in the absence of any other references to that member.

-V version
    Put the given version number into the output shared library (if one is created). Useful to make shared libaries compatible with other operating systems. Eg. SunOS 4.x libraries use version number 3. Defaults to 8.

-X  Discard local symbols in the input files that start with the letter “L”

-x  Discard all local symbols in the input files.

-y symbol
    Trace the manipulations inflicted on symbol

-z  Make a ZMAGIC output file. This is the default.

  Transitional Compatibility
Use of the following directives is required on ELF systems and is recommended on all others in order to prepare for the planned transition from COFF to ELF.

-rpath dir
    Record the given dir within the executable for run-time library search, as for -R. Ignored on COFF systems.

-shared
    Instructs the linker to build a shared object from the object files rather than a normal executable image.

-soname library-name
    The linker input file name is usually the plain ``.so'' file with no version number. On ELF systems, this option sets the DT_SONAME field of a shared library to libraryname, which should be specified with the major number and without the minor number. A program image linked with this library will use at run time the file name specified here rather than the linker input file name.

- -whole-archive
    A positional qualifier to force loading from archives. For each archive mentioned on the commandline after this option, include every object file from the archive in the link, rather than searching the archive for the required object files. This is normally used when building shared libraries. On COFF systems, the positional syntax is not currently implemented; - -whole-archive is treated exactly as -Bforcearchive.

- -no-whole-archive
    This option turns off the effect of a preceding - -whole-archive for any subsequent archive files on the command line. It is currently ignored on COFF systems.

- -export-dynamic
    Specifies that all symbols should be added to the dynamic symbol table. This option is needed only by programs that make run-time decisions to load modules they were never linked with. Ignored on COFF systems.

ENVIRONMENT
ld utilizes the following environment variables:

LD_LIBRARY_PATH
    This colon-separated list of directories is inserted into the search path for libraries following any directories specified via -L options and preceding the built-in path.

LD_NOSTD_PATH
    When set, do not search the built-in path for libraries. This is an alternative to the -nostdlib command-line flag.

SEE ALSO
ld.so(1), link(5), ldconfig(8)

CAVEATS
An entry point must now explicitly be given if the output is intended to be a normal executable program. This was not the case for the previous version of ld.

BUGS
Shared objects are not properly checked for undefined symbols.

Cascading of shared object defeats the “-Bstatic” option.

All shared objects presented to ld are marked for run-time loading in the output file, even if no symbols are needed from them.

HISTORY
The shared library model employed by ld appeared first in SunOS 4.0.