BSD 4_3_Tahoe development
[unix-history] / usr / man / cat1 / ld.0
LD(1) UNIX Programmer's Manual LD(1)
N\bNA\bAM\bME\bE
ld - link editor
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
l\bld\bd [ option ] ... file ...
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
_\bL_\bd combines several object programs into one, resolves
external references, and searches libraries. In the sim-
plest case several object _\bf_\bi_\bl_\be_\bs are given, and _\bl_\bd combines
them, producing an object module which can be either exe-
cuted or become the input for a further _\bl_\bd run. (In the
latter case, the -\b-r\br option must be given to preserve the
relocation bits.) The output of _\bl_\bd is left on a\ba.\b.o\bou\but\bt. This
file is made executable only if no errors occurred during
the load.
The argument routines are concatenated in the order speci-
fied. The entry point of the output is the beginning of the
first routine (unless the -\b-e\be option is specified).
If any argument is a library, it is searched exactly once at
the point it is encountered in the argument list. Only
those routines defining an unresolved external reference are
loaded. If a routine from a library references another rou-
tine in the library, and the library has not been processed
by _\br_\ba_\bn_\bl_\bi_\bb(1), the referenced routine must appear after the
referencing routine in the library. Thus the order of pro-
grams within libraries may be important. The first member
of a library should be a file named `__.SYMDEF', which is
understood to be a dictionary for the library as produced by
_\br_\ba_\bn_\bl_\bi_\bb(1); the dictionary is searched iteratively to satisfy
as many references as possible.
The symbols `_etext', `_edata' and `_end' (`etext', `edata'
and `end' in C) are reserved, and if referred to, are set to
the first location above the program, the first location
above initialized data, and the first location above all
data respectively. It is erroneous to define these symbols.
_\bL_\bd understands several options. Except for -\b-l\bl, they should
appear before the file names.
-\b-A\bA This option specifies incremental loading, i.e. link-
ing is to be done in a manner so that the resulting
object may be read into an already executing program.
The next argument is the name of a file whose symbol
table will be taken as a basis on which to define addi-
tional symbols. Only newly linked material will be
entered into the text and data portions of a\ba.\b.o\bou\but\bt,\b, but
the new symbol table will reflect every symbol defined
before and after the incremental load. This argument
Printed 7/9/88 May 8, 1986 1
LD(1) UNIX Programmer's Manual LD(1)
must appear before any other object file in the argu-
ment list. The -\b-T\bT option may be used as well, and will
be taken to mean that the newly linked segment will
commence at the corresponding address (which must be a
multiple of 1024). The default value is the old value
of _end.
-\b-D\bD Take the next argument as a hexadecimal number and pad
the data segment with zero bytes to the indicated
length.
-\b-d\bd Force definition of common storage even if the -\b-r\br flag
is present.
-\b-e\be The following argument is taken to be the name of the
entry point of the loaded program; location 0 is the
default.
-\b-L\bL_\bd_\bi_\br
Add _\bd_\bi_\br to the list of directories in which libraries
are searched for. Directories specified with -\b-L\bL are
searched before the standard directories.
-\b-l\bl_\bx This option is an abbreviation for the library name
`lib_\bx.a', where _\bx is a string. _\bL_\bd searches for
libraries first in any directories specified with -\b-L\bL
options, then in the standard directories `/lib',
`/usr/lib', and `/usr/local/lib'. A library is
searched when its name is encountered, so the placement
of a -\b-l\bl is significant.
-\b-M\bM produce a primitive load map, listing the names of the
files which will be loaded.
-\b-N\bN Do not make the text portion read only or sharable.
(Use "magic number" 0407.)
-\b-n\bn Arrange (by giving the output file a 0410 "magic
number") that when the output file is executed, the
text portion will be read-only and shared among all
users executing the file. This involves moving the
data areas up to the first possible 1024 byte boundary
following the end of the text.
-\b-o\bo The _\bn_\ba_\bm_\be argument after -\b-o\bo is used as the name of the
_\bl_\bd output file, instead of a\ba.\b.o\bou\but\bt.
-\b-r\br Generate relocation bits in the output file so that it
can be the subject of another _\bl_\bd run. This flag also
prevents final definitions from being given to common
symbols, and suppresses the `undefined symbol' diagnos-
tics.
Printed 7/9/88 May 8, 1986 2
LD(1) UNIX Programmer's Manual LD(1)
-\b-S\bS `Strip' the output by removing all symbols except
locals and globals.
-\b-s\bs `Strip' the output, that is, remove the symbol table
and relocation bits to save space (but impair the use-
fulness of the debuggers). This information can also
be removed by _\bs_\bt_\br_\bi_\bp(1).
-\b-T\bT The next argument is a hexadecimal number which sets
the text segment origin. The default origin is 0.
-\b-t\bt ("trace") Print the name of each file as it is pro-
cessed.
-\b-u\bu Take the following argument as a symbol and enter it as
undefined in the symbol table. This is useful for
loading wholly from a library, since initially the sym-
bol table is empty and an unresolved reference is
needed to force the loading of the first routine.
-\b-X\bX Save local symbols except for those whose names begin
with `L'. This option is used by _\bc_\bc(1) to discard
internally-generated labels while retaining symbols
local to routines.
-\b-x\bx Do not preserve local (non-.globl) symbols in the out-
put symbol table; only enter external symbols. This
option saves some space in the output file.
-\b-y\by_\bs_\by_\bm
Indicate each file in which _\bs_\by_\bm 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 _\bs_\by_\bm with an `_', as external
C, FORTRAN and Pascal variables begin with under-
scores.)
-\b-z\bz Arrange for the process to be loaded on demand from the
resulting executable file (413 format) rather than
preloaded. This is the default. Results in a 1024
byte header on the output file followed by a text and
data segment each of which have size a multiple of 1024
bytes (being padded out with nulls in the file if
necessary). With this format the first few BSS segment
symbols may actually appear (from the output of
_\bs_\bi_\bz_\be(1)) to live in the data segment; this to avoid
wasting the space resulting from data segment size
roundup.
F\bFI\bIL\bLE\bES\bS
/lib/lib*.a libraries
/usr/lib/lib*.a more libraries
Printed 7/9/88 May 8, 1986 3
LD(1) UNIX Programmer's Manual LD(1)
/usr/local/lib/lib*.a still more libraries
a.out output file
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
as(1), ar(1), cc(1), ranlib(1)
B\bBU\bUG\bGS\bS
There is no way to force data to be page aligned. _\bL_\bd pads
images which are to be demand loaded from the file system to
the next page boundary to avoid a bug in the system.
Printed 7/9/88 May 8, 1986 4