Skip to content

Commit 0def0f2

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent e4de522 commit 0def0f2

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

src/runtime/asm_arm64.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@ TEXT runtime·getcallerpc(SB),NOSPLIT|NOFRAME,$0-8
710710
RET
711711

712712
TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
713-
B (ZR)
713+
MOVD ZR, R0
714+
MOVD (R0), R0
714715
UNDEF
715716

716717
TEXT runtime·return0(SB), NOSPLIT, $0

src/runtime/os3_plan9.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
3535
print("sighandler: note is longer than ERRMAX\n")
3636
goto Throw
3737
}
38-
if c.pc() == funcPC(abort) || (GOARCH == "arm" && c.pc() == funcPC(abort)+4) {
38+
if isAbortPC(c.pc()) {
3939
// Never turn abort into a panic.
4040
goto Throw
4141
}

src/runtime/panic.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,9 @@ func shouldPushSigpanic(gp *g, pc, lr uintptr) bool {
837837
// will work.
838838
return true
839839
}
840+
841+
// isAbortPC returns true if pc is the program counter at which
842+
// runtime.abort raises a signal.
843+
func isAbortPC(pc uintptr) bool {
844+
return pc == funcPC(abort) || ((GOARCH == "arm" || GOARCH == "arm64") && pc == funcPC(abort)+sys.PCQuantum)
845+
}

src/runtime/signal_sighandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
4343
// stack. Abort in the signal handler instead.
4444
flags = (flags &^ _SigPanic) | _SigThrow
4545
}
46-
if c.sigpc() == funcPC(abort) || (GOARCH == "arm" && c.sigpc() == funcPC(abort)+4) {
46+
if isAbortPC(c.sigpc()) {
4747
// On many architectures, the abort function just
4848
// causes a memory fault. Don't turn that into a panic.
4949
flags = _SigThrow

src/runtime/signal_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func isgoexception(info *exceptionrecord, r *context) bool {
4646
return false
4747
}
4848

49-
if r.ip() == funcPC(abort) || (GOARCH == "arm" && r.ip() == funcPC(abort)+4) {
49+
if isAbortPC(r.ip()) {
5050
// Never turn abort into a panic.
5151
return false
5252
}

0 commit comments

Comments
 (0)