DLADDR(3)

NAME
dladdr - find the shared object containing a given address

SYNOPSIS
#include <dlfcn.h>
int
dladdr(const void *addr, Dl_info *info);

DESCRIPTION
The dladdr() function 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 members:

const char *dli_fname
    The pathname of the shared object containing the address.

void *dli_fbase
    The base address at which the shared object is mapped into the address space of the calling process.

const char *dli_sname
    The name of the nearest run-time symbol with a value less than or equal to addr.

    If no symbol with a suitable value is found, both this field and dli_saddr are set to NULL.

void *dli_saddr
    The value of the symbol returned in dli_sname.

The dladdr() function is available only in dynamically linked programs.

ERRORS
If a mapped shared object containing addr cannot be found, dladdr() returns 0.

On success, a non-zero value is returned.

SEE ALSO
dyld(3), dlopen(3)

HISTORY
The dladdr() function first appeared in the Solaris operating system.

AUTHORS
The dlcompat package was written by Jorge Acereda <jacereda@users.sourceforge.net> and Peter O'Gorman <ogorman@users.sourceforge.net>

Some of the code for this particular function was borrowed from a post to the darwin development list by Douglas Davidson.

This man page was borrowed from FreeBSD and modified.

BUGS
This implementation is almost bug-compatible with the Solaris implementation. The following bugs are present:

•   If addr lies in the main executable rather than in a shared library, the pathname returned in dli_fname may not be correct. The pathname is taken directly from argv[0] of the calling process. When executing a program specified by its full pathname, most shells set argv[0] to the pathname. But this is not required of shells or guaranteed by the operating system.

•   dlerror() can not be used to get the error string if dladdr() fails.

•   The symbol returned has an underscore if it is a C symbol, and can not be used as input to dlsym() as dlsym() in a default dlcompat installation takes symbol names as they appear in C source code (no underscore).

•   Returning 0 as an indication of failure goes against long-standing Unix tradition.