Binding Times

Because shared library routines and data are not actually contained in the a.out file, the dynamic loader must attach the routines and data to the program at run time. To accelerate program startup time, routines in a shared library are not bound until referenced. (Data items are always bound at program startup.) This deferred binding distributes binding overhead across the total execution time of the program and is especially helpful for programs that contain many references that are not likely to be executed.

Forcing Immediate Binding

You can force immediate binding, that forces all routines and data to be bound at startup time. With immediate binding, the overhead of binding occurs only at program startup time, rather than across the execution of the program. Immediate binding also detects unresolved symbols at startup time, rather than during program execution. Immediate binding provides better interactive performance, but the program startup time is longer. To force immediate binding, use the option -Wl,-B,immediate.

Example:

aCC -Wl,-B,immediate draw_shapes.o -lshape

To specify default binding, use the -Wl,B,deferredoption.

For more information, refer to the HP-UX Online Linker and Libraries User’s Guide.

Side Effects of C++ Shared Libraries

When you use a C++ shared library, all constructors and destructors of nonlocal static objects in the library are executed. This differs from a C++ archive library where only the constructors and destructors that are actually used in the application are executed.

Routines and Options to Manage C++ Shared Libraries

You can call any of several routines to explicitly load and unload shared libraries, and to obtain information about shared libraries.

If an error occurs when calling shared library management routines, the system error variable, errno, is set to an appropriate error value. Constants are defined for these error values in /usr/ include/errno.h. When a program checks for these values, it must include errno.h:

#include <errno.h>

Linker Options to Manage Shared Libraries

Use the linker options to specify shared library binding time, symbol export, and other shared library management features.

NOTE: You must use the -Wx,argscompiler option to specify any linker option on the compiler command line.

Refer to HP-UX Online Linker and Libraries User’s Guide for more information about library management routines and linker options.

Version Control for Shared Libraries

You can create different versions of a routine in a shared library with the HP_SHLIB_VERSION pragma. HP_SHLIB_VERSION assigns a version number to a module in a shared library. The version number applies to all global symbols defined in the source file. Use this pragma only if incompatible changes are made to a source file. Refer to HP-UX Online Linker and Libraries User’s Guide for more information about version control in shared libraries.

Creating and Using Libraries 183

Page 183
Image 183
HP C/aC++ for PA-RISC Software Binding Times, Side Effects of C++ Shared Libraries, Version Control for Shared Libraries