Dynamic Path Searching for Shared Libraries

Any library whose name has no "/" character in it becomes a candidate for dynamic path searching. Also, the linker always uses the LD_LIBRARY_PATH and the SHLIB_PATH environment variable to add directories to the run time search path for shared libraries, unless the ld +noenvvar option is set.

In PA-32 compatibility mode of the linker toolset (selected by the +compat option), the linker enables run-time dynamic path searching when you link a program with the -llibraryand +b path_name options. Or, you can use the -llibrary option with the +s path_name option. When programs are linked with +s, the dynamic loader searches directories specified by the SHLIB_PATH environment variable to find shared libraries.

The following example shows dynamic path searching changes for default mode.

$ ld main.o \

Subject to

-lfoo -o main

dynamic path searching.

The dynamic loader searches for libfoo.so in the directories specified by the LD_LIBRARY_PATH and SHLIB_PATH environment variables.

Shared Library Symbol Binding Semantics

Symbol binding resolution, both at link time and run time, changes slightly in the IPF and PA-64 HP-UX linker toolset. The symbol binding policy is more compatible with other open systems.

This section covers the following topics:

Link-time symbol resolution in shared libraries

Resolution of unsatisfied shared library references

Promotion of uninitialized global variables

Symbol searching in dependent libraries

Link-Time Symbol Resolution in Shared Libraries

In the IPF and PA-64 linker toolset, the linker remembers all symbols in a shared library for the duration of the link. Global definitions satisfy trailing references, and unsatisfied symbols remaining in shared libraries are reported.

The PA-32 linker does not remember the definition of a procedure in a shared library unless it was referenced in previously scanned object files.

If you have function names that are duplicated in a shared and archive library, the IPF and PA-64 linker may reference a different version of a procedure than is referenced by the PA-32 mode linker. This change can lead to unexpected results.

For example, given these source files:

sharedlib.c

void afunc()

{

printf("\tin SHARED library procedure 'afunc'\n");

}

unsat.c

void bfunc()

{

afunc();

}

archive.c

126 Creating and Using Libraries