-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
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.