This manual describes the operations of the Solaris link-editor and runtime linker, together with the objects on which they operate. The basic operation of the Solaris linkers involves the combination of objects and the connection of symbolic references from one object to the symbolic definitions within another. This operation is often referred to as binding.
This manual expands on the following areas:
The link-editor, ld(1), concatenates one or more input files (either relocatable objects, shared objects, or archive libraries) to produce one output file (either a relocatable object, an executable application, or a shared object). The link-editor is most commonly invoked as part of the compilation environment (see cc(1)).
The runtime linker, ld.so.1(1) [ld.so.1 is a special case of a shared object and therefore allows itself to be versioned. Here a version number of 1 is used, however later releases of Solaris might provide higher version numbers.] , processes dynamic executables and shared objects at runtime, and binds them to create a runable process.
Shared objects (sometimes referred to as Shared Libraries) are one form of output from the link-edit phase. However, their importance in creating a powerful, flexible runtime environment warrants a section of its own.
The Solaris linkers work with files that conform to the executable and linking format (ELF).
These areas, although separable into individual topics, have a great deal of overlap. While explaining each area, this document brings together the connecting principles and designs.
Link-editing takes a variety of input files, from cc(1), as(1) or ld(1), and concatenates and interprets the data within these input files to form a single output file. Although the link-editor provides numerous options, the output file produced is one of four basic types:
A concatenation of input relocatable objects, which can be used in subsequent link-edit phases.
A concatenation of input relocatable objects that has all symbolic references bound to the executable, and thus represents a ready-to-run process.
A concatenation of input relocatable objects that requires intervention by the runtime linker to produce a runable process. Its symbolic references might still need to be bound at runtime, and it might have one or more dependencies in the form of shared objects.
A concatenation of input relocatable objects that provides services that might be bound to a dynamic executable at runtime. The shared object might also have dependencies on other shared objects.
These output files, and the key link-editor options used to create them, are shown in Figure 1-1.
Dynamic executables and shared objects are often referred to jointly as dynamic objects and are the main focus of this document.
Runtime linking involves the binding of objects, usually generated from one or more previous link-edits, to generate a runable process. During the generation of these objects by the link-editor, the binding requirements are verified and appropriate bookkeeping information is added to each object to allow the runtime linker to map, relocate, and complete the binding process.
During the execution of the process, the facilities of the runtime linker are also made available and can be used to extend the process' address space by adding additional shared objects on demand. The two most common components involved in runtime linking are dynamic executables and shared objects.
Dynamic executables are applications that are executed under the control of a runtime linker. These applications usually have dependencies in the form of shared objects, which are located and bound by the runtime linker to create a runable process. Dynamic executables are the default output file generated by the link-editor.
Shared objects provide the key building block to a dynamically linked system. Basically, a shared object is similar to a dynamic executable; however, shared objects have not yet been assigned a virtual address.
Dynamic executables usually have dependencies on one or more shared objects. That is, the shared object(s) must be bound to the dynamic executable to produce a runable process. Because shared objects can be used by many applications, aspects of their construction directly affect shareability, versioning, and performance.
You can distinguish the processing of shared objects by either the link-editor or the runtime linker by referring to the environments in which the shared objects are being used:
Shared objects are processed by the link-editor to generate dynamic executables or other shared objects. The shared objects become dependencies of the output file being generated.
Shared objects are processed by the runtime linker, together with a dynamic executable, to produce a runable process.
Dynamic linking is a term often used to embrace those portions of the link-editing process that generate dynamic executables and shared objects, together with the runtime linking of these objects to generate a runable process. Dynamic linking allows multiple applications to use the code provided by a shared object by enabling the application to bind to the shared object at runtime.
By separating an application from the services of standard libraries, dynamic linking also increases the portability and extensibility of an application. This separation between the interface of a service and its implementation enables the system to evolve while maintaining application stability, and is a crucial factor in providing an application binary interface (ABI). Dynamic linking is the preferred compilation method for Solaris applications.
To enable the asynchronous evolution of system and application components, binary interfaces between these facilities are defined. The Solaris linkers operate upon these interfaces to assemble applications for execution. Although all components handled by the Solaris linkers have binary interfaces, one family of such interfaces of particular interest to applications writers is the System V Application Binary Interface.
The System V Application Binary Interface, or ABI, defines a system interface for compiled application programs. Its purpose is to document a standard binary interface for application programs on systems that implement the System V Interface Definition, Third Edition. Solaris provides for the generation and execution of ABI-conforming applications. On SPARCTM systems, the ABI is contained as a subset of the SPARC(R) Compliance Definition (SCD).
Many of the topics covered in the following chapters are influenced by the ABI. For more detailed information, see the appropriate ABI manuals.
The link-editors operate on 32-bit objects, and on SPARCV9 systems are also capable of operating on 64-bit objects. In fact on SPARC systems the 64-bit link-editor (ld(1)) is capable of generating 32-bit objects and the 32-bit link-editor is capable of generating 64-bit objects (however, in the latter case, the size of the generated object, not including the .bss, is restricted to 2 gigabytes).
There is no command line option required to distinguish 32-bit or 64-bit objects. The link-editor uses the ELF class of the first input relocatable file it sees to govern the mode in which it will operate. Intermixing of 32-bit and 64-bit objects is not permitted.
In general the operations of the link-editors on 32-bit and 64-bit objects is identical; however, this document typically uses 32-bit examples. Cases where 64-bit processing differs from the 32-bit processing are highlighted.
For more information regarding 64-bit applications refer to the Solaris 64-bit Developer's Guide.
Together with the objects mentioned in the previous sections come several support tools and libraries. These tools provide for the analysis and inspection of these objects and the linking processes. Among these tools are: elfdump(1), nm(1), dump(1), ldd(1), pvs(1), elf(3ELF), and a linker debugging support library. Throughout this document many discussions are augmented with examples of these tools.
This section gives an overview of new features and/or updates that have been added to this document and to which release they were added:
The secure directory from which files can be preloaded is now /usr/lib/secure for 32-bit objects and /usr/lib/secure/sparcv9 for 64-bit SPARC objects. See "Security".
Greater flexibility in modifying the runtime linkers search paths can be achieved with the link-editors -z nodefaultlib option, and runtime configuration files created by the new utility crle(1). See "Directories Searched by the Runtime Linker" and "Configuring the Default Search Paths".
The new extern mapfile directive provides for -z defs usage with externally defined symbols. See "Defining Additional Symbols".
Greater flexibility in establishing instruction set specific, and system specific dependencies is provided with the new $ISALIST, $OSNAME and $OSREL dynamic string tokens. See "Dynamic String Tokens".
Some cautionary notes on the use of the link-editors -Bsymbolic option are provided in "The Use of -Bsymbolic".
Additional means of invoking runtime link auditing libraries is provided by the link-editor options -p and -P. See "Recording Local Auditors". Additional runtime link auditing interfaces la_activity() and la_objsearch(), have been added. See "Audit Interface Functions".
Coordination of ELF files with core images is possible with a new dynamic section tag, DT_CHECKSUM. See Table 7-41.
The 64-bit ELF object format is now supported. See "File Format" for details. Link-editor extensions and differences for 64-bit processing
include: the use of /usr/lib/sparcv9 (see "Directories Searched by the Link-Editor", "Directories Searched by the Runtime Linker" and "Naming Conventions"), the environment variable LD_LIBRARY_PATH_64
(see "Using an Environment Variable" and "Directories Searched by the Runtime Linker"), and the runtime linker /usr/lib/sparcv9/ld.so.1 (see "Overview").
Shared objects can be built with optimized relocation sections by using the link-editor -z combreloc option. See "Combined Relocation Sections".
Greater flexibility in establishing dependencies within unbundled software is provided with the new $ORIGIN dynamic string token. See "Dynamic String Tokens".
The loading of a shared object can now be deferred until the object is actually referenced by the running program. See "Lazy Loading of Dynamic Dependencies".
The SHT_SUNW_COMDAT section has been added to allow for the elimination of multiply defined symbols. See "Comdat Section".
The SHT_SUNW_move section has been added to allow for partially initialized symbols. See "Move Section".
Additional runtime link auditing interfaces la_symbind64(), la_sparcv9_pltenter() and la_pltexit64(), together with a new link-auditing flag LA_SYMB_ALTVALUE, have been added. See "Audit Interface Functions".
Weak symbol references can trigger archive member extraction by using the link-editor -z weakextract option. Extracting all archive members can be achieved using the -z allextract option. See "Archive Processing".
Shared objects specified as part of a link-edit that are not referenced by the object being built can be ignored, and hence their dependency recording suppressed, using the -z ignore option. See "Shared Object Processing".
The link-editor generates the reserved symbols _START_ and _END_ to provide a means of establishing an objects address range. See "Generating the Output Image".
Changes have been made to the runtime ordering of initialization and finalization code to better accommodate dependency requirements. See "Debugging Aids".
Symbol resolution semantics have been expanded for dlopen(3DL). See "Symbol Lookup", RTLD_GROUP in "Isolating a Group", and RTLD_PARENT in "Object Hierarchies".
Symbol lookup semantics have been expanded with a new dlsym(3DL) handle RTLD_DEFAULT. See "Default Symbol Lookup Model".
Extensions have been made to filter processing that allow more than one filtee to be defined, and provide for forcibly loading filtees. An example of creating a platform specific filter is also provided. See "Shared Objects as Filters".
Recording additional version dependencies can be achieved using the mapfile file control directive $ADDVERS. See "Binding to Additional Version Definitions".
A runtime linker audit interface provides support for monitoring and modifying a dynamically linked application from within the process. See "Runtime Linker Auditing Interface".
A runtime linker debugger interface provides support for monitoring and modifying a dynamically linked application from an external process. See "Runtime Linker Debugger Interface".
Additional section types are supported. See Table 7-11 for SHN_BEFORE and SHN_AFTER, and see Table 7-14 for SHF_ORDERED and SHF_EXCLUDE.
A new dynamic section tag, DT_1_FLAGS, is supported. See Table 7-42 for the various flag values.
A package of demonstration ELF programs is provided. See Chapter 7, Object Files.
The link-editors now support internationalized messages. All system errors are reported using strerror(3C).