Manual page for LD(1)
ld, ld.so - link editor, dynamic link editor
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 ``dot-oh'' files
- dynamically-bound, sharable object files
are also referred to as ``shared libraries,''
which are created from previous
Unless an output file is specified,
produces a file named
This file contains the object files given as input,
appropriately combined to form an executable file.
When linking debugging or profiling objects, include the
as appropriate, in the
Options should appear before
filenames, except for abbreviated library
names specified with
options, and some binding control options specified by
(which can appear anywhere in the line).
- -align datum
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.
- -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.
- -A name
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
the incremental load.
This argument must appear before any other object
file in the argument list.
One or both of the
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
of the page size).
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 the default.
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
Implied when either
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
run, even when the
flag is present (which would otherwise postpone this binding
until the final linking phase).
but also copy initialized data referenced by this program
from shared objects.
Force an alias definition of undefined procedure entry points.
Used with dynamic binding to improve sharing and the locality
of run-time relocations.
- -D hex
Pad the data segment with zero-valued bytes to make it
- -e entry
Define the entry point: the
argument is made the
name of the entry point of the loaded program. Implies
This option is an abbreviation for the library name
is a string.
searches for libraries first in any directories specified with
options, then in the standard directories
A library is searched when its name is encountered,
so the placement of a
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
case, the optional
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 ``remembered'' 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 ``/'') 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
which will be loaded.
Arrange (by giving the output file a 0410 ``magic number'')
that when the output
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
the text. Implies
Do not make the text portion read-only. (Use ``magic number'' 0407.)
- -o name
is made the name of the
output file, instead of
Arrange for the data segment to begin on a page boundary, even if the text is
not shared (with the
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 ``undefined symbol'' 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
be removed by
Strip the output by removing all symbols except locals and globals.
Trace: display the name of each file as it is processed.
Start the text segment at location
is the same as using the
- -Tdata hex
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.
- -u name
as an undefined symbol.
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-.globl) 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
This option is used by
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
as external C,
and Pascal variables begin
Arrange for the process demand paged from the resulting executable
file (0413 ``magic number''). 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
in the data segment;
this is to avoid wasting the space resulting from rounding the data
segment size. Implies
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
These may appear
anywhere, and their influence is dependent upon their location.
Some options may be obtained from
environment variables, such options are interpreted before any
on the command line (see
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
in combination with
to place library members in calling order (see
for details), or both (for fastest symbol lookup).
The first member of an archived processed by
has the reserved name of
takes to be the dictionary of all symbols defined by
members of the archive.
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
structures and the
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.
below, for details.
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
and a suffix of either
to indicate an
archive or a shared library, respectively.
The specific suffix used is determined through rules discussed in
Binding and Relocation Semantics,
searches for the desired object file through a list of
directories specified by
options, the environment variable
and finally, the built-in list of standard library directories:
Binding and Relocation Semantics
The manner in which
processes a given object file is
dependent in part upon the ``binding mode'' 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
on and off.
the influence of each depends upon its location within the
is in effect,
searches may be satisfied by the first occurrence of either form of
but if both are encountered, the
form is preferred. When
is in effect,
refuses to use any
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 ``symbolic reduction,''
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 ``common'' 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 ``commons'' 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 ``relative reduction''
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.
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 ``main'' program should be
linked with a ``bootstrap'' routine that invokes
which uses the information
contained in the main program's
to assemble the rest
of the executables constituting the entire program. A standard
Sun compilation driver (such as
automatically includes such a module in each ``main'' 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
mimics that used when
is run, and like
can be influenced by the setting of
options specified to
when the program was built.
then completes all
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
``undefined symbol'' 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.
function (on by default) checks at
whether or not an execution-time binding error would occur.
Version Handling for Shared Libraries
To allow the independent evolution of
used as libraries and the programs which use them,
files found through
options involves the retention and
management of version control information. The
files used as such ``shared libraries'' are post-fixed with a
Dewey-decimal format string describing the version of the ``library''
contained in the file.
The first decimal component is called the library's
``major version'' number,
and the second component its ``minor version'' number. When
used as a library, it also records these two
numbers in the database used by
at execution time. In turn,
uses these numbers to
decide which of multiple versions of a given library is ``best'' 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
Note: C and several
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
A position-independent reference to an
table of addresses. This table is constructed from
``position-independent'' data references occurring in objects
that have been assembled with the assembler's
flag (invoked on behalf of C compilations
performed with the
flag). A related table (for which no
symbol is currently defined) contains a series of transfer
instructions and is created from ``position-independent'' procedure
calls or, if
is specified to
a list of undefined symbols.
Symbols in object files beginning with the letter
are taken to be
local symbols and unless otherwise specified are purged from
A colon-separated list of directories in which to search for
libraries specified with the
option. Similar to 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 ``trusts'', 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
is interpreted by
just as though its value had been placed on the command line,
immediately following the name used to invoke
example% ld $LD_OPTIONS ... other-arguments ...
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.
There needs to be
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
Created by unroff & hp-tools.
© by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97