Linker and Libraries Guide

Direct Bindings

An object that uses direct bindings maintains the relationship between a symbol reference and the dependency that provided the definition. The runtime linker uses this information to search directly for the symbol in the associated object, rather than carry out the default symbol search model. Direct binding information can only be established to dependencies specified with the link-edit. Therefore, use of the -z defs option is recommended.

The direct binding of a symbol reference to a symbol definition can be established with one of the following mechanisms.

Direct binding can significantly reduce the symbol lookup overhead incurred by a dynamic process that has many symbolic relocations and many dependencies. This model also enables multiple symbols of the same name to be located from different objects that have been bound to directly.


Note –

Direct bindings can be disabled at runtime by setting the environment variable LD_NODIRECT to a non-null value.


The default symbol search model allows all references to a symbol to bind to one definition. Direct binding circumvents implicit interposition symbols, as direct bindings bypass the default search model. However, any object explicitly identified as an interposer is searched before the object that supplies the symbol definition. Explicit interposers include objects loaded using the environment variable LD_PRELOAD, or objects created with the link-editor's -z interpose option. See Runtime Interposition.

Some interfaces exist to provide alternative implementations of a default technology. These interfaces expect their implementation to be the only instance of that technology within a process. An example is the malloc(3C) family. There are various malloc() family implementations, and each family expects to be the only implementation used within a process. The direct binding to an interface within such a family should be avoided, otherwise more than one instance of the technology can be referenced by the same process. For example, one dependency within a process can directly bind against libc.so.1, while another dependency directly binds against libmapmalloc.so.1. The potential for inconsistent use of two different implementations of malloc() and free() is error prone.

Objects that provide interfaces that expect to be single-instance within a process, should prevent any direct binding to their interfaces. An interface can be labelled to prevent any caller from directly binding to the interface with one of the following mechanisms.

Non-direct labelling prevents any symbol reference from directly binding to an implementation. The symbol search to satisfy the reference uses the default symbol search model. Non-direct labelling has been employed to build the various malloc() family implementations that are provided with the Solaris OS.


Note –

The NODIRECT mapfile keyword can be combined with the command line options -B direct or -z direct. Symbols that are not explicitly defined NODIRECT follow the command line directive. Similarly, the DIRECT mapfile keyword can be combined with the command line option -B nodirect. Symbols that are not explicitly defined DIRECT follow the command line directive.