Skip to content

plugin: can't open the same plugin with different names, like dlopen #29525

@JesseGuoX

Description

@JesseGuoX

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

$ go version
go version go1.11.4 linux/386

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GOARCH="386"
GOBIN=""
GOCACHE="/home/pw/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/pw/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="sse2"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/pw/Documents/hello/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build808633565=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go build -buildmode=plugin -o scanner.so scanner.go
cp scanner.so scanner2.so
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)
	}

	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)
    }

    // 4. use the module
    greeter.Greet()
    greeter2.Greet()

}

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?

plugin.Open("./plugins/scanner2.so"): plugin already loaded

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions