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: Open : invalid ELF header with non-main package #19882

Closed
wiless opened this issue Apr 7, 2017 · 7 comments
Closed

plugin: Open : invalid ELF header with non-main package #19882

wiless opened this issue Apr 7, 2017 · 7 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@wiless
Copy link

wiless commented Apr 7, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build619068367=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

package plugme

import "fmt"

func Run() {
	fmt.Print("Hello, I am running..")
}

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/nLF1o0CejJ

Seems that when we call the plugin.Open() it expects that the functions are defined with the same main package. Usually, when the built abcd.so plugin is built and shipped we may not know the package name.

What did you expect to see?

Hello, I am running..

What did you see instead?

panic: plugin.Open: /root/go/src/github.com/wiless/plugin.so: invalid ELF header

goroutine 1 [running]:
main.main()
	/root/go/src/github.com/wiless/main.go:10 +0x1e6
@ianlancetaylor
Copy link
Contributor

How precisely did you build the plugin?

@ianlancetaylor ianlancetaylor changed the title plugin Open : invalid ELF header with non-main package plugin: Open : invalid ELF header with non-main package Apr 7, 2017
@wiless
Copy link
Author

wiless commented Apr 7, 2017

go build -buildmode=plugin -o plugin.so

@ianlancetaylor
Copy link
Contributor

What is the output of readelf -h /root/go/src/github.com/wiless/plugin.so?

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 8, 2017
@wiless
Copy link
Author

wiless commented Apr 8, 2017


File: plugin.so(__.PKGDEF       )
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start

File: plugin.so(_go_.o          )
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start

@ianlancetaylor
Copy link
Contributor

That is what I would expect for a file built without -buildmode=plugin.

Oh, I see what you mean. If you use -buildmode=plugin but you don't build a main package, you get an object that can go into a plugin, but you don't get an actual plugin. That is a meaningful thing to do, but can be confusing. Hmmm.

@ianlancetaylor ianlancetaylor added this to the Go1.9Maybe milestone Apr 8, 2017
@ianlancetaylor
Copy link
Contributor

CC @crawshaw

@tzneal
Copy link
Member

tzneal commented Apr 21, 2017

Duplicate of #19023, which is the older issue.

@tzneal tzneal closed this as completed Apr 21, 2017
@golang golang locked and limited conversation to collaborators Apr 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants