[PATCH] D67097: [DWARF] Check for format mismatch between CU and Range List Table.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 07:13:06 PDT 2019


ikudrin created this revision.
ikudrin added reviewers: dblaikie, aprantl, probinson, MaskRay.
ikudrin added projects: debug-info, LLVM.
ikudrin added a parent revision: D66643: [DWARF] Support DWARF64 in DWARFListTableHeader..

As stated in section 7.4, p. 198 of DWARF Standard Version 5, "The 32-bit and 64-bit DWARF format conventions must not be intermixed within a single compilation unit."


Repository:
  rL LLVM

https://reviews.llvm.org/D67097

Files:
  lib/DebugInfo/DWARF/DWARFUnit.cpp
  test/DebugInfo/X86/debuginfo-rnglists-format-mismatch.s


Index: test/DebugInfo/X86/debuginfo-rnglists-format-mismatch.s
===================================================================
--- /dev/null
+++ test/DebugInfo/X86/debuginfo-rnglists-format-mismatch.s
@@ -0,0 +1,40 @@
+# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \
+# RUN:   llvm-dwarfdump -debug-info - 2>&1 > /dev/null | \
+# RUN:   FileCheck %s
+
+        .section .debug_abbrev.dwo,"", at progbits
+        .byte 0x01  # Abbrev code
+        .byte 0x11  # DW_TAG_compile_unit
+        .byte 0x00  # DW_CHILDREN_no
+        .byte 0x55  # DW_AT_ranges
+        .byte 0x23  # DW_FORM_rnglistx
+        .byte 0x00  # EOM(1)
+        .byte 0x00  # EOM(2)
+        .byte 0x00  # EOM(3)
+
+        .section .debug_info.dwo,"", at progbits
+        .long .LCUend - .LCUversion  # Length of Unit
+.LCUversion:
+        .short 5               # DWARF version number
+        .byte 5                # DW_UT_split_compile
+        .byte 4                # Address Size (in bytes)
+        .long 0                # Offset Into Abbrev Section
+        .byte 1                # Abbreviation code
+        .uleb128 0             # DW_AT_ranges
+.LCUend:
+
+        .section .debug_rnglists.dwo,"", at progbits
+        .long 0xffffffff                # DWARF64 mark
+        .quad .LRTend - .LRTversion     # table length
+.LRTversion:
+        .short 5                        # version
+        .byte 4                         # address size
+        .byte 0                         # segment selector size
+        .long 1                         # offset entry count
+.LRTbase:
+        .quad .LRTlist0 - .LRTbase
+.LRTlist0:
+        .byte 0                                     # DW_RLE_end_of_list
+.LRTend:
+
+# CHECK: error: parsing a range list table: Mismatched DWARF formats between CU and range list table with base = 0x0
Index: lib/DebugInfo/DWARF/DWARFUnit.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -306,7 +306,9 @@
 // Parse the rangelist table header, including the optional array of offsets
 // following it (DWARF v5 and later).
 static Expected<DWARFDebugRnglistTable>
-parseRngListTableHeader(DWARFDataExtractor &DA, uint64_t Offset) {
+parseRngListTableHeader(DWARFDataExtractor &DA, uint64_t Offset,
+                        DwarfFormat Format) {
+  const uint64_t OffsetIn = Offset;
   // TODO: Support DWARF64
   // We are expected to be called with Offset 0 or pointing just past the table
   // header, which is 12 bytes long for DWARF32.
@@ -320,6 +322,11 @@
   llvm::DWARFDebugRnglistTable Table;
   if (Error E = Table.extractHeaderAndOffsets(DA, &Offset))
     return std::move(E);
+  if (Format != Table.getFormat())
+    return createStringError(errc::invalid_argument,
+                             "Mismatched DWARF formats between CU and range "
+                             "list table with base = 0x%" PRIx64 "\n",
+                             OffsetIn);
   return Table;
 }
 
@@ -469,8 +476,8 @@
       // extracted lazily.
       DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
                                   isLittleEndian, 0);
-      auto TableOrError =
-              parseRngListTableHeader(RangesDA, RangeSectionBase);
+      auto TableOrError = parseRngListTableHeader(RangesDA, RangeSectionBase,
+                                                  Header.getFormat());
       if (!TableOrError)
         return createStringError(errc::invalid_argument,
                                  "parsing a range list table: " +
@@ -525,7 +532,8 @@
     DWO->setRangesSection(&Context.getDWARFObj().getRnglistsDWOSection(), 0);
     DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
                                 isLittleEndian, 0);
-    if (auto TableOrError = parseRngListTableHeader(RangesDA, RangeSectionBase))
+    if (auto TableOrError = parseRngListTableHeader(RangesDA, RangeSectionBase,
+                                                    Header.getFormat()))
       DWO->RngListTable = TableOrError.get();
     else
       WithColor::error() << "parsing a range list table: "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67097.218449.patch
Type: text/x-patch
Size: 4181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190903/0ed1852d/attachment.bin>


More information about the llvm-commits mailing list