Import ELF Tool Chain snapshot at revision 3475
[freebsd-src.git] / ld / ld.1
blob122050312de95be6061520913433ba677de224dd
1 .\" Copyright (c) 2016 Joseph Koshy.  All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" This software is provided by the author and contributors ``as is''
13 .\" and any express or implied warranties, including, but not limited
14 .\" to, the implied warranties of merchantability and fitness for a
15 .\" particular purpose are disclaimed.  In no event shall the author or
16 .\" contributors be liable for any direct, indirect, incidental, special,
17 .\" exemplary, or consequential damages (including, but not limited to,
18 .\" procurement of substitute goods or services; loss of use, data, or
19 .\" profits; or business interruption) however caused and on any
20 .\" theory of liability, whether in contract, strict liability, or
21 .\" tort (including negligence or otherwise) arising in any way
22 .\" out of the use of this software, even if advised of the
23 .\" possibility of such damage.
24 .\"
25 .\" $Id$
26 .\"
27 .Dd February 14, 2016
28 .Os
29 .Dt LD 1
30 .Sh NAME
31 .Nm ld
32 .Nd link editor
33 .Sh SYNOPSIS
34 .Nm
35 .Op Fl \&(
36 .Op Fl \&)
37 .Op Fl Bdynamic
38 .Op Fl Bshareable
39 .Op Fl Bstatic
40 .Op Fl I Ar file | Fl -dynamic-linker= Ns Ar file
41 .Op Fl L Ar dir | Fl -library-path= Ns Ar dir
42 .Op Fl M | Fl -print-map
43 .Op Fl T Ar script-file | Fl -script= Ns Ar script-file
44 .Op Fl V | Fl v | Fl -version
45 .Op Fl a Ar linkmode
46 .Op Fl b Ar input-format | Fl -format= Ns Ar input-format
47 .Op Fl call_shared
48 .Op Fl d | Fl dc | Fl dp
49 .Op Fl dn
50 .Op Fl dy
51 .Op Fl e Ar symbol | Fl -entry= Ns Ar symbol
52 .Op Fl h Ar name | Fl soname= Ns Ar name
53 .Op Fl l Ar library | Fl -library= Ns Ar library
54 .Op Fl o Ar output-file | Fl -output= Ns Ar output-file
55 .Op Fl q | Fl -emit-relocs
56 .Op Fl r | Fl -relocatable
57 .Op Fl u Ar name | Fl -undefined= Ns Ar name
58 .Op Fl z Ar keyword
59 .Op Fl -as-needed
60 .Op Fl -eh-frame-hdr
61 .Op Fl -end-group
62 .Op Fl -gc-sections
63 .Op Fl -no-as-needed
64 .Op Fl -no-define-common
65 .Op Fl -no-gc-sections
66 .Op Fl -no-print-gc-sections
67 .Op Fl -no-whole-archive
68 .Op Fl -oformat= Ns Ar format
69 .Op Fl -pic-executable | Fl pie
70 .Op Fl -print-gc-sections
71 .Op Fl -rpath= Ns Ar dirs
72 .Op Fl -rpath-link= Ns Ar dirs
73 .Op Fl -start-group
74 .Op Fl shared
75 .Op Fl static
76 .Op Fl -version-script= Ns Ar script
77 .Op Fl -whole-archive
78 .Ar
79 .Sh DESCRIPTION
80 The
81 .Nm
82 utility combines ELF objects and
83 .Xr ar 1
84 archives containing ELF objects into an executable or a partially
85 relocated object.
86 .Pp
87 The
88 .Nm
89 utility processes options and files in the order presented on the
90 command line.
91 Unlike most
92 .Ux
93 utilities, options and file names may be interspersed.
94 Options seen on the command line will generally apply to subsequent
95 files, or till overridden by another option.
96 .Sh OPTIONS
97 .Pp
98 The
99 .Nm
100 utility supports the following options:
101 .Bl -tag -width indent
102 .It Xo
103 .Fl \&(
104 .Ar archives Ns ...
105 .Fl \&)
107 Start a group of archives that are to be searched repeatedly until no new
108 undefined references are created.
109 This option is used when there are circular references between one or
110 more archives in the archive group.
112 The files named by the arguments
113 .Ar archives
114 are expected to be archive files.
116 Each use of the
117 .Fl \&(
118 option starts a new archive group that is ended by a matching
119 .Fl \&)
120 option.
121 .It Fl Bdynamic
122 Choose dynamic libraries for the libraries specified by subsequent
123 .Fl l
124 options.
125 .It Fl Bshareable
126 Create a shared library.
127 .It Fl Bstatic
128 Choose static libraries for the libraries specified by subsequent
129 .Fl l
130 options.
131 .It Fl I Ar file | Fl -dynamic-linker= Ns Ar file
132 Set the name of the dynamic linker when generating ELF executables.
133 .It Fl L Ar dir | Fl -library-path= Ns Ar dir
134 Add directory
135 .Ar dir
136 to the list of paths that
138 will search for archive libraries.
139 This option may be specified multiple times.
140 User supplied directories are searched in the order specified on
141 the command line.
142 .It Fl M | Fl -print-map
143 Print a link map to standard output.
144 .It Fl T Ar script-file | Fl -script= Ns Ar script-file
145 Use the file name by argument
146 .Ar script-file
147 as the linker script instead of the default.
148 .It Fl V | Fl v | Fl version
149 Print a version identifier for
151 and exit.
152 .It Fl a Ar linkmode
153 Select linking mode.
154 The value of the argument
155 .Ar linkmode
156 should be one of the following literals:
157 .Bl -tag -width ".Li default" -compact
158 .It Cm default
159 Equivalent to specifying
160 .Fl Bdynamic .
161 .It Cm archive
162 Equivalent to specifying
163 .Fl Bstatic .
164 .It Cm shared
165 Equivalent to specifying
166 .Fl Bdynamic .
168 .It Fl b Ar input-format | Fl -format Ar input-format
169 Set the input format to that specified by argument
170 .Ar input-format .
171 The legal values for the argument
172 .Ar input-format
173 are those supported by
174 .Xr elftc_bfd_find_target 3 .
175 .It Fl d | Fl dc | Fl dp
176 Assign space for common symbols even if generating a relocatable object.
177 .It Fl dn
178 Equivalent to specifying option
179 .Fl Bstatic .
180 .It Fl dy
181 Equivalent to specifying option
182 .Fl Bdynamic .
183 .It Fl e Ar entry | Fl -entry Ar entry
184 Set execution to start at the symbol named by the argument
185 .Ar entry .
186 The argument should be the name of a symbol.
187 .It Fl h Ar name | Fl soname Ar name
188 Set the
189 .Li DT_SONAME
190 field in the object to that specified by the argument
191 .Ar name .
192 .It Fl l Ar name | Fl -library= Ns Ar name
193 Add the archive library or shared library named by argument
194 .Ar name
195 to the set of files to link.
196 This file is looked for in the list of directories specified by prior
197 .Fl L
198 options on the command line.
199 .It Fl o Ar output-file | Fl -output= Ns Ar output-file
200 Use the file specified by argument
201 .Ar output-file
202 for the output, instead of the default file name of
203 .Sq a.out .
204 .It Fl q | Fl -emit-relocs
205 Preserve relocation information in executables, for use by post-link
206 analysis tools.
207 .It Fl r | Fl -relocatable
208 Generate a relocatable output file that can be used as input for subsequent
209 linker runs.
210 .It Fl u Ar name | Fl -undefined= Ns Ar name
211 Add the symbol specified by argument
212 .Ar name
213 to the output file as an undefined symbol.
214 This option may be specified multiple times.
215 .It Fl z Ar keyword
216 Recognized keywords include:
217 .Bl -tag -width ".Li defaultextract" -compact
218 .It Cm execstack
219 Require the object to use an executable stack.
220 .It Cm noexecstack
221 Do not require the object to use an executable stack.
223 .It Fl -as-needed
225 .Li DT_NEEDED
226 tags for only those shared libraries that satisfy non-weak
227 unresolved references from object files or other dynamic libraries
228 seen so far on the command line.
229 .It Fl call_shared
230 Equivalent to specifying option
231 .Fl Bdynamic .
232 .It Fl -eh-frame-hdr
233 Create a
234 .Dq ".eh_frame_hdr"
235 section, and a
236 .Li PT_GNU_EH_FRAME
237 segment header, containing exception handling information.
238 .It Fl -end-group
239 Equivalent to specifying option
240 .Fl \&) .
241 .It Fl -gc-sections
242 Garbage collect unused input sections.
243 .It Fl -no-as-needed
244 Insert
245 .Li DT_NEEDED
246 tags for all shared libraries seen henceforth on the command line,
247 irrespective of whether the shared library is needed to resolve an
248 undefined symbol or not.
249 This behavior is the default.
250 .It Fl -no-define-common
251 Do not assign addresses to common symbols.
252 .It Fl -no-gc-sections
253 Do not garbage collect input sections that contain unreferenced
254 symbols.
255 .It Fl -no-print-gc-sections
256 Do not print the list of sections removed when the
257 .Fl -gc-sections
258 directive is active.
259 .It Fl -no-whole-archive
260 Only include objects in an archive that satisfy an unresolved reference
261 in the link.
262 This behavior is the default.
263 .It Fl non_shared
264 Equivalent to specifying option
265 .Fl Bstatic .
266 .It Fl -oformat= Ns Ar format
267 Set the desired output format to that specified by the argument
268 .Ar format .
269 Supported values for argument
270 .Ar format
271 are those understood by
272 .Xr elftc_bfd_find_target 3 .
273 .It Fl -pic-executable | Fl pie
274 Create a position-independent executable.
275 .It Fl -print-gc-sections
276 Print the list of sections removed when the
277 .Fl -gc-sections
278 directive is active.
279 The output is printed to stderr.
280 .It Fl -rpath= Ns Ar dirs
281 Add the colon-separated list of directories named by the argument
282 .Ar dirs
283 to the runtime library search path and to the link-time search
284 path.
285 .It Fl -rpath-link= Ns Ar dirs
286 Add the directories specified by the colon-separated list of directories
287 in argument
288 .Ar dirs
289 to the link-time search path for libraries.
290 The directories specified by this option are searched before those
291 specified by
292 .Fl -rpath
293 options.
294 .It Fl shared
295 Equivalent to specifying option
296 .Fl Bshareable .
297 .It Fl -start-group
298 Equivalent to specifying option
299 .Fl \&( .
300 .It Fl static
301 Equivalent to specifying option
302 .Fl Bstatic .
303 .It Fl -version-script= Ns Ar script-file
304 Use the version script in the file named by argument
305 .Ar script-file .
306 .It Fl -whole-archive
307 Include the entire contents of every archive file encountered on the
308 command line after this option in the link.
310 .Sh DIAGNOSTICS
311 .Ex -std
312 .Sh SEE ALSO
313 .Xr ar 1 ,
314 .Xr ranlib 1 ,
315 .Xr archive 3 ,
316 .Xr elf 3 ,
317 .Xr elftc_bfd_find_target 3 ,
318 .Xr dwarf 3
319 .Sh IMPLEMENTATION NOTES
322 utility differs from its GNU equivalent in the following:
323 .Bl -bullet
327 utility currently supports a limited range of output formats.
330 .Fl e
332 .Fl -entry
333 options only accept a symbol name as an argument, and not a numeric
334 address.
337 .Fl l
338 option only searches files in the directories specified by
339 prior
340 .Fl L
341 options.
344 .Fl T | Fl -script
345 option does not search for script files in the directories specified
346 by prior
347 .Fl L
348 options.
351 .Fl -rpath
352 option accepts a colon-separated list of directories instead of
353 single directory.
356 The following options are recognized, but are currently unimplemented:
357 .Fl Bgroup ,
358 .Fl Bsymbolic ,
359 .Fl Bsymbolic_functions ,
360 .Fl E ,
361 .Fl EB ,
362 .Fl EL ,
363 .Fl F ,
364 .Fl Map ,
365 .Fl N ,
366 .Fl O ,
367 .Fl Qy ,
368 .Fl R ,
369 .Fl S ,
370 .Fl Tbss ,
371 .Fl Tdata ,
372 .Fl Ttext ,
373 .Fl X ,
374 .Fl Y ,
375 .Fl Ur ,
376 .Fl c ,
377 .Fl f ,
378 .Fl g ,
379 .Fl i ,
380 .Fl m ,
381 .Fl n ,
382 .Fl s ,
383 .Fl t ,
384 .Fl x ,
385 .Fl y ,
386 .Fl -accept-unknown-input-arch ,
387 .Fl -allow-multiple-definition ,
388 .Fl -allow-shlib-undefined ,
389 .Fl -assert ,
390 .Fl -auxiliary ,
391 .Fl -build-id ,
392 .Fl -check-sections ,
393 .Fl -cref ,
394 .Fl -defsym ,
395 .Fl -demangle ,
396 .Fl -disable-new-dtags ,
397 .Fl -discard-all ,
398 .Fl -discard-locals ,
399 .Fl -error-unresolved-symbols ,
400 .Fl -export-dynamic ,
401 .Fl -emulation ,
402 .Fl -enable-new-dtags ,
403 .Fl -fatal-warnings ,
404 .Fl -filter ,
405 .Fl -fini ,
406 .Fl -hash-style ,
407 .Fl -help ,
408 .Fl -init ,
409 .Fl -just-symbols ,
410 .Fl -mri-script ,
411 .Fl -nmagic ,
412 .Fl nostdlib ,
413 .Fl -no-accept-unknown-input-arch ,
414 .Fl -no-allow-shlib-undefined ,
415 .Fl -no-assert ,
416 .Fl -no-check-sections ,
417 .Fl -no-demangle ,
418 .Fl -no-keep-memory ,
419 .Fl -no-omagic ,
420 .Fl -no-undefined ,
421 .Fl -no-undefined-version ,
422 .Fl -no-warn-mismatch ,
423 .Fl -omagic ,
424 .Fl -qmagic ,
425 .Fl -relax ,
426 .Fl -retain-symbols-file ,
427 .Fl -runpath ,
428 .Fl -section-start ,
429 .Fl -sort-common ,
430 .Fl -split-by-file ,
431 .Fl -split-by-reloc ,
432 .Fl -stats ,
433 .Fl -strip-all ,
434 .Fl -strip-debug ,
435 .Fl -trace ,
436 .Fl -trace_symbol ,
437 .Fl -traditional-format ,
438 .Fl -unique ,
439 .Fl -unresolved-symbols ,
440 .Fl -verbose ,
441 .Fl -warn-common ,
442 .Fl -warn-constructors ,
443 .Fl -warn-multiple-gp ,
444 .Fl -warn-once ,
445 .Fl -warn-section-align ,
446 .Fl -warn-shared-textrel ,
447 .Fl -warn-unresolved-symbols ,
448 .Fl -wrap .
450 The following keywords are recognized by the
451 .Fl z
452 option, but are currently unimplemented:
453 .Cm allextract ,
454 .Cm defaultextract ,
455 .Cm defs ,
456 .Cm ignore ,
457 .Cm initfirst ,
458 .Cm lazyload ,
459 .Cm muldefs ,
460 .Cm nodefaultlib ,
461 .Cm nodefs ,
462 .Cm nodelete ,
463 .Cm nodlopen ,
464 .Cm nolazyload ,
465 .Cm now ,
466 .Cm origin ,
467 .Cm record ,
468 .Cm systemlibrary ,
469 .Cm weakextract .
470 .Sh HISTORY
473 command first appeared in AT&T UNIX Version 1.
475 The Elftoolchain implementation of
477 was written by
478 .An Kai Wang Aq Mt kaiwang27@gmail.com .