Kenwood HP 9000 Personal Computer User Manual


 
204 Chapter 6
Shared Library Management Routines
Initializers for Shared Libraries
For example, to create a shared library named libfoo.sl that uses an
initializer named init_foo, use this linker command line:
$ ld -b -o libfoo.sl libfoo.o +I init_foo
Order of Execution of Multiple Initializers . Multiple
initializers are executed in the same order that they appear on the
command line; they are unloaded in reverse order. (This applies only to
the calling order within a shared library, not across multiple shared
libraries.)
NOTE Initializers are not executed when unloading shared libraries which were
implicitly loaded since the program exits without re-entering the
dynamic loader to unload them. Initializers are only called during the
explicit unloading of a shared library.
Initializers behave the same as other symbols; once they are bound they
cannot be overridden with a new symbol through the use of
shl_definesym() or by loading a more visible occurrence of the
initializer symbol with the BIND_FIRST flag. What this means is that
once the initializer is executed upon a load, it is guaranteed to be the
same initializer that is called on an explicit unload.
Initializer Syntax
void initializer( shl_t handle,
int loading )
initializer The name of the initializer as specified with the +I
linker option.
handle The initializer is called with this parameter set to the
handle of the shared library for which it was invoked.
loading The initializer is called with this parameter set to 1
(true) when the shared library is loaded and 0 (false)
when the library is unloaded.
The initializers cannot be defined as local definitions. Initializers cannot
be hidden through the use of the -h option when building a shared
library.
It is strongly recommended that initializers be defined with names which
do not cause name collisions with other user-defined names in order to
avoid overriding behavior of shared library symbol binding.