cmd/compile: don't instrument counter globals in internal/fuzz

Fixes: #72766

Change-Id: I45b521e53c2a11e259dc99e2dfc8e40cac39139a
Reviewed-on: https://go-review.googlesource.com/c/go/+/673575
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Mateusz Poliwczak 2025-05-16 21:07:46 +02:00 committed by Gopher Robot
parent 123141166b
commit 3e82316a43
3 changed files with 10 additions and 1 deletions

View file

@ -135,6 +135,9 @@ func TestASANFuzz(t *testing.T) {
if bytes.Contains(out, []byte("AddressSanitizer")) { if bytes.Contains(out, []byte("AddressSanitizer")) {
t.Error(`output contains "AddressSanitizer", but should not`) t.Error(`output contains "AddressSanitizer", but should not`)
} }
if !bytes.Contains(out, []byte("FUZZ FAILED")) {
t.Error(`fuzz test did not fail with a "FUZZ FAILED" sentinel error`)
}
} }
func mustHaveASAN(t *testing.T) *config { func mustHaveASAN(t *testing.T) *config {

View file

@ -24,7 +24,7 @@ func FuzzReverse(f *testing.F) {
r1 := Reverse(s) r1 := Reverse(s)
r2 := Reverse(r1) r2 := Reverse(r1)
if s != r2 { if s != r2 {
t.Errorf("got %q want %q", r2, s) t.Errorf("FUZZ FAILED: got %q want %q", r2, s)
} }
}) })
} }

View file

@ -227,6 +227,12 @@ func canInstrumentGlobal(g ir.Node) bool {
return false return false
} }
// Do not instrument counter globals in internal/fuzz. These globals are replaced by the linker.
// See go.dev/issue/72766 for more details.
if n.Sym().Pkg.Path == "internal/fuzz" && (n.Sym().Name == "_counters" || n.Sym().Name == "_ecounters") {
return false
}
// Do not instrument globals that are linknamed, because their home package will do the work. // Do not instrument globals that are linknamed, because their home package will do the work.
if n.Sym().Linkname != "" { if n.Sym().Linkname != "" {
return false return false