summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2018-02-28 15:02:59 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2018-02-28 15:02:59 +0000
commit9de940b93bdbb0cf032b8337c5390630ba5e1acd (patch)
tree8d1b1b2e490b59d6f17b380ac3b0d14f89e6491e /llvm/lib/CodeGen
parenta1a29336340080d33893f82d5bf369df11615d58 (diff)
downloadbcm5719-llvm-9de940b93bdbb0cf032b8337c5390630ba5e1acd.tar.gz
bcm5719-llvm-9de940b93bdbb0cf032b8337c5390630ba5e1acd.zip
[DEBUGINFO] Add flag for DWARF2 or less to use sections as references.
Summary: Some targets does not support labels inside debug sections, but support references in form `section +|- offset`. Patch adds initial support for this. Also, this patch disables emission of all additional debug sections that may have labels inside of it (like pub sections and string tables). Reviewers: probinson, echristo Subscribers: JDevlieghere, llvm-commits Differential Revision: https://reviews.llvm.org/D43627 llvm-svn: 326328
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp23
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp29
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h9
3 files changed, 50 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 0b2a0469f8c..1dc9d5e2345 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -270,15 +270,20 @@ void DwarfCompileUnit::addRange(RangeSpan Range) {
void DwarfCompileUnit::initStmtList() {
// Define start line table label for each Compile Unit.
- MCSymbol *LineTableStartSym =
- Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
+ MCSymbol *LineTableStartSym;
+ const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
+ if (DD->useSectionsAsReferences()) {
+ LineTableStartSym = TLOF.getDwarfLineSection()->getBeginSymbol();
+ } else {
+ LineTableStartSym =
+ Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
+ }
// DW_AT_stmt_list is a offset of line number information for this
// compile unit in debug_line section. For split dwarf this is
// left in the skeleton CU and so not included.
// The line table entries are not always emitted in assembly, so it
// is not okay to use line_table_start here.
- const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
StmtListValue =
addSectionLabel(getUnitDie(), dwarf::DW_AT_stmt_list, LineTableStartSym,
TLOF.getDwarfLineSection()->getBeginSymbol());
@@ -410,9 +415,10 @@ void DwarfCompileUnit::addScopeRangeList(DIE &ScopeDIE,
void DwarfCompileUnit::attachRangesOrLowHighPC(
DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
- if (Ranges.size() == 1) {
- const auto &single = Ranges.front();
- attachLowHighPC(Die, single.getStart(), single.getEnd());
+ if (Ranges.size() == 1 || DD->useSectionsAsReferences()) {
+ const auto &front = Ranges.front();
+ const auto &back = Ranges.back();
+ attachLowHighPC(Die, front.getStart(), back.getEnd());
} else
addScopeRangeList(Die, std::move(Ranges));
}
@@ -834,7 +840,7 @@ void DwarfCompileUnit::createAbstractVariable(const DILocalVariable *Var,
void DwarfCompileUnit::emitHeader(bool UseOffsets) {
// Don't bother labeling the .dwo unit, as its offset isn't used.
- if (!Skeleton) {
+ if (!Skeleton && !DD->useSectionsAsReferences()) {
LabelBegin = Asm->createTempSymbol("cu_begin");
Asm->OutStreamer->EmitLabel(LabelBegin);
}
@@ -851,7 +857,8 @@ bool DwarfCompileUnit::hasDwarfPubSections() const {
if (CUNode->getGnuPubnames())
return true;
- return DD->tuneForGDB() && !includeMinimalInlineScopes();
+ return DD->tuneForGDB() && !includeMinimalInlineScopes() &&
+ !DD->useSectionsAsReferences();
}
/// addGlobalName - Add a new global name to the compile unit.
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 7985908f377..a9aa00cefc1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -123,6 +123,13 @@ DwarfInlinedStrings("dwarf-inlined-strings", cl::Hidden,
clEnumVal(Disable, "Disabled")),
cl::init(Default));
+static cl::opt<DefaultOnOff> DwarfSectionsAsReferences(
+ "dwarf-sections-as-references", cl::Hidden,
+ cl::desc("Use sections+offset as references rather than labels."),
+ cl::values(clEnumVal(Default, "Default for platform"),
+ clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
+ cl::init(Default));
+
enum LinkageNameOption {
DefaultLinkageNames,
AllLinkageNames,
@@ -310,6 +317,10 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
// Use dwarf 4 by default if nothing is requested.
DwarfVersion = DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION;
+ // Use sections as references in DWARF v2.
+ UseSectionsAsReferences =
+ DwarfVersion == 2 && DwarfSectionsAsReferences == Enable;
+
// Work around a GDB bug. GDB doesn't support the standard opcode;
// SCE doesn't support GNU's; LLDB prefers the standard opcode, which
// is defined as of DWARF 3.
@@ -737,7 +748,7 @@ void DwarfDebug::finalizeModuleInfo() {
// ranges for all subprogram DIEs for mach-o.
DwarfCompileUnit &U = SkCU ? *SkCU : TheCU;
if (unsigned NumRanges = TheCU.getRanges().size()) {
- if (NumRanges > 1)
+ if (NumRanges > 1 && !useSectionsAsReferences())
// A DW_AT_low_pc attribute may also be specified in combination with
// DW_AT_ranges to specify the default base address for use in
// location lists (see Section 2.6.2) and range lists (see Section
@@ -1565,7 +1576,13 @@ void DwarfDebug::emitDebugPubSection(bool GnuStyle, StringRef Name,
Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION);
Asm->OutStreamer->AddComment("Offset of Compilation Unit Info");
- Asm->emitDwarfSymbolReference(TheU->getLabelBegin());
+ if (useSectionsAsReferences()) {
+ Asm->EmitLabelPlusOffset(TheU->getSection()->getBeginSymbol(),
+ TheU->getDebugSectionOffset(),
+ Asm->MAI->getCodePointerSize());
+ } else {
+ Asm->emitDwarfSymbolReference(TheU->getLabelBegin());
+ }
Asm->OutStreamer->AddComment("Compilation Unit Length");
Asm->EmitInt32(TheU->getLength());
@@ -1864,7 +1881,13 @@ void DwarfDebug::emitDebugARanges() {
Asm->OutStreamer->AddComment("DWARF Arange version number");
Asm->EmitInt16(dwarf::DW_ARANGES_VERSION);
Asm->OutStreamer->AddComment("Offset Into Debug Info Section");
- Asm->emitDwarfSymbolReference(CU->getLabelBegin());
+ if (useSectionsAsReferences()) {
+ Asm->EmitLabelPlusOffset(CU->getSection()->getBeginSymbol(),
+ CU->getDebugSectionOffset(),
+ Asm->MAI->getCodePointerSize());
+ } else {
+ Asm->emitDwarfSymbolReference(CU->getLabelBegin());
+ }
Asm->OutStreamer->AddComment("Address Size (in bytes)");
Asm->EmitInt8(PtrSize);
Asm->OutStreamer->AddComment("Segment Size (in bytes)");
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index f858c96d0d2..46d644657a8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -258,6 +258,10 @@ class DwarfDebug : public DebugHandlerBase {
/// Use inlined strings.
bool UseInlineStrings = false;
+ /// True if the sections itself must be used as references and don't create
+ /// temp symbols inside DWARF sections.
+ bool UseSectionsAsReferences = false;
+
/// DWARF5 Experimental Options
/// @{
bool HasDwarfAccelTables;
@@ -497,6 +501,11 @@ public:
/// Returns whether to use inline strings.
bool useInlineStrings() const { return UseInlineStrings; }
+ /// Returns whether to use sections as labels rather than temp symbols.
+ bool useSectionsAsReferences() const {
+ return UseSectionsAsReferences;
+ }
+
// Experimental DWARF5 features.
/// Returns whether or not to emit tables that dwarf consumers can
OpenPOWER on IntegriCloud