log.Fatalf(`plugin1.F()=%d, want 17`, gotf)
}
- // plugin2 has no exported symbols, only an init function.
- if _, err := plugin.Open("plugin2.so"); err != nil {
+ p2, err := plugin.Open("plugin2.so")
+ if err != nil {
log.Fatalf("plugin.Open failed: %v", err)
}
+ // Check that plugin2's init function was called, and
+ // that it modifies the same global variable as the host.
if got, want := common.X, 2; got != want {
log.Fatalf("after loading plugin2, common.X=%d, want %d", got, want)
}
log.Fatalf(`plugin.Open("plugin-mismatch.so"): error does not mention "different version": %v`, s)
}
+ // Test that unexported types with the same names in
+ // different plugins do not interfere with each other.
+ //
+ // See Issue #21386.
+ UnexportedNameReuse, _ := p.Lookup("UnexportedNameReuse")
+ UnexportedNameReuse.(func())()
+ UnexportedNameReuse, _ = p2.Lookup("UnexportedNameReuse")
+ UnexportedNameReuse.(func())()
+
testUnnamed()
fmt.Println("PASS")
// // No C code required.
import "C"
-import "common"
+import (
+ "common"
+ "reflect"
+)
func F() int {
_ = make([]byte, 1<<21) // trigger stack unwind, Issue #18190.
call(g)
}
+type sameNameReusedInPlugins struct {
+ X string
+}
+
+type sameNameHolder struct {
+ F *sameNameReusedInPlugins
+}
+
+func UnexportedNameReuse() {
+ h := sameNameHolder{}
+ v := reflect.ValueOf(&h).Elem().Field(0)
+ newval := reflect.New(v.Type().Elem())
+ v.Set(newval)
+}
+
func main() {
panic("plugin1.main called")
}
import (
"common"
+ "reflect"
"strings"
)
common.X = 2
}
+type sameNameReusedInPlugins struct {
+ X string
+}
+
+type sameNameHolder struct {
+ F *sameNameReusedInPlugins
+}
+
+func UnexportedNameReuse() {
+ h := sameNameHolder{}
+ v := reflect.ValueOf(&h).Elem().Field(0)
+ newval := reflect.New(v.Type().Elem())
+ v.Set(newval)
+}
+
func main() {
panic("plugin1.main called")
}
ofile = objdir + out
}
- gcargs := []string{"-p", p.ImportPath}
- if p.Name == "main" {
- gcargs[1] = "main"
+ pkgpath := p.ImportPath
+ if cfg.BuildBuildmode == "plugin" {
+ if pkgpath == "command-line-arguments" {
+ pkgpath = "plugin/unnamed-" + p.Internal.BuildID
+ }
+ } else if p.Name == "main" {
+ pkgpath = "main"
}
+ gcargs := []string{"-p", pkgpath}
if p.Standard {
gcargs = append(gcargs, "-std")
}