I’m inside a shared object (code) loaded with dlopen. I want to know the flags given to the loading call. I do not have access to the loader (code) – e.g. it may be a script interpreter – but I have to create subsequent dlopen calls with the same flags.
How can I do this?
I think this is NOT possible without the aid of debuggers.
From the latest glibc code , here is the source code of
dlopenAnd
__dlopenis in turn defined asThe flags you are looking for,
RTLD_LAZY,RTLD_NOW,RTLD_GLOBALandRTLD_LOCALare ORed and stored inmodevariable. As you can see there is no route through which it is passed back or anything like that.EDIT: It seems there indeed is a way of achieving what you want as shown by the other answer. If you can un-accept my answer, I can delete it so as to help future visitors