]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't instrument counter globals in internal/fuzz
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Fri, 16 May 2025 19:07:46 +0000 (21:07 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 20 May 2025 17:47:59 +0000 (10:47 -0700)
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>
src/cmd/cgo/internal/testsanitizers/asan_test.go
src/cmd/cgo/internal/testsanitizers/testdata/asan_fuzz_test.go
src/cmd/compile/internal/pkginit/initAsanGlobals.go

index f7f53da334e72fc812e97d8ad077a609d76401e2..c2cdf7b6d645e881ec627df55ebcb10496bb5681 100644 (file)
@@ -135,6 +135,9 @@ func TestASANFuzz(t *testing.T) {
        if bytes.Contains(out, []byte("AddressSanitizer")) {
                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 {
index fb7ebd40780df8fa84bff249734d61719e2cd2e4..1a51819d7d70adfd192e9534cb703970f0c83adb 100644 (file)
@@ -24,7 +24,7 @@ func FuzzReverse(f *testing.F) {
                r1 := Reverse(s)
                r2 := Reverse(r1)
                if s != r2 {
-                       t.Errorf("got %q want %q", r2, s)
+                       t.Errorf("FUZZ FAILED: got %q want %q", r2, s)
                }
        })
 }
index 42db0eaf1bbd2abdab11aec6849e749823fbd62c..96c052204a2c116475c1d664b0495f1924edc8ff 100644 (file)
@@ -227,6 +227,12 @@ func canInstrumentGlobal(g ir.Node) bool {
                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.
        if n.Sym().Linkname != "" {
                return false