[llvm] 6f635f9 - [DWARF] Check that all fields of a Unit Header are read.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 23 18:39:23 PST 2019


Author: Igor Kudrin
Date: 2019-12-24T09:38:20+07:00
New Revision: 6f635f90929da9545dd696071a829a1a42f84b30

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

LOG: [DWARF] Check that all fields of a Unit Header are read.

Tests "dwarfdump-rnglists-dwarf64.s" and "dwarfdump-rnglists.s" were
malformed because they had missing required DWO ID fields in split
compilation unit headers. The patch fixes the tests and checks
the reading of a unit header more thoroughly.

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

Added: 
    llvm/test/DebugInfo/X86/invalid-unit-header.s

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
    llvm/test/DebugInfo/X86/dwarfdump-rnglists-dwarf64.s
    llvm/test/DebugInfo/X86/dwarfdump-rnglists.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index 9586d5aca1a9..7bb019466161 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -259,23 +259,26 @@ bool DWARFUnitHeader::extract(DWARFContext &Context,
                               const DWARFUnitIndex *Index,
                               const DWARFUnitIndex::Entry *Entry) {
   Offset = *offset_ptr;
+  Error Err = Error::success();
   IndexEntry = Entry;
   if (!IndexEntry && Index)
     IndexEntry = Index->getFromOffset(*offset_ptr);
-  Length = debug_info.getRelocatedValue(4, offset_ptr);
+  Length = debug_info.getRelocatedValue(4, offset_ptr, nullptr, &Err);
   FormParams.Format = DWARF32;
   if (Length == dwarf::DW_LENGTH_DWARF64) {
-    Length = debug_info.getU64(offset_ptr);
+    Length = debug_info.getU64(offset_ptr, &Err);
     FormParams.Format = DWARF64;
   }
-  FormParams.Version = debug_info.getU16(offset_ptr);
+  FormParams.Version = debug_info.getU16(offset_ptr, &Err);
   if (FormParams.Version >= 5) {
-    UnitType = debug_info.getU8(offset_ptr);
-    FormParams.AddrSize = debug_info.getU8(offset_ptr);
-    AbbrOffset = debug_info.getRelocatedValue(FormParams.getDwarfOffsetByteSize(), offset_ptr);
+    UnitType = debug_info.getU8(offset_ptr, &Err);
+    FormParams.AddrSize = debug_info.getU8(offset_ptr, &Err);
+    AbbrOffset = debug_info.getRelocatedValue(
+        FormParams.getDwarfOffsetByteSize(), offset_ptr, nullptr, &Err);
   } else {
-    AbbrOffset = debug_info.getRelocatedValue(FormParams.getDwarfOffsetByteSize(), offset_ptr);
-    FormParams.AddrSize = debug_info.getU8(offset_ptr);
+    AbbrOffset = debug_info.getRelocatedValue(
+        FormParams.getDwarfOffsetByteSize(), offset_ptr, nullptr, &Err);
+    FormParams.AddrSize = debug_info.getU8(offset_ptr, &Err);
     // Fake a unit type based on the section type.  This isn't perfect,
     // but distinguishing compile and type units is generally enough.
     if (SectionKind == DW_SECT_TYPES)
@@ -295,11 +298,14 @@ bool DWARFUnitHeader::extract(DWARFContext &Context,
     AbbrOffset = AbbrEntry->Offset;
   }
   if (isTypeUnit()) {
-    TypeHash = debug_info.getU64(offset_ptr);
-    TypeOffset =
-        debug_info.getUnsigned(offset_ptr, FormParams.getDwarfOffsetByteSize());
+    TypeHash = debug_info.getU64(offset_ptr, &Err);
+    TypeOffset = debug_info.getUnsigned(
+        offset_ptr, FormParams.getDwarfOffsetByteSize(), &Err);
   } else if (UnitType == DW_UT_split_compile || UnitType == DW_UT_skeleton)
-    DWOId = debug_info.getU64(offset_ptr);
+    DWOId = debug_info.getU64(offset_ptr, &Err);
+
+  if (errorToBool(std::move(Err)))
+    return false;
 
   // Header fields all parsed, capture the size of this unit header.
   assert(*offset_ptr - Offset <= 255 && "unexpected header size");

diff  --git a/llvm/test/DebugInfo/X86/dwarfdump-rnglists-dwarf64.s b/llvm/test/DebugInfo/X86/dwarfdump-rnglists-dwarf64.s
index 19bbd77586d8..43b3953658d3 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-rnglists-dwarf64.s
+++ b/llvm/test/DebugInfo/X86/dwarfdump-rnglists-dwarf64.s
@@ -109,6 +109,7 @@ CU_split_5_64_version:
         .byte 5                # DWARF Unit Type
         .byte 4                # Address Size (in bytes)
         .quad 0                # Offset Into Abbrev Section
+        .quad 0xdeadbeefbaadf00d  # DWO id
 # The compile-unit DIE, which has DW_AT_rnglists_base and DW_AT_ranges.
         .byte 1                # Abbreviation code
         .uleb128 1             # DW_AT_ranges

diff  --git a/llvm/test/DebugInfo/X86/dwarfdump-rnglists.s b/llvm/test/DebugInfo/X86/dwarfdump-rnglists.s
index 0d6898df170b..3c91799001a0 100644
--- a/llvm/test/DebugInfo/X86/dwarfdump-rnglists.s
+++ b/llvm/test/DebugInfo/X86/dwarfdump-rnglists.s
@@ -106,6 +106,7 @@ CU_split_5_version:
         .byte 5                # DWARF Unit Type
         .byte 4                # Address Size (in bytes)
         .long 0                # Offset Into Abbrev Section
+        .quad 0xdeadbeefbaadf00d  # DWO id
 # The compile-unit DIE, which has DW_AT_rnglists_base and DW_AT_ranges.
         .byte 1                # Abbreviation code
         .uleb128 1             # DW_AT_ranges

diff  --git a/llvm/test/DebugInfo/X86/invalid-unit-header.s b/llvm/test/DebugInfo/X86/invalid-unit-header.s
new file mode 100644
index 000000000000..ce8467902d03
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/invalid-unit-header.s
@@ -0,0 +1,29 @@
+# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \
+# RUN:   llvm-dwarfdump -debug-info - | \
+# 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 0x13  # DW_AT_language
+        .byte 0x05  # DW_FORM_data2
+        .byte 0x00  # EOM(1)
+        .byte 0x00  # EOM(2)
+        .byte 0x00  # EOM(3)
+
+# The CU was considered valid even though there were some required fields
+# missing in the header.
+        .section .debug_info.dwo,"", at progbits
+        .long .CUend - .CUver   # Length of Unit
+.CUver:
+        .short 5                # DWARF version number
+        .byte 5                 # DW_UT_split_compile
+        .byte 4                 # Address Size (in bytes)
+        # .long 0               # Missing: Offset Into Abbrev Section
+        # .quad 0               # Missing: DWO id
+        .byte 1                 # Abbreviation code
+        .short 4                # DW_LANG_C_plus_plus
+.CUend:
+
+# CHECK-NOT: Compile Unit:


        


More information about the llvm-commits mailing list