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.
Unbundled Dependencies
![Unbundled dependencies example. Unbundled dependencies example.](img/unblddep.jpg)
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 libA.so.1 .... [4] RUNPATH 0x1bf /opt/ABC/lib
Similarly, for the dependency libA.so.1
the runpath would be as follows.
$ cc -o libA.so.1 -G -Kpic A.c -R/opt/ABC/lib -L/opt/ABC/lib -lB $ elfdump -d libA.so.1 | egrep 'NEEDED|RUNPATH' [0] NEEDED 0x96 libB.so.1 [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 libA.so.1 .... [4] RUNPATH 0x1bf $ORIGIN/../lib
The dependency libA.so.1
can also be defined in terms of $ORIGIN
.
$ cc -o libA.so.1 -G -Kpic A.c '-R$ORIGIN' -L/opt/ABC/lib -lB $ elfdump -d lib/libA.so.1 | egrep 'NEEDED|RUNPATH' [0] NEEDED 0x96 libB.so.1 [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 object=libA.so.1; required by abc
search path=$ORIGIN/../lib (RUNPATH/RPATH from file abc)
trying path=/usr/local/ABC/lib/libA.so.1
libA.so.1 => /usr/local/ABC/lib/libA.so.1
find object=libB.so.1; required by /usr/local/ABC/lib/libA.so.1
search path=$ORIGIN (RUNPATH/RPATH from file /usr/local/ABC/lib/libA.so.1)
trying path=/usr/local/ABC/lib/libB.so.1
libB.so.1 => /usr/local/ABC/lib/libB.so.1
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.