dlopen on new binary with same name returns old handle

前端 未结 1 1364
情书的邮戳
情书的邮戳 2021-01-17 03:20

I\'m using dlopen to load dynamically generated code. The program calls the compiler on the code and generates a .so file which is then loaded by the program to extend itsel

相关标签:
1条回答
  • 2021-01-17 04:10

    Most probly dlclose failed to unload the library. This usually happens when it contains GNU_UNIQUE symbols (which tend to sneak in if you link with static libstdc++). This can be verified via

    $ readelf -sW --dyn-syms path/to/libxyz.so | grep '\bUNIQUE\b'
    ...
    3808: 0000000000302e78     8 OBJECT  UNIQUE DEFAULT   27 _ZNSt8messagesIcE2idE@@GLIBCXX_3.4
    

    To fix this, you can try one of the following:

    • build library with -fvisibility=hidden and __attribute__((visibility("default"))) to hide unique symbols
    • build with -Wl,--version-script to achieve the same
    • build shlib with toolchain that was configured with --disable-gnu-unique-object (see discussion in GCC list)
    0 讨论(0)
提交回复
热议问题