From 489d67927172941bf59b9f4829ab8910814fea24 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 28 Feb 2012 21:13:05 +0000 Subject: On ELF, create relocations to the abbreviation and line sections when producing debug info for assembly files. We were already doing the right thing when producing debug info for C/C++. ELF linkers don't know dwarf, so they depend on these relocations to produce valid dwarf output. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151655 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCAsmStreamer.cpp | 6 ++++-- lib/MC/MCDwarf.cpp | 33 +++++++++++++++++++++++++++------ lib/MC/MCObjectStreamer.cpp | 5 +++-- 3 files changed, 34 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index f7c6765ff3..742d15d9e7 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -1309,13 +1309,15 @@ void MCAsmStreamer::EmitRawText(StringRef String) { } void MCAsmStreamer::FinishImpl() { + // FIXME: This header is duplicated with MCObjectStreamer // Dump out the dwarf file & directory tables and line tables. + const MCSymbol *LineSectionSymbol; if (getContext().hasDwarfFiles() && !UseLoc) - MCDwarfFileTable::Emit(this); + LineSectionSymbol = MCDwarfFileTable::Emit(this); // If we are generating dwarf for assembly source files dump out the sections. if (getContext().getGenDwarfForAssembly()) - MCGenDwarfInfo::Emit(this); + MCGenDwarfInfo::Emit(this, LineSectionSymbol); if (!UseCFI) EmitFrames(false); diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp index 614549e523..e16f7aea07 100644 --- a/lib/MC/MCDwarf.cpp +++ b/lib/MC/MCDwarf.cpp @@ -209,7 +209,7 @@ static inline void EmitDwarfLineTable(MCStreamer *MCOS, // // This emits the Dwarf file and the line tables. // -void MCDwarfFileTable::Emit(MCStreamer *MCOS) { +const MCSymbol *MCDwarfFileTable::Emit(MCStreamer *MCOS) { MCContext &context = MCOS->getContext(); // Switch to the section where the table will be emitted into. MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection()); @@ -322,6 +322,8 @@ void MCDwarfFileTable::Emit(MCStreamer *MCOS) { // This is the end of the section, so set the value of the symbol at the end // of this section (that was used in a previous expression). MCOS->EmitLabel(LineEndSym); + + return LineStartSym; } /// Utility function to write the encoding to an object writer. @@ -545,7 +547,9 @@ static void EmitGenDwarfAranges(MCStreamer *MCOS) { // When generating dwarf for assembly source files this emits the data for // .debug_info section which contains three parts. The header, the compile_unit // DIE and a list of label DIEs. -static void EmitGenDwarfInfo(MCStreamer *MCOS) { +static void EmitGenDwarfInfo(MCStreamer *MCOS, + const MCSymbol *AbbrevSectionSymbol, + const MCSymbol *LineSectionSymbol) { MCContext &context = MCOS->getContext(); MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); @@ -568,7 +572,11 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS) { // 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. - MCOS->EmitIntValue(0, 4); + if (AbbrevSectionSymbol) { + MCOS->EmitSymbolValue(AbbrevSectionSymbol, 4); + } else { + MCOS->EmitIntValue(0, 4); + } const MCAsmInfo &asmInfo = context.getAsmInfo(); int AddrSize = asmInfo.getPointerSize(); @@ -582,7 +590,11 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS) { // 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. - MCOS->EmitIntValue(0, 4); + if (LineSectionSymbol) { + MCOS->EmitSymbolValue(LineSectionSymbol, 4); + } else { + MCOS->EmitIntValue(0, 4); + } // AT_low_pc, the first address of the default .text section. const MCExpr *Start = MCSymbolRefExpr::Create( @@ -686,11 +698,20 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS) { // When generating dwarf for assembly source files this emits the Dwarf // sections. // -void MCGenDwarfInfo::Emit(MCStreamer *MCOS) { +void MCGenDwarfInfo::Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol) { // Create the dwarf sections in this order (.debug_line already created). MCContext &context = MCOS->getContext(); + const MCAsmInfo &AsmInfo = context.getAsmInfo(); MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection()); MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfAbbrevSection()); + MCSymbol *AbbrevSectionSymbol; + if (AsmInfo.doesDwarfRequireRelocationForSectionOffset()) { + AbbrevSectionSymbol = context.CreateTempSymbol(); + MCOS->EmitLabel(AbbrevSectionSymbol); + } else { + AbbrevSectionSymbol = NULL; + LineSectionSymbol = NULL; + } MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfARangesSection()); // If there are no line table entries then do not emit any section contents. @@ -704,7 +725,7 @@ void MCGenDwarfInfo::Emit(MCStreamer *MCOS) { EmitGenDwarfAbbrev(MCOS); // Output the data for .debug_info section. - EmitGenDwarfInfo(MCOS); + EmitGenDwarfInfo(MCOS, AbbrevSectionSymbol, LineSectionSymbol); } // diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index f2911fa07b..a7eb8b03a2 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -266,12 +266,13 @@ void MCObjectStreamer::EmitGPRel32Value(const MCExpr *Value) { void MCObjectStreamer::FinishImpl() { // Dump out the dwarf file & directory tables and line tables. + const MCSymbol *LineSectionSymbol; if (getContext().hasDwarfFiles()) - MCDwarfFileTable::Emit(this); + LineSectionSymbol = MCDwarfFileTable::Emit(this); // If we are generating dwarf for assembly source files dump out the sections. if (getContext().getGenDwarfForAssembly()) - MCGenDwarfInfo::Emit(this); + MCGenDwarfInfo::Emit(this, LineSectionSymbol); getAssembler().Finish(); } -- cgit v1.2.3