Skip to content

Commit c363031

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. (cherry picked from commit 687a046)
1 parent cb8e6a9 commit c363031

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
@@ -906,6 +906,20 @@ AppleNamespaceSectionRef::create(MCCASBuilder &MB,
906906
return get(B->build());
907907
}
908908

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

1449+
Expected<uint64_t> AppleObjCSectionRef::materialize(MCCASReader &Reader,
1450+
raw_ostream *Stream) const {
1451+
StringRef Remaining = getData();
1452+
return materializeGenericDebugSection<AppleObjCSectionRef>(Reader, Remaining,
1453+
*this);
1454+
}
1455+
14351456
Expected<AtomRef> AtomRef::create(MCCASBuilder &MB,
14361457
ArrayRef<cas::ObjectRef> Fragments) {
14371458
Expected<Builder> B = Builder::startNode(MB.Schema, KindString);
@@ -1770,7 +1791,8 @@ DwarfSectionsCache mccasformats::v1::getDwarfSections(MCAssembler &Asm) {
17701791
Asm.getContext().getObjectFileInfo()->getDwarfDebugNamesSection(),
17711792
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamesSection(),
17721793
Asm.getContext().getObjectFileInfo()->getDwarfAccelTypesSection(),
1773-
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamespaceSection()};
1794+
Asm.getContext().getObjectFileInfo()->getDwarfAccelNamespaceSection(),
1795+
Asm.getContext().getObjectFileInfo()->getDwarfAccelObjCSection()};
17741796
}
17751797

17761798
Error MCCASBuilder::prepare() {
@@ -2760,6 +2782,23 @@ Error MCCASBuilder::createAppleNamespaceSection() {
27602782
return finalizeSection<AppleNamespaceSectionRef>();
27612783
}
27622784

2785+
Error MCCASBuilder::createAppleObjCSection() {
2786+
2787+
auto MaybeAppleObjCRef =
2788+
createGenericDebugRef<AppleObjCRef>(DwarfSections.AppleObjC);
2789+
if (!MaybeAppleObjCRef)
2790+
return Error::success();
2791+
2792+
if (!*MaybeAppleObjCRef)
2793+
return MaybeAppleObjCRef->takeError();
2794+
2795+
startSection(DwarfSections.AppleObjC);
2796+
addNode(**MaybeAppleObjCRef);
2797+
if (auto E = createPaddingRef(DwarfSections.AppleObjC))
2798+
return E;
2799+
return finalizeSection<AppleObjCSectionRef>();
2800+
}
2801+
27632802
static ArrayRef<char> getFragmentContents(const MCFragment &Fragment) {
27642803
switch (Fragment.getKind()) {
27652804
#define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \
@@ -2961,6 +3000,13 @@ Error MCCASBuilder::buildFragments() {
29613000
continue;
29623001
}
29633002

3003+
// Handle Debug AppleObjC sections separately.
3004+
if (&Sec == DwarfSections.AppleObjC) {
3005+
if (auto E = createAppleObjCSection())
3006+
return E;
3007+
continue;
3008+
}
3009+
29643010
// Start Subsection for one section.
29653011
startSection(&Sec);
29663012

@@ -3125,7 +3171,7 @@ void MCCASBuilder::startSection(const MCSection *Sec) {
31253171
Sec != DwarfSections.Rangelists && Sec != DwarfSections.LineStr &&
31263172
Sec != DwarfSections.Names && Sec != DwarfSections.AppleNames &&
31273173
Sec != DwarfSections.AppleTypes &&
3128-
Sec != DwarfSections.AppleNamespace)
3174+
Sec != DwarfSections.AppleNamespace && Sec != DwarfSections.AppleObjC)
31293175
RelMap[R.F].push_back(R.MRE);
31303176
else
31313177
// If the fragment is nullptr, it should a section with only relocation
@@ -3348,6 +3394,8 @@ Expected<uint64_t> MCCASReader::materializeGroup(cas::ObjectRef ID) {
33483394
return F->materialize(*this);
33493395
if (auto F = AppleNamespaceSectionRef::Cast(*Node))
33503396
return F->materialize(*this);
3397+
if (auto F = AppleObjCSectionRef::Cast(*Node))
3398+
return F->materialize(*this);
33513399
if (auto F = CStringRef::Cast(*Node)) {
33523400
auto Size = F->materialize(OS);
33533401
if (!Size)
@@ -3432,6 +3480,8 @@ Expected<uint64_t> MCCASReader::materializeSection(cas::ObjectRef ID,
34323480
return F->materialize(*Stream);
34333481
if (auto F = AppleNamespaceRef::Cast(*Node))
34343482
return F->materialize(*Stream);
3483+
if (auto F = AppleObjCRef::Cast(*Node))
3484+
return F->materialize(*Stream);
34353485
if (auto F = AddendsRef::Cast(*Node))
34363486
// AddendsRef is already handled when materializing Atoms, skip.
34373487
return 0;

0 commit comments

Comments
 (0)