Skip to content

Commit e4be2ac

Browse files
committed
runtime: mark morestack_noctxt SPWRITE on LR architectures
On LR architectures, morestack (and morestack_noctxt) are called with a special calling convention, where the caller doesn't save LR on stack but passes it as a register, which morestack will save to g.sched.lr. The stack unwinder currently doesn't understand it, and would fail to unwind from it. morestack already writes SP (as it switches stack), but morestack_noctxt (which tailcalls morestack) doesn't. If a profiling signal lands right in morestack_noctxt, the unwinder will try to unwind the stack and go off, and possibly crash. Marking morestack_noctxt SPWRITE stops the unwinding. Ideally we could teach the unwinder about the special calling convention, or change the calling convention to be less special (so the unwinder doesn't need to fetch a register from the signal context). This is a stop-gap solution, to stop the unwinder from crashing. Fixes #54332. Change-Id: I75295f2e27ddcf05f1ea0b541aedcb9000ae7576 Reviewed-on: https://go-review.googlesource.com/c/go/+/425396 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent d4ff25a commit e4be2ac

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

src/runtime/asm_arm.s

+7
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
387387
RET
388388

389389
TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
390+
// Force SPWRITE. This function doesn't actually write SP,
391+
// but it is called with a special calling convention where
392+
// the caller doesn't save LR on stack but passes it as a
393+
// register (R3), and the unwinder currently doesn't understand.
394+
// Make it SPWRITE to stop unwinding. (See issue 54332)
395+
MOVW R13, R13
396+
390397
MOVW $0, R7
391398
B runtime·morestack(SB)
392399

src/runtime/asm_arm64.s

+7
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
320320
UNDEF
321321

322322
TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
323+
// Force SPWRITE. This function doesn't actually write SP,
324+
// but it is called with a special calling convention where
325+
// the caller doesn't save LR on stack but passes it as a
326+
// register (R3), and the unwinder currently doesn't understand.
327+
// Make it SPWRITE to stop unwinding. (See issue 54332)
328+
MOVD RSP, RSP
329+
323330
MOVW $0, R26
324331
B runtime·morestack(SB)
325332

src/runtime/asm_mips64x.s

+7
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
258258
UNDEF
259259

260260
TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
261+
// Force SPWRITE. This function doesn't actually write SP,
262+
// but it is called with a special calling convention where
263+
// the caller doesn't save LR on stack but passes it as a
264+
// register (R3), and the unwinder currently doesn't understand.
265+
// Make it SPWRITE to stop unwinding. (See issue 54332)
266+
MOVV R29, R29
267+
261268
MOVV R0, REGCTXT
262269
JMP runtime·morestack(SB)
263270

src/runtime/asm_mipsx.s

+7
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
257257
UNDEF
258258

259259
TEXT runtime·morestack_noctxt(SB),NOSPLIT,$0-0
260+
// Force SPWRITE. This function doesn't actually write SP,
261+
// but it is called with a special calling convention where
262+
// the caller doesn't save LR on stack but passes it as a
263+
// register (R3), and the unwinder currently doesn't understand.
264+
// Make it SPWRITE to stop unwinding. (See issue 54332)
265+
MOVW R29, R29
266+
260267
MOVW R0, REGCTXT
261268
JMP runtime·morestack(SB)
262269

src/runtime/asm_ppc64x.s

+7
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
334334
UNDEF
335335

336336
TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
337+
// Force SPWRITE. This function doesn't actually write SP,
338+
// but it is called with a special calling convention where
339+
// the caller doesn't save LR on stack but passes it as a
340+
// register (R5), and the unwinder currently doesn't understand.
341+
// Make it SPWRITE to stop unwinding. (See issue 54332)
342+
MOVD R1, R1
343+
337344
MOVD R0, R11
338345
BR runtime·morestack(SB)
339346

src/runtime/asm_riscv64.s

+9-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8
158158
*/
159159

160160
// Called during function prolog when more stack is needed.
161-
// Caller has already loaded:
162-
// R1: framesize, R2: argsize, R3: LR
161+
// Called with return address (i.e. caller's PC) in X5 (aka T0),
162+
// and the LR register contains the caller's LR.
163163
//
164164
// The traceback routines see morestack on a g0 as being
165165
// the top of a stack (for example, morestack calling newstack
@@ -209,6 +209,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
209209

210210
// func morestack_noctxt()
211211
TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
212+
// Force SPWRITE. This function doesn't actually write SP,
213+
// but it is called with a special calling convention where
214+
// the caller doesn't save LR on stack but passes it as a
215+
// register, and the unwinder currently doesn't understand.
216+
// Make it SPWRITE to stop unwinding. (See issue 54332)
217+
MOV X2, X2
218+
212219
MOV ZERO, CTXT
213220
JMP runtime·morestack(SB)
214221

src/runtime/asm_s390x.s

+7
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
346346
UNDEF
347347

348348
TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
349+
// Force SPWRITE. This function doesn't actually write SP,
350+
// but it is called with a special calling convention where
351+
// the caller doesn't save LR on stack but passes it as a
352+
// register (R5), and the unwinder currently doesn't understand.
353+
// Make it SPWRITE to stop unwinding. (See issue 54332)
354+
MOVD R15, R15
355+
349356
MOVD $0, R12
350357
BR runtime·morestack(SB)
351358

0 commit comments

Comments
 (0)