public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tejas Belagod <Tejas.Belagod@arm.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: Richard Earnshaw <Richard.Earnshaw@arm.com>
Subject: [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection'.
Date: Fri, 12 Nov 2021 11:23:27 +0000	[thread overview]
Message-ID: <AS8PR08MB70793C3667ED5FADAD946EDBEA959@AS8PR08MB7079.eurprd08.prod.outlook.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 811 bytes --]

Hi,

This patch is part of the series of PACBTI-M patches posted earlier https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582773.html

This change adds the target function attribute 'branch-protection'.  The
options that it can take are the same the command-line option
'mbranch-protection'.  The function attribute options override the command-
line options for the function scope.

Regression tested for arm-none-eabi. OK for trunk?

2021-11-11  Tejas Belagod  <tbelagod@arm.com>

gcc/ChangeLog:
	* config/arm/arm.c (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-7.c: New test.

Thanks,
Tejas.

[-- Attachment #2: func_attr.txt --]
[-- Type: text/plain, Size: 2898 bytes --]

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index a87bcb298f9e6d7b2f3fd61b4586e291f46b0f81..64253f3814786b302f8fea573fdfc4213da439ce 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -33147,6 +33147,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 eee4c6737bbfa9529fd613a0197d513121d058ec..c605adf665754804735e244006fb39f02705c74e 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -4767,6 +4767,12 @@ In this example @code{target("+crc+nocrypto")} enables the @code{crc}
 extension and disables the @code{crypto} extension for the function @code{foo}
 without modifying an existing @option{-march=} or @option{-mcpu} option.
 
+@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
 
 @end table
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c
new file mode 100644
index 0000000000000000000000000000000000000000..ccf3e1cb9ae6cbed77844142e94641548b75c918
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c
@@ -0,0 +1,30 @@
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=pac-ret+leaf --save-temps" } */
+
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 2" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 2" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 74, 0" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
+
+#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
+
+__attribute__((target("branch-protection=pac-ret+bti"), noinline))
+void foo ()
+{
+  if (__ARM_FEATURE_PAC_DEFAULT != 5)
+    __builtin_abort ();
+}
+
+int
+main()
+{
+  foo ();
+  return 0;
+}

             reply	other threads:[~2021-11-12 11:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12 11:23 Tejas Belagod [this message]
2021-12-16 14:48 ` Andrea Corallo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS8PR08MB70793C3667ED5FADAD946EDBEA959@AS8PR08MB7079.eurprd08.prod.outlook.com \
    --to=tejas.belagod@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).