dlclose() doesn't work with factory function & complex static in function?

前端 未结 1 1854
花落未央
花落未央 2020-12-16 08:20

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

相关标签:
1条回答
  • 2020-12-16 08:50

    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.

    0 讨论(0)
提交回复
热议问题