aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorCherry Zhang <cherryyz@google.com>2021-02-25 20:01:53 -0500
committerCherry Zhang <cherryyz@google.com>2021-02-26 16:27:08 +0000
commita655208c9ecd2fee4de6deff35a863b1c28a091c (patch)
tree3a175147b63495465a363aebd68a2b7d71d2fb67 /misc
parent23943a67378040340d835734a55dee7cb639e586 (diff)
downloadgo-a655208c9ecd2fee4de6deff35a863b1c28a091c.tar.gz
go-a655208c9ecd2fee4de6deff35a863b1c28a091c.zip
cmd/link: handle types as converted to interface when dynlink
When using plugins, a type (whose value) may be pass to a plugin and get converted to interface there, or vice versa. We need to treat the type as potentially converted to interface, and retain its methods. Should fix #44586. Change-Id: I80dd35e68baedaa852a317543ccd78d94628d13b Reviewed-on: https://go-review.googlesource.com/c/go/+/296709 Trust: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/testplugin/plugin_test.go13
-rw-r--r--misc/cgo/testplugin/testdata/method2/main.go32
-rw-r--r--misc/cgo/testplugin/testdata/method2/p/p.go9
-rw-r--r--misc/cgo/testplugin/testdata/method2/plugin.go11
4 files changed, 58 insertions, 7 deletions
diff --git a/misc/cgo/testplugin/plugin_test.go b/misc/cgo/testplugin/plugin_test.go
index 9055dbda04..2d991012c8 100644
--- a/misc/cgo/testplugin/plugin_test.go
+++ b/misc/cgo/testplugin/plugin_test.go
@@ -201,12 +201,11 @@ func TestMethod(t *testing.T) {
// Exported symbol's method must be live.
goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./method/plugin.go")
goCmd(t, "build", "-o", "method.exe", "./method/main.go")
+ run(t, "./method.exe")
+}
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- defer cancel()
- cmd := exec.CommandContext(ctx, "./method.exe")
- out, err := cmd.CombinedOutput()
- if err != nil {
- t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out)
- }
+func TestMethod2(t *testing.T) {
+ goCmd(t, "build", "-buildmode=plugin", "-o", "method2.so", "./method2/plugin.go")
+ goCmd(t, "build", "-o", "method2.exe", "./method2/main.go")
+ run(t, "./method2.exe")
}
diff --git a/misc/cgo/testplugin/testdata/method2/main.go b/misc/cgo/testplugin/testdata/method2/main.go
new file mode 100644
index 0000000000..6a87e7b6a0
--- /dev/null
+++ b/misc/cgo/testplugin/testdata/method2/main.go
@@ -0,0 +1,32 @@
+// Copyright 2021 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.
+
+// A type can be passed to a plugin and converted to interface
+// there. So its methods need to be live.
+
+package main
+
+import (
+ "plugin"
+
+ "testplugin/method2/p"
+)
+
+var t p.T
+
+type I interface { M() }
+
+func main() {
+ pl, err := plugin.Open("method2.so")
+ if err != nil {
+ panic(err)
+ }
+
+ f, err := pl.Lookup("F")
+ if err != nil {
+ panic(err)
+ }
+
+ f.(func(p.T) interface{})(t).(I).M()
+}
diff --git a/misc/cgo/testplugin/testdata/method2/p/p.go b/misc/cgo/testplugin/testdata/method2/p/p.go
new file mode 100644
index 0000000000..acb526acec
--- /dev/null
+++ b/misc/cgo/testplugin/testdata/method2/p/p.go
@@ -0,0 +1,9 @@
+// Copyright 2021 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 p
+
+type T int
+
+func (T) M() { println("M") }
diff --git a/misc/cgo/testplugin/testdata/method2/plugin.go b/misc/cgo/testplugin/testdata/method2/plugin.go
new file mode 100644
index 0000000000..6198e7648e
--- /dev/null
+++ b/misc/cgo/testplugin/testdata/method2/plugin.go
@@ -0,0 +1,11 @@
+// Copyright 2021 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 "testplugin/method2/p"
+
+func main() {}
+
+func F(t p.T) interface{} { return t }