diff options
author | Katie Hockman <katie@golang.org> | 2021-09-27 16:12:05 -0400 |
---|---|---|
committer | Katie Hockman <katie@golang.org> | 2021-09-29 17:15:06 +0000 |
commit | c9af2bd21e86a218622b9c753cddfb5bba46d780 (patch) | |
tree | f213e3dda1b45c85a80cc9ae9ff8686dc5e7983f /src/cmd/go/internal/test | |
parent | 99d5d8ab6b6819f84bb62aeb3b1eaefaab01989f (diff) | |
download | go-git-c9af2bd21e86a218622b9c753cddfb5bba46d780.tar.gz |
cmd/go: prevent necessary GCFlag from being removed
There are special flags that must be passed to the
compiler at build time in order to instrument the
testing binary for fuzzing.
One potential option would be to add these flags to
p.Internal.Gcflags inside cmd/go/internal/test. However,
future calls to setToolFlags can cause these flags to
get cleared about before the build starts, removing
virtually all coverage guidance. This change moves the
logic to add the flag deeper down the call stack,
preventing it from being cleared.
Change-Id: I40eadb0cacc18f29cee75379cd9380f9e73bb8da
Reviewed-on: https://go-review.googlesource.com/c/go/+/352511
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/test')
-rw-r--r-- | src/cmd/go/internal/test/test.go | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 7c6f109cc5..a6c8631a37 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -818,12 +818,11 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) { // Inform the compiler that it should instrument the binary at // build-time when fuzzing is enabled. - fuzzFlags := work.FuzzInstrumentFlags() - if testFuzz != "" && fuzzFlags != nil { + if testFuzz != "" { // Don't instrument packages which may affect coverage guidance but are // unlikely to be useful. Most of these are used by the testing or // internal/fuzz packages concurrently with fuzzing. - var fuzzNoInstrument = map[string]bool{ + var skipInstrumentation = map[string]bool{ "context": true, "internal/fuzz": true, "reflect": true, @@ -835,10 +834,9 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) { "time": true, } for _, p := range load.TestPackageList(ctx, pkgOpts, pkgs) { - if fuzzNoInstrument[p.ImportPath] { - continue + if !skipInstrumentation[p.ImportPath] { + p.Internal.FuzzInstrument = true } - p.Internal.Gcflags = append(p.Internal.Gcflags, fuzzFlags...) } } |