Index: llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h =================================================================== --- llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h +++ llvm/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h @@ -139,6 +139,8 @@ bool parse(DataExtractor IndexData); void dump(raw_ostream &OS) const; + uint32_t getVersion() const { return Header.Version; } + const Entry *getFromOffset(uint32_t Offset) const; const Entry *getFromHash(uint64_t Offset) const; Index: llvm/test/tools/llvm-dwp/X86/unsupported_cu_index_version.s =================================================================== --- /dev/null +++ llvm/test/tools/llvm-dwp/X86/unsupported_cu_index_version.s @@ -0,0 +1,50 @@ +# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o %t.dwp +# RUN: not llvm-dwp %t.dwp -o %t 2>&1 | FileCheck %s + +# CHECK: error: unsupported cu_index version + +.section .debug_abbrev.dwo, "e", @progbits +.LAbbrevBegin: + .uleb128 1 # Abbreviation Code + .uleb128 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_no + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) +.LAbbrevEnd: + + .section .debug_info.dwo, "e", @progbits +.LCUBegin: + .long .LCUEnd-.LCUVersion # Length of Unit +.LCUVersion: + .short 5 # Version + .byte 5 # DW_UT_split_compile + .byte 8 # Address size + .long 0 # Abbrev offset + .quad 0x1100001122222222 # DWO id + .uleb128 1 # Abbrev [1] DW_TAG_compile_unit +.LCUEnd: + + .section .debug_cu_index, "", @progbits +## Header: + .short 5 # Version + .space 2 # Padding + .long 2 # Section count + .long 1 # Unit count + .long 2 # Slot count +## Hash Table of Signatures: + .quad 0x1100001122222222 + .quad 0 +## Parallel Table of Indexes: + .long 1 + .long 0 +## Table of Section Offsets: +## Row 0: + .long 1 # DW_SECT_INFO + .long 3 # DW_SECT_ABBREV +## Row 1: + .long 0 # Offset in .debug_info.dwo + .long 0 # Offset in .debug_abbrev.dwo +## Table of Section Sizes: + .long .LCUEnd-.LCUBegin # Size in .debug_info.dwo + .long .LAbbrevEnd-.LAbbrevBegin # Size in .debug_abbrev.dwo Index: llvm/tools/llvm-dwp/llvm-dwp.cpp =================================================================== --- llvm/tools/llvm-dwp/llvm-dwp.cpp +++ llvm/tools/llvm-dwp/llvm-dwp.cpp @@ -612,6 +612,8 @@ DataExtractor CUIndexData(CurCUIndexSection, Obj.isLittleEndian(), 0); if (!CUIndex.parse(CUIndexData)) return make_error("failed to parse cu_index"); + if (CUIndex.getVersion() != 2) + return make_error("unsupported cu_index version"); for (const DWARFUnitIndex::Entry &E : CUIndex.getRows()) { auto *I = E.getOffsets(); @@ -647,6 +649,8 @@ DataExtractor TUIndexData(CurTUIndexSection, Obj.isLittleEndian(), 0); if (!TUIndex.parse(TUIndexData)) return make_error("failed to parse tu_index"); + if (TUIndex.getVersion() != 2) + return make_error("unsupported tu_index version"); addAllTypesFromDWP( Out, TypeIndexEntries, TUIndex, TypesSection, CurTypesSection.front(), CurEntry,