Skip to content

Commit 76d5a79

Browse files
authored
[ORC] Drop EHFrameRegistrar, register eh-frames with AllocActions (#130719)
This simplifies resource management, and should improve performance for most use cases.
1 parent 634e253 commit 76d5a79

File tree

18 files changed

+100
-323
lines changed

18 files changed

+100
-323
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,9 @@ class EHFrameCFIBlockInspector {
8383
};
8484
};
8585

86-
/// Supports registration/deregistration of EH-frames in a target process.
87-
class EHFrameRegistrar {
88-
public:
89-
virtual ~EHFrameRegistrar();
90-
virtual Error registerEHFrames(orc::ExecutorAddrRange EHFrameSection) = 0;
91-
virtual Error deregisterEHFrames(orc::ExecutorAddrRange EHFrameSection) = 0;
92-
};
93-
94-
/// Registers / Deregisters EH-frames in the current process.
95-
class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
96-
public:
97-
Error registerEHFrames(orc::ExecutorAddrRange EHFrameSection) override;
98-
99-
Error deregisterEHFrames(orc::ExecutorAddrRange EHFrameSection) override;
100-
};
101-
102-
using StoreFrameRangeFunction = std::function<void(
103-
orc::ExecutorAddr EHFrameSectionAddr, size_t EHFrameSectionSize)>;
104-
105-
/// Creates a pass that records the address and size of the EH frame section.
106-
/// If no eh-frame section is found then the address and size will both be given
107-
/// as zero.
108-
///
109-
/// Authors of JITLinkContexts can use this function to register a post-fixup
110-
/// pass that records the range of the eh-frame section. This range can
111-
/// be used after finalization to register and deregister the frame.
112-
LinkGraphPassFunction
113-
createEHFrameRecorderPass(const Triple &TT,
114-
StoreFrameRangeFunction StoreFrameRange);
86+
/// Returns a pointer to the DWARF eh-frame section if the graph contains a
87+
/// non-empty one, otherwise returns null.
88+
Section *getEHFrameSection(LinkGraph &G);
11589

11690
} // end namespace jitlink
11791
} // end namespace llvm

llvm/include/llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@
1919
#include <mutex>
2020
#include <vector>
2121

22-
namespace llvm {
23-
24-
namespace jitlink {
25-
class EHFrameRegistrar;
26-
} // namespace jitlink
27-
28-
namespace orc {
22+
namespace llvm::orc {
2923

24+
/// Adds AllocationActions to register and deregister eh-frame sections in the
25+
/// absence of native Platform support.
3026
class EHFrameRegistrationPlugin : public LinkGraphLinkingLayer::Plugin {
3127
public:
32-
EHFrameRegistrationPlugin(
33-
ExecutionSession &ES,
34-
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar);
28+
static Expected<std::unique_ptr<EHFrameRegistrationPlugin>>
29+
Create(ExecutionSession &ES);
30+
31+
EHFrameRegistrationPlugin(ExecutorAddr RegisterEHFrame,
32+
ExecutorAddr DeregisterEHFrame)
33+
: RegisterEHFrame(RegisterEHFrame), DeregisterEHFrame(DeregisterEHFrame) {
34+
}
35+
3536
void modifyPassConfig(MaterializationResponsibility &MR,
3637
jitlink::LinkGraph &G,
3738
jitlink::PassConfiguration &PassConfig) override;
38-
Error notifyEmitted(MaterializationResponsibility &MR) override;
39-
Error notifyFailed(MaterializationResponsibility &MR) override;
40-
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override;
39+
Error notifyFailed(MaterializationResponsibility &MR) override {
40+
return Error::success();
41+
}
42+
Error notifyRemovingResources(JITDylib &JD, ResourceKey K) override {
43+
return Error::success();
44+
}
4145
void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
42-
ResourceKey SrcKey) override;
46+
ResourceKey SrcKey) override {}
4347

4448
private:
45-
std::mutex EHFramePluginMutex;
46-
ExecutionSession &ES;
47-
std::unique_ptr<jitlink::EHFrameRegistrar> Registrar;
48-
DenseMap<MaterializationResponsibility *, ExecutorAddrRange> InProcessLinks;
49-
DenseMap<ResourceKey, std::vector<ExecutorAddrRange>> EHFrameRanges;
49+
ExecutorAddr RegisterEHFrame;
50+
ExecutorAddr DeregisterEHFrame;
5051
};
5152

52-
} // end namespace orc
53-
} // end namespace llvm
53+
} // namespace llvm::orc
5454

5555
#endif // LLVM_EXECUTIONENGINE_ORC_EHFRAMEREGISTRATIONPLUGIN_H

llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h

Lines changed: 0 additions & 58 deletions
This file was deleted.

llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ extern const char *MemoryWriteUInt64sWrapperName;
4444
extern const char *MemoryWriteBuffersWrapperName;
4545
extern const char *MemoryWritePointersWrapperName;
4646

47-
extern const char *RegisterEHFrameSectionWrapperName;
48-
extern const char *DeregisterEHFrameSectionWrapperName;
47+
extern const char *RegisterEHFrameSectionAllocActionName;
48+
extern const char *DeregisterEHFrameSectionAllocActionName;
4949

5050
extern const char *RunAsMainWrapperName;
5151
extern const char *RunAsVoidFunctionWrapperName;

llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
3535
} // end namespace llvm
3636

3737
extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult
38-
llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size);
38+
llvm_orc_registerEHFrameSectionAllocAction(const char *Data, uint64_t Size);
3939

4040
extern "C" LLVM_ABI llvm::orc::shared::CWrapperFunctionResult
41-
llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size);
41+
llvm_orc_deregisterEHFrameSectionAllocAction(const char *Data, uint64_t Size);
4242

4343
#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_REGISTEREHFRAMES_H

llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -639,20 +639,6 @@ Error EHFrameNullTerminator::operator()(LinkGraph &G) {
639639
return Error::success();
640640
}
641641

642-
EHFrameRegistrar::~EHFrameRegistrar() = default;
643-
644-
Error InProcessEHFrameRegistrar::registerEHFrames(
645-
orc::ExecutorAddrRange EHFrameSection) {
646-
return orc::registerEHFrameSection(EHFrameSection.Start.toPtr<void *>(),
647-
EHFrameSection.size());
648-
}
649-
650-
Error InProcessEHFrameRegistrar::deregisterEHFrames(
651-
orc::ExecutorAddrRange EHFrameSection) {
652-
return orc::deregisterEHFrameSection(EHFrameSection.Start.toPtr<void *>(),
653-
EHFrameSection.size());
654-
}
655-
656642
EHFrameCFIBlockInspector EHFrameCFIBlockInspector::FromEdgeScan(Block &B) {
657643
if (B.edges_empty())
658644
return EHFrameCFIBlockInspector(nullptr);
@@ -678,36 +664,24 @@ EHFrameCFIBlockInspector::EHFrameCFIBlockInspector(Edge &CIEEdge,
678664
Edge *LSDAEdge)
679665
: CIEEdge(&CIEEdge), PCBeginEdge(&PCBeginEdge), LSDAEdge(LSDAEdge) {}
680666

681-
LinkGraphPassFunction
682-
createEHFrameRecorderPass(const Triple &TT,
683-
StoreFrameRangeFunction StoreRangeAddress) {
667+
Section *getEHFrameSection(LinkGraph &G) {
684668
const char *EHFrameSectionName = nullptr;
685-
if (TT.getObjectFormat() == Triple::MachO)
669+
switch (G.getTargetTriple().getObjectFormat()) {
670+
case Triple::MachO:
686671
EHFrameSectionName = "__TEXT,__eh_frame";
687-
else
672+
break;
673+
case Triple::ELF:
688674
EHFrameSectionName = ".eh_frame";
675+
break;
676+
default:
677+
return nullptr;
678+
}
689679

690-
auto RecordEHFrame =
691-
[EHFrameSectionName,
692-
StoreFrameRange = std::move(StoreRangeAddress)](LinkGraph &G) -> Error {
693-
// Search for a non-empty eh-frame and record the address of the first
694-
// symbol in it.
695-
orc::ExecutorAddr Addr;
696-
size_t Size = 0;
697-
if (auto *S = G.findSectionByName(EHFrameSectionName)) {
698-
auto R = SectionRange(*S);
699-
Addr = R.getStart();
700-
Size = R.getSize();
701-
}
702-
if (!Addr && Size != 0)
703-
return make_error<JITLinkError>(
704-
StringRef(EHFrameSectionName) +
705-
" section can not have zero address with non-zero size");
706-
StoreFrameRange(Addr, Size);
707-
return Error::success();
708-
};
680+
if (auto *S = G.findSectionByName(EHFrameSectionName))
681+
if (!S->empty())
682+
return S;
709683

710-
return RecordEHFrame;
684+
return nullptr;
711685
}
712686

713687
} // end namespace jitlink

llvm/lib/ExecutionEngine/Orc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ add_llvm_component_library(LLVMOrcJIT
1818
EHFrameRegistrationPlugin.cpp
1919
EPCDynamicLibrarySearchGenerator.cpp
2020
EPCDebugObjectRegistrar.cpp
21-
EPCEHFrameRegistrar.cpp
2221
EPCGenericDylibManager.cpp
2322
EPCGenericJITLinkMemoryManager.cpp
2423
EPCGenericRTDyldMemoryManager.cpp

0 commit comments

Comments
 (0)