HP-UX Linker and Libraries User's Guide
What are Shared Libraries?.....................................................................................................91
The Dynamic Loader ..........................................................................................................91
Default Behavior When Searching for Libraries at Run Time.....................................................91
Caution on Using Dynamic Library Searching........................................................................92
Running setuid Programs.....................................................................................................92
Example Program Comparing Shared and Archive Libraries.........................................................92
Shared Libraries with Debuggers, Profilers, and Static Analysis.....................................................94
Profiling Shared Libraries with gprof(1) .................................................................................94
Creating Archive Libraries........................................................................................................94
Overview of Creating an Archive Library...............................................................................95
Contents of an Archive File..................................................................................................95
Example of Creating an Archive Library................................................................................96
Replacing, Adding, and Deleting an Object Module..............................................................97
Replacing or Adding an Object Module...........................................................................97
Deleting an Object Module............................................................................................97
Summary of Keys to the ar(1) Command................................................................................97
Useful ar Keys...............................................................................................................97
crt0.o..........................................................................................................................98
Archive Library Location (IPF) ..............................................................................................98
Using /usr/lib and /usr/lib/pa20_64 ...........................................................................98
Using /usr/local/lib or /usr/contrib/lib..........................................................................98
Creating Shared Libraries........................................................................................................98
Creating Position-Independent Code (PIC).............................................................................99
Example Using +z.........................................................................................................99
Comparing +z and +Z...................................................................................................99
Compiler Support for +z and +Z.....................................................................................99
Creating the Shared Library with ld......................................................................................99
Shared Library Dependencies............................................................................................100
The Order in Which Libraries are Loaded (Load Graph)...................................................100
Placing Loaded Libraries in the Search List......................................................................101
Updating a Shared Library................................................................................................102
Incompatible Changes to a Shared Library.....................................................................102
Shared Library Location (IPF).............................................................................................102
Improving Shared Library Performance................................................................................102
Loading Shared Libraries with the LD_PRELOAD Environment Variable................................103
LD_PRELOAD Example.................................................................................................103
LD_PRELOAD Example (PA-RISC)...................................................................................104
64-bit Behavior......................................................................................................104
32-bit Behavior.......................................................................................................105
Loading Shared Libraries with the LD_PRELOAD_ONCE Environment Variable.....................106
Using Profile-Based Optimization on Shared Libraries.......................................................106
Exporting Only the Required Symbols............................................................................106
Placing Frequently-Called Routines Together....................................................................106
Making Shared Libraries Non-Writable..........................................................................107
Using the +ESlit/+Olit=all Option to cc..........................................................................107
+cond_rodata Command-Line Option............................................................................108
Using Filtered Shared Libraries (32-bit Mode Only)..........................................................108
Building Filtered Shared Libraries..............................................................................108
Building application programs linked to filtered shared libraries....................................109
Run time behavior of filtered shared libraries..............................................................109
Initializers..............................................................................................................109
Dynamic Path Lookup..............................................................................................110
Thread-Private Data (TLS).........................................................................................110
Maintaining filtered shared libraries..........................................................................110
Function Level Versioning..................................................................................................110
6 Contents