I have dlopen()
'ed a library, and I want to invert back from the handle it passes to me to the full pathname of shared library. On Linux and friends, I know that I can use dlinfo()
to get the linkmap and iterate through those structures, but I can't seem to find an analogue on OSX. The closest thing I can do is to either:
Use
dyld_image_count()
anddyld_get_image_name()
, iterate over all the currently opened libraries and hope I can guess which one corresponds to my handleSomehow find a symbol that lives inside of the handle I have, and pass that to
dladdr()
.
If I have apriori knowledge as to a symbol name inside of the library I just opened, I can dlsym()
that and then use dladdr()
. That works fine. But in the general case where I have no idea what is inside this shared library, I would need to be able to enumerate symbols to do that, which I don't know how to do either.
So any tips on how to lookup the pathname of a library from its dlopen
handle would be very much appreciated. Thanks!
dlopen()
is anImageLoader
subclass, but that source is not available in the standard library, is there a better way to get at the internal data than just including that source in my project? As far as I can tell, the data returned to me fromdlopen()
is completely opaque and Apple doesn't provide any methods to edit it. Should I just copy Apple's source into my own and call it good? – Nakesha