diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index 7bc522154906..fa165cf2d402 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -811,12 +811,19 @@ DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA) { auto Offset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base), 0); Optional Descriptor; // Attempt to find a DWARF64 contribution 16 bytes before the base. - if (Offset >= 16) + switch (Header.getFormat()) { + case dwarf::DwarfFormat::DWARF64: + if (Offset < 16) + return None; Descriptor = parseDWARF64StringOffsetsTableHeader(DA, (uint32_t)Offset - 16); - // Try to find a DWARF32 contribution 8 bytes before the base. - if (!Descriptor && Offset >= 8) + break; + case dwarf::DwarfFormat::DWARF32: + if (Offset < 8) + return None; Descriptor = parseDWARF32StringOffsetsTableHeader(DA, (uint32_t)Offset - 8); + break; + } return Descriptor ? Descriptor->validateContributionSize(DA) : Descriptor; } diff --git a/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s b/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s index 1332a94ec3c7..10a810a350d1 100644 --- a/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s +++ b/llvm/test/DebugInfo/X86/dwarfdump-str-offsets-macho.s @@ -160,18 +160,19 @@ CU1_5_version: CU1_5_end: # DWARF v5 CU header - .long CU2_5_end-CU2_5_version # Length of Unit + .long 0xffffffff + .quad CU2_5_end-CU2_5_version # Length of Unit CU2_5_version: .short 5 # DWARF version number .byte 1 # DWARF Unit Type .byte 8 # Address Size (in bytes) - .long 0 # Offset Into Abbrev. Section + .quad 0 # Offset Into Abbrev. Section # The compile-unit DIE, which has a DW_AT_producer, DW_AT_name, # DW_AT_str_offsets and DW_AT_compdir. .byte 1 # Abbreviation code .byte 0 # The index of the producer string .byte 1 # The index of the CU name string - .long Ldebug_str_offsets_base1-Ldebug_str_offsets + .quad Ldebug_str_offsets_base1-Ldebug_str_offsets .byte 2 # The index of the comp dir string .byte 0 # NULL CU2_5_end: