summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2020-09-17 14:02:24 +0300
committerTor Lillqvist <tml@collabora.com>2020-09-17 16:32:32 +0200
commit6c8a84978725eb9efb06d4cf3e99c64f151e6c56 (patch)
treee56a47cce4d7bfb02ec32bb7c2e97e5c2a9b3c55
parent7b922966bf6bcf16f34cc22f60f0f962deb5f24a (diff)
Add Stephan's "Very bad HACK" to the iOS code, too, for iOS 14
Change-Id: Ie05d2dc77bfdcd323037d2e94b523808df4e1c9c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102916 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r--bridges/source/cpp_uno/gcc3_ios/except.cxx34
-rw-r--r--bridges/source/cpp_uno/gcc3_ios/unwind-cxx.h17
2 files changed, 48 insertions, 3 deletions
diff --git a/bridges/source/cpp_uno/gcc3_ios/except.cxx b/bridges/source/cpp_uno/gcc3_ios/except.cxx
index 2ef8ef49b966..d5c49859db27 100644
--- a/bridges/source/cpp_uno/gcc3_ios/except.cxx
+++ b/bridges/source/cpp_uno/gcc3_ios/except.cxx
@@ -267,10 +267,14 @@ static void deleteException( void * pExc )
// size 8 in front of that member (changing its offset from 88 to 96,
// sizeof(__cxa_exception) from 120 to 128, and alignof(__cxa_exception)
// from 8 to 16); a hack to dynamically determine whether we run against a
- // new libcxxabi is to look at the exceptionDestructor member, which must
+ // LLVM 5 libcxxabi is to look at the exceptionDestructor member, which must
// point to this function (the use of __cxa_exception in fillUnoException is
// unaffected, as it only accesses members towards the start of the struct,
- // through a pointer known to actually point at the start):
+ // through a pointer known to actually point at the start). The libcxxabi commit
+ // <https://github.com/llvm/llvm-project/commit/9ef1daa46edb80c47d0486148c0afc4e0d83ddcf>
+ // "Insert padding before the __cxa_exception header to ensure the thrown" in LLVM 6
+ // removes the need for this hack, so it can be removed again once we can be sure that we only
+ // run against libcxxabi from LLVM >= 6:
if (header->exceptionDestructor != &deleteException) {
header = reinterpret_cast<__cxa_exception const *>(
reinterpret_cast<char const *>(header) - 8);
@@ -347,6 +351,32 @@ void fillUnoException(uno_Any * pUnoExc, uno_Mapping * pCpp2Uno)
return;
}
+ // Very bad HACK to find out whether we run against a libcxxabi that has a new
+ // __cxa_exception::reserved member at the start, introduced with LLVM 10
+ // <https://github.com/llvm/llvm-project/commit/674ec1eb16678b8addc02a4b0534ab383d22fa77>
+ // "[libcxxabi] Insert padding in __cxa_exception struct for compatibility". The layout of the
+ // start of __cxa_exception is
+ //
+ // [8 byte void *reserve]
+ // 8 byte size_t referenceCount
+ //
+ // where the (bad, hacky) assumption is that reserve (if present) is null
+ // (__cxa_allocate_exception in at least LLVM 11 zero-fills the object, and nothing actively
+ // sets reserve) while referenceCount is non-null (__cxa_throw sets it to 1, and
+ // __cxa_decrement_exception_refcount destroys the exception as soon as it drops to 0; for a
+ // __cxa_dependent_exception, the referenceCount member is rather
+ //
+ // 8 byte void* primaryException
+ //
+ // but which also will always be set to a non-null value in __cxa_rethrow_primary_exception).
+ // As described in the definition of __cxa_exception
+ // (bridges/source/cpp_uno/gcc3_macosx_x86-64/share.hxx), this hack (together with the "#if 0"
+ // there) can be dropped once we can be sure that we only run against new libcxxabi that has the
+ // reserve member:
+ if (*reinterpret_cast<void **>(header) == nullptr) {
+ header = reinterpret_cast<__cxa_exception *>(reinterpret_cast<void **>(header) + 1);
+ }
+
std::type_info *exceptionType = __cxxabiv1::__cxa_current_exception_type();
typelib_TypeDescription * pExcTypeDescr = nullptr;
diff --git a/bridges/source/cpp_uno/gcc3_ios/unwind-cxx.h b/bridges/source/cpp_uno/gcc3_ios/unwind-cxx.h
index 9a700445c12a..83ed084860fd 100644
--- a/bridges/source/cpp_uno/gcc3_ios/unwind-cxx.h
+++ b/bridges/source/cpp_uno/gcc3_ios/unwind-cxx.h
@@ -59,8 +59,23 @@ namespace __cxxabiv1
// followed by the exception object itself.
struct __cxa_exception
-{
+{
#if __LP64__
+#if 0
+ // This is a new field added with LLVM 10
+ // <https://github.com/llvm/llvm-project/commit/674ec1eb16678b8addc02a4b0534ab383d22fa77>
+ // "[libcxxabi] Insert padding in __cxa_exception struct for compatibility". The HACK in
+ // fillUnoException (bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx) tries to find out at
+ // runtime whether a __cxa_exception has this member. Once we can be sure that we only run
+ // against new libcxxabi that has this member, we can drop the "#if 0" here and drop the hack
+ // in fillUnoException.
+
+ // Now _Unwind_Exception is marked with __attribute__((aligned)),
+ // which implies __cxa_exception is also aligned. Insert padding
+ // in the beginning of the struct, rather than before unwindHeader.
+ void *reserve;
+#endif
+
// This is a new field to support C++ 0x exception_ptr.
// For binary compatibility it is at the start of this
// struct which is prepended to the object thrown in