public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: binutils@sourceware.org
Cc: Indu Bhagat <indu.bhagat@oracle.com>
Subject: [PATCH 2/6] [2/6] gas: sframe: add support for .cfi_negate_ra_state
Date: Wed, 14 Dec 2022 11:58:55 -0800	[thread overview]
Message-ID: <20221214195859.1233809-3-indu.bhagat@oracle.com> (raw)
In-Reply-To: <20221214195859.1233809-1-indu.bhagat@oracle.com>

DW_CFA_AARCH64_negate_ra_state in aarch64 is multiplexed with
DW_CFA_GNU_window_save in the DWARF format.

ChangeLog:

	* gas/gen-sframe.c (sframe_v1_set_fre_info): Add new argument
	for mangled_ra_p.
	(sframe_set_fre_info): Likewise.
	(output_sframe_row_entry): Handle mangled_ra_p.
	(sframe_row_entry_new): Initialize mangled_ra_p.
	(sframe_xlate_do_gnu_window_save): New definition.
	(sframe_do_cfi_insn): Handle DW_CFA_GNU_window_save.
	* gas/gen-sframe.h (struct sframe_row_entry):
	(struct sframe_version_ops): Add a new argument for mangled_ra_p.
---
 gas/gen-sframe.c | 41 +++++++++++++++++++++++++++++++++--------
 gas/gen-sframe.h |  6 +++++-
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 075720facd6..f31a66da377 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -243,10 +243,11 @@ 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)
+			unsigned int offset_size, bool mangled_ra_p)
 {
   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);
   return fre_info;
 }
 
@@ -275,10 +276,10 @@ 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)
+		     unsigned int offset_size, bool mangled_ra_p)
 {
   return sframe_ver_ops.set_fre_info (base_reg, num_offsets,
-					 offset_size);
+				      offset_size, mangled_ra_p);
 }
 
 /* SFrame set func info. */
@@ -507,7 +508,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);
+				  fre_offset_size, sframe_fre->mangled_ra_p);
   out_one (fre_info);
 
   idx = sframe_fre_offset_func_map_index (fre_offset_size);
@@ -845,6 +846,9 @@ sframe_row_entry_new (void)
      for the supported arches.  */
   fre->cfa_base_reg = -1;
   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;
 
   return fre;
 }
@@ -890,6 +894,9 @@ sframe_row_entry_initialize (struct sframe_row_entry *cur_fre,
   cur_fre->bp_offset = prev_fre->bp_offset;
   cur_fre->ra_loc = prev_fre->ra_loc;
   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;
 }
 
 /* Translate DW_CFA_advance_loc into SFrame context.
@@ -1150,6 +1157,22 @@ sframe_xlate_do_restore (struct sframe_xlate_ctx *xlate_ctx,
   return SFRAME_XLATE_OK;
 }
 
+/* Translate DW_CFA_GNU_window_save into SFrame context.
+   Return SFRAME_XLATE_OK if success.  */
+
+static int
+sframe_xlate_do_gnu_window_save (struct sframe_xlate_ctx *xlate_ctx,
+				 struct cfi_insn_data *cfi_insn ATTRIBUTE_UNUSED)
+{
+  struct sframe_row_entry *cur_fre = xlate_ctx->cur_fre;
+
+  gas_assert (cur_fre);
+  /* Toggle the mangled RA status bit.  */
+  cur_fre->mangled_ra_p = !cur_fre->mangled_ra_p;
+
+  return SFRAME_XLATE_OK;
+}
+
 /* Process CFI_INSN and update the translation context with the FRE
    information.
 
@@ -1195,6 +1218,11 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx,
     case DW_CFA_restore:
       err = sframe_xlate_do_restore (xlate_ctx, cfi_insn);
       break;
+    /* DW_CFA_AARCH64_negate_ra_state is multiplexed with
+       DW_CFA_GNU_window_save.  */
+    case DW_CFA_GNU_window_save:
+      err = sframe_xlate_do_gnu_window_save (xlate_ctx, cfi_insn);
+      break;
     case DW_CFA_undefined:
     case DW_CFA_same_value:
       break;
@@ -1207,10 +1235,7 @@ sframe_do_cfi_insn (struct sframe_xlate_ctx *xlate_ctx,
 	    - ...
 
 	   Following skipped operations do, however, impact the asynchronicity:
-	     - CFI_escape,
-	     - DW_CFA_GNU_window_save,
-	     - DW_CFA_AARCH64_negate_ra_state (multiplexed with
-	       DW_CFA_GNU_window_save)  */
+	     - CFI_escape  */
 
 	err = SFRAME_XLATE_ERR_NOTREPRESENTED;
 	// printf (_("SFrame Unsupported or unknown Dwarf CFI number: %#x\n"), op);
diff --git a/gas/gen-sframe.h b/gas/gen-sframe.h
index 93af499278c..aa8be5df457 100644
--- a/gas/gen-sframe.h
+++ b/gas/gen-sframe.h
@@ -50,6 +50,9 @@ struct sframe_row_entry
      on it.  */
   bool merge_candidate;
 
+  /* Toggle RA state wrt pointer authentication code.  */
+  bool mangled_ra_p;
+
   /* Track CFA base (architectural) register ID.  */
   unsigned int cfa_base_reg;
   /* Offset from the CFA base register for recovering CFA.  */
@@ -140,7 +143,8 @@ 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);
+  unsigned char (*set_fre_info) (unsigned int, unsigned int, unsigned int,
+				 bool);
   /* set SFrame Func info.  */
   unsigned char (*set_func_info) (unsigned int, unsigned int);
 };
-- 
2.37.2


  parent reply	other threads:[~2022-12-14 19:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 19:58 [PATCH 0/6] SFrame: support for .cfi_negate_ra_state in aarch64 Indu Bhagat
2022-12-14 19:58 ` [PATCH 1/6] [1/6] sframe.h: add support for .cfi_negate_ra_state Indu Bhagat
2022-12-14 19:58 ` Indu Bhagat [this message]
2022-12-14 19:58 ` [PATCH 3/6] [3/6] gas: sframe: testsuite: add testcase " Indu Bhagat
2022-12-14 19:58 ` [PATCH 4/6] [4/6] libsframe: provide new access API for mangled RA bit Indu Bhagat
2022-12-14 19:58 ` [PATCH 5/6] [5/6] objdump/readelf: sframe: emit marker for FREs with mangled RA Indu Bhagat
2022-12-14 19:58 ` [PATCH 6/6] [6/6] sframe: doc: update spec for the mangled-RA bit in FRE Indu Bhagat
2022-12-16 16:39 ` [PATCH 0/6] SFrame: support for .cfi_negate_ra_state in aarch64 Nick Clifton

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=20221214195859.1233809-3-indu.bhagat@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=binutils@sourceware.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).