In GCC, how can I export all typeinfo symbols for a shared library without exporting all symbols?

2.2k views Asked by At

Here is the problem:

I have a shared library that is hiding symbols by default. Actually, it uses the -Xlinker --version-script= option to export some symbols in a specific file but hide all the rest. The issue is that if we try to catch exceptions that were defined in other shared libraries, we get problems because the typeinfo is hidden by this shared library. I can't explicitly make the exception classes visible because they are defined in an open source library that is out of my control. I also don't want to explicitly list the mangled names for the typeinfo of the exception classes in the version-script symbol file because there are many developers working on this library and they are bound to forget to do this for some exception class in the future.

I've tried using the #pragma GCC visibility push(default) before the open source .hpp files but it didn't seem to work - the symbols were not visible.

I've also tried using -fvisibility-ms-compat which did export the typeinfo symbols but also exported tons of other symbols that I did not want exported. The library has both C and C++ code in it so I'm not sure how it is supposed to work with this option that is only for C++.

What I really need is an option that will make all typeinfo symbols visible, while leaving other symbols hidden (unless they are explicitly visible). Is there an option like this?

1

There are 1 answers

0
rtollert On

The most direct answer to your question is to try the ld option --dynamic-list-cpp-typeinfo. I haven't had the best of luck with that option, but YMMV.

You don't say which platform you're building on. Ostensibly you're using mingw, since you've tried -fvisibility-ms-compat; but in the offhand chance that you're actually on an ELF target like Linux, try exporting the symbol wildcards _ZTI* and _ZTN* from your version script. (You can probably do something similar on Windows, but insofar as Visual C++ name mangling is not really documented, I'm not aware of any canned wildcards you can use.)