[Libreoffice-commits] core.git: Branch 'libreoffice-6-3-6' - bridges/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 21 10:23:55 UTC 2020


 bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx |   32 ++++++++++++++++++-
 bridges/source/cpp_uno/gcc3_macosx_x86-64/share.hxx  |   15 ++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

New commits:
commit 4ee24fa70a41d960b1b96cc60f974ec07090c7de
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Feb 13 08:40:11 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Apr 21 12:23:21 2020 +0200

    Hack to dynamically adapt to __cxa_exceptiom in LLVM 11 libcxxabi
    
    (where the new change to __cxa_exception effectively reverts the change that
    prompted 7a9dd3d482deeeb3ed1d50074e56adbd3f928296 "Hack to dynamically adapt to
    __cxa_exceptiom in LLVM 5.0 libcxxabi")
    
    Change-Id: Iec4ef1dc188bea2223d99b1b7eb8adec636c98e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88583
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    (cherry picked from commit f4b6f6a8ae60bdec53512728d00853b73fa18500)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92023
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>
    (cherry picked from commit fcf62dcc5b5ee3eafad48666bde6c7a91409c98c)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92300
    Reviewed-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx b/bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx
index c31cf180a704..edc6753c73a8 100644
--- a/bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx
+++ b/bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx
@@ -270,7 +270,11 @@ static void deleteException( void * pExc )
     // new 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/f2a436058fcbc11291e73badb44e243f61046183>
+    // "[libcxxabi] Insert padding in __cxa_exception struct for compatibility" towards LLVM 11
+    // 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 >= 11:
     if (header->exceptionDestructor != &deleteException) {
         header = reinterpret_cast<__cxa_exception const *>(
             reinterpret_cast<char const *>(header) - 8);
@@ -344,6 +348,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 11
+    // <https://github.com/llvm/llvm-project/commit/f2a436058fcbc11291e73badb44e243f61046183>
+    // "[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_macosx_x86-64/share.hxx b/bridges/source/cpp_uno/gcc3_macosx_x86-64/share.hxx
index 39939ab6be72..015cda1c00e5 100644
--- a/bridges/source/cpp_uno/gcc3_macosx_x86-64/share.hxx
+++ b/bridges/source/cpp_uno/gcc3_macosx_x86-64/share.hxx
@@ -68,6 +68,21 @@ typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
 struct __cxa_exception
 {
 #if __LP64__
+#if 0
+    // This is a new field added with LLVM 11
+    // <https://github.com/llvm/llvm-project/commit/f2a436058fcbc11291e73badb44e243f61046183>
+    // "[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


More information about the Libreoffice-commits mailing list