From 9da7058466c8c9f32e1481f28d57732832ee3b30 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Sun, 30 Oct 2016 15:31:21 -0400 Subject: cmd/link, plugin: use full plugin path for symbols Plumb the import path of a plugin package through to the linker, and use it as the prefix on the exported symbol names. Before this we used the basename of the plugin file as the prefix, which could conflict and result in multiple loaded plugins sharing symbols that are distinct. Fixes #17155 Fixes #17579 Change-Id: I7ce966ca82d04e8507c0bcb8ea4ad946809b1ef5 Reviewed-on: https://go-review.googlesource.com/32355 Reviewed-by: Ian Lance Taylor --- src/plugin/plugin_dlopen.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/plugin/plugin_dlopen.go') diff --git a/src/plugin/plugin_dlopen.go b/src/plugin/plugin_dlopen.go index e881b258e0..4a3eb3d861 100644 --- a/src/plugin/plugin_dlopen.go +++ b/src/plugin/plugin_dlopen.go @@ -49,10 +49,10 @@ func open(name string) (*Plugin, error) { } C.free(unsafe.Pointer(cRelName)) - path := C.GoString(cPath) + filepath := C.GoString(cPath) pluginsMu.Lock() - if p := plugins[path]; p != nil { + if p := plugins[filepath]; p != nil { pluginsMu.Unlock() <-p.loaded return p, nil @@ -65,26 +65,25 @@ func open(name string) (*Plugin, error) { } // TODO(crawshaw): look for plugin note, confirm it is a Go plugin // and it was built with the correct toolchain. - // TODO(crawshaw): get full plugin name from note. if len(name) > 3 && name[len(name)-3:] == ".so" { name = name[:len(name)-3] } - syms := lastmoduleinit() + pluginpath, syms := lastmoduleinit() if plugins == nil { plugins = make(map[string]*Plugin) } // This function can be called from the init function of a plugin. // Drop a placeholder in the map so subsequent opens can wait on it. p := &Plugin{ - name: name, - loaded: make(chan struct{}), - syms: syms, + pluginpath: pluginpath, + loaded: make(chan struct{}), + syms: syms, } - plugins[path] = p + plugins[filepath] = p pluginsMu.Unlock() - initStr := C.CString(name + ".init") + initStr := C.CString(pluginpath + ".init") initFuncPC := C.pluginLookup(h, initStr, &cErr) C.free(unsafe.Pointer(initStr)) if initFuncPC != nil { @@ -101,7 +100,7 @@ func open(name string) (*Plugin, error) { symName = symName[1:] } - cname := C.CString(name + "." + symName) + cname := C.CString(pluginpath + "." + symName) p := C.pluginLookup(h, cname, &cErr) C.free(unsafe.Pointer(cname)) if p == nil { @@ -123,7 +122,7 @@ func lookup(p *Plugin, symName string) (Symbol, error) { if s := p.syms[symName]; s != nil { return s, nil } - return nil, errors.New("plugin: symbol " + symName + " not found in plugin " + p.name) + return nil, errors.New("plugin: symbol " + symName + " not found in plugin " + p.pluginpath) } var ( @@ -131,4 +130,5 @@ var ( plugins map[string]*Plugin ) -func lastmoduleinit() map[string]interface{} // in package runtime +// lastmoduleinit is defined in package runtime +func lastmoduleinit() (pluginpath string, syms map[string]interface{}) -- cgit v1.3