-
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: can't open the same plugin with different names, like dlopen #29525
Comments
I presume it's because of this bit of doc:
If you could load the same plugin twice with different paths, you'd effectively run the same init function twice. That seems to go against how plugins should be used, but the documentation isn't terribly clear about this edge case. /cc @ianlancetaylor @cherrymui as per https://dev.golang.org/owners/ |
Thank you @mvdan , I am a newcomer to golang. I am evaluating whether golang is suitable for current arm embedded projects. Is plugin not implemented for linux/arm yet? |
@Jexbat Plugin is supported on Linux/ARM. |
@cherrymui
I found same issue #19569, then I enable cgo like
Compile is succuss but when I exec it return
Could it be cross-compile toolchain problem? |
I assume you are copying the executable built with |
@ianlancetaylor sovled with
package main
import (
"fmt"
"os"
"plugin"
)
type Greeter interface {
Greet()
}
func main() {
plug, err := plugin.Open("./plugins/scanner.so")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
symGreeter, err := plug.Lookup("Greeter")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var greeter Greeter
greeter, ok := symGreeter.(Greeter)
if !ok {
fmt.Println("unexpected type from module symbol")
os.Exit(1)
}
greeter.Greet()
print("=======\n")
plug2, err := plugin.Open("./plugins/scanner2.so")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
symGreeter2, err := plug2.Lookup("Greeter")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var greeter2 Greeter
greeter2, ok2 := symGreeter2.(Greeter)
if !ok2 {
fmt.Println("unexpected type from module symbol")
os.Exit(1)
}
greeter2.Greet()
}
package main
import "fmt"
type greeting string
var count int
func (g greeting) Greet() {
count++
fmt.Printf("Hello Universe %d\n", count)
}
// exported as symbol named "Greeter"
var Greeter greeting
result is:
Does it should be |
I found change file name can solve this situation.Change
I think |
Hello, No errors, however when a main app on a raspberrypi tries to open the plugin, it says: is this the case? or did I miss something? somewhat of a showstopper... |
@witwit: That should work. One thing you might be hitting - your main app also needs to be compiled with CGO_ENABLED=1. |
@witwit this doesn't seem to be related to this issue, so I recommend discussing this somewhere else. For your problem, how do you build the program that opens the plugin? In particular, is it built with cgo enabled? |
Oh, thank you, that got me a bit further. CGO_ENABLED=1 was missing for the main app, d'oh!
|
yes, sorry. I truggle to find any infos on this at all. I will post a question on stack overflow. |
nm plugin/hello.so| grep '.V' Is there something wrong with compiling the symbol table? |
Ok, as this is a duplicate, do we have some work arounds for more modern go versions that would allow us to:
I particularly mention this as buildvcs is a recent addition, and there's Is there any approach considered in resolving this in the toolchain? Would we need a proposal to discuss a change, submit patches, or how can we move this forward? |
@ianlancetaylor @cherrymui as cmd/link and plugins package owners, I would appreciate your input and perhaps guidance towards contributing a patch, priorities permitting. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Same plugin copyed to different names can plugin.Open successfully and have different instances.
For example, I have a lot of scanners connect to my device and the number of scanners is uncertain,
the scanners have same protocol but the serial port is different, so I need to load the same scanner plugin and pass different serial port to the plugin to scan,so it is not suitable to complie different plugin by 'pluginpath', if I need 100 scanners I need to complie 100 times. Why can't just like
dlopen
distinguish by names?What did you see instead?
The text was updated successfully, but these errors were encountered: