]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/objabi,cmd/compile: move NoInstrumentPkgs and NoRacePkgs to PkgSpecials
authorAustin Clements <austin@google.com>
Fri, 7 Jul 2023 21:01:47 +0000 (17:01 -0400)
committerAustin Clements <austin@google.com>
Tue, 22 Aug 2023 19:18:34 +0000 (19:18 +0000)
This consolidates the NoInstrumentPkgs and NoRacePkgs lists into the
objabi.LookupPkgSpecial mechanism.

Change-Id: I411654afdd690fb01c412e7e8b57ddfbe85415e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/521702
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Austin Clements <austin@google.com>

src/cmd/compile/internal/base/base.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/types/type.go
src/cmd/compile/internal/walk/race.go
src/cmd/internal/objabi/pkgspecial.go

index 841241efb10617bb8a58d779961b11384e8c31c8..ee3772c5ca2bfa44feae2978405fd61b4ae4ebd9 100644 (file)
@@ -219,44 +219,3 @@ func AdjustStartingHeap(requestedHeapGoal uint64) {
 
        forEachGC(adjustFunc)
 }
-
-func Compiling(pkgs []string) bool {
-       if Ctxt.Pkgpath != "" {
-               for _, p := range pkgs {
-                       if Ctxt.Pkgpath == p {
-                               return true
-                       }
-               }
-       }
-
-       return false
-}
-
-// Do not instrument the following packages at all,
-// at best instrumentation would cause infinite recursion.
-var NoInstrumentPkgs = []string{
-       "runtime/internal/atomic",
-       "runtime/internal/math",
-       "runtime/internal/sys",
-       "runtime/internal/syscall",
-       "runtime",
-       "runtime/race",
-       "runtime/msan",
-       "runtime/asan",
-       "internal/cpu",
-       "internal/abi",
-       // We omit bytealg even though it's imported by runtime because it also
-       // backs a lot of package bytes. Currently we don't have a way to omit race
-       // instrumentation when used from the runtime while keeping race
-       // instrumentation when used from user code. Somehow this doesn't seem to
-       // cause problems, though we may be skating on thin ice. See #61204.
-       //"internal/bytealg",
-       "internal/coverage/rtcov",
-       "internal/godebugs",
-       "internal/goexperiment",
-       "internal/goos",
-}
-
-// Don't insert racefuncenter/racefuncexit into the following packages.
-// Memory accesses in the packages are either uninteresting or will cause false positives.
-var NoRacePkgs = []string{"sync", "sync/atomic"}
index f38438b7b312aa227aee0dde8378607e94629387..05f0340d39b334f9e364520ded7dbd37aeccd6ed 100644 (file)
@@ -151,7 +151,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
                symABIs.ReadSymABIs(base.Flag.SymABIs)
        }
 
-       if base.Compiling(base.NoInstrumentPkgs) {
+       if objabi.LookupPkgSpecial(base.Ctxt.Pkgpath).NoInstrument {
                base.Flag.Race = false
                base.Flag.MSan = false
                base.Flag.ASan = false
index bd63f651a53bf171c2f14d8a173828d981ec6d3a..696e8a5bc1321e1593e22aa27baeaa4461e8a20b 100644 (file)
@@ -6,6 +6,7 @@ package types
 
 import (
        "cmd/compile/internal/base"
+       "cmd/internal/objabi"
        "cmd/internal/src"
        "fmt"
        "internal/types/errors"
@@ -1862,23 +1863,13 @@ func ReflectSymName(s *Sym) string {
 // IsNoInstrumentPkg reports whether p is a package that
 // should not be instrumented.
 func IsNoInstrumentPkg(p *Pkg) bool {
-       for _, np := range base.NoInstrumentPkgs {
-               if p.Path == np {
-                       return true
-               }
-       }
-       return false
+       return objabi.LookupPkgSpecial(p.Path).NoInstrument
 }
 
 // IsNoRacePkg reports whether p is a package that
 // should not be race instrumented.
 func IsNoRacePkg(p *Pkg) bool {
-       for _, np := range base.NoRacePkgs {
-               if p.Path == np {
-                       return true
-               }
-       }
-       return false
+       return objabi.LookupPkgSpecial(p.Path).NoRaceFunc
 }
 
 // ReceiverBaseType returns the underlying type, if any,
index 6384e162702afdde5dc1066ca57fe0406276048f..972c878b30b7eb4a9a5e8d7ae699b9ba7aac554d 100644 (file)
@@ -8,6 +8,7 @@ import (
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
        "cmd/compile/internal/types"
+       "cmd/internal/objabi"
        "cmd/internal/src"
 )
 
@@ -36,7 +37,7 @@ func instrument(fn *ir.Func) {
                return
        }
 
-       if !base.Flag.Race || !base.Compiling(base.NoRacePkgs) {
+       if !base.Flag.Race || !objabi.LookupPkgSpecial(base.Ctxt.Pkgpath).NoRaceFunc {
                fn.SetInstrumentBody(true)
        }
 
index 144110b75510ef0f7ff7afe8042824d6cad2a809..9bf07153a4642e0b6d23ddb9b244921b68864f9c 100644 (file)
@@ -22,6 +22,17 @@ type PkgSpecial struct {
        // set for additional packages.
        Runtime bool
 
+       // NoInstrument indicates this package should not receive sanitizer
+       // instrumentation. In many of these, instrumentation could cause infinite
+       // recursion. This is all runtime packages, plus those that support the
+       // sanitizers.
+       NoInstrument bool
+
+       // NoRaceFunc indicates functions in this package should not get
+       // racefuncenter/racefuncexit instrumentation Memory accesses in these
+       // packages are either uninteresting or will cause false positives.
+       NoRaceFunc bool
+
        // AllowAsmABI indicates that assembly in this package is allowed to use ABI
        // selectors in symbol names. Generally this is needed for packages that
        // interact closely with the runtime package or have performance-critical
@@ -47,6 +58,22 @@ var runtimePkgs = []string{
        "internal/goos",
 }
 
+// extraNoInstrumentPkgs is the set of packages in addition to runtimePkgs that
+// should have NoInstrument set.
+var extraNoInstrumentPkgs = []string{
+       "runtime/race",
+       "runtime/msan",
+       "runtime/asan",
+       // We omit bytealg even though it's imported by runtime because it also
+       // backs a lot of package bytes. Currently we don't have a way to omit race
+       // instrumentation when used from the runtime while keeping race
+       // instrumentation when used from user code. Somehow this doesn't seem to
+       // cause problems, though we may be skating on thin ice. See #61204.
+       "-internal/bytealg",
+}
+
+var noRaceFuncPkgs = []string{"sync", "sync/atomic"}
+
 var allowAsmABIPkgs = []string{
        "runtime",
        "reflect",
@@ -74,7 +101,17 @@ func LookupPkgSpecial(pkgPath string) PkgSpecial {
                        pkgSpecials[elt] = s
                }
                for _, pkg := range runtimePkgs {
-                       set(pkg, func(ps *PkgSpecial) { ps.Runtime = true })
+                       set(pkg, func(ps *PkgSpecial) { ps.Runtime = true; ps.NoInstrument = true })
+               }
+               for _, pkg := range extraNoInstrumentPkgs {
+                       if pkg[0] == '-' {
+                               set(pkg[1:], func(ps *PkgSpecial) { ps.NoInstrument = false })
+                       } else {
+                               set(pkg, func(ps *PkgSpecial) { ps.NoInstrument = true })
+                       }
+               }
+               for _, pkg := range noRaceFuncPkgs {
+                       set(pkg, func(ps *PkgSpecial) { ps.NoRaceFunc = true })
                }
                for _, pkg := range allowAsmABIPkgs {
                        set(pkg, func(ps *PkgSpecial) { ps.AllowAsmABI = true })