xref: /illumos-gate/usr/src/man/man1/ld.1 (revision 201ceb75ab95f9bf1f42ea1dc9ab363b43ba47cf)
1.\"
2.\" The contents of this file are subject to the terms of the
3.\" Common Development and Distribution License (the "License").
4.\" You may not use this file except in compliance with the License.
5.\"
6.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7.\" or http://www.opensolaris.org/os/licensing.
8.\" See the License for the specific language governing permissions
9.\" and limitations under the License.
10.\"
11.\" When distributing Covered Code, include this CDDL HEADER in each
12.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
13.\" If applicable, add the following below this CDDL HEADER, with the
14.\" fields enclosed by brackets "[]" replaced with your own identifying
15.\" information: Portions Copyright [yyyy] [name of copyright owner]
16.\"
17.\" Copyright 1989 AT&T
18.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
19.\" Copyright 2019 Joyent, Inc.
20.\" Copyright 2023 Oxide Computer Company
21.\" Copyright 2024 OmniOS Community Edition (OmniOSce) Association.
22.\"
23.Dd January 15, 2024
24.Dt LD 1
25.Os
26.Sh NAME
27.Nm ld
28.Nd link-editor for object files
29.Sh SYNOPSIS
30.Nm
31.Op Fl 32 | 64
32.Op Fl a | r
33.Op Fl b
34.Op Fl B Cm direct | Fl B Cm nodirect
35.Op Fl B Cm dynamic | Fl B Cm static
36.Op Fl B Cm eliminate
37.Op Fl B Cm group
38.Op Fl B Cm local
39.Op Fl B Cm reduce
40.Op Fl B Cm symbolic
41.Op Fl c Ar name
42.Op Fl C
43.Op Fl d Cm y | Fl d Cm n
44.Op Fl D Ar token Ns No ,...
45.Op Fl e Ar epsym
46.Op Fl f Ar name | Fl F Ar name
47.Op Fl G
48.Op Fl h Ar name
49.Op Fl i
50.Op Fl I Ar name
51.Op Fl l Ar x
52.Op Fl L Ar path
53.Op Fl m
54.Op Fl M Ar mapfile
55.Op Fl N Ar string
56.Op Fl o Ar outfile
57.Op Fl p Ar auditlib
58.Op Fl P Ar auditlib
59.Op Fl Q Cm y | Fl Q Cm n
60.Op Fl R Ar path
61.Op Fl s
62.Op Fl S Ar supportlib
63.Op Fl t
64.Op Fl u Ar symname
65.Op Fl V
66.Op Fl Y Cm P Ns \&, Ns Ar dirlist
67.Op Fl z Cm absexec
68.Op Fl z Cm allextract | Fl z Cm defaultextract | Fl z Cm weakextract
69.Op Fl z Cm altexec64
70.Op Fl z Cm aslr Ns Op Cm \&= Ns Ar state
71.Op Fl z Cm assert-deflib
72.Op Fl z Cm assert-deflib= Ns Ar libname
73.Op Fl z Cm combreloc | Fl z Cm nocombreloc
74.Op Fl z Cm defs | Fl z Cm nodefs
75.Op Fl z Cm direct | Fl z Cm nodirect
76.Op Fl z Cm endfiltee
77.Op Fl z Cm fatal-warnings | Fl z Cm nofatal-warnings
78.Op Fl z Cm finiarray= Ns Ar function
79.Op Fl z Cm globalaudit
80.Op Fl z Cm groupperm | nogroupperm
81.Op Fl z Cm guidance Ns Op Cm \&= Ns Ar id Ns No \&,...
82.Op Fl z Cm help
83.Op Fl z Cm ignore | Fl z Cm record
84.Op Fl z Cm initarray= Ns Ar function
85.Op Fl z Cm initfirst
86.Op Fl z Cm interpose
87.Op Fl z Cm lazyload | Fl z Cm nolazyload
88.Op Fl z Cm ld32= Ns Ar arg Ns No \&,...
89.Op Fl z Cm ld64= Ns Ar arg Ns No \&,...
90.Op Fl z Cm loadfltr
91.Op Fl z Cm muldefs
92.Op Fl z Cm nocompstrtab
93.Op Fl z Cm nodefaultlib
94.Op Fl z Cm nodelete
95.Op Fl z Cm nodlopen
96.Op Fl z Cm nodump
97.Op Fl z Cm noldynsym
98.Op Fl z Cm nopartial
99.Op Fl z Cm noversion
100.Op Fl z Cm now
101.Op Fl z Cm origin
102.Op Fl z Cm preinitarray= Ns Ar function
103.Op Fl z Cm redlocsym
104.Op Fl z Cm relaxreloc
105.Op Fl z Cm rescan
106.Op Fl z Cm rescan-now
107.Op Fl z Cm rescan-start \&... Fl z Cm rescan-end
108.Op Fl z Cm symbolcap
109.Op Fl z Cm target= Ns Cm sparc Ns | Ns Cm x86
110.Op Fl z Cm text | Fl z Cm textwarn | Fl z Cm textoff
111.Sm off
112.Op Fl z\~ Cm type= Cm exec | kmod | reloc | shared
113.Sm on
114.Op Fl z Cm verbose
115.Op Fl z Cm wrap= Ns Ar symbol
116.Ar filename Ns No \&...
117.Sh DESCRIPTION
118The link-editor,
119.Nm ,
120combines relocatable object files by resolving symbol references to symbol
121definitions, together with performing relocations.
122.Nm
123operates in two modes, static or dynamic, as governed by the
124.Fl d
125option.
126In all cases, the output of
127.Nm
128is left in the file
129.Pa a.out
130by default.
131See
132.Sx NOTES .
133.Pp
134In dynamic mode,
135.Fl d Cm y ,
136the default, relocatable object files that are provided as arguments are
137combined to produce an executable object file.
138This file is linked at execution with any shared object files that are provided
139as arguments.
140If the
141.Fl G
142option is specified, relocatable object files are combined to produce a shared
143object.
144Without the
145.Fl G
146option, a dynamic executable is created.
147.Pp
148In static mode,
149.Fl d Cm n ,
150relocatable object files that are provided as arguments are combined to produce
151a static executable file.
152If the
153.Fl r
154option is specified, relocatable object files are combined to produce one
155relocatable object file.
156See
157.Sx Static Executables .
158.Pp
159Dynamic linking is the most common model for combining relocatable objects, and
160the eventual creation of processes within illumos.
161This environment tightly couples the work of the link-editor and the runtime
162linker,
163.Xr ld.so.1 1 .
164Both of these utilities, together with their related technologies and
165utilities, are extensively documented in the
166.%T Linker and Libraries Guide .
167.Pp
168If any argument is a library,
169.Nm
170by default searches the library exactly once at the point the library is
171encountered on the argument list.
172The library can be either a shared object or relocatable archive.
173See
174.Xr ar.h 3HEAD .
175.Pp
176A shared object consists of an indivisible, whole unit that has been generated
177by a previous link-edit of one or more input files.
178When the link-editor processes a shared object, the entire contents of the
179shared object become a logical part of the resulting output file image.
180The shared object is not physically copied during the link-edit as its actual
181inclusion is deferred until process execution.
182This logical inclusion means that all symbol entries defined in the shared
183object are made available to the link-editing process.
184See Chapter 4,
185.Em Shared Objects ,
186in
187.%T Linker and Libraries Guide .
188.Pp
189For an archive library,
190.Nm
191loads only those routines that define an unresolved external reference.
192.Nm
193searches the symbol table of the archive library sequentially to resolve
194external references that can be satisfied by library members.
195This search is repeated until no external references can be resolved by the
196archive.
197Thus, the order of members in the library is functionally unimportant, unless
198multiple library members exist that define the same external symbol.
199Archive libraries that have interdependencies can require multiple command line
200definitions, or the use of one of the
201.Fl z Cm rescan
202options.
203See
204.Em Archive Processing
205in
206.%T Linker and Libraries Guide .
207.Pp
208.Nm
209is a cross link-editor, able to link 32-bit objects or 64-bit objects, for
210Sparc or x86 targets.
211.Nm
212uses the
213.Sy ELF
214class and machine type of the first relocatable object on the command line to
215govern the mode in which to operate.
216The mixing of 32-bit objects and 64-bit objects is not permitted.
217Similarly, only objects of a single machine type are allowed.
218See the
219.Fl 32 ,
220.Fl 64
221and
222.Fl z Cm target
223options, and the
224.Ev LD_NOEXEC_64
225environment variable.
226.Ss Static Executables
227The creation of static executables is discouraged.
228Since a static executable is built against system archive libraries, the
229executable contains system implementation details.
230This self-containment has a number of drawbacks.
231.Bl -bullet -offset 4n
232.It
233The executable is immune to the benefits of system updates delivered as shared
234objects.
235The executable therefore, must be rebuilt to take advantage of many system
236improvements.
237.It
238The ability of the executable to run on future releases can be compromised.
239.It
240The duplication of system implementation details negatively affects system
241performance.
242.El
243.Pp
244On illumos, system archive libraries
245.Po
246such as
247.Pa libc.a
248.Pc
249have never been provided.
250Without these libraries, the creation of static executables is not achievable
251without specialized system knowledge.
252However, the capability of
253.Nm
254to process static linking options, and the processing of archive libraries,
255remains.
256.Sh OPTIONS
257The following options are supported.
258.Pp
259.Bl -tag -width 4n -compact
260.It Fl 32 | 64
261Creates a 32-bit, or 64-bit object.
262.Pp
263By default, the class of the object being generated is determined from the
264first
265.Sy ELF
266object processed from the command line.
267If no objects are specified, the class is determined by the first object
268encountered within the first archive processed from the command line.
269If there are no objects or archives, the link-editor creates a 32-bit object.
270.Pp
271The
272.Fl 64
273option is required to create a 64-bit object solely from a mapfile.
274.Pp
275The
276.Fl 32
277or
278.Fl 64
279options can also be used in the rare case of linking entirely from an archive
280that contains a mixture of 32 and 64-bit objects.
281If the first object in the archive is not the class of the object that is
282required to be created, then the
283.Fl 32
284or
285.Fl 64
286option can be used to direct the link-editor.
287See
288.Em The 32-bit link-editor and 64-bit link-editor
289in
290.%T Linker and Libraries Guide .
291.Pp
292Note that for compatibility with existing Makefiles and scripts, these options
293may be given multiple times and may be mixed in the same invocation: the last
294instance wins, so that, for example,
295.Ql ld -64 -32 -64 \&...
296gives 64-bit output.
297.Pp
298.It Fl a
299In static mode only, produces an executable object file.
300Undefined references are not permitted.
301This option is the default behavior for static mode.
302The
303.Fl a
304option can not be used with the
305.Fl r
306option.
307See
308.Sx Static Executables
309.Pp
310.It Fl b
311In dynamic mode only, provides no special processing for dynamic executable
312relocations that reference symbols in shared objects.
313Without the
314.Fl b
315option, the link-editor applies techniques within a dynamic executable so that
316the text segment can remain read-only.
317One technique is the creation of special position-independent relocations for
318references to functions that are defined in shared objects.
319Another technique arranges for data objects that are defined in shared objects
320to be copied into the memory image of an executable at runtime.
321.Pp
322The
323.Fl b
324option is intended for specialized dynamic objects and is not recommended for
325general use.
326Its use suppresses all specialized processing required to ensure an object's
327shareability, and can even prevent the relocation of 64-bit executables.
328.Pp
329.It Fl B Cm direct | Fl B Cm nodirect
330These options govern direct binding.
331.Fl B Cm direct
332establishes direct binding information by recording the relationship between
333each symbol reference together with the dependency that provides the
334definition.
335In addition, direct binding information is established between each symbol
336reference and an associated definition within the object being created.
337The runtime linker uses this information to search directly for a symbol in the
338associated object rather than to carry out a default symbol search.
339.Pp
340Direct binding information can only be established to dependencies specified
341with the link-edit.
342Thus, you should use the
343.Fl z Cm defs
344option.
345Objects that wish to interpose on symbols in a direct binding environment
346should identify themselves as interposers with the
347.Fl z Cm interpose
348option.
349The use of
350.Fl B Cm direct
351enables
352.Fl z Cm lazyload
353for all dependencies.
354.Pp
355The
356.Fl B Cm nodirect
357option prevents any direct binding to the interfaces offered by the object
358being created.
359The object being created can continue to directly bind to external interfaces
360by specifying the
361.Fl z Cm direct
362option.
363See Appendix D,
364.Em Direct Bindings ,
365in
366.%T Linker and Libraries Guide .
367.Pp
368.It Fl B Cm dynamic | Fl B Cm static
369Options governing library inclusion.
370.Fl B Cm dynamic
371is valid in dynamic mode only.
372These options can be specified any number of times on the command line as
373toggles: if the
374.Fl B Cm static
375option is given, no shared objects are accepted until
376.Fl B Cm dynamic
377is seen.
378See the
379.Fl l
380option.
381.Pp
382.It Fl B Cm eliminate
383Causes any global symbols, not assigned to a version definition, to be
384eliminated from the symbol table.
385Version definitions can be supplied by means of a
386.Sy mapfile
387to indicate the global symbols that should remain visible in the generated
388object.
389This option achieves the same symbol elimination as the
390.Em auto-elimination
391directive that is available as part of a mapfile version definition.
392This option can be useful when combining versioned and non-versioned
393relocatable objects.
394See also the
395.Fl B Cm local
396and
397.Fl B Cm reduce
398options.
399See
400.Em Defining Additional Symbols with a mapfile
401in
402.%T Linker and Libraries Guide .
403.Pp
404.It Fl B Cm group
405Establishes a shared object and its dependencies as a group.
406Objects within the group are bound to other members of the group at runtime.
407This mode is similar to adding the object to the process by using
408.Xr dlopen 3C
409with the
410.Dv RTLD_GROUP
411mode.
412An object that has an explicit dependency on a object identified as a group,
413becomes a member of the group.
414.Pp
415As the group must be self contained, use of the
416.Fl B Cm group
417option also asserts the
418.Fl z Cm defs
419option.
420.Pp
421.It Fl B Cm local
422Causes any global symbols, not assigned to a version definition, to be reduced
423to local.
424Version definitions can be supplied by means of a
425.Sy mapfile
426to indicate the global symbols that should remain visible in the generated
427object.
428This option achieves the same symbol reduction as the
429.Ar auto-reduction
430directive that is available as part of a mapfile version definition.
431This option can be useful when combining versioned and non-versioned
432relocatable objects.
433See also the
434.Fl B Cm eliminate
435and
436.Fl B Cm reduce
437options.
438See
439.Em Defining Additional Symbols with a mapfile
440in
441.%T Linker and Libraries Guide .
442.Pp
443.It Fl B Cm reduce
444When generating a relocatable object, causes the reduction of symbolic
445information defined by any version definitions.
446Version definitions can be supplied by means of a
447.Sy mapfile
448to indicate the global symbols that should remain visible in the generated
449object.
450By default, when a relocatable object is generated, version definitions are
451only recorded in the output image.
452The actual reduction of symbolic information is carried out when the object is
453used in the construction of a dynamic executable or shared object.
454The
455.Fl B Cm reduce
456option is applied automatically when a dynamic executable or shared object is
457created.
458.Pp
459.It Fl B Cm symbolic
460In dynamic mode only.
461When building a shared object, binds references to global symbols to their
462definitions, if available, within the object.
463Normally, references to global symbols within shared objects are not bound
464until runtime, even if definitions are available.
465This model allows definitions of the same symbol in an executable or other
466shared object to override the object's own definition.
467.Nm
468issues warnings for undefined symbols unless
469.Fl z Cm defs
470overrides.
471.Pp
472The
473.Fl B Cm symbolic
474option is intended for specialized dynamic objects and is not recommended for
475general use.
476To reduce the runtime relocation processing that is required an object, the
477creation of a version definition is recommended.
478.Fl c Ar name
479records the configuration file
480.Ar name
481for use at runtime.
482Configuration files can be employed to alter default search paths, provide a
483directory cache, together with providing alternative object dependencies.
484See
485.Xr crle 1 .
486.Pp
487.It Fl C
488Demangles C++ symbol names displayed in diagnostic messages.
489.Pp
490.It Fl d Cm y | Fl d Cm n
491When
492.Fl d Cm y ,
493the default, is specified,
494.Nm
495uses dynamic linking.
496When
497.Fl d Cm n
498is specified,
499.Nm
500uses static linking.
501See
502.Sx Static Executables
503and
504.Fl B Cm dynamic | Fl B Cm static .
505.Pp
506.It Fl D Ar token Ns \&,...
507Prints debugging information as specified by each
508.Ar token
509to the standard error.
510The special token
511.Cm help
512indicates the full list of tokens available.
513See
514.Em Debugging Aids
515in
516.%T Linker and Libraries Guide .
517.Pp
518.It Fl e Ar epsym
519.It Fl \&-entry Ar epsym
520Sets the entry point address for the output file to be the symbol
521.Ar epsym .
522.Pp
523.It Fl f Ar name
524.It Fl \&-auxiliary Ar name
525Useful only when building a shared object.
526Specifies that the symbol table of the shared object is used as an auxiliary
527filter on the symbol table of the shared object specified by
528.Ar name .
529Multiple instances of this option are allowed.
530This option can not be combined with the
531.Fl F
532option.
533See
534.Em Generating Auxiliary Filters
535in
536.%T Linker and Libraries Guide .
537.Pp
538.It Fl F Ar name
539.It Fl \&-filter Ar name
540Useful only when building a shared object.
541Specifies that the symbol table of the shared object is used as a filter on the
542symbol table of the shared object specified by
543.Ar name .
544Multiple instances of this option are allowed.
545This option cannot be combined with the
546.Fl f
547option.
548See
549.Em Generating Standard Filters
550in
551.%T Linker and Libraries Guide .
552.Pp
553.It Fl G
554.It Fl shared
555In dynamic mode only, produces a shared object.
556Undefined symbols are allowed.
557See Chapter 4,
558.Em Shared Objects ,
559in
560.%T Linker and Libraries Guide .
561.Pp
562.It Fl h Ar name
563.It Fl soname Ar name
564In dynamic mode only, when building a shared object, records
565.Ar name
566in the object's dynamic section.
567.Ar name
568is recorded in any dynamic objects that are linked with this object rather than
569the object's file system name.
570Accordingly,
571.Ar name
572is used by the runtime linker as the name of the shared object to search for at
573runtime.
574See
575.Em Recording a Shared Object Name
576in
577.%T Linker and Libraries Guide .
578.Pp
579.It Fl i
580Ignores
581.Ev LD_LIBRARY_PATH .
582This option is useful when an
583.Ev LD_LIBRARY_PATH
584setting is in effect to influence the runtime library search, which would
585interfere with the link-editing being performed.
586.Pp
587.It Fl I Ar name
588.It Fl \&-dynamic-linker Ar name
589When building an executable, uses
590.Ar name
591as the path name of the interpreter to be written into the program header.
592The default in static mode is no interpreter.
593In dynamic mode, the default is the name of the runtime linker,
594.Xr ld.so.1 1 .
595Either case can be overridden by
596.Fl I Ar name .
597.Xr exec 2
598loads this interpreter when the
599.Pa a.out
600is loaded, and passes control to the interpreter rather than to the
601.Pa a.out
602directly.
603.Pp
604.It Fl l Ar x
605.It Fl \&-library Ar x
606Searches a library
607.Sy lib Ns Ar x Ns Sy .so
608or
609.Sy lib Ns Ar x Ns Sy .a ,
610the conventional names for shared object and archive libraries, respectively.
611In dynamic mode, unless the
612.Fl B Cm static
613option is in effect,
614.Nm
615searches each directory specified in the library search path for a
616.Sy lib Ns Ar x Ns Sy .so
617or
618.Sy lib Ns Ar x Ns Sy \&.a .
619The directory search stops at the first directory containing either.
620.Nm
621chooses the file ending in
622.Sy .so
623if
624.Fl l Ar x
625expands to two files with names of the form
626.Sy lib Ns Ar x Ns Sy .so
627and
628.Sy lib Ns Ar x Ns Sy .a .
629If no
630.Sy lib Ns Ar x Ns Sy .so
631is found, then
632.Nm
633accepts
634.Sy lib Ns Ar x Ns Sy .a .
635In static mode, or when the
636.Fl B Cm static
637option is in effect,
638.Nm
639selects only the file ending in
640.Sy .a .
641.Nm
642searches a library when the library is encountered, so the placement of
643.Fl l
644is significant.
645See
646.Em Linking With Additional Libraries
647in
648.%T Linker and Libraries Guide .
649.Pp
650.It Fl L Ar path
651.It Fl \&-library-path Ar path
652Adds
653.Ar path
654to the library search directories.
655.Nm
656searches for libraries first in any directories specified by the
657.Fl L
658options and then in the standard directories.
659This option is useful only if the option precedes the
660.Fl l
661options to which the
662.Fl L
663option applies.
664See
665.Em Directories Searched by the Link-Editor
666in
667.%T Linker and Libraries Guide .
668.Pp
669The environment variable
670.Ev LD_LIBRARY_PATH
671can be used to supplement the library search path, however the
672.Fl L
673option is recommended, as the environment variable is also interpreted by the
674runtime environment.
675See
676.Ev LD_LIBRARY_PATH
677under
678.Sx ENVIRONMENT .
679.Pp
680.It Fl m
681Produces a memory map or listing of the input/output sections, together with
682any non-fatal multiply-defined symbols, on the standard output.
683.Pp
684.It Fl M Ar mapfile
685Reads
686.Ar mapfile
687as a text file of directives to
688.Nm .
689This option can be specified multiple times.
690If
691.Ar mapfile
692is a directory, then all regular files, as defined by
693.Xr stat 2 ,
694within the directory are processed.
695See Chapter 9,
696.Em Mapfile Option ,
697in
698.%T Linker and Libraries Guide .
699Example mapfiles are provided in
700.Pa /usr/lib/ld .
701See
702.Sx FILES .
703.Pp
704.It Fl N Ar string
705This option causes a
706.Dv DT_NEEDED
707entry to be added to the
708.Sy .dynamic
709section of the object being built.
710The value of the
711.Dv DT_NEEDED
712string is the
713.Ar string
714that is specified on the command line.
715This option is position dependent, and the
716.Dv DT_NEEDED
717.Sy .dynamic
718entry is relative to the other dynamic dependencies discovered on the link-edit
719line.
720This option is useful for specifying dependencies within device driver
721relocatable objects when combined with the
722.Fl d Cm y
723and
724.Fl r
725options.
726.Pp
727.It Fl o Ar outfile
728.It Fl \&-output Ar outfile
729Produces an output object file that is named
730.Ar outfile .
731The name of the default object file is
732.Pa a.out .
733.Pp
734.It Fl p Ar auditlib
735Identifies an audit library,
736.Ar auditlib .
737This audit library is used to audit the object being created at runtime.
738A shared object identified as requiring auditing with the
739.Fl p
740option, has this requirement inherited by any object that specifies the shared
741object as a dependency.
742See the
743.Fl P
744option.
745See
746.Em Runtime Linker Auditing Interface
747in
748.%T Linker and Libraries Guide .
749.Pp
750.It Fl P Ar auditlib
751Identifies an audit library,
752.Ar auditlib .
753This audit library is used to audit the dependencies of the object being
754created at runtime.
755Dependency auditing can also be inherited from dependencies that are identified
756as requiring auditing.
757See the
758.Fl p
759and
760.Fl z Cm globalaudit
761options.
762See
763.Em Runtime Linker Auditing Interface
764in
765.%T Linker and Libraries Guide .
766.Pp
767.It Fl Q Cm y | Fl Q Cm n
768Under
769.Fl Q Cm y ,
770an
771.Sy ident
772string is added to the
773.Sy .comment
774section of the output file.
775This string identifies the version of the
776.Nm
777used to create the file.
778This results in multiple
779.Nm
780idents when there have been multiple linking steps, such as when using
781.Nm Fl r .
782This identification is identical with the default action of the
783.Xr cc 1
784command.
785.Fl Q Cm n
786suppresses version identification.
787.Sy .comment
788sections can be manipulated by the
789.Xr mcs 1
790utility.
791.Pp
792.It Fl r
793.It Fl \&-relocatable
794Combines relocatable object files to produce one relocatable object file.
795.Nm
796does not complain about unresolved references.
797This option cannot be used with the
798.Fl a
799option.
800.Pp
801.It Fl R Ar path
802.It Fl rpath Ar path
803A colon-separated list of directories used to specify library search
804directories to the runtime linker.
805If present and not NULL, the path is recorded in the output object file and
806passed to the runtime linker.
807Multiple instances of this option are concatenated together with each
808.Ar path
809separated by a colon.
810See
811.Em Directories Searched by the Runtime Linker
812in
813.%T Linker and Libraries Guide .
814.Pp
815The use of a runpath within an associated object is preferable to setting
816global search paths such as through the
817.Ev LD_LIBRARY_PATH
818environment variable.
819Only the runpaths that are necessary to find the objects dependencies should be
820recorded.
821.Xr ldd 1
822can also be used to discover unused runpaths in dynamic objects, when used with
823the
824.Fl U
825option.
826.Pp
827Various tokens can also be supplied with a runpath that provide a flexible
828means of identifying system capabilities or an objects location.
829See Appendix C,
830.Em Establishing Dependencies with Dynamic String Tokens ,
831in
832.%T Linker and Libraries Guide .
833The
834.Sy $ORIGIN
835token is especially useful in allowing dynamic objects to be relocated to
836different locations in the file system.
837.Pp
838.It Fl s
839.It Fl \&-strip-all
840Strips symbolic information from the output file.
841Any debugging information,
842that is,
843.Sy .line ,
844.Sy .debug* ,
845and
846.Sy .stab*
847sections, and their associated relocation entries are removed.
848Except for relocatable files, a symbol table
849.Dv SHT_SYMTAB
850and its associated string table section are not created in the output object
851file.
852The elimination of a
853.Dv SHT_SYMTAB
854symbol table can reduce the .stab* debugging information that is generated
855using the compiler driver's
856.Fl g
857option.
858See the
859.Fl z Cm redlocsym
860and
861.Fl z Cm noldynsym
862options.
863.Pp
864.It Fl S Ar supportlib
865The shared object
866.Ar supportlib
867is loaded with
868.Nm
869and given information regarding the linking process.
870Shared objects that are defined by using the
871.Fl S
872option can also be supplied using the
873.Ev SGS_SUPPORT
874environment variable.
875See
876.Em Link-Editor Support Interface
877in
878.%T Linker and Libraries Guide .
879.Pp
880.It Fl t
881Turns off the warning for multiply-defined symbols that have different sizes or
882different alignments.
883.Pp
884.It Fl u Ar symname
885.It Fl \&-undefined Ar symname
886Enters
887.Ar symname
888as an undefined symbol in the symbol table.
889This option is useful for loading entirely from an archive library.
890In this instance, an unresolved reference is needed to force the loading of the
891first routine.
892The placement of this option on the command line is significant.
893This option must be placed before the library that defines the symbol.
894See
895.Em Defining Additional Symbols with the u option
896in
897.%T Linker and Libraries Guide .
898.Pp
899.It Fl V
900.It Fl \&-version
901Outputs a message giving information about the version of
902.Nm
903being used.
904.Pp
905.It Fl Y Cm P\&, Ns Ar dirlist
906Changes the default directories used for finding libraries.
907.Ar dirlist
908is a colon-separated path list.
909.Pp
910.It Fl z Cm absexec
911Useful only when building a dynamic executable.
912Specifies that references to external absolute symbols should be resolved
913immediately instead of being left for resolution at runtime.
914In very specialized circumstances, this option removes text relocations that
915can result in excessive swap space demands by an executable.
916.Pp
917.It Fl z Cm allextract | Fl z Cm defaultextract | Fl z Cm weakextract
918.It Fl \&-whole-archive | \&-no-whole-archive
919Alters the extraction criteria of objects from any archives that follow.
920By default, archive members are extracted to satisfy undefined references and
921to promote tentative definitions with data definitions.
922Weak symbol references do not trigger extraction.
923Under the
924.Fl z Cm allextract
925or
926.Fl \&-whole-archive
927options, all archive members are extracted from the archive.
928Under
929.Fl z Cm weakextract ,
930weak references trigger archive extraction.
931The
932.Fl z Cm defaultextract
933or
934.Fl \&-no-whole-archive
935options provide a means of returning to the default following use of the former
936extract options.
937See
938.Em Archive Processing
939in
940.%T Linker and Libraries Guide .
941.Pp
942.It Fl z Cm altexec64
943Execute the 64-bit
944.Nm .
945The creation of very large 32-bit objects can exhaust the virtual memory that
946is available to the 32-bit
947.Nm .
948The
949.Fl z Cm altexec64
950option can be used to force the use of the associated 64-bit
951.Nm .
952The 64-bit
953.Nm
954provides a larger virtual address space for building 32-bit objects.
955See
956.Em The 32-bit link-editor and 64-bit link-editor
957in
958.%T Linker and Libraries Guide .
959.Pp
960.It Fl z Cm aslr Ns Op Cm \&= Ns Ar state
961Specify whether the executable's address space should be randomized on
962execution.
963If
964.Ar state
965is
966.Cm enabled ,
967randomization will always occur when this executable is run
968.Pq regardless of inherited settings .
969If
970.Ar state
971is
972.Cm disabled ,
973randomization will never occur when this executable is run.
974If
975.Ar state
976is omitted, ASLR is enabled.
977An executable that should simply use the settings inherited from its
978environment should not use this flag at all.
979.Pp
980.It Fl z Cm combreloc | Fl z Cm nocombreloc
981By default,
982.Nm
983combines multiple relocation sections when building executables or shared
984objects.
985This section combination differs from relocatable objects, in which relocation
986sections are maintained in a one-to-one relationship with the sections to which
987the relocations must be applied.
988The
989.Fl z Cm nocombreloc
990option disables this merging of relocation sections, and preserves the
991one-to-one relationship found in the original relocatable objects.
992.Pp
993.Nm
994sorts the entries of data relocation sections by their symbol reference.
995This sorting reduces runtime symbol lookup.
996When multiple relocation sections are combined, this sorting produces the least
997possible relocation overhead when objects are loaded into memory, and speeds
998the runtime loading of dynamic objects.
999.Pp
1000Historically, the individual relocation sections were carried over to any
1001executable or shared object, and the
1002.Fl z Cm combreloc
1003option was required to enable the relocation section merging previously
1004described.
1005Relocation section merging is now the default.
1006The
1007.Fl z Cm combreloc
1008option is still accepted for the benefit of old build environments, but the
1009option is unnecessary, and has no effect.
1010.Pp
1011.It Fl z Cm assert-deflib
1012.It Fl z Cm assert-deflib= Ns Ar libname
1013Enables warnings that check the location of where libraries passed in with
1014.Fl l
1015are found.
1016If the link-editor finds a library on its default search path it will emit a
1017warning.
1018This warning can be made fatal in conjunction with the option
1019.Fl z Cm fatal-warnings .
1020Passing
1021.Ar libname
1022white lists a library from this check.
1023The library must be the full name of the library, e.g.
1024.Pa libc.so .
1025To white list multiple libraries, the
1026.Fl z Cm assert-deflib= Ns Ar libname
1027option can be repeated multiple times.
1028This option is useful when trying to build self-contained objects where a
1029referenced library might exist in the default system library path and in
1030alternate paths specified by
1031.Fl L ,
1032but you only want the alternate paths to be used.
1033.Pp
1034.It Fl z Cm defs | Fl z Cm nodefs
1035.It Fl \&-no-undefined
1036The
1037.Fl z Cm defs
1038option and the
1039.Fl \&-no-undefined
1040option force a fatal error if any undefined symbols remain at the end of the
1041link.
1042This mode is the default when an executable is built.
1043For historic reasons, this mode is
1044.Em not
1045the default when building a shared object.
1046Use of the
1047.Fl z Cm defs
1048option is recommended, as this mode assures the object being built is
1049self-contained.
1050A self-contained object has all symbolic references resolved internally, or to
1051the object's immediate dependencies.
1052.Pp
1053The
1054.Fl z Cm nodefs
1055option allows undefined symbols.
1056For historic reasons, this mode is the default when a shared object is built.
1057When used with executables, the behavior of references to such undefined
1058symbols is unspecified.
1059Use of the
1060.Fl z Cm nodefs
1061option is not recommended.
1062.Pp
1063.It Fl z Cm direct | Fl z Cm nodirect
1064Enables or disables direct binding to any dependencies that follow on the
1065command line.
1066These options allow finer control over direct binding than the global
1067counterpart
1068.Fl B Cm direct .
1069The
1070.Fl z Cm direct
1071option also differs from the
1072.Fl B Cm direct
1073option in the following areas.
1074Direct binding information is not established between a symbol reference and an
1075associated definition within the object being created.
1076Lazy loading is not enabled.
1077.Pp
1078.It Fl z Cm endfiltee
1079Marks a filtee so that when processed by a filter, the filtee terminates any
1080further filtee searches by the filter.
1081See
1082.Em Reducing Filtee Searches
1083in
1084.%T Linker and Libraries Guide .
1085.Pp
1086.It Fl z Cm fatal-warnings | Fl z Cm nofatal-warnings
1087.It Fl \&-fatal-warnings | \&-no-fatal-warnings
1088Controls the behavior of warnings emitted from the link-editor.
1089Setting
1090.Fl z Cm fatal-warnings
1091promotes warnings emitted by the link-editor to fatal errors that will cause
1092the link-editor to fail before linking.
1093.Fl z Cm nofatal-warnings
1094instead demotes these warnings such that they will not cause the link-editor to
1095exit prematurely.
1096.Pp
1097.It Fl z Cm finiarray= Ns Ar function
1098Appends an entry to the
1099.Sy .fini_array
1100section of the object being built.
1101If no
1102.Sy .fini_array
1103section is present, a section is created.
1104The new entry is initialized to point to
1105.Ar function .
1106See
1107.Em Initialization and Termination Sections
1108in
1109.%T Linker and Libraries Guide .
1110.Pp
1111.It Fl z Cm globalaudit
1112This option supplements an audit library definition that has been recorded with
1113the
1114.Fl P
1115option.
1116This option is only meaningful when building a dynamic executable.
1117Audit libraries that are defined within an object with the
1118.Fl P
1119option typically allow for the auditing of the immediate dependencies of the
1120object.
1121The
1122.Fl z Cm globalaudit
1123promotes the auditor to a global auditor, thus allowing the auditing of all
1124dependencies.
1125See
1126.Em Invoking the Auditing Interface
1127in
1128.%T Linker and Libraries Guide .
1129.Pp
1130An auditor established with the
1131.Fl P
1132option and the
1133.Fl z Cm globalaudit
1134option, is equivalent to the auditor being established with the
1135.Ev LD_AUDIT
1136environment variable.
1137See
1138.Xr ld.so.1 1 .
1139.Pp
1140.It Fl z Cm groupperm | Fl z Cm nogroupperm
1141Assigns, or deassigns each dependency that follows to a unique group.
1142The assignment of a dependency to a group has the same effect as if the
1143dependency had been built using the
1144.Fl B Cm group
1145option.
1146.Pp
1147.It Fl z Cm guidance Ns Op Cm \&= Ns Ar id Ns No ,...
1148Give messages suggesting link-editor features that could improve the resulting
1149dynamic object.
1150Specific classes of suggestion can be silenced by specifying an optional comma
1151separated list of guidance identifiers.
1152The current classes of suggestion provided are:
1153.Bl -tag -width 4n
1154.It Enable use of direct binding
1155Suggests that
1156.Fl z Cm direct
1157or
1158.Fl B Cm direct
1159be present prior to any specified dependency.
1160This allows predictable symbol binding at runtime.
1161Can be disabled with
1162.Fl z Cm guidance=nodirect
1163.It Enable lazy dependency loading
1164Suggests that
1165.Fl z Cm lazyload
1166be present prior to any specified dependency.
1167This allows the dynamic object to be loaded more quickly.
1168Can be disabled with
1169.Fl z Cm guidance=nolazyload
1170.It Shared objects should define all their dependencies.
1171Suggests that
1172.Fl z Cm defs
1173be specified on the link-editor command line.
1174Shared objects that explicitly state all their dependencies behave more
1175predictably when used.
1176Can be be disabled with
1177.Fl z Cm guidance=nodefs
1178.It Version 2 mapfile syntax
1179Suggests that any specified mapfiles use the more readable version 2 syntax.
1180Can be disabled with
1181.Fl z Cm guidance=nomapfile
1182.It Read-only text segment
1183Should any runtime relocations within the text segment exist, suggests that
1184the object be compiled with position independent code
1185.Pq PIC .
1186Keeping large allocatable sections read-only allows them to be shared between
1187processes using a given shared object.
1188Can be disabled with
1189.Fl z Cm guidance=notext
1190.It No unused dependencies
1191Suggests that any dependency not referenced by the resulting dynamic object be
1192removed from the link-editor command line.
1193Can be disabled with
1194.Fl z Cm guidance=nounused
1195.It Global data in shared libraries built with mapfiles have size assertions
1196Suggests that any global data in a library built with a mapfile asserts the
1197size of that global data for ABI stability purposes.
1198Can be disabled with
1199.Fl z Cm guidance=noasserts
1200.El
1201.Pp
1202.It Fl z Cm help
1203.It Fl \&-help
1204Print a summary of the command line options on the standard output and exit.
1205.Pp
1206.It Fl z Cm ignore | Fl z Cm record
1207Ignores, or records, dynamic dependencies that are not referenced as part of
1208the link-edit.
1209Ignores, or records, unreferenced
1210.Sy ELF
1211sections from the relocatable objects
1212that are read as part of the link-edit.
1213By default,
1214.Fl z Cm record
1215is in effect.
1216.Pp
1217If an
1218.Sy ELF
1219section is ignored, the section is eliminated from the output file being
1220generated.
1221A section is ignored when three conditions are true.
1222The eliminated section must contribute to an allocatable segment.
1223The eliminated section must provide no global symbols.
1224No other section from any object that contributes to the link-edit, must
1225reference an eliminated section.
1226.Pp
1227.It Fl z Cm initarray= Ns Ar function
1228Appends an entry to the
1229.Sy .init_array
1230section of the object being built.
1231If no
1232.Sy .init_array
1233section is present, a section is created.
1234The new entry is initialized to point to
1235.Ar function .
1236See
1237.Em Initialization and Termination Sections
1238in
1239.%T Linker and Libraries Guide .
1240.Pp
1241.It Fl z Cm initfirst
1242Marks the object so that its runtime initialization occurs before the runtime
1243initialization of any other objects brought into the process at the same time.
1244In addition, the object runtime finalization occurs after the runtime
1245finalization of any other objects removed from the process at the same time.
1246This option is only meaningful when building a shared object.
1247.Pp
1248.It Fl z Cm interpose
1249Marks the object as an interposer.
1250At runtime, an object is identified as an explicit interposer if the object has
1251been tagged using the
1252.Fl z Cm interpose
1253option.
1254An explicit interposer is also established when an object is loaded using the
1255.Ev LD_PRELOAD
1256environment variable.
1257Implicit interposition can occur because of the load order of objects, however,
1258this implicit interposition is unknown to the runtime linker.
1259Explicit interposition can ensure that interposition takes place regardless of
1260the order in which objects are loaded.
1261Explicit interposition also ensures that the runtime linker searches for
1262symbols in any explicit interposers when direct bindings are in effect.
1263.Pp
1264.It Fl z Cm lazyload | Fl z Cm nolazyload
1265Enables or disables the marking of dynamic dependencies to be lazily loaded.
1266Dynamic dependencies which are marked
1267Cm lazyload
1268are not loaded at initial process start-up.
1269These dependencies are delayed until the first binding to the object is made.
1270Note: Lazy loading requires the correct declaration of dependencies, together
1271with associated runpaths for each dynamic object used within a process.
1272See
1273.Em Lazy Loading of Dynamic Dependencies
1274in
1275.%T Linker and Libraries Guide .
1276.Pp
1277.It Fl z Cm ld32= Ns Ar arg Ns No ,...
1278.It Fl z Cm ld64= Ns Ar arg Ns No ,...
1279The class of the link-editor is affected by the class of the output file being
1280created and by the capabilities of the underlying operating system.
1281The
1282.Fl z Cm ld32 | Fl z Cm ld64
1283options provide a means of defining any link-editor argument.
1284The defined argument is only interpreted, respectively, by the 32-bit class or
128564-bit class of the link-editor.
1286.Pp
1287For example, support libraries are class specific, so the correct class of
1288support library can be ensured using:
1289.Pp
1290.Dl ld ... -z ld32=-Saudit32.so.1 -z ld64=-Saudit64.so.1 ...
1291.Pp
1292The class of link-editor that is invoked is determined from the
1293.Sy ELF
1294class of the first relocatable file that is seen on the command line.
1295This determination is carried out
1296.Em prior
1297to any
1298.Fl z Cm ld32 | Fl z Cm ld64
1299processing.
1300.Pp
1301.It Fl z Cm loadfltr
1302Marks a filter to indicate that filtees must be processed immediately at
1303runtime.
1304Normally, filter processing is delayed until a symbol reference is bound to the
1305filter.
1306The runtime processing of an object that contains this flag mimics that which
1307occurs if the
1308.Ev LD_LOADFLTR
1309environment variable is in effect.
1310See the
1311.Xr ld.so.1 1 .
1312.Pp
1313.It Fl z Cm muldefs
1314.It Fl \&-allow-multiple-definition
1315Allows multiple symbol definitions.
1316By default, multiple symbol definitions that occur between relocatable objects
1317result in a fatal error condition.
1318This option, suppresses the error condition, allowing the first symbol
1319definition to be taken.
1320.Pp
1321.It Fl z Cm nocompstrtab
1322Disables the compression of
1323.Sy ELF
1324string tables.
1325By default, string compression is applied to
1326.Dv SHT_STRTAB
1327sections, and to
1328.Dv SHT_PROGBITS
1329sections that have their
1330.Dv SHF_MERGE
1331and
1332.Dv SHF_STRINGS
1333section flags set.
1334.Pp
1335.It Fl z Cm nodefaultlib
1336Marks the object so that the runtime default library search path, used after
1337any
1338.Ev LD_LIBRARY_PATH
1339or runpaths, is ignored.
1340This option implies that all dependencies of the object can be satisfied from
1341its runpath.
1342.Pp
1343.It Fl z Cm nodelete
1344Marks the object as non-deletable at runtime.
1345This mode is similar to adding the object to the process by using
1346.Xr dlopen 3C
1347with the
1348.Dv RTLD_NODELETE
1349mode.
1350.Pp
1351.It Fl z Cm nodlopen
1352Marks the object as not available to
1353.Xr dlopen 3C ,
1354either as the object specified by the
1355.Xr dlopen 3C ,
1356or as any form of dependency required by the object specified by the
1357.Xr dlopen 3C .
1358This option is only meaningful when building a shared object.
1359.Pp
1360.It Fl z Cm nodump
1361Marks the object as not available to
1362.Xr dldump 3C .
1363.Pp
1364.It Fl z Cm noldynsym
1365Prevents the inclusion of a
1366.Sy .SUNW_ldynsym
1367section in dynamic executables or sharable libraries.
1368The
1369.Sy .SUNW_ldynsym
1370section augments the
1371.Sy .dynsym
1372section by providing symbols for local functions.
1373Local function symbols allow debuggers to display local function names in stack
1374traces from stripped programs.
1375Similarly,
1376.Xr dladdr 3C
1377is able to supply more accurate results.
1378.Pp
1379The
1380.Fl z Cm noldynsym
1381option also prevents the inclusion of the two symbol sort sections that are
1382related to the
1383.Sy .SUNW_ldynsym
1384section.
1385The
1386.Sy .SUNW_dynsymsort
1387section provides sorted access to regular function and variable symbols.
1388The
1389.Sy .SUNW_dyntlssort
1390section provides sorted access to thread local storage
1391.Pq TLS
1392variable symbols.
1393.Pp
1394The
1395.Sy .SUNW_ldynsym ,
1396.Sy .SUNW_dynsymsort ,
1397and
1398.Sy .SUNW_dyntlssort
1399sections, which becomes part of the allocable text segment of the resulting
1400file, cannot be removed by
1401.Xr strip 1 .
1402Therefore, the
1403.Fl z Cm noldynsym
1404option is the only way to prevent their inclusion.
1405See the
1406.Fl s
1407and
1408.Fl z Cm redlocsym
1409options.
1410.Pp
1411.It Fl z Cm nopartial
1412Partially initialized symbols, that are defined within relocatable object
1413files, are expanded in the output file being generated.
1414.Pp
1415.It Fl z Cm noversion
1416Does not record any versioning sections.
1417Any version sections or associated
1418.Sy .dynamic
1419section entries are not generated in the output image.
1420.Pp
1421.It Fl z Cm now
1422Marks the object as requiring non-lazy runtime binding.
1423This mode is similar to adding the object to the process by using
1424.Xr dlopen 3C
1425with the
1426.Dv RTLD_NOW
1427mode.
1428This mode is also similar to having the
1429.Ev LD_BIND_NOW
1430environment variable in effect.
1431See
1432.Xr ld.so.1 1 .
1433.Pp
1434.It Fl z Cm origin
1435Marks the object as requiring immediate
1436.Sy $ORIGIN
1437processing at runtime.
1438This option is only maintained for historic compatibility, as the runtime
1439analysis of objects to provide for
1440.Sy $ORIGIN
1441processing is now default.
1442.Pp
1443.It Fl z Cm preinitarray= Ns Ar function
1444Appends an entry to the
1445.Sy .preinitarray
1446section of the object being built.
1447If no
1448.Sy .preinitarray
1449section is present, a section is created.
1450The new entry is initialized to point to
1451.Ar function .
1452See
1453.Em Initialization and Termination Sections
1454in
1455.%T Linker and Libraries Guide .
1456.Pp
1457.It Fl z Cm redlocsym
1458Eliminates all local symbols except for the
1459.Sy SECT
1460symbols from the symbol
1461table
1462.Dv SHT_SYMTAB .
1463All relocations that refer to local symbols are updated to refer to the
1464corresponding
1465.Sy SECT
1466symbol.
1467This option allows specialized objects to greatly reduce their symbol table
1468sizes.
1469Eliminated local symbols can reduce the
1470.Sy .stab
1471debugging information that is generated using the compiler driver's
1472.Fl g
1473option.
1474See the
1475.Fl s
1476and
1477.Fl z Cm noldynsym
1478options.
1479.Pp
1480.It Fl z Cm relaxreloc
1481.Nm
1482normally issues a fatal error upon encountering a relocation using a
1483symbol that references an eliminated COMDAT section.
1484If
1485.Fl z Cm relaxreloc
1486is enabled,
1487.Nm
1488instead redirects such relocations to the equivalent symbol in the COMDAT
1489section that was kept.
1490.Fl z Cm relaxreloc
1491is a specialized option, mainly of interest to compiler authors, and is not
1492intended for general use.
1493.Pp
1494.It Fl z Cm rescan-now
1495.It Fl z Cm rescan
1496These options rescan the archive files that are provided to the link-edit.
1497By default, archives are processed once as the archives appear on the command
1498line.
1499Archives are traditionally specified at the end of the command line so that
1500their symbol definitions resolve any preceding references.
1501However, specifying archives multiple times to satisfy their own
1502interdependencies can be necessary.
1503.Pp
1504.Fl z Cm rescan-now
1505is a positional option, and is processed by the link-editor immediately when
1506encountered on the command line.
1507All archives seen on the command line up to that point are immediately
1508reprocessed in an attempt to locate additional archive members that resolve
1509symbol references.
1510This archive rescanning is repeated until a pass over the archives occurs in
1511which no new members are extracted.
1512.Pp
1513.Fl z Cm rescan
1514is a position independent option.
1515The link-editor defers the rescan operation until after it has processed the
1516entire command line, and then initiates a final rescan operation over all
1517archives seen on the command line.
1518The
1519.Fl z Cm rescan
1520operation can interact incorrectly with objects that contain initialization
1521.Pq .init
1522or finalization
1523.Pq .fini
1524sections, preventing the code in those sections from running.
1525For this reason,
1526.Fl z Cm rescan
1527is deprecated, and use of
1528.Fl z Cm rescan-now
1529is
1530advised.
1531.Pp
1532.It Fl z Cm rescan-start No \&... Fl z Cm rescan-end
1533.It Fl \&-start-group No \&... Fl \&-end-group
1534.It Fl \&( No \&... Fl \&)
1535Defines an archive rescan group.
1536This is a positional construct, and is processed by the link-editor immediately
1537upon encountering the closing delimiter option.
1538Archives found within the group delimiter options are reprocessed as a group in
1539an attempt to locate additional archive members that resolve symbol references.
1540This archive rescanning is repeated until a pass over the archives occurs in
1541which no new members are extracted.
1542Archive rescan groups cannot be nested.
1543.Pp
1544.It Fl z Cm symbolcap
1545Specifies that a relocatable object that defines object capabilities should
1546have those converted to symbol capabilities.
1547A relocatable object that does not have any object capabilities will ignore
1548this option.
1549.Pp
1550Symbol capabilities provide a means for multiple implementations of a function
1551to co-exist and have one picked at runtime based upon the hardware capabilities
1552of the system.
1553When
1554.Fl z Cm symbolcap
1555is invoked, all global functions are converted into local functions that have
1556the corresponding capability name appended to them and an undefined symbol with
1557the original name left in the resulting relocatable object.
1558At runtime, the global symbol will be bound to the corresponding implementation
1559that is appropriate based on the capabilities of the system.
1560.Pp
1561.It Fl z Cm target= Ns Cm sparc Ns | Ns Cm x86
1562Specifies the machine type for the output object.
1563Supported targets are
1564.Cm sparc
1565and
1566.Cm x86 .
1567The 32-bit machine type for the specified target is used unless the
1568.Fl 64
1569option is also present, in which case the corresponding 64-bit machine type is
1570used.
1571By default, the machine type of the object being generated is determined from
1572the first
1573.Sy ELF
1574object processed from the command line.
1575If no objects are specified, the machine type is determined by the first object
1576encountered within the first archive processed from the command line.
1577If there are no objects or archives, the link-editor assumes the native
1578machine.
1579This option is useful when creating an object directly with
1580.Nm
1581whose input is solely from a
1582.Sy mapfile .
1583See the
1584.Fl M
1585option.
1586It can also be useful in the rare case of linking entirely from an archive that
1587contains objects of different machine types for which the first object is not
1588of the desired machine type.
1589See
1590.Em The 32-bit link-editor and 64-bit link-editor
1591in
1592.%T Linker and Libraries Guide .
1593.Pp
1594Note that for compatibility with existing Makefiles and scripts, these options
1595may be given multiple times and may be mixed in the same invocation: the last
1596instance wins, so that, for example,
1597.Ql ld -z target=sparc -z target=x86 \&...
1598gives a machine type of
1599.Sq x86 .
1600.Pp
1601.It Fl z Cm text
1602In dynamic mode only, forces a fatal error if any relocations against
1603non-writable, allocatable sections remain.
1604For historic reasons, this mode is not the default when building an executable
1605or shared object.
1606However, its use is recommended to ensure that the text segment of the dynamic
1607object being built is shareable between multiple running processes.
1608A shared text segment incurs the least relocation overhead when loaded into
1609memory.
1610See
1611.Em Position-Independent Code
1612in
1613.%T Linker and Libraries Guide .
1614.Pp
1615.It Fl z Cm textoff
1616In dynamic mode only, allows relocations against all allocatable sections,
1617including non-writable ones.
1618This mode is the default when building a shared object.
1619.Pp
1620.It Fl z Cm textwarn
1621In dynamic mode only, lists a warning if any relocations against non-writable,
1622allocatable sections remain.
1623This mode is the default when building an executable.
1624.Pp
1625.It Xo
1626.Sm off
1627.Fl z\~ Cm type= Cm exec | kmod | reloc | shared
1628.Sm on
1629.Xc
1630Specifies the type of object to create.
1631.Bl -tag -width shared
1632.It exec
1633Dynamic executable
1634.It reloc
1635Relocatable object
1636.It shared
1637Dynamic shared object
1638.It kmod
1639illumos kernel module
1640.El
1641.Pp
1642.It Fl z Cm verbose
1643This option provides additional warning diagnostics during a link-edit.
1644Presently, this option conveys suspicious use of displacement relocations.
1645This option also conveys the restricted use of static TLS relocations when
1646building shared objects.
1647In future, this option might be enhanced to provide additional diagnostics that
1648are deemed too noisy to be generated by default.
1649.Pp
1650.It Fl z Cm wrap= Ns Ar symbol
1651.It Fl wrap Ns Cm \&= Ns Ar symbol
1652.It Fl \&-wrap Ns Cm \&= Ns Ar symbol
1653Rename undefined references to
1654.Ar symbol
1655in order to allow wrapper code to be linked into the output object without
1656having to modify source code.
1657When
1658.Fl z Cm wrap
1659is specified, all undefined references to
1660.Ar symbol
1661are modified to reference
1662.Sy __wrap_ Ns Ar symbol ,
1663and all references to
1664.Sy __real_ Ns Ar symbol
1665are modified to reference
1666.Ar symbol .
1667The user is expected to provide an object containing the
1668.Sy __wrap_ Ns Ar symbol
1669function.
1670This wrapper function can call
1671.Sy __real_ Ns Ar symbol
1672in order to reference the actual function being wrapped.
1673.Pp
1674The following is an example of a wrapper for the
1675.Xr malloc 3C
1676function:
1677.Bd -literal -offset 4n
1678void *
1679__wrap_malloc(size_t c)
1680{
1681    (void) printf("malloc called with %zu\en", c);
1682    return (__real_malloc(c));
1683}
1684.Ed
1685.Pp
1686If you link other code with this file using
1687.Fl z Cm wrap= Ns Ar malloc
1688to compile all the objects, then all calls to
1689.Sy malloc
1690will call the function
1691.Sy __wrap_malloc
1692instead.
1693The call to
1694.Sy __real_malloc
1695will call the real
1696.Sy malloc
1697function.
1698.Pp
1699The real and wrapped functions should be maintained in separate source files.
1700Otherwise, the compiler or assembler may resolve the call instead of leaving
1701that operation for the link-editor to carry out, and prevent the wrap from
1702occurring.
1703.El
1704.Sh ENVIRONMENT
1705.Bl -tag -width 4n
1706.It Ev LD_ALTEXEC
1707An alternative link-editor path name.
1708.Nm
1709executes, and passes control to this alternative link-editor.
1710This environment variable provides a generic means of overriding the default
1711link-editor that is called from the various compiler drivers.
1712See the
1713.Fl z Cm altexec64
1714option.
1715.It Ev LD_LIBRARY_PATH
1716A list of directories in which to search for the libraries specified using the
1717.Fl l
1718option.
1719Multiple directories are separated by a colon.
1720In the most general case, this environment variable contains two directory
1721lists separated by a semicolon:
1722.Pp
1723.D1 Ar dirlist1 Ns Cm \&; Ns Ar dirlist2
1724.Pp
1725If
1726.Nm
1727is called with any number of occurrences of
1728.Fl L ,
1729as in:
1730.Pp
1731.D1 Nm No ... Fl L Ns Ar path1 No ... Fl L Ns Ar pathn No ...
1732.Pp
1733then the search path ordering is:
1734.Pp
1735.D1 Ar dirlist1 Ar path1 No ... Ar pathn Ar dirlist2 Ev LIBPATH
1736.Pp
1737When the list of directories does not contain a semicolon, the list is
1738interpreted as
1739.Ar dirlist2 .
1740.Pp
1741The
1742.Ev LD_LIBRARY_PATH
1743environment variable also affects the runtime linkers search for dynamic
1744dependencies.
1745.Pp
1746This environment variable can be specified with a _32 or _64 suffix.
1747This makes the environment variable specific, respectively, to 32-bit or 64-bit
1748processes and overrides any non-suffixed version of the environment variable
1749that is in effect.
1750.It Ev LD_NOEXEC_64
1751Suppresses the automatic execution of the 64-bit link-editor.
1752By default, the link-editor executes the 64-bit version when the
1753.Sy ELF
1754class of the first relocatable file identifies a 64-bit object.
1755The 64-bit image that a 32-bit link-editor can create, has some limitations.
1756However, some link-edits might find the use of the 32-bit link-editor faster.
1757.It Ev LD_OPTIONS
1758A default set of options to
1759.Nm .
1760.Ev LD_OPTIONS
1761is interpreted by
1762.Nm
1763just as though its value had been placed on the command line, immediately
1764following the name used to invoke
1765.Nm ,
1766as in:
1767.Pp
1768.D1 Nm Ev $LD_OPTIONS No ... Ar other-arguments No ...
1769.It Ev LD_RUN_PATH
1770An alternative mechanism for specifying a runpath to the link-editor.
1771See the
1772.Fl R
1773option.
1774If both
1775.Ev LD_RUN_PATH
1776and the
1777.Fl R
1778option are specified,
1779.Fl R
1780supersedes.
1781.It Ev SGS_SUPPORT
1782Provides a colon-separated list of shared objects that are loaded with the
1783link-editor and given information regarding the linking process.
1784This environment variable can be specified with a _32 or _64 suffix.
1785This makes the environment variable specific, respectively, to the 32-bit or
178664-bit class of
1787.Nm
1788and overrides any non-suffixed version of the environment variable that is in
1789effect.
1790See the
1791.Fl S
1792option.
1793.El
1794.Pp
1795Notice that environment variable-names that begin with the characters
1796.Sq LD_
1797are reserved for possible future enhancements to
1798.Nm
1799and
1800.Xr ld.so.1 1 .
1801.Sh FILES
1802.Bl -tag -width 4n
1803.It lib Ns Ar x Ns No .so
1804shared object libraries.
1805.It lib Ns Ar x Ns No .a
1806archive libraries.
1807.It Pa a.out
1808default output file.
1809.It Ev LIBPATH
1810For 32-bit libraries, the default search path is
1811.Pa /usr/ccs/lib ,
1812followed by
1813.Pa /lib ,
1814and finally
1815.Pa /usr/lib .
1816For 64-bit libraries, the default search path is
1817.Pa /lib/64 ,
1818followed by
1819.Pa /usr/lib/64 .
1820.It Pa /usr/lib/ld
1821A directory containing several mapfiles that can be used during link-editing.
1822These mapfiles provide various capabilities, such as defining memory layouts,
1823aligning bss, and defining non-executable stacks.
1824.El
1825.Sh ATTRIBUTES
1826The command line interface of
1827.Nm
1828is
1829.Sy Committed .
1830The output of
1831.Nm
1832is
1833.Sy Committed .
1834.Sh SEE ALSO
1835.Xr as 1 ,
1836.Xr crle 1 ,
1837.Xr gprof 1 ,
1838.Xr ld.so.1 1 ,
1839.Xr ldd 1 ,
1840.Xr mcs 1 ,
1841.Xr pvs 1 ,
1842.Xr strip 1 ,
1843.Xr exec 2 ,
1844.Xr stat 2 ,
1845.Xr dladdr 3C ,
1846.Xr dldump 3C ,
1847.Xr dlopen 3C ,
1848.Xr malloc 3C ,
1849.Xr elf 3ELF ,
1850.Xr ar.h 3HEAD ,
1851.Xr a.out 5 ,
1852.Xr attributes 7
1853.Rs
1854.%B Linker and Libraries Guide
1855.Re
1856.Sh NOTES
1857Default options applied by
1858.Nm
1859are maintained for historic reasons.
1860In today's programming environment, where dynamic objects dominate, alternative
1861defaults would often make more sense.
1862However, historic defaults must be maintained to ensure compatibility with
1863existing program development environments.
1864Historic defaults are called out wherever possible in this manual.
1865For a description of the current recommended options, see Appendix A,
1866.Em Link-Editor Quick Reference ,
1867in
1868.%T Linker and Libraries Guide .
1869.Pp
1870If the file being created by
1871.Nm
1872already exists, the file is unlinked after all input files have been processed.
1873A new file with the specified name is then created.
1874This allows
1875.Nm
1876to create a new version of the file, while simultaneously allowing existing
1877processes that are accessing the old file contents to continue running.
1878If the old file has no other links, the disk space of the removed file is freed
1879when the last process referencing the file terminates.
1880.Pp
1881The behavior of
1882.Nm
1883when the file being created already exists was changed
1884with SXCE build 43.
1885In older versions, the existing file was rewritten in place, an approach with
1886the potential to corrupt any running processes that is using the file.
1887This change has an implication for output files that have multiple hard links
1888in the file system.
1889Previously, all links would remain intact, with all links accessing the new
1890file contents.
1891The new
1892.Nm
1893behavior
1894.Em breaks
1895such links, with the result that only the specified output file name references
1896the new file.
1897All the other links continue to reference the old file.
1898To ensure consistent behavior, applications that rely on multiple hard links to
1899linker output files should explicitly remove and relink the other file names.
1900