2022-11-25 11:19:19

by Vincent Whitchurch

[permalink] [raw]
Subject: [PATCH] arm64: vdso: Include .eh_frame in debug ELF

We currently strip out .eh_frame to work around crashes in libgcc when
it tries to unwind out of signal handlers, see commit 87676cfca141
("arm64: vdso: Disable dwarf unwinding through the sigreturn
trampoline").

The .eh_frame does however have correct unwind information for the
functions implemented in C in vgettimeofday.c, but currently this
information is not available even for offline unwinding using the
vdso.so.dbg. As a result of this, perf built with libdw is unable to
unwind the stack when the PC is inside one of these functions.

To fix this, strip the .eh_frame section only from the vdso.so and not
from the vdso.so.dbg. This can be used by offline unwinders with access
to the debug symbols, and will not affect libgcc since the section will
still not be present in the normal vDSO.

Cc: Tamas Zsoldos <[email protected]>
Cc: Szabolcs Nagy <[email protected]>
Cc: Daniel Kiss <[email protected]>
Cc: Vincenzo Frascino <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Signed-off-by: Vincent Whitchurch <[email protected]>
---
arch/arm64/kernel/vdso/Makefile | 2 +-
arch/arm64/kernel/vdso/vdso.lds.S | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index 619e2dc7ee14..91aac17e11bc 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -65,7 +65,7 @@ $(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
$(call if_changed,vdsold_and_vdso_check)

# Strip rule for the .so file
-$(obj)/%.so: OBJCOPYFLAGS := -S
+$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section=.eh_frame --remove-section=.eh_frame_hdr
$(obj)/%.so: $(obj)/%.so.dbg FORCE
$(call if_changed,objcopy)

diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vdso.lds.S
index 6028f1fe2d1c..66abf70efc58 100644
--- a/arch/arm64/kernel/vdso/vdso.lds.S
+++ b/arch/arm64/kernel/vdso/vdso.lds.S
@@ -31,6 +31,8 @@ SECTIONS
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
+ .eh_frame : { *(.eh_frame) }
+ .eh_frame_hdr : { *(.eh_frame_hdr) }

/*
* Discard .note.gnu.property sections which are unused and have
@@ -78,7 +80,6 @@ SECTIONS
/DISCARD/ : {
*(.data .data.* .gnu.linkonce.d.* .sdata*)
*(.bss .sbss .dynbss .dynsbss)
- *(.eh_frame .eh_frame_hdr)
}
}

--
2.34.1


2022-11-25 12:51:30

by Szabolcs Nagy

[permalink] [raw]
Subject: Re: [PATCH] arm64: vdso: Include .eh_frame in debug ELF

The 11/25/2022 11:37, Vincent Whitchurch wrote:
> We currently strip out .eh_frame to work around crashes in libgcc when
> it tries to unwind out of signal handlers, see commit 87676cfca141
> ("arm64: vdso: Disable dwarf unwinding through the sigreturn
> trampoline").
>
> The .eh_frame does however have correct unwind information for the
> functions implemented in C in vgettimeofday.c, but currently this
> information is not available even for offline unwinding using the
> vdso.so.dbg. As a result of this, perf built with libdw is unable to
> unwind the stack when the PC is inside one of these functions.
>
> To fix this, strip the .eh_frame section only from the vdso.so and not
> from the vdso.so.dbg. This can be used by offline unwinders with access
> to the debug symbols, and will not affect libgcc since the section will
> still not be present in the normal vDSO.

adding eh_frame to vdso.so.dbg makes sense.

but if libdw correctly unwinds across a signal handler
then libgcc should be able to do so too.

so maybe eh_frame should be added back to vdso.so just
without frame info for __kernel_rt_sigreturn+NOP to
ensure unwinders use heuristics for sigreturn.
(i dont know if this was considered back when eh_frame
was dropped from the vdso)

>
> Cc: Tamas Zsoldos <[email protected]>
> Cc: Szabolcs Nagy <[email protected]>
> Cc: Daniel Kiss <[email protected]>
> Cc: Vincenzo Frascino <[email protected]>
> Cc: Ard Biesheuvel <[email protected]>
> Signed-off-by: Vincent Whitchurch <[email protected]>
> ---
> arch/arm64/kernel/vdso/Makefile | 2 +-
> arch/arm64/kernel/vdso/vdso.lds.S | 3 ++-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
> index 619e2dc7ee14..91aac17e11bc 100644
> --- a/arch/arm64/kernel/vdso/Makefile
> +++ b/arch/arm64/kernel/vdso/Makefile
> @@ -65,7 +65,7 @@ $(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE
> $(call if_changed,vdsold_and_vdso_check)
>
> # Strip rule for the .so file
> -$(obj)/%.so: OBJCOPYFLAGS := -S
> +$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section=.eh_frame --remove-section=.eh_frame_hdr
> $(obj)/%.so: $(obj)/%.so.dbg FORCE
> $(call if_changed,objcopy)
>
> diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vdso.lds.S
> index 6028f1fe2d1c..66abf70efc58 100644
> --- a/arch/arm64/kernel/vdso/vdso.lds.S
> +++ b/arch/arm64/kernel/vdso/vdso.lds.S
> @@ -31,6 +31,8 @@ SECTIONS
> .gnu.version : { *(.gnu.version) }
> .gnu.version_d : { *(.gnu.version_d) }
> .gnu.version_r : { *(.gnu.version_r) }
> + .eh_frame : { *(.eh_frame) }
> + .eh_frame_hdr : { *(.eh_frame_hdr) }
>
> /*
> * Discard .note.gnu.property sections which are unused and have
> @@ -78,7 +80,6 @@ SECTIONS
> /DISCARD/ : {
> *(.data .data.* .gnu.linkonce.d.* .sdata*)
> *(.bss .sbss .dynbss .dynsbss)
> - *(.eh_frame .eh_frame_hdr)
> }
> }
>
> --
> 2.34.1
>

2022-11-28 10:50:31

by Vincent Whitchurch

[permalink] [raw]
Subject: Re: [PATCH] arm64: vdso: Include .eh_frame in debug ELF

On Fri, Nov 25, 2022 at 01:27:14PM +0100, Szabolcs Nagy wrote:
> The 11/25/2022 11:37, Vincent Whitchurch wrote:
> > We currently strip out .eh_frame to work around crashes in libgcc when
> > it tries to unwind out of signal handlers, see commit 87676cfca141
> > ("arm64: vdso: Disable dwarf unwinding through the sigreturn
> > trampoline").
> >
> > The .eh_frame does however have correct unwind information for the
> > functions implemented in C in vgettimeofday.c, but currently this
> > information is not available even for offline unwinding using the
> > vdso.so.dbg. As a result of this, perf built with libdw is unable to
> > unwind the stack when the PC is inside one of these functions.
> >
> > To fix this, strip the .eh_frame section only from the vdso.so and not
> > from the vdso.so.dbg. This can be used by offline unwinders with access
> > to the debug symbols, and will not affect libgcc since the section will
> > still not be present in the normal vDSO.
>
> adding eh_frame to vdso.so.dbg makes sense.
>
> but if libdw correctly unwinds across a signal handler
> then libgcc should be able to do so too.

I have not tested if libdw can unwind across a signal handler. It is
unlikely to work since all the CFI directives in __kernel_rt_sigreturn
are commented out. The CFI in .eh_frame only covers the C functions and
unwinding those works with libdw.

$ aarch64-linux-gnu-objdump --dwarf=frames arch/arm64/kernel/vdso/vdso.so.dbg | grep pc
00000014 000000000000001c 00000018 FDE cie=00000000 pc=0000000000000330..00000000000005cc
00000034 0000000000000014 00000038 FDE cie=00000000 pc=00000000000005d0..0000000000000784
0000004c 0000000000000018 00000050 FDE cie=00000000 pc=0000000000000784..00000000000007fc
$ nm -n arch/arm64/kernel/vdso/vdso.so.dbg
0000000000000330 T __kernel_clock_gettime
00000000000005d0 T __kernel_gettimeofday
0000000000000784 T __kernel_clock_getres
0000000000000820 T __kernel_rt_sigreturn

> so maybe eh_frame should be added back to vdso.so just
> without frame info for __kernel_rt_sigreturn+NOP to
> ensure unwinders use heuristics for sigreturn.
> (i dont know if this was considered back when eh_frame
> was dropped from the vdso)

I don't know either why 87676cfca141 had to both remove the CFI
directives from __kernel_rt_sigreturn and remove the .eh_frame section
completely from vdso.so instead of only doing the former, but I assume
there was a good reason for that.