How to get address of a symbol in a shared library when provided address of the library?



I am learning about working with shared libraries in C/C++ on Linux. I encountered a little problem that I don’t know how to solve.

Let’s say I have a shared library and an executable. However I don’t know the library’s name or file location (so I can’t dlopen it). I can only find the address range where the library is mapped into my executable’s memory.

Is there a way to programmatically get either the handle of the library (something like handle = dlopen(library_address)) or offset of a symbol within the library (something like address = dlsym(library_address, symbol_name))?


If you knew the library’s name, you could just call dlopen again.

From the man page:

If the same shared object is loaded again with dlopen(), the same object handle is returned.

To discover the loaded modules, you can use dl_iterate_phdr().

You can also use dladdr() to inquire about a specific address.

Answered By – Jonathon Reinhart

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More