From 03da2690c9fefdbaff613f9ccc224b5f0abfbe16 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Sat, 12 Nov 2016 06:24:36 -0500 Subject: cmd/link, runtime, plugin: versioning In plugins and every program that opens a plugin, include a hash of every imported package. There are two versions of each hash: one local and one exported. As the program starts and plugins are loaded, the first exported symbol for each package becomes the canonical version. Any subsequent plugin's local package hash symbol has to match the canonical version. Fixes #17832 Change-Id: I4e62c8e1729d322e14b1673bada40fa7a74ea8bc Reviewed-on: https://go-review.googlesource.com/33161 Reviewed-by: Ian Lance Taylor --- src/runtime/plugin.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/runtime/plugin.go') diff --git a/src/runtime/plugin.go b/src/runtime/plugin.go index 7907936e14..845bf76e92 100644 --- a/src/runtime/plugin.go +++ b/src/runtime/plugin.go @@ -7,7 +7,7 @@ package runtime import "unsafe" //go:linkname plugin_lastmoduleinit plugin.lastmoduleinit -func plugin_lastmoduleinit() (path string, syms map[string]interface{}) { +func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatchpkg string) { md := firstmoduledata.next if md == nil { throw("runtime: no plugin module data") @@ -41,6 +41,11 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}) { throw("plugin: new module data overlaps with previous moduledata") } } + for _, pkghash := range md.pkghashes { + if pkghash.linktimehash != *pkghash.runtimehash { + return "", nil, pkghash.modulename + } + } // Initialize the freshly loaded module. modulesinit() @@ -74,7 +79,7 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}) { } syms[name] = val } - return md.pluginpath, syms + return md.pluginpath, syms, "" } // inRange reports whether v0 or v1 are in the range [r0, r1]. -- cgit v1.3