Go to main content

Oracle® Solaris 11.4 Linkers and Libraries Guide

Exit Print View

Updated: March 2019
 
 

Link Editing With the Link-Editor

The link-editor, ld(1), takes a variety of input files, typically generated from compilers, assemblers, or previous invocations of the link-editor. The link-editor concatenates and interprets the data within these input files to form an output file. The output file that is produced is one of the following basic types.

  • Dynamic Executable - A concatenation of relocatable objects that can be executed by exec(2). A dynamic executable is loaded at a fixed virtual address space and is executed under control of the runtime linker, ld.so.1(1), to produce a runtime process. Dynamic executables typically have one or more dependencies in the form of shared objects.

    A dynamic executable is created when the –z type=exec option is used, or is the default when no other options that control the output file type are provided.

  • Kernel Module - A special case of a relocatable object, containing dynamic linking information, that can be loaded by the operating system kernel. Kernel modules can have dependencies on other kernel modules.

    A kernel module is created when the –z type=kmod option is used.

  • Position-independent Executable (PIE) - A position independent form of a dynamic executable that can be executed by exec(2). A position-independent executable is loaded at an arbitrary virtual address space and is executed under control of the runtime linker, ld.so.1(1), to produce a runtime process. Position-independent executables typically have one or more dependencies in the form of shared objects.

    A position-independent executable is created when the –z type=pie option is used.

  • Relocatable Object - A concatenation of relocatable objects that can be used in subsequent link-edit phases.

    A relocatable object is created when the –z type=reloc option, or –r option are used.

  • Shared Object - A concatenation of relocatable objects that provide services for other dynamic objects. A shared object is loaded at an arbitrary virtual address space under the control of the runtime linker, ld.so.1(1), and is bound to executables, or other shared objects, at runtime. Shared objects can have dependencies on other shared objects.

    A shared object is created when the –z type=shared option, or –G option are used.

  • Static Executable - A concatenation of relocatable objects that can be executed directly by exec(2), without assistance from the runtime linker, ld.so.1(1).

    A static executable is created when the –z type=static option, or –a option are used. However, modern versions of the Oracle Solaris operating system do not support the creation of static executables. See Static Executables.

Dynamic executables and position-independent executables are collectively referred to as executables. These executables, together with shared objects, are collectively referred to as dynamic objects.

Shared objects and relocatable archives, created with ar(1), are collectively referred to as libraries.

To provide for efficient arbitrary virtual address space mapping, position-independent executables and shared objects should be created from position-independent code (PIC).

Static Executables

The creation of static executables has been discouraged for many releases. In fact, 64-bit system archive libraries have never been provided. Because a static executable is built against system archive libraries, the executable contains system implementation details. This self-containment has a number of drawbacks.

  • A static 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 static executable to run on future releases can be compromised.

  • The duplication of system implementation details negatively affects system performance.

Beginning with the Oracle Solaris 10 release, the OS no longer includes 32-bit system archive libraries. Without these libraries, specifically libc.a, the creation of a static executable is no longer achievable without specialized system knowledge. Note, that the link-editors ability to process static linking options, and the processing of archive libraries, remains unchanged.