[7/12,V2] arm: Emit build attributes for PACBTI target feature
Commit Message
Richard Earnshaw <Richard.Earnshaw@foss.arm.com> writes:
> On 28/04/2022 10:45, Andrea Corallo via Gcc-patches wrote:
>> 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>
>> 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.
>
> This bit is OK.
>
>> gcc/testsuite/ChangeLog:
>> * gcc.target/arm/acle/pacbti-m-predef-1.c: New test.
>> * gcc.target/arm/acle/pacbti-m-predef-3: Likewise.
>> * gcc.target/arm/acle/pacbti-m-predef-6.c: Likewise.
>> * gcc.target/arm/acle/pacbti-m-predef-7.c: Likewise.
>
> These tests contain directives like:
>
> +/* { dg-additional-options " -mbranch-protection=pac-ret+bti
> --save-temps" } */
>
> But they don't check that the architecture permits this (it has to be
> armv8-m.main or later).
Hi Richard & all,
please find attached the updated patch.
BR
Andrea
From 7d66e00bf62c8624d03e0173be8b8631d7435c38 Mon Sep 17 00:00:00 2001
From: Andrea Corallo <andrea.corallo@arm.com>
Date: Mon, 6 Dec 2021 11:42:24 +0100
Subject: [PATCH] [PATCH 7/12] arm: Emit build attributes for PACBTI target
feature
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>
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: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-6.c: Likewise.
* gcc.target/arm/acle/pacbti-m-predef-7.c: Likewise.
Co-Authored-By: Tejas Belagod <tbelagod@arm.com>
---
gcc/config/arm/arm.cc | 18 ++++++++++++++++++
.../gcc.target/arm/acle/pacbti-m-predef-1.c | 16 ++++++++++++++++
.../gcc.target/arm/acle/pacbti-m-predef-3.c | 16 ++++++++++++++++
.../gcc.target/arm/acle/pacbti-m-predef-6.c | 15 +++++++++++++++
.../gcc.target/arm/acle/pacbti-m-predef-7.c | 16 ++++++++++++++++
5 files changed, 81 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c
create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-6.c
create mode 100644 gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c
Comments
On 13/07/2022 09:58, Andrea Corallo via Gcc-patches wrote:
> Richard Earnshaw <Richard.Earnshaw@foss.arm.com> writes:
>
>> On 28/04/2022 10:45, Andrea Corallo via Gcc-patches wrote:
>>> 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>
>>> 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.
>>
>> This bit is OK.
>>
>>> gcc/testsuite/ChangeLog:
>>> * gcc.target/arm/acle/pacbti-m-predef-1.c: New test.
>>> * gcc.target/arm/acle/pacbti-m-predef-3: Likewise.
>>> * gcc.target/arm/acle/pacbti-m-predef-6.c: Likewise.
>>> * gcc.target/arm/acle/pacbti-m-predef-7.c: Likewise.
>>
>> These tests contain directives like:
>>
>> +/* { dg-additional-options " -mbranch-protection=pac-ret+bti
>> --save-temps" } */
>>
>> But they don't check that the architecture permits this (it has to be
>> armv8-m.main or later).
>
> Hi Richard & all,
>
> please find attached the updated patch.
>
> BR
>
> Andrea
>
The tests in this patch have similar issues to my previous reply. You
need to make sure that adding options will not cause a conflict with
other options added by the test driver.
R.
@@ -28349,6 +28349,8 @@ static void
arm_file_start (void)
{
int val;
+ bool pac = (aarch_ra_sign_scope != AARCH_FUNCTION_NONE);
+ bool bti = (aarch_enable_bti == 1);
arm_print_asm_arch_directives
(asm_out_file, TREE_TARGET_OPTION (target_option_default_node));
@@ -28419,6 +28421,22 @@ 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);
+ }
+ else if (pac || bti)
+ {
+ arm_emit_eabi_attribute ("Tag_PAC_extension", 50, 1);
+ arm_emit_eabi_attribute ("Tag_BTI_extension", 52, 1);
+ }
+
+ if (bti)
+ arm_emit_eabi_attribute ("TAG_BTI_use", 74, 1);
+ if (pac)
+ arm_emit_eabi_attribute ("TAG_PACRET_use", 76, 1);
+
if (arm_lang_output_object_attributes_hook)
arm_lang_output_object_attributes_hook();
}
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8.1-m.main -mbranch-protection=pac-ret+bti --save-temps" } */
+
+#if !defined (__ARM_FEATURE_BTI_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_BTI_DEFAULT should be defined."
+#endif
+
+#if !defined (__ARM_FEATURE_PAC_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_PAC_DEFAULT should be defined."
+#endif
+
+/* { dg-final { scan-assembler-not "\.arch_extension pacbti" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 74, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8.1-m.main -mbranch-protection=pac-ret+leaf --save-temps" } */
+
+#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
+
+/* { dg-final { scan-assembler-not "\.arch_extension pacbti" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 1" } } */
+/* { dg-final { scan-assembler-not "\.eabi_attribute 74" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8.1-m.main -mbranch-protection=bti --save-temps" } */
+
+#if !defined (__ARM_FEATURE_BTI_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_BTI_DEFAULT should be defined."
+#endif
+
+#if defined (__ARM_FEATURE_PAC_DEFAULT)
+#error "Feature test macro __ARM_FEATURE_PAC_DEFAULT should be undefined."
+#endif
+/* { dg-final { scan-assembler-not "\.arch_extension pacbti" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 50, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 52, 1" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 74, 1" } } */
+/* { dg-final { scan-assembler-not "\.eabi_attribute 76" } } */
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8.1-m.main+pacbti --save-temps" } */
+
+#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 undefined."
+#endif
+
+/* { 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-not "\.eabi_attribute 74" } } */
+/* { dg-final { scan-assembler-not "\.eabi_attribute 76" } } */