From 86954d5246339231dc0c45f5547c37a1c3650264 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 13 Nov 2020 14:42:45 -0500 Subject: cmd/compile: mark plugin-exported types as used in interface Plugin exports symbols as interfaces. Mark their types as used in interfaces, so their methods will be kept alive by the linker. Fixes #42579. Change-Id: If1b5aacc21510c20c25f88bb131bca61db6f1d56 Reviewed-on: https://go-review.googlesource.com/c/go/+/269819 Trust: Cherry Zhang Reviewed-by: Than McIntosh --- misc/cgo/testplugin/plugin_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'misc/cgo/testplugin/plugin_test.go') diff --git a/misc/cgo/testplugin/plugin_test.go b/misc/cgo/testplugin/plugin_test.go index 2875271c03..9055dbda04 100644 --- a/misc/cgo/testplugin/plugin_test.go +++ b/misc/cgo/testplugin/plugin_test.go @@ -196,3 +196,17 @@ func TestIssue25756(t *testing.T) { }) } } + +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") + + 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) + } +} -- cgit v1.3