Skip to content

Commit 2d62e3d

Browse files
Introduce apple_names representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces DebugAppleNamesRef and DebugAppleNamesSectionRef to represent the apple_names section in DWARF4.
1 parent 9d0c069 commit 2d62e3d

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

llvm/include/llvm/MCCAS/MCCASObjectV1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CASV1_SIMPLE_DATA_REF(DebugLoclistsRef, mc:debug_loclists)
2424
CASV1_SIMPLE_DATA_REF(DebugRangesRef, mc:debug_ranges)
2525
CASV1_SIMPLE_DATA_REF(DebugRangelistsRef, mc:debug_rangelists)
2626
CASV1_SIMPLE_DATA_REF(DebugNamesRef, mc:debug_names)
27+
CASV1_SIMPLE_DATA_REF(AppleNamesRef, mc:apple_names)
2728
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2829
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
2930
CASV1_SIMPLE_DATA_REF(DebugLineStrRef, mc:debug_line_str)
@@ -54,6 +55,7 @@ CASV1_SIMPLE_GROUP_REF(DebugLoclistsSectionRef, mc:debug_loclists_section)
5455
CASV1_SIMPLE_GROUP_REF(DebugRangesSectionRef, mc:debug_ranges_section)
5556
CASV1_SIMPLE_GROUP_REF(DebugRangelistsSectionRef, mc:debug_rangelists_section)
5657
CASV1_SIMPLE_GROUP_REF(DebugNamesSectionRef, mc:debug_names_section)
58+
CASV1_SIMPLE_GROUP_REF(AppleNamesSectionRef, mc:apple_names_section)
5759
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
5860
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
5961
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
@@ -486,6 +486,7 @@ struct DwarfSectionsCache {
486486
MCSection *Rangelists;
487487
MCSection *LineStr;
488488
MCSection *Names;
489+
MCSection *AppleNames;
489490
};
490491

491492
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -633,6 +634,10 @@ class MCCASBuilder {
633634
// object for the section.
634635
Error createDebugNamesSection();
635636

637+
// If a DWARF Apple Names section exists, create a AppleNamesRef CAS
638+
// object for the section.
639+
Error createAppleNamesSection();
640+
636641
/// If there is any padding between one section and the next, create a
637642
/// PaddingRef CAS object to represent the bytes of Padding between the two
638643
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,20 @@ DebugNamesSectionRef::create(MCCASBuilder &MB,
863863
return get(B->build());
864864
}
865865

866+
Expected<AppleNamesSectionRef>
867+
AppleNamesSectionRef::create(MCCASBuilder &MB,
868+
ArrayRef<cas::ObjectRef> Fragments) {
869+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
870+
if (!B)
871+
return B.takeError();
872+
873+
if (auto E = createGenericDebugSection<AppleNamesSectionRef>(
874+
MB, Fragments, B->Data, B->Refs))
875+
return E;
876+
877+
return get(B->build());
878+
}
879+
866880
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
867881
raw_ostream *Stream) const {
868882
// Start a new section for relocations.
@@ -1371,6 +1385,14 @@ DebugNamesSectionRef::materialize(MCCASReader &Reader,
13711385
*this);
13721386
}
13731387

1388+
Expected<uint64_t>
1389+
AppleNamesSectionRef::materialize(MCCASReader &Reader,
1390+
raw_ostream *Stream) const {
1391+
StringRef Remaining = getData();
1392+
return materializeGenericDebugSection<AppleNamesSectionRef>(Reader, Remaining,
1393+
*this);
1394+
}
1395+
13741396
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
13751397
ArrayRef<cas::ObjectRef> Fragments) {
13761398
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1706,7 +1728,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
17061728
Asm.getContext().getObjectFileInfo()->getDwarfRangesSection(),
17071729
Asm.getContext().getObjectFileInfo()->getDwarfRnglistsSection(),
17081730
Asm.getContext().getObjectFileInfo()->getDwarfLineStrSection(),
1709-
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection()};
1731+
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection(),
1732+
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamesSection()};
17101733
}
17111734

17121735
Error MCCASBuilder::prepare() {
@@ -2650,6 +2673,23 @@ Error MCCASBuilder::createDebugNamesSection() {
26502673
return finalizeSection<DebugNamesSectionRef>();
26512674
}
26522675

2676+
Error MCCASBuilder::createAppleNamesSection() {
2677+
2678+
auto MaybeAppleNamesRef =
2679+
createGenericDebugRef<AppleNamesRef>(DwarfSections.AppleNames);
2680+
if (!MaybeAppleNamesRef)
2681+
return Error::success();
2682+
2683+
if (!*MaybeAppleNamesRef)
2684+
return MaybeAppleNamesRef->takeError();
2685+
2686+
startSection(DwarfSections.AppleNames);
2687+
addNode(**MaybeAppleNamesRef);
2688+
if (auto E = createPaddingRef(DwarfSections.AppleNames))
2689+
return E;
2690+
return finalizeSection<AppleNamesSectionRef>();
2691+
}
2692+
26532693
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
26542694
switch (Fragment.getKind()) {
26552695
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2830,6 +2870,13 @@ Error MCCASBuilder::buildFragments() {
28302870
continue;
28312871
}
28322872

2873+
// Handle Debug AppleNames sections separately.
2874+
if (&Sec == DwarfSections.AppleNames) {
2875+
if (auto E = createAppleNamesSection())
2876+
return E;
2877+
continue;
2878+
}
2879+
28332880
// Start Subsection for one section.
28342881
startSection(&Sec);
28352882

@@ -2992,7 +3039,7 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
29923039
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets &&
29933040
Sec != DwarfSections.Loclists && Sec != DwarfSections.Ranges &&
29943041
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr &&
2995-
Sec != DwarfSections.Names)
3042+
Sec != DwarfSections.Names && Sec != DwarfSections.AppleNames)
29963043
RelMap[R.F].push_back(R.MRE);
29973044
else
29983045
// If the fragment is nullptr, it should a section with only relocation
@@ -3209,6 +3256,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
32093256
return F->materialize(*this);
32103257
if (auto F = DebugNamesSectionRef::Cast(*Node))
32113258
return F->materialize(*this);
3259+
if (auto F = AppleNamesSectionRef::Cast(*Node))
3260+
return F->materialize(*this);
32123261
if (auto F = CStringRef::Cast(*Node)) {
32133262
auto Size = F->materialize(OS);
32143263
if (!Size)
@@ -3287,6 +3336,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
32873336
return F->materialize(*Stream);
32883337
if (auto F = DebugNamesRef::Cast(*Node))
32893338
return F->materialize(*Stream);
3339+
if (auto F = AppleNamesRef::Cast(*Node))
3340+
return F->materialize(*Stream);
32903341
if (auto F = AddendsRef::Cast(*Node))
32913342
// AddendsRef is already handled when materializing Atoms, skip.
32923343
return 0;

0 commit comments

Comments
 (0)