[libunwind] 542db87 - [libunwind] Ensure enough alignment for unw_cursor_t for SEH build configurations
Martin Storsjö via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 22 12:56:46 PDT 2020
Author: Martin Storsjö
Date: 2020-08-22T22:48:57+03:00
New Revision: 542db87f1ac67087aeb5cf572b1f9744d482da69
URL: https://github.com/llvm/llvm-project/commit/542db87f1ac67087aeb5cf572b1f9744d482da69
DIFF: https://github.com/llvm/llvm-project/commit/542db87f1ac67087aeb5cf572b1f9744d482da69.diff
LOG: [libunwind] Ensure enough alignment for unw_cursor_t for SEH build configurations
When built in SEH mode, UnwindCursor contains a CONTEXT struct,
which is aligned to 16 bytes in most configurations, causing the
whole UnwindCursor object to have 16 byte alignment.
This fixes backtraces using _Unwind_Backtrace on x86_64 mingw,
where an unw_cursor_t allocated on the stack was misaligned before.
This is an ABI break for this struct for this configuration, but very
few callers call libunwind directly (and even fewer directly allocate
an unw_cursor_t anyway).
Differential Revision: https://reviews.llvm.org/D86102
Added:
Modified:
libunwind/include/libunwind.h
libunwind/src/UnwindCursor.hpp
Removed:
################################################################################
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 23ef47f4ac83..6ec649a460b8 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -43,6 +43,12 @@
#define LIBUNWIND_AVAIL
#endif
+#if defined(_WIN32) && defined(__SEH__)
+ #define LIBUNWIND_CURSOR_ALIGNMENT_ATTR __attribute__((__aligned__(16)))
+#else
+ #define LIBUNWIND_CURSOR_ALIGNMENT_ATTR
+#endif
+
/* error codes */
enum {
UNW_ESUCCESS = 0, /* no error */
@@ -68,7 +74,7 @@ typedef struct unw_context_t unw_context_t;
struct unw_cursor_t {
uint64_t data[_LIBUNWIND_CURSOR_SIZE];
-};
+} LIBUNWIND_CURSOR_ALIGNMENT_ATTR;
typedef struct unw_cursor_t unw_cursor_t;
typedef struct unw_addr_space *unw_addr_space_t;
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 03e21fb87a8d..54913360ca29 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -530,6 +530,8 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
: _addressSpace(as), _unwindInfoMissing(false) {
static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
"UnwindCursor<> does not fit in unw_cursor_t");
+ static_assert((alignof(UnwindCursor<A, R>) <= alignof(unw_cursor_t)),
+ "UnwindCursor<> requires more alignment than unw_cursor_t");
memset(&_info, 0, sizeof(_info));
memset(&_histTable, 0, sizeof(_histTable));
_dispContext.ContextRecord = &_msContext;
@@ -1182,6 +1184,8 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
_isSignalFrame(false) {
static_assert((check_fit<UnwindCursor<A, R>, unw_cursor_t>::does_fit),
"UnwindCursor<> does not fit in unw_cursor_t");
+ static_assert((alignof(UnwindCursor<A, R>) <= alignof(unw_cursor_t)),
+ "UnwindCursor<> requires more alignment than unw_cursor_t");
memset(&_info, 0, sizeof(_info));
}
More information about the cfe-commits
mailing list