Index: llvm/lib/MC/MCDwarf.cpp =================================================================== --- llvm/lib/MC/MCDwarf.cpp +++ llvm/lib/MC/MCDwarf.cpp @@ -954,11 +954,19 @@ // First part: the header. - // The 4 byte total length of the information for this compilation unit, not - // including these 4 bytes. + unsigned UnitLengthBytes = + dwarf::getUnitLengthFieldByteSize(context.getDwarfFormat()); + unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(context.getDwarfFormat()); + + if (context.getDwarfFormat() == dwarf::DWARF64) + // Emit DWARF64 mark. + MCOS->emitInt32(dwarf::DW_LENGTH_DWARF64); + + // The 4 (8 for DWARF64) byte total length of the information for this + // compilation unit, not including the unit length field itself. const MCExpr *Length = - MakeStartMinusEndExpr(context, *InfoStart, *InfoEnd, 4); - emitAbsValue(*MCOS, Length, 4); + MakeStartMinusEndExpr(context, *InfoStart, *InfoEnd, UnitLengthBytes); + emitAbsValue(*MCOS, Length, OffsetSize); // The 2 byte DWARF version. MCOS->emitInt16(context.getDwarfVersion()); @@ -971,12 +979,12 @@ MCOS->emitInt8(dwarf::DW_UT_compile); MCOS->emitInt8(AddrSize); } - // The 4 byte offset to the debug abbrevs from the start of the .debug_abbrev, - // it is at the start of that section so this is zero. + // The 4 (8 for DWARF64) byte offset to the debug abbrevs from the start of + // the .debug_abbrev, it is at the start of that section so this is zero. if (AbbrevSectionSymbol == nullptr) - MCOS->emitInt32(0); + MCOS->emitIntValue(0, OffsetSize); else - MCOS->emitSymbolValue(AbbrevSectionSymbol, 4, + MCOS->emitSymbolValue(AbbrevSectionSymbol, OffsetSize, AsmInfo.needsDwarfSectionOffsetDirective()); if (context.getDwarfVersion() <= 4) MCOS->emitInt8(AddrSize); @@ -986,13 +994,13 @@ // The DW_TAG_compile_unit DIE abbrev (1). MCOS->emitULEB128IntValue(1); - // DW_AT_stmt_list, a 4 byte offset from the start of the .debug_line section, - // which is at the start of that section so this is zero. + // DW_AT_stmt_list, a 4 (8 for DWARF64) byte offset from the start of the + // .debug_line section, which is at the start of that section so this is zero. if (LineSectionSymbol) - MCOS->emitSymbolValue(LineSectionSymbol, 4, + MCOS->emitSymbolValue(LineSectionSymbol, OffsetSize, AsmInfo.needsDwarfSectionOffsetDirective()); else - MCOS->emitInt32(0); + MCOS->emitIntValue(0, OffsetSize); if (RangesSymbol) { // There are multiple sections containing code, so we must use Index: llvm/test/MC/ELF/gen-dwarf64.s =================================================================== --- llvm/test/MC/ELF/gen-dwarf64.s +++ llvm/test/MC/ELF/gen-dwarf64.s @@ -6,10 +6,19 @@ ## The references to other debug info sections are 64-bit, as required for DWARF64. # REL: Relocations [ +# 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: Section ({{[0-9]+}}) .rela.debug_line { # REL5-NEXT: R_X86_64_64 .debug_line_str 0x0 # REL5-NEXT: R_X86_64_64 .debug_line_str 0x +# DUMP: .debug_info contents: +# DUMP-NEXT: 0x00000000: Compile Unit: +# DUMP-SAME: format = DWARF64 +# DUMP: DW_TAG_compile_unit [1] * +# DUMP5-NEXT: DW_AT_stmt_list [DW_FORM_sec_offset] (0x0000000000000000) + # DUMP: .debug_line contents: # DUMP-NEXT: debug_line[0x00000000] # DUMP-NEXT: Line table prologue: @@ -23,3 +32,7 @@ # DUMP5: .debug_line_str contents: # DUMP5-NEXT: 0x00000000: "[[DIR]]" # DUMP5-NEXT: 0x[[FILEOFF]]: "[[FILE]]" + + .section .foo, "ax", @progbits +foo: + nop