aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/plugin.go
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2017-09-02 12:05:35 -0400
committerDavid Crawshaw <crawshaw@golang.org>2017-09-09 16:26:33 +0000
commitd8ae2156fe08f31f9b20a79b6971638c5bf203b5 (patch)
tree3619d960bfd11ddf4ea45fc60f6c30048f8bab55 /src/runtime/plugin.go
parent4e2ef7f7f9a3351c3774148c40fe0d7f12403da5 (diff)
downloadgo-d8ae2156fe08f31f9b20a79b6971638c5bf203b5.tar.xz
runtime, plugin: error not throw on duplicate open
Along the way, track bad modules. Make sure they don't end up on the active modules list, and aren't accidentally reprocessed as new plugins. Fixes #19004 Change-Id: I8a5e7bb11f572f7b657a97d521a7f84822a35c07 Reviewed-on: https://go-review.googlesource.com/61171 Run-TryBot: David Crawshaw <crawshaw@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/plugin.go')
-rw-r--r--src/runtime/plugin.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/runtime/plugin.go b/src/runtime/plugin.go
index caecba67f8..5e05be71ec 100644
--- a/src/runtime/plugin.go
+++ b/src/runtime/plugin.go
@@ -7,22 +7,29 @@ package runtime
import "unsafe"
//go:linkname plugin_lastmoduleinit plugin.lastmoduleinit
-func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatchpkg string) {
- md := firstmoduledata.next
+func plugin_lastmoduleinit() (path string, syms map[string]interface{}, errstr string) {
+ var md *moduledata
+ for pmd := firstmoduledata.next; pmd != nil; pmd = pmd.next {
+ if pmd.bad {
+ md = nil // we only want the last module
+ continue
+ }
+ md = pmd
+ }
if md == nil {
throw("runtime: no plugin module data")
}
- for md.next != nil {
- md = md.next
+ if md.pluginpath == "" {
+ throw("runtime: plugin has empty pluginpath")
}
if md.typemap != nil {
- throw("runtime: plugin already initialized")
+ return "", nil, "plugin already loaded"
}
for _, pmd := range activeModules() {
if pmd.pluginpath == md.pluginpath {
- println("plugin: plugin", md.pluginpath, "already loaded")
- throw("plugin: plugin already loaded")
+ md.bad = true
+ return "", nil, "plugin already loaded"
}
if inRange(pmd.text, pmd.etext, md.text, md.etext) ||
@@ -43,7 +50,8 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatch
}
for _, pkghash := range md.pkghashes {
if pkghash.linktimehash != *pkghash.runtimehash {
- return "", nil, pkghash.modulename
+ md.bad = true
+ return "", nil, "plugin was built with a different version of package " + pkghash.modulename
}
}