dladdr — get information relating to an address
#include <dlfcn.h>
int dladdr(const void *restrict addr, Dl_info_t *restrict dlip);
The dladdr() function shall determine whether the address specified by addr is located within the address range occupied by a mapped object. The mapped objects examined shall include any executable object files that have previously been loaded by a call to dlopen() and for which dlclose() has not subsequently been called, and any shared library files that were loaded as dependencies of the executable file from which the current process image was loaded; they may also include any executable object files that have previously been loaded by a call to dlopen() and for which dlclose() has subsequently been called, the executable file from which the current process image was loaded, and implementation-defined additional mapped objects (for example, all regular files mapped using mmap() might be included). If the specified address is within the mapped address range of one of these mapped objects and the object contains a symbol table, the symbol table shall be searched for a symbol (a function identifier or a data object identifier) that has the largest address less than or equal to the specified address.
If the address specified by addr is within the mapped address range of one of the examined mapped objects, the structure pointed to by dlip shall be populated as follows:
The value of the dli_fname member shall be set to point to the pathname of the mapped object. (This might no longer resolve to the file that was mapped, for example if it was a link that has subsequently been removed or renamed.)
The value of the dli_fbase member shall be set to the base of the address range occupied by the mapped object.
The value of the dli_sname member shall be set to point to the name of the symbol that has the largest address less than or equal to the specified address, or to a null pointer if no such symbol was found.
If dli_sname is set to a null pointer, the value of the dli_saddr member shall also be set to a null pointer. Otherwise, if dli_sname names a function identifier, dli_saddr shall be set to the address of the function converted from type pointer to function to type pointer to void; otherwise, dli_saddr shall be set to the address of the data object named by dli_sname converted from a pointer to the type of the data object to a pointer to void.
Upon successful completion, a non-zero value shall be returned. If the specified address is not located within the address range occupied by an examined mapped object, or if an error occurs, zero shall be returned. More detailed diagnostic information shall be available through dlerror().
No errors are defined.
None.
The Dl_info_t members may point to addresses within the mapped object. These pointers can become invalid if the object is unmapped (for example, loaded executable objects may be unloaded by dlclose()).
If dli_sname names a function identifier, the value of dli_saddr can be converted back to type pointer to function using a cast in the manner shown in the dlsym() EXAMPLES section. Note that this conversion is not defined by the ISO C standard. This standard requires this conversion to work correctly on conforming implementations.
None.
None.
dlclose, dlerror, dlopen, dlsym
XBD <dlfcn.h>
First released in Issue 8.
return to top of page