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: incorrect symbol lookup #20376

Closed
patrobinson opened this issue May 16, 2017 · 2 comments
Closed

plugin: incorrect symbol lookup #20376

patrobinson opened this issue May 16, 2017 · 2 comments
Milestone

Comments

@patrobinson
Copy link

patrobinson commented May 16, 2017

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

go version go1.8.1 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build326475474=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

main.go

    package main

    import "plugin"
    import "fmt"

    func main() {
    	aPlug, _ := plugin.Open("a.so")
    	aSymPlug, _ := aPlug.Lookup("Rule")
    	fmt.Printf("Plugin: %v loaded\n", aSymPlug)
    
    	bPlug, _ := plugin.Open("b.so")
    	bSymPlug, _ := bPlug.Lookup("Rule")
    	fmt.Printf("Plugin: %v loaded\n", bSymPlug)
    }

a.go plugin

    package main
    
    type plugin string
    
    func init() {
    	Rule = "a"
    }
    
    func (p plugin) String() string {
    	return "a"
    }
    
    var Rule plugin

b.go plugin

    package main
    
    type plugin string
    
    func init() {
    	Rule = "b"
    }
    
    func (p plugin) String() string {
            return "b"
    }
    
    var Rule plugin

What did you expect to see?

Output:

    Plugin: a loaded
    Plugin: b loaded

What did you see instead?

Output:

    Plugin: a loaded
    Plugin: a loaded

Note if I change the return value for String() method to string(p) then everything works as expected.

@odeke-em odeke-em changed the title Plugin: incorrect symbol lookup plugin: incorrect symbol lookup May 16, 2017
@odeke-em
Copy link
Member

/cc @crawshaw

@bradfitz bradfitz added this to the Go1.10 milestone May 16, 2017
patrobinson pushed a commit to patrobinson/go-fish that referenced this issue Jun 28, 2017
@crawshaw
Copy link
Member

crawshaw commented Sep 1, 2017

This is a variant of #21386, and I believe is fixed by https://golang.org/cl/60910 (605331f).

@crawshaw crawshaw closed this as completed Sep 1, 2017
@golang golang locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants