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/plugin/plugin_dlopen.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/plugin/plugin_dlopen.go') diff --git a/src/plugin/plugin_dlopen.go b/src/plugin/plugin_dlopen.go index f4addde74c..c5b0a4721c 100644 --- a/src/plugin/plugin_dlopen.go +++ b/src/plugin/plugin_dlopen.go @@ -69,7 +69,11 @@ func open(name string) (*Plugin, error) { name = name[:len(name)-3] } - pluginpath, syms := lastmoduleinit() + pluginpath, syms, mismatchpkg := lastmoduleinit() + if mismatchpkg != "" { + pluginsMu.Unlock() + return nil, errors.New("plugin.Open: plugin was built with a different version of package " + mismatchpkg) + } if plugins == nil { plugins = make(map[string]*Plugin) } @@ -131,4 +135,4 @@ var ( ) // lastmoduleinit is defined in package runtime -func lastmoduleinit() (pluginpath string, syms map[string]interface{}) +func lastmoduleinit() (pluginpath string, syms map[string]interface{}, mismatchpkg string) -- cgit v1.3