]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link, runtime: use a different section for Go libfuzzer counters
authorCherry Mui <cherryyz@google.com>
Wed, 21 Dec 2022 21:35:57 +0000 (16:35 -0500)
committerCherry Mui <cherryyz@google.com>
Fri, 23 Dec 2022 01:12:02 +0000 (01:12 +0000)
Currently in libfuzzer mode, we put our counters in section
__sancov_cntrs. When linking with C/C++ code that also has fuzzer
counters, apparently the C linker combines our counters and their
counters and registers them together. But in the Go runtime we
also have code to register our counters. So the Go counters ended
up registered twice, causing problems.

Since we already have code to register our counters, put them in
a Go-specific section so it won't be combined with the C counters.

Fixes #57449.

Change-Id: If3d41735124e7e301572d4b7aecf7d057ac134c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/459055
Reviewed-by: Nicolas Hillegeer <aktau@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>

src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/runtime/libfuzzer.go

index faae153babc899a3c1b767b92531ef316c16fb37..94f8fc32d6e2d61bedc2ffd1571efc9dbe4e7ff9 100644 (file)
@@ -1860,9 +1860,9 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
 
        // Coverage instrumentation counters for libfuzzer.
        if len(state.data[sym.SLIBFUZZER_8BIT_COUNTER]) > 0 {
-               sect := state.allocateNamedSectionAndAssignSyms(&Segdata, "__sancov_cntrs", sym.SLIBFUZZER_8BIT_COUNTER, sym.Sxxx, 06)
-               ldr.SetSymSect(ldr.LookupOrCreateSym("__start___sancov_cntrs", 0), sect)
-               ldr.SetSymSect(ldr.LookupOrCreateSym("__stop___sancov_cntrs", 0), sect)
+               sect := state.allocateNamedSectionAndAssignSyms(&Segdata, ".go.fuzzcntrs", sym.SLIBFUZZER_8BIT_COUNTER, sym.Sxxx, 06)
+               ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.__start___sancov_cntrs", 0), sect)
+               ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.__stop___sancov_cntrs", 0), sect)
                ldr.SetSymSect(ldr.LookupOrCreateSym("internal/fuzz._counters", 0), sect)
                ldr.SetSymSect(ldr.LookupOrCreateSym("internal/fuzz._ecounters", 0), sect)
        }
@@ -2643,7 +2643,7 @@ func (ctxt *Link) address() []*sym.Segment {
                        bss = s
                case ".noptrbss":
                        noptrbss = s
-               case "__sancov_cntrs":
+               case ".go.fuzzcntrs":
                        fuzzCounters = s
                }
        }
@@ -2764,8 +2764,8 @@ func (ctxt *Link) address() []*sym.Segment {
        ctxt.xdefine("runtime.end", sym.SBSS, int64(Segdata.Vaddr+Segdata.Length))
 
        if fuzzCounters != nil {
-               ctxt.xdefine("__start___sancov_cntrs", sym.SLIBFUZZER_8BIT_COUNTER, int64(fuzzCounters.Vaddr))
-               ctxt.xdefine("__stop___sancov_cntrs", sym.SLIBFUZZER_8BIT_COUNTER, int64(fuzzCounters.Vaddr+fuzzCounters.Length))
+               ctxt.xdefine("runtime.__start___sancov_cntrs", sym.SLIBFUZZER_8BIT_COUNTER, int64(fuzzCounters.Vaddr))
+               ctxt.xdefine("runtime.__stop___sancov_cntrs", sym.SLIBFUZZER_8BIT_COUNTER, int64(fuzzCounters.Vaddr+fuzzCounters.Length))
                ctxt.xdefine("internal/fuzz._counters", sym.SLIBFUZZER_8BIT_COUNTER, int64(fuzzCounters.Vaddr))
                ctxt.xdefine("internal/fuzz._ecounters", sym.SLIBFUZZER_8BIT_COUNTER, int64(fuzzCounters.Vaddr+fuzzCounters.Length))
        }
index 082adcc3c7f7a8ec2e7ae74ad01ffb0462432c9f..a1ae7eab57fe96f670a9759145a94f51b8e092ea 100644 (file)
@@ -1371,7 +1371,7 @@ func (ctxt *Link) doelf() {
        shstrtab.Addstring(".data")
        shstrtab.Addstring(".bss")
        shstrtab.Addstring(".noptrbss")
-       shstrtab.Addstring("__sancov_cntrs")
+       shstrtab.Addstring(".go.fuzzcntrs")
        shstrtab.Addstring(".go.buildinfo")
        if ctxt.IsMIPS() {
                shstrtab.Addstring(".MIPS.abiflags")
index 013e7165b21fff6b01807dfc5503157fe0953b18..0ece035405f7aa7e6de881c6262e6f7013d60d83 100644 (file)
@@ -148,13 +148,8 @@ var __sanitizer_cov_trace_const_cmp8 byte
 //go:cgo_import_static __sanitizer_cov_8bit_counters_init
 var __sanitizer_cov_8bit_counters_init byte
 
-//go:linkname __start___sancov_cntrs __start___sancov_cntrs
-//go:cgo_import_static __start___sancov_cntrs
-var __start___sancov_cntrs byte
-
-//go:linkname __stop___sancov_cntrs __stop___sancov_cntrs
-//go:cgo_import_static __stop___sancov_cntrs
-var __stop___sancov_cntrs byte
+// start, stop markers of counters, set by the linker
+var __start___sancov_cntrs, __stop___sancov_cntrs byte
 
 //go:linkname __sanitizer_cov_pcs_init __sanitizer_cov_pcs_init
 //go:cgo_import_static __sanitizer_cov_pcs_init