Linker and Libraries Guide

Binding to a Weak Version

Creating a Weak Version Definition described how weak version definitions can be used to mark an internal implementation change. These version definitions are well suited to indicate bug fixes and performance improvements made to an object. If the existence of a weak version is required, an explicit dependency on this version definition can be generated. The creation of such a dependency can be important when a bug fix, or performance improvement, is critical for the object to function correctly.

From the previous example, assume a bug fix is incorporated as the weak version definition SUNW_1.2.1 in software Release X+3:

$ pvs -dsv
        SUNW_1.1:           {STAND_A, STAND_B}:
        SUNW_1.2:           {SUNW_1.1}:
        SUNW_1.2.1 [WEAK]:  {SUNW_1.2}:

Normally, if an application is built against this, the application records a weak dependency on the version definition SUNW_1.2.1. This dependency is informational only. This dependency does not cause termination of the application should the version definition not exist in the implementation of that is used at runtime.

The REQUIRE attribute to the DEPEND_VERSIONS mapfile directive can be used to generate an explicit dependency on a version definition. If this definition is weak, then this explicit reference also the version definition to be promoted to a strong dependency.

The application prog can be built to enforce the requirement that the SUNW_1.2.1 interface be available at runtime by using the following file control directive.

$ cat mapfile
$mapfile_version 2
        ALLOW = SUNW_1.1;
        REQUIRE = SUNW_1.2.1;
$ cat prog
extern void foo1();

$ cc -M mapfile -o prog prog.c -L. -R. -lfoo
$ pvs -r prog (SUNW_1.2.1);

prog has an explicit dependency on the interface STAND_A. Because the version definition SUNW_1.2.1 is promoted to a strong version, the version SUNW_1.2.1 is normalized with the dependency STAND_A. At runtime, if the version definition SUNW_1.2.1 cannot be found, a fatal error is generated.

Note –

When working with a small number of dependencies, you can use the link-editor's -u option to explicitly bind to a version definition. Use this option to reference the version definition symbol. However, a symbol reference is nonselective. When working with multiple dependencies, that contain similarly named version definitions, this technique might be insufficient to create explicit bindings.