[PATCH] D54420: Fix .cfi_restore with register numbers > 64

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 12 03:29:39 PST 2018


arichardson created this revision.
arichardson added reviewers: probinson, dblaikie, aprantl.
Herald added subscribers: llvm-commits, JDevlieghere, emaste.
Herald added a reviewer: espindola.

DW_CFA_restore can only encode register numbers up to 64 (6 bits unsigned
int). For regsiter numbers > 64 we have to use DW_CFA_restore_extended
instead which uses a ULEB128 value.
I discovered this problem in the out-of-tree CHERI target since we use
DWARF register number 89 for our return capability register.


Repository:
  rL LLVM

https://reviews.llvm.org/D54420

Files:
  lib/MC/MCDwarf.cpp
  test/MC/ELF/cfi-restore-extended.s


Index: test/MC/ELF/cfi-restore-extended.s
===================================================================
--- /dev/null
+++ test/MC/ELF/cfi-restore-extended.s
@@ -0,0 +1,17 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-dwarfdump -debug-frame - | FileCheck %s
+
+// Check that register numbers greater than 63 can be used in .cfi_restore directives
+f:
+  .cfi_startproc
+  nop
+// CHECK: DW_CFA_advance_loc: 1
+  .cfi_restore %rbp
+// CHECK-NEXT: DW_CFA_restore: reg6
+  nop
+// CHECK-NEXT: DW_CFA_advance_loc: 1
+  .cfi_restore 89
+// CHECK-NEXT: DW_CFA_restore_extended: reg89
+// CHECK-NEXT: DW_CFA_nop:
+  nop
+  .cfi_endproc
+
Index: lib/MC/MCDwarf.cpp
===================================================================
--- lib/MC/MCDwarf.cpp
+++ lib/MC/MCDwarf.cpp
@@ -1418,7 +1418,12 @@
     unsigned Reg = Instr.getRegister();
     if (!IsEH)
       Reg = MRI->getDwarfRegNumFromDwarfEHRegNum(Reg);
-    Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
+    if (Reg < 64) {
+      Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);
+    } else {
+      Streamer.EmitIntValue(dwarf::DW_CFA_restore_extended, 1);
+      Streamer.EmitULEB128IntValue(Reg);
+    }
     return;
   }
   case MCCFIInstruction::OpGnuArgsSize:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54420.173644.patch
Type: text/x-patch
Size: 1273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181112/9c6a5f2f/attachment.bin>


More information about the llvm-commits mailing list