[PATCH v2] sframe: Fix RA and FP stack recovery rules

mengqinggang mengqinggang@loongson.cn
Mon Nov 9 06:49:49 GMT 2026


Fix the interpreted typo and change CFA + offset to *(CFA + offset)
for RA and FP stack recovery.
---
v1 -> v2:
  Add changes to libsframe/doc/sframe-spec.texi.

 include/sframe.h               | 12 ++++++------
 libsframe/doc/sframe-spec.texi | 22 +++++++++++-----------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/sframe.h b/include/sframe.h
index 2c9019cb64d..1d7bb9f1d86 100644
--- a/include/sframe.h
+++ b/include/sframe.h
@@ -449,14 +449,14 @@ typedef struct sframe_fre_info
    AMD64:
      offset1 (interpreted as CFA = BASE_REG + offset1)
       if FP is being tracked
-	offset2 (intrepreted as FP = CFA + offset2)
+	offset2 (interpreted as FP = *(CFA + offset2))
       fi
 
     AARCH64:
      offset1 (interpreted as CFA = BASE_REG + offset1)
      if FP is being tracked (in other words, if frame record created)
-       offset2 (interpreted as RA = CFA + offset2)
-       offset3 (intrepreted as FP = CFA + offset3)
+       offset2 (interpreted as RA = *(CFA + offset2))
+       offset3 (interpreted as FP = *(CFA + offset3))
      fi
      Note that in AAPCS64, a frame record, if created, will save both FP and
      LR on stack.
@@ -464,15 +464,15 @@ typedef struct sframe_fre_info
    s390x:
      offset1 (interpreted as CFA = BASE_REG + offset1)
      if RA is being tracked
-       offset2 (interpreted as RA = CFA + offset2; an offset value of
+       offset2 (interpreted as RA = *(CFA + offset2); an offset value of
 	       SFRAME_FRE_RA_OFFSET_INVALID indicates a dummy padding RA offset
 	       to represent FP without RA saved on stack)
        if FP is being tracked
-	 offset3 (intrepreted as FP = CFA + offset3)
+	 offset3 (interpreted as FP = *(CFA + offset3))
        fi
      else
       if FP is being tracked
-	offset2 (intrepreted as FP = CFA + offset2)
+	offset2 (interpreted as FP = *(CFA + offset2))
       fi
     fi
     Note that in s390x, if a FP/RA is to be restored from a register, flex FDEs
diff --git a/libsframe/doc/sframe-spec.texi b/libsframe/doc/sframe-spec.texi
index cd76bf9f8e3..728181749fc 100644
--- a/libsframe/doc/sframe-spec.texi
+++ b/libsframe/doc/sframe-spec.texi
@@ -1045,14 +1045,14 @@ encoded in the SFrame file format in the field @code{sfh_cfa_fixed_ra_offset}
 in the SFrame header.  @xref{SFrame Header}.
 
 Hence, the second stack offset (in the SFrame FRE), when present, will be used
-to locate the FP, by interpreting it as: FP = CFA + offset2.
+to locate the FP, by interpreting it as: FP = *(CFA + offset2).
 
 Hence, in summary:
 
 @multitable {Offset ID} {Interpretation in AMD64 in AMD64}
 @headitem Offset ID @tab Interpretation in AMD64
 @item 1 @tab CFA = @code{BASE_REG} + offset1
-@item 2 @tab FP = CFA + offset2
+@item 2 @tab FP = *(CFA + offset2)
 @end multitable
 
 @node AArch64
@@ -1068,8 +1068,8 @@ and LR (a.k.a the RA).  However, the standard does not mandate the precise
 location in the function where the frame record is created, if at all.  Hence
 the need to track RA in the SFrame stack trace format.  As RA is being tracked
 in this ABI, the second stack offset is always used to locate the RA, by
-interpreting it as: RA = CFA + offset2.  The third stack offset will be used to
-locate the FP, by interpreting it as: FP = CFA + offset3.
+interpreting it as: RA = *(CFA + offset2).  The third stack offset will be used to
+locate the FP, by interpreting it as: FP = *(CFA + offset3).
 
 Given the nature of things, the number of stack offsets seen on AArch64 per
 SFrame FRE is either 1 or 3.
@@ -1079,8 +1079,8 @@ Hence, in summary:
 @multitable {Offset ID} {Interpretation in AArch64 in X}
 @headitem Offset ID @tab Interpretation in AArch64
 @item 1 @tab CFA = @code{BASE_REG} + offset1
-@item 2 @tab RA = CFA + offset2
-@item 3 @tab FP = CFA + offset3
+@item 2 @tab RA = *(CFA + offset2)
+@item 3 @tab FP = *(CFA + offset3)
 @end multitable
 
 @node s390x
@@ -1114,12 +1114,12 @@ The (64-bit) s390x ELF ABI does not mandate the precise location in a function
 where the return address (RA) and frame pointer (FP) are saved, if at all.
 Hence the need to track RA in the SFrame stack trace format.  As RA is being
 tracked in this ABI, the second stack offset is always used to locate the RA
-stack slot, by interpreting it as: RA = CFA + offset2, unless the offset has a
-value of @code{SFRAME_FRE_RA_OFFSET_INVALID}.  RA remains unchanged, if the
+stack slot, by interpreting it as: RA = *(CFA + offset2), unless the offset has
+a value of @code{SFRAME_FRE_RA_OFFSET_INVALID}.  RA remains unchanged, if the
 offset is not available or has a value of @code{SFRAME_FRE_RA_OFFSET_INVALID}.
 Stack tracers are recommended to validate that the "unchanged RA" pattern, when
 present, is seen only for the topmost stack frame.  The third stack offset is
-used to locate the FP stack slot, by interpreting it as: FP = CFA + offset3.
+used to locate the FP stack slot, by interpreting it as: FP = *(CFA + offset3).
 FP remains unchanged, if the offset is not available.
 
 In leaf functions the RA and FP may be saved in other registers, such as
@@ -1135,9 +1135,9 @@ Hence, in summary:
 @multitable @columnfractions .15 .85
 @headitem Offset ID @tab Interpretation in s390x
 @item 1 @tab CFA = @code{BASE_REG} + offset1
-@item 2 @tab RA stack slot = CFA + offset2
+@item 2 @tab RA stack slot = *(CFA + offset2)
            @*RA not saved if (offset2 == @code{SFRAME_FRE_RA_OFFSET_INVALID})
-@item 3 @tab FP stack slot = CFA + offset3
+@item 3 @tab FP stack slot = *(CFA + offset3)
 @end multitable
 
 The s390x ELF ABI defines the CFA as stack pointer (SP) at call site +160.  The
-- 
2.34.1



More information about the Binutils mailing list