diff mbox series

[committed] libphobos: Give _Unwind_Exception an alignment that best resembles __attribute__((aligned))

Message ID 20210930164304.2837996-1-ibuclaw@gdcproject.org
State New
Headers show
Series [committed] libphobos: Give _Unwind_Exception an alignment that best resembles __attribute__((aligned)) | expand

Commit Message

Iain Buclaw Sept. 30, 2021, 4:43 p.m. UTC
Hi,

This patch gives the definition of _Unwind_Exception on the D side a
suitable alignment.  For interoperability with C++ EH, the alignment
should match, otherwise D may not be able to intercept exceptions thrown
from C++.  Ideally the correct alignment should be exposed by the
compiler, but for now this is good enough for current supported targets.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
committed to mainline.

Regards
Iain

---
libphobos/ChangeLog:

	* libdruntime/gcc/unwind/generic.d (__aligned__): Define.
	(_Unwind_Exception): Align struct to __aligned__.
---
 libphobos/libdruntime/gcc/unwind/generic.d | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libphobos/libdruntime/gcc/unwind/generic.d b/libphobos/libdruntime/gcc/unwind/generic.d
index 592b3afcb71..68ddd1d5410 100644
--- a/libphobos/libdruntime/gcc/unwind/generic.d
+++ b/libphobos/libdruntime/gcc/unwind/generic.d
@@ -123,7 +123,27 @@  enum : _Unwind_Reason_Code
 // @@@ The IA-64 ABI says that this structure must be double-word aligned.
 // Taking that literally does not make much sense generically.  Instead we
 // provide the maximum alignment required by any type for the machine.
-struct _Unwind_Exception
+     version (ARM)      private enum __aligned__ = 8;
+else version (AArch64)  private enum __aligned__ = 16;
+else version (HPPA)     private enum __aligned__ = 8;
+else version (HPPA64)   private enum __aligned__ = 16;
+else version (MIPS_N32) private enum __aligned__ = 16;
+else version (MIPS_N64) private enum __aligned__ = 16;
+else version (MIPS32)   private enum __aligned__ = 8;
+else version (MIPS64)   private enum __aligned__ = 8;
+else version (PPC)      private enum __aligned__ = 16;
+else version (PPC64)    private enum __aligned__ = 16;
+else version (RISCV32)  private enum __aligned__ = 16;
+else version (RISCV64)  private enum __aligned__ = 16;
+else version (S390)     private enum __aligned__ = 8;
+else version (SPARC)    private enum __aligned__ = 8;
+else version (SPARC64)  private enum __aligned__ = 16;
+else version (SystemZ)  private enum __aligned__ = 8;
+else version (X86)      private enum __aligned__ = 16;
+else version (X86_64)   private enum __aligned__ = 16;
+else static assert( false, "Platform not supported.");
+
+align(__aligned__) struct _Unwind_Exception
 {
     _Unwind_Exception_Class exception_class;
     _Unwind_Exception_Cleanup_Fn exception_cleanup;