aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2023-03-18 00:53:07 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2023-03-22 04:04:11 +0000
commitbcd82125f85c7c552493e863fa1bb14e6c444557 (patch)
treecef5a09e01472340412a52383984546d74432466 /misc
parentf17e7e84410aa03988dd2a9c4f446fc2c8d0da23 (diff)
downloadgo-bcd82125f85c7c552493e863fa1bb14e6c444557.tar.gz
go-bcd82125f85c7c552493e863fa1bb14e6c444557.zip
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 #58966 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>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/testshared/shared_test.go7
-rw-r--r--misc/cgo/testshared/testdata/issue58966/main.go15
2 files changed, 21 insertions, 1 deletions
diff --git a/misc/cgo/testshared/shared_test.go b/misc/cgo/testshared/shared_test.go
index 0b589d023b..e300e20e20 100644
--- a/misc/cgo/testshared/shared_test.go
+++ b/misc/cgo/testshared/shared_test.go
@@ -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")
}
diff --git a/misc/cgo/testshared/testdata/issue58966/main.go b/misc/cgo/testshared/testdata/issue58966/main.go
new file mode 100644
index 0000000000..2d923c3607
--- /dev/null
+++ b/misc/cgo/testshared/testdata/issue58966/main.go
@@ -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():
+ }
+}