mirror of
https://github.com/golang/go
synced 2024-11-08 18:26:14 -07:00
86954d5246
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 <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
27 lines
478 B
Go
27 lines
478 B
Go
// Copyright 2020 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.
|
|
|
|
// Issue 42579: methods of symbols exported from plugin must be live.
|
|
|
|
package main
|
|
|
|
import (
|
|
"plugin"
|
|
"reflect"
|
|
)
|
|
|
|
func main() {
|
|
p, err := plugin.Open("plugin.so")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
x, err := p.Lookup("X")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
reflect.ValueOf(x).Elem().MethodByName("M").Call(nil)
|
|
}
|