aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2019-01-09 11:21:07 -0500
committerCherry Zhang <cherryyz@google.com>2019-01-09 18:38:22 +0000
commit52cae2763ee59ea63e885e9a41708e3ce677039a (patch)
treebeca29fd1141c9fcc6a4c06573f4cd2399b7cf27
parent8765a786b6e8199959bba8244ac5f95aa3eb9474 (diff)
downloadgo-52cae2763ee59ea63e885e9a41708e3ce677039a.tar.gz
go-52cae2763ee59ea63e885e9a41708e3ce677039a.zip
cmd/internal/obj/wasm: increment PC by 2 at sigpanic
On Wasm, PC is not the instruction counter but the block ID. We advance the PC only when necessary. In the case of sigpanic (used in nil check), the panic stack trace expects the PC at the call of sigpanic, not the next one. However, runtime.Caller subtracts 1 from the PC. To make both PC and PC-1 work (have the same line number), we advance the PC by 2 at sigpanic. Fixes #29632. Change-Id: Ieb4d0bb9dc6a8103855a194e3d289f1db4bfb1e5 Reviewed-on: https://go-review.googlesource.com/c/157157 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Richard Musiol <neelance@gmail.com> Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/cmd/internal/obj/wasm/wasmobj.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/internal/obj/wasm/wasmobj.go b/src/cmd/internal/obj/wasm/wasmobj.go
index 52c9710ff0..23283a12cf 100644
--- a/src/cmd/internal/obj/wasm/wasmobj.go
+++ b/src/cmd/internal/obj/wasm/wasmobj.go
@@ -280,6 +280,13 @@ func preprocess(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
// implicit call, so entering and leaving this section affects the stack trace.
if p.As == ACALLNORESUME || p.As == obj.ANOP || p.As == ANop || p.Spadj != 0 || base != prevBase {
pc++
+ if p.To.Sym == sigpanic {
+ // The panic stack trace expects the PC at the call of sigpanic,
+ // not the next one. However, runtime.Caller subtracts 1 from the
+ // PC. To make both PC and PC-1 work (have the same line number),
+ // we advance the PC by 2 at sigpanic.
+ pc++
+ }
}
}
tableIdxs = append(tableIdxs, uint64(numResumePoints))