[PATCH] D54860: [llvm-dwarfdump] - Dump the older versions of .eh_frame/.debug_frame correctly.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 23 06:17:03 PST 2018


grimar created this revision.
grimar added reviewers: dblaikie, probinson.
Herald added subscribers: JDevlieghere, aprantl.

The issue is the following.

DWARF 2 used version 1 for .debug_frame.
(Appendix G, p. 416 http://dwarfstd.org/doc/DWARF5.pdf)

lib/MC now always sets version 1 for `.eh_frame` (and sets 1-4 versions for .debug_frame correctly):
https://github.com/llvm-mirror/llvm/blob/master/lib/MC/MCDwarf.cpp#L1530
https://github.com/llvm-mirror/llvm/blob/master/lib/MC/MCDwarf.cpp#L1562
https://github.com/llvm-mirror/llvm/blob/master/lib/MC/MCDwarf.cpp#L1602

In version 1, `return_address_register` was defined as `ubyte`, while other versions
switched to `uleb128`.

Patch teaches llvm-dwarfdump about this difference.


https://reviews.llvm.org/D54860

Files:
  lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
  test/tools/llvm-dwarfdump/X86/eh-frame-return-address-reg.s


Index: test/tools/llvm-dwarfdump/X86/eh-frame-return-address-reg.s
===================================================================
--- test/tools/llvm-dwarfdump/X86/eh-frame-return-address-reg.s
+++ test/tools/llvm-dwarfdump/X86/eh-frame-return-address-reg.s
@@ -0,0 +1,51 @@
+# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t.o
+# RUN: llvm-dwarfdump -v %t.o | FileCheck %s
+
+# The format of the .eh_frame section is similar in
+# format and purpose to the .debug_frame section.
+# Version 1 is often used for .eh_frame,
+# and also it was used for DWARF v2. For that case,
+# return address register should be encoded as ubyte,
+# while later versions use ULEB128. This test case
+# checks that we are able to dump it correctly.
+
+# CHECK:      .eh_frame contents:
+# CHECK:      00000000 00000010 ffffffff CIE
+# CHECK-NEXT:   Version:               1
+# CHECK-NEXT:   Augmentation:          "zR"
+# CHECK-NEXT:   Code alignment factor: 1
+# CHECK-NEXT:   Data alignment factor: 1
+# CHECK-NEXT:   Return address column: 240
+# CHECK-NEXT:   Augmentation data:     1A
+
+.text
+.global _start
+_start:
+ nop
+
+.section .eh_frame, "a"
+  .long 16   # Size
+  .long 0x00 # ID
+  .byte 0x01 # Version
+
+  .byte 0x7A # Augmentation string: "zR"
+  .byte 0x52
+  .byte 0x00
+
+  .byte 0x01 # Code alignment factor, ULEB128
+  .byte 0x01 # Data alignment factor, ULEB128
+  
+  .byte 0xF0 # Return address register, ubyte for version 1.
+
+  .byte 0x01 # LEB128
+  .byte 0x1A # DW_EH_PE_pcrel | DW_EH_PE_sdata2
+
+  .byte 0x00
+  .byte 0x00
+  .byte 0x00
+
+  .long 10   # Size
+  .long 24   # ID
+fde:
+  .long _start - fde
+  .word 0
Index: lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -396,7 +396,8 @@
       uint8_t SegmentDescriptorSize = Version < 4 ? 0 : Data.getU8(&Offset);
       uint64_t CodeAlignmentFactor = Data.getULEB128(&Offset);
       int64_t DataAlignmentFactor = Data.getSLEB128(&Offset);
-      uint64_t ReturnAddressRegister = Data.getULEB128(&Offset);
+      uint64_t ReturnAddressRegister =
+          Version == 1 ? Data.getU8(&Offset) : Data.getULEB128(&Offset);
 
       // Parse the augmentation data for EH CIEs
       StringRef AugmentationData("");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54860.175117.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181123/2346b54d/attachment.bin>


More information about the llvm-commits mailing list