Re: [PATCH for 6.6] LoongArch: vDSO: Emit GNU_EH_FRAME correctly
From: Xi Ruoyao
Date: Tue Mar 31 2026 - 08:01:51 EST
On Tue, 2026-03-31 at 13:10 +0200, Greg Kroah-Hartman wrote:
> On Mon, Mar 30, 2026 at 06:01:33PM +0800, Huacai Chen wrote:
> > From: Xi Ruoyao <xry111@xxxxxxxxxxx>
> >
> > commit e4878c37f6679fdea91b27a0f4e60a871f0b7bad upstream.
> >
> > With -fno-asynchronous-unwind-tables and --no-eh-frame-hdr (the default
> > of the linker), the GNU_EH_FRAME segment (specified by vdso.lds.S) is
> > empty. This is not valid, as the current DWARF specification mandates
> > the first byte of the EH frame to be the version number 1. It causes
> > some unwinders to complain, for example the ClickHouse query profiler
> > spams the log with messages:
> >
> > clickhouse-server[365854]: libunwind: unsupported .eh_frame_hdr
> > version: 127 at 7ffffffb0000
> >
> > Here "127" is just the byte located at the p_vaddr (0, i.e. the
> > beginning of the vDSO) of the empty GNU_EH_FRAME segment. Cross-
> > checking with /proc/365854/maps has also proven 7ffffffb0000 is the
> > start of vDSO in the process VM image.
> >
> > In LoongArch the -fno-asynchronous-unwind-tables option seems just a
> > MIPS legacy, and MIPS only uses this option to satisfy the MIPS-specific
> > "genvdso" program, per the commit cfd75c2db17e ("MIPS: VDSO: Explicitly
> > use -fno-asynchronous-unwind-tables"). IIRC it indicates some inherent
> > limitation of the MIPS ELF ABI and has nothing to do with LoongArch. So
> > we can simply flip it over to -fasynchronous-unwind-tables and pass
> > --eh-frame-hdr for linking the vDSO, allowing the profilers to unwind the
> > stack for statistics even if the sample point is taken when the PC is in
> > the vDSO.
> >
> > However simply adjusting the options above would exploit an issue: when
> > the libgcc unwinder saw the invalid GNU_EH_FRAME segment, it silently
> > falled back to a machine-specific routine to match the code pattern of
> > rt_sigreturn() and extract the registers saved in the sigframe if the
> > code pattern is matched. As unwinding from signal handlers is vital for
> > libgcc to support pthread cancellation etc., the fall-back routine had
> > been silently keeping the LoongArch Linux systems functioning since
> > Linux 5.19. But when we start to emit GNU_EH_FRAME with the correct
> > format, fall-back routine will no longer be used and libgcc will fail
> > to unwind the sigframe, and unwinding from signal handlers will no
> > longer work, causing dozens of glibc test failures. To make it possible
> > to unwind from signal handlers again, it's necessary to code the unwind
> > info in __vdso_rt_sigreturn via .cfi_* directives.
> >
> > The offsets in the .cfi_* directives depend on the layout of struct
> > sigframe, notably the offset of sigcontext in the sigframe. To use the
> > offset in the assembly file, factor out struct sigframe into a header to
> > allow asm-offsets.c to output the offset for assembly.
> >
> > To work around a long-term issue in the libgcc unwinder (the pc is
> > unconditionally substracted by 1: doing so is technically incorrect for
> > a signal frame), a nop instruction is included with the two real
> > instructions in __vdso_rt_sigreturn in the same FDE PC range. The same
> > hack has been used on x86 for a long time.
> >
> > Cc: stable@xxxxxxxxxxxxxxx
> > Fixes: c6b99bed6b8f ("LoongArch: Add VDSO and VSYSCALL support")
> > Signed-off-by: Xi Ruoyao <xry111@xxxxxxxxxxx>
> > Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
> > ---
>
> Does not apply cleanly on the latest 6.12.y queue :(
This is for 6.6. Maybe your agent is malfunctioning?
--
Xi Ruoyao <xry111@xxxxxxxxxxx>