From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1717) id 959CB3858C60; Fri, 16 Feb 2024 04:14:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 959CB3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708056871; bh=KFIplwcSOF+op5/FxW9L8nPRDd5tBkEo+QdxuYY2LSA=; h=From:To:Subject:Date:From; b=fy9iKyW0xxZEF1v+twHmmG2IaTN2yj+Re6EjNplnQbn40QCUwSZ1yLhnntilUNChf sQFEWzA7mTh45sSzuQ1s9TI0/9M/HSyPGmYkdmNHF7oXH/IEWii9i5+nAdTOQoY7mB 3Eh12/G49wMNACfkOci646gHkAwQkIiAcmh8/KHQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tejas Belagod To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9022] Arm: Fix incorrect tailcall-generation for indirect calls [PR113780] X-Act-Checkin: gcc X-Git-Author: Tejas Belagod X-Git-Refname: refs/heads/master X-Git-Oldrev: 5c30ecfa81cb64c8c5b52f561f54acf2d87d57ea X-Git-Newrev: f436a2ab6ad15968275c9bbf3bd56647e5559e68 Message-Id: <20240216041431.959CB3858C60@sourceware.org> Date: Fri, 16 Feb 2024 04:14:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f436a2ab6ad15968275c9bbf3bd56647e5559e68 commit r14-9022-gf436a2ab6ad15968275c9bbf3bd56647e5559e68 Author: Tejas Belagod Date: Thu Jan 25 16:05:36 2024 +0530 Arm: Fix incorrect tailcall-generation for indirect calls [PR113780] This patch fixes a bug that causes indirect calls in PAC-enabled functions to be tailcalled incorrectly when all argument registers R0-R3 are used. 2024-02-07 Tejas Belagod PR target/113780 * config/arm/arm.cc (arm_function_ok_for_sibcall): Don't allow tailcalls for indirect calls with 4 or more arguments in pac-enabled functions. * lib/target-supports.exp (v8_1m_main_pacbti): Add __ARM_FEATURE_PAUTH. * gcc.target/arm/pac-sibcall.c: New. Diff: --- gcc/config/arm/arm.cc | 11 +++++++---- gcc/testsuite/gcc.target/arm/pac-sibcall.c | 14 ++++++++++++++ gcc/testsuite/lib/target-supports.exp | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index c44047c377a8..1cd69268ee98 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -7980,10 +7980,13 @@ arm_function_ok_for_sibcall (tree decl, tree exp) && DECL_WEAK (decl)) return false; - /* We cannot do a tailcall for an indirect call by descriptor if all the - argument registers are used because the only register left to load the - address is IP and it will already contain the static chain. */ - if (!decl && CALL_EXPR_BY_DESCRIPTOR (exp) && !flag_trampolines) + /* We cannot tailcall an indirect call by descriptor if all the call-clobbered + general registers are live (r0-r3 and ip). This can happen when: + - IP contains the static chain, or + - IP is needed for validating the PAC signature. */ + if (!decl + && ((CALL_EXPR_BY_DESCRIPTOR (exp) && !flag_trampolines) + || arm_current_function_pac_enabled_p())) { tree fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); CUMULATIVE_ARGS cum; diff --git a/gcc/testsuite/gcc.target/arm/pac-sibcall.c b/gcc/testsuite/gcc.target/arm/pac-sibcall.c new file mode 100644 index 000000000000..e15bd2f478d1 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pac-sibcall.c @@ -0,0 +1,14 @@ +/* If all call-clobbered general registers are live (r0-r3, ip), disable + indirect tail-call for a PAC-enabled function. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target arm_arch_v8_1m_main_pacbti_ok } */ +/* { dg-add-options arm_arch_v8_1m_main_pacbti } */ +/* { dg-additional-options "-mbranch-protection=pac-ret+leaf -O2" } */ + +void fail(void (*f)(int, int, int, int)) +{ + f(1, 2, 3, 4); +} + +/* { dg-final { scan-assembler-not "bx\tip\t@ indirect register sibling call" } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 81715999f871..645759496b7b 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -5534,7 +5534,7 @@ foreach { armfunc armflag armdefs } { v8m_main "-march=armv8-m.main+fp -mthumb" __ARM_ARCH_8M_MAIN__ v8_1m_main "-march=armv8.1-m.main+fp -mthumb" __ARM_ARCH_8M_MAIN__ v8_1m_main_pacbti "-march=armv8.1-m.main+pacbti+fp -mthumb" - "__ARM_ARCH_8M_MAIN__ && __ARM_FEATURE_BTI" + "__ARM_ARCH_8M_MAIN__ && __ARM_FEATURE_BTI && __ARM_FEATURE_PAUTH" v9a "-march=armv9-a+simd" __ARM_ARCH_9A__ } { eval [string map [list FUNC $armfunc FLAG $armflag DEFS $armdefs ] { proc check_effective_target_arm_arch_FUNC_ok { } {