Kenwood HP 9000 Personal Computer User Manual


 
182 Chapter 5
Creating and Using Libraries
Using Shared Libraries in 64-bit mode
cc -c main.c
cc -c +z a.c b.c
ld -b a.o -o libA.sl
ld -b b.o -o libB.sl
cc main.o libA.sl libB.sl -o test3
The 32-bit mode linker toolset produces:
$ test3
object is 1
The 32-bit mode linker toolset defines the object global variable in
libA.sl as a storage export symbol. The dynamic loader, when
searching for a definition of object to satisfy the import request in
libA.sl, does not stop with the storage export in that library. It
continues to see if there is a data export symbol for the same symbol
definition.
The 64-bit mode linker toolset produces:
$ test 3
object is 0
The 64-bit mode linker toolset does not allow storage exports from a
shared library. The uninitialized variable called object in a.o turns
into a data export in libA.sl, with an initial value of 0. During symbol
resolution for the import request from that same library, the dynamic
loader stops with the first seen definition.
Symbol Searching in Dependent Libraries
In the 64-bit mode linker toolset, the linker searches dependent
libraries in a breadth-first order for symbol resolution. This means it
searches libraries linked to the main program file before libraries linked
to shared libraries. This behavior change is consistent with other SVR4
systems. The linker also searches siblings of a dependent shared library
before its children. For example, using the structure described in Figure
5-25, if libD had dependent libraries libDK and libLH, libD, libE, libF,
then libDK, libLH would be searched in that order. The dlopen library
management routines and executable files (a.out) created by the linker
with the +std option (default) use the breadth-first search order.
The 32-bit mode linker toolset searches dependent libraries in a
depth-first order. This means it searches dependent shared library files
in the order in which they are linked to shared libraries. The shl_load
library management routines and executable files (a.out) created by the
linker with the +compat option use the depth-first search order.