Skip to content

Commit c0841ec

Browse files
committed
cmd/compile: disable instrumentation for no-race packages earlier
Rather than checking for each function whether the package supports instrumentation, check once up front. Relatedly, tweak the logic for preventing inlining calls to runtime functions from instrumented packages. Previously, we simply disallowed inlining runtime functions altogether when instrumenting. With this CL, it's only disallowed from packages that are actually being instrumented. That is, now intra-runtime calls can be inlined. Updates #19054. Change-Id: I88c97b48bf70193a8a3ee18d952dcb26b0369d55 Reviewed-on: https://go-review.googlesource.com/102815 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 6903244 commit c0841ec

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,6 @@ func caninl(fn *Node) {
138138
Fatalf("caninl on non-typechecked function %v", fn)
139139
}
140140

141-
// Runtime package must not be instrumented.
142-
// Instrument skips runtime package. However, some runtime code can be
143-
// inlined into other packages and instrumented there. To avoid this,
144-
// we disable inlining of runtime functions when instrumenting.
145-
// The example that we observed is inlining of LockOSThread,
146-
// which lead to false race reports on m contents.
147-
if instrumenting && myimportpath == "runtime" {
148-
reason = "instrumenting and is runtime function"
149-
return
150-
}
151-
152141
n := fn.Func.Nname
153142
if n.Func.InlinabilityChecked() {
154143
return
@@ -783,6 +772,16 @@ func mkinlcall1(n, fn *Node) *Node {
783772
return n
784773
}
785774

775+
if instrumenting && isRuntimePkg(fn.Sym.Pkg) {
776+
// Runtime package must not be instrumented.
777+
// Instrument skips runtime package. However, some runtime code can be
778+
// inlined into other packages and instrumented there. To avoid this,
779+
// we disable inlining of runtime functions when instrumenting.
780+
// The example that we observed is inlining of LockOSThread,
781+
// which lead to false race reports on m contents.
782+
return n
783+
}
784+
786785
if Debug_typecheckinl == 0 {
787786
typecheckinl(fn)
788787
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,23 @@ func Main(archInit func(*Arch)) {
290290

291291
startProfile()
292292

293+
if flag_race && flag_msan {
294+
log.Fatal("cannot use both -race and -msan")
295+
}
296+
if ispkgin(omit_pkgs) {
297+
flag_race = false
298+
flag_msan = false
299+
}
293300
if flag_race {
294301
racepkg = types.NewPkg("runtime/race", "race")
295302
}
296303
if flag_msan {
297304
msanpkg = types.NewPkg("runtime/msan", "msan")
298305
}
299-
if flag_race && flag_msan {
300-
log.Fatal("cannot use both -race and -msan")
301-
} else if flag_race || flag_msan {
306+
if flag_race || flag_msan {
302307
instrumenting = true
303308
}
309+
304310
if compiling_runtime && Debug['N'] != 0 {
305311
log.Fatal("cannot disable optimizations while compiling runtime")
306312
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func ispkgin(pkgs []string) bool {
5252
}
5353

5454
func instrument(fn *Node) {
55-
if ispkgin(omit_pkgs) || fn.Func.Pragma&Norace != 0 {
55+
if fn.Func.Pragma&Norace != 0 {
5656
return
5757
}
5858

0 commit comments

Comments
 (0)