Skip to content

Commit 3e82316

Browse files
mateusz834gopherbot
authored andcommitted
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>
1 parent 1231411 commit 3e82316

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/cmd/cgo/internal/testsanitizers/asan_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func TestASANFuzz(t *testing.T) {
135135
if bytes.Contains(out, []byte("AddressSanitizer")) {
136136
t.Error(`output contains "AddressSanitizer", but should not`)
137137
}
138+
if !bytes.Contains(out, []byte("FUZZ FAILED")) {
139+
t.Error(`fuzz test did not fail with a "FUZZ FAILED" sentinel error`)
140+
}
138141
}
139142

140143
func mustHaveASAN(t *testing.T) *config {

src/cmd/cgo/internal/testsanitizers/testdata/asan_fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func FuzzReverse(f *testing.F) {
2424
r1 := Reverse(s)
2525
r2 := Reverse(r1)
2626
if s != r2 {
27-
t.Errorf("got %q want %q", r2, s)
27+
t.Errorf("FUZZ FAILED: got %q want %q", r2, s)
2828
}
2929
})
3030
}

src/cmd/compile/internal/pkginit/initAsanGlobals.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ func canInstrumentGlobal(g ir.Node) bool {
227227
return false
228228
}
229229

230+
// Do not instrument counter globals in internal/fuzz. These globals are replaced by the linker.
231+
// See go.dev/issue/72766 for more details.
232+
if n.Sym().Pkg.Path == "internal/fuzz" && (n.Sym().Name == "_counters" || n.Sym().Name == "_ecounters") {
233+
return false
234+
}
235+
230236
// Do not instrument globals that are linknamed, because their home package will do the work.
231237
if n.Sym().Linkname != "" {
232238
return false

0 commit comments

Comments
 (0)