Skip to content

Commit 687a046

Browse files
Introduce apple_objc representation in MCCAS
MCCAS has an ability to have different block types for different data, this patch introduces AppleObjCRef and AppleObjCSectionRef to represent the apple_objc section in DWARF4.
1 parent 1d95a08 commit 687a046

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

llvm/include/llvm/MCCAS/MCCASObjectV1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ 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)
2929
CASV1_SIMPLE_DATA_REF(AppleNamespaceRef, mc:apple_namespac)
30+
CASV1_SIMPLE_DATA_REF(AppleObjCRef, mc:apple_objc)
3031
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
3132
CASV1_SIMPLE_DATA_REF(DebugLineUnoptRef, mc:debug_line_unopt)
3233
CASV1_SIMPLE_DATA_REF(DebugLineStrRef, mc:debug_line_str)
@@ -60,6 +61,7 @@ CASV1_SIMPLE_GROUP_REF(DebugNamesSectionRef, mc:debug_names_section)
6061
CASV1_SIMPLE_GROUP_REF(AppleNamesSectionRef, mc:apple_names_section)
6162
CASV1_SIMPLE_GROUP_REF(AppleTypesSectionRef, mc:apple_types_section)
6263
CASV1_SIMPLE_GROUP_REF(AppleNamespaceSectionRef, mc:apple_namepsac_section)
64+
CASV1_SIMPLE_GROUP_REF(AppleObjCSectionRef, mc:apple_objc_section)
6365
CASV1_SIMPLE_GROUP_REF(DIEAbbrevSetRef, mc:debug_DIE_abbrev_set)
6466
CASV1_SIMPLE_GROUP_REF(DIETopLevelRef, mc:debug_DIE_top_level)
6567
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
@@ -489,6 +489,7 @@ struct DwarfSectionsCache {
489489
MCSection *AppleNames;
490490
MCSection *AppleTypes;
491491
MCSection *AppleNamespace;
492+
MCSection *AppleObjC;
492493
};
493494

494495
/// Queries `Asm` for all dwarf sections and returns an object with (possibly
@@ -648,6 +649,10 @@ class MCCASBuilder {
648649
// object for the section.
649650
Error createAppleNamespaceSection();
650651

652+
// If a DWARF Apple Objc section exists, create a AppleObjcRef CAS
653+
// object for the section.
654+
Error createAppleObjCSection();
655+
651656
/// If there is any padding between one section and the next, create a
652657
/// PaddingRef CAS object to represent the bytes of Padding between the two
653658
/// sections.

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,20 @@ AppleNamespaceSectionRef::create(MCCASBuilder &MB,
905905
return get(B->build());
906906
}
907907

908+
Expected<AppleObjCSectionRef>
909+
AppleObjCSectionRef::create(MCCASBuilder &MB,
910+
ArrayRef<cas::ObjectRef> Fragments) {
911+
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
912+
if (!B)
913+
return B.takeError();
914+
915+
if (auto E = createGenericDebugSection<AppleObjCSectionRef>(MB, Fragments,
916+
B->Data, B->Refs))
917+
return E;
918+
919+
return get(B->build());
920+
}
921+
908922
Expected<uint64_t> SectionRef::materialize(MCCASReader &Reader,
909923
raw_ostream *Stream) const {
910924
// Start a new section for relocations.
@@ -1437,6 +1451,13 @@ AppleNamespaceSectionRef::materialize(MCCASReader &Reader,
14371451
Reader, Remaining, *this);
14381452
}
14391453

1454+
Expected<uint64_t> AppleObjCSectionRef::materialize(MCCASReader &Reader,
1455+
raw_ostream *Stream) const {
1456+
StringRef Remaining = getData();
1457+
return materializeGenericDebugSection<AppleObjCSectionRef>(Reader, Remaining,
1458+
*this);
1459+
}
1460+
14401461
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
14411462
ArrayRef<cas::ObjectRef> Fragments) {
14421463
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1775,7 +1796,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
17751796
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection(),
17761797
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamesSection(),
17771798
Asm.getContext().getObjectFileInfo()->getDwarfAccelTypesSection(),
1778-
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamespaceSection()};
1799+
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamespaceSection(),
1800+
Asm.getContext().getObjectFileInfo()->getDwarfAccelObjCSection()};
17791801
}
17801802

17811803
Error MCCASBuilder::prepare() {
@@ -2770,6 +2792,23 @@ Error MCCASBuilder::createAppleNamespaceSection() {
27702792
return finalizeSection<AppleNamespaceSectionRef>();
27712793
}
27722794

2795+
Error MCCASBuilder::createAppleObjCSection() {
2796+
2797+
auto MaybeAppleObjCRef =
2798+
createGenericDebugRef<AppleObjCRef>(DwarfSections.AppleObjC);
2799+
if (!MaybeAppleObjCRef)
2800+
return Error::success();
2801+
2802+
if (!*MaybeAppleObjCRef)
2803+
return MaybeAppleObjCRef->takeError();
2804+
2805+
startSection(DwarfSections.AppleObjC);
2806+
addNode(**MaybeAppleObjCRef);
2807+
if (auto E = createPaddingRef(DwarfSections.AppleObjC))
2808+
return E;
2809+
return finalizeSection<AppleObjCSectionRef>();
2810+
}
2811+
27732812
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
27742813
switch (Fragment.getKind()) {
27752814
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2971,6 +3010,13 @@ Error MCCASBuilder::buildFragments() {
29713010
continue;
29723011
}
29733012

3013+
// Handle Debug AppleObjC sections separately.
3014+
if (&Sec == DwarfSections.AppleObjC) {
3015+
if (auto E = createAppleObjCSection())
3016+
return E;
3017+
continue;
3018+
}
3019+
29743020
// Start Subsection for one section.
29753021
startSection(&Sec);
29763022

@@ -3135,7 +3181,7 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
31353181
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr &&
31363182
Sec != DwarfSections.Names && Sec != DwarfSections.AppleNames &&
31373183
Sec != DwarfSections.AppleTypes &&
3138-
Sec != DwarfSections.AppleNamespace)
3184+
Sec != DwarfSections.AppleNamespace && Sec != DwarfSections.AppleObjC)
31393185
RelMap[R.F].push_back(R.MRE);
31403186
else
31413187
// If the fragment is nullptr, it should a section with only relocation
@@ -3358,6 +3404,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
33583404
return F->materialize(*this);
33593405
if (auto F = AppleNamespaceSectionRef::Cast(*Node))
33603406
return F->materialize(*this);
3407+
if (auto F = AppleObjCSectionRef::Cast(*Node))
3408+
return F->materialize(*this);
33613409
if (auto F = CStringRef::Cast(*Node)) {
33623410
auto Size = F->materialize(OS);
33633411
if (!Size)
@@ -3442,6 +3490,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
34423490
return F->materialize(*Stream);
34433491
if (auto F = AppleNamespaceRef::Cast(*Node))
34443492
return F->materialize(*Stream);
3493+
if (auto F = AppleObjCRef::Cast(*Node))
3494+
return F->materialize(*Stream);
34453495
if (auto F = AddendsRef::Cast(*Node))
34463496
// AddendsRef is already handled when materializing Atoms, skip.
34473497
return 0;

0 commit comments

Comments
 (0)