public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][committed] aarch64: Add __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI ACLE defines
@ 2022-12-12 11:09 Kyrylo Tkachov
  0 siblings, 0 replies; only message in thread
From: Kyrylo Tkachov @ 2022-12-12 11:09 UTC (permalink / raw)
  To: gcc-patches

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

Hi all,

Recent ACLE additions specified the __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI macros [1] that the compiler
should define when the pointer authentication and BTI instructions are available (and don't act as NOPs).
We've received requests to enable them in GCC for aarch64, similar to clang [2].
It's a fairly simple patch and should be non-intrusive at this stage.
Pointer authentication has its own "pauth" feature flag, whereas BTI depends on an architecture level
of Armv8.5-a or later.

Bootstrapped and tested on aarch64-none-linux-gnu.
Pushing to trunk.
Thanks,
Kyrill

[1] https://github.com/ARM-software/acle/blob/main/main/acle.md#pointer-authentication
[2] https://reviews.llvm.org/rG7d40baa82b1f272f68de63f3c4f68d970bdcd6ed

gcc/ChangeLog:

	* config/aarch64/aarch64-c.cc (aarch64_update_cpp_builtins): Define
	__ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI when appropriate.
	* config/aarch64/aarch64.h (TARGET_BTI): Define.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/acle/bti_def.c: New test.
	* gcc.target/aarch64/acle/pauth_def.c: New test.

[-- Attachment #2: acle-pacbti.patch --]
[-- Type: application/octet-stream, Size: 2443 bytes --]

diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc
index e296c73350f1ec70f6017c11be54e0749bf114d5..e47b6a870e20867003393d7496f761e47057e804 100644
--- a/gcc/config/aarch64/aarch64-c.cc
+++ b/gcc/config/aarch64/aarch64-c.cc
@@ -195,6 +195,8 @@ aarch64_update_cpp_builtins (cpp_reader *pfile)
       builtin_define_with_int_value ("__ARM_FEATURE_PAC_DEFAULT", v);
     }
 
+  aarch64_def_or_undef (TARGET_PAUTH, "__ARM_FEATURE_PAUTH", pfile);
+  aarch64_def_or_undef (TARGET_BTI, "__ARM_FEATURE_BTI", pfile);
   aarch64_def_or_undef (TARGET_I8MM, "__ARM_FEATURE_MATMUL_INT8", pfile);
   aarch64_def_or_undef (TARGET_BF16_SIMD,
 			"__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", pfile);
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index dcb1ecef71a937ece4d9849161157541855ab638..db6ec5c48d8f57d57c983f410315cdffe8d45a27 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -312,6 +312,11 @@ enum class aarch64_feature : unsigned char {
 /* PAUTH instructions are enabled through +pauth.  */
 #define TARGET_PAUTH (AARCH64_ISA_PAUTH)
 
+/* BTI instructions exist from Armv8.5-a onwards.  Their automatic use is
+   enabled through -mbranch-protection by using NOP-space instructions,
+   but this TARGET_ is used for defining BTI-related ACLE things.  */
+#define TARGET_BTI (AARCH64_ISA_V8_5A)
+
 /* MOPS instructions are enabled through +mops.  */
 #define TARGET_MOPS (AARCH64_ISA_MOPS)
 
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/bti_def.c b/gcc/testsuite/gcc.target/aarch64/acle/bti_def.c
new file mode 100644
index 0000000000000000000000000000000000000000..db94769ec8b9dcad2b0f3b84753ad4b8d7d4b412
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/acle/bti_def.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+#pragma GCC target "arch=armv8.5-a"
+#ifndef __ARM_FEATURE_BTI
+#error "__ARM_FEATURE_BTI is not defined but should be!"
+#endif
+
+void
+foo (void) {}
+
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c b/gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c
new file mode 100644
index 0000000000000000000000000000000000000000..400a0f61deb0749b3512322fad637a4c793b0dfb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/acle/pauth_def.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+#pragma GCC target "+pauth"
+#ifndef __ARM_FEATURE_PAUTH
+#error "__ARM_FEATURE_PAUTH is not defined but should be!"
+#endif
+
+void
+foo (void) {}
+

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-12 11:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-12 11:09 [PATCH][committed] aarch64: Add __ARM_FEATURE_PAUTH and __ARM_FEATURE_BTI ACLE defines Kyrylo Tkachov

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