aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-02-23 10:34:01 -0800
committerIan Lance Taylor <iant@golang.org>2018-02-23 22:39:46 +0000
commit804e3e565e98e1ff3a22eb354a473225f6dc7351 (patch)
tree17140bfce6bd2ea40c967e9df4610b0a754b2fc3 /src
parenta5e8e2d99815346cdff61905237056e0095c75ea (diff)
downloadgo-804e3e565e98e1ff3a22eb354a473225f6dc7351.tar.xz
runtime: don't check for String/Error methods in printany
They have either already been called by preprintpanics, or they can not be called safely because of the various conditions checked at the start of gopanic. Fixes #24059 Change-Id: I4a6233d12c9f7aaaee72f343257ea108bae79241 Reviewed-on: https://go-review.googlesource.com/96755 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/error.go6
-rw-r--r--src/runtime/iface.go8
-rw-r--r--src/runtime/panic.go3
3 files changed, 10 insertions, 7 deletions
diff --git a/src/runtime/error.go b/src/runtime/error.go
index 6048272e75..e1291e1543 100644
--- a/src/runtime/error.go
+++ b/src/runtime/error.go
@@ -73,14 +73,12 @@ func typestring(x interface{}) string {
}
// printany prints an argument passed to panic.
+// If panic is called with a value that has a String or Error method,
+// it has already been converted into a string by preprintpanics.
func printany(i interface{}) {
switch v := i.(type) {
case nil:
print("nil")
- case stringer:
- print(v.String())
- case error:
- print(v.Error())
case bool:
print(v)
case int:
diff --git a/src/runtime/iface.go b/src/runtime/iface.go
index 7c5d3a05b2..bd6bc282f4 100644
--- a/src/runtime/iface.go
+++ b/src/runtime/iface.go
@@ -113,6 +113,14 @@ func (t *itabTableType) find(inter *interfacetype, typ *_type) *itab {
// itabAdd adds the given itab to the itab hash table.
// itabLock must be held.
func itabAdd(m *itab) {
+ // Bugs can lead to calling this while mallocing is set,
+ // typically because this is called while panicing.
+ // Crash reliably, rather than only when we need to grow
+ // the hash table.
+ if getg().m.mallocing != 0 {
+ throw("malloc deadlock")
+ }
+
t := itabTable
if t.count >= 3*(t.size/4) { // 75% load factor
// Grow hash table.
diff --git a/src/runtime/panic.go b/src/runtime/panic.go
index 55ecb67654..dac63203fb 100644
--- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -389,7 +389,6 @@ func Goexit() {
// Call all Error and String methods before freezing the world.
// Used when crashing with panicking.
-// This must match types handled by printany.
func preprintpanics(p *_panic) {
defer func() {
if recover() != nil {
@@ -415,8 +414,6 @@ func printpanics(p *_panic) {
print("\t")
}
print("panic: ")
- // Because of preprintpanics, p.arg cannot be an error or
- // stringer, so this won't call into user code.
printany(p.arg)
if p.recovered {
print(" [recovered]")