HP-UX Reference (11i v2 04/09) - 3 Library Functions A-M (vol 6)

d
dlopen_ia(3C) dlopen_ia(3C)
(For Itanium(R)-based Systems)
NAME
dlopen_ia: dlopen() - open a shared library
SYNOPSIS
cc [flag]... cfile ...
-ldl [library]...
#include <dlfcn.h>
void *dlopen(const char *file, int mode);
DESCRIPTION
dlopen() is one of a family of routines that give the user direct access to the dynamic linking facilities
(using the -ldl option on the compiler or
ld command line). dlopen() makes a shared object
specified by a file available to a running process. A shared object may specify other objects that it ‘‘needs’’
in order to execute properly. These dependencies are specified by
DT_NEEDED entries int the .dynamic
section of the original object. Each needed object may, in turn, specify other needed objects. All such
objects are loaded along with the original object as a result of the call to
dlopen().
A successful
dlopen() call returns to the process a handle which the process may use on subsequent
calls to
dlsym() and dlclose(). This value should not be interpreted in any way by the process.
file is used to construct a path name to the object file. If file contains a slash character, the file argument
itself is used as the path name. Otherwise
dlopen() searches a series of directories, in the following
order, for file:
Any directories specified by the environment variable
LD_LIBRARY_PATH
Any directories specified by SHLIB_PATH
Any directories specified by a DT_RPATH entry in the .dynamic section of the original program
object
The directories
/usr/lib/hpux32
in 32-bit mode and /usr/lib/hpux64 in 64-bit mode
If the value of file is 0,
dlopen() provides a handle on a "global symbol object." This object provides
access to the symbols from an ordered set of objects consisting of the original a.out, all of the objects
that were loaded at program startup along with the a.out, and all objects loaded using a
dlopen()
operation along with the RTLD_GLOBAL flag. As the latter set of objects can change during execution,
the set identified by handle can also change dynamically.
Only a single copy of an object file is brought into the address space, even if
dlopen() is invoked multi-
ple times in reference to the file, and even if different path names are used to reference the file.
When a shared object is brought into the address space of a process, it may contain references to symbols
whose addresses are not known until the object is loaded. These references must be relocated before the
symbols can be accessed. The mode parameter governs when these relocations take place and may have
the following values:
RTLD_LAZY Under this mode, only references to data symbols are relocated when the object is loaded.
References to functions are not relocated until a given function is invoked for the first
time. This mode should result in better performance, since a process may not reference
all of the functions in any given shared object.
RTLD_NOW Under this mode, all necessary relocations are performed when the object is first loaded.
This may result in some wasted effort, if relocations are performed for functions that are
never referenced, but is useful for applications that need to know as soon as an object is
loaded that all symbols referenced during execution will be available.
Any object loaded by
dlopen() that requires relocations against global symbols can reference the sym-
bols in the original a.out, any objects loaded at program startup, from the object itself as well as any
other object included in the same dlopen() invocation, and any objects that were loaded in any dlo-
pen() invocation that specified the RTLD_GLOBAL flag. To determine the scope of visibility for the sym-
bols loaded with a dlopen() invocation, the mode parameter should be bitwise or’ed with one of the fol-
lowing values:
RTLD_GLOBAL
The object’s symbols are made available for the relocation processing of any other object.
In addition, symbol lookup using dlopen(0,mode) and an associated dlsym() allows
objects loaded with RTLD_GLOBAL to be searched.
Section 3216 Hewlett-Packard Company 1 HP-UX 11i Version 2: September 2004