public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrea Corallo <andrea.corallo@arm.com>
To: Richard Earnshaw via Gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Tejas Belagod <Tejas.Belagod@arm.com>,
	Richard Earnshaw <Richard.Earnshaw@arm.com>,
	Richard Earnshaw <Richard.Earnshaw@foss.arm.com>
Subject: Re: [Patch 7/8 V2] Arm: Emit build attributes for PACBTI target feature.
Date: Fri, 10 Dec 2021 17:36:27 +0100	[thread overview]
Message-ID: <gkrk0gcxvqs.fsf_-_@arm.com> (raw)
In-Reply-To: <5ee84862-83fe-6629-9022-f6018e374f2d@foss.arm.com> (Richard Earnshaw via Gcc-patches's message of "Tue, 7 Dec 2021 14:48:16 +0000")

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

Richard Earnshaw via Gcc-patches <gcc-patches@gcc.gnu.org> writes:

> On 28/10/2021 12:43, Tejas Belagod via Gcc-patches wrote:
>> 
>>> -----Original Message-----
>>> From: Gcc-patches <gcc-patches-
>>> bounces+belagod=gcc.gnu.org@gcc.gnu.org> On Behalf Of Tejas Belagod via
>>> Gcc-patches
>>> Sent: Friday, October 8, 2021 1:19 PM
>>> To: gcc-patches@gcc.gnu.org
>>> Subject: [Patch 6/7, Arm, GCC] Emit build attributes for PACBTI target
>>> feature.
>>>
>>> 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.
>> 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
>> 2021-10-25  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.
>
> I'm not sure what the value of making these executable tests is.  It
> means that they can only be used when the test model has PAC/BTI
> available.  But they don't really test the PAC/BTI generation, so that
> seems rather pointless.
>
> Better, IMO to make them simple compile/scan-assembler tests that
> check the build attributes are correct.
>
> R.

Hi Richard,

agreed.  Please find attached the updated version of the patch.

Thanks for reviewing

  Andrea


[-- Attachment #2: 0001-Emit-build-attributes-for-PACBTI-target-feature.patch --]
[-- Type: text/plain, Size: 6376 bytes --]

From 6e54ecc3e20a3af8f72a38e55f086a33490353a0 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] Emit build attributes for PACBTI target feature.

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.c                          | 20 +++++++++++++++++++
 .../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, 83 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

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index ee22acddee5..a493523fe30 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -28221,6 +28221,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));
@@ -28291,6 +28293,24 @@ 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, bti);
+	  arm_emit_eabi_attribute ("TAG_PACRET_use", 76, pac);
+	}
+      else
+	{
+	  if (pac || bti)
+	    {
+	      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, bti);
+	      arm_emit_eabi_attribute ("TAG_PACRET_use", 76, pac);
+	    }
+	}
+
       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 00000000000..75d3e00ef64
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options " -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" } } */
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 00000000000..54fd42f16a3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-3.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options " -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 "\.eabi_attribute 74, 0" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 1" } } */
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 00000000000..309910f7c55
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-6.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options " -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 "\.eabi_attribute 76, 0" } } */
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 00000000000..bdf9131c142
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/acle/pacbti-m-predef-7.c
@@ -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 defined."
+#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 "\.eabi_attribute 74, 0" } } */
+/* { dg-final { scan-assembler "\.eabi_attribute 76, 0" } } */
-- 
2.20.1


  reply	other threads:[~2021-12-10 16:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28 11:43 [Patch 7/8, Arm, GCC] Emit build attributes for PACBTI target feature. [ Was RE: [Patch 6/7, Arm, GCC] Emit build attributes for PACBTI target feature.] Tejas Belagod
2021-12-07 14:48 ` Richard Earnshaw
2021-12-10 16:36   ` Andrea Corallo [this message]
2021-12-10 16:48     ` [Patch 7/8 V2] Arm: Emit build attributes for PACBTI target feature Richard Earnshaw
2021-12-13 16:52       ` [Patch 7/8 V3] " Andrea Corallo
2021-12-10 16:51     ` [Patch 7/8 V2] " Richard Earnshaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gkrk0gcxvqs.fsf_-_@arm.com \
    --to=andrea.corallo@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=Richard.Earnshaw@foss.arm.com \
    --cc=Tejas.Belagod@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).