Skip Navigation Links | |
Exit Print View | |
man pages section 1: User Commands Oracle Solaris 11.1 Information Library |
- link-editor for object files
ld [-32 | -64] [-Bdirect | nodirect] [-B dynamic | static] [-B eliminate[=mode] | local[=mode]] [-B reduce] [-c name] [-C] [-D [!]token1,[!]token2,...] [-e epsym] [-f name | -F name] [-G] [-h name] [-i] [-l x] [-L path] [-m] [-M mapfile] [-N string] [-o outfile] [-p auditlib] [-P auditlib] [-Q y | n] [-r] [-R path] [-s] [-S supportlib] [-t] [-u symname] [-V] [-Y P,dirlist] [-z allextract | defaultextract | weakextract ] [-z altexec64] [-z aslr[=mode]] [-z ancillary[=outfile]] [-z assert-deflib[=libname]] [-z deferred | nodeferred] [-z defs | nodefs] [-z direct | nodirect] [-z discard-unused=item1,item2,...] [-z endfiltee] [-z fatal-warnings | nofatal-warnings] [-z finiarray=function] [-z globalaudit] [-z guidance[=item1,item2,...]] [-z help ] [-z ignore | record] [-z initarray=function] [-z initfirst] [-z interpose] [-z lazyload | nolazyload] [-z ld32=arg1,arg2,...] [-z ld64=arg1,arg2,...] [-z loadfltr] [-z mapfile-add=name] [-z muldefs] [-z nocompstrtab] [-z nodefaultlib] [-z nodelete] [-z nodlopen] [-z nodump] [-z noldynsym] [-z nopartial] [-z origin] [-z parent=object] [-z preinitarray=function] [-z relaxreloc] [-z rescan-now] [-z rescan-start ... -z rescan-end] [-z strip-class=[!]class1,[!]class2,...] [-z stub] [-z symbolcap] [-z target=sparc|x86] [-z text | textwarn | textoff] [-z verbose] [-z wrap=symbol] filename ...
The link-editor, ld, combines relocatable object files by resolving symbol references to symbol definitions, together with performing relocations. In all cases, the default output of ld is left in the file a.out. See NOTES.
ld has a large number of options. Those options that are relevant to modern programming practices are defined in the SYNOPSIS, and described in the sections that follow. Other options are less commonly used, and are described under the SECONDARY OPTIONS section.
ld operates in one of two modes, dynamic or static. Dynamic mode is the default, however this mode can be governed by the -r or -d options. In dynamic mode, relocatable object files that are provided as arguments, are combined to produce a dynamic executable file. This file is combined at runtime with any shared object files that are provided as arguments. If the -G option is specified, relocatable object files are combined to produce a shared object file. This dynamic linking environment tightly couples the work of the link-editor and the runtime linker, ld.so.1(1). Both of these utilities, together with their related technologies and utilities, are extensively documented in the Linker and Libraries Guide.
In static mode, with the -r option, relocatable object files that are provided as arguments are combined to produce one relocatable object file. Modern versions of the Oracle Solaris operating system do not support the creation of static executables. See Static Executables. All discussion in this section assumes dynamic linking, or static linking with the -r option.
If any argument is a library, ld by default searches the library exactly once at the point the library is encountered on the command line. The library can be either a shared object or relocatable archive. See ar.h(3HEAD).
A shared object consists of an indivisible, whole unit that has been generated by a previous link-edit of one or more input files. When the link-editor processes a shared object, the entire contents of the shared object become a logical part of the resulting output file image. The shared object is not physically copied during the link-edit as its actual inclusion is deferred until process execution. This logical inclusion means that all symbol entries defined in the shared object are made available to the link-editing process. See Chapter 4, Shared Objects, in Linker and Libraries Guide
For an archive library, ld loads only those archive members that define an unresolved external reference. ld searches the symbol table of the archive library sequentially to resolve external references that can be satisfied by archive members. This search is repeated until no external references can be resolved by the archive. Thus, the order of members in the library is functionally unimportant, unless multiple archive members exist that define the same external symbol. Archive libraries that have interdependencies can require multiple command line definitions, or the use of one of the -z rescan options. See Archive Processing in Linker and Libraries Guide.
ld is a cross link-editor, able to link 32–bit objects or 64–bit objects, for SPARC or x86 targets. ld uses the ELF class and machine type of the first relocatable object on the command line to govern the mode in which to operate. The mixing of 32–bit objects and 64–bit objects is not permitted. Similarly, only objects of a single machine type are allowed. See the -32, -64 and -z target options, and the LD_NOEXEC_64 environment variable.
The creation of static executables has been discouraged for many releases. In fact, 64–bit system archive libraries have never been provided with Solaris. Because a static executable is built against system archive libraries, the executable contains system implementation details. This self-containment has a number of drawbacks.
The executable is immune to the benefits of system patches delivered as shared objects. The executable therefore, must be rebuilt to take advantage of many system improvements.
The ability of the executable to run on future releases can be compromised.
The duplication of system implementation details negatively affects system performance.
Starting with Oracle Solaris 10, 32–bit system archive libraries are no longer provided. Without these libraries, specifically libc.a, the creation of static executables is no longer achievable without specialized system knowledge. However, the capability of ld to process static linking options, and the processing of archive libraries, remains unchanged.
The following options are supported.
Create a 32–bit, or 64–bit object.
By default, the class of the object being generated is determined from the first ELF object processed from the command line. If no objects are specified, the class is determined by the first object encountered within the first archive processed from the command line. If there are no objects or archives, the link-editor creates a 32–bit object.
The -64 option is required to create a 64–bit object solely from a mapfile.
The -32 or -64 options can also be used in the rare case of linking entirely from an archive that contains a mixture of 32 and 64–bit objects. If the first object in the archive is not the class of the object that is required to be created, then the -32 or -64 option can be used to direct the link-editor.
These options govern direct binding. -B direct establishes direct binding information by recording the relationship between a symbol reference and the dependency that provides the symbol definition. In addition, direct binding information can be established between a symbol reference and an associated definition within the object being created. The runtime linker uses this information to search directly for a symbol in the associated object rather than to carry out a default symbol search.
Direct binding information can only be established to dependencies specified with the link-edit. Thus, you should also add the -z defs option. Objects that wish to interpose on symbols in a direct binding environment should identify themselves as interposers with the -z interpose option. The use of -B direct also enables -z lazyload for all dependencies.
The -B nodirect option prevents any direct binding to the interfaces offered by the object being created. The object being created can continue to directly bind to external interfaces by specifying the -z direct option. See Chapter 9, Direct Bindings, in Linker and Libraries Guide.
These options govern library inclusion. -B dynamic allows a -l option library search to expand to a shared object and an archive library name. This option is valid, and the default, in dynamic mode only. -B static restricts a -l option library search to expand to archive library names only. These options can be specified any number of times on the command line as toggles. If the -B static option is given, no shared objects are accepted until -B dynamic is seen. See the -l option.
Causes any symbols that default to global binding, to be eliminated from the symbol table, or reduced to local visibility. A global symbol that has a STV_DEFAULT visibility, can be reduced to a more restrictive visibility by the link-editor. A global symbol that has any other STV_ visibility is considered to have an explicit visibility. An explicit visibility is honored by the link-editor, and can not be modified. See SYMBOL_SCOPE / SYMBOL_VERSION Directives in Linker and Libraries Guide. A symbols visibility can be explicitly defined through compiler directives, or through mapfiles that define version or interface definitions.
Mapfile version and interface definitions can contain auto-elimination or auto-reduction directives. See SYMBOL_SCOPE / SYMBOL_VERSION Directives in Linker and Libraries Guide. These directives result in symbols that are not explicitly defined in a mapfile, or do not define an explicit visibility, to be eliminated or reduced to local, respectively. Besides any explicit symbol definitions, symbol elimination or reduction can also be affected by the type of object being produced, as described in the paragraphs that follow. The -B eliminate option requests the same symbol elimination as the mapfile auto-elimination directive. The -B local option requests the same symbol reduction as the mapfile auto-reduction directive.
Either option can be qualified with a mode, external, or noexternal, to control the selection of eliminated or reduced global symbols. This fine-tuning is usually unnecessary, as the link-editor defaults to the appropriate mode for the type of object being produced, external for executables, and noexternal for shared objects.
When building a dynamic object, it can be necessary to ensure that some symbols remain global so that they can be referenced from external dependencies. This is particularly true for dynamic executables. When building an executable, relocatable objects are contributed by the compilation environment that provide for runtime process initialization. These relocatable objects can contain global symbols that are referenced from system dependencies. These symbols should remain global regardless of any auto-elimination or auto-reduction symbol techniques, so as not to compromise runtime execution.
Defining the mode as external results in the analysis of any external dependencies to determine if any symbol reference from the dependency might bind to a symbol definition within the object being built. Any global symbol that satisfies such a binding is not eliminated or reduced to local. This mode is the default when producing a dynamic executable.
Defining the mode as noexternal circumvents the analysis of any external dependencies, and results in the reduction of all symbols that are not explicitly defined in a mapfile, or do not define an explicit visibility. This mode is the default when producing a shared object.
See also the -B reduce option.
When generating a relocatable object, causes the reduction of symbolic information defined by any symbol visibility attribute, or through mapfiles that define version or interface definitions. By default, when a relocatable object is generated, visibility attributes, version definitions, or interface definitions are only recorded in the output image. Visibility attributes, or mapfile version or interface definitions, are always applied to any symbolic information when creating a dynamic executable or shared object.
Records the configuration file name for use at runtime. Configuration files can be employed to alter default search paths, provide a directory cache, together with providing alternative object dependencies. See crle(1).
Demangles C++ symbol names displayed in diagnostic messages.
Prints debugging information as specified by each token, to the standard error. The special token help indicates the full list of tokens available. See Debugging Aids in Linker and Libraries Guide.
Sets the entry point address for the output file to be the symbol epsym.
Used only when building a shared object. Specifies that the symbol table of the shared object is used as an auxiliary filter on the symbol table of the shared object specified by name. Multiple instances of this option are allowed. This option can not be combined with the -F option. See Generating Auxiliary Filters in Linker and Libraries Guide.
Used only when building a shared object. Specifies that the symbol table of the shared object is used as a filter on the symbol table of the shared object specified by name. Multiple instances of this option are allowed. This option can not be combined with the -f option. See Generating Standard Filters in Linker and Libraries Guide.
In dynamic mode only, produces a shared object. Undefined symbols are allowed. See Chapter 4, Shared Objects, in Linker and Libraries Guide.
In dynamic mode only, when building a shared object, records name in the object's dynamic section. name is recorded in any dynamic objects that are linked with this object rather than the object's file system name. Accordingly, name is used by the runtime linker as the name of the shared object to search for at runtime. See Recording a Shared Object Name in Linker and Libraries Guide.
Ignores LD_LIBRARY_PATH. This option is useful when an LD_LIBRARY_PATH setting is in effect to influence the runtime library search, which would interfere with the link-editing being performed.
Searches a library libx.so or libx.a, the conventional names for shared object and archive libraries, respectively. In dynamic mode, unless the -B static option is in effect, ld searches each directory specified in the library search path for a libx.so or libx.a file. The directory search stops at the first directory containing either. ld chooses the file ending in .so if -lx expands to two files with names of the form libx.so and libx.a. If no libx.so is found, then ld accepts libx.a. In static mode, or when the -B static option is in effect, ld selects only the file ending in .a. ld searches a library when the library is encountered, so the placement of -l is significant. See Linking With Additional Libraries in Linker and Libraries Guide.
Adds path to the library search directories. ld searches for libraries first in any directories specified by the -L options and then in the standard directories. This option is useful only if the option precedes the -l options to which the -L option applies. See Directories Searched by the Link-Editor in Linker and Libraries Guide.
The environment variable LD_LIBRARY_PATH can be used to supplement the library search path, however the -L option is recommended, as the environment variable is also interpreted by the runtime environment. See LD_LIBRARY_PATH under ENVIRONMENT VARIABLES.
Produces a memory map or listing of the input/output sections, together with any non-fatal multiply-defined symbols, on the standard output.
Reads mapfile as a text file of directives to ld. This option can be specified multiple times. If mapfile is a directory, then all regular files, as defined by stat(2), within the directory are processed. See Appendix B, System V Release 4 (Version 1) Mapfiles, in Linker and Libraries Guide. Example mapfiles are provided in /usr/lib/ld. See FILES.
This option causes a DT_NEEDED entry to be added to the .dynamic section of the object being built. The value of the DT_NEEDED string is the string that is specified on the command line. This option is position dependent, and the DT_NEEDED .dynamic entry is relative to the other dynamic dependencies discovered on the link-edit line. This option is useful for specifying dependencies within device driver relocatable objects when combined with the -dy and -r options.
Produces an output object file that is named outfile. The name of the default object file is a.out.
Identifies an audit library, auditlib. This audit library is used to audit the object being created at runtime. A shared object identified as requiring auditing with the -p option, has this requirement inherited by any object that specifies the shared object as a dependency. See the -P option. See Runtime Linker Auditing Interface in Linker and Libraries Guide.
Identifies an audit library, auditlib. This audit library is used to audit the dependencies of the object being created at runtime. Dependency auditing can also be inherited from dependencies that are identified as requiring auditing. See the -p option, and the -z globalaudit option. See Runtime Linker Auditing Interface in Linker and Libraries Guide.
Under -Q y, an ident string is added to the .comment section of the output file. This string identifies the version of the ld used to create the file. This results in multiple ld idents when there have been multiple linking steps, such as when using ld -r. This identification is identical with the default action of the cc command. -Q n suppresses version identification. .comment sections can be manipulated by the mcs(1) utility.
Combines relocatable objects to produce one relocatable object file. ld does not complain about unresolved references. This option cannot be used with the -a option.
A colon-separated list of directories used to specify library search directories to the runtime linker. If present and not NULL, the path is recorded in the output object file and passed to the runtime linker. Multiple instances of this option are concatenated together with each path separated by a colon. See Directories Searched by the Runtime Linker in Linker and Libraries Guide.
The use of a runpath within an associated object is preferable to setting global search paths such as through the LD_LIBRARY_PATH environment variable. Only the runpaths that are necessary to find the objects dependencies should be recorded. ldd(1) can also be used to discover unused runpaths in dynamic objects, when used with the -U option.
Various tokens can also be supplied with a runpath that provide a flexible means of identifying system capabilities or an objects location. See Chapter 6, Establishing Dependencies with Dynamic String Tokens, in Linker and Libraries Guide. The $ORIGIN token is especially useful in allowing dynamic objects to be relocated to different locations in the file system.
Strip any symbolic information from the output file. These options are equivalent to using the -z strip-class option with the debug and symbol class identifiers. See also the -z redlocsym and -z noldynsym options.
The shared object supportlib is loaded with ld and given information regarding the linking process. Shared objects that are defined by using the -S option can also be supplied using the SGS_SUPPORT environment variable. See Link-Editor Support Interface in Linker and Libraries Guide.
Turns off the warning for multiply-defined symbols that have different sizes or different alignments.
Enters symname as an undefined symbol in the symbol table. This option is useful for loading entirely from an archive library. In this instance, an unresolved reference is needed to force the loading of the first routine. The placement of this option on the command line is significant. This option must be placed before the library that defines the symbol. See Defining Additional Symbols with the -u option in Linker and Libraries Guide.
Outputs a message giving information about the version of ld being used.
Changes the default directories used for finding libraries. dirlist is a colon-separated path list.
Alters the extraction criteria of objects from any archives that follow. By default, archive members are extracted to satisfy undefined references and to promote tentative definitions with data definitions. Weak symbol references do not trigger extraction. Under the -z allextract or --whole-archive options, all archive members are extracted from the archive. Under -z weakextract, weak references trigger archive extraction. The -z defaultextract or --no-whole-archive options provide a means of returning to the default following use of the former extract options. See Archive Processing in Linker and Libraries Guide.
Execute the 64–bit ld. Historically, the class of link-editor that was executed was determined by the class of ELF object being created. Now, the class of the link-editor that is executed is determined by the class of the underlying system. Typically this is 64–bit. This option is maintained for backward compatibility.
Specifies an ancillary output file, which will receive any non-allocable sections that would normally be added to the output object. Non-allocable sections are not required at runtime, and are primarily for use by debuggers and other observability tools. If outfile is present, the ancillary file is created with the given name. If outfile is not present, the ancillary file is given the same name as the primary output file with the addition of a .anc suffix. See Chapter 2, Link-Editor, in Linker and Libraries Guide.
Ancillary objects are supported for executable and shared objects only. The -z ancillary option cannot be used when the -r option is specified to build a relocatable object. The -z ancillary option is quietly ignored if used in conjunction with the -z stub option. The -z ancillary option is also ignored if specified without outfile, and the output file specified via the -o option is a device special file such as /dev/null.
Specifies the Address Space Layout Randomization (ASLR) behavior for an executable. The mode value can be set to enabled or disabled. If mode is omitted, ASLR is enabled.
Enables warning messages for libraries specified with the -l command line option that are found by examining the default search paths provided by the link-editor. If a libname value is provided, the default library warning feature is enabled, and the specified library is added to a list of libraries for which no warnings will be issued. Multiple -z assert-deflib options can be specified in order to specify multiple libraries for which warnings should not be issued.
The libname value should be the name of the library file, as found by the link-editor, without any path components. For example, the following enables default library warnings, and excludes the standard C library.
ld ... -z assert-deflib=libc.so ...
-z assert-deflib is a specialized option, primarily of interest in build environments where multiple objects with the same name exist and tight control over the library used is required. This option is not intended for general use.
Enables or disables the marking of dynamic dependencies as deferred. Dynamic dependencies which are marked deferred, are also marked as lazy loadable, and are not loaded at initial process start-up. The loading of deferred dependencies is delayed until process execution, when the first binding to a deferred reference is made. Unlike basic lazy loadable dependencies, deferred dependencies are not processed as part of LD_BIND_NOW processing, or through dlopen(3C) with the RTLD_NOW flag. See Lazy Loading of Dynamic Dependencies in Linker and Libraries Guide.
The use of deferred dependencies, together with dlsym(3C) and the RTLD_PROBE handle, provides a flexible mechanism, and natural coding style, for testing for functionality.
The -z defs option and the --no-undefined option force a fatal error if any undefined symbols remain at the end of the link. This mode is the default when an executable is built. For historic reasons, this mode is not the default when building a shared object. Use of the -z defs option is recommended, as this mode assures the object being built is self-contained. A self-contained object has all symbolic references resolved internally, or to the object's immediate dependencies.
The -z nodefs option allows undefined symbols. For historic reasons, this mode is the default when a shared object is built. When used with executables, the behavior of references to such undefined symbols is unspecified. Use of the -z nodefs option is not recommended.
Enables or disables direct binding to any dependencies that follow on the command line. These options allow finer control over direct binding than the global counterpart -B direct. The -z direct option also differs from the -B direct option in the following areas. Direct binding information is not established between a symbol reference and an associated definition within the object being created. Lazy loading is not enabled.
By default, the link-editor discards unused, empty sections. Other categories of input material can be determined to be unused during the link-edit. The -z discard-unused option enables the automatic removal of such items. The following item tokens are recognized.
Unused sections are discarded from the output file created from the link-edit.
Unused relocatable object files are discarded from the output file created from the link-edit.
An input relocatable object file is determined to be unused if all allocatable sections provided by the relocatable object are unused. See also the “Non-Required Relocatable Object Files” discussion of the -z guidance option.
Unused, explicit, shared object dependencies are not recorded in the output file created from the link-edit.
An explicit dependency is one that is defined on the command-line, either using the path name, or more commonly by using the -l option. Explicit dependencies can depend on other objects, which are referred to as implicit dependencies. An explicit dependency is determined to be unused if two conditions are true.
No global symbols that are provided by the dependency are referenced from the object being built.
The dependency does not compensate for the requirements of any implicit dependencies.
See also the “Non-Required or Compensating Dependencies” discussion of the -z guidance option.
Disables all unused processing, including the default action of removing unused, empty sections.
See also Remove Unused Material in Linker and Libraries Guide.
Marks a filtee so that when processed by a filter, the filtee terminates any further filtee searches by the filter. See Reducing Filtee Searches in Linker and Libraries Guide.
The -z fatal-warnings and the --fatal-warnings option cause the link-editor to treat warnings as fatal errors.
The -z nofatal-warnings and the --no-fatal-warnings option cause the link-editor to treat warnings as non-fatal. This is the default behavior.
Appends an entry to the .fini_array section of the object being built. If no .fini_array section is present, a section is created. The new entry is initialized to point to function. See Initialization and Termination Sections in Linker and Libraries Guide.
This option supplements an audit library definition that has been recorded with the -P option. This option is only meaningful when building a dynamic executable. Audit libraries that are defined within an object with the -P option typically allow for the auditing of the immediate dependencies of the object. The -z globalaudit promotes the auditor to a global auditor, thus allowing the auditing of all dependencies. See Invoking the Auditing Interface in Linker and Libraries Guide.
An auditor established with the -P option and the -z globalaudit option, is equivalent to the auditor being established with the LD_AUDIT environment variable. See ld.so.1(1).
Provide guidance messages to suggest ld options that can improve the quality of the resulting object, or which are otherwise considered to be beneficial. The specific guidance offered is subject to change over time as the system evolves. Obsolete guidance offered by older versions of ld may be dropped in new versions. Similarly, new guidance may be added to new versions of ld. Guidance therefore always represents current best practices.
It is possible to enable guidance, while preventing specific guidance messages, by providing a list of item tokens, representing the class of guidance to be suppressed. In this way, unwanted advice can be suppressed without losing the benefit of other guidance. Unrecognized item tokens are quietly ignored by ld, allowing a given ld command line to be executed on a variety of older or newer versions of Solaris.
The guidance offered by the current version of ld, and the item tokens used to disable these messages, are as follows.
Dynamic executables and shared objects should explicitly define all of the dependencies they require. Guidance recommends the use of the -z defs option, should any symbol references remain unsatisfied when building dynamic objects. This guidance can be disabled with -z guidance=nodefs.
Dynamic executables and shared objects should not define any explicit dependencies that do not satisfy the symbol references made by the dynamic object. Guidance recommends that non-required, or unused dependencies, be removed. Unused dependencies, can fall into one of two categories.
Explicit dependencies that satisfy no symbol references.
Explicit dependencies that satisfy no symbol references from the dynamic object being built, but that compensate for implicit dependencies. See the “dependencies” discussion of the -z discard-unused option.
Guidance for both of these categories can be disabled with -z guidance=nounused-dependencies, or the synonym -z guidance=nounused. Guidance for compensating dependencies can be disabled with -z guidance=nounused-compensators.
See also Remove Unused Material in Linker and Libraries Guide.
The output file being created should not contain any information from a relocatable object whose allocatable sections are not referenced by any other objects involved with the link-edit. Guidance recommends that unused relocatable objects be removed. This guidance can be disabled with -z guidance=nounused-files.
See also Remove Unused Material in Linker and Libraries Guide.
Dependencies should be identified for lazy loading. Guidance recommends the use of the -z lazyload option should any dependency be processed before either a -z lazyload or -z nolazyload option is encountered. This guidance can be disabled with -z guidance=nolazyload.
Dependencies should be referenced with direct bindings. Guidance recommends the use of the -B direct, or -z direct options should any dependency be processed before either of these options, or the -z nodirect option is encountered. This guidance can be disabled with -z guidance=nodirect.
Dynamic objects should not contain relocations to non-writable, allocable sections. Guidance recommends compiling objects with Position Independent Code (PIC) should any relocations against the text segment remain, and neither the -z textwarn or -z textoff options are encountered. This guidance can be disabled with -z guidance=notext.
All mapfiles should use the version 2 mapfile syntax. Guidance recommends the use of the version 2 syntax should any mapfiles be encountered that use the version 1 syntax. This guidance can be disabled with -z guidance=nomapfile.
Inappropriate dependencies that are encountered by ld are quietly ignored. For example, a 32–bit dependency that is encountered when generating a 64–bit object is ignored. These dependencies can result from incorrect search path settings, such as supplying an incorrect -L option. Although benign, this dependency processing is wasteful, and might hide a build problem that should be solved. Guidance recommends the removal of any inappropriate dependencies. This guidance can be disabled with -z guidance=nolibpath.
In addition, -z guidance=noall can be used to entirely disable the guidance feature. Chapter 7, Link-Editor Quick Reference, in Linker and Libraries Guide for more information on guidance and advice for building better objects.
Print a summary of the command line options on the standard output and exit.
Ignores, or records, shared object dependencies that are not referenced as part of the link-edit.
-z ignore and -z record are positional options, used to toggle how ld handles unreferenced dependencies encountered on the command line. When -z ignore is encountered, any subsequent unreferenced dependencies are quietly ignored. When -z record is encountered, all dependencies are recorded without regard to whether the dependency is referenced or not.
By default, ld records all dependencies whether or not the dependency is referenced. The non-positional -z discard-unused=dependencies option can be used to alter this initial default. Once the initial setting is established, -z ignore and -z record can be used to alter the default behavior.
Appends an entry to the .init_array section of the object being built. If no .init_array section is present, a section is created. The new entry is initialized to point to function. See Initialization and Termination Sections in Linker and Libraries Guide.
Marks the object so that its runtime initialization occurs before the runtime initialization of any other objects brought into the process at the same time. In addition, the object runtime finalization occurs after the runtime finalization of any other objects removed from the process at the same time. This option is only meaningful when building a shared object.
Marks the object as an interposer. At runtime, an object is identified as an explicit interposer if the object has been tagged using the -z interpose option. An explicit interposer is also established when an object is loaded using the LD_PRELOAD environment variable. Implicit interposition can occur because of the load order of objects, however, this implicit interposition is unknown to the runtime linker. Explicit interposition can ensure that interposition takes place regardless of the order in which objects are loaded. Explicit interposition also ensures that the runtime linker searches for symbols in any explicit interposers when direct bindings are in effect.
Enables or disables the marking of dynamic dependencies to be lazily loaded. Dynamic dependencies which are marked lazyload are not loaded at initial process start-up. These dependencies are delayed until the first binding to the object is made. Note: Lazy loading requires the correct declaration of dependencies, together with associated runpaths for each dynamic object used within a process. See Lazy Loading of Dynamic Dependencies in Linker and Libraries Guide.
The class of the link-editor is affected by the class of the output file being created and by the capabilities of the underlying operating system. The -z ld[32|64] options provide a means of defining any link-editor argument. The defined argument is only interpreted, respectively, by the 32–bit class or 64–bit class of the link-editor.
For example, support libraries are class specific, so the correct class of support library can be ensured using:
ld ... -z ld32=-Saudit32.so.1 -z ld64=-Saudit64.so.1 ...
Marks a filter to indicate that filtees must be processed immediately at runtime. Normally, filter processing is delayed until a symbol reference is bound to the filter. The runtime processing of an object that contains this flag mimics that which occurs if the LD_LOADFLTR environment variable is in effect. See the ld.so.1(1).
Adds name to the list of known mapfile conditional input expression predicates. This option is equivalent to placing the following lines at the top of the first mapfile read by the link-editor.
$mapfile_version 2 $add name
Names entered via -z mapfile-add can be used with mapfile $if and $elif directives to conditionally process mapfile input. See Chapter 10, Mapfiles, in Linker and Libraries Guide.
Allows multiple symbol definitions. By default, multiple symbol definitions that occur between relocatable objects result in a fatal error condition. This option, suppresses the error condition, allowing the first symbol definition to be taken.
Marks the object as non-deletable at runtime. This mode is similar to adding the object to the process by using dlopen(3C) with the RTLD_NODELETE mode.
Marks the object as not available to dlopen(3C), either as the object specified by the dlopen(), or as any form of dependency required by the object specified by the dlopen(). This option is only meaningful when building a shared object.
Marks the object as not available to dldump(3C).
Specifies a parent object, which can be an executable or shared object, against which to link the output object. This option is typically used when creating plugin shared objects intended to be loaded by an executable at runtime via the dlopen() function. The symbol table from the parent object is used to satisfy references from the plugin object. See Chapter 2, Link-Editor, in Linker and Libraries Guide.
Appends an entry to the .preinit_array section of the object being built. If no .preinit_array section is present, a section is created. The new entry is initialized to point to function. See Initialization and Termination Sections in Linker and Libraries Guide.
ld normally issues a fatal error upon encountering a relocation using a symbol that references an eliminated COMDAT section. If -z relaxreloc is enabled, ld instead redirects such relocations to the equivalent symbol in the COMDAT section that was kept. -z relaxreloc is a specialized option, mainly of interest to compiler authors, and is not intended for general use.
These options rescan the archive files that are provided to the link-edit. By default, archives are processed once as the archives appear on the command line. Archives are traditionally specified at the end of the command line so that their symbol definitions resolve any preceding references. However, specifying archives multiple times to satisfy their own interdependencies can be necessary.
-z rescan-now is a positional option, and is processed by the link-editor immediately when encountered on the command line. All archives seen on the command line up to that point are immediately reprocessed in an attempt to locate additional archive members that resolve symbol references. This archive rescanning is repeated until a pass over the archives occurs in which no new members are extracted.
-z rescan is a position independent option. The link-editor defers the rescan operation until after it has processed the entire command line, and then initiates a final rescan operation over all archives seen on the command line. The -z rescan operation can interact incorrectly with objects that contain initialization (.init) or finalization (.fini) sections, preventing the code in those sections from running. For this reason, -z rescan is deprecated, and use of -z rescan-now is advised.
Defines an archive rescan group. This is a positional construct, and is processed by the link-editor immediately upon encountering the closing delimiter option. Archives found within the group delimiter options are reprocessed as a group in an attempt to locate additional archive members that resolve symbol references. This archive rescanning is repeated until a pass over the archives On the occurs in which no new members are extracted. Archive rescan groups cannot be nested.
Strip a specific class of section from any input objects, preventing these sections from being added to the output file. This option provides fine grained control over the sections that can be omitted from the output file.
The strip class descriptions that follow only apply to non-allocatable sections.
Each class token can be prepended with a '!' to indicate that the class should not be removed. This definition can be useful when combined with the nonalloc class. For example, using '-z strip-class=nonalloc,!note' removes all non-allocatable sections except for the note section.
Stripped sections are completely removed from the output object. The use of the -z ancillary option alters this behavior with regard to the non-dynamic symbol table .symtab, and the sections related to it. By default, the symbol table is written to both the primary and ancillary objects. If stripped, the symbol table is written to the ancillary object only, and is marked as absent in the primary object. If .symtab is stripped from an object without the use of -z ancillary, the section is completely removed in the usual manner.
The following classes of section can be defined.
Strip any non-allocatable section. These sections are identified as not including the SHF_ALLOC section flag. This class encapsulates all of the other classes, except for the symbol class. The nonalloc class is often sufficient by itself to remove any unwanted sections.
Strip any annotation section. These sections provide information that is used by memory access tools, and coverage related tools. These sections are identified by having a SHT_SUNW_ANNOTATE section type.
Strip any comment section. These sections are identified by having a .comment section name. Alternatively, the mcs(1) utility is commonly used to manipulate comment sections.
Strip sections commonly used to contain debugging data. These sections are identified by having a .compcom, .line, .stab*, or .debug* section name. These sections are also identified by having a SHT_SUNW_DEBUG* section type.
Strip any excludable section. These sections are identified by having a SHF_EXCLUDE section flag. This class can be useful when creating a relocatable object. By default, such sections are automatically excluded when a dynamic executable or shared object is created, and are retained when creating a relocatable object.
Strip any note section. These sections are identified by having a SHT_NOTE section type.
Strip any non-allocatable symbol table and string table sections, providing the output file is not a relocatable object. These sections are identified by having a SHT_SYMTAB section type. Any associated string table is also removed.
Produces a stub shared object. A stub object is a shared object, built entirely from mapfiles, that supplies the same linking interface as the real object, while containing no code or data. Stub objects cannot be used at runtime. However, an application can be built against a stub object, where the stub object provides the real object name to be used at runtime, and then use the real object at runtime.
Stub objects can only be produced for shared objects, and a mapfile defining the global symbols to be exported must be supplied. The -G and -M options are therefore required when -z stub is used. When building a stub object, the link-editor ignores any object or library files specified on the command line, and these files need not exist in order to build a stub. Since the compilation step can be omitted, and because the link-editor has relatively little work to do, stub objects can be built very quickly.
See Stub Objects in Linker and Libraries Guide.
Convert a relocatable object that defines object capabilities into a relocatable object that defines symbol capabilities. See Converting Object Capabilities to Symbol Capabilities in Linker and Libraries Guide.
Specifies the machine type for the output object. Supported targets are SPARC and x86. The 32–bit machine type for the specified target is used unless the -64 option is also present, in which case the corresponding 64–bit machine type is used. By default, the machine type of the object being generated is determined from the first ELF object processed from the command line. If no objects are specified, the machine type is determined by the first object encountered within the first archive processed from the command line. If there are no objects or archives, the link-editor assumes the native machine. This option is useful when creating an object directly with ld whose input is solely from a mapfile. See the -M option. It can also be useful in the rare case of linking entirely from an archive that contains objects of different machine types for which the first object is not of the desired machine type.
These options can be used in dynamic mode only. The -z text option forces a fatal error if any relocations against non-writable, allocatable sections remain. For historic reasons, this mode is not the default when building an executable or shared object. However, its use is recommended to ensure that the text segment of the dynamic object being built is shareable between multiple running processes. A shared text segment incurs the least relocation overhead when loaded into memory. See Position-Independent Code in Linker and Libraries Guide.
The -z textoff option allows relocations against all allocatable sections, including non-writable ones. This mode is the default when building a shared object.
The -z textwarn option lists a warning if any relocations against non-writable, allocatable sections remain. This mode is the default when building an executable.
This option provides additional warning diagnostics during a link-edit. Presently, this option enables the following warnings.
Suspicious use of displacement relocations.
Restricted use of static TLS relocations when building shared objects.
Symbol visibility inconsistencies.
In the future, this option might be enhanced to provide additional diagnostics that are deemed too noisy to be generated by default.
Rename undefined references to symbol in order to allow wrapper code to be linked into the output object without having to modify source code. When -z wrap is specified, all undefined references to symbol are modified to reference __wrap_symbol, and all references to __real_symbol are modified to reference symbol. You are expected to provide an object containing the __wrap_symbol function. This wrapper function can call __real_symbol in order to reference the actual function being wrapped.
The following is an example of a wrapper for the malloc(3C) function.
void * __wrap_malloc(size_t c) { (void) printf("malloc called with %zu\n", c); return (__real_malloc(c)); }
If you link other code with this file using -z wrap=malloc to compile all the objects, then all calls to malloc call the function __wrap_malloc instead. The call to __real_malloc calls the real malloc function.
The real and wrapped functions should be maintained in separate source files. Otherwise, the compiler or assembler may resolve the call instead of leaving that operation for the link-editor to carry out, and prevent the wrap from occurring.
The following options are less commonly used. These options provide for backward compatibility, very specialized features, or options that have been superseded with improved variants.
In static mode only, produces a static executable file. Undefined references are not permitted. This option is the default behavior for static mode. The -a option can not be used with the -r option. See Static Executables under DESCRIPTION.
In dynamic mode only, provides no special processing for dynamic executable relocations that reference symbols in shared objects. Without the -b option, the link-editor applies techniques within a dynamic executable so that the text segment can remain read-only. One technique is the creation of special position-independent relocations for references to functions that are defined in shared objects. Another technique arranges for data objects that are defined in shared objects to be copied into the memory image of an executable at runtime.
The -b option is intended for specialized dynamic objects and is not recommended for general use. Its use suppresses all specialized processing required to ensure an object's shareability, and can even prevent the relocation of 64–bit executables.
Establishes a shared object and its dependencies as a group. Objects within the group are bound to other members of the group at runtime. This mode is similar to adding the object to the process by using dlopen(3C) with the RTLD_GROUP mode. An object that has an explicit dependency on a object identified as a group, becomes a member of the group.
As the group must be self contained, use of the -B group option also asserts the -z defs option.
Establishing a group provides a primitive means of controlling the binding of a group of objects. However, better control can be accomplished with direct bindings. See the -B direct option.
In dynamic mode only. When building a shared object, binds references to global symbols to their definitions, if available, within the object. Normally, references to global symbols within shared objects are not bound until runtime, even if definitions are available. This model allows definitions of the same symbol in an executable or other shared object to override the object's own definition. ld issues warnings for undefined symbols unless -z defs overrides.
The -B symbolic option is intended for specialized dynamic objects and is not recommended for general use. To reduce the runtime relocation processing that is required an object, the creation of a version definition is recommended, together with the use of direct bindings. See the -B direct option.
When -d y, the default, is specified, ld uses dynamic linking. When -d n is specified, ld uses static linking. See Static Executables under DESCRIPTION, and -B dynamic|static.
When building an executable, uses name as the path name of the interpreter to be written into the program header. The default in static mode is no interpreter. In dynamic mode, the default is the name of the runtime linker, ld.so.1(1). Either case can be overridden by -I name. exec(2) loads this interpreter when the a.out is loaded, and passes control to the interpreter rather than to the a.out directly.
Used only when building a dynamic executable. Specifies that references to external absolute symbols should be resolved immediately instead of being left for resolution at runtime. In very specialized circumstances, this option removes text relocations that can result in excessive swap space demands by an executable.
By default, ld combines multiple relocation sections when building executables or shared objects. This section combination differs from relocatable objects, in which relocation sections are maintained in a one-to-one relationship with the sections to which the relocations must be applied. The -z nocombreloc option disables this merging of relocation sections, and preserves the one-to-one relationship found in the original relocatable objects.
ld sorts the entries of data relocation sections by their symbol reference. This sorting reduces runtime symbol lookup. When multiple relocation sections are combined, this sorting produces the least possible relocation overhead when objects are loaded into memory, and speeds the runtime loading of dynamic objects.
Historically, the individual relocation sections were carried over to any executable or shared object, and the -z combreloc option was required to enable the relocation section merging previously described. Relocation section merging is now the default. The -z combreloc option is still accepted for the benefit of old build environments, but the option is unnecessary, and has no effect.
Assigns, or deassigns each dependency that follows to a unique group. The assignment of a dependency to a group has the same effect as if the dependency had been built using the -B group option.
Disables the compression of ELF string tables, and comment sections. By default, string compression is applied to SHT_STRTAB sections, to SHT_PROGBITS sections that have their SHF_MERGE and SHF_STRINGS section flags set, and to comment sections.
The mcs(1) utility, together with -c option, can be used to compress comment sections after an object has been built.
Marks the object so that the runtime default library search path, used after any LD_LIBRARY_PATH or runpaths, is ignored. This option implies that all dependencies of the object can be satisfied from its runpath.
Prevents the inclusion of a .SUNW_ldynsym section in a dynamic executable or shared object. The .SUNW_ldynsym section augments the .dynsym section by providing symbols for local functions. Local function symbols allow debuggers to display local function names in stack traces from stripped programs. Similarly, dladdr(3C) is able to supply more accurate results.
The -z noldynsym option also prevents the inclusion of the two symbol sort sections that are related to the .SUNW_ldynsym section. The .SUNW_dynsymsort section provides sorted access to regular function and variable symbols. The .SUNW_dyntlssort section provides sorted access to thread local storage (TLS) variable symbols.
The .SUNW_ldynsym, .SUNW_dynsymsort, and .SUNW_dyntlssort sections, which becomes part of the allocable text segment of the resulting file, cannot be removed by strip(1). Therefore, the -z noldynsym option is the only way to prevent their inclusion.
Partially initialized symbols, that are defined within relocatable objects, are expanded in the output file being generated.
Marks the object as requiring non-lazy runtime binding. This mode is similar to adding the object to the process by using dlopen(3C) with the RTLD_NOW mode. This mode is also similar to having the LD_BIND_NOW environment variable in effect. See ld.so.1(1).
Marks the object as requiring immediate $ORIGIN processing at runtime. This option is only maintained for historic compatibility, as the runtime analysis of objects to provide for $ORIGIN processing is now default.
Eliminates all local symbols except for the SECT symbols from the symbol table SHT_SYMTAB. All relocations that refer to local symbols are updated to refer to the corresponding SECT symbol. This option allows specialized objects to greatly reduce their symbol table sizes. See also the -z strip-class and -z noldynsym options.
Although useful for special objects such as those used within the operating system kernel, the -z redlocsym option is not recommended for general use. The size of the symbol table SHT_SYMTAB does not effect runtime behavior, and the elimination of local symbols can negatively effect process observability. Eliminated local symbols can reduce the debugging information that is generated using the compiler drivers -g option. Eliminated local symbols will also remove the information normally written to the .SUNW_ldynsym section, reducing the effectiveness of debuggers and tools such as pstack(1) and truss(1).
A position independent option that causes a rescan of the archive files that are provided to the link-edit. The link-editor defers the rescan operation until after it has processed the entire command line, and then initiates a final rescan operation over all archives seen on the command line. The -z rescan operation can interact incorrectly with objects that contain initialization (.init) or finalization (.fini) sections, preventing the code in those sections from running. For this reason, -z rescan is deprecated, and use of -z rescan-now is advised.
An alternative link-editor path name. ld executes, and passes control to this alternative link-editor. This environment variable provides a generic means of overriding the default link-editor that is called from the various compiler drivers. See the -z altexec64 option.
A list of directories in which to search for the libraries specified using the -l option. Multiple directories are separated by a colon. In the most general case, this environment variable contains two directory lists separated by a semicolon.
dirlist1;dirlist2
If ld is called with any number of occurrences of -L, as in:
ld ... -Lpath1 ... -Lpathn ...
then the search path ordering is:
dirlist1 path1 ... pathn dirlist2 LIBPATH
When the list of directories does not contain a semicolon, the list is interpreted as dirlist2.
The LD_LIBRARY_PATH environment variable also affects the runtime linkers search for dynamic dependencies.
This environment variable can be specified with a _32 or _64 suffix. This makes the environment variable specific, respectively, to 32–bit or 64–bit processes and overrides any non-suffixed version of the environment variable that is in effect.
Suppresses the automatic execution of the 64–bit link-editor. By default, the link-editor executes the 64–bit version when the ELF class of the first relocatable object identifies a 64–bit object. The 64–bit image that a 32–bit link-editor can create, has some limitations. However, some link-edits might find the use of the 32–bit link-editor faster.
A default set of options to ld. LD_OPTIONS is interpreted by ld just as though its value had been placed on the command line, immediately following the name used to invoke ld, as in:
ld $LD_OPTIONS ... other-arguments ...
An alternative mechanism for specifying a runpath to the link-editor. See the -R option. If both LD_RUN_PATH and the -R option are specified, -R supersedes.
Provides a colon-separated list of shared objects that are loaded with the link-editor and given information regarding the linking process. This environment variable can be specified with a _32 or _64 suffix. This makes the environment variable specific, respectively, to the 32–bit or 64–bit class of ld and overrides any non-suffixed version of the environment variable that is in effect. See the -S option.
Notice that environment variable-names that begin with the characters 'LD_' are reserved for possible future enhancements to ld and ld.so.1(1).
shared object libraries.
archive libraries.
default output file.
For 32–bit libraries, the default search path is /lib, followed by /usr/lib. For 64–bit libraries, the default search path is /lib/64, followed by /usr/lib/64.
A directory containing several mapfiles that can be used during link-editing. These mapfiles provide various capabilities, such as defining memory layouts, aligning bss, and defining non-executable stacks.
See attributes(5) for descriptions of the following attributes:
|
as(1), crle(1), gprof(1), ld.so.1(1), ldd(1), mcs(1), pvs(1), strip(1), exec(2), stat(2), dlopen(3C), dldump(3C), elf(3ELF), ar.h(3HEAD), a.out(4), attributes(5)
Default options applied by ld are maintained for historic reasons. In today's programming environment, where dynamic objects dominate, alternative defaults would often make more sense. However, historic defaults must be maintained to ensure compatibility with existing program development environments. Historic defaults are called out wherever possible in this manual. For a description of the current recommended options, see Chapter 7, Link-Editor Quick Reference, in Linker and Libraries Guide.
If the file being created by ld already exists, the file is unlinked after all input files have been processed. A new file with the specified name is then created. This allows ld to create a new version of the file, while simultaneously allowing existing processes that are accessing the old file contents to continue running. If the old file has no other links, the disk space of the removed file is freed when the last process referencing the file terminates.
The behavior of ld when the file being created already exists was changed with Oracle Solaris 11. In older versions, the existing file was rewritten in place, an approach with the potential to corrupt any running processes that is using the file. This change has an implication for output files that have multiple hard links in the file system. Previously, all links would remain intact, with all links accessing the new file contents. The new ld behavior breaks such links, with the result that only the specified output file name references the new file. All the other links continue to reference the old file. To ensure consistent behavior, applications that rely on multiple hard links to linker output files should explicitly remove and relink the other file names.