cc ... -ldl ...
#include <dlfcn.h>
typedef struct {
const char *dli_fname;
void *dli_fbase;
const char *dli_sname;
void *dli_saddr;
} Dl_info; |
dladdr is the inverse of dlsym. If address is successfully located inside a module, dladdr returns a non-ZERO value, otherwise, it returns a 0. On success, dladdr fills in the fields of dlip as follows:
the pathname of the module
the base address of the module
the name of the highest addressed symbol whose address precedes the given address
the address of that symbol
Shared objects must be linked using the -shared option to the linker ld(1). The linker flag -rpath may be used to add a directory to the default search path for shared objects and shared libraries. The linker flag -E or the C compiler flag -rdynamic should be used to cause the application to export its symbols to the shared objects.