dlopen, dlclose, dlsym, dladdr, dlctl, dlerror - dynamic
dlopen(const char *path, int mode);
dlsym(void *handle, const char *symbol);
dladdr(const void *addr, Dl_info *info);
dlctl(void *handle, int cmd, void *data);
const char *
These functions provide an interface to the run-time linker
They allow new shared objects to be loaded into a process's
under program control.
The dlopen() function takes a name of a shared object as its
The shared object is mapped into the address space,
its external references are resolved in the same way as is
done with the
implicitly loaded shared libraries at program startup.
The path argument can either be an absolute pathname or it
can be of the
form ``lib<name>.so[.xx[.yy]]'' in which case the same library search
rules apply that are used for ``intrinsic'' shared library
null pointer supplied for path is interpreted as a reference
to the main
executable of the process. The second argument currently
has no effect,
but should be set to DL_LAZY for future compatibility.
dlopen() returns a handle to be used in calls to dlclose(),
dlctl(). If the named shared object has already been loaded
by a previous
call to dlopen() (and not yet unloaded by dlclose()), a
to the resident copy is returned.
dlclose() unlinks and removes the object referred to by
handle from the
process address space. If multiple calls to dlopen() have
been done on
this object (or the object was once loaded at startup time)
the object is
removed when its reference count drops to zero.
dlsym() looks for a definition of symbol in the shared object designated
by handle. The symbol's address is returned. If the symbol
resolved, NULL is returned.
If dlsym() is called with the special handle NULL, it is interpreted as a
reference to the executable or shared object from which the
call is being
made. Thus a shared object can reference its own symbols.
If dlsym() is called with the special handle RTLD_DEFAULT,
all the shared
objects will be searched in the order they were loaded.
If dlsym() is called with the special handle RTLD_NEXT, then
for the symbol is limited to the shared objects which were
the one issuing the call to dlsym(). Thus, if the function
from the main program, all the shared libraries are
searched. If it is
called from a shared library, all subsequent shared libraries are
If dlsym() is called with the special handle RTLD_SELF, then
for the symbol is limited to the shared object issuing the
dlsym() and those shared objects which were loaded after it.
dladdr() queries the dynamic linker for information about
the shared object
containing the address addr. The information is returned in the
structure specified by info. The structure contains at
least the following
const char *dli_fname The pathname of the shared object
the address addr.
void *dli_fbase The base address at which the
shared object is
mapped into the address space of
const char *dli_sname The name of the nearest run-time
symbol with a
address less than or equal to
If no symbol with a suitable address is found,
both this field and dli_saddr are
set to NULL.
void *dli_saddr The address of the symbol returned
If a mapped shared object containing addr cannot be found,
0. In that case, a message detailing the failure can
by calling dlerror(). On success, a non-zero value is returned. Note:
both strings pointed at by dli_fname and dli_sname reside in
to the run-time linker module and should not be modified by the
In dynamically linked programs, the address of a global
point to its program linkage table entry, rather than to the
of the function itself. This causes most global functions
to appear to
be defined within the main executable, rather than in the
where the actual code resides.
dlctl() provides an interface similar to ioctl(2) to control
of the run-time linker's operation. This interface is
dlerror() returns a character string representing the most
that has occurred while processing one of the other functions described
here. If no dynamic linking errors have occurred since the
of dlerror(), dlerror() returns NULL. Thus, invoking
second time, immediately following a prior invocation, will
NULL being returned.
ld(1), ld.so(1), link(5)
Some of the dl* functions first appeared in SunOS 4.
An error that occurs while processing a dlopen() request results in the
termination of the program.
OpenBSD 3.6 September 30, 1995
[ Back ]