]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't clobber saved frame pointer during arm64 racecall
authorNick Ripley <nick.ripley@datadoghq.com>
Mon, 5 Feb 2024 19:20:10 +0000 (14:20 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 27 Feb 2024 20:11:27 +0000 (20:11 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/race_arm64.s

index c818345852f6b07bd5d9f4d3465ca30297495d1d..ae0030cf105f5efd19d78ba894d6227e95dd29fb 100644 (file)
@@ -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)