[binutils-gdb] sframe.h: add support for .cfi_negate_ra_state

Indu Bhagat ibhagat@sourceware.org
Sat Dec 17 06:20:16 GMT 2022


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

commit 4604c7294166199f89a0122ee35095d7e0cd2d07
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Fri Dec 16 22:01:40 2022 -0800

    sframe.h: add support for .cfi_negate_ra_state
    
    Use the last remaining bit in the 'SFrame FRE info' word to store whether
    the RA is signed/unsigned with PAC authorization code: this bit is named
    as the "mangled RA" bit.  This bit is still unused for x86-64.
    
    The behaviour of the mangled-RA info bit in SFrame format closely
    follows the behaviour of DW_CFA_AARCH64_negate_ra_state in DWARF.  During
    unwinding, whenever an SFrame FRE with non-zero "mangled RA" bit is
    encountered, it means the upper bits of the return address contain Pointer
    Authentication code.  The unwinder, hence, must use appropriate means to
    restore LR correctly in such cases.
    
    include/ChangeLog:
    
            * sframe.h (SFRAME_V1_FRE_INFO_UPDATE_MANGLED_RA_P): New macro.
            (SFRAME_V1_FRE_MANGLED_RA_P): Likewise.

Diff:
---
 include/sframe.h | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/include/sframe.h b/include/sframe.h
index 03a2d75dfd3..b2bd41a724e 100644
--- a/include/sframe.h
+++ b/include/sframe.h
@@ -227,11 +227,12 @@ typedef struct sframe_fre_info
      - 2 bits: information about size of the offsets (S) in bytes.
      Valid values are SFRAME_FRE_OFFSET_1B, SFRAME_FRE_OFFSET_2B,
      SFRAME_FRE_OFFSET_4B
-     - 1 bit: Unused.
-     -----------------------------------------------------------------------
-     |  Unused  |  Size of offsets   |   Number of offsets    |   base_reg |
-     -----------------------------------------------------------------------
-     8          7                    5                        1            0
+     - 1 bit: Mangled RA state bit (aarch64 only).
+     ----------------------------------------------------------------------------------
+     | Mangled-RA (aarch64) |  Size of offsets   |   Number of offsets    |   base_reg |
+     |  Unused (amd64)      |                    |                        |            |
+     ----------------------------------------------------------------------------------
+     8                     7                    5                        1            0
 
      */
   uint8_t fre_info;
@@ -239,13 +240,19 @@ typedef struct sframe_fre_info
 
 /* Macros to compose and decompose FRE info.  */
 
+/* Note: Set mangled_ra_p to zero by default.  */
 #define SFRAME_V1_FRE_INFO(base_reg_id, offset_num, offset_size) \
-  ((((offset_size) & 0x3) << 5) | (((offset_num) & 0xf) << 1) | \
-   ((base_reg_id) & 0x1))
+  (((0 & 0x1) << 7) | (((offset_size) & 0x3) << 5) | \
+   (((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_CFA_BASE_REG_ID(data)	  ((data) & 0x1)
 #define SFRAME_V1_FRE_OFFSET_COUNT(data)	  (((data) >> 1) & 0xf)
-#define SFRAME_V1_FRE_OFFSET_SIZE(data)	  (((data) >> 5) & 0x3)
+#define SFRAME_V1_FRE_OFFSET_SIZE(data)		  (((data) >> 5) & 0x3)
+#define SFRAME_V1_FRE_MANGLED_RA_P(data)	  (((data) >> 7) & 0x1)
 
 /* SFrame Frame Row Entry definitions.


More information about the Binutils-cvs mailing list