I\'m making a simple plugin framework in which I\'d like to be able to dlopen() a shared library (i.e. plugin), inspect and use whatever factory functions is provides and ev
What's happening is that there is a STB_GNU_UNIQUE
symbol in libempty.so
:
readelf -Ws libempty.so | grep _ZGVZN3Foo4initEvE2ns
91: 0000000000203e80 8 OBJECT UNIQUE DEFAULT 25 _ZGVZN3Foo4initEvE2ns
77: 0000000000203e80 8 OBJECT UNIQUE DEFAULT 25 _ZGVZN3Foo4initEvE2ns
The problem is that STB_GNU_UNIQUE
symbols work quite un-intuitively, and persist across dlopen
/dlclose
calls.
The use of that symbol forces glibc to mark your library as non-unloadable here.
There are other surprises with GNU_UNIQUE
symbols as well. If you use sufficiently recent gold linker, you can disable the GNU_UNIQUE
with --no-gnu-unique
flag.