LD(1) INTERACTIVE UNIX System LD(1)
NAME
ld - link editor for common object files
SYNOPSIS
ld [options] file name
DESCRIPTION
The ld command combines several object files into one, per-
forms relocation, resolves external symbols, and supports
symbol table information for symbolic debugging. In the
simplest case, the names of several object programs are
given, and ld combines the objects, producing an object
module that can either be executed or, if the -r option is
specified, used as input for a subsequent ld run. The out-
put of ld is left in a.out. By default this file is execut-
able if no errors occurred during the load. If any input
file, filename, is not an object file, ld assumes it is
either an archive library or a text file containing link
editor directives. [See Link Editor Directives in the UNIX
System V Programmer's Guide for a discussion of input direc-
tives.]
If any argument is a library, it is searched exactly once at
the point it is encountered in the argument list. The
library may be either a relocatable archive library or a
shared library. [See Shared Libraries in the UNIX System V
Programmer's Guide for a discussion of shared libraries.]
Only those routines defining an unresolved external refer-
ence are loaded. The library (archive) symbol table [see
ar(4)] is searched sequentially with as many passes as are
necessary to resolve external references which can be satis-
fied by library members. Thus, the ordering of library
members is functionally unimportant, unless there exist mul-
tiple library members defining the same external symbol.
The following options are recognized by ld:
-e epsym
Set the default entry point address for the output file
to be that of the symbol epsym.
-f fill
Set the default fill pattern for ``holes'' within an
output section as well as initialized bss sections.
The argument fill is a two-byte constant.
-lx Search a library libx.a, where x is up to nine charac-
ters. A library is searched when its name is encoun-
tered, so the placement of a -l is significant. By
default, libraries are located in LIBDIR or LLIBDIR.
-m Produce a map or listing of the input/output sections
on the standard output.
Rev. C Software Development Set Page 1
LD(1) INTERACTIVE UNIX System LD(1)
-o outfile
Produce an output object file by the name outfile. The
name of the default object file is a.out.
-r Retain relocation entries in the output object file.
Relocation entries must be saved if the output file is
to become an input file in a subsequent ld run. The
link editor will not complain about unresolved refer-
ences, and the output file will not be executable.
-a Create an absolute file. This is the default if the -r
option is not used. Used with the -r option, -a allo-
cates memory for common symbols.
-s Strip line number entries and symbol table information
from the output object file.
-t Turn off the warning about multiply-defined symbols
that are not the same size.
-u symname
Enter symname as an undefined symbol in the symbol
table. This is useful for loading entirely from a
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 ld line is significant; it must be placed before
the library which will define the symbol.
-x Do not preserve local symbols in the output symbol
table; enter external and static symbols only. This
option saves some space in the output file.
-z Do not bind anything to address zero. This option will
allow runtime detection of null pointers.
-L dir
Change the algorithm of searching for libx.a to look in
dir before looking in LIBDIR and LLIBDIR. This option
is effective only if it precedes the -l option on the
command line.
-M Output a message for each multiply-defined external
definition.
-N Put the text section at the beginning of the text seg-
ment rather than after all header information, and put
the data section immediately following text in the core
image.
-V Output a message giving information about the version
of ld being used.
Rev. C Software Development Set Page 2
LD(1) INTERACTIVE UNIX System LD(1)
-VS num
Use num as a decimal version stamp identifying the
a.out file that is produced. The version stamp is
stored in the optional header.
-Y[LU],dir
Change the default directory used for finding
libraries. If L is specified, the first default direc-
tory which ld searches, LIBDIR, is replaced by dir. If
U is specified and ld has been built with a second
default directory, LLIBDIR, then that directory is
replaced by dir. If ld was built with only one default
directory and U is specified a warning is printed and
the option is ignored.
FILES
LIBDIR/libx.a libraries
LLIBDIR/libx.a libraries
a.out output file
LIBDIR usually /lib
LLIBDIR usually /usr/lib
SEE ALSO
as(1), cc(1), mkshlib(1), exit(2), end(3C), a.out(4), ar(4).
Link Editor Directives and Shared Libraries in the UNIX
System V Programmer's Guide.
CAVEATS
Through its options and input directives, the common link
editor gives users great flexibility; however, those who use
the input directives must assume some added responsibili-
ties. Input directives and options should insure the fol-
lowing properties for programs:
- C defines a zero pointer as null. A pointer to which
zero has been assigned must not point to any object.
To satisfy this, users must not place any object at
virtual address zero in the program's address space.
- When the link editor is called through cc(1), a startup
routine is linked with the user's program. This rou-
tine calls exit( ) [see exit(2)] after execution of the
main program. If the user calls the link editor
directly, then the user must insure that the program
always calls exit( ) rather than falling through the
end of the entry routine.
The symbols etext, edata, and end [see end(3C)] are reserved
and are defined by the link editor. It is incorrect for a
user program to redefine them.
If the link editor does not recognize an input file as an
object file or an archive file, it will assume that it
Rev. C Software Development Set Page 3
LD(1) INTERACTIVE UNIX System LD(1)
contains link editor directives and will attempt to parse
it. This will occasionally produce an error message com-
plaining about "syntax errors".
Arithmetic expressions may only have one forward referenced
symbol per expression.
Rev. C Software Development Set Page 4