Mucking about simplifying a test case ( https://reviews.llvm.org/D55261 ) I stumbled across something I've hit before - that LLVM's (GCC's does too, FWIW) assembly output includes a hardcode length for a DWARF unit in its header. Instead we could emit a label difference - making the assembly easier to read/edit (though potentially at a slight (I haven't tried to observe it) performance cost of delaying/sinking the length computation into the MC layer).
Reviewers: JDevlieghere, probinson, ABataev
Differential Revision: https://reviews.llvm.org/D55281
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348806
91177308-0d34-0410-b5e6-
96231b3b80d8
TheU->emitHeader(UseOffsets);
Asm->emitDwarfDIE(Die);
+
+ Asm->OutStreamer->EmitLabel(TheU->getEndLabel());
}
// Compute the size and offset for each DIE.
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cstdint>
#include <string>
void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) {
// Emit size of content not including length itself
Asm->OutStreamer->AddComment("Length of Unit");
- Asm->emitInt32(getHeaderSize() + getUnitDie().getSize());
+ StringRef Prefix = isDwoUnit() ? "debug_info_dwo_" : "debug_info_";
+ MCSymbol *BeginLabel = Asm->createTempSymbol(Prefix + "start");
+ EndLabel = Asm->createTempSymbol(Prefix + "end");
+
+ // Use a label difference for the convenience of legible/easily modified
+ // assembly - except on NVPTX where label differences aren't supported.
+ if (Asm->TM.getTargetTriple().isNVPTX())
+ Asm->emitInt32(getHeaderSize() + getUnitDie().getSize());
+ else
+ Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
+ Asm->OutStreamer->EmitLabel(BeginLabel);
Asm->OutStreamer->AddComment("DWARF version number");
unsigned Version = DD->getDwarfVersion();
/// Target of Dwarf emission.
AsmPrinter *Asm;
+ MCSymbol *EndLabel;
// Holders for some common dwarf information.
DwarfDebug *DD;
public:
// Accessors.
AsmPrinter* getAsmPrinter() const { return Asm; }
+ MCSymbol *getEndLabel() const { return EndLabel; }
uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
const DICompileUnit *getCUNode() const { return CUNode; }
; CHECK-NOT: .L
; CHECK: .section .debug_info
-; CHECK-NOT: .L
-; CHECK: .short 2 # DWARF version number
+; CHECK-NEXT: .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+; CHECK-NEXT: .Ldebug_info_start0:
+; CHECK-NEXT: .short 2 # DWARF version number
; CHECK-NOT: .L
; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section
; CHECK-NOT: .L
; CHECK: .long .debug_line # DW_AT_stmt_list
; CHECK-NOT: .L
+; CHECK: .Ldebug_info_end0:
+; CHECK-NOT: .L
+; CHECK: .long .Ldebug_info_end1-.Ldebug_info_start1 # Length of Unit
+; CHECK-NEXT: .Ldebug_info_start1:
+; CHECK-NOT: .L
; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section
; CHECK-NOT: .L
; CHECK: .long .debug_line # DW_AT_stmt_list
; CHECK: .quad .debug_info+{{[0-9]+}} # DW_AT_type
; CHECK-NOT: .L
; CHECK: .byte 0 # End Of Children Mark
+; CHECK-NEXT: .Ldebug_info_end1:
; CHECK-NOT: .L
source_filename = "test/DebugInfo/X86/sections_as_references.ll"