Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit c56e8e0

Browse files
committed
Fix issue 16856: Apply correct alignment on the Unwind_Exception structure
In libundwind, _Unwind_Exception structure is defined as follows: ``` struct _Unwind_Exception { uint64_t exception_class; _Unwind_Exception_Cleanup_Fn exception_cleanup; unsigned long private_1; unsigned long private_2; } __attribute__((__aligned__)); ``` so the alignment is done on the entire structure, and it depends on the architecture. This sets the structure to be 16bit aligned on the X86_64, so the binary layout matches and that the C++ compiler's optimizations are still valid (for example, on FreeBSD-12, exception handling was broken because libunwind assumes correct alignment, so the fast but fragile instructions were used.
1 parent eb58dcb commit c56e8e0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/rt/unwind.d

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,25 @@ alias _Unwind_Exception_Cleanup_Fn = void function(
4848
_Unwind_Reason_Code reason,
4949
_Unwind_Exception *exc);
5050

51-
struct _Unwind_Exception
51+
version (X86_64)
5252
{
53-
align(8) _Unwind_Exception_Class exception_class;
54-
_Unwind_Exception_Cleanup_Fn exception_cleanup;
55-
_Unwind_Word private_1;
56-
_Unwind_Word private_2;
53+
align(16) struct _Unwind_Exception
54+
{
55+
_Unwind_Exception_Class exception_class;
56+
_Unwind_Exception_Cleanup_Fn exception_cleanup;
57+
_Unwind_Word private_1;
58+
_Unwind_Word private_2;
59+
}
60+
}
61+
else
62+
{
63+
align(8) struct _Unwind_Exception
64+
{
65+
_Unwind_Exception_Class exception_class;
66+
_Unwind_Exception_Cleanup_Fn exception_cleanup;
67+
_Unwind_Word private_1;
68+
_Unwind_Word private_2;
69+
}
5770
}
5871

5972
struct _Unwind_Context;

0 commit comments

Comments
 (0)