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

Error passing byte array back and forth to plugin function #26436

Closed
suoigwg opened this issue Jul 18, 2018 · 8 comments
Closed

Error passing byte array back and forth to plugin function #26436

suoigwg opened this issue Jul 18, 2018 · 8 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@suoigwg
Copy link

suoigwg commented Jul 18, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/yishengyang/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/yishengyang//go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vh/6m51srdn3ps28tc64qy1343h0000gp/T/go-build869355597=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
	"log"
)

type dummy struct {}


func (d dummy)GenByte() []byte  {
	log.Println("From plugin GenByte")
	data:=[]byte{1,2,3,4,5}
	return data
}

func (d dummy)PrintByte(data []byte)  {
	log.Println("From plugin PrintByte")
	log.Println(data)
}

var Endpoint dummy


func main() {
	
}
package main

import (
	"plugin"
	"log"
)

type T interface {
	GenByte() []byte
	PrintByte(data []byte)
}

func main()  {
	plgin, err := plugin.Open("./plugin.so")
	if err != nil {
		panic(err)
	}
	symbol, err:= plgin.Lookup("Endpoint")
	if err != nil {
		panic(err)
	}
	b, ok := symbol.(T)
	if !ok{
		panic("Type assertion fail")
	}
	log.Println("From main")
	for{
		data := b.GenByte()
		b.PrintByte(data)
	}


}

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

build the second code segment with buildmode =plugin and load it in the first segment

What did you expect to see?

no error

What did you see instead?

2018/07/18 16:47:51 From plugin GenByte
2018/07/18 16:47:51 From plugin PrintByte
2018/07/18 16:47:51 [1 2 3 4 5]
.......
After a couple of iterations
runtime: bad pointer in frame plugin/unnamed-8b1a52c90a93f94ad1c14cee47dc41ef6a9bc487.dummy.PrintByte at 0xc420055eb0: 0x5
fatal error: invalid pointer found on stack

I don't know it is go or it is me. Basically I need to pass a byte array to a plugin function. How can I achieve this?

@mvdan
Copy link
Member

mvdan commented Jul 18, 2018

Your program is not checking errors. Have you tried fixing that first?

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 18, 2018
@suoigwg suoigwg changed the title Error passing byte array to plugin function Error passing byte array back and forth to plugin function Jul 18, 2018
@suoigwg
Copy link
Author

suoigwg commented Jul 18, 2018

Sorry I've updated my question

@mvdan
Copy link
Member

mvdan commented Jul 18, 2018

Your program is still not checking for errors correctly. All the plugin funcs return errors.

@suoigwg
Copy link
Author

suoigwg commented Jul 18, 2018

Sorry I've updated my question again.
Some people on stackoverflow reported ok running on linux, it could be OSX specific

@mvdan mvdan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 18, 2018
@mvdan mvdan added this to the Go1.12 milestone Jul 18, 2018
@icza
Copy link

icza commented Jul 18, 2018

For reference, the above plugin and app runs fine on Linux amd64. This issue seems to be macOS related.

@mvdan
Copy link
Member

mvdan commented Jul 18, 2018

Thanks for the updates. CC @ianlancetaylor @cherrymui as per dev.golang.org/owners.

@cherrymui
Copy link
Member

cherrymui commented Jul 18, 2018

Have you tried Go 1.11 beta? I think this should be fixed with Go 1.11 beta, probably by https://go-review.googlesource.com/c/go/+/104715.

I can reproduce it with Go 1.10 but not Go tip on Mac, so I think it is fixed now.

@agnivade agnivade added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 18, 2018
@suoigwg
Copy link
Author

suoigwg commented Jul 19, 2018

I tried go 1.11 beta and it's fine. Also ok on Ubuntu 18.04

@suoigwg suoigwg closed this as completed Jul 19, 2018
@golang golang locked and limited conversation to collaborators Jul 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

7 participants