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: "unexpected fault address 0x0" with 8+ exported functions #19269

Closed
fsenart opened this issue Feb 24, 2017 · 2 comments
Closed

plugin: "unexpected fault address 0x0" with 8+ exported functions #19269

fsenart opened this issue Feb 24, 2017 · 2 comments
Milestone

Comments

@fsenart
Copy link

fsenart commented Feb 24, 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="/home/fsenart/projects"
GORACE=""
GOROOT="/home/fsenart/tools/go1.8"
GOTOOLDIR="/home/fsenart/tools/go1.8/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build519169107=/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?

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

// host.go
package main

import (
	"plugin"
)

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

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

	f.(func())()
}
// guest.go
package main

func F() {}

func F1() {}
func F2() {}
func F3() {}
func F4() {}
func F5() {}
func F6() {}
func F7() {}
run: build
	@for i in `seq 1 100`; do \
          ./host; \
          if [ $$? -eq 2 ] ; then \
	    echo -e "\n\n>>> Fails after $$i runs"; \
	    exit 1; \
	  fi \
	done

build:
	@go build -o host host.go
	@go build -buildmode=plugin -o guest.so guest.go

What did you expect to see?

I don't expect to see any error to happen.

What did you see instead?

Randomly, after a few runs, I encounter a fatal error.

unexpected fault address 0x0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0x4911e4]

goroutine 1 [running]:
runtime.throw(0x4af7bd, 0x5)
	/home/fsenart/tools/go1.8/src/runtime/panic.go:596 +0x95 fp=0xc42004deb0 sp=0xc42004de90
runtime.sigpanic()
	/home/fsenart/tools/go1.8/src/runtime/signal_unix.go:297 +0x28c fp=0xc42004df00 sp=0xc42004deb0
main.main()
	/home/fsenart/projects/src/issue/host.go:18 +0xb4 fp=0xc42004df88 sp=0xc42004df00
runtime.main()
	/home/fsenart/tools/go1.8/src/runtime/proc.go:185 +0x20a fp=0xc42004dfe0 sp=0xc42004df88
runtime.goexit()
	/home/fsenart/tools/go1.8/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc42004dfe8 sp=0xc42004dfe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/home/fsenart/tools/go1.8/src/runtime/asm_amd64.s:2197 +0x1


>>> Fails after 6 runs
Makefile:2: recipe for target 'run' failed
make: *** [run] Error 1

Observations

  • The number of exported functions in the plugin is very important.
  • If I export less than 8 functions no error happens anymore.
@ianlancetaylor ianlancetaylor changed the title plugins: "unexpected fault address 0x0" with 8+ exported functions plugin: "unexpected fault address 0x0" with 8+ exported functions Feb 24, 2017
@ianlancetaylor
Copy link
Contributor

CC @crawshaw

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/40431 mentions this issue.

lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
open modified the plugin symbols map while ranging over it. This is
normally harmless, except that the operations performed were not
idempotent leading to function pointers being corrupted.

Fixes golang#19269

Change-Id: I4b6eb1d45567161412e4a34b41f1ebf647bcc942
Reviewed-on: https://go-review.googlesource.com/40431
Run-TryBot: Todd Neal <todd@tneal.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
lion3ls added a commit to lifadev/archive_aws-lambda-go-shim that referenced this issue Aug 28, 2017
- Add unit test for Go 1.8 golang/go#19269
- Remove resolved limitation from README.md
- Refactor internal Makefile
- Rename benchs and tests folders for less verbosity

CAT: #refactor #test #docs
REF: golang/go#19269
@golang golang locked and limited conversation to collaborators Apr 12, 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

3 participants