mirror of
https://github.com/golang/go
synced 2024-11-25 16:57:58 -07:00
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
3959d54c0b
commit
f0de94ff12
@ -1007,6 +1007,15 @@ func canInlineCallExpr(callerfn *ir.Func, n *ir.CallExpr, callee *ir.Func, bigCa
|
||||
return false, 0, false
|
||||
}
|
||||
|
||||
if base.Debug.Checkptr != 0 && types.IsRuntimePkg(callee.Sym().Pkg) {
|
||||
// We don't intrument runtime packages for checkptr (see base/flag.go).
|
||||
if log && logopt.Enabled() {
|
||||
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", ir.FuncName(callerfn),
|
||||
fmt.Sprintf(`call to into runtime package function %s in -d=checkptr build`, ir.PkgFuncName(callee)))
|
||||
}
|
||||
return false, 0, false
|
||||
}
|
||||
|
||||
// Check if we've already inlined this function at this particular
|
||||
// call site, in order to stop inlining when we reach the beginning
|
||||
// of a recursion cycle again. We don't inline immediately recursive
|
||||
|
@ -1927,6 +1927,11 @@ func IsNoRacePkg(p *Pkg) bool {
|
||||
return objabi.LookupPkgSpecial(p.Path).NoRaceFunc
|
||||
}
|
||||
|
||||
// IsRuntimePkg reports whether p is a runtime package.
|
||||
func IsRuntimePkg(p *Pkg) bool {
|
||||
return objabi.LookupPkgSpecial(p.Path).Runtime
|
||||
}
|
||||
|
||||
// ReceiverBaseType returns the underlying type, if any,
|
||||
// that owns methods with receiver parameter t.
|
||||
// The result is either a named type or an anonymous struct.
|
||||
|
@ -18,6 +18,8 @@ type PkgSpecial struct {
|
||||
//
|
||||
// - Optimizations are always enabled.
|
||||
//
|
||||
// - Checkptr is always disabled.
|
||||
//
|
||||
// This should be set for runtime and all packages it imports, and may be
|
||||
// set for additional packages.
|
||||
Runtime bool
|
||||
|
@ -23,18 +23,6 @@ type Builder struct {
|
||||
buf []byte
|
||||
}
|
||||
|
||||
// This is just a wrapper around abi.NoEscape.
|
||||
//
|
||||
// This wrapper is necessary because internal/abi is a runtime package,
|
||||
// so it can not be built with -d=checkptr, causing incorrect inlining
|
||||
// decision when building with checkptr enabled, see issue #68415.
|
||||
//
|
||||
//go:nosplit
|
||||
//go:nocheckptr
|
||||
func noescape(p unsafe.Pointer) unsafe.Pointer {
|
||||
return abi.NoEscape(p)
|
||||
}
|
||||
|
||||
func (b *Builder) copyCheck() {
|
||||
if b.addr == nil {
|
||||
// This hack works around a failing of Go's escape analysis
|
||||
@ -42,7 +30,7 @@ func (b *Builder) copyCheck() {
|
||||
// See issue 23382.
|
||||
// TODO: once issue 7921 is fixed, this should be reverted to
|
||||
// just "b.addr = b".
|
||||
b.addr = (*Builder)(noescape(unsafe.Pointer(b)))
|
||||
b.addr = (*Builder)(abi.NoEscape(unsafe.Pointer(b)))
|
||||
} else if b.addr != b {
|
||||
panic("strings: illegal use of non-zero Builder copied by value")
|
||||
}
|
||||
|
@ -6,10 +6,14 @@
|
||||
|
||||
package main
|
||||
|
||||
import "regexp"
|
||||
import (
|
||||
"regexp"
|
||||
"unique"
|
||||
)
|
||||
|
||||
var dataFileRegexp = regexp.MustCompile(`^data\.\d+\.bin$`)
|
||||
|
||||
func main() {
|
||||
_ = dataFileRegexp
|
||||
unique.Make("")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user