From: Nick Ripley Date: Mon, 5 Feb 2024 19:20:10 +0000 (-0500) Subject: runtime: don't clobber saved frame pointer during arm64 racecall X-Git-Tag: go1.23rc1~1095 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=234390e741dd43b1ce54b0cfd91dc591c0b190f7;p=gostls13.git runtime: don't clobber saved frame pointer during arm64 racecall During calls to the race detector on arm64, we switch to the g0 stack if we aren't already on it. If we are already on the g0 stack, the race detector library code can then create a stack frame using the stack pointer coming from Go code. The race detector library can go on to write values to the top of its stack frame. But the Go ABI for arm64 saves the caller's frame pointer in the word below the current stack frame. So, the saved frame pointer on the stack can be clobbered by the race detector. Decrement the stack pointer to account for where the frame pointer is saved, like we do for asmcgocall. Change-Id: I66e5e4a671c3befc10776bac6869810ecf71790d Reviewed-on: https://go-review.googlesource.com/c/go/+/561515 LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Auto-Submit: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Michael Knyszek --- diff --git a/src/runtime/race_arm64.s b/src/runtime/race_arm64.s index c818345852..ae0030cf10 100644 --- a/src/runtime/race_arm64.s +++ b/src/runtime/race_arm64.s @@ -419,6 +419,10 @@ TEXT racecall<>(SB), NOSPLIT|NOFRAME, $0-0 MOVD (g_sched+gobuf_sp)(R11), R12 MOVD R12, RSP call: + // Decrement SP past where the frame pointer is saved in the Go arm64 + // ABI (one word below the stack pointer) so the race detector library + // code doesn't clobber it + SUB $16, RSP BL R9 MOVD R19, RSP JMP (R20)