[libcxx-commits] [PATCH] D86102: [libunwind] Ensure enough alignment for unw_cursor_t for SEH build configurations

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 17 12:52:06 PDT 2020


mstorsjo created this revision.
mstorsjo added reviewers: cdavis5x, compnerd, libunwind.
Herald added projects: LLVM, libunwind.
Herald added a subscriber: llvm-commits.
Herald added 1 blocking reviewer(s): libunwind.
mstorsjo requested review of this revision.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86102

Files:
  libunwind/include/libunwind.h
  libunwind/src/UnwindCursor.hpp


Index: libunwind/src/UnwindCursor.hpp
===================================================================
--- libunwind/src/UnwindCursor.hpp
+++ libunwind/src/UnwindCursor.hpp
@@ -530,6 +530,8 @@
     : _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 @@
       _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));
 }
 
Index: libunwind/include/libunwind.h
===================================================================
--- libunwind/include/libunwind.h
+++ libunwind/include/libunwind.h
@@ -68,7 +68,11 @@
 
 struct unw_cursor_t {
   uint64_t data[_LIBUNWIND_CURSOR_SIZE];
-};
+}
+#if defined(_WIN32) && defined(__SEH__)
+__attribute__((aligned(16)))
+#endif
+;
 typedef struct unw_cursor_t unw_cursor_t;
 
 typedef struct unw_addr_space *unw_addr_space_t;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86102.286116.patch
Type: text/x-patch
Size: 1497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200817/15925c57/attachment.bin>


More information about the libcxx-commits mailing list