Oracle® Solaris 11.2 Linkers and Libraries Guide

Exit Print View

Updated: July 2014

Locating Associated Dependencies

Typically, an unbundled product is designed to be installed in a unique location. This product is composed of binaries, shared object dependencies, and associated configuration files. For example, the unbundled product ABC might have the layout shown in the following figure.

Figure 10-1  Unbundled Dependencies

image:Unbundled dependencies example.

Assume that the product is designed for installation under /opt. Normally, you would augment your PATH with /opt/ABC/bin to locate the product's binaries. Each binary locates their dependencies using a hard-coded runpath within the binary. For the application abc, this runpath would be as follows.

$ cc -o abc abc.c -R/opt/ABC/lib -L/opt/ABC/lib -lA
$ elfdump -d abc | egrep 'NEEDED|RUNPATH'
     [0]  NEEDED           0x1b5      
     [4]  RUNPATH          0x1bf                /opt/ABC/lib

Similarly, for the dependency the runpath would be as follows.

$ cc -o -G -Kpic A.c -R/opt/ABC/lib -L/opt/ABC/lib -lB
$ elfdump -d | egrep 'NEEDED|RUNPATH'
     [0]  NEEDED            0x96      
     [4]  RUNPATH           0xa0                /opt/ABC/lib

This dependency representation works until the product is installed in some directory other than the recommended default.

The dynamic token $ORIGIN expands to the directory in which an object originated. This token is available for filters, runpath, or dependency definitions. Use this technology to redefine the unbundled application to locate its dependencies in terms of $ORIGIN.

$ cc -o abc abc.c '-R$ORIGIN/../lib' -L/opt/ABC/lib -lA
$ elfdump -d abc | egrep 'NEEDED|RUNPATH'
     [0]  NEEDED           0x1b5      
     [4]  RUNPATH          0x1bf                $ORIGIN/../lib

The dependency can also be defined in terms of $ORIGIN.

$ cc -o -G -Kpic A.c '-R$ORIGIN' -L/opt/ABC/lib -lB
$ elfdump -d lib/ | egrep 'NEEDED|RUNPATH'
     [0]  NEEDED            0x96      
     [4]  RUNPATH           0xa0                $ORIGIN

If this product is now installed under /usr/local/ABC and your PATH is augmented with /usr/local/ABC/bin, invocation of the application abc result in a path name lookup for its dependencies as follows.

$ ldd -s abc
  find; required by abc
    search path=$ORIGIN/../lib  (RUNPATH/RPATH from file abc)
      trying path=/usr/local/ABC/lib/ =>     /usr/local/ABC/lib/

  find; required by /usr/local/ABC/lib/
    search path=$ORIGIN  (RUNPATH/RPATH from file /usr/local/ABC/lib/
      trying path=/usr/local/ABC/lib/ =>     /usr/local/ABC/lib/

Note - Objects that contain a $ORIGIN token can be referenced using a symbolic link. In this case, the symbolic link is fully resolved in order to determine the true origin of the object.