Linker and Libraries Guide

Direct Binding

When creating an object to use direct bindings, the relationship between the referenced symbol and the dependency that provided the definition is recorded in the object. 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.

Direct bindings can be established with one of the following mechanisms.

The direct binding model can significantly reduce the symbol lookup overhead within 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.

Direct binding can circumvent the traditional use of interposition symbols because it bypasses the default search model. The default model ensures that all references to a symbol bind to one definition.

Interposition can still be achieved in a direct binding environment, on a per-object basis, if an object is identified as an interposer. Any object loaded using the environment variable LD_PRELOAD or created with the link-editor's -z interpose option, is identified as an interposer. When the runtime linker searches for a directly bound symbol, it first looks in any object identified as an interposer before it looks in the object that supplies the symbol definition.


Note –

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


Some interfaces exist that offer alternative implementations of a default technology. These implementations also assume they are the only instance of that technology within a process. An example of this is the malloc(3C) family. Directly binding to interfaces within such a family should be avoided, as it is possible for more than one instance of the technology to be referenced by the same process. For example, one dependency within a process may directly bind against libc.so.1, while another dependency directly binds against libmapmalloc.so.1.

Objects that provide a single implementation for a process, should define the interfaces to that implementation using the mapfile directive NODIRECT. This directive insures no users directly bind to an implementation, but use the default symbol search model.


Note –

NODIRECT mapfile directives can be combined with the command line options -B direct or -z direct. Symbols that are not explicitly defined NODIRECT will follow the command line directive.