[llvm] 0e02977 - Recommit "[DWARF] Support for loclist.dwo section in llvm and llvm-dwarfdump."
Sourabh Singh Tomar via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 23 06:41:10 PST 2019
Author: Sourabh Singh Tomar
Date: 2019-11-23T20:10:23+05:30
New Revision: 0e02977b6e64810bdf9265260a39d80fda031aa3
URL: https://github.com/llvm/llvm-project/commit/0e02977b6e64810bdf9265260a39d80fda031aa3
DIFF: https://github.com/llvm/llvm-project/commit/0e02977b6e64810bdf9265260a39d80fda031aa3.diff
LOG: Recommit "[DWARF] Support for loclist.dwo section in llvm and llvm-dwarfdump."
The original commit message follows.
This patch adds support for debug_loclists.dwo section in llvm and llvm-dwarfdump.
Also Fixes PR43622, PR43623.
Reviewers: dblaikie, probinson, labath, aprantl, jini.susan.george
Differential Revision: https://reviews.llvm.org/D69462
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
llvm/include/llvm/MC/MCObjectFileInfo.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/test/CodeGen/X86/debug-loclists.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
index 88fe3f434edc..9cd34a588c56 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFObject.h
@@ -60,6 +60,7 @@ class DWARFObject {
virtual StringRef getAbbrevDWOSection() const { return ""; }
virtual const DWARFSection &getLineDWOSection() const { return Dummy; }
virtual const DWARFSection &getLocDWOSection() const { return Dummy; }
+ virtual const DWARFSection &getLoclistsDWOSection() const { return Dummy; }
virtual StringRef getStrDWOSection() const { return ""; }
virtual const DWARFSection &getStrOffsetsDWOSection() const {
return Dummy;
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index 4ecfac4dcc4c..12d681ffbebc 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -120,8 +120,9 @@ class MCObjectFileInfo {
/// The DWARF v5 locations list section.
MCSection *DwarfLoclistsSection = nullptr;
- /// The DWARF v5 range list section for fission.
+ /// The DWARF v5 range and location list sections for fission.
MCSection *DwarfRnglistsDWOSection = nullptr;
+ MCSection *DwarfLoclistsDWOSection = nullptr;
// These are for Fission DWP files.
MCSection *DwarfCUIndexSection = nullptr;
@@ -299,6 +300,9 @@ class MCObjectFileInfo {
MCSection *getDwarfRnglistsDWOSection() const {
return DwarfRnglistsDWOSection;
}
+ MCSection *getDwarfLoclistsDWOSection() const {
+ return DwarfLoclistsDWOSection;
+ }
MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 84444ca51743..551e8a2751b5 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1158,11 +1158,12 @@ void DwarfDebug::finalizeModuleInfo() {
if (U.hasRangeLists())
U.addRnglistsBase();
- if (!DebugLocs.getLists().empty() && !useSplitDwarf()) {
+ if (!DebugLocs.getLists().empty()) {
DebugLocs.setSym(Asm->createTempSymbol("loclists_table_base"));
- U.addSectionLabel(U.getUnitDie(), dwarf::DW_AT_loclists_base,
- DebugLocs.getSym(),
- TLOF.getDwarfLoclistsSection()->getBeginSymbol());
+ if (!useSplitDwarf())
+ U.addSectionLabel(U.getUnitDie(), dwarf::DW_AT_loclists_base,
+ DebugLocs.getSym(),
+ TLOF.getDwarfLoclistsSection()->getBeginSymbol());
}
}
@@ -1207,9 +1208,10 @@ void DwarfDebug::endModule() {
emitDebugStr();
if (useSplitDwarf())
+ // Handles debug_loc.dwo / debug_loclists.dwo section emission
emitDebugLocDWO();
else
- // Emit info into a debug loc section.
+ // Handles debug_loc / debug_loclists section emission
emitDebugLoc();
// Corresponding abbreviations into a abbrev section.
@@ -2335,8 +2337,6 @@ static MCSymbol *emitLoclistsTableHeader(AsmPrinter *Asm,
const auto &DebugLocs = DD.getDebugLocs();
- // FIXME: Generate the offsets table and use DW_FORM_loclistx with the
- // DW_AT_loclists_base attribute. Until then set the number of offsets to 0.
Asm->OutStreamer->AddComment("Offset entry count");
Asm->emitInt32(DebugLocs.getLists().size());
Asm->OutStreamer->EmitLabel(DebugLocs.getSym());
@@ -2443,27 +2443,29 @@ static void emitRangeList(
}
}
+// Handles emission of both debug_loclist / debug_loclist.dwo
static void emitLocList(DwarfDebug &DD, AsmPrinter *Asm, const DebugLocStream::List &List) {
- emitRangeList(
- DD, Asm, List.Label, DD.getDebugLocs().getEntries(List), *List.CU,
- dwarf::DW_LLE_base_addressx, dwarf::DW_LLE_offset_pair,
- dwarf::DW_LLE_startx_length, dwarf::DW_LLE_end_of_list,
- llvm::dwarf::LocListEncodingString,
- /* ShouldUseBaseAddress */ true,
- [&](const DebugLocStream::Entry &E) {
- DD.emitDebugLocEntryLocation(E, List.CU);
- });
+ emitRangeList(DD, Asm, List.Label, DD.getDebugLocs().getEntries(List),
+ *List.CU, dwarf::DW_LLE_base_addressx,
+ dwarf::DW_LLE_offset_pair, dwarf::DW_LLE_startx_length,
+ dwarf::DW_LLE_end_of_list, llvm::dwarf::LocListEncodingString,
+ /* ShouldUseBaseAddress */ true,
+ [&](const DebugLocStream::Entry &E) {
+ DD.emitDebugLocEntryLocation(E, List.CU);
+ });
}
-// Emit locations into the .debug_loc/.debug_rnglists section.
+// Emit locations into the .debug_loc/.debug_loclists section.
void DwarfDebug::emitDebugLoc() {
if (DebugLocs.getLists().empty())
return;
MCSymbol *TableEnd = nullptr;
if (getDwarfVersion() >= 5) {
+
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfLoclistsSection());
+
TableEnd = emitLoclistsTableHeader(Asm, *this);
} else {
Asm->OutStreamer->SwitchSection(
@@ -2477,11 +2479,29 @@ void DwarfDebug::emitDebugLoc() {
Asm->OutStreamer->EmitLabel(TableEnd);
}
+// Emit locations into the .debug_loc.dwo/.debug_loclists.dwo section.
void DwarfDebug::emitDebugLocDWO() {
+ if (DebugLocs.getLists().empty())
+ return;
+
+ if (getDwarfVersion() >= 5) {
+ MCSymbol *TableEnd = nullptr;
+ Asm->OutStreamer->SwitchSection(
+ Asm->getObjFileLowering().getDwarfLoclistsDWOSection());
+ TableEnd = emitLoclistsTableHeader(Asm, *this);
+ for (const auto &List : DebugLocs.getLists())
+ emitLocList(*this, Asm, List);
+
+ if (TableEnd)
+ Asm->OutStreamer->EmitLabel(TableEnd);
+ return;
+ }
+
for (const auto &List : DebugLocs.getLists()) {
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfLocDWOSection());
Asm->OutStreamer->EmitLabel(List.Label);
+
for (const auto &Entry : DebugLocs.getEntries(List)) {
// GDB only supports startx_length in pre-standard split-DWARF.
// (in v5 standard loclists, it currently* /only/ supports base_address +
@@ -2494,7 +2514,6 @@ void DwarfDebug::emitDebugLocDWO() {
unsigned idx = AddrPool.getIndex(Entry.Begin);
Asm->EmitULEB128(idx);
Asm->EmitLabelDifference(Entry.End, Entry.Begin, 4);
-
emitDebugLocEntryLocation(Entry, List.CU);
}
Asm->emitInt8(dwarf::DW_LLE_end_of_list);
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index f7b3fb495f92..012bab354600 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -403,6 +403,14 @@ void DWARFContext::dump(
0);
dumpLoclistsSection(OS, LLDumpOpts, Data, getRegisterInfo(), *Off);
}
+ if (const auto *Off =
+ shouldDump(ExplicitDWO, ".debug_loclists.dwo", DIDT_ID_DebugLoclists,
+ DObj->getLoclistsDWOSection().Data)) {
+ DWARFDataExtractor Data(*DObj, DObj->getLoclistsDWOSection(),
+ isLittleEndian(), 0);
+ dumpLoclistsSection(OS, LLDumpOpts, Data, getRegisterInfo(), *Off);
+ }
+
if (const auto *Off =
shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
DObj->getLocDWOSection().Data)) {
@@ -1385,6 +1393,7 @@ class DWARFObjInMemory final : public DWARFObject {
DWARFSectionMap LocSection;
DWARFSectionMap LoclistsSection;
+ DWARFSectionMap LoclistsDWOSection;
DWARFSectionMap LineSection;
DWARFSectionMap RangesSection;
DWARFSectionMap RnglistsSection;
@@ -1411,6 +1420,7 @@ class DWARFObjInMemory final : public DWARFObject {
return StringSwitch<DWARFSectionMap *>(Name)
.Case("debug_loc", &LocSection)
.Case("debug_loclists", &LoclistsSection)
+ .Case("debug_loclists.dwo", &LoclistsDWOSection)
.Case("debug_line", &LineSection)
.Case("debug_frame", &FrameSection)
.Case("eh_frame", &EHFrameSection)
@@ -1741,6 +1751,9 @@ class DWARFObjInMemory final : public DWARFObject {
const DWARFSection &getRnglistsDWOSection() const override {
return RnglistsDWOSection;
}
+ const DWARFSection &getLoclistsDWOSection() const override {
+ return LoclistsDWOSection;
+ }
const DWARFSection &getAddrSection() const override { return AddrSection; }
StringRef getCUIndexSection() const override { return CUIndexSection; }
StringRef getGdbIndexSection() const override { return GdbIndexSection; }
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 6cf30270539b..cc3d021b0ddb 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -89,6 +89,7 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
if (FormValue.getForm() == DW_FORM_loclistx) {
FormValue.dump(OS, DumpOpts);
+
if (auto LoclistOffset = U->getLoclistOffset(Offset))
Offset = *LoclistOffset + U->getLocSectionBase();
else
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index e5d33e136445..b662e88816f8 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -186,9 +186,16 @@ DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
if (auto *IndexEntry = Header.getIndexEntry())
if (const auto *C = IndexEntry->getOffset(DW_SECT_LOC))
Data = Data.substr(C->Offset, C->Length);
- LocTable = std::make_unique<DWARFDebugLoclists>(
- DWARFDataExtractor(Data, isLittleEndian, getAddressByteSize()),
- Header.getVersion());
+
+ DWARFDataExtractor DWARFData =
+ Header.getVersion() >= 5
+ ? DWARFDataExtractor(Context.getDWARFObj(),
+ Context.getDWARFObj().getLoclistsDWOSection(),
+ isLittleEndian, getAddressByteSize())
+ : DWARFDataExtractor(Data, isLittleEndian, getAddressByteSize());
+ LocTable =
+ std::make_unique<DWARFDebugLoclists>(DWARFData, Header.getVersion());
+
} else if (Header.getVersion() >= 5) {
LocTable = std::make_unique<DWARFDebugLoclists>(
DWARFDataExtractor(Context.getDWARFObj(),
@@ -502,14 +509,23 @@ Error DWARFUnit::tryExtractDIEsIfNeeded(bool CUDieOnly) {
RangeSectionBase = RngListTable->getHeaderSize();
}
- // FIXME: add loclists.dwo support
- setLocSection(&Context.getDWARFObj().getLoclistsSection(),
- toSectionOffset(UnitDie.find(DW_AT_loclists_base), 0));
+ // In a split dwarf unit, there is no DW_AT_loclists_base attribute.
+ // Setting LocSectionBase to point past the table header.
+ if (IsDWO)
+ setLocSection(&Context.getDWARFObj().getLoclistsDWOSection(),
+ DWARFListTableHeader::getHeaderSize(Header.getFormat()));
+ else
+ setLocSection(&Context.getDWARFObj().getLoclistsSection(),
+ toSectionOffset(UnitDie.find(DW_AT_loclists_base), 0));
if (LocSection->Data.size()) {
- LoclistTableHeader.emplace(".debug_loclists", "locations");
- uint64_t Offset = LocSectionBase;
+ if (IsDWO)
+ LoclistTableHeader.emplace(".debug_loclists.dwo", "locations");
+ else
+ LoclistTableHeader.emplace(".debug_loclists", "locations");
+
uint64_t HeaderSize = DWARFListTableHeader::getHeaderSize(Header.getFormat());
+ uint64_t Offset = getLocSectionBase();
DWARFDataExtractor Data(Context.getDWARFObj(), *LocSection,
isLittleEndian, getAddressByteSize());
if (Offset < HeaderSize)
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index 53a9467041c0..5b4da1998c41 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -464,6 +464,9 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
DwarfRnglistsDWOSection =
Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
+ DwarfLoclistsDWOSection =
+ Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);
+
// DWP Sections
DwarfCUIndexSection =
Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);
diff --git a/llvm/test/CodeGen/X86/debug-loclists.ll b/llvm/test/CodeGen/X86/debug-loclists.ll
index a4dd7edf8dda..10cd877bf1c1 100644
--- a/llvm/test/CodeGen/X86/debug-loclists.ll
+++ b/llvm/test/CodeGen/X86/debug-loclists.ll
@@ -1,6 +1,9 @@
; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t < %s
; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | FileCheck %s
+; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -mtriple=x86_64-pc-linux -filetype=obj -function-sections -o %t < %s
+; RUN: llvm-dwarfdump -v -debug-info -debug-loclists %t | FileCheck %s --check-prefix=DWO
+
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location [DW_FORM_loclistx] (indexed (0x0) loclist = 0x00000018:
; CHECK-NEXT: [0x0000000000000000, 0x0000000000000003) ".text._Z2f1ii": DW_OP_consts +3, DW_OP_stack_value
@@ -20,6 +23,9 @@
; CHECK: .debug_loclists contents:
; CHECK-NEXT: 0x00000000: locations list header: length = 0x00000035, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000003
+; DWO: .debug_loclists.dwo contents:
+; DWO-NEXT: 0x00000000: locations list header: length = 0x00000035, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000003
+
; CHECK-NEXT: offsets: [
; CHECK-NEXT: 0x0000000c => 0x00000018
; CHECK-NEXT: 0x0000001d => 0x00000029
More information about the llvm-commits
mailing list