|DLSYM(3P)||POSIX Programmer's Manual||DLSYM(3P)|
void *dlsym(void *restrict handle, const char *restrict name);
The dlsym() function shall search for the named symbol in the symbol table referenced by handle. If the symbol table was created with lazy loading (see RTLD_LAZY in dlopen()), load ordering shall be used in dlsym() operations to relocate executable object files needed to resolve the symbol. The symbol resolution algorithm used shall be dependency order as described in dlopen().
The RTLD_DEFAULT and RTLD_NEXT symbolic constants (which may be defined in <dlfcn.h>) are reserved for future use as special values that applications may be allowed to use for handle.
More detailed diagnostic information shall be available through dlerror().
The following sections are informative.
void *handle; int (*fptr)(int), *iptr, result; /* open the needed symbol table */ handle = dlopen("/usr/home/me/libfoo.so", RTLD_LOCAL | RTLD_LAZY); /* find the address of the function my_function */ fptr = (int (*)(int))dlsym(handle, "my_function"); /* find the address of the data object my_object */ iptr = (int *)dlsym(handle, "my_OBJ"); /* invoke my_function, passing the value of my_OBJ as the parameter */ result = (*fptr)(*iptr);
- The identifier lookup happens in the normal global scope; that is, a search for an identifier using handle would find the same definition as a direct use of this identifier in the program code.
- Specifies the next executable object file after this one that defines name. This one refers to the executable object file containing the invocation of dlsym(). The next executable object file is the one found upon the application of a load order symbol resolution algorithm (see dlopen()). The next symbol 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 in an executable object file 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() that embedded some statistics gathering about memory allocations, such an implementation could use the real malloc() definition to perform the memory allocation — and itself only embed the necessary logic to implement the statistics gathering function.
Note that conversion from a void * pointer to a function pointer as in:
fptr = (int (*)(int))dlsym(handle, "my_function");
is not defined by the ISO C standard. This standard requires this conversion to work correctly on conforming implementations.
The Base Definitions volume of POSIX.1‐2008, <dlfcn.h>
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|2013||IEEE/The Open Group|