I did not understand the use of plugin. I can't use a plugin with different go versions even with minor version because plugin.open is failed. The only way which I found to use plugin'functions is through LD_PRELOAD.
I created a plugin using https://github.com/vladimirvivien/go-plugin-example
go build -buildmode=plugin -o eng/eng.so eng/greeter.go
Created a go binary using command:
go build -linkshared test.go
Load plugin with test binary:
export LD_PRELOAD=./eng.so; ./test
plugin addresses will be loaded into firstmoduledata structure of go runtime.
Created another go binary (which I want to use) using command:
go build test2.go
load plugin with test binary:
export LD_PRELOAD=./eng.so; ./test2
in this case, plugin addresses are not loaded into firstmoduledata. This is because addmoduledata() is not called.
I did not understand why addresses are not loaded in this case while if i load plugin using plugin.open then addresses are loaded for same go binary test2
Please suggest how to load plugin addresses into go runtime for this case. Can't I call addmoduledata in this case?
go versions 1.15,1.16,1.17
os - ubuntu 16
I did not understand the use of plugin. I can't use a plugin with different go versions even with minor version because plugin.open is failed.
Hi Brian,greeter.go calls plugin.open and it will be work only for one sub version of go. If plugin and binary are made in different sub versions of go1.15 then plugin.open will not work.
On Monday, November 1, 2021 at 6:55:02 PM UTC+5:30 Brian Candler wrote:> My question was how to load plugin address in go runtime using LD_PRELOAD. I am using LD_PRELOAD because plug.open is failed. Is there any other solution?
When I tried it, I didn't need to set any environment variables (and certainly no LD_XXX variables). Follow this tutorial:It works fine for me:ubuntu@builder:~/go-plugin-example$ cat /etc/lsb-releaseDISTRIB_ID=UbuntuDISTRIB_RELEASE=18.04DISTRIB_CODENAME=bionicDISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
ubuntu@builder:~/go-plugin-example$ lsLICENSE README.md chi eng greeter.go sweubuntu@builder:~/go-plugin-example$ go versiongo version go1.16.6 linux/amd64ubuntu@builder:~/go-plugin-example$ go build -buildmode=plugin -o eng/eng.so eng/greeter.goubuntu@builder:~/go-plugin-example$ go run greeter.go englishHello Universe
ubuntu@builder:~/go-plugin-example$If you're still using Ubuntu 16, note that it went obsolete nearly a year ago (unless you're paying for extended maintenance).
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/42e3d250-cb69-43b6-a297-7a56fcbe688en%40googlegroups.com.
greeter.go calls plugin.open and it will be work only for one sub version of go. If plugin and binary are made in different sub versions of go1.15 then plugin.open will not work.
The plugin compiler version must exactly match the program's compiler version. If the program was compiled with 1.11.4, it won't work to compile the plugin with 1.11.5. When distributing a program binary, you must communicate what the compiler version you used is.
Any packages outside of the standard library that are used by both the plugin and the program must have their versions match exactly. This means that when distributing a program binary, you must communicate the exact versions of all dependencies