-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.8rc3 linux/amd64
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/fsenart/projects"
GORACE=""
GOROOT="/home/fsenart/tools/go1.8rc3"
GOTOOLDIR="/home/fsenart/tools/go1.8rc3/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build101924921=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Scenario:
- Build a main program with some dependency located in the GOPATH
- Build a plugin program with the same dependency vendored
- Load the plugin from main
Result:
- At runtime, the GOPATH dependency is not the same as the vendored depedency.
// $GOPATH/src/issues/issue_vendor/main .go
package main
import (
"foo"
"plugin"
"reflect"
)
func main() {
p, err := plugin.Open("plugin.so")
if err != nil {
panic(err)
}
f, err := p.Lookup("F")
if err != nil {
panic(err)
}
println(reflect.TypeOf(f).Elem() == reflect.TypeOf((*foo.Bar)(nil)))
}// $GOPATH/src/issues/issue_vendor/plugin.go
package main
import "C"
import "foo"
var F *foo.Bar// Copy the file one time in the GOPATH and one time in the vendor directory
// $GOPATH/src/foo/bar.go
// $GOPATH/src/issues/issue_vendor/vendor/foo/bar.go
package foo
type Bar struct{}# $GOPATH/src/issues/issue_vendor/Makefile
test1: build1
@./main
test2: build2
@./main
build1: clean
@go build -o main main.go
@go build -buildmode=plugin -o plugin.so plugin.go
build2: clean
@mv vendor _vendor
@go build -o main main.go
@mv _vendor vendor
@go build -buildmode=plugin -o plugin.so plugin.go
clean:
@rm -rf mainWhat did you expect to see?
make test1should printtruemake test2should printtrue
What did you see instead?
make test1printstruemake test2printsfalse