[PATCH v2 1/2] elf: Do not over-align __FRAME_END__ in sofini.c
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Nov 2 20:10:00 GMT 2026
On 29/10/26 14:49, Adrian Ratiu wrote:
> __FRAME_END__ has no explicit alignment, so on targets where GCC's
> DATA_ALIGNMENT raises the alignment of arrays (e.g. on aarch64,
> loongarch64 and mips64) it gets 8-byte alignment.
>
> The .eh_frame section of sofini.os then has sh_addralign 8 while the
> one of crtendS.o has 4, and GNU ld may insert 4 bytes of zero padding
> before the terminator. The padding reads as a zero length so the result
> still works, but it should not be relied upon.
>
> So we set the alignment explicitly, as libgcc's crtstuff.c does (see
> GCC commit 51084e13c01, "Don't overalign if DECL_USER_ALIGN").
>
> Suggested-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
I checked that the .eh_frame alignment of sofini.o goes from 8 to 4 on
aarch64, loongarch64, mips64, mips64el and riscv64, matching crtendS.o.
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> elf/sofini.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/elf/sofini.c b/elf/sofini.c
> index 1c526fd603..1dae5ccc67 100644
> --- a/elf/sofini.c
> +++ b/elf/sofini.c
> @@ -1,7 +1,9 @@
> /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
> - this would be the 'length' field in a real FDE. */
> -
> + this would be the 'length' field in a real FDE. PT_GNU_EH_FRAME only
> + provides the start of .eh_frame, so unwinders that scan it linearly
> + need the sentinel even when there is an .eh_frame_hdr. Set the alignment
> + explicitly so that the compiler does not over-align the array. */
> typedef unsigned int ui32 __attribute__ ((mode (SI)));
> static const ui32 __FRAME_END__[1]
> - __attribute__ ((used, section (".eh_frame")))
> + __attribute__ ((used, section (".eh_frame"), aligned (__alignof__ (ui32))))
> = { 0 };
More information about the Libc-alpha
mailing list