Chapter 6 201
Shared Library Management Routines
Initializers for Shared Libraries
Initializers for Shared Libraries
A shared library can have an initialization routine—known as an
initializer—that is called when the load module (a shared library or
executable) is loaded (initializer) or explicitly unloaded (terminator).
Typically, an initializer is used to initialize a shared library's data when
the library is loaded.
When a program begins execution its initializers are called before any
other user code is executed.This allow for setup at initialization and
cleanup at termination. Also, when a shared library is explicitly loaded
using shl_load or dlopen or unloaded using shl_unload or dlclose,
it initializers and terminators are called at the appropriate time.
In 64-bit mode, you can specify initializers and terminators even for
archive libraries or nonshared executables.
Styles of Initializers
The linker supports two different types of initializers and terminators:
• HP-UX 10.X style.
• Init/fini style.
NOTE The 32-bit mode linker supports only the HP-UX 10.X style initializers.
See “32-bit Mode Initializers” for more information.
The 64-bit mode linker supports both of these styles.See “64-bit Mode
Initializers” for more information.
HP-UX-10.X-Style Initializers
HP-UX 10.X style initializers are the same type supported in all HP-UX
10.X releases. These are called both before the user’s code is started or a
shared library is loaded (using shl_load or dlopen) as well as when
the shared library is unloaded (using shl_unload or dlclose). The
linker option +I is used to create this type of initializer. The function
returns nothing but takes two arguments. The first is a handle to the
shared library being initialized. This handle can be used in calling
shl_load routines. The second is set to non-zero at startup and zero at
program termination.