Index: llvm/lib/MC/MCDwarf.cpp =================================================================== --- llvm/lib/MC/MCDwarf.cpp +++ llvm/lib/MC/MCDwarf.cpp @@ -50,8 +50,14 @@ S.getContext().createTempSymbol("debug_list_header_start", true, true); MCSymbol *End = S.getContext().createTempSymbol("debug_list_header_end", true, true); + auto DwarfFormat = S.getContext().getDwarfFormat(); + if (DwarfFormat == dwarf::DWARF64) { + S.AddComment("DWARF64 mark"); + S.emitInt32(dwarf::DW_LENGTH_DWARF64); + } S.AddComment("Length"); - S.emitAbsoluteSymbolDiff(End, Start, 4); + S.emitAbsoluteSymbolDiff(End, Start, + dwarf::getDwarfOffsetByteSize(DwarfFormat)); S.emitLabel(Start); S.AddComment("Version"); S.emitInt16(S.getContext().getDwarfVersion()); @@ -1012,9 +1018,9 @@ if (RangesSymbol) { // There are multiple sections containing code, so we must use - // .debug_ranges/.debug_rnglists. AT_ranges, the 4 byte offset from the + // .debug_ranges/.debug_rnglists. AT_ranges, the 4/8 byte offset from the // start of the .debug_ranges/.debug_rnglists. - MCOS->emitSymbolValue(RangesSymbol, 4); + MCOS->emitSymbolValue(RangesSymbol, OffsetSize); } else { // If we only have one non-empty code section, we can use the simpler // AT_low_pc and AT_high_pc attributes. Index: llvm/test/MC/ELF/gen-dwarf64.s =================================================================== --- llvm/test/MC/ELF/gen-dwarf64.s +++ llvm/test/MC/ELF/gen-dwarf64.s @@ -9,6 +9,7 @@ # REL: Section ({{[0-9]+}}) .rela.debug_info { # REL-NEXT: R_X86_64_64 .debug_abbrev 0x0 # REL-NEXT: R_X86_64_64 .debug_line 0x0 +# REL5-NEXT: R_X86_64_64 .debug_rnglists 0x14 # REL: Section ({{[0-9]+}}) .rela.debug_aranges { # REL-NEXT: R_X86_64_64 .debug_info 0x0 # REL5: Section ({{[0-9]+}}) .rela.debug_line { @@ -20,11 +21,15 @@ # DUMP-SAME: format = DWARF64 # DUMP: DW_TAG_compile_unit [1] * # DUMP5-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] (0x0000000000000000) +# DUMP5-NEXT: DW_AT_ranges [DW_FORM_sec_offset] (0x0000000000000014 +# DUMP-NEXT: [0x0000000000000000, 0x0000000000000001) ".foo" +# DUMP-NEXT: [0x0000000000000000, 0x0000000000000001) ".bar") # DUMP: .debug_aranges contents: # DUMP-NEXT: Address Range Header: # DUMP-SAME: format = DWARF64 # DUMP-NEXT: [0x0000000000000000, 0x0000000000000001) +# DUMP-NEXT: [0x0000000000000000, 0x0000000000000001) # DUMP-EMPTY: # DUMP: .debug_line contents: @@ -41,6 +46,18 @@ # DUMP5-NEXT: 0x00000000: "[[DIR]]" # DUMP5-NEXT: 0x[[FILEOFF]]: "[[FILE]]" +# DUMP5: .debug_rnglists contents: +# DUMP5-NEXT: 0x00000000: range list header: +# DUMP5-SAME: format = DWARF64 +# DUMP5-NEXT: ranges: +# DUMP5-NEXT: 0x00000014: [DW_RLE_start_length]: 0x0000000000000000, 0x0000000000000001 => [0x0000000000000000, 0x0000000000000001) +# DUMP5-NEXT: 0x0000001e: [DW_RLE_start_length]: 0x0000000000000000, 0x0000000000000001 => [0x0000000000000000, 0x0000000000000001) +# DUMP5-NEXT: 0x00000028: [DW_RLE_end_of_list ] + .section .foo, "ax", @progbits foo: nop + + .section .bar, "ax", @progbits +bar: + nop