date and time created 92/10/17 13:31:40 by bostic
[unix-history] / usr / src / old / ld / ld.1
CommitLineData
d9d7a9f0 1.\" Copyright (c) 1980, 1990 The Regents of the University of California.
7430d53a 2.\" All rights reserved.
b126b715 3.\"
7430d53a
KB
4.\" %sccs.include.proprietary.man%
5.\"
3f4f3ab0 6.\" @(#)ld.1 6.7 (Berkeley) %G%
b126b715 7.\"
d9d7a9f0
CL
8.Dd
9.Dt LD 1
10.Os BSD 4
11.Sh NAME
12.Nm ld
13.Nd link editor
14.Sh SYNOPSIS
15.Nm ld
16.Op option
3f4f3ab0 17.Ar ...
d9d7a9f0
CL
18.Ar file ...
19.Sh DESCRIPTION
20.Nm Ld
b126b715
KM
21combines several
22object programs into one, resolves external
23references, and searches libraries.
24In the simplest case several object
d9d7a9f0 25.Ar files
b126b715 26are given, and
d9d7a9f0 27.Nm ld
b126b715
KM
28combines them, producing
29an object module which can be either executed or
30become the input for a further
d9d7a9f0 31.Nm ld
b126b715
KM
32run.
33(In the latter case, the
d9d7a9f0 34.Fl r
b126b715 35option must be given
5325ced3 36to preserve the relocation bits.)
b126b715 37The output of
d9d7a9f0 38.Nm ld
b126b715 39is left on
d9d7a9f0 40.Pa a.out .
b126b715
KM
41This file is made executable
42only if no errors occurred during the load.
d9d7a9f0 43.Pp
b126b715
KM
44The argument routines are concatenated in the order
45specified. The entry point of the output is the
d9d7a9f0
CL
46beginning of the first routine (unless the
47.Fl e
48option is specified).
49.Pp
b126b715
KM
50If any argument is a library, it is searched exactly once
51at the point it is encountered in the argument list.
52Only those routines defining an unresolved external
53reference are loaded.
54If a routine from a library
55references another routine in the library,
56and the library has not been processed by
d9d7a9f0 57.Xr ranlib 1 ,
b126b715
KM
58the referenced routine must appear after the
59referencing routine in the library.
60Thus the order of programs within libraries
61may be important.
62The first member of a library
63should be a file named `\_\^\_.SYMDEF',
64which is understood to be a dictionary for the library as produced by
d9d7a9f0 65.Xr ranlib 1 ;
b126b715
KM
66the dictionary is searched iteratively to satisfy as many references as
67possible.
d9d7a9f0 68.Pp
b126b715
KM
69The symbols `\_etext', `\_edata' and `\_end'
70(`etext', `edata' and `end' in C)
71are reserved, and if referred to,
72are set to the first location above the program,
73the first location above initialized data,
74and the first location above all data respectively.
75It is erroneous to define these symbols.
d9d7a9f0
CL
76.Pp
77.Nm Ld
b126b715
KM
78understands several options.
79Except for
d9d7a9f0 80.Fl l ,
b126b715 81they should appear before the file names.
3f4f3ab0
CL
82.Bl -tag -width flagx
83.It Fl A
b126b715
KM
84This option specifies incremental loading, i.e.
85linking is to be done in a manner so that the resulting object
86may be read into an already executing program.
87The next argument is the name of a file whose symbol table will be
88taken as a basis on which to define additional symbols.
89Only newly linked material will be entered into the text and
d9d7a9f0
CL
90data portions of
91.Xr a.out ,
b126b715
KM
92but the new symbol table will reflect
93every symbol defined before and after the incremental load.
94This argument must appear before any other object file in the argument list.
95The
d9d7a9f0 96.Fl T
b126b715
KM
97option may be used as well, and will be taken to mean that the
98newly linked segment will commence at the corresponding address
99(which must be a multiple of 1024).
100The default value is the old value of _end.
3f4f3ab0 101.It Fl D
b126b715
KM
102Take the next argument as a hexadecimal number and pad the data segment
103with zero bytes to the indicated length.
3f4f3ab0 104.It Fl d
b126b715
KM
105Force definition of common storage
106even if the
d9d7a9f0 107.Fl r
b126b715 108flag is present.
3f4f3ab0 109.It Fl e
b126b715
KM
110The following argument is taken to be the
111name of the entry point of the loaded
112program; location 0 is the default.
3f4f3ab0 113.It Fl L Ns Ar dir
98c29de5 114Add
d9d7a9f0 115.Ar dir
98c29de5 116to the list of directories in which libraries are searched for.
d9d7a9f0
CL
117Directories specified with
118.Fl L
69428b9e 119are searched before the standard directories.
3f4f3ab0 120.It Fl l Ns Ar x
b126b715
KM
121This
122option is an abbreviation for the library name
d9d7a9f0 123.Sq Pa libx.a,
b126b715 124where
d9d7a9f0 125.Ar x
b126b715 126is a string.
d9d7a9f0 127.Nm Ld
98c29de5
KM
128searches for libraries first in any directories
129specified with
d9d7a9f0 130.Fl L
5325ced3
CL
131options, then in the standard directories
132.Pa /lib ,
133.Pa /usr/lib ,
134and
135.Pa /usr/local/lib .
b126b715
KM
136A library is searched when its name is encountered,
137so the placement of a
d9d7a9f0 138.Fl l
b126b715 139is significant.
3f4f3ab0 140.It Fl M
b126b715
KM
141produce a primitive load map, listing the names of the files
142which will be loaded.
3f4f3ab0 143.It Fl N
b126b715 144Do not make the text portion read only or sharable. (Use "magic number" 0407.)
3f4f3ab0 145.It Fl n
b126b715
KM
146Arrange (by giving the output file a 0410 "magic number") that
147when the output file is executed,
148the text portion will be read-only and shared
149among all users executing the file.
150This involves moving the data areas up to the first
151possible 1024 byte boundary following the
152end of the text.
3f4f3ab0 153.It Fl o
b126b715 154The
d9d7a9f0 155.Ar name
b126b715 156argument after
d9d7a9f0 157.Fl o
b126b715 158is used as the name of the
d9d7a9f0 159.Nm ld
b126b715 160output file, instead of
d9d7a9f0 161.Pa a.out .
3f4f3ab0 162.It Fl r
b126b715
KM
163Generate relocation bits in the output file
164so that it can be the subject of another
d9d7a9f0 165.Nm ld
b126b715
KM
166run.
167This flag also prevents final definitions from being
168given to common symbols,
169and suppresses the `undefined symbol' diagnostics.
3f4f3ab0 170.It Fl S
b126b715 171`Strip' the output by removing all symbols except locals and globals.
3f4f3ab0 172.It Fl s
b126b715
KM
173`Strip' the output, that is, remove the symbol table
174and relocation bits to save space (but impair the
175usefulness of the debuggers).
176This information can also be removed by
d9d7a9f0 177.Xr strip 1 .
3f4f3ab0 178.It Fl T
b126b715
KM
179The next argument is a hexadecimal number which sets the text segment origin.
180The default origin is 0.
3f4f3ab0 181.It Fl t
b126b715 182("trace") Print the name of each file as it is processed.
3f4f3ab0 183.It Fl u
b126b715
KM
184Take the following argument as a symbol and enter
185it as undefined in the symbol table. This is useful
186for loading wholly from a library, since initially the symbol
187table is empty and an unresolved reference is needed
188to force the loading of the first routine.
3f4f3ab0 189.It Fl X
b126b715
KM
190Save local symbols
191except for those whose names begin with `L'.
192This option is used by
d9d7a9f0 193.Xr cc 1
b126b715
KM
194to discard internally-generated labels while
195retaining symbols local to routines.
3f4f3ab0 196.It Fl x
b126b715
KM
197Do not preserve local
198(non-.globl) symbols in the output symbol table; only enter
199external symbols.
200This option saves some space in the output file.
3f4f3ab0 201.It Fl y Ns Ar sym
b126b715 202Indicate each file in which
d9d7a9f0 203.Ar sym
b126b715
KM
204appears, its type and whether the file defines or references it.
205Many such options may be given to trace many symbols.
206(It is usually necessary to begin
d9d7a9f0 207.Ar sym
3f4f3ab0
CL
208with an `_', as external C,
209.Tn FORTRAN
210and Pascal variables begin
b126b715 211with underscores.)
3f4f3ab0 212.It Fl z
b126b715
KM
213Arrange for the process to be loaded on
214demand from the resulting executable file (413 format)
215rather than preloaded.
216This is the default.
217Results in a 1024 byte header on the output file followed by
218a text and data segment each of which have size a multiple of 1024 bytes
219(being padded out with nulls in the file if necessary).
3f4f3ab0
CL
220With this format the first few
221.Tn BSS
222segment symbols may actually appear
b126b715 223(from the output of
d9d7a9f0 224.Xr size 1 )
b126b715
KM
225to live in the data segment;
226this to avoid wasting the space resulting from data segment size roundup.
3f4f3ab0 227.El
d9d7a9f0 228.Sh FILES
3f4f3ab0
CL
229.Bl -tag -width /usr/local/lib/lib*.a -compact
230.It Pa /usr/lib/lib*.a
231Libraries.
232.It Pa /usr/local/lib/lib*.a
233More libraries.
234.It Pa a.out
235Output file.
236.El
d9d7a9f0
CL
237.Sh SEE ALSO
238.Xr as 1 ,
239.Xr ar 1 ,
240.Xr cc 1 ,
241.Xr ranlib 1
242.Sh HISTORY
3f4f3ab0
CL
243The
244.Nm ld
245command appeared in
246.At v6 .
d9d7a9f0 247.Sh BUGS
b126b715 248There is no way to force data to be page aligned.
d9d7a9f0 249.Nm Ld
3d685d18
KM
250pads images which are to be demand loaded from
251the file system to the next
252page boundary to avoid a bug in the system.