Description
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.
Activity
[-]how does go plugin check package version[/-][+]plugin: loading on machine with different GOPATH fails[/+]randall77 commentedon Aug 7, 2018
I don't think that's intentional.
Can you run
go version
on your two different Go installations and report what they print?The version mismatch is not between the plugin and the Go installation, it is between the Go installation that built the plugin and the Go installation that built the main program. Where was the main binary built? (You don't need the Go installation on the server at all, at least to run Go binaries and plugins.)
I can install two identical
go
instances at different paths, build the plugin with one and the main program with another, and the plugin loads just fine.suoigwg commentedon Aug 8, 2018
@randall77
They run exactly the same version of go(1.10.3). The only difference in
go env
is the go path.Yes the main file is build by a different installation of go on a different machine(which only differs in gopath)
Basically what I am doing is building a plugin that references some model.go, and serve the model and plugin to the client so they can write program of their own.
that is
build a plugin.so and serve the so and model to user, the user may write a program on their machine like
Essentially I need to hide the implementation of the
PublicApi
, I tried to build the plugin in a docker container(go path/go
) and test it on a vm (go path/home/username/go
). By testing I mean copy copying plugin.so ./model and stub.go to the corresponding directory and of course build the stub.go there, I always get that panic unless I change the go path to the samesuoigwg commentedon Aug 8, 2018
@randall77
docker file to reproduce
environment 1
build plugin
copy the plugin from docker container
environment 2(differ only in gopath)
use plugin in env2
suoigwg commentedon Aug 8, 2018
It will work by using plugin in env1 in the same way
randall77 commentedon Aug 8, 2018
I still can't reproduce your issue. Your plugin runs fine for me.
Please run
go version
on all the Go installations involved and report the results. Maybe your symlinks aren't putting thego
binary sufficiently in front of a default Go installation in the path?I've never used Docker, unfortunately, so I don't know what things like "use plugin in env2" mean.
suoigwg commentedon Aug 8, 2018
go version
from machine 1go env
in case you need more infogo version
from machine 2go env
from machine 2randall77 commentedon Aug 11, 2018
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
plugin
package. 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.
juhwany commentedon Sep 19, 2018
@randall77
It still happens in Go 1.11. Is there any progress about this issue?
randall77 commentedon Sep 19, 2018
No progress. I think I understand the problem but I have no idea what the fix might be.
24 remaining items