HP-UX Reference (11i v2 04/09) - 3 Library Functions A-M (vol 6)
d
dlopen_pa(3C) dlopen_pa(3C)
(For PA-RISC Systems)
NAME
dlopen_pa: 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
• For ELF applications, any directories specified by a
DT_RPATH entry in the .dynamic section
of the original program object
• The directories
/usr/lib and usr/ccs/lib in 32-bit mode and /usr/lib/pa20_64
and
/usr/ccs/lib/pa20_64
in 64-bit mode
The use of
SHLIB_PATH is static. This means that when the program starts, the dynamic loader
dld
uses the value in environment variable SHLIB_PATH. Any change to SHLIB_PATH during the program
execution has no effect. The dld_getenv() function removes this constraint. With dld_getenv()
you can change the SHLIB_PATH value (using putenv) and call dld_getenv() to cause dld to read
current SHLIB_PATH value. You can use this new SHLIB_PATH value for subsequent library searching.
You can use
dld_getenv() while loading shared libraries using shl_load() or dlopen().As
described earlier, you should enable SHLIB_PATH searching using the chatr +s enable option. In
case of shl_load(), you should use the DYNAMIC_PATH flag.
The following example demonstrates the
dld_getenv() function:
#include <stdio.h>
#include <dl.h>
main(int argc, char **argv) {
char * str;
shl_t shl;
void (*fptr)(void);
char *strpath[267];
sprintf(strpath, %s%s", SHLIB_PATH= ,argv[1]);
putenv(strpath);
dld_getenv();
shl = shl_load( a.sl", BIND_IMMEDIATE | DYNAMIC_PATH, 0);
if(!shl) {
printf("shl_load failed\n");
exit(-1);
}
}
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.
HP-UX 11i Version 2: September 2004 − 1 − Hewlett-Packard Company Section 3−−219