diff options
author | Wolfgang Pieb <Wolfgang.Pieb@sony.com> | 2018-07-26 22:48:52 +0000 |
---|---|---|
committer | Wolfgang Pieb <Wolfgang.Pieb@sony.com> | 2018-07-26 22:48:52 +0000 |
commit | 9ea65082ff5a5fe187608783641d57afe8fcf18e (patch) | |
tree | d2f1cdeb2d792ce84d52f5bbca5ccd65a7b2260f /llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | |
parent | 8da280f50b3a5783d2ecdfe2ba6be8505ab039db (diff) | |
download | bcm5719-llvm-9ea65082ff5a5fe187608783641d57afe8fcf18e.tar.gz bcm5719-llvm-9ea65082ff5a5fe187608783641d57afe8fcf18e.zip |
[DWARF v5] Reposting r337981, which was reverted in r337997 due to a test failure in debuginfo_tests.
The test failure was caused by the compiler not emitting a __debug_ranges section with DWARF 4 and
earlier when no ranges are needed. The test checks for the existence regardless.
llvm-svn: 338081
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index d2f123ce78e..8761fae9dd2 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -820,6 +820,10 @@ void DwarfDebug::finalizeModuleInfo() { U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges()); } + if (getDwarfVersion() >= 5 && !useSplitDwarf() && + !U.getRangeLists().empty()) + U.addRnglistsBase(); + auto *CUNode = cast<DICompileUnit>(P.first); // If compile Unit has macros, emit "DW_AT_macro_info" attribute. if (CUNode->getMacros()) @@ -2087,23 +2091,10 @@ static void emitRangeList(AsmPrinter *Asm, DwarfCompileUnit *CU, } } -void DwarfDebug::emitDebugRnglists() { - - // Don't emit a rangelist table if there are no ranges. - if (llvm::all_of(CUMap, - [](const decltype(CUMap)::const_iterator::value_type &Pair) { - DwarfCompileUnit *TheCU = Pair.second; - if (auto *Skel = TheCU->getSkeleton()) - TheCU = Skel; - return TheCU->getRangeLists().empty(); - })) - return; - - assert(getDwarfVersion() >= 5 && "Dwarf version must be 5 or greater"); - // FIXME: As long as we don't support DW_RLE_base_addrx, we cannot generate - // any tables in the .debug_rnglists.dwo section. - Asm->OutStreamer->SwitchSection( - Asm->getObjFileLowering().getDwarfRnglistsSection()); +// Emit the header of a DWARF 5 range list table. Returns the symbol that +// designates the end of the table for the caller to emit when the table is +// complete. +static MCSymbol *emitRnglistsTableHeader(AsmPrinter *Asm, DwarfFile &Holder) { // The length is described by a starting label right after the length field // and an end label. MCSymbol *TableStart = Asm->createTempSymbol("debug_rnglist_table_start"); @@ -2112,56 +2103,52 @@ void DwarfDebug::emitDebugRnglists() { Asm->EmitLabelDifference(TableEnd, TableStart, 4); Asm->OutStreamer->EmitLabel(TableStart); // Version number (DWARF v5 and later). - Asm->emitInt16(getDwarfVersion()); + Asm->emitInt16(Asm->OutStreamer->getContext().getDwarfVersion()); // Address size. Asm->emitInt8(Asm->MAI->getCodePointerSize()); // Segment selector size. Asm->emitInt8(0); - MCSymbol *RnglistTableBaseSym = - (useSplitDwarf() ? SkeletonHolder : InfoHolder).getRnglistsTableBaseSym(); + MCSymbol *RnglistTableBaseSym = Holder.getRnglistsTableBaseSym(); // FIXME: Generate the offsets table and use DW_FORM_rnglistx with the // DW_AT_ranges attribute. Until then set the number of offsets to 0. Asm->emitInt32(0); Asm->OutStreamer->EmitLabel(RnglistTableBaseSym); - - // Emit the individual range lists. - for (const auto &I : CUMap) { - DwarfCompileUnit *TheCU = I.second; - if (auto *Skel = TheCU->getSkeleton()) - TheCU = Skel; - for (const RangeSpanList &List : TheCU->getRangeLists()) - emitRangeList(Asm, TheCU, List); - } - - Asm->OutStreamer->EmitLabel(TableEnd); + return TableEnd; } -/// Emit address ranges into the .debug_ranges section or DWARF v5 rangelists -/// into the .debug_rnglists section. +/// Emit address ranges into the .debug_ranges section or into the DWARF v5 +/// .debug_rnglists section. void DwarfDebug::emitDebugRanges() { if (CUMap.empty()) return; + auto NoRangesPresent = [this]() { + return llvm::all_of( + CUMap, [](const decltype(CUMap)::const_iterator::value_type &Pair) { + return Pair.second->getRangeLists().empty(); + }); + }; + if (!useRangesSection()) { - assert(llvm::all_of( - CUMap, - [](const decltype(CUMap)::const_iterator::value_type &Pair) { - return Pair.second->getRangeLists().empty(); - }) && - "No debug ranges expected."); + assert(NoRangesPresent() && "No debug ranges expected."); return; } - if (getDwarfVersion() >= 5) { - emitDebugRnglists(); + if (getDwarfVersion() >= 5 && NoRangesPresent()) return; - } // Start the dwarf ranges section. - Asm->OutStreamer->SwitchSection( - Asm->getObjFileLowering().getDwarfRangesSection()); + MCSymbol *TableEnd = nullptr; + if (getDwarfVersion() >= 5) { + Asm->OutStreamer->SwitchSection( + Asm->getObjFileLowering().getDwarfRnglistsSection()); + TableEnd = emitRnglistsTableHeader(Asm, useSplitDwarf() ? SkeletonHolder + : InfoHolder); + } else + Asm->OutStreamer->SwitchSection( + Asm->getObjFileLowering().getDwarfRangesSection()); // Grab the specific ranges for the compile units in the module. for (const auto &I : CUMap) { @@ -2174,6 +2161,9 @@ void DwarfDebug::emitDebugRanges() { for (const RangeSpanList &List : TheCU->getRangeLists()) emitRangeList(Asm, TheCU, List); } + + if (TableEnd) + Asm->OutStreamer->EmitLabel(TableEnd); } void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) { @@ -2249,9 +2239,6 @@ void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die, SkeletonHolder.addUnit(std::move(NewU)); } -// This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list, -// DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id, -// DW_AT_addr_base, DW_AT_ranges_base or DW_AT_rnglists_base. DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) { auto OwnedUnit = llvm::make_unique<DwarfCompileUnit>( |