summaryrefslogtreecommitdiff
path: root/lib/MC
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-04-01 07:35:52 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-04-01 07:35:52 +0000
commit5b2de5dd3d46b54788abe8ec920561484da44f02 (patch)
treeb02255d5201268b24ae0c8646202a3c345fe9d23 /lib/MC
parent75b7b95687477fd5338cf0684a4f3552fef5af0b (diff)
downloadllvm-5b2de5dd3d46b54788abe8ec920561484da44f02.tar.gz
llvm-5b2de5dd3d46b54788abe8ec920561484da44f02.tar.bz2
llvm-5b2de5dd3d46b54788abe8ec920561484da44f02.tar.xz
DebugInfo: Emit relocation to debug_line section when emitting asm for asm
I don't think this is reachable by any frontend (why would you transform asm to asm+debug info?) but it helps tidy up some of this code, avoid the weird special case of "emit the first CU, store the label, then emit the rest" in MCDwarfLineTable::Emit by instead having the DWARF-for-assembly case use the same codepath as DwarfDebug.cpp, by registering the label of the debug_line section, thus causing it to be emitted. (with a special case in asm output to just emit the label since asm output uses the .loc directives, etc, rather than the debug_loc directly) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/MCAsmStreamer.cpp15
-rw-r--r--lib/MC/MCDwarf.cpp37
-rw-r--r--lib/MC/MCObjectStreamer.cpp10
-rw-r--r--lib/MC/MCParser/AsmParser.cpp14
4 files changed, 44 insertions, 32 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp
index cc30d056a2..fa54c1a8da 100644
--- a/lib/MC/MCAsmStreamer.cpp
+++ b/lib/MC/MCAsmStreamer.cpp
@@ -1435,7 +1435,20 @@ void MCAsmStreamer::EmitRawTextImpl(StringRef String) {
void MCAsmStreamer::FinishImpl() {
// If we are generating dwarf for assembly source files dump out the sections.
if (getContext().getGenDwarfForAssembly())
- MCGenDwarfInfo::Emit(this, NULL);
+ MCGenDwarfInfo::Emit(this);
+
+ // Emit the label for the line table, if requested - since the rest of the
+ // line table will be defined by .loc/.file directives, and not emitted
+ // directly, the label is the only work required here.
+ auto &Tables = getContext().getMCDwarfLineTables();
+ if (!Tables.empty()) {
+ // FIXME: assert Tables.size() == 1 here, except that's not currently true
+ // due to DwarfUnit.cpp:2074.
+ if (auto *Label = Tables.begin()->second.getLabel()) {
+ SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
+ EmitLabel(Label);
+ }
+ }
if (!UseCFI)
EmitFrames(AsmBackend.get(), false);
diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp
index 5fa8f66422..231948eaff 100644
--- a/lib/MC/MCDwarf.cpp
+++ b/lib/MC/MCDwarf.cpp
@@ -204,24 +204,22 @@ EmitDwarfLineTable(MCStreamer *MCOS, const MCSection *Section,
//
// This emits the Dwarf file and the line tables.
//
-const MCSymbol *MCDwarfLineTable::Emit(MCStreamer *MCOS) {
+void MCDwarfLineTable::Emit(MCStreamer *MCOS) {
MCContext &context = MCOS->getContext();
- // CUID and MCLineTableSymbols are set in DwarfDebug, when DwarfDebug does
- // not exist, CUID will be 0 and MCLineTableSymbols will be empty.
- // Handle Compile Unit 0, the line table start symbol is the section symbol.
- auto I = MCOS->getContext().getMCDwarfLineTables().begin(),
- E = MCOS->getContext().getMCDwarfLineTables().end();
+ auto &LineTables = context.getMCDwarfLineTables();
+
+ // Bail out early so we don't switch to the debug_line section needlessly and
+ // in doing so create an unnecessary (if empty) section.
+ if (LineTables.empty())
+ return;
// Switch to the section where the table will be emitted into.
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfLineSection());
- const MCSymbol *LineStartSym = I->second.EmitCU(MCOS);
// Handle the rest of the Compile Units.
- for (++I; I != E; ++I)
- I->second.EmitCU(MCOS);
-
- return LineStartSym;
+ for (const auto &CUIDTablePair : LineTables)
+ CUIDTablePair.second.EmitCU(MCOS);
}
void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS) const {
@@ -320,10 +318,8 @@ MCDwarfLineTableHeader::Emit(MCStreamer *MCOS,
return std::make_pair(LineStartSym, LineEndSym);
}
-const MCSymbol *MCDwarfLineTable::EmitCU(MCStreamer *MCOS) const {
- MCSymbol *LineStartSym;
- MCSymbol *LineEndSym;
- std::tie(LineStartSym, LineEndSym) = Header.Emit(MCOS);
+void MCDwarfLineTable::EmitCU(MCStreamer *MCOS) const {
+ MCSymbol *LineEndSym = Header.Emit(MCOS).second;
// Put out the line tables.
for (const auto &LineSec : MCLineSections.getMCLineEntries())
@@ -344,8 +340,6 @@ const MCSymbol *MCDwarfLineTable::EmitCU(MCStreamer *MCOS) const {
// 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;
}
unsigned MCDwarfLineTable::getFile(StringRef &Directory, StringRef &FileName,
@@ -787,14 +781,17 @@ static void EmitGenDwarfInfo(MCStreamer *MCOS,
// When generating dwarf for assembly source files this emits the Dwarf
// sections.
//
-void MCGenDwarfInfo::Emit(MCStreamer *MCOS, const MCSymbol *LineSectionSymbol) {
+void MCGenDwarfInfo::Emit(MCStreamer *MCOS) {
// Create the dwarf sections in this order (.debug_line already created).
MCContext &context = MCOS->getContext();
const MCAsmInfo *AsmInfo = context.getAsmInfo();
bool CreateDwarfSectionSymbols =
AsmInfo->doesDwarfUseRelocationsAcrossSections();
- if (!CreateDwarfSectionSymbols)
- LineSectionSymbol = NULL;
+ MCSymbol *LineSectionSymbol = nullptr;
+ if (CreateDwarfSectionSymbols) {
+ LineSectionSymbol = context.CreateTempSymbol();
+ context.setMCLineTableSymbol(LineSectionSymbol, 0);
+ }
MCSymbol *AbbrevSectionSymbol = NULL;
MCSymbol *InfoSectionSymbol = NULL;
MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp
index 35786accb4..4451264cff 100644
--- a/lib/MC/MCObjectStreamer.cpp
+++ b/lib/MC/MCObjectStreamer.cpp
@@ -383,14 +383,12 @@ void MCObjectStreamer::EmitZeros(uint64_t NumBytes) {
}
void MCObjectStreamer::FinishImpl() {
- // Dump out the dwarf file & directory tables and line tables.
- const MCSymbol *LineSectionSymbol = NULL;
- if (getContext().hasMCLineSections())
- LineSectionSymbol = MCDwarfLineTable::Emit(this);
-
// If we are generating dwarf for assembly source files dump out the sections.
if (getContext().getGenDwarfForAssembly())
- MCGenDwarfInfo::Emit(this, LineSectionSymbol);
+ MCGenDwarfInfo::Emit(this);
+
+ // Dump out the dwarf file & directory tables and line tables.
+ MCDwarfLineTable::Emit(this);
getAssembler().Finish();
}
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp
index ac6ebbde7b..910a424ce8 100644
--- a/lib/MC/MCParser/AsmParser.cpp
+++ b/lib/MC/MCParser/AsmParser.cpp
@@ -661,11 +661,15 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
return TokError("unmatched .ifs or .elses");
// Check to see there are no empty DwarfFile slots.
- const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
- getContext().getMCDwarfFiles();
- for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
- if (MCDwarfFiles[i].Name.empty())
- TokError("unassigned file number: " + Twine(i) + " for .file directives");
+ const auto &LineTables = getContext().getMCDwarfLineTables();
+ if (!LineTables.empty()) {
+ unsigned Index = 0;
+ for (const auto &File : LineTables.begin()->second.getMCDwarfFiles()) {
+ if (File.Name.empty() && Index != 0)
+ TokError("unassigned file number: " + Twine(Index) +
+ " for .file directives");
+ ++Index;
+ }
}
// Check to see that all assembler local symbols were actually defined.