From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2092) id BF7303858423; Fri, 10 Mar 2023 16:21:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF7303858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678465303; bh=mTZl6wu5Sk94VmuywxzlIC5lLffKPqWa2FVLamARMEU=; h=From:To:Subject:Date:From; b=IpUzx34EwpFQZ9dkkEXJLU0mzIlPg819DIejYOjYieJ0de7EusV1BPWyewULXG4if q5X8eChHDgbrtebAVPmz5hLf93JNIeRwYaR5VJbGzrqUCFPYh74pFFrafxMYjPWjd4 GZ00PdHmjYjnE6jGeOxgiuTHEK65oHrYST+xuCOQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Andrea Corallo To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/arm-12-m-pacbti)] arm: Implement arm Function target attribute 'branch-protection' X-Act-Checkin: gcc X-Git-Author: Andrea Corallo X-Git-Refname: refs/vendors/ARM/heads/arm-12-m-pacbti X-Git-Oldrev: 9d560b2365c8aee249a0ad17ba0af0c5a157d20a X-Git-Newrev: 8b7f28f2e81ea09bd4f1a5cfb4f7ba285bfcca9a Message-Id: <20230310162143.BF7303858423@sourceware.org> Date: Fri, 10 Mar 2023 16:21:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8b7f28f2e81ea09bd4f1a5cfb4f7ba285bfcca9a commit 8b7f28f2e81ea09bd4f1a5cfb4f7ba285bfcca9a Author: Andrea Corallo Date: Mon Jan 23 17:38:03 2023 +0100 arm: Implement arm Function target attribute 'branch-protection' gcc/ * config/arm/arm.cc (arm_valid_target_attribute_rec): Add ARM function attribute 'branch-protection' and parse its options. * doc/extend.texi: Document ARM Function attribute 'branch-protection'. gcc/testsuite/ * gcc.target/arm/acle/pacbti-m-predef-13.c: New test. Co-Authored-By: Tejas Belagod Diff: --- gcc/config/arm/arm.cc | 16 +++++++++ gcc/doc/extend.texi | 7 ++++ .../gcc.target/arm/acle/pacbti-m-predef-13.c | 41 ++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc index 5fcf8a10ba8..7fbfdc30d39 100644 --- a/gcc/config/arm/arm.cc +++ b/gcc/config/arm/arm.cc @@ -33397,6 +33397,22 @@ arm_valid_target_attribute_rec (tree args, struct gcc_options *opts) opts->x_arm_arch_string = xstrndup (arch, strlen (arch)); } + else if (startswith (q, "branch-protection=")) + { + char *bp_str = q + strlen ("branch-protection="); + + opts->x_arm_branch_protection_string + = xstrndup (bp_str, strlen (bp_str)); + + /* Capture values from target attribute. */ + aarch_validate_mbranch_protection + (opts->x_arm_branch_protection_string); + + /* Init function target attr values. */ + opts->x_aarch_ra_sign_scope = aarch_ra_sign_scope; + opts->x_aarch_enable_bti = aarch_enable_bti; + + } else if (q[0] == '+') { opts->x_arm_arch_string diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 33a776a7978..519d6c350a6 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -4457,6 +4457,13 @@ Enable or disable calls to out-of-line helpers to implement atomic operations. This corresponds to the behavior of the command line options @option{-moutline-atomics} and @option{-mno-outline-atomics}. +@item branch-protection= +@cindex @code{branch-protection=} function attribute, arm +Select the function scope on which branch protection will be applied. +The behavior and permissible arguments are the same as for the +command-line option @option{-mbranch-protection=}. The default value +is @code{none}. + @end table The above target attributes can be specified as follows: diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c new file mode 100644 index 00000000000..b6d2df53072 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.c @@ -0,0 +1,41 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target mbranch_protection_ok } */ +/* { dg-options "-march=armv8.1-m.main+fp -mbranch-protection=pac-ret+leaf -mfloat-abi=hard --save-temps" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#if defined (__ARM_FEATURE_BTI_DEFAULT) +#error "Feature test macro __ARM_FEATURE_BTI_DEFAULT should be undefined." +#endif + +#if !defined (__ARM_FEATURE_PAC_DEFAULT) +#error "Feature test macro __ARM_FEATURE_PAC_DEFAULT should be defined." +#endif + +/* +**foo: +** bti +** ... +*/ +__attribute__((target("branch-protection=pac-ret+bti"), noinline)) +int foo () +{ + return 3; +} + +/* +**main: +** pac ip, lr, sp +** ... +** aut ip, lr, sp +** bx lr +*/ +int +main() +{ + return 1 + foo (); +} + +/* { dg-final { scan-assembler "\.eabi_attribute 50, 1" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 52, 1" } } */ +/* { dg-final { scan-assembler-not "\.eabi_attribute 74" } } */ +/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */