aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-04-23 14:15:51 -0700
committerGopher Robot <gobot@golang.org>2025-04-23 23:22:12 -0700
commitc1fc209c41c18806b7cef1cf114f1ca9b3731eb9 (patch)
tree114e29f716a776314195b3c4769ada19b024b5a1 /src/runtime
parent9d0320de2574586f3b0610c1b5fd15b8f9c85dec (diff)
downloadgo-c1fc209c41c18806b7cef1cf114f1ca9b3731eb9.tar.xz
runtime: use precise bounds of Go data/bss for race detector
We only want to call into the race detector for Go global variables. By rounding up the region bounds, we can include some C globals. Even worse, we can include only *part* of a C global, leading to race{read,write}range calls which straddle the end of shadow memory. That causes the race detector to barf. Fix some off-by-one errors in the assembly comparisons. We want to skip calling the race detector when addr == racedataend. Fixes #73483 Change-Id: I436b0f588d6165b61f30cb7653016ba9b7cbf585 Reviewed-on: https://go-review.googlesource.com/c/go/+/667655 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/race.go10
-rw-r--r--src/runtime/race_arm64.s2
-rw-r--r--src/runtime/race_ppc64le.s2
3 files changed, 8 insertions, 6 deletions
diff --git a/src/runtime/race.go b/src/runtime/race.go
index 6b7bbe5245..fa781a3ccc 100644
--- a/src/runtime/race.go
+++ b/src/runtime/race.go
@@ -455,7 +455,6 @@ func raceinit() (gctx, pctx uintptr) {
racecall(&__tsan_init, uintptr(unsafe.Pointer(&gctx)), uintptr(unsafe.Pointer(&pctx)), abi.FuncPCABI0(racecallbackthunk), 0)
- // Round data segment to page boundaries, because it's used in mmap().
start := ^uintptr(0)
end := uintptr(0)
if start > firstmoduledata.noptrdata {
@@ -482,10 +481,13 @@ func raceinit() (gctx, pctx uintptr) {
if end < firstmoduledata.ebss {
end = firstmoduledata.ebss
}
- size := alignUp(end-start, _PageSize)
- racecall(&__tsan_map_shadow, start, size, 0, 0)
+ // Use exact bounds for boundary check in racecalladdr. See issue 73483.
racedatastart = start
- racedataend = start + size
+ racedataend = end
+ // Round data segment to page boundaries for race detector (TODO: still needed?)
+ start = alignDown(start, _PageSize)
+ end = alignUp(end, _PageSize)
+ racecall(&__tsan_map_shadow, start, end-start, 0, 0)
return
}
diff --git a/src/runtime/race_arm64.s b/src/runtime/race_arm64.s
index c42a6c1377..83dfdef2e5 100644
--- a/src/runtime/race_arm64.s
+++ b/src/runtime/race_arm64.s
@@ -163,7 +163,7 @@ data:
BLT ret
MOVD runtime·racedataend(SB), R10
CMP R10, R1
- BGT ret
+ BGE ret
call:
JMP racecall<>(SB)
ret:
diff --git a/src/runtime/race_ppc64le.s b/src/runtime/race_ppc64le.s
index 43829479bd..d3cac03ff4 100644
--- a/src/runtime/race_ppc64le.s
+++ b/src/runtime/race_ppc64le.s
@@ -153,7 +153,7 @@ data:
BLT ret
MOVD runtime·racedataend(SB), R9
CMP R4, R9
- BGT ret
+ BGE ret
call:
// Careful!! racecall will save LR on its
// stack, which is OK as long as racecalladdr