/// Registers / Deregisters EH-frames in the current process.
class InProcessEHFrameRegistrar final : public EHFrameRegistrar {
public:
- /// Get a reference to the InProcessEHFrameRegistrar singleton.
- static InProcessEHFrameRegistrar &getInstance();
-
- InProcessEHFrameRegistrar(const InProcessEHFrameRegistrar &) = delete;
- InProcessEHFrameRegistrar &
- operator=(const InProcessEHFrameRegistrar &) = delete;
-
- InProcessEHFrameRegistrar(InProcessEHFrameRegistrar &&) = delete;
- InProcessEHFrameRegistrar &operator=(InProcessEHFrameRegistrar &&) = delete;
-
Error registerEHFrames(JITTargetAddress EHFrameSectionAddr,
- size_t EHFrameSectionSize) override {
- return registerEHFrameSection(
- jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
- EHFrameSectionSize);
- }
+ size_t EHFrameSectionSize) override;
Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr,
- size_t EHFrameSectionSize) override {
- return deregisterEHFrameSection(
- jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
- EHFrameSectionSize);
- }
-
-private:
- InProcessEHFrameRegistrar();
+ size_t EHFrameSectionSize) override;
};
using StoreFrameRangeFunction =
class EHFrameRegistrationPlugin : public ObjectLinkingLayer::Plugin {
public:
- EHFrameRegistrationPlugin(jitlink::EHFrameRegistrar &Registrar);
+ EHFrameRegistrationPlugin(
+ std::unique_ptr<jitlink::EHFrameRegistrar> Registrar);
Error notifyEmitted(MaterializationResponsibility &MR) override;
void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT,
jitlink::PassConfiguration &PassConfig) override;
};
std::mutex EHFramePluginMutex;
- jitlink::EHFrameRegistrar &Registrar;
+ std::unique_ptr<jitlink::EHFrameRegistrar> Registrar;
DenseMap<MaterializationResponsibility *, EHFrameRange> InProcessLinks;
DenseMap<VModuleKey, EHFrameRange> TrackedEHFrameRanges;
std::vector<EHFrameRange> UntrackedEHFrameRanges;
EHFrameRegistrar::~EHFrameRegistrar() {}
-InProcessEHFrameRegistrar &InProcessEHFrameRegistrar::getInstance() {
- static InProcessEHFrameRegistrar Instance;
- return Instance;
+Error InProcessEHFrameRegistrar::registerEHFrames(
+ JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
+ return registerEHFrameSection(
+ jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
+ EHFrameSectionSize);
}
-InProcessEHFrameRegistrar::InProcessEHFrameRegistrar() {}
+Error InProcessEHFrameRegistrar::deregisterEHFrames(
+ JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
+ return deregisterEHFrameSection(
+ jitTargetAddressToPointer<void *>(EHFrameSectionAddr),
+ EHFrameSectionSize);
+}
LinkGraphPassFunction
createEHFrameRecorderPass(const Triple &TT,
ObjLinkingLayer = std::make_unique<ObjectLinkingLayer>(
ES, std::make_unique<jitlink::InProcessMemoryManager>());
ObjLinkingLayer->addPlugin(std::make_unique<EHFrameRegistrationPlugin>(
- jitlink::InProcessEHFrameRegistrar::getInstance()));
+ std::make_unique<jitlink::InProcessEHFrameRegistrar>()));
return std::move(ObjLinkingLayer);
};
}
}
EHFrameRegistrationPlugin::EHFrameRegistrationPlugin(
- EHFrameRegistrar &Registrar)
- : Registrar(Registrar) {}
+ std::unique_ptr<EHFrameRegistrar> Registrar)
+ : Registrar(std::move(Registrar)) {}
void EHFrameRegistrationPlugin::modifyPassConfig(
MaterializationResponsibility &MR, const Triple &TT,
else
UntrackedEHFrameRanges.push_back(EHFrameRange);
- return Registrar.registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
+ return Registrar->registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
}
Error EHFrameRegistrationPlugin::notifyRemovingModule(VModuleKey K) {
TrackedEHFrameRanges.erase(EHFrameRangeItr);
- return Registrar.deregisterEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
+ return Registrar->deregisterEHFrames(EHFrameRange.Addr, EHFrameRange.Size);
}
Error EHFrameRegistrationPlugin::notifyRemovingAllModules() {
auto EHFrameRange = EHFrameRanges.back();
assert(EHFrameRange.Addr && "Untracked eh-frame range must not be null");
EHFrameRanges.pop_back();
- Err = joinErrors(std::move(Err),
- Registrar.deregisterEHFrames(EHFrameRange.Addr,
- EHFrameRange.Size));
+ Err = joinErrors(std::move(Err), Registrar->deregisterEHFrames(
+ EHFrameRange.Addr, EHFrameRange.Size));
}
return Err;
if (!NoExec && !TT.isOSWindows())
ObjLayer.addPlugin(std::make_unique<EHFrameRegistrationPlugin>(
- InProcessEHFrameRegistrar::getInstance()));
+ std::make_unique<InProcessEHFrameRegistrar>()));
ObjLayer.addPlugin(std::make_unique<JITLinkSessionPlugin>(*this));