Index: llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -329,7 +329,7 @@ template static Expected parseListTableHeader(DWARFDataExtractor &DA, uint64_t Offset, - DwarfFormat Format) { + DwarfFormat Format, uint64_t CUOffset) { // We are expected to be called with Offset 0 or pointing just past the table // header. Correct Offset in the latter case so that it points to the start // of the header. @@ -342,8 +342,15 @@ Offset -= HeaderSize; } ListTableType Table; + uint64_t StartOffset = Offset; 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 at offset 0x%" PRIx64 " " + "and list table with base = 0x%" PRIx64 "\n", + CUOffset, StartOffset); return Table; } @@ -497,7 +504,7 @@ DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection, isLittleEndian, 0); auto TableOrError = parseListTableHeader( - RangesDA, RangeSectionBase, Header.getFormat()); + RangesDA, RangeSectionBase, Header.getFormat(), Header.getOffset()); if (!TableOrError) return createStringError(errc::invalid_argument, "parsing a range list table: " + @@ -587,7 +594,7 @@ DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection, isLittleEndian, 0); if (auto TableOrError = parseListTableHeader( - RangesDA, RangeSectionBase, Header.getFormat())) + RangesDA, RangeSectionBase, Header.getFormat(), Header.getOffset())) DWO->RngListTable = TableOrError.get(); else WithColor::error() << "parsing a range list table: " Index: llvm/test/DebugInfo/X86/dwarfdump-rnglists-format-mismatch.s =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/dwarfdump-rnglists-format-mismatch.s @@ -0,0 +1,42 @@ +# 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,"",@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,"",@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 + .quad 0 # DWO Id + .byte 1 # Abbreviation code + .uleb128 0 # DW_AT_ranges +.LCUend: + + .section .debug_rnglists.dwo,"",@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 +# CHECK-SAME: CU at offset 0x0 and list table with base = 0x0