From ade71641dcf6fc2c457e318634f0bcff8f8feee1 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 18 Jan 2022 15:58:45 +1100 Subject: [PATCH] [ORC] Add Platform::teardownJITDylib method. This is a counterpart to Platform::setupJITDylib, and is called when JITDylib instances are removed (via ExecutionSession::removeJITDylib). Upcoming MachOPlatform patches will use this to clear per-JITDylib data when JITDylibs are removed. --- llvm/include/llvm/ExecutionEngine/Orc/Core.h | 4 ++++ llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h | 1 + llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h | 1 + llvm/lib/ExecutionEngine/Orc/Core.cpp | 7 ++++++- llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp | 4 ++++ llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 5 +++++ llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp | 2 ++ 7 files changed, 23 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h index b0931db..6bf5ba8 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h @@ -1309,6 +1309,10 @@ public: /// __dso_handle). virtual Error setupJITDylib(JITDylib &JD) = 0; + /// This method will be called outside the session lock each time a JITDylib + /// is removed to allow the Platform to remove any JITDylib-specific data. + virtual Error teardownJITDylib(JITDylib &JD) = 0; + /// This method will be called under the ExecutionSession lock each time a /// MaterializationUnit is added to a JITDylib. virtual Error notifyAdding(ResourceTracker &RT, diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h index 8f1bf85..6b12fe9 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ELFNixPlatform.h @@ -101,6 +101,7 @@ public: ObjectLinkingLayer &getObjectLinkingLayer() const { return ObjLinkingLayer; } Error setupJITDylib(JITDylib &JD) override; + Error teardownJITDylib(JITDylib &JD) override; Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) override; Error notifyRemoving(ResourceTracker &RT) override; diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h index 9482f20..01f3f1b 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h @@ -97,6 +97,7 @@ public: ObjectLinkingLayer &getObjectLinkingLayer() const { return ObjLinkingLayer; } Error setupJITDylib(JITDylib &JD) override; + Error teardownJITDylib(JITDylib &JD) override; Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) override; Error notifyRemoving(ResourceTracker &RT) override; diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index 01921c2..c6933cf 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -1933,9 +1933,14 @@ Error ExecutionSession::removeJITDylib(JITDylib &JD) { JDs.erase(I); }); - // Clear the JITDylib. + // Clear the JITDylib. Hold on to any error while we clean up the + // JITDylib members below. auto Err = JD.clear(); + // Notify the platform of the teardown. + if (P) + Err = joinErrors(std::move(Err), P->teardownJITDylib(JD)); + // Set JD to closed state. Clear remaining data structures. runSessionLocked([&] { assert(JD.State == JITDylib::Closing && "JD should be closing"); diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp index e25d7c4..2552955 100644 --- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp @@ -155,6 +155,10 @@ Error ELFNixPlatform::setupJITDylib(JITDylib &JD) { std::make_unique(*this, DSOHandleSymbol)); } +Error ELFNixPlatform::teardownJITDylib(JITDylib &JD) { + return Error::success(); +} + Error ELFNixPlatform::notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) { auto &JD = RT.getJITDylib(); diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 0ab0d7d..cffc340 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -89,6 +89,7 @@ class GenericLLVMIRPlatform : public Platform { public: GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {} Error setupJITDylib(JITDylib &JD) override; + Error teardownJITDylib(JITDylib &JD) override; Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) override; Error notifyRemoving(ResourceTracker &RT) override { @@ -460,6 +461,10 @@ Error GenericLLVMIRPlatform::setupJITDylib(JITDylib &JD) { return S.setupJITDylib(JD); } +Error GenericLLVMIRPlatform::teardownJITDylib(JITDylib &JD) { + return Error::success(); +} + Error GenericLLVMIRPlatform::notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) { return S.notifyAdding(RT, MU); diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp index c2a8965..9df4c8c 100644 --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -203,6 +203,8 @@ Error MachOPlatform::setupJITDylib(JITDylib &JD) { *this, MachOHeaderStartSymbol)); } +Error MachOPlatform::teardownJITDylib(JITDylib &JD) { return Error::success(); } + Error MachOPlatform::notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) { auto &JD = RT.getJITDylib(); -- 2.7.4