$ cc -c ?.c

$ ld -b -o libB.so b.o $ ld -b -o libA.so a.o $ cc foo.c -L. -lA -lB

ldd(1) shows the order in which the shared libraries are loaded:

$ ldd a.out

 

libA.so

=>

./libA.so

libB.so

=>

./libB.so

libc.so.1 =>

/usr/lib/hpux32/libc.so.1

libdl.so.1 =>

/usr/lib/hpux32/libdl.so.1

The symbol resolution order for the user libraries is:

a.out- ->libA.so --> libB.so

If the LD_PRELOAD environment variable is set to "./libC.so", the symbol resolution order is:

$ export LD_PRELOAD=./libC.so

$ ldd a.out

 

./libC.so =>

./libC.so

libA.so =>

./libA.so

libB.so =>

./libB.so

libc.so.1 =>

/usr/lib/hpux32/libc.so.1

libdl.so.1 =>

/usr/lib/hpux32/libdl.so.1

a.out -->libC.so -->libA.so -->libB.so

LD_PRELOAD Example (PA-RISC)

The PA64 linker toolset searches dependent libraries in a breadth-first order for symbol resolution. The PA32 linker toolset searches in depth-first order. Therefore, the library load order and symbol resolution order may differ depending on which mode is used. Consider a case where a.out has the following dependents:

a.out

/\

libA.sl libB.sl

/\

libC.sl libD.sl

That is, a.out is built with commands like these:

$ cc +DA2.0W -c +z ?.c $ ld -b -o libB.sl b.o $ ld -b -o libC.sl c.o $ ld -b -o libD.sl d.o

$ ld -b -o libA.sl a.o -L. -lC -lD $ cc foo.c -L. -lA -lB

64-bit Behavior

In 64-bit mode, ldd(1) shows the order in which the shared libraries are loaded (siblings first, then dependents):

$ ldd a.out

 

libA.sl =>

./libA.sl

libB.sl =>

./libB.sl

libc.2 =>

/usr/lib/pa20_64/libc.2

libC.sl =>

./libC.sl

libD.sl =>

./libD.sl

libdl.1 =>

/usr/lib/pa20_64/libdl.1

Therefore, with LD_PRELOAD unset, the symbol resolution order for the user libraries in 64-bit mode is:

a.out- -> libA.sl --> libB.sl --> libC.sl -->libD.sl

Case (i): LD_PRELOAD="./libB.sl" In 64-bit mode, the symbol resolution order is:

104 Creating and Using Libraries

Page 104
Image 104
HP UX Software Transition Kit (STK) manual Ldpreload Example PA-RISC, Symbol resolution order for the user libraries is