public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch 4/7, Arm. GCC] Implement target feature macros for PACBTI.
@ 2021-10-08 12:18 Tejas Belagod
  2021-10-11 13:58 ` Richard Earnshaw
  0 siblings, 1 reply; 2+ messages in thread
From: Tejas Belagod @ 2021-10-08 12:18 UTC (permalink / raw)
  To: gcc-patches

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

Hi,

This patch implements target feature macros when PACBTI is
enabled through the -march option or -mbranch-protection.

Tested on arm-none-eabi. OK for trunk?

2021-10-04  Tejas Belagod  <tbelagod@arm.com>

gcc/ChangeLog:

	* config/arm/arm-c.c (arm_cpu_builtins): Define
	__ARM_FEATURE_BTI_DEFAULT and __ARM_FEATURE_PAC_DEFAULT.

gcc/testsuite/ChangeLog:

	* gcc.target/arm/acle/pacbti-m-predef-2.c: New test.
	* gcc.target/arm/acle/pacbti-m-predef-4.c: New test.
	* gcc.target/arm/acle/pacbti-m-predef-5.c: New test.

[-- Attachment #2: pacbti-tm.txt --]
[-- Type: text/plain, Size: 2791 bytes --]

diff --git a/gcc/config/arm/arm-c.c b/gcc/config/arm/arm-c.c
index cc7901bca8dc9c5c27ed6afc5bc26afd42689e6d..00dc1c2f13f2023c2ba8d7b03038a4cdde068ef6 100644
--- a/gcc/config/arm/arm-c.c
+++ b/gcc/config/arm/arm-c.c
@@ -193,6 +193,17 @@ arm_cpu_builtins (struct cpp_reader* pfile)
   def_or_undef_macro (pfile, "__ARM_FEATURE_COMPLEX", TARGET_COMPLEX);
   def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT);
 
+  cpp_undef (pfile, "__ARM_FEATURE_BTI_DEFAULT");
+  cpp_undef (pfile, "__ARM_FEATURE_PAC_DEFAULT");
+  if (TARGET_HAVE_PACBTI)
+    {
+      builtin_define_with_int_value ("__ARM_FEATURE_BTI_DEFAULT",
+				     arm_enable_pacbti & 0x1);
+      builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT",
+				     arm_enable_pacbti >> 1);
+    }
+
+
   cpp_undef (pfile, "__ARM_FEATURE_MVE");
   if (TARGET_HAVE_MVE && TARGET_HAVE_MVE_FLOAT)
     {
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c
new file mode 100644
index 0000000000000000000000000000000000000000..7e8cdb2c5fc74dd22085fcac1f692229300a333a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c
@@ -0,0 +1,16 @@
+
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=bti+pac-ret+b-key+leaf" } */
+
+int
+main()
+{
+  if (__ARM_FEATURE_BTI_DEFAULT != 1)
+    __builtin_abort ();
+
+  if (__ARM_FEATURE_PAC_DEFAULT != 6)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-4.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-4.c
new file mode 100644
index 0000000000000000000000000000000000000000..41fdcf91a8ab789d055407ae3f8c151984660ee9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-4.c
@@ -0,0 +1,16 @@
+
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=pac-ret+b-key" } */
+
+int
+main()
+{
+  if (__ARM_FEATURE_BTI_DEFAULT != 0)
+    __builtin_abort ();
+
+  if (__ARM_FEATURE_PAC_DEFAULT != 2)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-5.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-5.c
new file mode 100644
index 0000000000000000000000000000000000000000..9527c9620a3a5c973b47a5f364ae290d975358c1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-5.c
@@ -0,0 +1,16 @@
+
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=bti+pac-ret+leaf" } */
+
+int
+main()
+{
+  if (__ARM_FEATURE_BTI_DEFAULT != 1)
+    __builtin_abort ();
+
+  if (__ARM_FEATURE_PAC_DEFAULT != 5)
+    __builtin_abort ();
+
+  return 0;
+}

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

* Re: [Patch 4/7, Arm. GCC] Implement target feature macros for PACBTI.
  2021-10-08 12:18 [Patch 4/7, Arm. GCC] Implement target feature macros for PACBTI Tejas Belagod
@ 2021-10-11 13:58 ` Richard Earnshaw
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Earnshaw @ 2021-10-11 13:58 UTC (permalink / raw)
  To: Tejas Belagod, gcc-patches

On 08/10/2021 13:18, Tejas Belagod via Gcc-patches wrote:
> Hi,
> 
> This patch implements target feature macros when PACBTI is
> enabled through the -march option or -mbranch-protection.
> 
> Tested on arm-none-eabi. OK for trunk?
> 
> 2021-10-04  Tejas Belagod  <tbelagod@arm.com>
> 
> gcc/ChangeLog:
> 
> 	* config/arm/arm-c.c (arm_cpu_builtins): Define
> 	__ARM_FEATURE_BTI_DEFAULT and __ARM_FEATURE_PAC_DEFAULT.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/arm/acle/pacbti-m-predef-2.c: New test.
> 	* gcc.target/arm/acle/pacbti-m-predef-4.c: New test.
> 	* gcc.target/arm/acle/pacbti-m-predef-5.c: New test.
> 

I presume the specification for this is ACLE - please say so rather than 
making me guess.


+  cpp_undef (pfile, "__ARM_FEATURE_BTI_DEFAULT");
+  cpp_undef (pfile, "__ARM_FEATURE_PAC_DEFAULT");
+  if (TARGET_HAVE_PACBTI)
+    {
+      builtin_define_with_int_value ("__ARM_FEATURE_BTI_DEFAULT",
+				     arm_enable_pacbti & 0x1);

My reading of the ACLE specification would suggest this shouldn't be 
defined if it would have a value of 0, but that's not what this code 
does.  I think it would be better to move this outside the 
TARGET_HAVE_PACBTI and use the def_or_undef approach.

+      builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT",
+				     arm_enable_pacbti >> 1);

This one is less clear, could the value ever be zero?  I guess exactly 
one of a-key and b-key must be defined and each has a separate bit.

+    }
+
+

Not more than one blank line at the end of a block.


diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c 
b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-2.c


Given what I've said above, I think you need to also test that 
__ARM_FEATURE_BTI_DEFAULT is defined before testing the value (and 
emitting #error if it isn't).

R.

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

end of thread, other threads:[~2021-10-11 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08 12:18 [Patch 4/7, Arm. GCC] Implement target feature macros for PACBTI Tejas Belagod
2021-10-11 13:58 ` Richard Earnshaw

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