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: can't load same plugin using 2 different names #47298

Open
Wwwwwxh opened this issue Jul 20, 2021 · 4 comments
Open

plugin: can't load same plugin using 2 different names #47298

Wwwwwxh opened this issue Jul 20, 2021 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Wwwwwxh
Copy link

Wwwwwxh commented Jul 20, 2021

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

$ go version
go version go1.15.3 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/wangxuhui/Library/Caches/go-build"
GOENV="/Users/wangxuhui/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/wangxuhui/go/pkg/mod"
GONOPROXY="github.com/bangwork/*"
GONOSUMDB="github.com/bangwork/*"
GOOS="darwin"
GOPATH="/Users/wangxuhui/go/"
GOPRIVATE="github.com/bangwork/*"
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/q3/xc_0rmp5295bh2nmnmnq3gkc0000gn/T/go-build785620014=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

p.so
package main

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

Main program
package main

import (
	"plugin"
)

func main() {
	p, err := plugin.Open("./p1.so")
	if err != nil {
		panic(err)
	}
	p, err = plugin.Open("./p2.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"
}

go build -buildmode=plugin -o=../p1.so
go build -buildmode=plugin -o=../p2.so

What did you expect to see?

Both plugins can be loaded

What did you see instead?

panic: plugin.Open("./p2"): plugin already loaded

@randall77
Copy link
Contributor

I'm not sure why the plugin package is giving that error. I guess the question is: are they the same plugin, or not? It matters because we need to know whether to run the init function once, or twice, and (for plugins more complicated than this one) decide whether types declared in each plugin are identical or not. In this case it's not clear which choice should be made.

(The plugin package treats identity using filenames, so it thinks they are different plugins. But the runtime uses a content hash, by which the two plugins look identical.)

If you build the plugins as separate packages (i.e. don't list .go files on the command line, instead put them in separate directories and build the plugin using all the source in each directory), it shouldn't conflict.

@crawshaw

@randall77 randall77 added this to the Go1.18 milestone Jul 20, 2021
@Wwwwwxh
Copy link
Author

Wwwwwxh commented Jul 20, 2021

@randall77 They are the same plugin,I used the same file to build two so files The main program loads the two so files

@randall77
Copy link
Contributor

Right, but I guess my question is more philosophical. If you load p1.so into p1 and p2.so into p2, then lookup V in each, what should this print: println(v1.(*int) == v2.(*int))? In other words, should those be the same Vs, or different Vs? My guess is it should print false, as you're loading different files, even if their contents are the same.
But what if p2.so is just a symlink to p1.so? Is that still "two different files"?
We do require that if you load p1.so twice, then it should print true.

@seankhliao seankhliao changed the title plugin already loaded (previous failure) plugin: can't load same plugin using 2 different names Jul 20, 2021
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 20, 2021
@edwingeng
Copy link

https://github.com/edwingeng/hotswap can handle this problem perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Triage Backlog
Development

No branches or pull requests

6 participants