From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 80886385840B; Mon, 26 Jul 2021 15:18:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80886385840B Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/strub)] make builtins callable X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/strub X-Git-Oldrev: fb2b0649a5615004db14ddf4dc8d49c11ee51da6 X-Git-Newrev: 55724817dd9d178f5671ec1db4a5d3a836f8928b Message-Id: <20210726151843.80886385840B@sourceware.org> Date: Mon, 26 Jul 2021 15:18:43 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jul 2021 15:18:43 -0000 https://gcc.gnu.org/g:55724817dd9d178f5671ec1db4a5d3a836f8928b commit 55724817dd9d178f5671ec1db4a5d3a836f8928b Author: Alexandre Oliva Date: Mon Jul 26 12:15:36 2021 -0300 make builtins callable Diff: --- gcc/ipa-strub.c | 153 +++++++++++++++----------------------------------------- 1 file changed, 41 insertions(+), 112 deletions(-) diff --git a/gcc/ipa-strub.c b/gcc/ipa-strub.c index 7b05321e980..ba80f2faed9 100644 --- a/gcc/ipa-strub.c +++ b/gcc/ipa-strub.c @@ -438,6 +438,34 @@ strub_from_body_p (cgraph_node *node) return false; } +/* Return true iff node is associated with a builtin that should be callable + from strub contexts. */ +static inline bool +strub_callable_builtin_p (cgraph_node *node) +{ + if (DECL_BUILT_IN_CLASS (node->decl) != BUILT_IN_NORMAL) + return false; + + enum built_in_function fcode = DECL_FUNCTION_CODE (node->decl); + + switch (fcode) + { + case BUILT_IN_NONE: + gcc_unreachable (); + + /* ??? Make all builtins callable. We wish to make any builtin call the + compiler might introduce on its own callable. Anything that is + predictable enough as to be known not to allow stack data that should + be strubbed to unintentionally escape to non-strub contexts can be + allowed, and pretty much every builtin appears to fit this description. + The exceptions to this rule seem to be rare, and only available as + explicit __builtin calls, so let's keep it simple and allow all of + them... */ + default: + return true; + } +} + static enum strub_mode compute_strub_mode (cgraph_node *node, tree strub_attr) { @@ -495,7 +523,8 @@ compute_strub_mode (cgraph_node *node, tree strub_attr) = (!strub_flag_disabled && (strub_attr ? req_mode == STRUB_CALLABLE - : strub_flag_viable)); + : (strub_flag_viable + || strub_callable_builtin_p (node)))); /* This is a shorthand for either strub-enabled mode. */ const bool consider_strub @@ -1014,116 +1043,6 @@ public: } // anon namespace -#if 0 -static bool -may_throw_p (gcall *stmt) -{ - return flag_exceptions && !gimple_call_nothrow_p (stmt); -} - -static bool -strub_this_call_p (gcall *stmt) -{ - if (gimple_call_internal_p (stmt)) - return false; - - /* If there's no outgoing path in which to do the scrubbing, don't - bother. */ - if (gimple_call_noreturn_p (stmt) && !may_throw_p (stmt)) - return false; - - /* ??? Maybe non-mandatory tail calls should be disabled for - scrubbing. Or maybe it won't matter, as long as both tail-caller - and callee are scrubbing-capable. */ - if (gimple_call_must_tail_p (stmt) || gimple_call_tail_p (stmt)) - return false; - - if (gimple_alloca_call_p (stmt)) - return true; - - tree fndecl = gimple_call_fndecl (stmt); - if (!fndecl) - return true; - - if (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL) - return true; - - enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl); - - switch (fcode) - { - CASE_BUILT_IN_ALLOCA: - return true; - - case BUILT_IN_NONE: - return true; - - case BUILT_IN___STRUB_ENTER: - case BUILT_IN___STRUB_UPDATE: - case BUILT_IN___STRUB_LEAVE: - return false; - - case BUILT_IN_CLASSIFY_TYPE: - case BUILT_IN_CONSTANT_P: - return false; - - case BUILT_IN_RETURN_ADDRESS: - case BUILT_IN_FRAME_ADDRESS: - case BUILT_IN_STACK_ADDRESS: - case BUILT_IN_AGGREGATE_INCOMING_ADDRESS: - return false; - - case BUILT_IN_STACK_SAVE: - case BUILT_IN_STACK_RESTORE: - case BUILT_IN_ASAN_ALLOCAS_UNPOISON: - return false; - - case BUILT_IN_SETJMP_SETUP: - case BUILT_IN_SETJMP_RECEIVER: - case BUILT_IN_LONGJMP: - case BUILT_IN_NONLOCAL_GOTO: - case BUILT_IN_UPDATE_SETJMP_BUF: - case BUILT_IN_TRAP: - case BUILT_IN_UNREACHABLE: - return false; - - case BUILT_IN_UNWIND_INIT: - case BUILT_IN_DWARF_CFA: -#ifdef DWARF2_UNWIND_INFO - case BUILT_IN_DWARF_SP_COLUMN: - case BUILT_IN_INIT_DWARF_REG_SIZES: -#endif - case BUILT_IN_FROB_RETURN_ADDR: - case BUILT_IN_EXTRACT_RETURN_ADDR: - case BUILT_IN_EH_RETURN: - case BUILT_IN_EH_RETURN_DATA_REGNO: - case BUILT_IN_EXTEND_POINTER: - case BUILT_IN_EH_POINTER: - case BUILT_IN_EH_FILTER: - case BUILT_IN_EH_COPY_VALUES: - return false; - - case BUILT_IN_VA_START: - case BUILT_IN_VA_END: - case BUILT_IN_VA_COPY: - case BUILT_IN_EXPECT: - case BUILT_IN_EXPECT_WITH_PROBABILITY: - case BUILT_IN_ASSUME_ALIGNED: - case BUILT_IN_PREFETCH: - return false; - - case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE: - case BUILT_IN_OBJECT_SIZE: - case BUILT_IN_THREAD_POINTER: - case BUILT_IN_SET_THREAD_POINTER: - return false; - - default: - return true; - } -} -#endif - typedef hash_set indirect_parms_t; static tree @@ -2291,7 +2210,17 @@ pass_ipa_strub::execute (function *) } gimple_call_set_arg (call, 1, arg); update_stmt (call); - e->redirect_callee (cgraph_node::get_create (bvacopy)); + + /* If we are causing the cgraph_node for va_copy to be needed, + compute a strub mode for it to make it callable, otherwise + verify_strub will reject it. */ + cgraph_node *vacopy_node = cgraph_node::get (bvacopy); + if (!vacopy_node) + { + vacopy_node = cgraph_node::get_create (bvacopy); + set_strub_mode (vacopy_node); + } + e->redirect_callee (vacopy_node); } else if (fndecl && apply_args && fndecl_built_in_p (fndecl, BUILT_IN_APPLY_ARGS))