Static library loads twice

I have a generic A.so object that statically references libssl.a and another generic B.so object that also statically links libssl.a.

A.so and B.so have characters from libssl.a in the GLOBAL region. I checked this with readelf -s A.so

I have a.out executable that loads A.so and B.so. When a.out completes, I get a double free error in one of the characters from libssl.a in A.so.

Despite the fact that libssl.a is statically associated with each shared object, since they are all over the world it is possible that the same symbol is shared, instead of selecting its local copy.

What workaround is this? How to make characters here here?

Please, help

+7
source share
1 answer

It is really expected. One instance of libssl.a inserts (probably a subset) of the other, and the results are not very good. You can use the script version ( --version-script to ld, with -Wl, for cc) to control export from A.so and B.so If something is not exported, it also cannot be inserted.

Alternatively, you can compile libssl.a flags of visibility, such as -fvisibility=hidden . These flags only affect the dynamic linker, not the static link. Most likely, you needed to compile it yourself, because the sent .a files usually contain position-specific code designed to communicate with executable files. Only on some platforms, such as 32-bit x86, can you get away with binding such code to shared objects and only by redistributing the text.

dlopen with RTLD_LOCAL , as suggested in the comment, should also work, but it seems difficult to use dlopen for this purpose.

Another option is to use the same generic libssl.so in both libraries.

+5
source

All Articles