[v0,07/13] aarch64: refactor binary approach for RA signing method to make it extendable

Message ID 20240708123452.1883314-8-matthieu.longo@arm.com
State New
Headers
Series aarch64: add instructions for Armv9.5-A PAC enhancement |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Matthieu Longo July 8, 2024, 12:34 p.m. UTC
  ---
 gas/gen-sframe.c | 21 +++++++++++++--------
 gas/gen-sframe.h | 14 +++++++++++---
 include/sframe.h |  4 ++--
 3 files changed, 26 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 626dc33b71d..247b65a37d0 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -254,11 +254,12 @@  static struct sframe_version_ops sframe_ver_ops;
 
 static unsigned char
 sframe_v1_set_fre_info (unsigned int base_reg, unsigned int num_offsets,
-			unsigned int offset_size, bool mangled_ra_p)
+			unsigned int offset_size,
+			RA_signing_method_t ra_signing_info)
 {
   unsigned char fre_info;
   fre_info = SFRAME_V1_FRE_INFO (base_reg, num_offsets, offset_size);
-  fre_info = SFRAME_V1_FRE_INFO_UPDATE_MANGLED_RA_P (mangled_ra_p, fre_info);
+  fre_info = SFRAME_V1_FRE_INFO_UPDATE_RA_SIGNING_INFO (ra_signing_info, fre_info);
   return fre_info;
 }
 
@@ -292,10 +293,11 @@  sframe_set_version (uint32_t sframe_version ATTRIBUTE_UNUSED)
 
 static unsigned char
 sframe_set_fre_info (unsigned int base_reg, unsigned int num_offsets,
-		     unsigned int offset_size, bool mangled_ra_p)
+		     unsigned int offset_size,
+		     RA_signing_method_t ra_signing_info)
 {
   return sframe_ver_ops.set_fre_info (base_reg, num_offsets,
-				      offset_size, mangled_ra_p);
+				      offset_size, ra_signing_info);
 }
 
 /* SFrame set func info. */
@@ -526,7 +528,7 @@  output_sframe_row_entry (symbolS *fde_start_addr,
   fre_num_offsets = get_fre_num_offsets (sframe_fre);
   fre_offset_size = sframe_get_fre_offset_size (sframe_fre);
   fre_info = sframe_set_fre_info (fre_base_reg, fre_num_offsets,
-				  fre_offset_size, sframe_fre->mangled_ra_p);
+				  fre_offset_size, sframe_fre->ra_signing_info);
   out_one (fre_info);
 
   idx = sframe_fre_offset_func_map_index (fre_offset_size);
@@ -879,7 +881,7 @@  sframe_row_entry_new (void)
   fre->merge_candidate = true;
   /* Reset the mangled RA status bit to zero by default.  We will initialize it in
      sframe_row_entry_initialize () with the sticky bit if set.  */
-  fre->mangled_ra_p = false;
+  fre->ra_signing_info = RA_no_signing;
 
   return fre;
 }
@@ -927,7 +929,7 @@  sframe_row_entry_initialize (struct sframe_row_entry *cur_fre,
   cur_fre->ra_offset = prev_fre->ra_offset;
   /* Treat RA mangling as a sticky bit.  It retains its value until another
      .cfi_negate_ra_state is seen.  */
-  cur_fre->mangled_ra_p = prev_fre->mangled_ra_p;
+  cur_fre->ra_signing_info = prev_fre->ra_signing_info;
 }
 
 /* Return SFrame register name for SP, FP, and RA, or NULL if other.  */
@@ -1276,7 +1278,10 @@  sframe_xlate_do_aarch64_negate_ra_state (struct sframe_xlate_ctx *xlate_ctx,
 
   gas_assert (cur_fre);
   /* Toggle the mangled RA status bit.  */
-  cur_fre->mangled_ra_p = !cur_fre->mangled_ra_p;
+  cur_fre->ra_signing_info
+    = ((cur_fre->ra_signing_info == RA_no_signing)
+       ? RA_signing_SP
+       : RA_no_signing);
   cur_fre->merge_candidate = false;
 
   return SFRAME_XLATE_OK;
diff --git a/gas/gen-sframe.h b/gas/gen-sframe.h
index 8ed46dbb087..db1e5de968f 100644
--- a/gas/gen-sframe.h
+++ b/gas/gen-sframe.h
@@ -21,6 +21,8 @@ 
 #ifndef GENSFRAME_H
 #define GENSFRAME_H
 
+#include "ansidecl.h"
+
 #define SFRAME_FRE_ELEM_LOC_REG		0
 #define SFRAME_FRE_ELEM_LOC_STACK	1
 
@@ -39,6 +41,12 @@ 
    the RA.
 */
 
+typedef enum ATTRIBUTE_PACKED
+{
+  RA_no_signing = 0x0,
+  RA_signing_SP = 0x1,
+} RA_signing_method_t;
+
 struct sframe_row_entry
 {
   /* A linked list.  */
@@ -52,8 +60,8 @@  struct sframe_row_entry
      on it.  */
   bool merge_candidate;
 
-  /* Whether the return address is mangled with pauth code.  */
-  bool mangled_ra_p;
+  /* Track the PAuth mangling information for RA.  */
+  RA_signing_method_t ra_signing_info;
 
   /* Track CFA base (architectural) register ID.  */
   unsigned int cfa_base_reg;
@@ -146,7 +154,7 @@  struct sframe_version_ops
   unsigned char format_version;    /* SFrame format version.  */
   /* set SFrame FRE info.  */
   unsigned char (*set_fre_info) (unsigned int, unsigned int, unsigned int,
-				 bool);
+				 RA_signing_method_t);
   /* set SFrame Func info.  */
   unsigned char (*set_func_info) (unsigned int, unsigned int, unsigned int);
 };
diff --git a/include/sframe.h b/include/sframe.h
index b3d0c2e937d..53388aaaa91 100644
--- a/include/sframe.h
+++ b/include/sframe.h
@@ -264,8 +264,8 @@  typedef struct sframe_fre_info
    (((offset_num) & 0xf) << 1) | ((base_reg_id) & 0x1))
 
 /* Set the mangled_ra_p bit as indicated.  */
-#define SFRAME_V1_FRE_INFO_UPDATE_MANGLED_RA_P(mangled_ra_p, fre_info) \
-  ((((mangled_ra_p) & 0x1) << 7) | ((fre_info) & 0x7f))
+#define SFRAME_V1_FRE_INFO_UPDATE_RA_SIGNING_INFO(ra_signing_info, fre_info) \
+  ((((ra_signing_info) & 0x1) << 7) | ((fre_info) & 0x7f))
 
 #define SFRAME_V1_FRE_CFA_BASE_REG_ID(data)	  ((data) & 0x1)
 #define SFRAME_V1_FRE_OFFSET_COUNT(data)	  (((data) >> 1) & 0xf)