From 0723f062ff906902c44086476f95016e50164c53 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sun, 4 Apr 2021 12:59:49 -0400 Subject: [PATCH] cmd/compile: enable panic+recover adjustment for some ABI wrappers For most ABI wrappers we don't need it because we're never going to defer an ABI wrapper for a function that then recovers, so that's would just be unnecessary code in the ABI wrapper. However, for functions that could be on the path of invoking a deferred function that can recover (runtime.reflectcall, reflect.callReflect, and reflect.callMethod), we do want the panic+recover adjustment. Set the Wrapper flag for them. Currently, those functions are defined as ABIInternal to avoid the ABI wrappers. But the assembly code still follows ABI0 calling convention, which would not work with the register-based calling convention. In particlar, it is not possible to make runtime.reflectcall ABIInternal, because it tail calls runtime.callNN functions, which are splittable. Later CLs will make them ABI0 and use the wrappers. Updates #40724. Change-Id: Ic7a45bbc6f726d29b5cb4932951a9d71578dcaf6 Reviewed-on: https://go-review.googlesource.com/c/go/+/307236 Trust: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Go Bot Reviewed-by: Austin Clements --- src/cmd/compile/internal/ssagen/abi.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssagen/abi.go b/src/cmd/compile/internal/ssagen/abi.go index ecd6a32eb3..9229d0212c 100644 --- a/src/cmd/compile/internal/ssagen/abi.go +++ b/src/cmd/compile/internal/ssagen/abi.go @@ -393,10 +393,20 @@ func setupTextLSym(f *ir.Func, flag int) { } // Clumsy but important. + // For functions that could be on the path of invoking a deferred + // function that can recover (runtime.reflectcall, reflect.callReflect, + // and reflect.callMethod), we want the panic+recover special handling. // See test/recover.go for test cases and src/reflect/value.go // for the actual functions being considered. - if base.Ctxt.Pkgpath == "reflect" { - switch f.Sym().Name { + // + // runtime.reflectcall is an assembly function which tailcalls + // WRAPPER functions (runtime.callNN). Its ABI wrapper needs WRAPPER + // flag as well. + fnname := f.Sym().Name + if base.Ctxt.Pkgpath == "runtime" && fnname == "reflectcall" { + flag |= obj.WRAPPER + } else if base.Ctxt.Pkgpath == "reflect" { + switch fnname { case "callReflect", "callMethod": flag |= obj.WRAPPER } -- 2.50.0