Skip to content

plugin: not usable on another host using same go version and common dependencies #29055

Closed
@oszika

Description

@oszika

What version of Go are you using (go version)?

$ go version
go version go1.11.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env ArchLinux host
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/oszika/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/oszika/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/oszika/go/src/plugin/main/go.mod"
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-build912174408=/tmp/go-build -gno-record-gcc-switches"
go env Docker golang:1.11.2
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/plugins/main/go.mod"
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-build407785075=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I try to build plugin on host and use it on container. Versions of common dependencies are defined in go.mod.

p1/go.mod

module p1

require gopkg.in/yaml.v2 v2.2.1

p1/p1.go

package main

import (
        "fmt"

        yaml "gopkg.in/yaml.v2"
)

var e = yaml.Encoder{}

func init() { fmt.Printf("p1: Type: %T\n", e) }

func main() {}

main/go.mod

module main

require (
        gopkg.in/yaml.v2 v2.2.1
        p1 v0.0.0 // indirect
)

replace p1 => ../p1

main/main.go

package main

import (
        "fmt"
        "plugin"

        yaml "gopkg.in/yaml.v2"
)

var e = yaml.Encoder{}

func init() { fmt.Printf("main: Type: %T\n", e) }

func main() {
        if _, err := plugin.Open("p1.so"); err != nil {
                panic(err)
        }
}

On host :

.../main $ go build -buildmode=plugin p1

On docker

.../main $ go run main.go

What did you expect to see?

Like on host:

.../main $ go run main.go
main: Type: yaml.Encoder
p1: Type: yaml.Encode

What did you see instead?

.../main $ go run main.go 
go: finding gopkg.in/yaml.v2 v2.2.1
go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
go: downloading gopkg.in/yaml.v2 v2.2.1
main: Type: yaml.Encoder
panic: plugin.Open("p1"): plugin was built with a different version of package gopkg.in/yaml.v2

goroutine 1 [running]:
main.main()
	/plugins/main/main.go:16 +0x63
exit status 2

Except the GOROOT, the package built seems the same:

On host:

#
# gopkg.in/yaml.v2
#

mkdir -p $WORK/b026/
cat >$WORK/b026/importcfg << 'EOF' # internal
# import config
packagefile bytes=/usr/lib/go/pkg/linux_amd64/bytes.a
packagefile encoding=/usr/lib/go/pkg/linux_amd64/encoding.a
packagefile encoding/base64=/usr/lib/go/pkg/linux_amd64/encoding/base64.a
packagefile errors=/usr/lib/go/pkg/linux_amd64/errors.a
packagefile fmt=/usr/lib/go/pkg/linux_amd64/fmt.a
packagefile io=/usr/lib/go/pkg/linux_amd64/io.a
packagefile math=/usr/lib/go/pkg/linux_amd64/math.a
packagefile reflect=/usr/lib/go/pkg/linux_amd64/reflect.a
packagefile regexp=/usr/lib/go/pkg/linux_amd64/regexp.a
packagefile sort=/usr/lib/go/pkg/linux_amd64/sort.a
packagefile strconv=/usr/lib/go/pkg/linux_amd64/strconv.a
packagefile strings=/usr/lib/go/pkg/linux_amd64/strings.a
packagefile sync=/usr/lib/go/pkg/linux_amd64/sync.a
packagefile time=/usr/lib/go/pkg/linux_amd64/time.a
packagefile unicode=/usr/lib/go/pkg/linux_amd64/unicode.a
packagefile unicode/utf8=/usr/lib/go/pkg/linux_amd64/unicode/utf8.a
EOF
cd /home/oszika/go/pkg/mod/gopkg.in/yaml.v2@v2.2.1
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/b026/_pkg_.a -trimpath $WORK/b026 -p gopkg.in/yaml.v2 -complete -buildid -TBoSu6rbJldl0TAHMGq/-TBoSu6rbJldl0TAHMGq -goversion go1.11.2 -D "" -importcfg $WORK/b026/importcfg -pack -c=4 ./apic.go ./decode.go ./emitterc.go ./encode.go ./parserc.go ./readerc.go ./resolve.go ./scannerc.go ./sorter.go ./writerc.go ./yaml.go ./yamlh.go ./yamlprivateh.go
/usr/lib/go/pkg/tool/linux_amd64/buildid -w $WORK/b026/_pkg_.a # internal

On container:

#
# gopkg.in/yaml.v2
#

mkdir -p $WORK/b026/
cat >$WORK/b026/importcfg << 'EOF' # internal
# import config
packagefile bytes=/usr/local/go/pkg/linux_amd64/bytes.a
packagefile encoding=/usr/local/go/pkg/linux_amd64/encoding.a
packagefile encoding/base64=/usr/local/go/pkg/linux_amd64/encoding/base64.a
packagefile errors=/usr/local/go/pkg/linux_amd64/errors.a
packagefile fmt=/usr/local/go/pkg/linux_amd64/fmt.a
packagefile io=/usr/local/go/pkg/linux_amd64/io.a
packagefile math=/usr/local/go/pkg/linux_amd64/math.a
packagefile reflect=/usr/local/go/pkg/linux_amd64/reflect.a
packagefile regexp=/usr/local/go/pkg/linux_amd64/regexp.a
packagefile sort=/usr/local/go/pkg/linux_amd64/sort.a
packagefile strconv=/usr/local/go/pkg/linux_amd64/strconv.a
packagefile strings=/usr/local/go/pkg/linux_amd64/strings.a
packagefile sync=/usr/local/go/pkg/linux_amd64/sync.a
packagefile time=/usr/local/go/pkg/linux_amd64/time.a
packagefile unicode=/usr/local/go/pkg/linux_amd64/unicode.a
packagefile unicode/utf8=/usr/local/go/pkg/linux_amd64/unicode/utf8.a
EOF
cd /go/pkg/mod/gopkg.in/yaml.v2@v2.2.1
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/b026/_pkg_.a -trimpath $WORK/b026 -p gopkg.in/yaml.v2 -complete -buildid Vu3xvoPx_6--pylAg8yB/Vu3xvoPx_6--pylAg8yB -goversion go1.11.2 -D "" -importcfg $WORK/b026/importcfg -pack -c=4 ./apic.go ./decode.go ./emitterc.go ./encode.go ./parserc.go ./readerc.go ./resolve.go ./scannerc.go ./sorter.go ./writerc.go ./yaml.go ./yamlh.go ./yamlprivateh.go
/usr/local/go/pkg/tool/linux_amd64/buildid -w $WORK/b026/_pkg_.a # internal

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions