-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
anchor vtables of exceptions, helps throwing across DSO boundaries #1941
Conversation
I think we definitely need some in-code documentation on what these are doing and what problem they solve. Maybe a detailed description in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment.
Hm, I wonder why this hasn't caused problems before. I remember that we had a bug at work with exceptions / RTTI across DSOs, but I can't remember if that was Linux or macOS... |
#1678 anchored |
clang's Avoiding weak vtables makes things work more readily, situations that might not work when relying on them re:exceptions/dynamic_cast:
Anchoring vtables (no weak vtables) is part of LLVM's coding standard, FWIW, although AFAIK not for these reasons as LLVM avoids both RTTI and exceptions: https://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers So basically anchoring them helps code size a bit and helps avoid the need to ensure things work right, instead of relying on type_info merging we just have one and done. I'll try to come up with how to best reference/document this in the code. |
Plugins rely on RTLD_LOCAL, just FYI |
I'm not sure how well this sort of detail is "documented", but here's a post that seems to describe it well enough: https://marcmutz.wordpress.com/2010/08/04/fun-with-exceptions/ . That said much of this is implementation-specific with various compilers/toolchains having different behavior and workarounds-- even the approach here is only required and indeed AFAIK only effective due to implementation choices on various platforms and compilers. AFAIK the C++ standard simply requires that whatever the compiler/linker do that there only be one definition (the so-called "one definition rule"). I like the explanation here, hopefully it helps this make sense: https://stackoverflow.com/a/23749273 As for plugins, I'm not sure that RTLD_LOCAL + exceptions will work? Will get back to you. |
Looks like doesn't work with libc++, which makes sense since IIRC it has stricter behavior re:comparing addresses of type_info's. Here's a quick repo I put together for demonstrating/testing this behavior; https://github.com/dtzWill/throw_from_shared . EDIT: fixed link |
Updated to demonstrate with and without anchor! |
4a625a9
to
8154fe2
Compare
@dtzWill That link doesn't work for me. What precisely doesn't work with libc++? We can't throw from RTLD_LOCAL DSOs at all? |
@dtzWill Can you give a bit more information on how this impacts plugins, if at all? |
I marked this as stale due to inactivity. → More info |
I closed this issue due to inactivity. → More info |
At least it does on my special platform :).
As-is the vtables will be anchored in every translation unit that
includes them, so this should reduce size a bit everywhere.