Skip to content

Commit a4eb355

Browse files
committed
arm64: vdso: Fix CFI directives in sigreturn trampoline
Daniel reports that the .cfi_startproc is misplaced for the sigreturn trampoline, which causes LLVM's unwinder to misbehave: | I run into this with LLVM’s unwinder. | This combination was always broken. This prompted Dave to question our use of CFI directives more generally, and I ended up going down a rabbit hole trying to figure out how this very poorly documented stuff gets used. Move the CFI directives so that the "mysterious NOP" is included in the .cfi_{start,end}proc block and add a bunch of comments so that I can save myself another headache in future. Cc: Tamas Zsoldos <tamas.zsoldos@arm.com> Reported-by: Dave Martin <dave.martin@arm.com> Reported-by: Daniel Kiss <daniel.kiss@arm.com> Tested-by: Daniel Kiss <daniel.kiss@arm.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 9a96428 commit a4eb355

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

arch/arm64/kernel/vdso/sigreturn.S

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
/*
33
* Sigreturn trampoline for returning from a signal when the SA_RESTORER
4-
* flag is not set.
4+
* flag is not set. It serves primarily as a hall of shame for crappy
5+
* unwinders and features an exciting but mysterious NOP instruction.
6+
*
7+
* It's also fragile as hell, so please think twice before changing anything
8+
* in here.
59
*
610
* Copyright (C) 2012 ARM Limited
711
*
@@ -14,7 +18,38 @@
1418

1519
.text
1620

17-
nop
21+
/* Ensure that the mysterious NOP can be associated with a function. */
22+
.cfi_startproc
23+
24+
/*
25+
* .cfi_signal_frame causes the corresponding Frame Description Entry in the
26+
* .eh_frame section to be annotated as a signal frame. This allows DWARF
27+
* unwinders (e.g. libstdc++) to implement _Unwind_GetIPInfo(), which permits
28+
* unwinding out of the signal trampoline without the need for the mysterious
29+
* NOP.
30+
*/
31+
.cfi_signal_frame
32+
33+
/*
34+
* Tell the unwinder where to locate the frame record linking back to the
35+
* interrupted context. We don't provide unwind info for registers other
36+
* than the frame pointer and the link register here; in practice, this
37+
* is sufficient for unwinding in C/C++ based runtimes and the values in
38+
* the sigcontext may have been modified by this point anyway. Debuggers
39+
* already have baked-in strategies for attempting to unwind out of signals.
40+
*/
41+
.cfi_def_cfa x29, 0
42+
.cfi_offset x29, 0 * 8
43+
.cfi_offset x30, 1 * 8
44+
45+
/*
46+
* This mysterious NOP is required for some unwinders (e.g. libc++) that
47+
* unconditionally subtract one from the result of _Unwind_GetIP() in order to
48+
* identify the calling function.
49+
* Hack borrowed from arch/powerpc/kernel/vdso64/sigtramp.S.
50+
*/
51+
nop // Mysterious NOP
52+
1853
/*
1954
* GDB relies on being able to identify the sigreturn instruction sequence to
2055
* unwind from signal handlers. We cannot, therefore, use SYM_FUNC_START()
@@ -23,11 +58,6 @@
2358
* is perfectly fine.
2459
*/
2560
SYM_CODE_START(__kernel_rt_sigreturn)
26-
.cfi_startproc
27-
.cfi_signal_frame
28-
.cfi_def_cfa x29, 0
29-
.cfi_offset x29, 0 * 8
30-
.cfi_offset x30, 1 * 8
3161
mov x8, #__NR_rt_sigreturn
3262
svc #0
3363
.cfi_endproc

arch/arm64/kernel/vdso32/sigreturn.S

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* This file provides both A32 and T32 versions, in accordance with the
44
* arm sigreturn code.
55
*
6+
* Please read the comments in arch/arm64/kernel/vdso/sigreturn.S to
7+
* understand some of the craziness in here.
8+
*
69
* Copyright (C) 2018 ARM Limited
710
*/
811

0 commit comments

Comments
 (0)