Kenwood HP 9000 Personal Computer User Manual


 
202 Chapter 6
Shared Library Management Routines
Initializers for Shared Libraries
$ ld -b foo.o +I my_10x_init -o libfoo.sl
#include <dl.h>
void my_10x_init(shl_t handle, int loading)
{
/* handle is the shl_load API handle for the shared library being
initialized. */
/* loading is non-zero at startup and zero at termination. */
if (loading) {
... do some initializations ...
} else {
... do some clean up ...
}
}
NOTE Unlike 32-bit mode, the 64-bit HP-UX 10.X style initiators are called
when unloading implicitly lordered shared libraries.
See “32-bit Mode Initializers” for more information on using these
initiators.
Init/Fini Style Initializers
This style uses init and fini functions to handle initialization operations.
Init. Inits are called before the user’s code starts or when a shared
library is loaded. They are functions which take no arguments and
return nothing. The C compiler pragma “init” is used to declare them.
For example:
#pragma init “my_init”
void my_init() { ... do some initializations ... }
The ld command supports the +init option to specify the initializer.
Fini. Finis are called after the user’s code terminates by either calling
the libc exit function, returning from the main or _start functions, or
when the shared library which contains the fini is unloaded from
memory. Like inits, these also take no arguments and return nothing.
The C compiler pragma “fini” is used to create them. For example:
#pragma fini “my_fini”
void my_fini() { ... do some clean up ... }