diff options
author | David Crawshaw <crawshaw@golang.org> | 2016-11-12 06:24:36 -0500 |
---|---|---|
committer | David Crawshaw <crawshaw@golang.org> | 2016-11-15 16:14:27 +0000 |
commit | 03da2690c9fefdbaff613f9ccc224b5f0abfbe16 (patch) | |
tree | 548d28619823ab21f19ea6be1b35f979ce879396 /src/plugin | |
parent | a145890059e9c7aae870e1b9e74b204b6c8bc8d5 (diff) | |
download | go-03da2690c9fefdbaff613f9ccc224b5f0abfbe16.tar.gz go-03da2690c9fefdbaff613f9ccc224b5f0abfbe16.zip |
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 <iant@golang.org>
Diffstat (limited to 'src/plugin')
-rw-r--r-- | src/plugin/plugin_dlopen.go | 8 |
1 files changed, 6 insertions, 2 deletions
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) |