Skip to content

Commit 1d95a08

Browse files
Introduce apple_namepsac representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces AppleNamespaceRef and AppleNamespaceSectionRef to represent the apple_namepsac section in DWARF4.
1 parent 744d390 commit 1d95a08

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
@@ -26,6 +26,7 @@ CASV1_SIMPLE_DATA_REF(DebugRangelistsRef, mc:debug_rangelists)
2626
CASV1_SIMPLE_DATA_REF(DebugNamesRef, mc:debug_names)
2727
CASV1_SIMPLE_DATA_REF(AppleNamesRef, mc:apple_names)
2828
CASV1_SIMPLE_DATA_REF(AppleTypesRef, mc:apple_types)
29+
CASV1_SIMPLE_DATA_REF(AppleNamespaceRef, mc:apple_namespac)
2930
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
3031
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
3132
CASV1_SIMPLE_DATA_REF(DebugLineStrRef, mc:debug_line_str)
@@ -58,6 +59,7 @@ CASV1_SIMPLE_GROUP_REF(DebugRangelistsSectionRef, mc:debug_rangelists_section)
5859
CASV1_SIMPLE_GROUP_REF(DebugNamesSectionRef, mc:debug_names_section)
5960
CASV1_SIMPLE_GROUP_REF(AppleNamesSectionRef, mc:apple_names_section)
6061
CASV1_SIMPLE_GROUP_REF(AppleTypesSectionRef, mc:apple_types_section)
62+
CASV1_SIMPLE_GROUP_REF(AppleNamespaceSectionRef, mc:apple_namepsac_section)
6163
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
6264
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
6365
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
@@ -488,6 +488,7 @@ struct DwarfSectionsCache {
488488
MCSection *Names;
489489
MCSection *AppleNames;
490490
MCSection *AppleTypes;
491+
MCSection *AppleNamespace;
491492
};
492493

493494
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -643,6 +644,10 @@ class MCCASBuilder {
643644
// object for the section.
644645
Error createAppleTypesSection();
645646

647+
// If a DWARF Apple Namespaces section exists, create a AppleNamespaceRef CAS
648+
// object for the section.
649+
Error createAppleNamespaceSection();
650+
646651
/// If there is any padding between one section and the next, create a
647652
/// PaddingRef CAS object to represent the bytes of Padding between the two
648653
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,20 @@ AppleTypesSectionRef::create(MCCASBuilder &MB,
891891
return get(B->build());
892892
}
893893

894+
Expected<AppleNamespaceSectionRef>
895+
AppleNamespaceSectionRef::create(MCCASBuilder &MB,
896+
ArrayRef<cas::ObjectRef> Fragments) {
897+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
898+
if (!B)
899+
return B.takeError();
900+
901+
if (auto E = createGenericDebugSection<AppleNamespaceSectionRef>(
902+
MB, Fragments, B->Data, B->Refs))
903+
return E;
904+
905+
return get(B->build());
906+
}
907+
894908
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
895909
raw_ostream *Stream) const {
896910
// Start a new section for relocations.
@@ -1415,6 +1429,14 @@ AppleTypesSectionRef::materialize(MCCASReader &Reader,
14151429
*this);
14161430
}
14171431

1432+
Expected<uint64_t>
1433+
AppleNamespaceSectionRef::materialize(MCCASReader &Reader,
1434+
raw_ostream *Stream) const {
1435+
StringRef Remaining = getData();
1436+
return materializeGenericDebugSection<AppleNamespaceSectionRef>(
1437+
Reader, Remaining, *this);
1438+
}
1439+
14181440
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
14191441
ArrayRef<cas::ObjectRef> Fragments) {
14201442
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1752,7 +1774,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
17521774
Asm.getContext().getObjectFileInfo()->getDwarfLineStrSection(),
17531775
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection(),
17541776
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamesSection(),
1755-
Asm.getContext().getObjectFileInfo()->getDwarfAccelTypesSection()};
1777+
Asm.getContext().getObjectFileInfo()->getDwarfAccelTypesSection(),
1778+
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamespaceSection()};
17561779
}
17571780

17581781
Error MCCASBuilder::prepare() {
@@ -2730,6 +2753,23 @@ Error MCCASBuilder::createAppleTypesSection() {
27302753
return finalizeSection<AppleTypesSectionRef>();
27312754
}
27322755

2756+
Error MCCASBuilder::createAppleNamespaceSection() {
2757+
2758+
auto MaybeAppleNamespaceRef =
2759+
createGenericDebugRef<AppleNamespaceRef>(DwarfSections.AppleNamespace);
2760+
if (!MaybeAppleNamespaceRef)
2761+
return Error::success();
2762+
2763+
if (!*MaybeAppleNamespaceRef)
2764+
return MaybeAppleNamespaceRef->takeError();
2765+
2766+
startSection(DwarfSections.AppleNamespace);
2767+
addNode(**MaybeAppleNamespaceRef);
2768+
if (auto E = createPaddingRef(DwarfSections.AppleNamespace))
2769+
return E;
2770+
return finalizeSection<AppleNamespaceSectionRef>();
2771+
}
2772+
27332773
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
27342774
switch (Fragment.getKind()) {
27352775
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2924,6 +2964,13 @@ Error MCCASBuilder::buildFragments() {
29242964
continue;
29252965
}
29262966

2967+
// Handle Debug AppleNamespace sections separately.
2968+
if (&Sec == DwarfSections.AppleNamespace) {
2969+
if (auto E = createAppleNamespaceSection())
2970+
return E;
2971+
continue;
2972+
}
2973+
29272974
// Start Subsection for one section.
29282975
startSection(&Sec);
29292976

@@ -3087,7 +3134,8 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
30873134
Sec != DwarfSections.Loclists && Sec != DwarfSections.Ranges &&
30883135
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr &&
30893136
Sec != DwarfSections.Names && Sec != DwarfSections.AppleNames &&
3090-
Sec != DwarfSections.AppleTypes)
3137+
Sec != DwarfSections.AppleTypes &&
3138+
Sec != DwarfSections.AppleNamespace)
30913139
RelMap[R.F].push_back(R.MRE);
30923140
else
30933141
// If the fragment is nullptr, it should a section with only relocation
@@ -3308,6 +3356,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
33083356
return F->materialize(*this);
33093357
if (auto F = AppleTypesSectionRef::Cast(*Node))
33103358
return F->materialize(*this);
3359+
if (auto F = AppleNamespaceSectionRef::Cast(*Node))
3360+
return F->materialize(*this);
33113361
if (auto F = CStringRef::Cast(*Node)) {
33123362
auto Size = F->materialize(OS);
33133363
if (!Size)
@@ -3390,6 +3440,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
33903440
return F->materialize(*Stream);
33913441
if (auto F = AppleTypesRef::Cast(*Node))
33923442
return F->materialize(*Stream);
3443+
if (auto F = AppleNamespaceRef::Cast(*Node))
3444+
return F->materialize(*Stream);
33933445
if (auto F = AddendsRef::Cast(*Node))
33943446
// AddendsRef is already handled when materializing Atoms, skip.
33953447
return 0;

0 commit comments

Comments
 (0)