Reputation: 1336
I have a situation where I have two shared libraries, let's call them libA.so and libB.so. libA.so gets loaded via dlopen() and uses a singleton. libA.so at some point loads libB.so via dlopen(), which also uses the same singleton. Unfortunately, the dynamic linker cannot merge those tho singleton symbols into one, and the result is two singleton instances.
When such situation happens with an executable and a dynamically loaded library, I know the usual solution is to add -rdynamic when linking the executable. This doesn't work here. The symbol in both libraries is exported as V
and I don't know what to do to make the dynamic linker merge them together.
EDIT: This was tested on Android and seems to be Android-specific, rather than generic.
Upvotes: 1
Views: 838
Reputation: 213799
libA.so gets loaded via dlopen() and uses a singleton. libA.so at some point loads libB.so via dlopen(), which also uses the same singleton. Unfortunately, the dynamic linker cannot merge those tho singleton symbols into one, and the result is two singleton instances.
I can reproduce this on a trivial example, but only if the loading of libA.so
uses RTLD_LOCAL
flag. If I use the RTLD_GLOBAL
, then a variable shared between libA.so
and libB.so
gets resolved to the first loaded instance (inside libA.so
).
I believe this is working as designed.
Upvotes: 2