[03/13] gas: sframe: ignore .cfi_offset for RA selectively

Message ID 20251202073414.200246-4-indu.bhagat@oracle.com
State New
Headers
Series sframe: some refactoring and misc improvements |

Commit Message

Indu Bhagat Dec. 2, 2025, 7:34 a.m. UTC
  For ABIs not tracking RA (e.g., AMD64), the return address is expected
to be in a specific location (usually a fixed offset from CFA on stack).
Explicit manourvering to a different offset may be non-representable in
SFrame, and should not be simply ignored.

Although such patterns are not usually seen in the wild, it is more
correct to catch them if at all they manifest.

gas/
        * gen-sframe.c (sframe_xlate_do_offset): Do not ignore
	.cfi_offset for RA all the time.
---
 gas/gen-sframe.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index eead58b00f6..f39b4f495b4 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1179,8 +1179,19 @@  sframe_xlate_do_offset (struct sframe_xlate_ctx *xlate_ctx,
      being interpreted.  This FRE eventually gets linked in into the
      list of FREs for the specific function.  */
   struct sframe_row_entry *cur_fre = xlate_ctx->cur_fre;
-
   gas_assert (cur_fre);
+
+  /* For ABIs not tracking RA, the return address is expected to be in a
+     specific location.  Explicit manourvering to a different offset (than the
+     default offset) is non-representable in SFrame.  */
+  if (!sframe_ra_tracking_p () && cfi_insn->u.ri.reg == SFRAME_CFA_RA_REG
+      && cfi_insn->u.ri.offset != sframe_cfa_ra_offset ())
+    {
+      as_warn (_("no SFrame FDE emitted; %s register %u in .cfi_offset"),
+	       sframe_register_name (cfi_insn->u.ri.reg), cfi_insn->u.ri.reg);
+      return SFRAME_XLATE_ERR_NOTREPRESENTED;  /* Not represented.  */
+    }
+
   /* Change the rule for the register indicated by the register number to
      be the specified offset.  */
   /* Ignore SP reg, as it can be recovered from the CFA tracking info.  */