From 605df8112cca3c68f044e4f761a1744c39f52c9d Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 26 Aug 2020 16:56:33 -0700 Subject: [PATCH] [ORC][JITLink] Switch to unique ownership for EHFrameRegistrars. This will make stateful registrars (e.g. a future TargetProcessControl based registrar) easier to deal with. --- .../llvm/ExecutionEngine/JITLink/EHFrameSupport.h | 25 ++-------------------- .../llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h | 5 +++-- .../lib/ExecutionEngine/JITLink/EHFrameSupport.cpp | 15 +++++++++---- llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 2 +- .../lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp | 13 ++++++----- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 2 +- 6 files changed, 24 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h index 7268768..72394d7 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h @@ -42,32 +42,11 @@ public: /// 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(EHFrameSectionAddr), - EHFrameSectionSize); - } + size_t EHFrameSectionSize) override; Error deregisterEHFrames(JITTargetAddress EHFrameSectionAddr, - size_t EHFrameSectionSize) override { - return deregisterEHFrameSection( - jitTargetAddressToPointer(EHFrameSectionAddr), - EHFrameSectionSize); - } - -private: - InProcessEHFrameRegistrar(); + size_t EHFrameSectionSize) override; }; using StoreFrameRangeFunction = diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h index fbf9bde..cb8ee13 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h @@ -177,7 +177,8 @@ private: class EHFrameRegistrationPlugin : public ObjectLinkingLayer::Plugin { public: - EHFrameRegistrationPlugin(jitlink::EHFrameRegistrar &Registrar); + EHFrameRegistrationPlugin( + std::unique_ptr Registrar); Error notifyEmitted(MaterializationResponsibility &MR) override; void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT, jitlink::PassConfiguration &PassConfig) override; @@ -192,7 +193,7 @@ private: }; std::mutex EHFramePluginMutex; - jitlink::EHFrameRegistrar &Registrar; + std::unique_ptr Registrar; DenseMap InProcessLinks; DenseMap TrackedEHFrameRanges; std::vector UntrackedEHFrameRanges; diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp index 54ba9ac..9eda6fb 100644 --- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp @@ -763,12 +763,19 @@ Error deregisterEHFrameSection(const void *EHFrameSectionAddr, EHFrameRegistrar::~EHFrameRegistrar() {} -InProcessEHFrameRegistrar &InProcessEHFrameRegistrar::getInstance() { - static InProcessEHFrameRegistrar Instance; - return Instance; +Error InProcessEHFrameRegistrar::registerEHFrames( + JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) { + return registerEHFrameSection( + jitTargetAddressToPointer(EHFrameSectionAddr), + EHFrameSectionSize); } -InProcessEHFrameRegistrar::InProcessEHFrameRegistrar() {} +Error InProcessEHFrameRegistrar::deregisterEHFrames( + JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) { + return deregisterEHFrameSection( + jitTargetAddressToPointer(EHFrameSectionAddr), + EHFrameSectionSize); +} LinkGraphPassFunction createEHFrameRecorderPass(const Triple &TT, diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 531a71d5..56dec86 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -984,7 +984,7 @@ Error LLJITBuilderState::prepareForConstruction() { ObjLinkingLayer = std::make_unique( ES, std::make_unique()); ObjLinkingLayer->addPlugin(std::make_unique( - jitlink::InProcessEHFrameRegistrar::getInstance())); + std::make_unique())); return std::move(ObjLinkingLayer); }; } diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp index 5b828ed..50fa23d 100644 --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -536,8 +536,8 @@ Error ObjectLinkingLayer::removeAllModules() { } EHFrameRegistrationPlugin::EHFrameRegistrationPlugin( - EHFrameRegistrar &Registrar) - : Registrar(Registrar) {} + std::unique_ptr Registrar) + : Registrar(std::move(Registrar)) {} void EHFrameRegistrationPlugin::modifyPassConfig( MaterializationResponsibility &MR, const Triple &TT, @@ -572,7 +572,7 @@ Error EHFrameRegistrationPlugin::notifyEmitted( else UntrackedEHFrameRanges.push_back(EHFrameRange); - return Registrar.registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size); + return Registrar->registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size); } Error EHFrameRegistrationPlugin::notifyRemovingModule(VModuleKey K) { @@ -587,7 +587,7 @@ 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() { @@ -608,9 +608,8 @@ 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; diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index ff9579b..f1cc1f2 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -618,7 +618,7 @@ Session::Session(Triple TT, uint64_t PageSize, Error &Err) if (!NoExec && !TT.isOSWindows()) ObjLayer.addPlugin(std::make_unique( - InProcessEHFrameRegistrar::getInstance())); + std::make_unique())); ObjLayer.addPlugin(std::make_unique(*this)); -- 2.7.4