diff options
| author | David Crawshaw <crawshaw@golang.org> | 2017-10-01 20:28:53 -0400 |
|---|---|---|
| committer | David Crawshaw <crawshaw@golang.org> | 2017-10-04 00:46:06 +0000 |
| commit | 273b657b4e970f510afb258aa73dc2e264a701e3 (patch) | |
| tree | 073164ae68d916ae18899f30251943eb5aa3252d /misc/cgo/testplugin | |
| parent | 5fe9bbcf6312b32e0c9df10a5ea6ba18e929de72 (diff) | |
| download | go-273b657b4e970f510afb258aa73dc2e264a701e3.tar.xz | |
cmd/link: support -X values for main.* in plugins
Fixes #19418
Change-Id: I98205f40c1915cd68a5d20438469ba06f1efb160
Reviewed-on: https://go-review.googlesource.com/67432
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'misc/cgo/testplugin')
| -rw-r--r-- | misc/cgo/testplugin/src/issue19418/main.go | 29 | ||||
| -rw-r--r-- | misc/cgo/testplugin/src/issue19418/plugin.go | 7 | ||||
| -rwxr-xr-x | misc/cgo/testplugin/test.bash | 5 |
3 files changed, 41 insertions, 0 deletions
diff --git a/misc/cgo/testplugin/src/issue19418/main.go b/misc/cgo/testplugin/src/issue19418/main.go new file mode 100644 index 0000000000..2ec9f9aaaa --- /dev/null +++ b/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/misc/cgo/testplugin/src/issue19418/plugin.go b/misc/cgo/testplugin/src/issue19418/plugin.go new file mode 100644 index 0000000000..fe93b16143 --- /dev/null +++ b/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/misc/cgo/testplugin/test.bash b/misc/cgo/testplugin/test.bash index a52aa46037..ae3368b45f 100755 --- a/misc/cgo/testplugin/test.bash +++ b/misc/cgo/testplugin/test.bash @@ -66,3 +66,8 @@ GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -o issue19534 src/issue19534/main. 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 |
