From: Cuong Manh Le Date: Tue, 13 Jun 2023 15:25:50 +0000 (+0700) Subject: cmd/compile: mark instantiated functions from package runtime as norace X-Git-Tag: go1.22rc1~1354 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5b2ddfadb2e218e325c91d1024ffbe87c1f38d19;p=gostls13.git cmd/compile: mark instantiated functions from package runtime as norace Fixes #60439 Change-Id: I09fcd2d3deb7f80ed012a769fdb6f53b09c0290b Reviewed-on: https://go-review.googlesource.com/c/go/+/502895 Reviewed-by: Michael Knyszek Auto-Submit: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/noder/unified.go b/src/cmd/compile/internal/noder/unified.go index 6c4ac66e3d..0afa505550 100644 --- a/src/cmd/compile/internal/noder/unified.go +++ b/src/cmd/compile/internal/noder/unified.go @@ -118,6 +118,16 @@ func unified(m posMap, noders []*noder) { } } + // For functions originally came from package runtime, + // mark as norace to prevent instrumenting, see issue #60439. + for _, n := range target.Decls { + if fn, ok := n.(*ir.Func); ok { + if !base.Flag.CompilingRuntime && types.IsRuntimePkg(fn.Sym().Pkg) { + fn.Pragma |= ir.Norace + } + } + } + base.ExitIfErrors() // just in case } diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go index 5641005401..a4a1fa580d 100644 --- a/src/runtime/export_test.go +++ b/src/runtime/export_test.go @@ -1932,3 +1932,11 @@ func SetPinnerLeakPanic(f func()) { func GetPinnerLeakPanic() func() { return pinnerLeakPanic } + +var testUintptr uintptr + +func MyGenericFunc[T any]() { + systemstack(func() { + testUintptr = 4 + }) +} diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go index bd01e36103..0c21cd43cd 100644 --- a/src/runtime/gc_test.go +++ b/src/runtime/gc_test.go @@ -929,3 +929,7 @@ func TestMemoryLimitNoGCPercent(t *testing.T) { t.Fatalf("expected %q, but got %q", want, got) } } + +func TestMyGenericFunc(t *testing.T) { + runtime.MyGenericFunc[int]() +}