views:

41

answers:

1

I have the offset address's of all symbols (obtained with libelf executing on its own binary .so). Now, at runtime, I would need to calculate the absolutue address's of all those symbols and for that I would need to get the base address (where the shared library is loaded) and do a calculation:

symbol_address = base_address + symbol_offset

How can a shared lib get its own base address? On Windows I would use the parameter passed to DllMain, is there some equivalent in linux?

A: 

On Linux, dladdr() on any symbol from libfoo.so will give you

  void *dli_fbase;      /* Load address of that object */

More info here.

Alternatively, dl_iterate_phdr can give you load address of every ELF image loaded into current process.

Both are GLIBC extensions. If you are not using GLIBC, do tell what you are using, so more appropriate answer can be given.

Employed Russian
thanks, works with dladdr()
Sasha