[libcxx-commits] [PATCH] D72543: [libcxxabi] Insert padding in __cxa_exception struct for compatibility

Steven Wu via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 30 10:10:30 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2a436058fcb: [libcxxabi] Insert padding in __cxa_exception struct for compatibility (authored by steven_wu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72543/new/

https://reviews.llvm.org/D72543

Files:
  libcxxabi/src/cxa_exception.h


Index: libcxxabi/src/cxa_exception.h
===================================================================
--- libcxxabi/src/cxa_exception.h
+++ libcxxabi/src/cxa_exception.h
@@ -29,6 +29,11 @@
 
 struct _LIBCXXABI_HIDDEN __cxa_exception {
 #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
+    // 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;
+
     // 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
@@ -71,6 +76,7 @@
 // primaryException instead of referenceCount.
 struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
 #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
+    void* reserve; // padding.
     void* primaryException;
 #endif
 
@@ -100,6 +106,45 @@
     _Unwind_Exception unwindHeader;
 };
 
+// Verify the negative offsets of different fields.
+static_assert(sizeof(_Unwind_Exception) +
+                      offsetof(__cxa_exception, unwindHeader) ==
+                  sizeof(__cxa_exception),
+              "unwindHeader has wrong negative offsets");
+static_assert(sizeof(_Unwind_Exception) +
+                      offsetof(__cxa_dependent_exception, unwindHeader) ==
+                  sizeof(__cxa_dependent_exception),
+              "unwindHeader has wrong negative offsets");
+
+#if defined(_LIBCXXABI_ARM_EHABI)
+static_assert(offsetof(__cxa_exception, propagationCount) +
+                      sizeof(_Unwind_Exception) + sizeof(void*) ==
+                  sizeof(__cxa_exception),
+              "propagationCount has wrong negative offset");
+static_assert(offsetof(__cxa_dependent_exception, propagationCount) +
+                      sizeof(_Unwind_Exception) + sizeof(void*) ==
+                  sizeof(__cxa_dependent_exception),
+              "propagationCount has wrong negative offset");
+#elif defined(__LP64__)
+static_assert(offsetof(__cxa_exception, adjustedPtr) +
+                      sizeof(_Unwind_Exception) + sizeof(void*) ==
+                  sizeof(__cxa_exception),
+              "adjustedPtr has wrong negative offset");
+static_assert(offsetof(__cxa_dependent_exception, adjustedPtr) +
+                      sizeof(_Unwind_Exception) + sizeof(void*) ==
+                  sizeof(__cxa_dependent_exception),
+              "adjustedPtr has wrong negative offset");
+#else
+static_assert(offsetof(__cxa_exception, referenceCount) +
+                      sizeof(_Unwind_Exception) + sizeof(void*) ==
+                  sizeof(__cxa_exception),
+              "referenceCount has wrong negative offset");
+static_assert(offsetof(__cxa_dependent_exception, primaryException) +
+                      sizeof(_Unwind_Exception) + sizeof(void*) ==
+                  sizeof(__cxa_dependent_exception),
+              "primaryException has wrong negative offset");
+#endif
+
 struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
     __cxa_exception *   caughtExceptions;
     unsigned int        uncaughtExceptions;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72543.241500.patch
Type: text/x-patch
Size: 3175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200130/14942421/attachment.bin>


More information about the libcxx-commits mailing list