diff options
author | Ian Lance Taylor <iant@golang.org> | 2018-01-09 01:23:08 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-01-09 01:23:08 +0000 |
commit | 1a2f01efa63036a5104f203a4789e682c0e0915d (patch) | |
tree | 373e15778dc8295354584e1f86915ae493b604ff /libgo/misc/cgo/testplugin | |
parent | 8799df67f2dab88f9fda11739c501780a85575e2 (diff) |
libgo: update to Go1.10beta1
Update the Go library to the 1.10beta1 release.
Requires a few changes to the compiler for modifications to the map
runtime code, and to handle some nowritebarrier cases in the runtime.
Reviewed-on: https://go-review.googlesource.com/86455
gotools/:
* Makefile.am (go_cmd_vet_files): New variable.
(go_cmd_buildid_files, go_cmd_test2json_files): New variables.
(s-zdefaultcc): Change from constants to functions.
(noinst_PROGRAMS): Add vet, buildid, and test2json.
(cgo$(EXEEXT)): Link against $(LIBGOTOOL).
(vet$(EXEEXT)): New target.
(buildid$(EXEEXT)): New target.
(test2json$(EXEEXT)): New target.
(install-exec-local): Install all $(noinst_PROGRAMS).
(uninstall-local): Uninstasll all $(noinst_PROGRAMS).
(check-go-tool): Depend on $(noinst_PROGRAMS). Copy down
objabi.go.
(check-runtime): Depend on $(noinst_PROGRAMS).
(check-cgo-test, check-carchive-test): Likewise.
(check-vet): New target.
(check): Depend on check-vet. Look at cmd_vet-testlog.
(.PHONY): Add check-vet.
* Makefile.in: Rebuild.
From-SVN: r256365
Diffstat (limited to 'libgo/misc/cgo/testplugin')
16 files changed, 312 insertions, 20 deletions
diff --git a/libgo/misc/cgo/testplugin/src/host/host.go b/libgo/misc/cgo/testplugin/src/host/host.go index 898f44efa15..0ca17da3def 100644 --- a/libgo/misc/cgo/testplugin/src/host/host.go +++ b/libgo/misc/cgo/testplugin/src/host/host.go @@ -126,14 +126,24 @@ func main() { 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) } + _, err = plugin.Open("plugin2-dup.so") + if err == nil { + log.Fatal(`plugin.Open("plugin2-dup.so"): duplicate open should have failed`) + } + if s := err.Error(); !strings.Contains(s, "already loaded") { + log.Fatal(`plugin.Open("plugin2.so"): error does not mention "already loaded"`) + } + _, err = plugin.Open("plugin-mismatch.so") if err == nil { log.Fatal(`plugin.Open("plugin-mismatch.so"): should have failed`) @@ -142,6 +152,24 @@ func main() { log.Fatalf(`plugin.Open("plugin-mismatch.so"): error does not mention "different version": %v`, s) } + _, err = plugin.Open("plugin2-dup.so") + if err == nil { + log.Fatal(`plugin.Open("plugin2-dup.so"): duplicate open after bad plugin should have failed`) + } + _, err = plugin.Open("plugin2.so") + if err != nil { + log.Fatalf(`plugin.Open("plugin2.so"): second open with same name failed: %v`, err) + } + + // 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") diff --git a/libgo/misc/cgo/testplugin/src/issue18584/main.go b/libgo/misc/cgo/testplugin/src/issue18584/main.go new file mode 100644 index 00000000000..c280fd46203 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue18584/main.go @@ -0,0 +1,23 @@ +// Copyright 2017 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 "plugin" + +func main() { + p, err := plugin.Open("plugin.so") + if err != nil { + panic(err) + } + + sym, err := p.Lookup("G") + if err != nil { + panic(err) + } + g := sym.(func() bool) + if !g() { + panic("expected types to match, Issue #18584") + } +} diff --git a/libgo/misc/cgo/testplugin/src/issue18584/plugin.go b/libgo/misc/cgo/testplugin/src/issue18584/plugin.go new file mode 100644 index 00000000000..be0868d3752 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue18584/plugin.go @@ -0,0 +1,19 @@ +// Copyright 2017 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 "reflect" + +type C struct { +} + +func F(c *C) *C { + return nil +} + +func G() bool { + var c *C + return reflect.TypeOf(F).Out(0) == reflect.TypeOf(c) +} diff --git a/libgo/misc/cgo/testplugin/src/issue19418/main.go b/libgo/misc/cgo/testplugin/src/issue19418/main.go new file mode 100644 index 00000000000..2ec9f9aaaa2 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue19418/main.go @@ -0,0 +1,29 @@ +// Copyright 2017 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 ( + "fmt" + "os" + "plugin" +) + +func main() { + p, err := plugin.Open("plugin.so") + if err != nil { + panic(err) + } + + val, err := p.Lookup("Val") + if err != nil { + panic(err) + } + got := *val.(*string) + const want = "linkstr" + if got != want { + fmt.Fprintf(os.Stderr, "issue19418 value is %q, want %q\n", got, want) + os.Exit(2) + } +} diff --git a/libgo/misc/cgo/testplugin/src/issue19418/plugin.go b/libgo/misc/cgo/testplugin/src/issue19418/plugin.go new file mode 100644 index 00000000000..fe93b161431 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue19418/plugin.go @@ -0,0 +1,7 @@ +// Copyright 2017 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 + +var Val = "val-unset" diff --git a/libgo/misc/cgo/testplugin/src/issue19529/plugin.go b/libgo/misc/cgo/testplugin/src/issue19529/plugin.go new file mode 100644 index 00000000000..ad2df6cc7c7 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue19529/plugin.go @@ -0,0 +1,15 @@ +package main + +import ( + "reflect" +) + +type Foo struct { + Bar string `json:"Bar@baz,omitempty"` +} + +func F() { + println(reflect.TypeOf(Foo{}).Field(0).Tag) +} + +func main() {} diff --git a/libgo/misc/cgo/testplugin/src/issue22175/main.go b/libgo/misc/cgo/testplugin/src/issue22175/main.go new file mode 100644 index 00000000000..9be9bab9dc3 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue22175/main.go @@ -0,0 +1,28 @@ +// Copyright 2017 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 ( + "fmt" + "os" + "plugin" +) + +func main() { + p2, err := plugin.Open("issue22175_plugin1.so") + if err != nil { + panic(err) + } + f, err := p2.Lookup("F") + if err != nil { + panic(err) + } + got := f.(func() int)() + const want = 971 + if got != want { + fmt.Fprintf(os.Stderr, "issue22175: F()=%d, want %d", got, want) + os.Exit(1) + } +} diff --git a/libgo/misc/cgo/testplugin/src/issue22175/plugin1.go b/libgo/misc/cgo/testplugin/src/issue22175/plugin1.go new file mode 100644 index 00000000000..5ae6cb631e7 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue22175/plugin1.go @@ -0,0 +1,21 @@ +// Copyright 2017 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 "plugin" + +func F() int { + p2, err := plugin.Open("issue22175_plugin2.so") + if err != nil { + panic(err) + } + g, err := p2.Lookup("G") + if err != nil { + panic(err) + } + return g.(func() int)() +} + +func main() {} diff --git a/libgo/misc/cgo/testplugin/src/issue22175/plugin2.go b/libgo/misc/cgo/testplugin/src/issue22175/plugin2.go new file mode 100644 index 00000000000..f387a192e67 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue22175/plugin2.go @@ -0,0 +1,9 @@ +// Copyright 2017 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 + +func G() int { return 971 } + +func main() {} diff --git a/libgo/misc/cgo/testplugin/src/issue22295.pkg/main.go b/libgo/misc/cgo/testplugin/src/issue22295.pkg/main.go new file mode 100644 index 00000000000..6cb186e1003 --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue22295.pkg/main.go @@ -0,0 +1,28 @@ +// Copyright 2017 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. + +// +build ignore + +package main + +import ( + "log" + "plugin" +) + +func main() { + p, err := plugin.Open("issue.22295.so") + if err != nil { + log.Fatal(err) + } + f, err := p.Lookup("F") + if err != nil { + log.Fatal(err) + } + const want = 2503 + got := f.(func() int)() + if got != want { + log.Fatalf("got %d, want %d", got, want) + } +} diff --git a/libgo/misc/cgo/testplugin/src/issue22295.pkg/plugin.go b/libgo/misc/cgo/testplugin/src/issue22295.pkg/plugin.go new file mode 100644 index 00000000000..46b08a405bc --- /dev/null +++ b/libgo/misc/cgo/testplugin/src/issue22295.pkg/plugin.go @@ -0,0 +1,16 @@ +// Copyright 2017 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 + +var f *int + +func init() { + f = new(int) + *f = 2503 +} + +func F() int { return *f } + +func main() {} diff --git a/libgo/misc/cgo/testplugin/src/plugin1/plugin1.go b/libgo/misc/cgo/testplugin/src/plugin1/plugin1.go index edcef2c77e9..0a9fa2f2c1f 100644 --- a/libgo/misc/cgo/testplugin/src/plugin1/plugin1.go +++ b/libgo/misc/cgo/testplugin/src/plugin1/plugin1.go @@ -7,7 +7,10 @@ package main // // No C code required. import "C" -import "common" +import ( + "common" + "reflect" +) func F() int { _ = make([]byte, 1<<21) // trigger stack unwind, Issue #18190. @@ -33,6 +36,21 @@ func init() { 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") } diff --git a/libgo/misc/cgo/testplugin/src/plugin2/plugin2.go b/libgo/misc/cgo/testplugin/src/plugin2/plugin2.go index 9c507fc3658..a67f2de27a7 100644 --- a/libgo/misc/cgo/testplugin/src/plugin2/plugin2.go +++ b/libgo/misc/cgo/testplugin/src/plugin2/plugin2.go @@ -13,6 +13,7 @@ import "C" import ( "common" + "reflect" "strings" ) @@ -22,6 +23,21 @@ func init() { 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") } diff --git a/libgo/misc/cgo/testplugin/test.bash b/libgo/misc/cgo/testplugin/test.bash index 69df5bd2bfa..18e3803bf42 100644 --- a/libgo/misc/cgo/testplugin/test.bash +++ b/libgo/misc/cgo/testplugin/test.bash @@ -15,38 +15,73 @@ goos=$(go env GOOS) goarch=$(go env GOARCH) function cleanup() { - rm -f plugin*.so unnamed*.so iface*.so - rm -rf host pkg sub iface issue18676 issue19534 + rm -f plugin*.so unnamed*.so iface*.so issue* + rm -rf host pkg sub iface } trap cleanup EXIT rm -rf pkg sub mkdir sub -GOPATH=$(pwd) go build -buildmode=plugin plugin1 -GOPATH=$(pwd) go build -buildmode=plugin plugin2 -GOPATH=$(pwd)/altpath go build -buildmode=plugin plugin-mismatch -GOPATH=$(pwd) go build -buildmode=plugin -o=sub/plugin1.so sub/plugin1 -GOPATH=$(pwd) go build -buildmode=plugin unnamed1.go -GOPATH=$(pwd) go build -buildmode=plugin unnamed2.go -GOPATH=$(pwd) go build host +GOPATH=$(pwd) go build -i -gcflags "$GO_GCFLAGS" -buildmode=plugin plugin1 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin plugin2 +cp plugin2.so plugin2-dup.so +GOPATH=$(pwd)/altpath go build -gcflags "$GO_GCFLAGS" -buildmode=plugin plugin-mismatch +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=sub/plugin1.so sub/plugin1 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed1.so unnamed1/main.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed2.so unnamed2/main.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" host LD_LIBRARY_PATH=$(pwd) ./host # Test that types and itabs get properly uniqified. -GOPATH=$(pwd) go build -buildmode=plugin iface_a -GOPATH=$(pwd) go build -buildmode=plugin iface_b -GOPATH=$(pwd) go build iface +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin iface_a +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin iface_b +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" iface LD_LIBRARY_PATH=$(pwd) ./iface +function _timeout() ( + set -e + $2 & + p=$! + (sleep $1; kill $p 2>/dev/null) & + p2=$! + wait $p 2>/dev/null + kill -0 $p2 2>/dev/null +) + # Test for issue 18676 - make sure we don't add the same itab twice. # The buggy code hangs forever, so use a timeout to check for that. -GOPATH=$(pwd) go build -buildmode=plugin -o plugin.so src/issue18676/plugin.go -GOPATH=$(pwd) go build -o issue18676 src/issue18676/main.go -timeout 10s ./issue18676 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue18676/plugin.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue18676 src/issue18676/main.go +_timeout 10s ./issue18676 # Test for issue 19534 - that we can load a plugin built in a path with non-alpha # characters -GOPATH=$(pwd) go build -buildmode=plugin -ldflags='-pluginpath=issue.19534' -o plugin.so src/issue19534/plugin.go -GOPATH=$(pwd) go build -o issue19534 src/issue19534/main.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -ldflags='-pluginpath=issue.19534' -o plugin.so src/issue19534/plugin.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19534 src/issue19534/main.go ./issue19534 + +# Test for issue 18584 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue18584/plugin.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue18584 src/issue18584/main.go +./issue18584 + +# Test for issue 19418 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin "-ldflags=-X main.Val=linkstr" -o plugin.so src/issue19418/plugin.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19418 src/issue19418/main.go +./issue19418 + +# Test for issue 19529 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o plugin.so src/issue19529/plugin.go + +# Test for issue 22175 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o issue22175_plugin1.so src/issue22175/plugin1.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o issue22175_plugin2.so src/issue22175/plugin2.go +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue22175 src/issue22175/main.go +./issue22175 + +# Test for issue 22295 +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o issue.22295.so issue22295.pkg +GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue22295 src/issue22295.pkg/main.go +./issue22295 diff --git a/libgo/misc/cgo/testplugin/unnamed1.go b/libgo/misc/cgo/testplugin/unnamed1/main.go index 5c1df086d76..5c1df086d76 100644 --- a/libgo/misc/cgo/testplugin/unnamed1.go +++ b/libgo/misc/cgo/testplugin/unnamed1/main.go diff --git a/libgo/misc/cgo/testplugin/unnamed2.go b/libgo/misc/cgo/testplugin/unnamed2/main.go index 7ef66109c5c..7ef66109c5c 100644 --- a/libgo/misc/cgo/testplugin/unnamed2.go +++ b/libgo/misc/cgo/testplugin/unnamed2/main.go |