ld(1) CLIX ld(1)
NAME
ld - Runs a link editor for common object files
SYNOPSIS
ld [flag ... ] filename
FLAGS
-a Creates an absolute file. This flag is turned on by default.
However, if the -a flag is used with -r it instead allocates
memory for common symbols.
-b Forces unresolved symbols to be resolved to the address -1.
-e epsym Sets the default entry point address for the output file to
be that of the symbol epsym.
-f fill Sets the default fill pattern for ``holes'' within an output
section as well as initialized bss sections. The fill
argument is a two-byte constant.
-l x Searches a library libx.a, where x is up to nine characters.
A library is searched when its name is encountered, so the
placement of the -l flag is significant. By default, the
libraries are located in the LIBDIR or LLIBDIR directories.
-m Produces a map or listing of the input/output sections on
stdout.
-o outfile Produces an output object file with the name outfile. The
default name of the object file is a.out.
-r Retains 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 references, and the output
file will not be executable. If the -a flag is also
specified, memory will also be allocated for common symbols.
-s Strips line number entries and symbol table information from
the output object file.
-t Turns off the warning about multiply-defined symbols that are
not the same size.
-u symname Enters 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
2/94 - Intergraph Corporation 1
ld(1) CLIX ld(1)
routine. The placement of this flag is significant; it must
be placed before the library that will define the symbol.
-x Does not preserve local symbols in the output symbol table;
enters external and static symbols only. This flag saves
some space in the output file.
-z Does not bind to address 0. This flag will allow runtime
detection of null pointers.
-Ca am Sets the cache allocation mode for the entire image to am,
where am is one of the following:
ad Kernel default. This is the default if no cache
allocation mode flags are specified.
an No-write-allocate.
aw Write-allocate.
-Ct cm Sets the cache mode for the text region to cm, where cm is
one of the following:
pw Private, write through.
sw Shared, write through.
cb Private, copy back.
nc Noncached.
df Default for the region. Defaults are defined in the
kernel as sw for the text region and cb for stack and
data. These are also the defaults assumed by ld in
absence of any cache mode directives.
-Cd cm Sets the cache mode for the data region to cm.
-Cs cm Sets the cache mode for the stack region to cm.
-L dir Changes the algorithm of searching for libx.a to look in dir
before looking in $LIBDIR and $LLIBDIR. This flag is
effective only if it precedes the -l flag on the command
line.
-M Displays a message for each multiply-defined external
definition.
-N Puts the text section at the beginning of the text segment
rather than after all header information, and puts the data
section immediately after text in the core image.
2 Intergraph Corporation - 2/94
ld(1) CLIX ld(1)
-U Ignores multiply-defined symbols and resolve to the last
defined symbol.
-V Displays a message giving information about the version of ld
being used.
-VS num Uses num as a decimal version stamp identifying the a.out
file produced. The version stamp is stored in the optional
header.
-Y [LU],dir Changes the default directory used for finding libraries. If
L is specified, the first default directory that ld searches,
$LIBDIR, is replaced by dir. If U is specified and ld has
been built with a second default directory, $LIBDIR, that
directory is replaced by dir. If ld was built with only one
default directory and U is specified, a warning is displayed
and the flag is ignored.
DESCRIPTION
The ld command combines several object files into one file, performs
relocation, resolves external symbols, and supports symbol table
information for symbolic debugging. In the simplest case, the names of
several object programs are given. The ld command combines the object
files, producing an object module that can either be executed or, if the
-r flag is specified, used as input for a subsequent ld command. If the
-o flag is not specified, the default name of the output file is a.out.
This file is executable if no errors occurred during the load and the -r
flag is not specified. 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.
If any argument is a library, it is searched once at the point it is
encountered in the argument list. The library may be either a relocatable
archive library or a shared library. Only the routines defining an
unresolved external reference are loaded. The library (archive) symbol
table (see ar(0)) is searched sequentially with as many passes as
necessary to resolve external references that can be satisfied by library
members. Thus, the ordering of library members is functionally
unimportant unless multiple library members defining the same external
symbol exist.
EXAMPLES
1. This example links the file myfile.o with the standard startup files,
the C library, and strips all symbolic information from the resulting
file a.out.
ld -s /lib/crt1.0 myfile.o -lc /lib/crtn.o
2/94 - Intergraph Corporation 3
ld(1) CLIX ld(1)
2. This example links the file myfile.o to the standard startup file, the
C shared library, the standard C library, names the resulting file
myfile, and strips all symbolic information.
ld -o myfile /lib/crt1.0 myfile.o -lc -s -lc /lib/crtn.o
FILES
$LIBDIR/libx.a Libraries.
$LLIBDIR/libx.a Libraries.
a.out Output file.
$LIBDIR Usually /lib.
$LLIBDIR Usually /usr/lib.
NOTES
The symbols etext, edata, and end (see end(3)) are reserved and 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 contains link editor directives
and will attempt to parse it. This will occasionally produce an error
message identifying syntax errors.
Arithmetic expressions may only have one forward-referenced symbol per
expression.
Due to the complexities of creating executables and object files,
Intergraph recommends accessing the assembler through a compilation system
interface program (such as acc).
CAUTIONS
Through its flags and input directives, the common link editor gives users
great flexibility; however, those who use the input directives must assume
some added responsibilities. Input directives and flags should ensure the
following properties for programs:
1. C and C++ define a 0 pointer as null. A pointer to which 0 has been
assigned must not point to any object. To satisfy this, users must
not place any object at virtual address 0 in the program's address
space.
2. When the link editor is called through the cc command, a startup
routine is linked with the user's program. This routine calls exit()
after execution of the main program. If the user calls the link
4 Intergraph Corporation - 2/94
ld(1) CLIX ld(1)
editor directly, the user must ensure that the program always calls
exit() rather than falling through the end of the entry routine.
EXIT VALUES
The exit values are not valid.
RELATED INFORMATION
Commands: as(1), cc(1), mkshlib(1)
Functions: exit(2), end(3)
Files: ar(0)
AT&T UNIX System V Programmer's Guide
2/94 - Intergraph Corporation 5