From 5cc5576a9cff098e6e47397ee32cb250de43d814 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sun, 4 Apr 2021 12:46:21 -0400 Subject: [PATCH] cmd/compile: untangle Wrapper and ABIWrapper flags Currently, there are Wrapper and ABIWrapper attributes. Wrapper is set when compiler generates an wrapper function (e.g. method wrapper). ABIWrapper is set when compiler generates an ABI wrapper. It also sets Wrapper flag for ABI wrappers. Currently, they have the following meanings: - Wrapper flag hides the frame from (normal) traceback. - Wrapper flag enables special panic+recover adjustment, so it can correctly recover when a wrapper function is deferred. - ABIWrapper flag disables the panic+recover adjustment, because we never defer an ABI wrapper that can recover. This CL changes them to: - Both Wrapper and ABIWrapper flags hide the frame from (normal) traceback. (Setting one is enough.) - Wrapper flag enables special panic+recover adjustment. ABIWrapper flag no longer has effect on this. This makes it clearer if we do want an ABI wrapper that also does the panic+recover adjustment. In the old mechanism we'd have to unset ABIWrapper flag, even if the function is actually an ABI wrapper. In the new mechanism we just need to set both ABIWrapper and Wrapper flags. Updates #40724. Change-Id: I7fbc83f85d23676dc94db51dfda63dcacdf1fc19 Reviewed-on: https://go-review.googlesource.com/c/go/+/307235 Trust: Cherry Zhang Reviewed-by: Than McIntosh Reviewed-by: Austin Clements --- src/cmd/compile/internal/ssagen/abi.go | 7 ------- src/cmd/internal/obj/plist.go | 2 +- src/cmd/internal/obj/x86/obj6.go | 4 ++-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/abi.go b/src/cmd/compile/internal/ssagen/abi.go index 61d065cea83..ecd6a32eb3c 100644 --- a/src/cmd/compile/internal/ssagen/abi.go +++ b/src/cmd/compile/internal/ssagen/abi.go @@ -289,13 +289,6 @@ func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) { fn.SetABIWrapper(true) fn.SetDupok(true) - // Set this as a wrapper so it doesn't appear in tracebacks. - // Having both ABIWrapper and Wrapper set suppresses obj's - // usual panic+recover handling for wrappers; that's okay - // because we're never going to defer a wrapper for a function - // that then recovers, so that's would just be unnecessary - // code in the ABI wrapper. - fn.SetWrapper(true) // ABI0-to-ABIInternal wrappers will be mainly loading params from // stack into registers (and/or storing stack locations back to diff --git a/src/cmd/internal/obj/plist.go b/src/cmd/internal/obj/plist.go index b2f2bdcaed6..9dbad20589c 100644 --- a/src/cmd/internal/obj/plist.go +++ b/src/cmd/internal/obj/plist.go @@ -136,7 +136,7 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int) { ctxt.Diag("symbol %s listed multiple times", s.Name) } name := strings.Replace(s.Name, "\"\"", ctxt.Pkgpath, -1) - s.Func().FuncID = objabi.GetFuncID(name, flag&WRAPPER != 0) + s.Func().FuncID = objabi.GetFuncID(name, flag&WRAPPER != 0 || flag&ABIWRAPPER != 0) s.Func().FuncFlag = toFuncFlag(flag) s.Set(AttrOnList, true) s.Set(AttrDuplicateOK, flag&DUPOK != 0) diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go index e81e38ad259..b8c7ad7d1bb 100644 --- a/src/cmd/internal/obj/x86/obj6.go +++ b/src/cmd/internal/obj/x86/obj6.go @@ -645,7 +645,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { } var regg int16 - if !p.From.Sym.NoSplit() || (p.From.Sym.Wrapper() && !p.From.Sym.ABIWrapper()) { + if !p.From.Sym.NoSplit() || p.From.Sym.Wrapper() { if ctxt.Arch.Family == sys.AMD64 && objabi.Experiment.RegabiG && cursym.ABI() == obj.ABIInternal { regg = REGG // use the g register directly in ABIInternal } else { @@ -713,7 +713,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { p.To.Reg = REG_BP } - if cursym.Func().Text.From.Sym.Wrapper() && !cursym.Func().Text.From.Sym.ABIWrapper() { + if cursym.Func().Text.From.Sym.Wrapper() { // if g._panic != nil && g._panic.argp == FP { // g._panic.argp = bottom-of-frame // }