Question about alignment of struct _Unwind_Exception

Florian Weimer fweimer@redhat.com
Wed Nov 4 13:38:25 GMT 2020


* Matheus Castanho via Libc-alpha:

> Hi,
>
> Recently I've been investigating an issue with an invalid TLS access on
> powerpc64le when __libc_malloc tries to read SINGLE_THREAD_P [1]. The
> issue could only be reproduced when using a glibc compiled with
> -mcpu=power10. We found out that the size of 'struct pthread' was
> changing between compiling with -mcpu=power9 and -mcpu=power10.
>
> After inspecting that struct we found out that one specific field was
> changing sizes:
> 	struct _Unwind_Exception exc;
>
> That struct is declared without a fixed alignment value:
>
> struct _Unwind_Exception
> {
>   _Unwind_Exception_Class exception_class;
>   _Unwind_Exception_Cleanup_Fn exception_cleanup;
>   _Unwind_Word private_1;
>   _Unwind_Word private_2;
>   /* @@@ 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__));
>
> The GCC manual says [2]:
>
>> Specifying no alignment argument implies the maximum alignment for the target
>
> The maximum alignment has been recently increased for P10, which we
> suspect is causing the behavior we see.
>
> Is there an specific reason why a fixed alignment value was not used for
> struct _Unwind_Exception?

This looks like a historical accident.  IA-64 probably had a double-word
as the maximum alignment.

Is the problem you are seeing that ld.so has a different struct pthread
layout than libc.so if a multilib is used?  The struct pthread layout
itself is not part of the external ABI, only bits of it are.

Thanks,
Florian
-- 
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill



More information about the Libc-alpha mailing list