]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
Remove compat hacks from libcxxrt's _Unwind_Exception
authorDimitry Andric <dim@FreeBSD.org>
Tue, 8 Mar 2022 21:53:16 +0000 (22:53 +0100)
committerDimitry Andric <dim@FreeBSD.org>
Thu, 17 Mar 2022 15:13:06 +0000 (16:13 +0100)
This reverts 9097e3cbcac4, which was in itself a revert of upstream
libcxxrt commits 88bdf6b290da ("Specify double-word alignment for ARM
unwind") and b96169641f79 ("Updated Itanium unwind"), and a
reapplication of our commit 3c4fd2463bb2 ("libcxxrt: add padding in
__cxa_allocate_* to fix alignment").

The editors/libreoffice port will be patched to be able to cope with the
standards-compliant alignment of _Unwind_Exception and consequently,
that of __cxa_exception. The layouts and sizes of these structures
should then be completely the same for libcxxrt, libunwind and
libc++abi.

PR: 262008
Reviewed by: emaste, jhb, theraven
Approved by: re (gjb)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D34488

(cherry picked from commit 72df847a94bccee245a3316e4f848482b9ac2ac2)
(cherry picked from commit 93779214f1c64c0713f7c900021e35d4e4e49697)

contrib/libcxxrt/exception.cc
contrib/libcxxrt/unwind-arm.h
contrib/libcxxrt/unwind-itanium.h

index 0de878e9e6dbd8b72cd073a317154fa36480a2d2..0fb26ddb4ed2db7dfd98086150b0311fe1ac63bf 100644 (file)
@@ -572,19 +572,6 @@ static void free_exception(char *e)
        }
 }
 
-#ifdef __LP64__
-/**
- * There's an ABI bug in __cxa_exception: unwindHeader requires 16-byte
- * alignment but it was broken by the addition of the referenceCount.
- * The unwindHeader is at offset 0x58 in __cxa_exception.  In order to keep
- * compatibility with consumers of the broken __cxa_exception, explicitly add
- * padding on allocation (and account for it on free).
- */
-static const int exception_alignment_padding = 8;
-#else
-static const int exception_alignment_padding = 0;
-#endif
-
 /**
  * Allocates an exception structure.  Returns a pointer to the space that can
  * be used to store an object of thrown_size bytes.  This function will use an
@@ -593,19 +580,16 @@ static const int exception_alignment_padding = 0;
  */
 extern "C" void *__cxa_allocate_exception(size_t thrown_size)
 {
-       size_t size = exception_alignment_padding + sizeof(__cxa_exception) +
-           thrown_size;
+       size_t size = thrown_size + sizeof(__cxa_exception);
        char *buffer = alloc_or_die(size);
-       return buffer + exception_alignment_padding + sizeof(__cxa_exception);
+       return buffer+sizeof(__cxa_exception);
 }
 
 extern "C" void *__cxa_allocate_dependent_exception(void)
 {
-       size_t size = exception_alignment_padding +
-           sizeof(__cxa_dependent_exception);
+       size_t size = sizeof(__cxa_dependent_exception);
        char *buffer = alloc_or_die(size);
-       return buffer + exception_alignment_padding +
-           sizeof(__cxa_dependent_exception);
+       return buffer+sizeof(__cxa_dependent_exception);
 }
 
 /**
@@ -633,8 +617,7 @@ extern "C" void __cxa_free_exception(void *thrown_exception)
                }
        }
 
-       free_exception(reinterpret_cast<char*>(ex) -
-           exception_alignment_padding);
+       free_exception(reinterpret_cast<char*>(ex));
 }
 
 static void releaseException(__cxa_exception *exception)
@@ -661,8 +644,7 @@ void __cxa_free_dependent_exception(void *thrown_exception)
        {
                releaseException(realExceptionFromException(reinterpret_cast<__cxa_exception*>(ex)));
        }
-       free_exception(reinterpret_cast<char*>(ex) -
-           exception_alignment_padding);
+       free_exception(reinterpret_cast<char*>(ex));
 }
 
 /**
index 6eb9d9e459817fee0693d92a4828d4b19bdb6aa4..ec81237e573b0e5acf6a6121079a72b7c84e1f95 100644 (file)
@@ -97,7 +97,7 @@ struct _Unwind_Exception
        } pr_cache;
        /** Force alignment of next item to 8-byte boundary */
        long long int :0;
-};
+} __attribute__((__aligned__(8)));
 
 /* Unwinding functions */
 _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *ucbp);
index 1ee0cf0e81c4ff8a2eb98162dad2d49e30260467..199d91de283db69193c6297f6338ebc87b538a84 100644 (file)
@@ -79,9 +79,12 @@ struct _Unwind_Exception
   {
     uint64_t exception_class;
     _Unwind_Exception_Cleanup_Fn exception_cleanup;
-    unsigned long private_1;
-    unsigned long private_2;
-  } ;
+    uintptr_t private_1;
+    uintptr_t private_2;
+#if __SIZEOF_POINTER__ == 4
+    uint32_t reserved[3];
+#endif
+  } __attribute__((__aligned__));
 
 extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
 extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,