Skip to content

Commit 744d390

Browse files
Introduce apple_types representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces AppleTypesRef and AppleTypesSectionRef to represent the apple_types section in DWARF4.
1 parent 2d62e3d commit 744d390

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
@@ -25,6 +25,7 @@ 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)
2727
CASV1_SIMPLE_DATA_REF(AppleNamesRef, mc:apple_names)
28+
CASV1_SIMPLE_DATA_REF(AppleTypesRef, mc:apple_types)
2829
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
2930
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
3031
CASV1_SIMPLE_DATA_REF(DebugLineStrRef, mc:debug_line_str)
@@ -56,6 +57,7 @@ CASV1_SIMPLE_GROUP_REF(DebugRangesSectionRef, mc:debug_ranges_section)
5657
CASV1_SIMPLE_GROUP_REF(DebugRangelistsSectionRef, mc:debug_rangelists_section)
5758
CASV1_SIMPLE_GROUP_REF(DebugNamesSectionRef, mc:debug_names_section)
5859
CASV1_SIMPLE_GROUP_REF(AppleNamesSectionRef, mc:apple_names_section)
60+
CASV1_SIMPLE_GROUP_REF(AppleTypesSectionRef, mc:apple_types_section)
5961
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
6062
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
6163
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
@@ -487,6 +487,7 @@ struct DwarfSectionsCache {
487487
MCSection *LineStr;
488488
MCSection *Names;
489489
MCSection *AppleNames;
490+
MCSection *AppleTypes;
490491
};
491492

492493
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -638,6 +639,10 @@ class MCCASBuilder {
638639
// object for the section.
639640
Error createAppleNamesSection();
640641

642+
// If a DWARF Apple Types section exists, create a AppleTypesRef CAS
643+
// object for the section.
644+
Error createAppleTypesSection();
645+
641646
/// If there is any padding between one section and the next, create a
642647
/// PaddingRef CAS object to represent the bytes of Padding between the two
643648
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,20 @@ AppleNamesSectionRef::create(MCCASBuilder &MB,
877877
return get(B->build());
878878
}
879879

880+
Expected<AppleTypesSectionRef>
881+
AppleTypesSectionRef::create(MCCASBuilder &MB,
882+
ArrayRef<cas::ObjectRef> Fragments) {
883+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
884+
if (!B)
885+
return B.takeError();
886+
887+
if (auto E = createGenericDebugSection<AppleTypesSectionRef>(
888+
MB, Fragments, B->Data, B->Refs))
889+
return E;
890+
891+
return get(B->build());
892+
}
893+
880894
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
881895
raw_ostream *Stream) const {
882896
// Start a new section for relocations.
@@ -1393,6 +1407,14 @@ AppleNamesSectionRef::materialize(MCCASReader &Reader,
13931407
*this);
13941408
}
13951409

1410+
Expected<uint64_t>
1411+
AppleTypesSectionRef::materialize(MCCASReader &Reader,
1412+
raw_ostream *Stream) const {
1413+
StringRef Remaining = getData();
1414+
return materializeGenericDebugSection<AppleTypesSectionRef>(Reader, Remaining,
1415+
*this);
1416+
}
1417+
13961418
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
13971419
ArrayRef<cas::ObjectRef> Fragments) {
13981420
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1729,7 +1751,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
17291751
Asm.getContext().getObjectFileInfo()->getDwarfRnglistsSection(),
17301752
Asm.getContext().getObjectFileInfo()->getDwarfLineStrSection(),
17311753
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection(),
1732-
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamesSection()};
1754+
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamesSection(),
1755+
Asm.getContext().getObjectFileInfo()->getDwarfAccelTypesSection()};
17331756
}
17341757

17351758
Error MCCASBuilder::prepare() {
@@ -2690,6 +2713,23 @@ Error MCCASBuilder::createAppleNamesSection() {
26902713
return finalizeSection<AppleNamesSectionRef>();
26912714
}
26922715

2716+
Error MCCASBuilder::createAppleTypesSection() {
2717+
2718+
auto MaybeAppleTypesRef =
2719+
createGenericDebugRef<AppleTypesRef>(DwarfSections.AppleTypes);
2720+
if (!MaybeAppleTypesRef)
2721+
return Error::success();
2722+
2723+
if (!*MaybeAppleTypesRef)
2724+
return MaybeAppleTypesRef->takeError();
2725+
2726+
startSection(DwarfSections.AppleTypes);
2727+
addNode(**MaybeAppleTypesRef);
2728+
if (auto E = createPaddingRef(DwarfSections.AppleTypes))
2729+
return E;
2730+
return finalizeSection<AppleTypesSectionRef>();
2731+
}
2732+
26932733
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
26942734
switch (Fragment.getKind()) {
26952735
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2877,6 +2917,13 @@ Error MCCASBuilder::buildFragments() {
28772917
continue;
28782918
}
28792919

2920+
// Handle Debug AppleTypes sections separately.
2921+
if (&Sec == DwarfSections.AppleTypes) {
2922+
if (auto E = createAppleTypesSection())
2923+
return E;
2924+
continue;
2925+
}
2926+
28802927
// Start Subsection for one section.
28812928
startSection(&Sec);
28822929

@@ -3039,7 +3086,8 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
30393086
Sec != DwarfSections.Abbrev && Sec != DwarfSections.StrOffsets &&
30403087
Sec != DwarfSections.Loclists && Sec != DwarfSections.Ranges &&
30413088
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr &&
3042-
Sec != DwarfSections.Names && Sec != DwarfSections.AppleNames)
3089+
Sec != DwarfSections.Names && Sec != DwarfSections.AppleNames &&
3090+
Sec != DwarfSections.AppleTypes)
30433091
RelMap[R.F].push_back(R.MRE);
30443092
else
30453093
// If the fragment is nullptr, it should a section with only relocation
@@ -3258,6 +3306,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
32583306
return F->materialize(*this);
32593307
if (auto F = AppleNamesSectionRef::Cast(*Node))
32603308
return F->materialize(*this);
3309+
if (auto F = AppleTypesSectionRef::Cast(*Node))
3310+
return F->materialize(*this);
32613311
if (auto F = CStringRef::Cast(*Node)) {
32623312
auto Size = F->materialize(OS);
32633313
if (!Size)
@@ -3338,6 +3388,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
33383388
return F->materialize(*Stream);
33393389
if (auto F = AppleNamesRef::Cast(*Node))
33403390
return F->materialize(*Stream);
3391+
if (auto F = AppleTypesRef::Cast(*Node))
3392+
return F->materialize(*Stream);
33413393
if (auto F = AddendsRef::Cast(*Node))
33423394
// AddendsRef is already handled when materializing Atoms, skip.
33433395
return 0;

0 commit comments

Comments
 (0)