[PATCH] D47593: [MC] Fallback on DWARF when generating compact unwind on AArch64

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 31 08:02:29 PDT 2018


thegameg created this revision.
thegameg added reviewers: t.p.northover, ab, pete.
Herald added subscribers: chrib, JDevlieghere, kristof.beyls, aprantl.
Herald added a reviewer: javed.absar.

Instead of asserting when using the def_cfa directive with a register different from fp, fallback on DWARF.

Easily triggered with:

  .cfi_def_cfa x1, 32;


https://reviews.llvm.org/D47593

Files:
  lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
  test/MC/AArch64/arm64-compact-unwind-fallback.s


Index: test/MC/AArch64/arm64-compact-unwind-fallback.s
===================================================================
--- /dev/null
+++ test/MC/AArch64/arm64-compact-unwind-fallback.s
@@ -0,0 +1,26 @@
+// RUN: llvm-mc -triple=arm64-apple-ios -filetype=obj < %s | \
+// RUN: llvm-readobj --expand-relocs -sections -section-relocations -section-data | \
+// RUN: FileCheck %s
+//
+// rdar://40249694
+
+// FIXME: we should add compact unwind support to llvm-objdump -unwind-info
+
+// Check that we fallback on DWARF instead of asserting.
+
+// CHECK:    Name: __compact_unwind
+// CHECK-NOT: Section {
+// CHECK:    SectionData (
+// CHECK-NEXT:      0000: 00000000 00000000 00000000 00000003  |................|
+// CHECK-NEXT:      0010: 00000000 00000000 00000000 00000000  |................|
+// CHECK-NEXT:    )
+// CHECK-NEXT:  }
+
+// CHECK:      Section {
+// CHECK-NOT:      Section {
+// CHECK:    Name: __eh_frame
+
+_cfi_dwarf:
+ .cfi_startproc
+ .cfi_def_cfa x1, 32;
+ .cfi_endproc
Index: lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
===================================================================
--- lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -455,9 +455,17 @@
         return CU::UNWIND_ARM64_MODE_DWARF;
       case MCCFIInstruction::OpDefCfa: {
         // Defines a frame pointer.
-        assert(getXRegFromWReg(MRI.getLLVMRegNum(Inst.getRegister(), true)) ==
-                   AArch64::FP &&
-               "Invalid frame pointer!");
+        unsigned XReg =
+            getXRegFromWReg(MRI.getLLVMRegNum(Inst.getRegister(), true));
+
+        // Other CFA registers than FP are not supported by compact unwind.
+        // Fallback on DWARF.
+        // FIXME: When opt-remarks are supported in MC, add a remark to notify
+        // the user.
+        if (XReg != AArch64::FP)
+          return CU::UNWIND_ARM64_MODE_DWARF;
+
+        assert(XReg == AArch64::FP && "Invalid frame pointer!");
         assert(i + 2 < e && "Insufficient CFI instructions to define a frame!");
 
         const MCCFIInstruction &LRPush = Instrs[++i];


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47593.149297.patch
Type: text/x-patch
Size: 2147 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180531/ddd127b9/attachment.bin>


More information about the llvm-commits mailing list