Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: unable to load plugin if go mod is not enabled #31951

Closed
life1347 opened this issue May 9, 2019 · 4 comments
Closed

plugin: unable to load plugin if go mod is not enabled #31951

life1347 opened this issue May 9, 2019 · 4 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@life1347
Copy link

life1347 commented May 9, 2019

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

1.11.10

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (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=""
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-build245942501=/tmp/go-build -gno-record-gcc-switches"

What did you do?

test-go/
├── main.go
└── plugins
    └── main.go
  • test-go/plugins/main.go
package main

import (
	"fmt"
	"net/http"
)

func Foobar() {
	fmt.Printf("Foo Bar: %v", http.StatusOK)
}
  • test-go/main.go
package main

import (
	"fmt"
	"plugin"
	"net/http"
)

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

	symbol, err := p.Lookup("Foobar")
	if err != nil {
		panic(err)
	}

	f := symbol.(func())
	f()

	fmt.Printf("%v", http.StatusOK)
}

Steps to reproduce

/go/src/test-go# cd plugins
/go/src/test-go/plugins# export export GO111MODULE=on
/go/src/test-go/plugins# go build -buildmode=plugin -o plugin.so
/go/src/test-go/plugins# mv plugin.so ../
/go/src/test-go/plugins# cd ../
/go/src/test-go# export export GO111MODULE=off
/go/src/test-go# go run main.go

panic: plugin.Open("plugin"): plugin was built with a different version of package net

goroutine 1 [running]:
main.main()
	/go/src/test-go/main.go:12 +0x249
exit status 2

Everything works with 1.12.4 but failed with 1.11.10 (Test with docker golang:1.12.4 and golang:1.11.10).

The workaround is to set GO111MODULE=on then it works again.

/go/src/test-go# export export GO111MODULE=on
/go/src/test-go# go mod init
/go/src/test-go# go run main.go

Foo Bar: 200200

Question

  1. Why having different results in 1.12.4 and 1.11.10 if GO111MODULE=off?
  2. As long as plugins/main.go doesn't import net/http then it works in 1.11.10. Why?

What did you expect to see?

Main application should be able to load the plugin.

What did you see instead?

In 1.11.10

panic: plugin.Open("plugin"): plugin was built with a different version of package net

goroutine 1 [running]:
main.main()
	/go/src/test-go/main.go:12 +0x249
exit status 2

in 1.12.4

Foo Bar: 200200
@andybons andybons added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 13, 2019
@andybons andybons added this to the Unplanned milestone May 13, 2019
@andybons
Copy link
Member

@bcmills
Copy link
Contributor

bcmills commented May 13, 2019

See previously #31354 and #31278.

@bcmills
Copy link
Contributor

bcmills commented May 13, 2019

The difference you observe between 1.11.10 and 1.12.4 is possibly due to #27285.

@bcmills
Copy link
Contributor

bcmills commented May 13, 2019

Duplicate of #31278

@bcmills bcmills marked this as a duplicate of #31278 May 13, 2019
@bcmills bcmills closed this as completed May 13, 2019
@golang golang locked and limited conversation to collaborators May 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants