go: plugin: loading on machine with different GOPATH fails
What version of Go are you using (go version)?
go version go1.10.3 linux/amd64
Does this issue reproduce with the latest release?
Yes?
What operating system and processor architecture are you using (go env)?
GOARCH=“amd64” GOBIN=“” GOCACHE=“/home/blablabla/.cache/go-build” GOEXE=“” GOHOSTARCH=“amd64” GOHOSTOS=“linux” GOOS=“linux” GOPATH=“/go” GORACE=“” GOROOT=“/opt/go” GOTMPDIR=“” GOTOOLDIR=“/opt/go/pkg/tool/linux_amd64” GCCGO=“gccgo” CC=“gcc” CXX=“g++” CGO_ENABLED=“1” CGO_CFLAGS=“-g -O2” CGO_CPPFLAGS=“” CGO_CXXFLAGS=“-g -O2” CGO_FFLAGS=“-g -O2” CGO_LDFLAGS=“-g -O2” PKG_CONFIG=“pkg-config” GOGCCFLAGS=“-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build657274199=/tmp/go-build -gno-record-gcc-switches”
What did you do?
I build a go plugin from a docker image and copy it to a server. They have essentially the same go env except for the go path. (One was /go the other /home/username/go)
When I tried to load the plugin from other server, I always get
panic: plugin.Open("./parser"): plugin was built with a different version of package xxxx
It can only be fixed by setting the gopath the same as that in the docker image I used to build the plugin
I don’t know if this is a bug or it is just how go plugin works.
Thanks.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 16 (6 by maintainers)
Hello,
UP ?
Ok, my bad. I was thinking GOROOT, not GOPATH. I am now able to reproduce. With the following directory structure:
If you do:
The version check is using the hash of some header information in the exported information from the
pluginpackage. That exported information has the full path in it, not just the path from GOPATH. As such, it’s different for the two otherwise identical plugin packages.The full path just appears in the filenames. I’m not sure that’s relevant information to be hashing. For source code from GOROOT, the path starts at $GOROOT/src/… but for source from GOPATH the full path is used. I can understand why, as GOPATH can have colon-separated paths and it would not be clear which one was the source of the file in question.
Seems related to #9206 and #16860.