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: go build plugin with -pluginpath case symbol not found #57301

Closed
exfly opened this issue Dec 14, 2022 · 3 comments
Closed

plugin: go build plugin with -pluginpath case symbol not found #57301

exfly opened this issue Dec 14, 2022 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@exfly
Copy link

exfly commented Dec 14, 2022

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

$ go version
go version go1.19.3 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/xxx/go/gobin/"
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/path/to/go/1.19.3/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/path/to/go/1.19.3"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/path/to/.goenv/versions/1.19.3"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/path/to/1.19.3/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/path/to/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xq/_f5bvf216r55vjw5g5mdwvlm0000gn/T/go-build2366786974=/tmp/go-build -gno-record-gcc-switches -fno-common"

$ go env

What did you do?

# plugin code in plugin/hello.go
package main

import "fmt"

var V int

func F() { fmt.Printf("Hello, number %d\n", V) }


# main in main.go
package main

import "plugin"

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

	v, err := p.Lookup("V")
	if err != nil {
		panic(err)
	}
	f, err := p.Lookup("F")
	if err != nil {
		panic(err)
	}
	*v.(*int) = 7
	f.(func())() // prints "Hello, number 7"

	p, err = plugin.Open("plugin/hello2.so")
	if err != nil {
		panic(err)
	}
	v, err = p.Lookup("V")
	if err != nil {
		panic(err)
	}
	f, err = p.Lookup("F")
	if err != nil {
		panic(err)
	}
	_ = v
	// *v.(*int) = 7
	f.(func())() // prints "Hello, number 7"
}
go build -trimpath -ldflags "-pluginpath=plugin/hot-$(date +%s)" -buildmode=plugin -o plugin/hello.so plugin/hello.go
go build -trimpath -ldflags "-pluginpath=plugin/hot-$(date +%s)" -buildmode=plugin -o plugin/hello2.so plugin/hello.go

go run -trimpath main.go

What did you expect to see?

Hello, number 7
Hello, number 7

What did you see instead?

panic: plugin.Open("plugin/hello"): could not find symbol V: dlsym(0x100205980, plugin/hot-1670990324.V): symbol not found

goroutine 1 [running]:
main.main()
        ./main.go:8 +0x4ae
exit status 2
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 14, 2022
@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 14, 2022
@thanm
Copy link
Contributor

thanm commented Dec 14, 2022

@golang/runtime per owners

@seankhliao
Copy link
Member

note loading the same plugin twice might not work: #47298

@prattmic
Copy link
Member

It looks like this is a duplicate of #47298, except that -pluginpath is set to make the plugins slightly different from one another. I don't think that is sufficient to make the plugins usable together. IIUC, the plugins should at least be different packages.

@prattmic prattmic closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2022
@golang golang locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants