-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: report the version of Go used to build a plugin when a mismatch occurs #63290
Comments
You can run |
I was dealing with a blackbox situation where I didn't have access to the
program loading my shared library, all I can see is that there was a
version mismatch.
…On Fri, Sep 29, 2023 at 10:48 AM cherrymui ***@***.***> wrote:
You can run go version -m handler.so and go version -m <main_executable>
to find out the versions and how they differ. Would that be helpful?
—
Reply to this email directly, view it on GitHub
<#63290 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4Z2TGR36GF4NP2QRNJJTX43UVHANCNFSM6AAAAAA5L2FRQE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I'm afraid that there are some cases where
package main
import (
"fmt"
_ "golang.org/x/xerrors"
)
var ExportedVariable int = 42
func ExportedFunction() {
fmt.Println("Hello from the plugin!")
}
package main
import (
"fmt"
"plugin"
_ "golang.org/x/xerrors"
)
func main() {
p, err := plugin.Open("plugin/myplugin.so")
if err != nil {
fmt.Println("Error opening plugin:", err)
return
}
exportedVar, err := p.Lookup("ExportedVariable")
if err != nil {
fmt.Println("Error looking up variable:", err)
return
}
varValue, ok := exportedVar.(*int)
if !ok {
fmt.Println("Error getting variable value")
return
}
fmt.Println("Exported variable:", *varValue)
exportedFunc, err := p.Lookup("ExportedFunction")
if err != nil {
fmt.Println("Error looking up function:", err)
return
}
exportedFunc.(func())()
} Build the plugin: $ cd plugin
$ go build -buildmode=plugin -mod=vendor -o myplugin.so myplugin.go Build the main program:
$ go version -m plugin/myplugin.so
plugin/myplugin.so: devel go1.22-5873bd1d7e Mon Oct 16 03:29:27 2023 +0000
path command-line-arguments
dep golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
build -buildmode=plugin
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=arm64
build GOOS=darwin
$ go version -m main
main: devel go1.22-5873bd1d7e Mon Oct 16 03:29:27 2023 +0000
path command-line-arguments
dep golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
build -buildmode=exe
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=arm64
build GOOS=darwin
The root cause might be something else: the full file path, the build flags, ... not the package version. Moreover, I'm not sure if we can tell what the different versions are. I tried to make a change here:
but what I got is something like this:
|
Hi @quantonganh, for your specific example in #63290 (comment), were you able to resolve the issue? Also, I’m not sure if this would help, but I’m curious if you tried building with -trimpath. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Y
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Then when I tried to use it with another program:
2023/09/29 02:11:29 main.go:26: plugin error: plugin.Open("/plugin/handler"): plugin was built with a different version of package google.golang.org/protobuf/internal/pragma
What did you expect to see?
It should tell me what the different version is so I can match it.
What did you see instead?
Nothing other than a not very useful message telling me that I have the wrong version, but not what the correct version should be.
The text was updated successfully, but these errors were encountered: