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