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

cmd/go: -buildmode=plugin generated Go archive, not ELF shared object #22656

Closed
kidinamoto01 opened this issue Nov 10, 2017 · 3 comments
Closed

Comments

@kidinamoto01
Copy link

kidinamoto01 commented Nov 10, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9 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="/home/suyu/go"
GORACE=""
GOROOT="/home/suyu/.gvm/gos/go1.9"
GOTOOLDIR="/home/suyu/.gvm/gos/go1.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build725236087=/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?

go get -u github.com/whyrusleeping/gx
go get -u github.com/whyrusleeping/gx-go

gx-go rw
gx install --global

go build -buildmode=plugin -o=ethereum.so
mv ethereum.so ~/.ipfs/plugins/
chmod +x ~/.ipfs/plugins/ethereum.so
ipfs daemon

What did you expect to see?

ipfs should be started.

What did you see instead?

error message

Error: loading plugin /home/suyu/ipfs/data/plugins/ethereum.so: plugin.Open: /home/ipfs//plugins/ethereum.so: invalid ELF header

readelf -h ethereum.so

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

File: ethereum.so(go.o )
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
@ianlancetaylor ianlancetaylor changed the title invalid ELF header in build output cmd/go: -buildmode=plugin generated Go archive, not ELF shared object Nov 10, 2017
@ianlancetaylor
Copy link
Member

I don't see how this is possible. Are you absolutely certain that you are looking at the same ethereum.so file in both cases? Can you show us the output of go build -buildmode=plugin -x -o=ethereum.so?

@ALTree
Copy link
Member

ALTree commented Nov 10, 2017

Take this file:

$ cat test.go 
package p

import "fmt"

func main() {
	fmt.Println("hi")
}

If you run go build -buildmode=plugin, gc complains:

$ go build -buildmode=plugin
-buildmode=plugin requires exactly one main package

but if you use -o, it doesn't:

$ go build -buildmode=plugin -o test.so

A test.so is generated, but it's an archive!

$ file test.so 
test.so: current ar archive

so readelf fails on it:

$ readelf -h test.so 

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

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

Is this what is happening?

@ianlancetaylor
Copy link
Member

@ALTree Thanks for figuring that out. I bet that it is it. I'm going to close this as a dup of #19023, which will be fixed in the 1.10 release.

@golang golang locked and limited conversation to collaborators Nov 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants