1
0
mirror of https://github.com/golang/go synced 2024-11-17 05:54:46 -07:00

internal/fuzz,cmd/compile: don't add race instrumentation to counters

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>
This commit is contained in:
Roland Shoemaker 2021-09-16 11:33:17 -07:00
parent ccfc41eee0
commit 7a03ca65b3
3 changed files with 14 additions and 4 deletions

View 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
}

View 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))

View 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)