public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] gas: Skip SFrame FDE if FP without RA on stack
@ 2024-07-04  8:39 Jens Remus
  0 siblings, 0 replies; only message in thread
From: Jens Remus @ 2024-07-04  8:39 UTC (permalink / raw)
  To: binutils-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c6024caf0ce26c149b9d0a42cf7b8ab49ee6053c

commit c6024caf0ce26c149b9d0a42cf7b8ab49ee6053c
Author: Jens Remus <jremus@linux.ibm.com>
Date:   Thu Jul 4 10:34:12 2024 +0200

    gas: Skip SFrame FDE if FP without RA on stack
    
    The SFrame format cannot represent the frame pointer (FP) being saved
    on the stack without the return address (RA) also being saved on the
    stack, if RA tracking is used.
    
    A SFrame FDE is followed by 1-3 offsets with the following information:
    
    Without RA tracking:
    1. Offset from base pointer (SP or FP) to locate the CFA
    2. Optional: Offset to CFA to restore the frame pointer (FP)
    
    With RA tracking:
    1. Offset from base pointer (SP or FP) to locate the CFA
    2. Optional: Offset to CFA to restore the return address (RA)
    3. Optional: Offset to CFA to restore the frame pointer (FP)
    
    When RA tracking is used and a FDE is followed by two offsets the
    SFrame format does not provide any information to distinguish whether
    the second offset is the RA or FP offset. SFrame assumes the offset to
    be the RA offset, which may be wrong.
    
    Therefore skip generation of SFrame FDE information and print the
    following warning, if RA tracking is used and the FP is saved on the
    stack without the RA being saved as well:
    
      skipping SFrame FDE; FP without RA on stack
    
    gas/
            * gen-sframe.c (sframe_do_fde): Skip SFrame FDE if FP without RA
            on stack, as the SFrame format cannot represent this case.
    
    Signed-off-by: Jens Remus <jremus@linux.ibm.com>

Diff:
---
 gas/gen-sframe.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index 3d9824a7a08..c29c407cc86 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -1423,8 +1423,6 @@ sframe_do_fde (struct sframe_xlate_ctx *xlate_ctx,
 	}
     }
 
-  /* No errors encountered.  */
-
   /* Link in the scratchpad FRE that the last few CFI insns helped create.  */
   if (xlate_ctx->cur_fre)
     {
@@ -1438,6 +1436,25 @@ sframe_do_fde (struct sframe_xlate_ctx *xlate_ctx,
 	= get_dw_fde_end_addrS (xlate_ctx->dw_fde);
     }
 
+#ifdef SFRAME_FRE_RA_TRACKING
+  if (sframe_ra_tracking_p ())
+    {
+      struct sframe_row_entry *fre;
+
+      /* Iterate over the scratchpad FREs and validate them.  */
+      for (fre = xlate_ctx->first_fre; fre; fre = fre->next)
+	{
+	  /* SFrame format cannot represent FP on stack without RA on stack.  */
+	  if (fre->ra_loc != SFRAME_FRE_ELEM_LOC_STACK
+	      && fre->bp_loc == SFRAME_FRE_ELEM_LOC_STACK)
+	    {
+	      as_warn (_("skipping SFrame FDE; FP without RA on stack"));
+	      return SFRAME_XLATE_ERR_NOTREPRESENTED;
+	    }
+	}
+    }
+#endif /* SFRAME_FRE_RA_TRACKING  */
+
   return SFRAME_XLATE_OK;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-07-04  8:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-04  8:39 [binutils-gdb] gas: Skip SFrame FDE if FP without RA on stack Jens Remus

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).