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

d
dlopen(3C) dlopen(3C)
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() opera-
tion 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 multiple
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_TEXT_PRIVATE
Under this mode, the shared library loaded has its text segment mapped private. This can
be useful for debugging.
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 are available.
Any object loaded by dlopen() that requires relocations against global symbols can reference the symbols
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 dlopen()
invocation that specified the RTLD_GLOBAL flag. To determine the scope of visibility for the symbols
loaded with a dlopen() invocation, the mode parameter should be bitwise or’ed with one of the following
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.
RTLD_LOCAL The object’s symbols are made available for relocation processing only to objects loaded in
the same dlopen() invocation.
If neither RTLD_GLOBAL nor RTLD_LOCAL are specified, the default is RTLD_LOCAL.
If a file is specified in multiple dlopen() invocations, mode is interpreted at each invocation. Note, how-
ever, that once RTLD_NOW has been specified, all relocations will have been completed, rendering any
further RTLD_NOW operations redundant and any further RTLD_LAZY operations irrelevant. Similarly
note that once RTLD_GLOBAL has been specified, the object will maintain the RTLD_GLOBAL status
regardless of any previous or future specification of RTLD_LOCAL , so long as the object remains in the
address space (see dlclose(3C)).
To determine the scope of symbols that are made available for relocation processing of objects loaded in a
dlopen() invocation, the mode parameter can be bitwise or’ed with one of the following values:
HP-UX 11i Version 1: September 2005 2 Hewlett-Packard Company Section 3173