Chapter 5 141
Creating and Using Libraries
Creating Shared Libraries
Thereafter, any programs that load libdep.sl — either explicitly with
shl_load or implicitly with the dynamic loader when the program
begins execution — also automatically load the dependent libraries
libcurses.sl and libcustom.sl.
There are two additional issues that may be important to some shared
library developers:
• When a shared library with dependencies is loaded, in what order are
the dependent libraries loaded?
• Where are all the dependent libraries placed in relation to other
already loaded libraries? That is, where are they placed in the
process's shared library search list used by the dynamic loader?
The Order in Which Libraries Are Loaded (Load
Graph)
When a shared library with dependencies is loaded, the dynamic loader
builds a load graph to determine the order in which the dependent
libraries are loaded.
For example, suppose you create three libraries — libQ, libD, and libP
— using the ld commands below. The order in which the libraries are
built is important because a library must exist before you can specify it
as a dependent library.
$ ld -b -o libQ.sl modq.o -lB
$ ld -b -o libD.sl modd.o -lQ -lB
$ ld -b -o libP.sl modp.o -lA -lD -lQ
The dependency lists for these three libraries are:
• libQ depends on libB
• libD depends on libQ and libB
• libP depends on libA, libD, and libQ
+-->libA.sl
|
libP.sl-->libD------+
||
|v
+-->libQ.sl-->libB.sl
For 32-bit mode. The loader uses the following algorithm in 32-bit
mode: