Commit 81a61a96 authored by Keith Randall's avatar Keith Randall

runtime: for plugins, don't add duplicate itabs

We already do this for shared libraries. Do it for plugins also.
Suggestions on how to test this would be welcome.

I'd like to get this in for 1.8.  It could lead to mysterious
hangs when using plugins.

Fixes #18676

Change-Id: I03209b096149090b9ba171c834c5e59087ed0f92
Reviewed-on: https://go-review.googlesource.com/35117Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
parent f674537c
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package dynamodbstreamsevt
import "encoding/json"
var foo json.RawMessage
type Event struct{}
func (e *Event) Dummy() {}
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The bug happened like this:
// 1) The main binary adds an itab for *json.UnsupportedValueError / error
// (concrete type / interface type). This itab goes in hash bucket 0x111.
// 2) The plugin adds that same itab again. That makes a cycle in the itab
// chain rooted at hash bucket 0x111.
// 3) The main binary then asks for the itab for *dynamodbstreamsevt.Event /
// json.Unmarshaler. This itab happens to also live in bucket 0x111.
// The lookup code goes into an infinite loop searching for this itab.
// The code is carefully crafted so that the two itabs are both from the
// same bucket, and so that the second itab doesn't exist in
// the itab hashmap yet (so the entire linked list must be searched).
package main
import (
"encoding/json"
"issue18676/dynamodbstreamsevt"
"plugin"
)
func main() {
plugin.Open("plugin.so")
var x interface{} = (*dynamodbstreamsevt.Event)(nil)
if _, ok := x.(json.Unmarshaler); !ok {
println("something")
}
}
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "C"
import "issue18676/dynamodbstreamsevt"
func F(evt *dynamodbstreamsevt.Event) {}
...@@ -16,7 +16,7 @@ goarch=$(go env GOARCH) ...@@ -16,7 +16,7 @@ goarch=$(go env GOARCH)
function cleanup() { function cleanup() {
rm -f plugin*.so unnamed*.so iface*.so rm -f plugin*.so unnamed*.so iface*.so
rm -rf host pkg sub iface rm -rf host pkg sub iface issue18676
} }
trap cleanup EXIT trap cleanup EXIT
...@@ -38,3 +38,9 @@ GOPATH=$(pwd) go build -buildmode=plugin iface_a ...@@ -38,3 +38,9 @@ GOPATH=$(pwd) go build -buildmode=plugin iface_a
GOPATH=$(pwd) go build -buildmode=plugin iface_b GOPATH=$(pwd) go build -buildmode=plugin iface_b
GOPATH=$(pwd) go build iface GOPATH=$(pwd) go build iface
LD_LIBRARY_PATH=$(pwd) ./iface LD_LIBRARY_PATH=$(pwd) ./iface
# Test for issue 18676 - make sure we don't add the same itab twice.
# The buggy code hangs forever, so use a timeout to check for that.
GOPATH=$(pwd) go build -buildmode=plugin -o plugin.so src/issue18676/plugin.go
GOPATH=$(pwd) go build -o issue18676 src/issue18676/main.go
timeout 10s ./issue18676
...@@ -56,8 +56,10 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatch ...@@ -56,8 +56,10 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatch
lock(&ifaceLock) lock(&ifaceLock)
for _, i := range md.itablinks { for _, i := range md.itablinks {
if i.inhash == 0 {
additab(i, true, false) additab(i, true, false)
} }
}
unlock(&ifaceLock) unlock(&ifaceLock)
// Build a map of symbol names to symbols. Here in the runtime // Build a map of symbol names to symbols. Here in the runtime
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment