-
Notifications
You must be signed in to change notification settings - Fork 120
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
Crash when throwing exceptions in ObjC++ due to __cxa_exception struct mismatch #146
Comments
Thanks. Just to clarify this:
|
Makes sense. I think it’s like this:
For the last one I’m not sure which unwind.h is included by unwind-cxx.h in libsupc++ – FreeBSD contains 3 different versions:
The last two headers unfortunately contain further variants of
#if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__)
_Unwind_Word private_[6];
#else
_Unwind_Word private_1;
_Unwind_Word private_2;
#endif If you can tell me which of the above unwind.h are used by libsupc++ I can try to pick it further apart. |
To be on the safe side, I'd aim to support all of the plausible ones. Ignore anything in a |
All four
On top of that I found that libsupc++ on ARM using GCC uses a very different Finally I found a small mistake in the definitions, so please use this fixed version of cxa_exception_variants.cpp (also updated above). |
I was a bit surprised to see the v1 and v2 structures used by libsupc++. Looking a bit more carefully at their code, it appears as if this is technically the case, but they put the refcount in a separate structure and always allocate the enclosing structure. |
We now, the first time we encounter a foreign exception, throw a C++ exception through a frame that has a custom personality function and probe the layout of the __cxa_exception structure. We then use the offsets learned from this along with the public ABI functions for allocating the structure. At the same time, add a test that we are correctly setting the count of uncaught exceptions. Fixes #146
We now, the first time we encounter a foreign exception, throw a C++ exception through a frame that has a custom personality function and probe the layout of the __cxa_exception structure. We then use the offsets learned from this along with the public ABI functions for allocating the structure. At the same time, add a test that we are correctly setting the count of uncaught exceptions. Fixes #146
We now, the first time we encounter a foreign exception, throw a C++ exception through a frame that has a custom personality function and probe the layout of the __cxa_exception structure. We then use the offsets learned from this along with the public ABI functions for allocating the structure. At the same time, add a test that we are correctly setting the count of uncaught exceptions. Fixes #146
We now, the first time we encounter a foreign exception, throw a C++ exception through a frame that has a custom personality function and probe the layout of the __cxa_exception structure. We then use the offsets learned from this along with the public ABI functions for allocating the structure. At the same time, add a test that we are correctly setting the count of uncaught exceptions. Fixes #146
Throwing exceptions in Objective C++ code currently crashes with some setups. #138 adds tests that expose (some of?) these issues.
According to @davidchisnall:
I have created cxa_exception_variants.cpp containing the four different possible layouts of the __cxa_exception struct that are found in libobjc2, libcxxrt, and libunwind:
This leaves us with a total of four different variants of __cxa_exception:
Depending on the architecture some of these will have the same size. Following are the sizes for the different architectures as printed by the attached tool.
x86
x86_64
ARM32
ARM64
I’m not 100% sure which of these variants are actually used in the wild, although I think that FreeBSD 12.0 is using v2, and libcxxrt was using v3 and is now using v4 after libcxxrt/libcxxrt#1 was merged.
The text was updated successfully, but these errors were encountered: