I load a symbol from a shared library like this:
void *sym = dlsym(RTLD_DEFAULT, "printf");
That will tell me whether the symbol printf exists in a loaded shared library, and if it does, what its address is, but it will not tell me which shared library it was loaded from. Is there a way to determine that?
Note I want to find the answer programatically at runtime, so solutions using debuggers, the LD_DEBUG environment variable, etc., are not what I am looking for.
I am particularly looking for solutions for Linux and macOS.