diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-02-26 15:38:12 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-02-26 15:38:12 +0000 |
commit | 4fd3c8aad91decbcb204c9c0900da15383945500 (patch) | |
tree | e4af19ac0fbd8be46db16d65a1a6b7b4815adf50 /libgo/go/runtime | |
parent | 5c98b419f75a77545abcccb10743829704a4e5d5 (diff) |
libgo: update to Go 1.12 release
Reviewed-on: https://go-review.googlesource.com/c/163742
From-SVN: r269216
Diffstat (limited to 'libgo/go/runtime')
-rw-r--r-- | libgo/go/runtime/crash_test.go | 12 | ||||
-rw-r--r-- | libgo/go/runtime/extern.go | 6 | ||||
-rw-r--r-- | libgo/go/runtime/mgcsweep.go | 14 | ||||
-rw-r--r-- | libgo/go/runtime/runtime1.go | 2 | ||||
-rw-r--r-- | libgo/go/runtime/testdata/testprog/crash.go | 21 |
5 files changed, 53 insertions, 2 deletions
diff --git a/libgo/go/runtime/crash_test.go b/libgo/go/runtime/crash_test.go index 6627bdc6726..6343e8ef75f 100644 --- a/libgo/go/runtime/crash_test.go +++ b/libgo/go/runtime/crash_test.go @@ -764,3 +764,15 @@ func TestG0StackOverflow(t *testing.T) { runtime.G0StackOverflow() } + +// Test that panic message is not clobbered. +// See issue 30150. +func TestDoublePanic(t *testing.T) { + output := runTestProg(t, "testprog", "DoublePanic", "GODEBUG=clobberfree=1") + wants := []string{"panic: XXX", "panic: YYY"} + for _, want := range wants { + if !strings.Contains(output, want) { + t.Errorf("output:\n%s\n\nwant output containing: %s", output, want) + } + } +} diff --git a/libgo/go/runtime/extern.go b/libgo/go/runtime/extern.go index d07a5ed024f..298eb81c65e 100644 --- a/libgo/go/runtime/extern.go +++ b/libgo/go/runtime/extern.go @@ -27,6 +27,10 @@ It is a comma-separated list of name=val pairs setting these named variables: allocfreetrace: setting allocfreetrace=1 causes every allocation to be profiled and a stack trace printed on each object's allocation and free. + clobberfree: setting clobberfree=1 causes the garbage collector to + clobber the memory content of an object with bad content when it frees + the object. + cgocheck: setting cgocheck=0 disables all checks for packages using cgo to incorrectly pass Go pointers to non-Go code. Setting cgocheck=1 (the default) enables relatively cheap @@ -121,7 +125,7 @@ It is a comma-separated list of name=val pairs setting these named variables: IDs will refer to the ID of the goroutine at the time of creation; it's possible for this ID to be reused for another goroutine. Setting N to 0 will report no ancestry information. -The net and net/http packages also refer to debugging variables in GODEBUG. +The net, net/http, and crypto/tls packages also refer to debugging variables in GODEBUG. See the documentation for those packages for details. The GOMAXPROCS variable limits the number of operating system threads that diff --git a/libgo/go/runtime/mgcsweep.go b/libgo/go/runtime/mgcsweep.go index dcaeb106dc4..fb5ee6ad46d 100644 --- a/libgo/go/runtime/mgcsweep.go +++ b/libgo/go/runtime/mgcsweep.go @@ -293,7 +293,7 @@ func (s *mspan) sweep(preserve bool) bool { } } - if debug.allocfreetrace != 0 || raceenabled || msanenabled { + if debug.allocfreetrace != 0 || debug.clobberfree != 0 || raceenabled || msanenabled { // Find all newly freed objects. This doesn't have to // efficient; allocfreetrace has massive overhead. mbits := s.markBitsForBase() @@ -304,6 +304,9 @@ func (s *mspan) sweep(preserve bool) bool { if debug.allocfreetrace != 0 { tracefree(unsafe.Pointer(x), size) } + if debug.clobberfree != 0 { + clobberfree(unsafe.Pointer(x), size) + } if raceenabled { racefree(unsafe.Pointer(x), size) } @@ -472,3 +475,12 @@ retry: traceGCSweepDone() } } + +// clobberfree sets the memory content at x to bad content, for debugging +// purposes. +func clobberfree(x unsafe.Pointer, size uintptr) { + // size (span.elemsize) is always a multiple of 4. + for i := uintptr(0); i < size; i += 4 { + *(*uint32)(add(x, i)) = 0xdeadbeef + } +} diff --git a/libgo/go/runtime/runtime1.go b/libgo/go/runtime/runtime1.go index 4e771629b0e..66091ff6580 100644 --- a/libgo/go/runtime/runtime1.go +++ b/libgo/go/runtime/runtime1.go @@ -313,6 +313,7 @@ type dbgVar struct { var debug struct { allocfreetrace int32 cgocheck int32 + clobberfree int32 efence int32 gccheckmark int32 gcpacertrace int32 @@ -330,6 +331,7 @@ var debug struct { var dbgvars = []dbgVar{ {"allocfreetrace", &debug.allocfreetrace}, + {"clobberfree", &debug.clobberfree}, {"cgocheck", &debug.cgocheck}, {"efence", &debug.efence}, {"gccheckmark", &debug.gccheckmark}, diff --git a/libgo/go/runtime/testdata/testprog/crash.go b/libgo/go/runtime/testdata/testprog/crash.go index ed4ae7fcdbc..2f0f2f805a4 100644 --- a/libgo/go/runtime/testdata/testprog/crash.go +++ b/libgo/go/runtime/testdata/testprog/crash.go @@ -11,6 +11,7 @@ import ( func init() { register("Crash", Crash) + register("DoublePanic", DoublePanic) } var NilPointer *string @@ -44,3 +45,23 @@ func Crash() { testInNewThread("second-new-thread") test("main-again") } + +type P string + +func (p P) String() string { + // Try to free the "YYY" string header when the "XXX" + // panic is stringified. + runtime.GC() + runtime.GC() + runtime.GC() + return string(p) +} + +// Test that panic message is not clobbered. +// See issue 30150. +func DoublePanic() { + defer func() { + panic(P("YYY")) + }() + panic(P("XXX")) +} |