]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw, aarch64: Implement DW_CFA_AARCH64_negate_ra_state CFI instruction
authorGerman Gomez <german.gomez@arm.com>
Mon, 26 Aug 2024 10:52:54 +0000 (11:52 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 30 Aug 2024 12:54:43 +0000 (14:54 +0200)
Implement DW_CFA_AARCH64_negate_ra_state in accordance with the DWARF
AARCH64 ABI [1].

Followup commits will use the value of this register to remove the PAC
from return addresses.

[1] https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#44call-frame-instructions

Signed-off-by: German Gomez <german.gomez@arm.com>
Signed-off-by: Steve Capper <steve.capper@arm.com>
libdw/cfi.c

index a71744056459d9cbea1b3c3325285664174bad74..743bfc073a4a23a44c2e5b5f95984c611df9a338 100644 (file)
@@ -125,6 +125,15 @@ execute_cfi (Dwarf_CFI *cache,
     fs->regs[regno].value = (r_value);                 \
   } while (0)
 
+  /* The AARCH64 DWARF ABI states that register 34 (ra_sign_state) must
+     be initialized to 0. So do it before executing the CFI. */
+  if (cache->e_machine == EM_AARCH64)
+    {
+      if (unlikely (! enough_registers (DW_AARCH64_RA_SIGN_STATE, &fs, &result)))
+       goto out;
+      fs->regs[DW_AARCH64_RA_SIGN_STATE].value = 0;
+    }
+
   while (program < end)
     {
       uint8_t opcode = *program++;
@@ -357,7 +366,10 @@ execute_cfi (Dwarf_CFI *cache,
            {
              /* Toggles the return address state, indicating whether
                 the return address is encrypted or not on
-                aarch64. XXX not handled yet.  */
+                aarch64. */
+             if (unlikely (! enough_registers (DW_AARCH64_RA_SIGN_STATE, &fs, &result)))
+               goto out;
+             fs->regs[DW_AARCH64_RA_SIGN_STATE].value ^= 0x1;
            }
          else
            {