Here's the setup:
- There's an application
A
that loadsliba.so
(linked at compile time) liba.so
exports a symbolexpA
- I don't control either
A
orliba.so
- Application A can load a library I specify,
libmine.so
, into the same process viadlopen
(think plugin architecture) - I need to use
expA
fromlibmine.so
but don't know how to find it without explicitly linking againstliba.so
, which is what I've been doing so far. I assume this won't work in the real world since that symbol is not guaranteed to be at the same address as the one in my local copy ofliba.so
(or is it?).libmine.so
will be closed-source and can't be recompiled withA
.
I've never done anything like this, so am a bit unclear on the details of library loading. For example, if I try to dlopen("liba.so")
from within libmine.so
, will I get a handle to the already loaded library or a new copy?
In terms of how libmine.so
is loaded, all I know is that it will be loaded with RTLD_LAZY
(and nothing else).
Any help and pointers would be greatly appreciated!
If all the
liba.so
library isdlopen
ed usingRTLD_GLOBAL
, then you can usedlsym(RTLD_DEFAULT, "expA")
to find the symbol without needing to reopen the library.If the
liba.so
library isdlopen
ed usingRTLD_LOCAL
then you will need to obtain a handle to the library usingdlopen
again within your ownlibmine.so
. Note the following:i.e. it's the same copy of the library.
the mechanism is (pseudo), assuming expA is a function:
int expA(int value)
:That's pseudo code, with little to no error handling.