In my C shared library, I want to dlopen() another shared library and retrieve a list of the exported symbols this library has.
Is there a way I can do that programmatically, without running nm/objdump?
As a secondary question: How can I retrieve the base address where this second library got loaded after dlopen() - without knowing the names of any symbols (so I can't run dlsym!) and without reading /proc/self/maps?
I have tried the following:
struct link_map *imagehandle = (struct link_map*)dlopen(libraryname, RTLD_LOCAL | RTLD_LAZY);
void * fbase = (void*) imagehandle->l_addr;
printf("base addr is %p",fbase)
This prints
"base addr is 0x6862696c"
However, the library is not located there:
[ /proc/pid/maps output: ]
b6d27000-b6d28000 r-xp 00000000 1f:01 1581 mysecondlib.so
b6d28000-b6d29000 r--p 00000000 1f:01 1581 mysecondlib.so
b6d29000-b6d2a000 rw-p 00001000 1f:01 1581 mysecondlib.so
It has been suggested that l_addr is not the actual library base address ,but the offset from the executable header - but I am not sure how to find that header address.