Skip to content

Commit 56b3b24

Browse files
committed
cmd/internal/objabi,cmd/compile: move NoInstrumentPkgs and NoRacePkgs to PkgSpecials
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 <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Austin Clements <[email protected]>
1 parent 83e0704 commit 56b3b24

File tree

5 files changed

+44
-56
lines changed

5 files changed

+44
-56
lines changed

src/cmd/compile/internal/base/base.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -219,44 +219,3 @@ func AdjustStartingHeap(requestedHeapGoal uint64) {
219219

220220
forEachGC(adjustFunc)
221221
}
222-
223-
func Compiling(pkgs []string) bool {
224-
if Ctxt.Pkgpath != "" {
225-
for _, p := range pkgs {
226-
if Ctxt.Pkgpath == p {
227-
return true
228-
}
229-
}
230-
}
231-
232-
return false
233-
}
234-
235-
// Do not instrument the following packages at all,
236-
// at best instrumentation would cause infinite recursion.
237-
var NoInstrumentPkgs = []string{
238-
"runtime/internal/atomic",
239-
"runtime/internal/math",
240-
"runtime/internal/sys",
241-
"runtime/internal/syscall",
242-
"runtime",
243-
"runtime/race",
244-
"runtime/msan",
245-
"runtime/asan",
246-
"internal/cpu",
247-
"internal/abi",
248-
// We omit bytealg even though it's imported by runtime because it also
249-
// backs a lot of package bytes. Currently we don't have a way to omit race
250-
// instrumentation when used from the runtime while keeping race
251-
// instrumentation when used from user code. Somehow this doesn't seem to
252-
// cause problems, though we may be skating on thin ice. See #61204.
253-
//"internal/bytealg",
254-
"internal/coverage/rtcov",
255-
"internal/godebugs",
256-
"internal/goexperiment",
257-
"internal/goos",
258-
}
259-
260-
// Don't insert racefuncenter/racefuncexit into the following packages.
261-
// Memory accesses in the packages are either uninteresting or will cause false positives.
262-
var NoRacePkgs = []string{"sync", "sync/atomic"}

src/cmd/compile/internal/gc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func Main(archInit func(*ssagen.ArchInfo)) {
151151
symABIs.ReadSymABIs(base.Flag.SymABIs)
152152
}
153153

154-
if base.Compiling(base.NoInstrumentPkgs) {
154+
if objabi.LookupPkgSpecial(base.Ctxt.Pkgpath).NoInstrument {
155155
base.Flag.Race = false
156156
base.Flag.MSan = false
157157
base.Flag.ASan = false

src/cmd/compile/internal/types/type.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package types
66

77
import (
88
"cmd/compile/internal/base"
9+
"cmd/internal/objabi"
910
"cmd/internal/src"
1011
"fmt"
1112
"internal/types/errors"
@@ -1862,23 +1863,13 @@ func ReflectSymName(s *Sym) string {
18621863
// IsNoInstrumentPkg reports whether p is a package that
18631864
// should not be instrumented.
18641865
func IsNoInstrumentPkg(p *Pkg) bool {
1865-
for _, np := range base.NoInstrumentPkgs {
1866-
if p.Path == np {
1867-
return true
1868-
}
1869-
}
1870-
return false
1866+
return objabi.LookupPkgSpecial(p.Path).NoInstrument
18711867
}
18721868

18731869
// IsNoRacePkg reports whether p is a package that
18741870
// should not be race instrumented.
18751871
func IsNoRacePkg(p *Pkg) bool {
1876-
for _, np := range base.NoRacePkgs {
1877-
if p.Path == np {
1878-
return true
1879-
}
1880-
}
1881-
return false
1872+
return objabi.LookupPkgSpecial(p.Path).NoRaceFunc
18821873
}
18831874

18841875
// ReceiverBaseType returns the underlying type, if any,

src/cmd/compile/internal/walk/race.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"cmd/compile/internal/base"
99
"cmd/compile/internal/ir"
1010
"cmd/compile/internal/types"
11+
"cmd/internal/objabi"
1112
"cmd/internal/src"
1213
)
1314

@@ -36,7 +37,7 @@ func instrument(fn *ir.Func) {
3637
return
3738
}
3839

39-
if !base.Flag.Race || !base.Compiling(base.NoRacePkgs) {
40+
if !base.Flag.Race || !objabi.LookupPkgSpecial(base.Ctxt.Pkgpath).NoRaceFunc {
4041
fn.SetInstrumentBody(true)
4142
}
4243

src/cmd/internal/objabi/pkgspecial.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ type PkgSpecial struct {
2222
// set for additional packages.
2323
Runtime bool
2424

25+
// NoInstrument indicates this package should not receive sanitizer
26+
// instrumentation. In many of these, instrumentation could cause infinite
27+
// recursion. This is all runtime packages, plus those that support the
28+
// sanitizers.
29+
NoInstrument bool
30+
31+
// NoRaceFunc indicates functions in this package should not get
32+
// racefuncenter/racefuncexit instrumentation Memory accesses in these
33+
// packages are either uninteresting or will cause false positives.
34+
NoRaceFunc bool
35+
2536
// AllowAsmABI indicates that assembly in this package is allowed to use ABI
2637
// selectors in symbol names. Generally this is needed for packages that
2738
// interact closely with the runtime package or have performance-critical
@@ -47,6 +58,22 @@ var runtimePkgs = []string{
4758
"internal/goos",
4859
}
4960

61+
// extraNoInstrumentPkgs is the set of packages in addition to runtimePkgs that
62+
// should have NoInstrument set.
63+
var extraNoInstrumentPkgs = []string{
64+
"runtime/race",
65+
"runtime/msan",
66+
"runtime/asan",
67+
// We omit bytealg even though it's imported by runtime because it also
68+
// backs a lot of package bytes. Currently we don't have a way to omit race
69+
// instrumentation when used from the runtime while keeping race
70+
// instrumentation when used from user code. Somehow this doesn't seem to
71+
// cause problems, though we may be skating on thin ice. See #61204.
72+
"-internal/bytealg",
73+
}
74+
75+
var noRaceFuncPkgs = []string{"sync", "sync/atomic"}
76+
5077
var allowAsmABIPkgs = []string{
5178
"runtime",
5279
"reflect",
@@ -74,7 +101,17 @@ func LookupPkgSpecial(pkgPath string) PkgSpecial {
74101
pkgSpecials[elt] = s
75102
}
76103
for _, pkg := range runtimePkgs {
77-
set(pkg, func(ps *PkgSpecial) { ps.Runtime = true })
104+
set(pkg, func(ps *PkgSpecial) { ps.Runtime = true; ps.NoInstrument = true })
105+
}
106+
for _, pkg := range extraNoInstrumentPkgs {
107+
if pkg[0] == '-' {
108+
set(pkg[1:], func(ps *PkgSpecial) { ps.NoInstrument = false })
109+
} else {
110+
set(pkg, func(ps *PkgSpecial) { ps.NoInstrument = true })
111+
}
112+
}
113+
for _, pkg := range noRaceFuncPkgs {
114+
set(pkg, func(ps *PkgSpecial) { ps.NoRaceFunc = true })
78115
}
79116
for _, pkg := range allowAsmABIPkgs {
80117
set(pkg, func(ps *PkgSpecial) { ps.AllowAsmABI = true })

0 commit comments

Comments
 (0)