mirror of
https://github.com/golang/go
synced 2025-04-18 00:56:09 +00:00
[release-branch.go1.20] cmd/compile: re-compile instantiated generic methods in linkshared mode
For G[T] that was seen and compiled in imported package, it is not added to typecheck.Target.Decls, prevent wasting compile time re-creating DUPOKS symbols. However, the linker do not support a type symbol referencing a method symbol across DSO boundary. That causes unreachable sym error when building under -linkshared mode. To fix it, always re-compile generic methods in linkshared mode. Fixes #59236 Change-Id: I894b417cfe8234ae1fe809cc975889345df22cef Reviewed-on: https://go-review.googlesource.com/c/go/+/477375 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/479355
This commit is contained in:
committed by
Matthew Dempsky
parent
65fa8a6931
commit
94c02a3cc4
@ -1112,8 +1112,13 @@ func TestStd(t *testing.T) {
|
||||
t.Skip("skip in short mode")
|
||||
}
|
||||
t.Parallel()
|
||||
tmpDir := t.TempDir()
|
||||
// Use a temporary pkgdir to not interfere with other tests, and not write to GOROOT.
|
||||
// Cannot use goCmd as it runs with cloned GOROOT which is incomplete.
|
||||
runWithEnv(t, "building std", []string{"GOROOT=" + oldGOROOT},
|
||||
filepath.Join(oldGOROOT, "bin", "go"), "install", "-buildmode=shared", "-pkgdir="+t.TempDir(), "std")
|
||||
filepath.Join(oldGOROOT, "bin", "go"), "install", "-buildmode=shared", "-pkgdir="+tmpDir, "std")
|
||||
|
||||
// Issue #58966.
|
||||
runWithEnv(t, "testing issue #58966", []string{"GOROOT=" + oldGOROOT},
|
||||
filepath.Join(oldGOROOT, "bin", "go"), "run", "-linkshared", "-pkgdir="+tmpDir, "./issue58966/main.go")
|
||||
}
|
||||
|
15
misc/cgo/testshared/testdata/issue58966/main.go
vendored
Normal file
15
misc/cgo/testshared/testdata/issue58966/main.go
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "crypto/elliptic"
|
||||
|
||||
var curve elliptic.Curve
|
||||
|
||||
func main() {
|
||||
switch curve {
|
||||
case elliptic.P224():
|
||||
}
|
||||
}
|
@ -158,7 +158,11 @@ func readBodies(target *ir.Package, duringInlining bool) {
|
||||
// Instantiated generic function: add to Decls for typechecking
|
||||
// and compilation.
|
||||
if fn.OClosure == nil && len(pri.dict.targs) != 0 {
|
||||
if duringInlining {
|
||||
// cmd/link does not support a type symbol referencing a method symbol
|
||||
// across DSO boundary, so force re-compiling methods on a generic type
|
||||
// even it was seen from imported package in linkshared mode, see #58966.
|
||||
canSkipNonGenericMethod := !(base.Ctxt.Flag_linkshared && ir.IsMethod(fn))
|
||||
if duringInlining && canSkipNonGenericMethod {
|
||||
inlDecls = append(inlDecls, fn)
|
||||
} else {
|
||||
target.Decls = append(target.Decls, fn)
|
||||
|
Reference in New Issue
Block a user