-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to catch RDKit exceptions in linked library when compiling with fvisibility=hidden #2753
Comments
RDKIT_GRAPHMOL_BUILD is defined in RDGeneral/export.h which SanitException.h includes. The relevant bit is here:
Could you try defining RDKIT_DYN_LINK in your build? |
So we should be defining RDKIT_DYN_LINK when building any library that links against RDKit? |
It certainly looks that way (for dynamic linking). Did it end up working
for you? I'm going to ping Greg on this one.
Cheers,
Brian
…On Thu, Oct 31, 2019 at 12:18 PM Dan N ***@***.***> wrote:
So we should be defining RDKIT_DYN_LINK when building any library that
links against RDKit?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2753?email_source=notifications&email_token=ACLOFIASWETUJZNNPKPAWWDQRMAN3A5CNFSM4JHL36O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECYL5SA#issuecomment-548454088>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACLOFIG75Z62W52RVFHV6M3QRMAN3ANCNFSM4JHL36OQ>
.
|
The plot thickens. Here is my test case:
I'm using rdkit as installed via conda.
Which works ok. Let's try
which also works. It also appears that the symbols are certainly exported properly:
Could you run the later on your libRDKitGraphMol? |
Sorry for coming back to this after so long, but yesterday I hit an issue like this one (but with a different library), and I found some interesting information in https://stackoverflow.com/questions/14268736/symbol-visibility-exceptions-runtime-error. I think the second paragraph in the answer gives a good explanation about what is causing the problem: classes with different visibility cannot be matched as the same. Apparently some compilers do not have this problem, e.g., the post mentions MSVC comparing the exception classes by literal name, and I couldn't reproduce my problem when using gcc 6.4 on linux, but clang 11.0 on Mac did definitely hit it. What happens both in @cdvonbargen's case, and in the one I had yesterday, is that the libraries we were using were built with "default" visibility for the exported functions (the libraries would be useless otherwise), but the code that uses them is building with the "hidden" visibility flag, triggering the mismatch. The problem can be addressed by hardcoding the "default" visibility attribute into the
|
I just pushed a branch with a "proof of concept" to my fork of this repo. The differences with the current master are this executable and the CMakeLists update that builds 2 copies of the executable, one with 'hidden' and one with 'default' visibility: Looking at the CI build, we can see that the one with hidden visibility fails on Mac (the test failure in Ubuntu 16.04 py27 looks like a random artifact). It seems that clang doesn't do a good job matching object types with different visibilities: when the RDKit library is built, the header which declares There's a way to work around this if you want to link RDKit to something that is build with hidden visibility, which consists in wrapping RDKit's |
Apparently, clang doesn't correctly handle type comparisons with mismatched visibility: even if a library is compiled with default visibility, if the code linking it compiles using "hidden" visibility, types won't be correctly matched, creating problems at least in catching exceptions. This is better explained in the last few comments in rdkit/rdkit/issues/2753. There are also some links to a proof of concept I built to demonstrate the problem with the RDKit.
* add test export heder to gitignore * define export macros in separate file * install new header * patch GA with the new macros * fix struct declarations * fix conformerparser exports * fix MolSGroupParsing ParseV3000Array export * fix java wrappers * export exceptions * remove duplicated exports * Build RDGeneral exceptions into lib * export queries, only for *nix * fix RingDecomposerLib header manipulation * fix CIP labeler test issues
For example, the following won't get caught if this is in a library that compiles with
-fvisibility=hidden
because RDKIT_GRAPHMOL_BUILD is not defined in this external library, and so the macro is defined by empty and falls back to hidden visibility:
See some discussion of "Problems with C++ exceptions" in https://gcc.gnu.org/wiki/Visibility
The text was updated successfully, but these errors were encountered: