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: panic calling function returned by plugin function on Darwin #17946

Closed
urso opened this issue Nov 16, 2016 · 2 comments
Closed

plugin: panic calling function returned by plugin function on Darwin #17946

urso opened this issue Nov 16, 2016 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@urso
Copy link

urso commented Nov 16, 2016

Please answer these questions before submitting your issue. Thanks!

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

darwin:
go version devel +d338f2e Wed Nov 16 05:51:18 2016 +0000 darwin/amd64

linux (debian 8, same commit ID as darwin):
go version master linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/urso/.gvm/pkgsets/master/global"
GORACE=""
GOROOT="/Users/urso/.gvm/gos/master"
GOTOOLDIR="/Users/urso/.gvm/gos/master/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2s/38f_b6sj0mn6_14km12vyq0r0000gn/T/go-build044211422=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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?

Playing with plugin support in master, I found function calls to functions stored in structs/interfaces and returned by functions within the plugin to create a panic on darwin.

Example plugin loader:

package main

import (
	"errors"
	"fmt"
	"os"
	"plugin"
)

type testPlugin interface {
	Call()
}

func main() {
	for _, arg := range os.Args[1:] {
		p, err := load(arg)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}

		p.Call()
	}
}

func load(path string) (testPlugin, error) {
	p, err := plugin.Open(path)
	if err != nil {
		return nil, err
	}

	sym, err := p.Lookup("Load")
	if err != nil {
		return nil, err
	}

	loader, ok := sym.(func() interface{})
	if !ok {
		return nil, errors.New("plugin Load-interface mismatch")
	}

	inst, ok := loader().(testPlugin)
	if !ok {
		return nil, errors.New("plugin does not implement testPlugin interface")
	}

	return inst, nil
}

Example plugin.go:

package main

import "fmt"

type plugin func()

func (p plugin) Call() { p() }

func Load() interface{} {
	return plugin(func() {
		fmt.Println("call")
	})
}

What did you expect to see?

$ ./loader plugin.so
call

Works on linux (debian 8).

What did you see instead?

panic in call to function being wrapped:

$ ./loader plugin.so
unexpected fault address 0xb01dfacedebac1e
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x45d9677]

goroutine 1 [running]:
runtime.throw(0x40ccf18, 0x5)
	/Users/urso/.gvm/gos/master/src/runtime/panic.go:596 +0x95 fp=0xc420053ea8 sp=0xc420053e88
runtime.sigpanic()
	/Users/urso/.gvm/gos/master/src/runtime/signal_unix.go:276 +0x28c fp=0xc420053ef8 sp=0xc420053ea8
plugintest/plugin.plugin.Call(0x45d96b0)
	/Users/urso/.gvm/pkgsets/master/global/src/plugintest/plugin/plugin.go:7 +0x17 fp=0xc420053f00 sp=0xc420053ef8
main.main()
	/Users/urso/.gvm/pkgsets/master/global/src/plugintest/loader.go:22 +0x126 fp=0xc420053f88 sp=0xc420053f00
runtime.main()
	/Users/urso/.gvm/gos/master/src/runtime/proc.go:185 +0x20a fp=0xc420053fe0 sp=0xc420053f88
runtime.goexit()
	/Users/urso/.gvm/gos/master/src/runtime/asm_amd64.s:2184 +0x1 fp=0xc420053fe8 sp=0xc420053fe0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/Users/urso/.gvm/gos/master/src/runtime/asm_amd64.s:2184 +0x1
@quentinmit quentinmit changed the title Panic calling function returned by plugin function plugin: panic calling function returned by plugin function Nov 16, 2016
@ianlancetaylor ianlancetaylor changed the title plugin: panic calling function returned by plugin function plugin: panic calling function returned by plugin function on Darwin Nov 16, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 16, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Nov 16, 2016
@quentinmit quentinmit modified the milestones: Go1.8Maybe, Go1.8 Nov 16, 2016
@crawshaw
Copy link
Member

This is probably a duplicate of #17828. Please sync to after 7ee7936 and let me know if the problem persists.

@urso
Copy link
Author

urso commented Nov 16, 2016

It is fixed. Thanks!

@golang golang locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants