Using
The initializer is called for libraries that are loaded implicitly at program startup, or explicitly with shl_load or dlopen. When calling initializers for implicitly loaded libraries, the dynamic loader waits until all libraries have been loaded before calling the initializers. It calls the initializers in
•“Declaring the Initializer with the +I Option” (page 143)
•“Order of Execution of Multiple Initializers” (page 143)
•“Initializer Syntax” (page 144)
•“Example: An Initializer for Each Library” (page 144)
•“Example: A Common Initializer for Multiple Libraries” (page 146)
Declaring the Initializer with the +I Option
To declare the name of the initializer, use the +I linker option when creating the shared library. The syntax of the +I option is:
+I initializer
where initializer is the initializer's name.
Multiple initializers may be called by repeating the +I initializer option.
For example, to create a shared library named libfoo.so that uses an initializer named init_foo, use this linker command line:
$ ld
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: In
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 )
Initializers for Shared Libraries 143