From 8f296f59de0703b0559474beb434a265e277bdca Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Sat, 8 Jun 2019 17:20:57 +0000 Subject: Revert "Revert "cmd/compile,runtime: allocate defer records on the stack"" This reverts CL 180761 Reason for revert: Reinstate the stack-allocated defer CL. There was nothing wrong with the CL proper, but stack allocation of defers exposed two other issues. Issue #32477: Fix has been submitted as CL 181258. Issue #32498: Possible fix is CL 181377 (not submitted yet). Change-Id: I32b3365d5026600069291b068bbba6cb15295eb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/181378 Reviewed-by: Brad Fitzpatrick --- src/runtime/stack.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/runtime/stack.go') diff --git a/src/runtime/stack.go b/src/runtime/stack.go index 22a0053fdb..7ae3eeef83 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -719,16 +719,21 @@ func adjustctxt(gp *g, adjinfo *adjustinfo) { } func adjustdefers(gp *g, adjinfo *adjustinfo) { - // Adjust defer argument blocks the same way we adjust active stack frames. - tracebackdefers(gp, adjustframe, noescape(unsafe.Pointer(adjinfo))) - // Adjust pointers in the Defer structs. - // Defer structs themselves are never on the stack. + // We need to do this first because we need to adjust the + // defer.link fields so we always work on the new stack. + adjustpointer(adjinfo, unsafe.Pointer(&gp._defer)) for d := gp._defer; d != nil; d = d.link { adjustpointer(adjinfo, unsafe.Pointer(&d.fn)) adjustpointer(adjinfo, unsafe.Pointer(&d.sp)) adjustpointer(adjinfo, unsafe.Pointer(&d._panic)) + adjustpointer(adjinfo, unsafe.Pointer(&d.link)) } + + // Adjust defer argument blocks the same way we adjust active stack frames. + // Note: this code is after the loop above, so that if a defer record is + // stack allocated, we work on the copy in the new stack. + tracebackdefers(gp, adjustframe, noescape(unsafe.Pointer(adjinfo))) } func adjustpanics(gp *g, adjinfo *adjustinfo) { -- cgit v1.3