Question about alignment of struct _Unwind_Exception

Matheus Castanho msc@linux.ibm.com
Tue Nov 10 17:47:13 GMT 2020



On 11/6/20 8:16 PM, Peter Bergner wrote:
> On 11/4/20 1:31 PM, Florian Weimer wrote:
>>> If I can align the MMA types a different way, then the default
>>> alignment will go back to 128 bits, which should "fix" the issue
>>> you are seeing.
>>
>> x86-64 does this as well if 512-bit vector types exist.  We need to fix
>> this in glibc.  (Maybe things work out due to the struct pthread layout
>> on x86-64, but it's still a bug.)
> 
> I agree GLIBC has a problem here.  That said, GCC should not have changed
> the default alignment either.  I just committed a fix to GCC trunk that
> reverts the change to BIGGEST_ALIGNMENT and fixes the alignment of the MMA
> types a different way.  I will backport the fix to thje GCC 10 release
> branch after it's baked a couple of days on trunk.
> 
> Peter
> 

Thanks for the GCC fix, Peter.

Florian, on the glibc side, I'm experimenting with declaring a new macro to be used
as the alignment value for struct _Unwind_Exception and then fixing that macro to
the current BIGGEST_ALIGNMENT value for each arch, according to GCC source.

This should effectively be a no-op and protect struct pthread from future changes to
BIGGEST_ALIGNMENT. I tried something like (powerpc-only example):

diff --git a/sysdeps/generic/unwind-arch.h b/sysdeps/generic/unwind-arch.h
index d712e5e11d..17f3efd271 100644
--- a/sysdeps/generic/unwind-arch.h
+++ b/sysdeps/generic/unwind-arch.h
@@ -19,7 +19,9 @@
 #ifndef _UNWIND_ARCH_H
 #define _UNWIND_ARCH_H
 
-#include <unwind.h>
+#ifndef UNWIND_EXCEPTION_ALIGN
+# define UNWIND_EXCEPTION_ALIGN
+#endif
 
 static inline void *
 unwind_arch_adjustment (void *prev, void *addr)
diff --git a/sysdeps/generic/unwind.h b/sysdeps/generic/unwind.h
index b667a5b652..da1b5e6ca7 100644
--- a/sysdeps/generic/unwind.h
+++ b/sysdeps/generic/unwind.h
@@ -27,6 +27,8 @@
 extern "C" {
 #endif
 
+#include <unwind-arch.h>
+
 /* Level 1: Base ABI  */
 
 /* @@@ The IA-64 ABI uses uint64 throughout.  Most places this is
@@ -83,7 +85,7 @@ struct _Unwind_Exception
   /* @@@ 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.  */
-} __attribute__((__aligned__));
+} __attribute__((__aligned__(UNWIND_EXCEPTION_ALIGN)));
 
 
 /* The ACTIONS argument to the personality routine is a bitwise OR of one
diff --git a/sysdeps/powerpc/unwind-arch.h b/sysdeps/powerpc/unwind-arch.h
new file mode 100644
index 0000000000..b7756da28a
--- /dev/null
+++ b/sysdeps/powerpc/unwind-arch.h
@@ -0,0 +1,6 @@
+#ifndef _UNWIND_ARCH_H
+#define _UNWIND_ARCH_H
+
+#define UNWIND_EXCEPTION_ALIGN 16
+
+#endif

--

Do you have any suggestions on a better way to deal with this?

Thanks,
Matheus Castanho


More information about the Libc-alpha mailing list