Oracle® Solaris 11.2 Linkers and Libraries Guide

Exit Print View

Updated: July 2014

Using the –B direct Option

The –B direct option provides the simplest mechanism of enabling direct binding for any dynamic object. This option establishes direct bindings to any dependencies, and within the object being built.

From the components used in the previous example, a directly bound object,, can be produced.

$ cc -o -G -Kpic W.c -R. -Bdirect
$ cc -o prog2 -R. main.c

The direct binding information is maintained in a symbol information section, .SUNW_syminfo, within This section can be viewed with elfdump(1).

$ elfdump -y
     [6]  DB          <self>         a
     [7]  DBL     [1]         b

The letters “DB” indicates a direct binding has been recorded for the associated symbol. The function a() has been bound to the containing object The function b() has been bound directly to the dependency The letter “L” indicates that the dependency should also be lazily loaded.

The direct bindings that are established for can be observed using the LD_DEBUG environment variable. The detail token adds additional information to the binding diagnostics. For, this token indicates the direct nature of the binding. The detail token also provides additional information about the binding addresses. For simplification, this address information has been omitted from the output generated from the following examples.

$ LD_DEBUG=symbols,bindings,detail  prog2
18452: symbol=a;  lookup in file=./  [ ELF ]
18452: binding file=./ to file=./ symbol 'a'  (direct)
18452: symbol=b;  lookup in file=./  [ ELF ]
18452: binding file=./ to file=./ symbol 'b'  (direct)

The lari(1) utility can also reveal the direct binding information.

$ lari prog2
[2:2ESD]: a(): ./
[2:0]: a(): ./
[2:2ED]: b(): ./
[2:0]: b(): ./

The letter “D” indicates that the function a() defined by has been bound to directly. Similarly, the function b() defined in has been bound to directly.

Note - The direct binding of to for the function a() results in a similar effect as would be created had the –B symbolic option been used to build However, the –B symbolic option causes references such as a(), that can be resolved internally, to be finalized at link-edit time. This symbol resolution leaves no binding to resolve at runtime.

Unlike –B symbolic bindings, a –B direct binding is left for resolution at runtime. Therefore, this binding can be overridden by explicit interposition, or disabled by setting the environment variable LD_NODIRECT to a non-null value.

Symbolic bindings have often been employed to reduce the runtime relocation overhead incurred when loading complex objects. Direct bindings can be used to establish exactly the same symbol bindings. However, a runtime relocation is still required to create each direct binding. Direct bindings require more overhead than symbolic bindings, but provide for greater flexibility.