Navigation Menu

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: linker error when one plugin tries to open another plugin #22175

Closed
nzlov opened this issue Oct 8, 2017 · 15 comments
Closed

plugin: linker error when one plugin tries to open another plugin #22175

nzlov opened this issue Oct 8, 2017 · 15 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@nzlov
Copy link

nzlov commented Oct 8, 2017

There is a problem that has been closed, but did not reply after asking.
#20312

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

go version go1.9.1 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=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/workspace/go"
GORACE=""
GOROOT="/home/nzlov/program/go"
GOTOOLDIR="/home/nzlov/program/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build294433604=/tmp/go-build -gno-record-gcc-switches"
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"

What did you do?

DEMO

make

What did you expect to see?

9

What did you see instead?

runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"
@davecheney
Copy link
Contributor

This is working as intended. You need to include a main.main function in every plugin even if it is never called.

@nzlov
Copy link
Author

nzlov commented Oct 8, 2017

@davecheney I have added main.main, but still being given. Have you tested my demo?

@davecheney
Copy link
Contributor

The error is on this line

https://github.com/nzlov/testplugin/blob/master/Makefile#L4

Because you are not including main.go

Unlike many projects on GitHub, the Go project does not use its bug tracker for general discussion or asking questions. We only use our bug tracker for tracking bugs and tracking proposals going through the Proposal Process.

Please see https://golang.org/wiki/Questions for good places to ask questions.

@nzlov
Copy link
Author

nzlov commented Oct 8, 2017

@davecheney Sorry.
Why include main.go?

 main.go  -> plugin.so(plugin.go) -> models.so(models.go)

I think is a bug,when plugin open other plugin.

@davecheney
Copy link
Contributor

I'm sorry, that's just the way plugins work in Go, each plugin must have a main.main function. This is not used by the plugin, but is needed by the linker.

@nzlov
Copy link
Author

nzlov commented Oct 8, 2017

@davecheney I'm sure I've added main.main.Can you make a demo ? Please.

@davecheney
Copy link
Contributor

Please see https://golang.org/wiki/Questions for good places to ask questions.

I recommend asking on golang-nuts.

@nzlov
Copy link
Author

nzlov commented Oct 8, 2017

@davecheney Sorry.
Please look demo.I have added func main(){},but still has error.

runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"

I think is a bug...

@ianlancetaylor ianlancetaylor changed the title plugin: runtime.main_main·f: undefined: "main.main"(buildmode=plugin) plugin: linker error when one plugin tries to open another plugin Oct 9, 2017
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 9, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 9, 2017
@ianlancetaylor
Copy link
Contributor

Sorry for the confusion. This is a bug when a plugin calls plugin.Open. Simple test case:

package main

import "plugin"

func F() {
	plugin.Open("x.so")
}

func main() {}

Compiling this with go build -buildmode=plugin produces

# command-line-arguments
runtime.main_main·f: relocation target main.main not defined
runtime.main_main·f: undefined: "main.main"

Removing the call to plugin.Open permits it to build, even if "plugin" is still imported.

@ianlancetaylor ianlancetaylor reopened this Oct 9, 2017
@crawshaw
Copy link
Member

crawshaw commented Oct 9, 2017

Oops, sorry for missing this @nzlov. I'll look into it.

It does not appear to be related to the special handling for plugin.Open in the linker. Instead, the fact that plugin.Open calls runtime.plugin_lastmoduleinit brings extra symbols into the plugin that cause the confusion. Stubbing out the implementation of plugin_lastmoduleinit lets the program build.

@gopherbot
Copy link

Change https://golang.org/cl/69250 mentions this issue: cmd/link: dynamically import main.main in plugins

@gopherbot
Copy link

Change https://golang.org/cl/69370 mentions this issue: cmd/link, runtime: put hasmain bit in moduledata

@nzlov
Copy link
Author

nzlov commented Oct 10, 2017

@crawshaw @ianlancetaylor Thank you for your help.

@d1vyank
Copy link

d1vyank commented Oct 19, 2017

Are there any known workarounds for this until Go 1.10 is released?

@basantashah
Copy link

you dont have a main file in package main, if you could add a main function your issue will be solved

@golang golang locked and limited conversation to collaborators Sep 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

7 participants