.\" This source code is a product of Sun Microsystems, Inc. and is provided
.\" for unrestricted use provided that this legend is included on all tape
.\" media and as a part of the software program in whole or part. Users
.\" may copy or modify this source code without charge, but are not authorized
.\" to license or distribute it to anyone else except as part of a product or
.\" program developed by the user.
.\" THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC.
.\" SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY
.\" OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
.\" EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS
.\" ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
.\" NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT,
.\" INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
.\" FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY.
.\" This source code is provided with no support and without any obligation on
.\" the part of Sun Microsystems, Inc. to assist in its use, correction,
.\" modification or enhancement.
.\" SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
.\" INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS
.\" SOURCE CODE OR ANY PART THEREOF.
.\" Sun Microsystems, Inc.
.\" Mountain View, California 94043
.\" Copyright (c) 1991 Sun Microsystems, Inc.
.\" @(#)ld.1 1.48 90/02/02 SMI;
.TH LD 1 "21 January 1990"
ld, ld.so \- link editor, dynamic link editor
.BI \-assert " assertion-keyword"
.BI \-B "binding-keyword"
.IX "ld command" "" "\fLld\fP \(em link editor"
.IX "programming tools" "ld command" "" "\fLld\fP \(em link editor"
.IX "link editor" "" "link editor \(em \fLld\fP"
combines object programs to create an
file or another object program suitable for further
option). The object modules on which
operates are specified on the command line, and can be:
simple object files, which typically end in the
suffix, and are referred to as \*(lqdot-oh\*(rq files
dynamically-bound, sharable object files
are also referred to as \*(lqshared libraries,\*(rq
which are created from previous
Unless an output file is specified,
This file contains the object files given as input,
appropriately combined to form an executable file.
When linking debugging or profiling objects, include the
Options should appear before
filenames, except for abbreviated library
options, and some binding control options specified by
(which can appear anywhere in the line).
Force the global uninitialized data symbol
common block) to be page-aligned. Increase its size to a whole number of
pages, and place its first byte at the start of a page.
.BI \-assert " assertion-keyword"
Check an assertion about the link editing being performed. The assertion
desired is specified by the
is silent if the assertion holds, else it yields a diagnostic and aborts.
and their interpretations are:
If the resulting program were run now, there would be no run-time undefined
symbol diagnostics. This assertion is set by default.
Permit the successful linking of a program with
There are no symbolic relocation items remaining to be resolved.
The resulting load has no relocation items remaining in its text.
Incremental loading: linking is to be done in a manner so that the
resulting object may be read into an already executing program.
is the name of a file whose symbol table is taken as a basis
on which to define additional symbols.
Only newly linked material is
entered into the text and data portions of
but the new symbol table will reflect all symbols defined before and after
This argument must appear before any other object
file in the argument list.
options may be used as well, and will be taken to mean that the newly linked
segment will commence at the corresponding addresses (which must be a multiple
The default value is the old value of
Specify allowed binding times for the items which follow. Allowed values of
Allow dynamic binding: do not resolve symbolic references, allow creation of
run-time symbol and relocation environment.
is in effect, all sharable objects encountered until a
may be added dynamically to the object being
linked. Non-sharable objects are bound statically.
Do not perform symbolic relocation, even if other options imply it.
Bind statically. Opposite of
is specified. Influences handling of all objects
following its specification on a command line until the next
Force symbolic relocation. Normally implied if an entry point has been
or if dynamic loading is in effect.
Force common storage for uninitialized variables and other
common symbols to be allocated in the current
flag is present (which would otherwise postpone this binding
until the final linking phase).
but also copy initialized data referenced by this program
Force an alias definition of undefined procedure entry points.
Used with dynamic binding to improve sharing and the locality
Pad the data segment with zero-valued bytes to make it
Define the entry point: the
name of the entry point of the loaded program. Implies
.BI \-l x\|\fR[ . v\|\fR]
This option is an abbreviation for the library name
searches for libraries first in any directories specified with
options, then in the standard directories
A library is searched when its name is encountered,
is significant. If a dynamically loadable object is found, and
is in effect at that point on the command line, then
prepares to access the object for relocation at run-time. In such a
suffix can be used to indicate a specific library version.
to the list of directories in which to search for libraries.
Directories specified with
are searched before the standard directories,
When building a program in which one or more objects are loaded when
is in effect, those directories specified by
options will be \*(lqremembered\*(rq for use at execution time. This permits
the construction of software that uses shared objects as libraries not
in the standard locations and avoids requiring the specification of
in order to execute such software. Note that such directories are
the form specified in the option, which means that relative directory
specifications (i.e., not beginning with \*(lq/\*(rq) will be evaluated
relative to the current directory when the program is
not just during the operation of
Produce a primitive load map, listing the names of the files
Arrange (by giving the output file a 0410 \*(lqmagic number\*(rq)
file is executed, the text portion will be read-only with the data areas
placed at the beginning of the next address boundary following the end of
Do not make the text portion read-only. (Use \*(lqmagic number\*(rq 0407.)
Arrange for the data segment to begin on a page boundary, even if the text is
Generate relocation bits in the output file
so that it can be the subject of another
run. This flag also prevents final definitions from being given to common
symbols, and suppresses the \*(lqundefined symbol\*(rq diagnostics.
Strip the output, that is, remove the symbol table and relocation bits to save
space (but impair the usefulness of the debuggers). This information can also
Strip the output by removing all symbols except locals and globals.
Trace: display the name of each file as it is processed.
.BR \-T \|[\| text \|]\| \fIhex\fR
Start the text segment at location
Start the data segment at location
This option is only of use
to programmers wishing to write code for
since the resulting code cannot be executed by the system.
This is useful for loading
wholly from a library, since initially the symbol table is empty and an
unresolved reference is needed to force the loading of the first routine.
Preserve only global (non-\fB.globl\fP) symbols in the output symbol
table; only enter external symbols.
This option saves some space in the output file.
Record local symbols, except for those whose names begin with
to discard internally generated labels while
retaining symbols local to routines.
Display each file in which
appears, its type and whether the file defines or references it.
Many such options may be given to trace many symbols.
It is usually necessary to begin
and Pascal variables begin
Arrange for the process demand paged from the resulting executable
file (0413 \*(lqmagic number\*(rq). This is the default.
Results in a (32-byte) header on the output file followed by
text and data segments, each of which has a multiple of page-size
bytes (being padded out with
characters in the file if necessary).
With this format the first few
segment symbols may actually end up
this is to avoid wasting the space resulting from rounding the data
.SS Command Line Processing
In general, options should appear ahead of the list of files to
process. Unless otherwise specified, the
effect of an option covers all of
of that option's placement on the command line. Exceptions to this
rule include some of the binding control options specified by
and the abbreviated library-names specified by
anywhere, and their influence is dependent upon their location.
Some options may be obtained from
environment variables, such options are interpreted before any
.SS Object File Processing
The files specified on the command line are processed in
the order listed. Information is extracted from each file,
and concatenated to form the output. The specific
processing performed on a given file depends upon whether it is
a simple object file, a library archive, or a shared library.
files are concatenated to the output as they are encountered.
files are searched exactly once each, as each is encountered;
only those archive entries matching an unresolved external reference
are extracted and concatenated to the output. If a member of an
archive references a symbol defined by another member of that same
archive, the member making the reference must appear before the
member containing the definition.
On Sun386i, a library contains a dictionary of symbols, On
other Sun systems, processing library archives through
provides this dictionary. In addition, you can use
to place library members in calling order (see
for details), or both (for fastest symbol lookup).
The first member of an archived processed by
takes to be the dictionary of all symbols defined by
are scanned for symbol definitions and references,
but are not normally included in the output from
except in cases where a shared library exports initialized data
option is in effect. However, the
occurrence of each sharable object file in the
command line is noted in the resulting executable file; this
notation is utilized by an execution-time variant of
loading and binding during execution.
.BR "Execution-Time Loading" ,
option specifies a short name for an object
file or archive used as a library.
The full name of the object file is
derived by adding the prefix
archive or a shared library, respectively.
The specific suffix used is determined through rules discussed in
.BR "Binding and Relocation Semantics" ,
searches for the desired object file through a list of
options, the environment variable
.BR \s-1LD_LIBRARY_PATH\s0 ,
and finally, the built-in list of standard library directories:
.SS Binding and Relocation Semantics
processes a given object file is
dependent in part upon the \*(lqbinding mode\*(rq in which it is operating
at the time the file is encountered.
This binding mode is specified by the
flag, which takes the keyword arguments:
Allow dynamic binding, do not resolve symbolic references, and allow
creation of execution-time symbol and relocation information.
This is the default setting.
Force static binding, implied by options that generate non-sharable
may be specified several times, and may be used to toggle each other
the influence of each depends upon its location within the
searches may be satisfied by the first occurrence of either form of
but if both are encountered, the
libraries it encounters; it continue searching
form. Furthermore, an explicit request to load a
file is treated as an error.
has processed all input files and command line options, the form of
the output it produces is based on the information provided in
first tries to reduce all symbolic references to
relative numerical offsets within the executable it is building. To
perform this \*(lqsymbolic reduction,\*(rq
must be able to determine that:
all information relating to the program has been provided, in
is to be added at execution time; and/or
the program has an entry point, and symbolic reduction can
be performed for all symbols having definitions existing in the
It should be noted that uninitialized \*(lqcommon\*(rq areas
(for example, uninitialized C globals) are allocated by the
it has collected all references.
In particular, this allocation can not occur in a program that still
requires the addition of information contained in a
file, as the missing information may affect the allocation process.
Initialized \*(lqcommons\*(rq however, are allocated within the executable
in which their definition appears.
has performed all the symbolic reductions it can, it
attempts to transform all relative references to absolute addresses.
is able to perform this \*(lqrelative reduction\*(rq
only if it has been provided
absolute address, either implicitly through the specification of an
entry point, or explicitly through
If, after performing all the reductions it can,
there are no further relocations or definitions to perform, then
has produced a completely linked executable.
.SS Execution-Time Loading
In the event that one or more reductions can not be completed,
the executable will require further link editing at execution
time in order to be usable. Such executables contain an
data structure identified with the symbol
An incompletely linked \*(lqmain\*(rq program should be
linked with a \*(lqbootstrap\*(rq routine that invokes
which uses the information
contained in the main program's
of the executables constituting the entire program. A standard
Sun compilation driver (such as
automatically includes such a module in each \*(lqmain\*(rq executable.
is given control on program startup, it finds all
files specified when the program was constructed (and
on which they depend), and loads
them into the address space. The algorithm by which such files are found
can be influenced by the setting of
when the program was built.
remaining relocations, with the exception of procedure call
relocations; failure to resolve a given non-procedural relocation
results in termination of the program with an appropriate diagnostic.
Procedure relocations are resolved when the referencing instruction
is first executed. It should be noted that it is possible for
\*(lqundefined symbol\*(rq diagnostics to be produced during program
execution if a given target is not defined when referenced.
Although it is possible for binding errors to occur at execution-time,
such an occurrence generally indicates something wrong in the
maintenance of shared objects.
.B "\-assert nodefinitions"
function (on by default) checks at
whether or not an execution-time binding error would occur.
.SS Version Handling for Shared Libraries
To allow the independent evolution of
used as libraries and the programs which use them,
options involves the retention and
management of version control information. The
files used as such \*(lqshared libraries\*(rq are post-fixed with a
Dewey-decimal format string describing the version of the \*(lqlibrary\*(rq
The first decimal component is called the library's
\*(lqmajor version\*(rq number,
and the second component its \*(lqminor version\*(rq number. When
used as a library, it also records these two
numbers in the database used by
at execution time. In turn,
decide which of multiple versions of a given library is \*(lqbest\*(rq or
of the available versions are acceptable. The
Major Versions Identical: the major version used at
execution time must exactly match the version found at
Failure to find an instance of the library with a matching major
version causes a diagnostic to be issued and the program's
execution to be terminated.
Highest Minor Version: in the presence of multiple instances of
libraries that match the desired major version,
uses the highest minor version it finds. However, if the highest minor
version found at execution time is less than the version found at
a warning diagnostic is issued; program execution continues.
The semantics of version numbers are such that major version numbers
should be changed whenever interfaces are changed. Minor versions
should be changed to reflect compatible updates to libraries, and
programs will silently favor the highest compatible version they can
A number of symbols have special meanings to
and programs should not define these symbols. The symbols described
below are those actually seen by
other languages prepend symbols they use with
The first location after the text of the program.
The first location after initialized data.
The first location after all data.
data structure. It is defined with a non-zero value in
executables which require execution-time link editing.
By convention, if defined, it is the
first symbol in the symbol table associated with an
.SB _\^_GLOBAL_OFFSET_TABLE_
A position-independent reference to an
table of addresses. This table is constructed from
\*(lqposition-independent\*(rq data references occurring in objects
that have been assembled with the assembler's
flag (invoked on behalf of C compilations
flag). A related table (for which no
symbol is currently defined) contains a series of transfer
instructions and is created from \*(lqposition-independent\*(rq procedure
a list of undefined symbols.
Symbols in object files beginning with the letter
local symbols and unless otherwise specified are purged from
A colon-separated list of directories in which to search for
libraries specified with the
also affects library searching during execution-time loading, causing
the search to use first those directories found in
the environment variable, then any directories specified by
options, and finally the standard directories
when running a set-user- or set-group-ID program,
will only search for libraries in directories it \*(lqtrusts\*(rq, which
and any directories specified within the executable as a result of
options given when the executable was constructed.
A default set of options to
just as though its value had been placed on the command line,
immediately following the name used to invoke
example% ld $LD_OPTIONS \fR.\|.\|. \fIother-arguments \fR.\|.\|.
Note: Environment variable-names beginning with the characters
are reserved for possible future enhancements to
exported, initialized shared library data
default program bootstraps
Options are being overloaded and are an inappropriate vehicle for describing
the wide variety of things it can do.
a link-editing language which can be used in the more complex situations.
option does not properly handle programs assembled with
(position-independent) flag, invoked from