[PATCH] D78971: [llvm/DebugInfo] Fix invalid verifier error for DWARF5

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 16:44:35 PDT 2020


JDevlieghere created this revision.
JDevlieghere added reviewers: aprantl, dblaikie, probinson.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
JDevlieghere edited the summary of this revision.

We were unconditionally comparing the DW_AT_ranges offset to the length of the .debug_ranges section. For DWARF5 we should look at the debug_rnglists section instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78971

Files:
  llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp


Index: llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -2013,6 +2013,45 @@
       "error: DW_AT_ranges offset is beyond .debug_ranges bounds: 0x00001000");
 }
 
+TEST(DWARFDebugInfo, TestDwarfVerifyInvalidRnglists) {
+  // Create a single compile unit with a DW_AT_ranges whose section offset
+  // isn't valid.
+  const char *yamldata = R"(
+    debug_str:
+      - ''
+      - /tmp/main.c
+    debug_abbrev:
+      - Code:            0x00000001
+        Tag:             DW_TAG_compile_unit
+        Children:        DW_CHILDREN_no
+        Attributes:
+          - Attribute:       DW_AT_name
+            Form:            DW_FORM_strp
+          - Attribute:       DW_AT_ranges
+            Form:            DW_FORM_sec_offset
+    debug_info:
+      - Length:
+          TotalLength:     17
+        Version:         5
+        UnitType:        DW_UT_compile
+        AbbrOffset:      0
+        AddrSize:        8
+        Entries:
+          - AbbrCode:        0x00000001
+            Values:
+              - Value:           0x0000000000000001
+              - Value:           0x0000000000001000
+
+  )";
+  auto ErrOrSections = DWARFYAML::EmitDebugSections(StringRef(yamldata));
+  ASSERT_TRUE((bool)ErrOrSections);
+  std::unique_ptr<DWARFContext> DwarfContext =
+      DWARFContext::create(*ErrOrSections, 8);
+  VerifyError(
+      *DwarfContext,
+      "error: DW_AT_ranges offset is beyond .debug_rnglists bounds: 0x00001000");
+}
+
 TEST(DWARFDebugInfo, TestDwarfVerifyInvalidStmtList) {
   // Create a single compile unit with a DW_AT_stmt_list whose section offset
   // isn't valid.
Index: llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
@@ -457,9 +457,15 @@
   case DW_AT_ranges:
     // Make sure the offset in the DW_AT_ranges attribute is valid.
     if (auto SectionOffset = AttrValue.Value.getAsSectionOffset()) {
-      if (*SectionOffset >= DObj.getRangesSection().Data.size())
-        ReportError("DW_AT_ranges offset is beyond .debug_ranges bounds: " +
-                    llvm::formatv("{0:x8}", *SectionOffset));
+      unsigned DwarfVersion = Die.getDwarfUnit()->getVersion();
+      const DWARFSection &RangeSection = DwarfVersion < 5
+                                             ? DObj.getRangesSection()
+                                             : DObj.getRnglistsSection();
+      if (*SectionOffset >= RangeSection.Data.size())
+        ReportError(
+            "DW_AT_ranges offset is beyond " +
+            StringRef(DwarfVersion < 5 ? ".debug_ranges" : ".debug_rnglists") +
+            " bounds: " + llvm::formatv("{0:x8}", *SectionOffset));
       break;
     }
     ReportError("DIE has invalid DW_AT_ranges encoding:");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78971.260496.patch
Type: text/x-patch
Size: 3024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200427/7d8ebee3/attachment.bin>


More information about the llvm-commits mailing list