Commit 0def0f2e authored by Austin Clements's avatar Austin Clements

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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarCherry Zhang <cherryyz@google.com>
parent e4de522c
...@@ -710,7 +710,8 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8 ...@@ -710,7 +710,8 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8
RET RET
TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0 TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
B (ZR) MOVD ZR, R0
MOVD (R0), R0
UNDEF UNDEF
TEXT runtime·return0(SB), NOSPLIT, $0 TEXT runtime·return0(SB), NOSPLIT, $0
......
...@@ -35,7 +35,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int { ...@@ -35,7 +35,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
print("sighandler: note is longer than ERRMAX\n") print("sighandler: note is longer than ERRMAX\n")
goto Throw goto Throw
} }
if c.pc() == funcPC(abort) || (GOARCH == "arm" && c.pc() == funcPC(abort)+4) { if isAbortPC(c.pc()) {
// Never turn abort into a panic. // Never turn abort into a panic.
goto Throw goto Throw
} }
......
...@@ -837,3 +837,9 @@ func shouldPushSigpanic(gp *g, pc, lr uintptr) bool { ...@@ -837,3 +837,9 @@ func shouldPushSigpanic(gp *g, pc, lr uintptr) bool {
// will work. // will work.
return true 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)
}
...@@ -43,7 +43,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) { ...@@ -43,7 +43,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
// stack. Abort in the signal handler instead. // stack. Abort in the signal handler instead.
flags = (flags &^ _SigPanic) | _SigThrow 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 // On many architectures, the abort function just
// causes a memory fault. Don't turn that into a panic. // causes a memory fault. Don't turn that into a panic.
flags = _SigThrow flags = _SigThrow
......
...@@ -46,7 +46,7 @@ func isgoexception(info *exceptionrecord, r *context) bool { ...@@ -46,7 +46,7 @@ func isgoexception(info *exceptionrecord, r *context) bool {
return false return false
} }
if r.ip() == funcPC(abort) || (GOARCH == "arm" && r.ip() == funcPC(abort)+4) { if isAbortPC(r.ip()) {
// Never turn abort into a panic. // Never turn abort into a panic.
return false return false
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment