[llvm] be66cf2 - [DebugInfo] Read CIE pointer as a relocatable value.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 18:13:13 PST 2020


Author: Igor Kudrin
Date: 2020-02-20T09:12:05+07:00
New Revision: be66cf221bbe6bb119d478e69fd2ca21872e2ad3

URL: https://github.com/llvm/llvm-project/commit/be66cf221bbe6bb119d478e69fd2ca21872e2ad3
DIFF: https://github.com/llvm/llvm-project/commit/be66cf221bbe6bb119d478e69fd2ca21872e2ad3.diff

LOG: [DebugInfo] Read CIE pointer as a relocatable value.

The CIE pointer field of an FDE record contains an offset to
a corresponding CIE record. In object files, this value comes with
relocation because the value has to be fixed when a linker combines
the final section from multiple sources. In most object files there is
only one CIE record at offset 0 of the .debug_frame section, so reading
a relocated or a raw value makes no difference. However, in partially
linked object files there are multiple CIE records and the relocations
should be applied to recover the right offset value.

Differential Revision: https://reviews.llvm.org/D74612

Added: 
    llvm/test/DebugInfo/debug-frame-cie-pointer-reloc.test

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
index b7d8fb81c54f..ff3ce456adc3 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -380,7 +380,7 @@ void DWARFDebugFrame::parse(DWARFDataExtractor Data) {
     uint64_t EndStructureOffset = Offset + Length;
 
     // The Id field's size depends on the DWARF format
-    Id = Data.getUnsigned(&Offset, (IsDWARF64 && !IsEH) ? 8 : 4);
+    Id = Data.getRelocatedValue((IsDWARF64 && !IsEH) ? 8 : 4, &Offset);
     bool IsCIE =
         ((IsDWARF64 && Id == DW64_CIE_ID) || Id == DW_CIE_ID || (IsEH && !Id));
 

diff  --git a/llvm/test/DebugInfo/debug-frame-cie-pointer-reloc.test b/llvm/test/DebugInfo/debug-frame-cie-pointer-reloc.test
new file mode 100644
index 000000000000..59fa273d8816
--- /dev/null
+++ b/llvm/test/DebugInfo/debug-frame-cie-pointer-reloc.test
@@ -0,0 +1,41 @@
+# RUN: yaml2obj %s -o - | \
+# RUN:   llvm-dwarfdump -debug-frame - | \
+# RUN:   FileCheck %s
+
+## This checks that we resolve relocations when reading CIE pointers.
+## The second FDE references the second CIE. The value for the CIE pointer
+## field in the raw section data is 0, thus, to recover the real reference,
+## it is required to read the addend from the corresponding RELA relocation.
+
+# CHECK: .debug_frame contents:
+# CHECK: 00000000 0000000c ffffffff CIE
+# CHECK: 00000010 00000014 00000000 FDE cie=00000000 pc=00000000...00000001
+# CHECK: 00000028 0000000c ffffffff CIE
+# CHECK: 00000038 00000014 00000028 FDE cie=00000028 pc=00000010...00000011
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections:
+  - Name:    .debug_frame
+    Type:    SHT_PROGBITS
+    Content: 0C000000FFFFFFFF02000178100000001400000000000000000000000000000001000000000000000C000000FFFFFFFF0200017810000000140000000000000010000000000000000100000000000000
+  - Name:    .rela.debug_frame
+    Type:    SHT_RELA
+    Info:    .debug_frame
+    Relocations:
+      - Offset: 0x0000000000000014
+        Symbol: .debug_frame
+        Type:   R_X86_64_32
+      - Offset: 0x000000000000003C
+        Symbol: .debug_frame
+        Type:   R_X86_64_32
+        Addend: 0x28
+Symbols:
+  - Name:    .debug_frame
+    Type:    STT_SECTION
+    Section: .debug_frame
+...


        


More information about the llvm-commits mailing list