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>
This commit is contained in:
Ian Lance Taylor 2018-02-23 10:34:01 -08:00
parent a5e8e2d998
commit 804e3e565e
3 changed files with 10 additions and 7 deletions

View file

@ -73,14 +73,12 @@ func typestring(x interface{}) string {
} }
// printany prints an argument passed to panic. // 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{}) { func printany(i interface{}) {
switch v := i.(type) { switch v := i.(type) {
case nil: case nil:
print("nil") print("nil")
case stringer:
print(v.String())
case error:
print(v.Error())
case bool: case bool:
print(v) print(v)
case int: case int:

View file

@ -113,6 +113,14 @@ func (t *itabTableType) find(inter *interfacetype, typ *_type) *itab {
// itabAdd adds the given itab to the itab hash table. // itabAdd adds the given itab to the itab hash table.
// itabLock must be held. // itabLock must be held.
func itabAdd(m *itab) { 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 t := itabTable
if t.count >= 3*(t.size/4) { // 75% load factor if t.count >= 3*(t.size/4) { // 75% load factor
// Grow hash table. // Grow hash table.

View file

@ -389,7 +389,6 @@ func Goexit() {
// Call all Error and String methods before freezing the world. // Call all Error and String methods before freezing the world.
// Used when crashing with panicking. // Used when crashing with panicking.
// This must match types handled by printany.
func preprintpanics(p *_panic) { func preprintpanics(p *_panic) {
defer func() { defer func() {
if recover() != nil { if recover() != nil {
@ -415,8 +414,6 @@ func printpanics(p *_panic) {
print("\t") print("\t")
} }
print("panic: ") print("panic: ")
// Because of preprintpanics, p.arg cannot be an error or
// stringer, so this won't call into user code.
printany(p.arg) printany(p.arg)
if p.recovered { if p.recovered {
print(" [recovered]") print(" [recovered]")