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: load plugin crash fatal error: runtime: no plugin module data #33072

Open
WebFeng opened this issue Jul 12, 2019 · 7 comments
Open

plugin: load plugin crash fatal error: runtime: no plugin module data #33072

WebFeng opened this issue Jul 12, 2019 · 7 comments
Milestone

Comments

@WebFeng
Copy link

@WebFeng WebFeng commented Jul 12, 2019

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

go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
GOARCH="amd64"
GOBIN="/Users/webtom/go/bin"
GOCACHE="/Users/webtom/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/webtom/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0t/9w0_mgfs511g4ssg2r38cb240000gn/T/go-build339879137=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

// **notice** build plugin command:   go build -o test1.so -buildmode=plugin *.go
// **notice** test1.so and test2.so have the same content and different paths
_, err1 := plugin.Open("test1.so")
fmt.Println(err)
// err1:   plugin.Open("./test1.so"): plugin was built with a different version of package errors
_, _ = plugin.Open("test2.so")
// fatal error: runtime: no plugin module data

What did you expect to see?

No crash

What did you see instead?

fatal error: runtime: no plugin module data

goroutine 1 [running]:
runtime.throw(0x40f2177, 0x1e)
/usr/local/go/src/runtime/panic.go:608 +0x72 fp=0xc000047b00 sp=0xc000047ad0 pc=0x402a602
plugin.lastmoduleinit(0xc00008c480, 0xc00000e038, 0x4302ad0, 0x42, 0x41c7da0)
/usr/local/go/src/runtime/plugin.go:22 +0xc03 fp=0xc000047c28 sp=0xc000047b00 pc=0x402baa3
plugin.open(0x40efb00, 0x10, 0x60, 0x0, 0x0)
/usr/local/go/src/plugin/plugin_dlopen.go:87 +0x3b3 fp=0xc000047ee0 sp=0xc000047c28 pc=0x40b19d3
plugin.Open(0x40efb00, 0x13, 0x2, 0x60, 0x0)
/usr/local/go/src/plugin/plugin.go:32 +0x35 fp=0xc000047f18 sp=0xc000047ee0 pc=0x40b11e5
main.main()

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 15, 2019

Thanks for the report.

You answered "Does this issue reproduce with the latest release?" with "Yes", I just want to confirm, did you test it with Go 1.12.7 or a different version?

@dmitshur dmitshur changed the title load plugin crash fatal error: runtime: no plugin module data plugin: load plugin crash fatal error: runtime: no plugin module data Jul 15, 2019
@dmitshur dmitshur added this to the Go1.14 milestone Jul 15, 2019
@WebFeng
Copy link
Author

@WebFeng WebFeng commented Jul 16, 2019

did you test it with Go 1.12.7 or a different version?

I used Go 1.12.7 and 1.11, both versions can reproduce this problem.

@ztmr
Copy link

@ztmr ztmr commented Aug 21, 2019

I am having issue reproducible using this demo repository: https://gitlab.com/ztmr/goplugfail/-/jobs/276665302
Is this related? Is it a bug or just me doing bad things?

In my case, I think that the plugin loader treats the cshared lib's memory as C memory because it was loaded as SO from C. That would make sense but is also not really correct. Any thoughts?

@spellr
Copy link

@spellr spellr commented Feb 18, 2020

This still happens in go1.13.8:

fatal error: runtime: no plugin module data

goroutine 17 [running, locked to thread]:
runtime.throw(0x55df236ade9b, 0x1e)
	GOROOT/src/runtime/panic.go:774 +0x74 fp=0xc0000548e0 sp=0xc0000548b0 pc=0x55df20e5ab24
plugin.lastmoduleinit(0xc00009ac00, 0x1001, 0x1001, 0xc0000b2020, 0x55df27259e00)
	GOROOT/src/runtime/plugin.go:20 +0xb31 fp=0xc000054a00 sp=0xc0000548e0 pc=0x55df20e5bef1
plugin.open(0x7f480257e950, 0xb, 0x5e4c0a83, 0x28a2b168, 0x1c0bf56d57c1)
	GOROOT/src/plugin/plugin_dlopen.go:77 +0x517 fp=0xc000054c90 sp=0xc000054a00 pc=0x55df210d8847
plugin.Open(0x7f480257e950, 0xe, 0x55df25aaaee0, 0xf, 0x0)
	GOROOT/src/plugin/plugin.go:32 +0x37 fp=0xc000054cc8 sp=0xc000054c90 pc=0x55df210d7f57
main.LoadPlugin(0x7f480257e950, 0xe)
	cbridge.go:17 +0x125 fp=0xc000054e20 sp=0xc000054cc8 pc=0x55df210d9995
main._cgoexpwrap_181dbf39f508_LoadPlugin(0x7f480257e950, 0xe)
	_cgo_gotypes.go:51 +0x37 fp=0xc000054e40 sp=0xc000054e20 pc=0x55df210d9777
runtime.call32(0x0, 0x7f480257e840, 0x7f480257e900, 0x10)
	src/runtime/asm_amd64.s:539 +0x3d fp=0xc000054e70 sp=0xc000054e40 pc=0x55df20e8628d
runtime.cgocallbackg1(0x0)
	GOROOT/src/runtime/cgocall.go:314 +0x1bb fp=0xc000054f58 sp=0xc000054e70 pc=0x55df20e3036b
runtime.cgocallbackg(0x0)
	GOROOT/src/runtime/cgocall.go:191 +0xc7 fp=0xc000054fc0 sp=0xc000054f58 pc=0x55df20e30117
runtime.cgocallback_gofunc(0x0, 0x0, 0x0, 0x0)
	src/runtime/asm_amd64.s:793 +0x9a fp=0xc000054fe0 sp=0xc000054fc0 pc=0x55df20e8789a
runtime.goexit()
	src/runtime/asm_amd64.s:1357 +0x1 fp=0xc000054fe8 sp=0xc000054fe0 pc=0x55df20e87ff1
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Feb 18, 2020

@spellr
Copy link

@spellr spellr commented Feb 18, 2020

I just found out using -buildmode=c-shared, and executing the c++ with LD_PRELOAD=./cbridge.so bypasses the problem

@spellr
Copy link

@spellr spellr commented Feb 18, 2020

If I'm not mistaken, addmoduledata is called as part of init_array, and it initializes firstmoduledata. When go is ran through a shared-object or an archive, firstmoduledata is not initialized and therefore loading the plugins fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.