diff mbox series

[6/7,Arm] Emit build attributes for PACBTI target feature.

Message ID AM5PR0801MB1844C2F78EF4F9159F20A2ABEAB29@AM5PR0801MB1844.eurprd08.prod.outlook.com
State New
Headers show
Series [1/7,Arm] Add Armv8.1-M Mainline target feature +pacbti. | expand

Commit Message

Tejas Belagod Oct. 8, 2021, 12:18 p.m. UTC
Hi,

This patch emits assembler directives for PACBTI build attributes
as defined by the ABI. (https://github.com/ARM-software/abi-aa/releases/download/2021Q1/addenda32.pdf)

Tested on arm-none-eabi.

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

gcc/ChangeLog:

	* config/arm/arm.c (arm_file_start): Emit EABI attributes for
	Tag_PAC_extension, Tag_BTI_extension, TAG_BTI_use, TAG_PACRET_use.

gcc/testsuite/ChangeLog:

	* gcc.target/arm/acle/pacbti-m-predef-1.c: New test.
	* gcc.target/arm/acle/pacbti-m-predef-3: New test.
	* gcc.target/arm/acle/pacbti-m-predef-6.c: New test.
diff mbox series

Patch

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 1f939a6b79a90430abf120e0aa075dfc1fab29a8..557aae371e2707cb8db569ce033242a139b64e86 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -28305,6 +28305,27 @@  arm_file_start (void)
 	arm_emit_eabi_attribute ("Tag_ABI_FP_16bit_format", 38,
 			     (int) arm_fp16_format);
 
+      if (TARGET_HAVE_PACBTI)
+	{
+	  arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 2);
+	  arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 2);
+	  arm_emit_eabi_attribute ("TAG_BTI_use", 74, arm_enable_pacbti & 0x1);
+	  arm_emit_eabi_attribute ("TAG_PACRET_use", 76,
+				   (arm_enable_pacbti >> 1 != 0));
+	}
+      else
+	{
+	  if (arm_enable_pacbti != 0)
+	    {
+	      arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 1);
+	      arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 1);
+	      arm_emit_eabi_attribute ("TAG_BTI_use", 74,
+				       arm_enable_pacbti & 0x1);
+	      arm_emit_eabi_attribute ("TAG_PACRET_use", 76,
+				       (arm_enable_pacbti >> 1 != 0));
+	    }
+	}
+
       if (arm_lang_output_object_attributes_hook)
 	arm_lang_output_object_attributes_hook();
     }
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
new file mode 100644
index 0000000000000000000000000000000000000000..de9102be3f293605d0891c45cd247be9cf8bd00b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
@@ -0,0 +1,22 @@ 
+
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=pac-ret+bti --save-temps" } */
+
+/* { dg-final { scan-assembler "\.arch_extension pacbti" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 2" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 2" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 74, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
+
+int
+main()
+{
+  if (__ARM_FEATURE_BTI_DEFAULT != 1)
+    __builtin_abort ();
+
+  if (__ARM_FEATURE_PAC_DEFAULT != 1)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c
new file mode 100644
index 0000000000000000000000000000000000000000..6ecdf2f7411e5d44a5304681032d0841d965b49c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c
@@ -0,0 +1,21 @@ 
+
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=pac-ret+b-key+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" } } */
+
+int
+main()
+{
+  if (__ARM_FEATURE_BTI_DEFAULT != 0)
+    __builtin_abort ();
+
+  if (__ARM_FEATURE_PAC_DEFAULT != 6)
+    __builtin_abort ();
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-6.c b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-6.c
new file mode 100644
index 0000000000000000000000000000000000000000..2340bf0f937b7ea68a02500b66f151f0ce3f39b6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-6.c
@@ -0,0 +1,21 @@ 
+
+/* { dg-do run } */
+/* { dg-require-effective-target arm_pacbti_hw } */
+/* { dg-additional-options " -mbranch-protection=bti --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, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 0" } } */
+
+int
+main()
+{
+  if (__ARM_FEATURE_BTI_DEFAULT != 1)
+    __builtin_abort ();
+
+  if (__ARM_FEATURE_PAC_DEFAULT != 0)
+    __builtin_abort ();
+
+  return 0;
+}