From: Austin Clements Date: Fri, 9 Mar 2018 21:12:40 +0000 (-0500) Subject: runtime: fix abort handling on arm64 X-Git-Tag: go1.11beta1~1253 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0def0f2e993111308a114bb83604618f218b7c3d;p=gostls13.git runtime: fix abort handling on arm64 The implementation of runtime.abort on arm64 currently branches to address 0, which results in a signal from PC 0, rather than from runtime.abort, so the runtime fails to recognize it as an abort. Fix runtime.abort on arm64 to read from address 0 like what other architectures do and recognize this in the signal handler. Should fix the linux/arm64 build. Change-Id: I960ab630daaeadc9190287604d4d8337b1ea3853 Reviewed-on: https://go-review.googlesource.com/99895 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index e88532728a..2b39d2ec72 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -710,7 +710,8 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8 RET TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0 - B (ZR) + MOVD ZR, R0 + MOVD (R0), R0 UNDEF TEXT runtime·return0(SB), NOSPLIT, $0 diff --git a/src/runtime/os3_plan9.go b/src/runtime/os3_plan9.go index 9158c44f2f..0e3a4c8024 100644 --- a/src/runtime/os3_plan9.go +++ b/src/runtime/os3_plan9.go @@ -35,7 +35,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int { print("sighandler: note is longer than ERRMAX\n") goto Throw } - if c.pc() == funcPC(abort) || (GOARCH == "arm" && c.pc() == funcPC(abort)+4) { + if isAbortPC(c.pc()) { // Never turn abort into a panic. goto Throw } diff --git a/src/runtime/panic.go b/src/runtime/panic.go index d9fa512530..10945ace0d 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -837,3 +837,9 @@ func shouldPushSigpanic(gp *g, pc, lr uintptr) bool { // will work. return true } + +// isAbortPC returns true if pc is the program counter at which +// runtime.abort raises a signal. +func isAbortPC(pc uintptr) bool { + return pc == funcPC(abort) || ((GOARCH == "arm" || GOARCH == "arm64") && pc == funcPC(abort)+sys.PCQuantum) +} diff --git a/src/runtime/signal_sighandler.go b/src/runtime/signal_sighandler.go index 3004e36769..b75e98b262 100644 --- a/src/runtime/signal_sighandler.go +++ b/src/runtime/signal_sighandler.go @@ -43,7 +43,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) { // stack. Abort in the signal handler instead. flags = (flags &^ _SigPanic) | _SigThrow } - if c.sigpc() == funcPC(abort) || (GOARCH == "arm" && c.sigpc() == funcPC(abort)+4) { + if isAbortPC(c.sigpc()) { // On many architectures, the abort function just // causes a memory fault. Don't turn that into a panic. flags = _SigThrow diff --git a/src/runtime/signal_windows.go b/src/runtime/signal_windows.go index 4d55f0fe6c..ad08019fc1 100644 --- a/src/runtime/signal_windows.go +++ b/src/runtime/signal_windows.go @@ -46,7 +46,7 @@ func isgoexception(info *exceptionrecord, r *context) bool { return false } - if r.ip() == funcPC(abort) || (GOARCH == "arm" && r.ip() == funcPC(abort)+4) { + if isAbortPC(r.ip()) { // Never turn abort into a panic. return false }