Skip to content

Commit 500bc6b

Browse files
committed
runtime: don't jump stack if at entry of systemstack
The traceback code has special "jump stack" logic, to trace back stack switches through systemstack. If we're at the entry of systemstack, the stack switch hasn't happened, so don't jump to user stack. The jump stack logic is only used if we're on the g0 stack. It can happen that we're at the entry of a recursive systemstack call on the g0 stack. In we jump stack here, there will be two problems: 1. There are frames between entering the g0 stack and this recursive systemstack call. Those frames will be lost. 2. Worse, we switched frame.sp but frame.fp calculation will use the entry SP delta (0), which will be wrong, which in turn leads wrong frame.lr and things will go off. For now, don't jump stack if we're at entry of systemstack (SP delta is 0). Using a per-PC SPWRITE marker may be a better fix. If we haven't written the SP, we haven't switched the stack so we can just unwind like a normal function. May fix #55851. Change-Id: I2b624c8c086b235b34d9c7d3cebd4a37264f00f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/437299 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 7d3a5a5 commit 500bc6b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/runtime/traceback.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
182182
case funcID_systemstack:
183183
// systemstack returns normally, so just follow the
184184
// stack transition.
185+
if usesLR && funcspdelta(f, frame.pc, &cache) == 0 {
186+
// We're at the function prologue and the stack
187+
// switch hasn't happened, or epilogue where we're
188+
// about to return. Just unwind normally.
189+
// Do this only on LR machines because on x86
190+
// systemstack doesn't have an SP delta (the CALL
191+
// instruction opens the frame), therefore no way
192+
// to check.
193+
flag &^= funcFlag_SPWRITE
194+
break
195+
}
185196
gp = gp.m.curg
186197
frame.sp = gp.sched.sp
187198
stack = gp.stack

0 commit comments

Comments
 (0)