Skip to content

Commit d68ee59

Browse files
Introduce debug_loclists representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces DebugLoclistsRef and DebugLoclistsSectionRef to represent the debug_loclists section in DWARF5.
1 parent 3ebb5f1 commit d68ee59

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

llvm/include/llvm/MCCAS/MCCASObjectV1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CASV1_SIMPLE_DATA_REF(CStringRef, mc:cstring)
1919
CASV1_SIMPLE_DATA_REF(MergedFragmentRef, mc:merged_fragment)
2020
CASV1_SIMPLE_DATA_REF(DebugStrRef, mc:debug_string)
2121
CASV1_SIMPLE_DATA_REF(DebugStrOffsetsRef, mc:debug_string_offsets)
22+
CASV1_SIMPLE_DATA_REF(DebugLoclistsRef, mc:debug_loclists)
2223
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2324
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
2425
CASV1_SIMPLE_DATA_REF(DebugInfoUnoptRef, mc:debug_info_unopt)
@@ -42,6 +43,7 @@ CASV1_SIMPLE_GROUP_REF(AtomRef, mc:atom)
4243
CASV1_SIMPLE_GROUP_REF(SymbolTableRef, mc:symbol_table)
4344
CASV1_SIMPLE_GROUP_REF(DebugStringSectionRef, mc:debug_string_section)
4445
CASV1_SIMPLE_GROUP_REF(DebugStringOffsetsSectionRef, mc:debug_string_offsets_section)
46+
CASV1_SIMPLE_GROUP_REF(DebugLoclistsSectionRef, mc:debug_loclists_section)
4547
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
4648
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
4749
CASV1_SIMPLE_GROUP_REF(DIEDedupeTopLevelRef, mc:debug_DIE_Dedupe_top_level)

llvm/include/llvm/MCCAS/MCCASObjectV1.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ struct DwarfSectionsCache {
480480
MCSection *Str;
481481
MCSection *Abbrev;
482482
MCSection *StrOffsets;
483+
MCSection *Loclists;
483484
};
484485

485486
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -603,6 +604,10 @@ class MCCASBuilder {
603604
// object for the section.
604605
Error createDebugStrOffsetsSection();
605606

607+
// If a DWARF Loclists section exists, create a DebugLoclistsRef CAS
608+
// object for the section.
609+
Error createDebugLoclistsSection();
610+
606611
/// If there is any padding between one section and the next, create a
607612
/// PaddingRef CAS object to represent the bytes of Padding between the two
608613
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,20 @@ DebugStringOffsetsSectionRef::create(MCCASBuilder &MB,
779779
return get(B->build());
780780
}
781781

782+
Expected<DebugLoclistsSectionRef>
783+
DebugLoclistsSectionRef::create(MCCASBuilder &MB,
784+
ArrayRef<cas::ObjectRef> Fragments) {
785+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
786+
if (!B)
787+
return B.takeError();
788+
789+
if (auto E = createGenericDebugSection<DebugLoclistsSectionRef>(
790+
MB, Fragments, B->Data, B->Refs))
791+
return E;
792+
793+
return get(B->build());
794+
}
795+
782796
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
783797
raw_ostream *Stream) const {
784798
// Start a new section for relocations.
@@ -1240,6 +1254,14 @@ DebugStringOffsetsSectionRef::materialize(MCCASReader &Reader,
12401254
Reader, Remaining, *this);
12411255
}
12421256

1257+
Expected<uint64_t>
1258+
DebugLoclistsSectionRef::materialize(MCCASReader &Reader,
1259+
raw_ostream *Stream) const {
1260+
StringRef Remaining = getData();
1261+
return materializeGenericDebugSection<DebugLoclistsSectionRef>(
1262+
Reader, Remaining, *this);
1263+
}
1264+
12431265
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
12441266
ArrayRef<cas::ObjectRef> Fragments) {
12451267
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1569,7 +1591,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
15691591
Asm.getContext().getObjectFileInfo()->getDwarfLineSection(),
15701592
Asm.getContext().getObjectFileInfo()->getDwarfStrSection(),
15711593
Asm.getContext().getObjectFileInfo()->getDwarfAbbrevSection(),
1572-
Asm.getContext().getObjectFileInfo()->getDwarfStrOffSection()};
1594+
Asm.getContext().getObjectFileInfo()->getDwarfStrOffSection(),
1595+
Asm.getContext().getObjectFileInfo()->getDwarfLoclistsSection()};
15731596
}
15741597

15751598
Error MCCASBuilder::prepare() {
@@ -2412,6 +2435,23 @@ Error MCCASBuilder::createDebugStrOffsetsSection() {
24122435
return finalizeSection<DebugStringOffsetsSectionRef>();
24132436
}
24142437

2438+
Error MCCASBuilder::createDebugLoclistsSection() {
2439+
2440+
auto MaybeDebugLoclistsRef =
2441+
createGenericDebugRef<DebugLoclistsRef>(DwarfSections.Loclists);
2442+
if (!MaybeDebugLoclistsRef)
2443+
return Error::success();
2444+
2445+
if (!*MaybeDebugLoclistsRef)
2446+
return MaybeDebugLoclistsRef->takeError();
2447+
2448+
startSection(DwarfSections.Loclists);
2449+
addNode(**MaybeDebugLoclistsRef);
2450+
if (auto E = createPaddingRef(DwarfSections.Loclists))
2451+
return E;
2452+
return finalizeSection<DebugLoclistsSectionRef>();
2453+
}
2454+
24152455
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
24162456
switch (Fragment.getKind()) {
24172457
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2550,6 +2590,13 @@ Error MCCASBuilder::buildFragments() {
25502590
continue;
25512591
}
25522592

2593+
// Handle Debug Loclists sections separately.
2594+
if (&Sec == DwarfSections.Loclists) {
2595+
if (auto E = createDebugLoclistsSection())
2596+
return E;
2597+
continue;
2598+
}
2599+
25532600
// Start Subsection for one section.
25542601
startSection(&Sec);
25552602

@@ -2709,7 +2756,8 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
27092756
// For the Dwarf Sections, just append the relocations to the
27102757
// SectionRelocs. No Atoms are considered for this section.
27112758
if (R.F && Sec != DwarfSections.Line && Sec != DwarfSections.DebugInfo &&
2712-
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets)
2759+
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets &&
2760+
Sec != DwarfSections.Loclists)
27132761
RelMap[R.F].push_back(R.MRE);
27142762
else
27152763
// If the fragment is nullptr, it should a section with only relocation
@@ -2914,6 +2962,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
29142962
return F->materialize(*this);
29152963
if (auto F = DebugStringOffsetsSectionRef::Cast(*Node))
29162964
return F->materialize(*this);
2965+
if (auto F = DebugLoclistsSectionRef::Cast(*Node))
2966+
return F->materialize(*this);
29172967
if (auto F = CStringRef::Cast(*Node)) {
29182968
auto Size = F->materialize(OS);
29192969
if (!Size)
@@ -2980,6 +3030,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
29803030
}
29813031
if (auto F = DebugStrOffsetsRef::Cast(*Node))
29823032
return F->materialize(*Stream);
3033+
if (auto F = DebugLoclistsRef::Cast(*Node))
3034+
return F->materialize(*Stream);
29833035
if (auto F = AddendsRef::Cast(*Node))
29843036
// AddendsRef is already handled when materializing Atoms, skip.
29853037
return 0;

0 commit comments

Comments
 (0)