]> Cypherpunks.ru repositories - gostls13.git/commitdiff
internal/fuzz,cmd/compile: don't add race instrumentation to counters
authorRoland Shoemaker <roland@golang.org>
Thu, 16 Sep 2021 18:33:17 +0000 (11:33 -0700)
committerRoland Shoemaker <roland@golang.org>
Wed, 22 Sep 2021 18:44:36 +0000 (18:44 +0000)
Don't add race detector instrumentation to the fuzzing counters,
allowing usage of -race without immediately triggering the
detector. Also fixes a minor race in contextReader.Read.

Fixes #48307

Change-Id: Idb2cfeaa4283f8a74473b4bac6cd68eed577e943
Reviewed-on: https://go-review.googlesource.com/c/go/+/351453
Trust: Roland Shoemaker <roland@golang.org>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/cmd/compile/internal/ssa/writebarrier.go
src/cmd/compile/internal/walk/order.go
src/internal/fuzz/worker.go

index 52f060b601785426794719ea614db436e10412a9..5120cd1086ac6088b54636180a6f44364d4dc550 100644 (file)
@@ -650,7 +650,7 @@ func IsSanitizerSafeAddr(v *Value) bool {
                // read-only once initialized.
                return true
        case OpAddr:
-               return v.Aux.(*obj.LSym).Type == objabi.SRODATA
+               return v.Aux.(*obj.LSym).Type == objabi.SRODATA || v.Aux.(*obj.LSym).Type == objabi.SLIBFUZZER_EXTRA_COUNTER
        }
        return false
 }
index 7ac1f75c8f21148edad1f060d7f49a14cd888344..861c122456d7648f2fc319beecb77f23004e2ae1 100644 (file)
@@ -14,6 +14,7 @@ import (
        "cmd/compile/internal/staticinit"
        "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
+       "cmd/internal/objabi"
        "cmd/internal/src"
 )
 
@@ -443,6 +444,13 @@ func (o *orderState) edge() {
        // __libfuzzer_extra_counters.
        counter := staticinit.StaticName(types.Types[types.TUINT8])
        counter.SetLibfuzzerExtraCounter(true)
+       // As well as setting SetLibfuzzerExtraCounter, we preemptively set the
+       // symbol type to SLIBFUZZER_EXTRA_COUNTER so that the race detector
+       // instrumentation pass (which does not have access to the flags set by
+       // SetLibfuzzerExtraCounter) knows to ignore them. This information is
+       // lost by the time it reaches the compile step, so SetLibfuzzerExtraCounter
+       // is still necessary.
+       counter.Linksym().Type = objabi.SLIBFUZZER_EXTRA_COUNTER
 
        // counter += 1
        incr := ir.NewAssignOpStmt(base.Pos, ir.OADD, counter, ir.NewInt(1))
index 36a7c629e5497ac0dabd12d19cd4569b78e6eac1..5b24e575c039d96fffa1d2bd700b8ff95cd76d0a 100644 (file)
@@ -1142,14 +1142,16 @@ type contextReader struct {
        r   io.Reader
 }
 
-func (cr *contextReader) Read(b []byte) (n int, err error) {
-       if err := cr.ctx.Err(); err != nil {
-               return 0, err
+func (cr *contextReader) Read(b []byte) (int, error) {
+       if ctxErr := cr.ctx.Err(); ctxErr != nil {
+               return 0, ctxErr
        }
        done := make(chan struct{})
 
        // This goroutine may stay blocked after Read returns because the underlying
        // read is blocked.
+       var n int
+       var err error
        go func() {
                n, err = cr.r.Read(b)
                close(done)