Skip to content

Commit

Permalink
runtime: ignore SPWRITE in syscall functions
Browse files Browse the repository at this point in the history
netbsd/amd64's Syscall9 changes SP using ADD and SUB,
which are treated as SPWRITEs (they are not accounted for
in the sp-adjust tracking, and there are too many functions that
would report mismatched stack adjustments at RET if they were).
A traceback starting in Syscall9 as saved by entersyscall complains
about the SPWRITE-ness unnecessarily, since the PC/SP are saved
at the start of the function. Ignore SPWRITE in that case.

netbsd/arm's Syscall6 also changes SP (R13), using a direct write.
So even if we could handle the ADD/SUB in the amd64 case or
rewrote that assembly, we'd still be stuck with a more difficult
problem in this case. Ignoring the SPWRITE fixes it.

Example crashes:
https://build.golang.org/log/160fc7b051a2cf90782b75a99984fff129329e66
https://build.golang.org/log/7879e2fecdb400eee616294285e1f952e5b17301

Change-Id: I0c8e9696066e90dafed6d4a93d11697da23f0080
Reviewed-on: https://go-review.googlesource.com/c/go/+/294072
Reviewed-by: Cherry Zhang <[email protected]>
Trust: Russ Cox <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
  • Loading branch information
rsc committed Feb 19, 2021
1 parent fa18f22 commit 02e5a8f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runtime/traceback.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
// So we don't need to exclude it with the other SP-writing functions.
flag &^= funcFlag_SPWRITE
}
if frame.pc == pc0 && frame.sp == sp0 && pc0 == gp.syscallpc && sp0 == gp.syscallsp {
// Some Syscall functions write to SP, but they do so only after
// saving the entry PC/SP using entersyscall.
// Since we are using the entry PC/SP, the later SP write doesn't matter.
flag &^= funcFlag_SPWRITE
}

// Found an actual function.
// Derive frame pointer and link register.
Expand Down

0 comments on commit 02e5a8f

Please sign in to comment.