Skip to content

Commit 3ebb5f1

Browse files
Introduce debug_str_offsets representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces DebugStrOffsetsRef and DebugStringOffsetsSectionRef to represent the debug_str_offsets section in DWARF5.
1 parent 02326d7 commit 3ebb5f1

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

llvm/include/llvm/MCCAS/MCCASObjectV1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CASV1_SIMPLE_DATA_REF(DataInCodeRef, mc:data_in_code)
1818
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)
21+
CASV1_SIMPLE_DATA_REF(DebugStrOffsetsRef, mc:debug_string_offsets)
2122
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2223
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
2324
CASV1_SIMPLE_DATA_REF(DebugInfoUnoptRef, mc:debug_info_unopt)
@@ -40,6 +41,7 @@ CASV1_SIMPLE_GROUP_REF(DebugLineSectionRef, mc:debug_line_section)
4041
CASV1_SIMPLE_GROUP_REF(AtomRef, mc:atom)
4142
CASV1_SIMPLE_GROUP_REF(SymbolTableRef, mc:symbol_table)
4243
CASV1_SIMPLE_GROUP_REF(DebugStringSectionRef, mc:debug_string_section)
44+
CASV1_SIMPLE_GROUP_REF(DebugStringOffsetsSectionRef, mc:debug_string_offsets_section)
4345
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
4446
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
4547
CASV1_SIMPLE_GROUP_REF(DIEDedupeTopLevelRef, mc:debug_DIE_Dedupe_top_level)

llvm/include/llvm/MCCAS/MCCASObjectV1.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ class MCCASBuilder {
599599
// string in the section.
600600
Error createDebugStrSection();
601601

602+
// If a DWARF String Offsets section exists, create a DebugStrOffsetsRef CAS
603+
// object for the section.
604+
Error createDebugStrOffsetsSection();
605+
602606
/// If there is any padding between one section and the next, create a
603607
/// PaddingRef CAS object to represent the bytes of Padding between the two
604608
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,20 @@ static Error createGenericDebugSection(MCCASBuilder &MB,
765765
return Error::success();
766766
}
767767

768+
Expected<DebugStringOffsetsSectionRef>
769+
DebugStringOffsetsSectionRef::create(MCCASBuilder &MB,
770+
ArrayRef<cas::ObjectRef> Fragments) {
771+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
772+
if (!B)
773+
return B.takeError();
774+
775+
if (auto E = createGenericDebugSection<DebugStringOffsetsSectionRef>(
776+
MB, Fragments, B->Data, B->Refs))
777+
return E;
778+
779+
return get(B->build());
780+
}
781+
768782
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
769783
raw_ostream *Stream) const {
770784
// Start a new section for relocations.
@@ -1218,6 +1232,14 @@ static Expected<uint64_t> materializeGenericDebugSection(MCCASReader &Reader,
12181232
return Size;
12191233
}
12201234

1235+
Expected<uint64_t>
1236+
DebugStringOffsetsSectionRef::materialize(MCCASReader &Reader,
1237+
raw_ostream *Stream) const {
1238+
StringRef Remaining = getData();
1239+
return materializeGenericDebugSection<DebugStringOffsetsSectionRef>(
1240+
Reader, Remaining, *this);
1241+
}
1242+
12211243
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
12221244
ArrayRef<cas::ObjectRef> Fragments) {
12231245
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -2373,6 +2395,23 @@ MCCASBuilder::createGenericDebugRef(MCSection *Section) {
23732395
return *DebugCASRef;
23742396
}
23752397

2398+
Error MCCASBuilder::createDebugStrOffsetsSection() {
2399+
2400+
auto MaybeDebugStringOffsetsRef =
2401+
createGenericDebugRef<DebugStrOffsetsRef>(DwarfSections.StrOffsets);
2402+
if (!MaybeDebugStringOffsetsRef)
2403+
return Error::success();
2404+
2405+
if (!*MaybeDebugStringOffsetsRef)
2406+
return MaybeDebugStringOffsetsRef->takeError();
2407+
2408+
startSection(DwarfSections.StrOffsets);
2409+
addNode(**MaybeDebugStringOffsetsRef);
2410+
if (auto E = createPaddingRef(DwarfSections.StrOffsets))
2411+
return E;
2412+
return finalizeSection<DebugStringOffsetsSectionRef>();
2413+
}
2414+
23762415
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
23772416
switch (Fragment.getKind()) {
23782417
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2504,6 +2543,13 @@ Error MCCASBuilder::buildFragments() {
25042543
continue;
25052544
}
25062545

2546+
// Handle Debug Str Offsets sections separately.
2547+
if (&Sec == DwarfSections.StrOffsets) {
2548+
if (auto E = createDebugStrOffsetsSection())
2549+
return E;
2550+
continue;
2551+
}
2552+
25072553
// Start Subsection for one section.
25082554
startSection(&Sec);
25092555

@@ -2663,7 +2709,7 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
26632709
// For the Dwarf Sections, just append the relocations to the
26642710
// SectionRelocs. No Atoms are considered for this section.
26652711
if (R.F && Sec != DwarfSections.Line && Sec != DwarfSections.DebugInfo &&
2666-
Sec != DwarfSections.Abbrev)
2712+
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets)
26672713
RelMap[R.F].push_back(R.MRE);
26682714
else
26692715
// If the fragment is nullptr, it should a section with only relocation
@@ -2866,6 +2912,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
28662912
return F->materialize(*this);
28672913
if (auto F = DebugStringSectionRef::Cast(*Node))
28682914
return F->materialize(*this);
2915+
if (auto F = DebugStringOffsetsSectionRef::Cast(*Node))
2916+
return F->materialize(*this);
28692917
if (auto F = CStringRef::Cast(*Node)) {
28702918
auto Size = F->materialize(OS);
28712919
if (!Size)
@@ -2930,6 +2978,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
29302978
Stream->write_zeros(1);
29312979
return *Size + 1;
29322980
}
2981+
if (auto F = DebugStrOffsetsRef::Cast(*Node))
2982+
return F->materialize(*Stream);
29332983
if (auto F = AddendsRef::Cast(*Node))
29342984
// AddendsRef is already handled when materializing Atoms, skip.
29352985
return 0;

0 commit comments

Comments
 (0)