1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
.\" $OpenBSD: ld.1,v 1.12 1998/05/11 20:23:31 niklas Exp $
.\" $NetBSD: ld.1,v 1.14 1998/02/20 03:12:50 jonathan Exp $
.\"
.\" Copyright (c) 1993 Paul Kranenburg
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by Paul Kranenburg.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\"
.Dd October 14, 1993
.Dt LD 1
.Os
.Sh NAME
.Nm ld
.Nd link editor
.Sh SYNOPSIS
.Nm ld
.Op Fl MNnprSstXxZz
.Bk -words
.Op Fl A Ar symbol-file
.Op Fl assert Ar keyword
.Op Fl B Ns Ar linkmode
.Op Fl D Ar data-size
.Op Fl d\ c
.Op Fl d\ p
.Op Fl e Ar entry
.Op Fl l Ns Ar library-specifier
.Op Fl L Ns Ar library-search-path
.Op Fl R Ns Ar record-library-search-path
.Op Fl nostdlib
.Op Fl o Ar filename
.Op Fl T Ar address
.Op Fl u Ar symbol
.Op Fl V Ar shlib-version
.Op Fl y Ar symbol
.Ek
.Sh DESCRIPTION
.Nm
combines the object and archive files given on the command line into a new
object file. The output object file is either an executable program, a
shared object suitable for loading at run-time, or an object file that can
once again be processed by
.Nm ld.
Object files and archives are processed in the order given on the command line.
.Pp
The options are as follows:
.Pp
.Bl -tag -width indent
.It Fl A Ar symbol-file
The symbol-file is taken as a base for link-editing the object files
on the command line.
.It Fl assert Ar keyword
This option has currently no effect. It is here for compatibility with
SunOS ld. All conditions which would cause a Sun assertion to fail will
currently always cause error or warning messages from
.Nm ld .
.It Fl Bdynamic
Specifies that linking against dynamic libraries can take place. If a library
specifier of the form
.Fl l Ns Ar spec
appears on the command line,
.Nm ld
searches for a library of the from
.Pa lib<spec>.so.<n>.<m>
(see the
.Fl l
option)
according to the search rules in effect. If such a file can not be
found a traditional archive is looked for.
This options can appear anywhere on the command line and is complementary
to
.Fl Bstatic .
.It Fl Bstatic
The counterpart of
.Fl Bdynamic .
This option turns off dynamic linking for
all library specifiers until a
.Fl Bdynamic
is once again given. Any explicitly
mentioned shared object encountered on the command line while this option is
in effect is flagged as an error.
.It Fl Bshareable
Instructs the linker to build a shared object from the object files rather
than a normal executable image.
.It Fl Bsymbolic
This option causes all symbolic references in the output to be resolved in
this link-edit session. The only remaining run-time relocation requirements are
.Em base-relative
relocations, i.e. translation with respect to the load address. Failure to
resolve any symbolic reference causes an error to be reported.
.It Fl Bforcearchive
Force all members of archives to be loaded, whether or not such members
contribute a definition to any plain object files. Useful for making a
shared library from an archive of PIC objects without having to unpack
the archive.
.It Fl Bsilly
Search for
.Pa \.sa
silly archive companions of shared objects. Useful for compatibility with
version 3 shared objects.
.It Fl D Ar data-size
Set the size of the data segment. For sanity's sake, this should be larger
than the cumulative data sizes of the input files.
.It Fl d\ c
Force allocation of commons even producing relocatable output.
.It Fl d\ p
Force alias definitions of procedure calls in non-PIC code. Useful to
obtain shareable code in the presence of run-time relocations as such
calls will be re-directed through the Procedure Linkage Table (see
.Xr link 5 . )
.It Fl e Ar entry
Specifies the entry symbol for an executable.
.It Fl L Ns Ar path
Add
.Ar path
to the list of directories to search for libraries specified with the
.Fl l
option.
.It Fl l Ns Ar spec
This option specifies a library to be considered for inclusion in the
output. If the
.Fl Bdynamic
option is in effect, a shared library of the
form
.Pa lib<spec>.so.<m>.<n>
is searched for first (where
.Em m
is the major, and
.Em n
is the minor version number, respectively.)
The
library with the highest version found in the search path is selected.
If no shared library is found or the
.Fl Bstatic
option is in effect, an archive of the form
.Pa lib<spec>.a
is looked for in
the library search path.
.It Fl M
Produce output about the mapping of segments of the input files and the
values assigned to
.Pq global
symbols in the output file.
.It Fl N
Produce an
.Dv OMAGIC
output file.
.It Fl n
Produce a
.Dv NMAGIC
output file.
.It Fl nostdlib
Do not search the built-in path
.Po
usually
.Dq Pa /usr/lib
.Pc
for
.Fl l
specified libraries.
.It Fl o Ar filename
Specifies the name of the output file. Defaults to
.Dq Pa a.out .
.It Fl p
Make the data segment start on a page boundary.
.It Fl Q
Produce a
.Dv QMAGIC
output file.
.It Fl r
Produce relocatable object file, suitable for another pass through
.Nm ld .
.It Fl R Ns Ar path
Record
.Ar path
within the executable for run-time library search.
This only applies to dynamically linked executables.
.It Fl S
Strip all debugger symbols from the output.
.It Fl s
Strip all symbols from the output.
.It Fl T Ar address
Specifies the start address of the text segment, with respect to which
all input files will be relocated.
.It Fl t
Leave a trace of the input files as they are processed.
.It Fl u Ar symbol
Force
.Ar symbol
to be marked as undefined. Useful to force loading of an archive member
in the absence of any other references to that member.
.It Fl V Ar version
Put the given version number into the output shared library
.Pq if one is created .
Useful to make shared libraries compatible with other operating
systems. E.g., SunOS 4.x libraries use version number 3. Defaults to 8.
.It Fl X
Discard local symbols in the input files that start with the letter
.Dq L .
.It Fl x
Discard all local symbols in the input files.
.It Fl y Ar symbol
Trace the manipulations inflicted on
.Ar symbol .
.It Fl z
Make a
.Dv ZMAGIC
output file. This is the default.
.It Fl Z
Make an old-style
.Dv ZMAGIC
output file. This means no flags and no machine ID in the magic.
.Sh
The following long options are exceptions to the normal option syntax
described above, and are provided for compatibility with later versions of
GNU
.Nm ld :
.Bl -tag -width indent
.It Fl rpath Ar path
Record the given
.Ar path
within the executable for run-time library
search, as for
.Fl R .
This only applies to dynamically linked executables.
.It Fl shared
Instructs the linker to build a shared object from the object files rather
than a normal executable image.
.It Fl soname Ar library-name
This option and its
.Ar library-name
argument are ignored. They are provided for compatibility with versions of
.Nm ld ,
which allow the user to specify an internal name and version number
for dynamically-linked shared libraries.
.It Fl \&-whole-archive
A positional qualifier to force loading from archives.
For each archive mentioned on the commandline after this option,
include every object file from the archive in the link, rather than
searching the archive for the required object files. This is normally used
when building shared libraries.
The positional syntax is not currently implemented;
.Fl \&-whole-archive
is treated exactly as
.Fl Bforcearchive .
.It Fl \&-no-whole-archive
This option should turn off the effect of a preceding
.Fl \&-whole-archive
for any subsequent archive files on the command line.
It is currently ignored.
.El
.Sh ENVIRONMENT
.Nm
utilizes the following environment variables:
.Bl -tag -width "LD_LIBRARY_PATH"
.It Ev LD_LIBRARY_PATH
This colon-separated list of directories is inserted into the search
path for libraries following any directories specified via
.Fl L
options and preceding the built-in path.
.It Ev LD_NOSTD_PATH
When set, do not search the built-in path for libraries.
This is an alternative to the
.Fl nostdlib
command-line flag.
.El
.\" .Sh FILES
.Sh SEE ALSO
.Xr ldconfig 1 ,
.Xr ld.so 1 ,
.Xr link 5
.Sh CAVEATS
An entry point must now explicitly be given if the output is intended to be
a normal executable program. This was not the case for the previous version of
.Nm ld .
.Sh BUGS
Shared objects are not properly checked for undefined symbols.
.Pp
Cascading of shared object defeats the
.Fl Bstatic
option.
.Pp
All shared objects presented to
.Nm ld
are marked for run-time loading in the output file, even if no symbols
are needed from them.
.Sh HISTORY
The shared library model employed by
.Nm ld
appeared first in SunOS 4.0.
|