NAME
dlsym — obtain the
address of a symbol from a dlopen object
SYNOPSIS
void *dlsym(void *restrict handle, const char *restrict name);
DESCRIPTION
The dlsym () function shall obtain the
address of a symbol defined within an object made accessible through a
dlopen(3) call. The handle argument is
the value returned from a call to dlopen(3) (and which has
not since been released via a call to dlclose(3)), and
name is
the symbol's name as a character string.
The dlsym () function shall search for the
named symbol in all objects loaded automatically as a result of loading the
object referenced by handle (see
dlopen(3) ). Load ordering is used in
dlsym () operations upon the global symbol object.
The symbol resolution algorithm used shall be dependency order as described
in dlopen(3) .
The RTLD_DEFAULT and RTLD_NEXT flags are reserved for future use.
RETURN VALUE
If handle does not refer to a valid object
opened by dlopen(3), or if the named symbol cannot be
found within any of the objects associated with handle,
dlsym () shall return NULL. More detailed diagnostic
information shall be available through dlerror(3) .
ERRORS
No errors are defined.
EXAMPLES
The following example shows how dlopen(3) and
dlsym () can be used to access either function or
data objects. For simplicity, error checking has been omitted.
void *handle;
int *iptr, (*fptr)(int);
/* open the needed object */
handle = dlopen("/usr/home/me/libfoo.so", RTLD_LOCAL | RTLD_LAZY);
/* find the address of function and data objects */
fptr = (int (*)(int))dlsym(handle, "my_function");
iptr = (int *)dlsym(handle, "my_object");
/* invoke function, passing value of integer as a parameter */
(*fptr)(*iptr);
APPLICATION USAGE
Special purpose values for handle are reserved for future use. These values and their meanings are:
- RTLD_DEFAULT
- The symbol lookup happens in the normal global scope; that is, a search for a symbol using this handle would find the same definition as a direct use of this symbol in the program code.
- RTLD_NEXT
- Specifies the next object after this one that defines name . This one
refers to the object containing the invocation of
dlsym(). The next object is the one found upon the application of a load order symbol resolution algorithm (see dlopen () ). The next object is either one of global scope (because it was introduced as part of the original process image or because it was added with a dlopen () operation including the RTLD_GLOBAL flag), or is an object that was included in the same dlopen () operation that loaded this one.The RTLD_NEXT flag is useful to navigate an intentionally created hierarchy of multiply-defined symbols created through interposition. For example, if a program wished to create an implementation of malloc(3) that embedded some statistics gathering about memory allocations, such an implementation could use the real malloc(3) definition to perform the memory allocation-and itself only embed the necessary logic to implement the statistics gathering function.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
dlclose(3) , dlerror(3) , dlopen(3) , the Base Definitions volume of IEEE Std 1003.1-2001 (“POSIX.1”), <dlfcn.h>
CHANGE HISTORY
First released in Issue 5.
Issue 6
The
restrict
keyword is added to the dlsym () prototype for
alignment with the ISO/IEC 9899:1999
(“ISO C99”) standard.
The RTLD_DEFAULT and RTLD_NEXT flags are reserved for future use.
End of informative text. footer end