diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp --- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp @@ -18,40 +18,41 @@ namespace llvm { namespace jitlink { -EHFrameSplitter::EHFrameSplitter(StringRef EHFrameSectionName) - : EHFrameSectionName(EHFrameSectionName) {} +DWARFRecordSectionSplitter::DWARFRecordSectionSplitter(StringRef SectionName) + : SectionName(SectionName) {} -Error EHFrameSplitter::operator()(LinkGraph &G) { - auto *EHFrame = G.findSectionByName(EHFrameSectionName); +Error DWARFRecordSectionSplitter::operator()(LinkGraph &G) { + auto *Section = G.findSectionByName(SectionName); - if (!EHFrame) { + if (!Section) { LLVM_DEBUG({ - dbgs() << "EHFrameSplitter: No " << EHFrameSectionName + dbgs() << "DWARFRecordSectionSplitter: No " << SectionName << " section. Nothing to do\n"; }); return Error::success(); } LLVM_DEBUG({ - dbgs() << "EHFrameSplitter: Processing " << EHFrameSectionName << "...\n"; + dbgs() << "DWARFRecordSectionSplitter: Processing " << SectionName + << "...\n"; }); DenseMap Caches; { // Pre-build the split caches. - for (auto *B : EHFrame->blocks()) + for (auto *B : Section->blocks()) Caches[B] = LinkGraph::SplitBlockCache::value_type(); - for (auto *Sym : EHFrame->symbols()) + for (auto *Sym : Section->symbols()) Caches[&Sym->getBlock()]->push_back(Sym); - for (auto *B : EHFrame->blocks()) + for (auto *B : Section->blocks()) llvm::sort(*Caches[B], [](const Symbol *LHS, const Symbol *RHS) { return LHS->getOffset() > RHS->getOffset(); }); } // Iterate over blocks (we do this by iterating over Caches entries rather - // than EHFrame->blocks() as we will be inserting new blocks along the way, + // than Section->blocks() as we will be inserting new blocks along the way, // which would invalidate iterators in the latter sequence. for (auto &KV : Caches) { auto &B = *KV.first; @@ -63,14 +64,14 @@ return Error::success(); } -Error EHFrameSplitter::processBlock(LinkGraph &G, Block &B, - LinkGraph::SplitBlockCache &Cache) { +Error DWARFRecordSectionSplitter::processBlock( + LinkGraph &G, Block &B, LinkGraph::SplitBlockCache &Cache) { LLVM_DEBUG(dbgs() << " Processing block at " << B.getAddress() << "\n"); - // eh-frame should not contain zero-fill blocks. + // Section should not contain zero-fill blocks. if (B.isZeroFill()) return make_error("Unexpected zero-fill block in " + - EHFrameSectionName + " section"); + SectionName + " section"); if (B.getSize() == 0) { LLVM_DEBUG(dbgs() << " Block is empty. Skipping.\n"); diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h --- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h +++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h @@ -21,19 +21,19 @@ namespace llvm { namespace jitlink { -/// A LinkGraph pass that splits blocks in an eh-frame section into sub-blocks -/// representing individual eh-frames. -/// EHFrameSplitter should not be run without EHFrameEdgeFixer, which is -/// responsible for adding FDE-to-CIE edges. -class EHFrameSplitter { +/// A LinkGraph pass that splits blocks in a section that follows the DWARF +/// Record format into sub-blocks where each header gets its own block. +/// When splitting EHFrames, DWARFRecordSectionSplitter should not be run +/// without EHFrameEdgeFixer, which is responsible for adding FDE-to-CIE edges. +class DWARFRecordSectionSplitter { public: - EHFrameSplitter(StringRef EHFrameSectionName); + DWARFRecordSectionSplitter(StringRef SectionName); Error operator()(LinkGraph &G); private: Error processBlock(LinkGraph &G, Block &B, LinkGraph::SplitBlockCache &Cache); - StringRef EHFrameSectionName; + StringRef SectionName; }; /// A LinkGraph pass that adds missing FDE-to-CIE, FDE-to-PC and FDE-to-LSDA diff --git a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp @@ -379,7 +379,7 @@ if (Ctx->shouldAddDefaultTargetPasses(G->getTargetTriple())) { - Config.PrePrunePasses.push_back(EHFrameSplitter(".eh_frame")); + Config.PrePrunePasses.push_back(DWARFRecordSectionSplitter(".eh_frame")); Config.PrePrunePasses.push_back( EHFrameEdgeFixer(".eh_frame", x86_64::PointerSize, x86_64::Delta64, x86_64::Delta32, x86_64::NegDelta32)); diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp @@ -712,7 +712,8 @@ // Add eh-frame passses. // FIXME: Prune eh-frames for which compact-unwind is available once // we support compact-unwind registration with libunwind. - Config.PrePrunePasses.push_back(EHFrameSplitter("__TEXT,__eh_frame")); + Config.PrePrunePasses.push_back( + DWARFRecordSectionSplitter("__TEXT,__eh_frame")); Config.PrePrunePasses.push_back( EHFrameEdgeFixer("__TEXT,__eh_frame", 8, Delta64, Delta32, NegDelta32)); diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp --- a/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/MachO_x86_64.cpp @@ -504,7 +504,7 @@ } LinkGraphPassFunction createEHFrameSplitterPass_MachO_x86_64() { - return EHFrameSplitter("__TEXT,__eh_frame"); + return DWARFRecordSectionSplitter("__TEXT,__eh_frame"); } LinkGraphPassFunction createEHFrameEdgeFixerPass_MachO_x86_64() { diff --git a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_ehframe.s b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_ehframe.s --- a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_ehframe.s +++ b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_ehframe.s @@ -5,7 +5,7 @@ # # Check that splitting of eh-frame sections works. # -# CHECK: EHFrameSplitter: Processing __TEXT,__eh_frame... +# CHECK: DWARFRecordSectionSplitter: Processing __TEXT,__eh_frame... # CHECK: Processing block at # CHECK: Processing CFI record at # CHECK: Extracted {{.*}} section = __TEXT,__eh_frame