From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 7B1703858C50 for ; Sat, 22 Apr 2023 21:14:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B1703858C50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=googlemail.com Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f193ca053eso11739895e9.0 for ; Sat, 22 Apr 2023 14:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1682198092; x=1684790092; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XhpFgI53TkLbom64q/YZqtoAdCcomFPeY5gMmUJimZ4=; b=f4BEifgbsZ6itEWHEJy88+JPZEaNMHGn86pCeGDKRfFDQ/MQ4bovNmmGUDOdq+BFeG Q+zUBdNrIP6Sp5BVNG6QCgxhGjgWsSKRGGMlL7cjPb9PQpeimG8WZwbdNyk6I5KymzwK s0hm2m/JfuzpMmonKdSSMYqB3suEFe5JKxpChGh3uLRKHHUweDfyL0X8zDCR27m5A2g+ ZODnC6uA+38qgo8ys58RhezefTwXqyo60X5zsMU71XBUVqVpTe1J6nvv+2pAL5O5GbC+ Z+CyekQ/iD0WO7P7019fzq9BA+7NT5bcLOg1M4gw1H2VKN+vUCh/5EmnuUjxcvWf96lD acTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682198092; x=1684790092; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XhpFgI53TkLbom64q/YZqtoAdCcomFPeY5gMmUJimZ4=; b=UyXirNFCz9jRPlQZnwmPGQo/s/6GDlrC38S1i0cqif7KJngt0vZruz4qwz26tVYJBs aMfbol8KhG6UNv+FtSVE4SxmTKu21yQylTRwbEf/HxAHlSpPTVNrxP3fxp94DjuqdMAZ BPNlYpiHiUl8bMrRyGmBwEt3IATbV5DyYACIuECQQFqkzzNcTAe8zuAFoMnoT6KUuSq/ BmEKgqo72CUA3E+Gj+w8ak7mefiWDfIalIvNXl7Ca/drNrumXdXdEsSRJg8a7FDZAi3B 24AIahDITCqsMbVhkzaDBi3j6/XSQ+fLiotaremha9yTCqRj05KNQq4P6Yq5ui4HyqRg h5Qg== X-Gm-Message-State: AAQBX9cG8zZZZ2Al00mCOo+dyW6egT4zTO9pKZjRco/Pj+ZJkuvGtNOr 4lL6kMv2WJw+4AOCv5ndzTC5eHARxS5PyXAVVDY= X-Google-Smtp-Source: AKy350YL6im1WcU2RxE1b3h6ZBjTuTxU+SK8oLDaHhh2Hz8KUB9BAuPWogGR2mJSuldIQsf+gpdaXyc1BhCr540SyXQ= X-Received: by 2002:a7b:c008:0:b0:3f1:7440:f21d with SMTP id c8-20020a7bc008000000b003f17440f21dmr4369441wmb.33.1682198091951; Sat, 22 Apr 2023 14:14:51 -0700 (PDT) MIME-Version: 1.0 References: <20230127144311.2188730-1-andrea.corallo@arm.com> In-Reply-To: <20230127144311.2188730-1-andrea.corallo@arm.com> From: Ramana Radhakrishnan Date: Sat, 22 Apr 2023 22:14:40 +0100 Message-ID: Subject: Re: [PATCH] arm: Implement arm Function target attribute 'branch-protection' To: Andrea Corallo Cc: gcc-patches@gcc.gnu.org, kyrylo.tkachov@arm.com, Richard.Earnshaw@arm.com, Tejas Belagod Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Jan 27, 2023 at 2:44=E2=80=AFPM Andrea Corallo via Gcc-patches wrote: > > gcc/ > > * config/arm/arm.cc (arm_valid_target_attribute_rec): Add ARM fun= ction > attribute 'branch-protection' and parse its options. > * doc/extend.texi: Document ARM Function attribute 'branch-protec= tion'. Nit: s/ARM/arm or s/ARM/AArch32. > > gcc/testsuite/ > > * gcc.target/arm/acle/pacbti-m-predef-13.c: New test. > > Co-Authored-By: Tejas Belagod > --- > 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(+) > create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-13.= c > > diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc > index efc48349dd3..add33090f18 100644 > --- a/gcc/config/arm/arm.cc > +++ b/gcc/config/arm/arm.cc > @@ -33568,6 +33568,22 @@ arm_valid_target_attribute_rec (tree args, struc= t gcc_options *opts) > > opts->x_arm_arch_string =3D xstrndup (arch, strlen (arch)); > } > + else if (startswith (q, "branch-protection=3D")) > + { > + char *bp_str =3D q + strlen ("branch-protection=3D"); > + > + opts->x_arm_branch_protection_string > + =3D 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 =3D aarch_ra_sign_scope; > + opts->x_aarch_enable_bti =3D aarch_enable_bti; > + > + } > else if (q[0] =3D=3D '+') > { > opts->x_arm_arch_string > diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi > index 4a89a3eae7c..23ee43919dd 100644 > --- a/gcc/doc/extend.texi > +++ b/gcc/doc/extend.texi > @@ -4492,6 +4492,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=3D > +@cindex @code{branch-protection=3D} 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=3D}. 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=3Darmv8.1-m.main+fp -mbranch-protection=3Dpac-re= t+leaf -mfloat-abi=3Dhard --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=3Dpac-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" } } */ > -- > 2.25.1 > If the attribute covers all the options that are in the command line documentation, surely there need to be tests for __attribute__((target("branch-protection=3Dstandard")) ? regards Ramana