public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection'.
@ 2021-11-12 11:23 Tejas Belagod
  2021-12-16 14:48 ` Andrea Corallo
  0 siblings, 1 reply; 2+ messages in thread
From: Tejas Belagod @ 2021-11-12 11:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Earnshaw

[-- 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;
+}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection'.
  2021-11-12 11:23 [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection' Tejas Belagod
@ 2021-12-16 14:48 ` Andrea Corallo
  0 siblings, 0 replies; 2+ messages in thread
From: Andrea Corallo @ 2021-12-16 14:48 UTC (permalink / raw)
  To: Tejas Belagod via Gcc-patches; +Cc: Tejas Belagod, Richard Earnshaw

Tejas Belagod via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

> 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.

[...]

Ping

  Andrea

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-16 14:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-12 11:23 [Patch 9/9, GCC, Arm] Implement arm Function target attribute 'branch-protection' Tejas Belagod
2021-12-16 14:48 ` Andrea Corallo

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).