Skip to content

Commit f0de94f

Browse files
committed
cmd/compile: don't inline runtime functions in -d=checkptr build
Runtime functions, e.g. internal/abi.NoEscape, should not be instrumented with checkptr. But if they are inlined into a checkptr-enabled function, they will be instrumented, and may result in a check failure. Let the compiler not inline runtime functions into checkptr- enabled functions. Also undo the change in the strings package in CL 598295, as the compiler handles it now. Fixes #68511. Updates #68415. Change-Id: I78eb380855ac9dd53c1a1a628ec0da75c3e5a1a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/599435 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 3959d54 commit f0de94f

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,15 @@ func canInlineCallExpr(callerfn *ir.Func, n *ir.CallExpr, callee *ir.Func, bigCa
10071007
return false, 0, false
10081008
}
10091009

1010+
if base.Debug.Checkptr != 0 && types.IsRuntimePkg(callee.Sym().Pkg) {
1011+
// We don't intrument runtime packages for checkptr (see base/flag.go).
1012+
if log && logopt.Enabled() {
1013+
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(callerfn),
1014+
fmt.Sprintf(`call to into runtime package function %s in -d=checkptr build`, ir.PkgFuncName(callee)))
1015+
}
1016+
return false, 0, false
1017+
}
1018+
10101019
// Check if we've already inlined this function at this particular
10111020
// call site, in order to stop inlining when we reach the beginning
10121021
// of a recursion cycle again. We don't inline immediately recursive

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

+5
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,11 @@ func IsNoRacePkg(p *Pkg) bool {
19271927
return objabi.LookupPkgSpecial(p.Path).NoRaceFunc
19281928
}
19291929

1930+
// IsRuntimePkg reports whether p is a runtime package.
1931+
func IsRuntimePkg(p *Pkg) bool {
1932+
return objabi.LookupPkgSpecial(p.Path).Runtime
1933+
}
1934+
19301935
// ReceiverBaseType returns the underlying type, if any,
19311936
// that owns methods with receiver parameter t.
19321937
// The result is either a named type or an anonymous struct.

src/cmd/internal/objabi/pkgspecial.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type PkgSpecial struct {
1818
//
1919
// - Optimizations are always enabled.
2020
//
21+
// - Checkptr is always disabled.
22+
//
2123
// This should be set for runtime and all packages it imports, and may be
2224
// set for additional packages.
2325
Runtime bool

src/strings/builder.go

+1-13
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,14 @@ type Builder struct {
2323
buf []byte
2424
}
2525

26-
// This is just a wrapper around abi.NoEscape.
27-
//
28-
// This wrapper is necessary because internal/abi is a runtime package,
29-
// so it can not be built with -d=checkptr, causing incorrect inlining
30-
// decision when building with checkptr enabled, see issue #68415.
31-
//
32-
//go:nosplit
33-
//go:nocheckptr
34-
func noescape(p unsafe.Pointer) unsafe.Pointer {
35-
return abi.NoEscape(p)
36-
}
37-
3826
func (b *Builder) copyCheck() {
3927
if b.addr == nil {
4028
// This hack works around a failing of Go's escape analysis
4129
// that was causing b to escape and be heap allocated.
4230
// See issue 23382.
4331
// TODO: once issue 7921 is fixed, this should be reverted to
4432
// just "b.addr = b".
45-
b.addr = (*Builder)(noescape(unsafe.Pointer(b)))
33+
b.addr = (*Builder)(abi.NoEscape(unsafe.Pointer(b)))
4634
} else if b.addr != b {
4735
panic("strings: illegal use of non-zero Builder copied by value")
4836
}

test/fixedbugs/issue68415.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
package main
88

9-
import "regexp"
9+
import (
10+
"regexp"
11+
"unique"
12+
)
1013

1114
var dataFileRegexp = regexp.MustCompile(`^data\.\d+\.bin$`)
1215

1316
func main() {
1417
_ = dataFileRegexp
18+
unique.Make("")
1519
}

0 commit comments

Comments
 (0)