[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
Mon Jan 20 11:12:59 PST 2020


steven_wu updated this revision to Diff 239175.
steven_wu added a comment.

Fix ARM_EHABI.


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.cpp
  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
 
Index: libcxxabi/src/cxa_exception.cpp
===================================================================
--- libcxxabi/src/cxa_exception.cpp
+++ libcxxabi/src/cxa_exception.cpp
@@ -36,6 +36,46 @@
 
 namespace __cxxabiv1 {
 
+// 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
+
+
 //  Utility routines
 static
 inline


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72543.239175.patch
Type: text/x-patch
Size: 3244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200120/89cac12d/attachment-0001.bin>


More information about the libcxx-commits mailing list