diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h --- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h +++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h @@ -124,9 +124,7 @@ return CODLayer.findSymbol(MangledNameStream.str(), true); } - void removeModule(VModuleKey K) { - cantFail(CODLayer.removeModule(K)); - } + void removeModule(VModuleKey K) { cantFail(CODLayer.removeModule(K)); } private: std::unique_ptr optimizeModule(std::unique_ptr M) { diff --git a/llvm/examples/OrcV2Examples/CMakeLists.txt b/llvm/examples/OrcV2Examples/CMakeLists.txt --- a/llvm/examples/OrcV2Examples/CMakeLists.txt +++ b/llvm/examples/OrcV2Examples/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(LLJITDumpObjects) +add_subdirectory(LLJITRemoveCode) add_subdirectory(LLJITWithCustomObjectLinkingLayer) add_subdirectory(LLJITWithGDBRegistrationListener) add_subdirectory(LLJITWithInitializers) diff --git a/llvm/examples/OrcV2Examples/ExampleModules.h b/llvm/examples/OrcV2Examples/ExampleModules.h --- a/llvm/examples/OrcV2Examples/ExampleModules.h +++ b/llvm/examples/OrcV2Examples/ExampleModules.h @@ -30,6 +30,14 @@ } )"; +const llvm::StringRef NoopEntryPointExample = + R"( + define void @entry() { + entry: + ret void + } +)"; + inline llvm::Expected parseExampleModule(llvm::StringRef Source, llvm::StringRef Name) { using namespace llvm; diff --git a/llvm/examples/OrcV2Examples/LLJITRemoveCode/CMakeLists.txt b/llvm/examples/OrcV2Examples/LLJITRemoveCode/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/llvm/examples/OrcV2Examples/LLJITRemoveCode/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_LINK_COMPONENTS + Core + ExecutionEngine + IRReader + JITLink + OrcJIT + Support + nativecodegen + ) + +add_llvm_example(LLJITRemoveCode + LLJITRemoveCode.cpp + ) diff --git a/llvm/examples/OrcV2Examples/LLJITRemoveCode/LLJITRemoveCode.cpp b/llvm/examples/OrcV2Examples/LLJITRemoveCode/LLJITRemoveCode.cpp new file mode 100644 --- /dev/null +++ b/llvm/examples/OrcV2Examples/LLJITRemoveCode/LLJITRemoveCode.cpp @@ -0,0 +1,85 @@ +//===--------------- LLJITWithCustomObjectLinkingLayer.cpp ----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file shows how to switch LLJIT to use a custom object linking layer (we +// use ObjectLinkingLayer, which is backed by JITLink, as an example). +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringMap.h" +#include "llvm/ExecutionEngine/JITLink/JITLink.h" +#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h" +#include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/raw_ostream.h" + +#include "../ExampleModules.h" + +using namespace llvm; +using namespace llvm::orc; + +ExitOnError ExitOnErr; + +class MyPlugin : public ObjectLinkingLayer::Plugin { +public: + Error notifyRemoving(JITDylib &JD) override { + dbgs() << "Removing resources for JITDylib " << JD.getName() << "\n"; + return Error::success(); + } +}; + +int main(int argc, char *argv[]) { + // Initialize LLVM. + InitLLVM X(argc, argv); + + InitializeNativeTarget(); + InitializeNativeTargetAsmPrinter(); + + cl::ParseCommandLineOptions(argc, argv, "LLJITWithObjectLinkingLayerPlugin"); + ExitOnErr.setBanner(std::string(argv[0]) + ": "); + + // Detect the host and set code model to small. + auto JTMB = ExitOnErr(JITTargetMachineBuilder::detectHost()); + JTMB.setCodeModel(CodeModel::Small); + + // Create an LLJIT instance with an ObjectLinkingLayer as the base layer. + // We attach our plugin in to the newly created ObjectLinkingLayer before + // returning it. + auto J = ExitOnErr( + LLJITBuilder() + .setJITTargetMachineBuilder(std::move(JTMB)) + .setObjectLinkingLayerCreator( + [&](ExecutionSession &ES, const Triple &TT) { + // Create ObjectLinkingLayer. + auto ObjLinkingLayer = std::make_unique( + ES, std::make_unique()); + // Add an instance of our plugin. + ObjLinkingLayer->addPlugin(std::make_unique()); + return ObjLinkingLayer; + }) + .create()); + + auto M = ExitOnErr(parseExampleModule(NoopEntryPointExample, "test-module")); + + auto &MyJD = ExitOnErr(J->getExecutionSession().createJITDylib("MyJD")); + ExitOnErr(J->addIRModule(MyJD, std::move(M))); + + // Look up the JIT'd function, cast it to a function pointer, then call it. + auto EntrySym = ExitOnErr(J->lookup(MyJD, "entry")); + auto *Entry = (void (*)())EntrySym.getAddress(); + + // Call the entry point to make sure it executes successfully. + Entry(); + + // Now close the JITDylib. + ExitOnErr(J->getExecutionSession().destroyJITDylib(MyJD)); + + return 0; +} diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h --- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h @@ -423,9 +423,6 @@ /// into. JITDylib &getTargetJITDylib() const { return JD; } - /// Returns the VModuleKey for this instance. - VModuleKey getVModuleKey() const { return K; } - /// Returns the symbol flags map for this responsibility instance. /// Note: The returned flags may have transient flags (Lazy, Materializing) /// set. These should be stripped with JITSymbolFlags::stripTransientFlags @@ -514,8 +511,7 @@ /// Delegates responsibility for the given symbols to the returned /// materialization responsibility. Useful for breaking up work between /// threads, or different kinds of materialization processes. - MaterializationResponsibility delegate(const SymbolNameSet &Symbols, - VModuleKey NewKey = VModuleKey()); + MaterializationResponsibility delegate(const SymbolNameSet &Symbols); void addDependencies(const SymbolStringPtr &Name, const SymbolDependenceMap &Dependencies); @@ -527,16 +523,15 @@ /// Create a MaterializationResponsibility for the given JITDylib and /// initial symbols. MaterializationResponsibility(JITDylib &JD, SymbolFlagsMap SymbolFlags, - SymbolStringPtr InitSymbol, VModuleKey K) + SymbolStringPtr InitSymbol) : JD(JD), SymbolFlags(std::move(SymbolFlags)), - InitSymbol(std::move(InitSymbol)), K(std::move(K)) { + InitSymbol(std::move(InitSymbol)) { assert(!this->SymbolFlags.empty() && "Materializing nothing?"); } JITDylib &JD; SymbolFlagsMap SymbolFlags; SymbolStringPtr InitSymbol; - VModuleKey K; }; /// A MaterializationUnit represents a set of symbol definitions that can @@ -550,9 +545,9 @@ class MaterializationUnit { public: MaterializationUnit(SymbolFlagsMap InitalSymbolFlags, - SymbolStringPtr InitSymbol, VModuleKey K) + SymbolStringPtr InitSymbol) : SymbolFlags(std::move(InitalSymbolFlags)), - InitSymbol(std::move(InitSymbol)), K(std::move(K)) { + InitSymbol(std::move(InitSymbol)) { assert((!this->InitSymbol || this->SymbolFlags.count(this->InitSymbol)) && "If set, InitSymbol should appear in InitialSymbolFlags map"); } @@ -573,8 +568,8 @@ /// ExecutionSession::DispatchMaterializationFunction) to trigger /// materialization of this MaterializationUnit. void doMaterialize(JITDylib &JD) { - materialize(MaterializationResponsibility( - JD, std::move(SymbolFlags), std::move(InitSymbol), std::move(K))); + materialize(MaterializationResponsibility(JD, std::move(SymbolFlags), + std::move(InitSymbol))); } /// Called by JITDylibs to notify MaterializationUnits that the given symbol @@ -587,7 +582,6 @@ protected: SymbolFlagsMap SymbolFlags; SymbolStringPtr InitSymbol; - VModuleKey K; private: virtual void anchor(); @@ -613,7 +607,7 @@ /// materialized. class AbsoluteSymbolsMaterializationUnit : public MaterializationUnit { public: - AbsoluteSymbolsMaterializationUnit(SymbolMap Symbols, VModuleKey K); + AbsoluteSymbolsMaterializationUnit(SymbolMap Symbols); StringRef getName() const override; @@ -636,9 +630,9 @@ /// \endcode /// inline std::unique_ptr -absoluteSymbols(SymbolMap Symbols, VModuleKey K = VModuleKey()) { +absoluteSymbols(SymbolMap Symbols) { return std::make_unique( - std::move(Symbols), std::move(K)); + std::move(Symbols)); } /// A materialization unit for symbol aliases. Allows existing symbols to be @@ -655,7 +649,7 @@ /// resolved. ReExportsMaterializationUnit(JITDylib *SourceJD, JITDylibLookupFlags SourceJDLookupFlags, - SymbolAliasMap Aliases, VModuleKey K); + SymbolAliasMap Aliases); StringRef getName() const override; @@ -681,10 +675,9 @@ /// return Err; /// \endcode inline std::unique_ptr -symbolAliases(SymbolAliasMap Aliases, VModuleKey K = VModuleKey()) { +symbolAliases(SymbolAliasMap Aliases) { return std::make_unique( - nullptr, JITDylibLookupFlags::MatchAllSymbols, std::move(Aliases), - std::move(K)); + nullptr, JITDylibLookupFlags::MatchAllSymbols, std::move(Aliases)); } /// Create a materialization unit for re-exporting symbols from another JITDylib @@ -693,10 +686,9 @@ inline std::unique_ptr reexports(JITDylib &SourceJD, SymbolAliasMap Aliases, JITDylibLookupFlags SourceJDLookupFlags = - JITDylibLookupFlags::MatchExportedSymbolsOnly, - VModuleKey K = VModuleKey()) { + JITDylibLookupFlags::MatchExportedSymbolsOnly) { return std::make_unique( - &SourceJD, SourceJDLookupFlags, std::move(Aliases), std::move(K)); + &SourceJD, SourceJDLookupFlags, std::move(Aliases)); } /// Build a SymbolAliasMap for the common case where you want to re-export @@ -1070,10 +1062,6 @@ /// MaterializationUnit is added to a JITDylib. virtual Error notifyAdding(JITDylib &JD, const MaterializationUnit &MU) = 0; - /// This method will be called under the ExecutionSession lock when a - /// VModuleKey is removed. - virtual Error notifyRemoving(JITDylib &JD, VModuleKey K) = 0; - /// A utility function for looking up initializer symbols. Performs a blocking /// lookup for the given symbols in each of the given JITDylibs. static Expected> @@ -1081,6 +1069,18 @@ const DenseMap &InitSyms); }; +/// For objects that want to track JITDylib teardowns, in particular resource +/// managers. +class JITDylibDestructionListener { +public: + JITDylibDestructionListener() = default; + JITDylibDestructionListener(const JITDylib &) = delete; + JITDylibDestructionListener &operator=(const JITDylib &) = delete; + virtual ~JITDylibDestructionListener(); + + virtual Error notifyDestroyingJITDylib(JITDylib &JD) = 0; +}; + /// An ExecutionSession represents a running JIT program. class ExecutionSession { // FIXME: Remove this when we remove the old ORC layers. @@ -1118,6 +1118,11 @@ return F(); } + /// Register a JITDylibDestructionListener. + void registerJITDylibDestructionListener(JITDylibDestructionListener &L) { + runSessionLocked([&]() { JITDylibDestructionListeners.push_back(&L); }); + } + /// Return a pointer to the "name" JITDylib. /// Ownership of JITDylib remains within Execution Session JITDylib *getJITDylibByName(StringRef Name); @@ -1143,6 +1148,13 @@ /// If no Platform is attached this call is equivalent to createBareJITDylib. Expected createJITDylib(std::string Name); + /// Close a JITDylib. + /// + /// This will delete the JITDylib and release any resources associated with + /// it. This method does *not* run static destructors: If supported they must + /// be run by the Platform prior to calling this method. + Error destroyJITDylib(JITDylib &JD); + /// Allocate a module key for a new module to add to the JIT. VModuleKey allocateVModule() { return runSessionLocked([this]() { return ++LastKey; }); @@ -1280,6 +1292,7 @@ materializeOnCurrentThread; std::vector> JDs; + std::vector JITDylibDestructionListeners; // FIXME: Remove this (and runOutstandingMUs) once the linking layer works // with callbacks from asynchronous queries. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h @@ -45,8 +45,7 @@ IRSymbolMapper::ManglingOptions MO; }; - using NotifyCompiledFunction = - std::function; + using NotifyCompiledFunction = std::function; IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, std::unique_ptr Compile); @@ -75,7 +74,7 @@ public: /// Callback type for notifications when modules are compiled. using NotifyCompiledCallback = - std::function)>; + std::function)>; /// Construct an LegacyIRCompileLayer with the given BaseLayer, which must /// implement the ObjectLayer concept. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/Layer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Layer.h @@ -34,15 +34,15 @@ /// SymbolFlags and SymbolToDefinition maps. IRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, - ThreadSafeModule TSM, VModuleKey K); + ThreadSafeModule TSM); /// Create an IRMaterializationLayer from a module, and pre-existing /// SymbolFlags and SymbolToDefinition maps. The maps must provide /// entries for each definition in M. /// This constructor is useful for delegating work from one /// IRMaterializationUnit to another. - IRMaterializationUnit(ThreadSafeModule TSM, VModuleKey K, - SymbolFlagsMap SymbolFlags, SymbolStringPtr InitSymbol, + IRMaterializationUnit(ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags, + SymbolStringPtr InitSymbol, SymbolNameToDefinitionMap SymbolToDefinition); /// Return the ModuleIdentifier as the name for this MaterializationUnit. @@ -96,8 +96,7 @@ /// Adds a MaterializationUnit representing the given IR to the given /// JITDylib. - virtual Error add(JITDylib &JD, ThreadSafeModule TSM, - VModuleKey K = VModuleKey()); + virtual Error add(JITDylib &JD, ThreadSafeModule TSM); /// Emit should materialize the given IR. virtual void emit(MaterializationResponsibility R, ThreadSafeModule TSM) = 0; @@ -114,14 +113,13 @@ public: BasicIRLayerMaterializationUnit(IRLayer &L, const IRSymbolMapper::ManglingOptions &MO, - ThreadSafeModule TSM, VModuleKey K); + ThreadSafeModule TSM); private: void materialize(MaterializationResponsibility R) override; IRLayer &L; - VModuleKey K; }; /// Interface for Layers that accept object files. @@ -135,8 +133,7 @@ /// Adds a MaterializationUnit representing the given IR to the given /// JITDylib. - virtual Error add(JITDylib &JD, std::unique_ptr O, - VModuleKey K = VModuleKey()); + virtual Error add(JITDylib &JD, std::unique_ptr O); /// Emit should materialize the given IR. virtual void emit(MaterializationResponsibility R, @@ -151,9 +148,9 @@ class BasicObjectLayerMaterializationUnit : public MaterializationUnit { public: static Expected> - Create(ObjectLayer &L, VModuleKey K, std::unique_ptr O); + Create(ObjectLayer &L, std::unique_ptr O); - BasicObjectLayerMaterializationUnit(ObjectLayer &L, VModuleKey K, + BasicObjectLayerMaterializationUnit(ObjectLayer &L, std::unique_ptr O, SymbolFlagsMap SymbolFlags, SymbolStringPtr InitSymbol); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h b/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h --- a/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LazyReexports.h @@ -152,7 +152,7 @@ IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, - ImplSymbolMap *SrcJDLoc, VModuleKey K); + ImplSymbolMap *SrcJDLoc); StringRef getName() const override; @@ -174,11 +174,10 @@ inline std::unique_ptr lazyReexports(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, - SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc = nullptr, - VModuleKey K = VModuleKey()) { + SymbolAliasMap CallableAliases, + ImplSymbolMap *SrcJDLoc = nullptr) { return std::make_unique( - LCTManager, ISManager, SourceJD, std::move(CallableAliases), SrcJDLoc, - std::move(K)); + LCTManager, ISManager, SourceJD, std::move(CallableAliases), SrcJDLoc); } } // End namespace orc diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h --- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h @@ -99,7 +99,6 @@ Error setupJITDylib(JITDylib &JD) override; Error notifyAdding(JITDylib &JD, const MaterializationUnit &MU) override; - Error notifyRemoving(JITDylib &JD, VModuleKey K) override; Expected getInitializerSequence(JITDylib &JD); diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h @@ -51,7 +51,8 @@ /// Clients can use this class to add relocatable object files to an /// ExecutionSession, and it typically serves as the base layer (underneath /// a compiling layer like IRCompileLayer) for the rest of the JIT. -class ObjectLinkingLayer : public ObjectLayer { +class ObjectLinkingLayer : public ObjectLayer, + public JITDylibDestructionListener { friend class ObjectLinkingLayerJITLinkContext; public: @@ -72,10 +73,7 @@ virtual Error notifyEmitted(MaterializationResponsibility &MR) { return Error::success(); } - virtual Error notifyRemovingModule(VModuleKey K) { - return Error::success(); - } - virtual Error notifyRemovingAllModules() { return Error::success(); } + virtual Error notifyRemoving(JITDylib &JD) { return Error::success(); } /// Return any dependencies that synthetic symbols (e.g. init symbols) /// have on locally scoped jitlink::Symbols. This is used by the @@ -95,9 +93,6 @@ ObjectLinkingLayer(ExecutionSession &ES, std::unique_ptr MemMgr); - /// Destruct an ObjectLinkingLayer. - ~ObjectLinkingLayer(); - /// Set an object buffer return function. By default object buffers are /// deleted once the JIT has linked them. If a return function is set then /// it will be called to transfer ownership of the buffer instead. @@ -116,6 +111,9 @@ void emit(MaterializationResponsibility R, std::unique_ptr O) override; + /// Handle JITDylib teardown notifications. + Error notifyDestroyingJITDylib(JITDylib &JD) override; + /// Instructs this ObjectLinkingLayer instance to override the symbol flags /// found in the AtomGraph with the flags supplied by the /// MaterializationResponsibility instance. This is a workaround to support @@ -149,22 +147,20 @@ private: using AllocPtr = std::unique_ptr; + using AllocVector = std::vector; void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT, jitlink::PassConfiguration &PassConfig); void notifyLoaded(MaterializationResponsibility &MR); Error notifyEmitted(MaterializationResponsibility &MR, AllocPtr Alloc); - - Error removeModule(VModuleKey K); - Error removeAllModules(); + Error removeJITDylib(JITDylib &JD); mutable std::mutex LayerMutex; std::unique_ptr MemMgr; bool OverrideObjectFlags = false; bool AutoClaimObjectSymbols = false; ReturnObjectBufferFunction ReturnObjectBuffer; - DenseMap TrackedAllocs; - std::vector UntrackedAllocs; + DenseMap Allocs; std::vector> Plugins; }; @@ -174,8 +170,7 @@ Error notifyEmitted(MaterializationResponsibility &MR) override; void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT, jitlink::PassConfiguration &PassConfig) override; - Error notifyRemovingModule(VModuleKey K) override; - Error notifyRemovingAllModules() override; + Error notifyRemoving(JITDylib &JD) override; private: @@ -183,12 +178,12 @@ JITTargetAddress Addr = 0; size_t Size; }; + using EHFrameRangeVector = std::vector; std::mutex EHFramePluginMutex; jitlink::EHFrameRegistrar &Registrar; DenseMap InProcessLinks; - DenseMap TrackedEHFrameRanges; - std::vector UntrackedEHFrameRanges; + DenseMap EHFrameRanges; }; } // end namespace orc diff --git a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h --- a/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h @@ -39,13 +39,12 @@ class RTDyldObjectLinkingLayer : public ObjectLayer { public: /// Functor for receiving object-loaded notifications. - using NotifyLoadedFunction = - std::function; + using NotifyLoadedFunction = std::function; /// Functor for receiving finalization notifications. using NotifyEmittedFunction = - std::function)>; + std::function)>; using GetMemoryManagerFunction = std::function()>; @@ -123,14 +122,14 @@ void unregisterJITEventListener(JITEventListener &L); private: - Error onObjLoad(VModuleKey K, MaterializationResponsibility &R, + Error onObjLoad(MaterializationResponsibility &R, const object::ObjectFile &Obj, RuntimeDyld::MemoryManager *MemMgr, std::unique_ptr LoadedObjInfo, std::map Resolved, std::set &InternalSymbols); - void onObjEmit(VModuleKey K, MaterializationResponsibility &R, + void onObjEmit(MaterializationResponsibility &R, object::OwningBinary O, RuntimeDyld::MemoryManager *MemMgr, Error Err); diff --git a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp @@ -73,17 +73,16 @@ public: PartitioningIRMaterializationUnit(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, - ThreadSafeModule TSM, VModuleKey K, + ThreadSafeModule TSM, CompileOnDemandLayer &Parent) - : IRMaterializationUnit(ES, MO, std::move(TSM), std::move(K)), - Parent(Parent) {} + : IRMaterializationUnit(ES, MO, std::move(TSM)), Parent(Parent) {} PartitioningIRMaterializationUnit( - ThreadSafeModule TSM, VModuleKey K, SymbolFlagsMap SymbolFlags, + ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags, SymbolStringPtr InitSymbol, SymbolNameToDefinitionMap SymbolToDefinition, CompileOnDemandLayer &Parent) - : IRMaterializationUnit(std::move(TSM), std::move(K), - std::move(SymbolFlags), std::move(InitSymbol), + : IRMaterializationUnit(std::move(TSM), std::move(SymbolFlags), + std::move(InitSymbol), std::move(SymbolToDefinition)), Parent(Parent) {} @@ -158,8 +157,7 @@ // implementation dylib. if (auto Err = PDR.getImplDylib().define( std::make_unique( - ES, *getManglingOptions(), std::move(TSM), R.getVModuleKey(), - *this))) { + ES, *getManglingOptions(), std::move(TSM), *this))) { ES.reportError(std::move(Err)); R.failMaterialization(); return; @@ -287,8 +285,8 @@ // If the partition is empty, return the whole module to the symbol table. if (GVsToExtract->empty()) { R.replace(std::make_unique( - std::move(TSM), R.getVModuleKey(), R.getSymbols(), - R.getInitializerSymbol(), std::move(Defs), *this)); + std::move(TSM), R.getSymbols(), R.getInitializerSymbol(), + std::move(Defs), *this)); return; } @@ -354,7 +352,7 @@ } R.replace(std::make_unique( - ES, *getManglingOptions(), std::move(TSM), R.getVModuleKey(), *this)); + ES, *getManglingOptions(), std::move(TSM), *this)); BaseLayer.emit(std::move(R), std::move(*ExtractedTSM)); } diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -280,12 +280,7 @@ } MaterializationResponsibility -MaterializationResponsibility::delegate(const SymbolNameSet &Symbols, - VModuleKey NewKey) { - - if (NewKey == VModuleKey()) - NewKey = K; - +MaterializationResponsibility::delegate(const SymbolNameSet &Symbols) { SymbolStringPtr DelegatedInitSymbol; SymbolFlagsMap DelegatedFlags; @@ -303,8 +298,7 @@ } return MaterializationResponsibility(JD, std::move(DelegatedFlags), - std::move(DelegatedInitSymbol), - std::move(NewKey)); + std::move(DelegatedInitSymbol)); } void MaterializationResponsibility::addDependencies( @@ -329,8 +323,8 @@ } AbsoluteSymbolsMaterializationUnit::AbsoluteSymbolsMaterializationUnit( - SymbolMap Symbols, VModuleKey K) - : MaterializationUnit(extractFlags(Symbols), nullptr, std::move(K)), + SymbolMap Symbols) + : MaterializationUnit(extractFlags(Symbols), nullptr), Symbols(std::move(Symbols)) {} StringRef AbsoluteSymbolsMaterializationUnit::getName() const { @@ -360,10 +354,9 @@ ReExportsMaterializationUnit::ReExportsMaterializationUnit( JITDylib *SourceJD, JITDylibLookupFlags SourceJDLookupFlags, - SymbolAliasMap Aliases, VModuleKey K) - : MaterializationUnit(extractFlags(Aliases), nullptr, std::move(K)), - SourceJD(SourceJD), SourceJDLookupFlags(SourceJDLookupFlags), - Aliases(std::move(Aliases)) {} + SymbolAliasMap Aliases) + : MaterializationUnit(extractFlags(Aliases), nullptr), SourceJD(SourceJD), + SourceJDLookupFlags(SourceJDLookupFlags), Aliases(std::move(Aliases)) {} StringRef ReExportsMaterializationUnit::getName() const { return ""; @@ -1767,6 +1760,8 @@ return std::move(CompoundResult); } +JITDylibDestructionListener::~JITDylibDestructionListener() {} + ExecutionSession::ExecutionSession(std::shared_ptr SSP) : SSP(SSP ? std::move(SSP) : std::make_shared()) { } @@ -1797,6 +1792,28 @@ return JD; } +Error ExecutionSession::destroyJITDylib(JITDylib &JD) { + std::unique_ptr OwnedJD; + + runSessionLocked([&]() { + for (auto JDI = JDs.begin(); JDI != JDs.end();) { + if (JDI->get() == &JD) { + OwnedJD = std::move(*JDI); + JDI = JDs.erase(JDI); + } else { + (*JDI)->removeFromSearchOrder(JD); + ++JDI; + } + } + }); + + Error Err = Error::success(); + for (auto *L : reverse(JITDylibDestructionListeners)) + Err = joinErrors(std::move(Err), L->notifyDestroyingJITDylib(JD)); + + return Err; +} + void ExecutionSession::legacyFailQuery(AsynchronousSymbolQuery &Q, Error Err) { assert(!!Err && "Error should be in failure state"); diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -396,8 +396,7 @@ MemoryBufferRef ChildBufferRef(ChildBufferInfo.first, ChildBufferInfo.second); - if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false), - VModuleKey())) + if (auto Err = L.add(JD, MemoryBuffer::getMemBuffer(ChildBufferRef, false))) return Err; } diff --git a/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp b/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp @@ -33,7 +33,7 @@ { std::lock_guard Lock(IRLayerMutex); if (NotifyCompiled) - NotifyCompiled(R.getVModuleKey(), std::move(TSM)); + NotifyCompiled(std::move(TSM)); else TSM = ThreadSafeModule(); } diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -25,9 +25,9 @@ using CompileFunction = JITCompileCallbackManager::CompileFunction; CompileCallbackMaterializationUnit(SymbolStringPtr Name, - CompileFunction Compile, VModuleKey K) + CompileFunction Compile) : MaterializationUnit(SymbolFlagsMap({{Name, JITSymbolFlags::Exported}}), - nullptr, std::move(K)), + nullptr), Name(std::move(Name)), Compile(std::move(Compile)) {} StringRef getName() const override { return ""; } @@ -65,10 +65,9 @@ std::lock_guard Lock(CCMgrMutex); AddrToSymbol[*TrampolineAddr] = CallbackName; - cantFail(CallbacksJD.define( - std::make_unique( - std::move(CallbackName), std::move(Compile), - ES.allocateVModule()))); + cantFail( + CallbacksJD.define(std::make_unique( + std::move(CallbackName), std::move(Compile)))); return *TrampolineAddr; } else return TrampolineAddr.takeError(); diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -88,10 +88,6 @@ GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {} Error setupJITDylib(JITDylib &JD) override; Error notifyAdding(JITDylib &JD, const MaterializationUnit &MU) override; - Error notifyRemoving(JITDylib &JD, VModuleKey K) override { - // Noop -- Nothing to do (yet). - return Error::success(); - } private: GenericLLVMIRPlatformSupport &S; @@ -972,14 +968,13 @@ TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); })) return Err; - return InitHelperTransformLayer->add(JD, std::move(TSM), - ES->allocateVModule()); + return InitHelperTransformLayer->add(JD, std::move(TSM)); } Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr Obj) { assert(Obj && "Can not add null object"); - return ObjTransformLayer.add(JD, std::move(Obj), ES->allocateVModule()); + return ObjTransformLayer.add(JD, std::move(Obj)); } Expected LLJIT::lookupLinkerMangled(JITDylib &JD, @@ -1140,7 +1135,7 @@ [&](Module &M) -> Error { return applyDataLayout(M); })) return Err; - return CODLayer->add(JD, std::move(TSM), ES->allocateVModule()); + return CODLayer->add(JD, std::move(TSM)); } LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) { diff --git a/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/llvm/lib/ExecutionEngine/Orc/Layer.cpp --- a/llvm/lib/ExecutionEngine/Orc/Layer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Layer.cpp @@ -22,16 +22,15 @@ IRLayer::~IRLayer() {} -Error IRLayer::add(JITDylib &JD, ThreadSafeModule TSM, VModuleKey K) { +Error IRLayer::add(JITDylib &JD, ThreadSafeModule TSM) { return JD.define(std::make_unique( - *this, *getManglingOptions(), std::move(TSM), std::move(K))); + *this, *getManglingOptions(), std::move(TSM))); } IRMaterializationUnit::IRMaterializationUnit( ExecutionSession &ES, const IRSymbolMapper::ManglingOptions &MO, - ThreadSafeModule TSM, VModuleKey K) - : MaterializationUnit(SymbolFlagsMap(), nullptr, std::move(K)), - TSM(std::move(TSM)) { + ThreadSafeModule TSM) + : MaterializationUnit(SymbolFlagsMap(), nullptr), TSM(std::move(TSM)) { assert(this->TSM && "Module must not be null"); @@ -99,10 +98,9 @@ } IRMaterializationUnit::IRMaterializationUnit( - ThreadSafeModule TSM, VModuleKey K, SymbolFlagsMap SymbolFlags, + ThreadSafeModule TSM, SymbolFlagsMap SymbolFlags, SymbolStringPtr InitSymbol, SymbolNameToDefinitionMap SymbolToDefinition) - : MaterializationUnit(std::move(SymbolFlags), std::move(InitSymbol), - std::move(K)), + : MaterializationUnit(std::move(SymbolFlags), std::move(InitSymbol)), TSM(std::move(TSM)), SymbolToDefinition(std::move(SymbolToDefinition)) {} StringRef IRMaterializationUnit::getName() const { @@ -129,11 +127,9 @@ } BasicIRLayerMaterializationUnit::BasicIRLayerMaterializationUnit( - IRLayer &L, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM, - VModuleKey K) - : IRMaterializationUnit(L.getExecutionSession(), MO, std::move(TSM), - std::move(K)), - L(L), K(std::move(K)) {} + IRLayer &L, const IRSymbolMapper::ManglingOptions &MO, ThreadSafeModule TSM) + : IRMaterializationUnit(L.getExecutionSession(), MO, std::move(TSM)), L(L) { +} void BasicIRLayerMaterializationUnit::materialize( MaterializationResponsibility R) { @@ -163,17 +159,15 @@ ObjectLayer::~ObjectLayer() {} -Error ObjectLayer::add(JITDylib &JD, std::unique_ptr O, - VModuleKey K) { - auto ObjMU = BasicObjectLayerMaterializationUnit::Create(*this, std::move(K), - std::move(O)); +Error ObjectLayer::add(JITDylib &JD, std::unique_ptr O) { + auto ObjMU = BasicObjectLayerMaterializationUnit::Create(*this, std::move(O)); if (!ObjMU) return ObjMU.takeError(); return JD.define(std::move(*ObjMU)); } Expected> -BasicObjectLayerMaterializationUnit::Create(ObjectLayer &L, VModuleKey K, +BasicObjectLayerMaterializationUnit::Create(ObjectLayer &L, std::unique_ptr O) { auto ObjSymInfo = getObjectSymbolInfo(L.getExecutionSession(), O->getMemBufferRef()); @@ -186,15 +180,14 @@ return std::unique_ptr( new BasicObjectLayerMaterializationUnit( - L, K, std::move(O), std::move(SymbolFlags), std::move(InitSymbol))); + L, std::move(O), std::move(SymbolFlags), std::move(InitSymbol))); } BasicObjectLayerMaterializationUnit::BasicObjectLayerMaterializationUnit( - ObjectLayer &L, VModuleKey K, std::unique_ptr O, - SymbolFlagsMap SymbolFlags, SymbolStringPtr InitSymbol) - : MaterializationUnit(std::move(SymbolFlags), std::move(InitSymbol), - std::move(K)), - L(L), O(std::move(O)) {} + ObjectLayer &L, std::unique_ptr O, SymbolFlagsMap SymbolFlags, + SymbolStringPtr InitSymbol) + : MaterializationUnit(std::move(SymbolFlags), std::move(InitSymbol)), L(L), + O(std::move(O)) {} StringRef BasicObjectLayerMaterializationUnit::getName() const { if (O) diff --git a/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp b/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp --- a/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp @@ -115,9 +115,8 @@ LazyReexportsMaterializationUnit::LazyReexportsMaterializationUnit( LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, - JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc, - VModuleKey K) - : MaterializationUnit(extractFlags(CallableAliases), nullptr, std::move(K)), + JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc) + : MaterializationUnit(extractFlags(CallableAliases), nullptr), LCTManager(LCTManager), ISManager(ISManager), SourceJD(SourceJD), CallableAliases(std::move(CallableAliases)), AliaseeTable(SrcJDLoc) {} diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp --- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp @@ -173,10 +173,6 @@ return Error::success(); } -Error MachOPlatform::notifyRemoving(JITDylib &JD, VModuleKey K) { - llvm_unreachable("Not supported yet"); -} - Expected MachOPlatform::getInitializerSequence(JITDylib &JD) { diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -449,11 +449,8 @@ ObjectLinkingLayer::ObjectLinkingLayer( ExecutionSession &ES, std::unique_ptr MemMgr) - : ObjectLayer(ES), MemMgr(std::move(MemMgr)) {} - -ObjectLinkingLayer::~ObjectLinkingLayer() { - if (auto Err = removeAllModules()) - getExecutionSession().reportError(std::move(Err)); + : ObjectLayer(ES), MemMgr(std::move(MemMgr)) { + ES.registerJITDylibDestructionListener(*this); } void ObjectLinkingLayer::emit(MaterializationResponsibility R, @@ -463,6 +460,13 @@ *this, std::move(R), std::move(O))); } +Error ObjectLinkingLayer::notifyDestroyingJITDylib(JITDylib &JD) { + Error Err = Error::success(); + for (auto &P : Plugins) + Err = joinErrors(std::move(Err), P->notifyRemoving(JD)); + return Err; +} + void ObjectLinkingLayer::modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT, PassConfiguration &PassConfig) { @@ -486,54 +490,29 @@ { std::lock_guard Lock(LayerMutex); - UntrackedAllocs.push_back(std::move(Alloc)); + Allocs[&MR.getTargetJITDylib()].push_back(std::move(Alloc)); } return Error::success(); } -Error ObjectLinkingLayer::removeModule(VModuleKey K) { +Error ObjectLinkingLayer::removeJITDylib(JITDylib &JD) { Error Err = Error::success(); for (auto &P : Plugins) - Err = joinErrors(std::move(Err), P->notifyRemovingModule(K)); + Err = joinErrors(std::move(Err), P->notifyRemoving(JD)); - AllocPtr Alloc; + AllocVector AllocsToRemove; { std::lock_guard Lock(LayerMutex); - auto AllocItr = TrackedAllocs.find(K); - Alloc = std::move(AllocItr->second); - TrackedAllocs.erase(AllocItr); + auto AllocsItr = Allocs.find(&JD); + AllocsToRemove = std::move(AllocsItr->second); + Allocs.erase(AllocsItr); } - assert(Alloc && "No allocation for key K"); - - return joinErrors(std::move(Err), Alloc->deallocate()); -} - -Error ObjectLinkingLayer::removeAllModules() { - - Error Err = Error::success(); - - for (auto &P : Plugins) - Err = joinErrors(std::move(Err), P->notifyRemovingAllModules()); - - std::vector Allocs; - { - std::lock_guard Lock(LayerMutex); - Allocs = std::move(UntrackedAllocs); - - for (auto &KV : TrackedAllocs) - Allocs.push_back(std::move(KV.second)); - - TrackedAllocs.clear(); - } - - while (!Allocs.empty()) { - Err = joinErrors(std::move(Err), Allocs.back()->deallocate()); - Allocs.pop_back(); - } + for (auto &Alloc : AllocsToRemove) + Err = joinErrors(std::move(Err), Alloc->deallocate()); return Err; } @@ -570,52 +549,27 @@ "eh-frame addr to register can not be null"); InProcessLinks.erase(EHFrameRangeItr); - if (auto Key = MR.getVModuleKey()) - TrackedEHFrameRanges[Key] = EHFrameRange; - else - UntrackedEHFrameRanges.push_back(EHFrameRange); + EHFrameRanges[&MR.getTargetJITDylib()].push_back(EHFrameRange); return Registrar.registerEHFrames(EHFrameRange.Addr, EHFrameRange.Size); } -Error EHFrameRegistrationPlugin::notifyRemovingModule(VModuleKey K) { +Error EHFrameRegistrationPlugin::notifyRemoving(JITDylib &JD) { std::lock_guard Lock(EHFramePluginMutex); - auto EHFrameRangeItr = TrackedEHFrameRanges.find(K); - if (EHFrameRangeItr == TrackedEHFrameRanges.end()) + auto EHFrameRangeItr = EHFrameRanges.find(&JD); + if (EHFrameRangeItr == EHFrameRanges.end()) return Error::success(); - auto EHFrameRange = EHFrameRangeItr->second; - assert(EHFrameRange.Addr && "Tracked eh-frame range must not be null"); - - TrackedEHFrameRanges.erase(EHFrameRangeItr); - - return Registrar.deregisterEHFrames(EHFrameRange.Addr, EHFrameRange.Size); -} - -Error EHFrameRegistrationPlugin::notifyRemovingAllModules() { - std::lock_guard Lock(EHFramePluginMutex); - - std::vector EHFrameRanges = - std::move(UntrackedEHFrameRanges); - EHFrameRanges.reserve(EHFrameRanges.size() + TrackedEHFrameRanges.size()); - - for (auto &KV : TrackedEHFrameRanges) - EHFrameRanges.push_back(KV.second); - - TrackedEHFrameRanges.clear(); - Error Err = Error::success(); - - while (!EHFrameRanges.empty()) { - 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)); + for (auto &EHFrameRange : EHFrameRangeItr->second) { + assert(EHFrameRange.Addr && "Tracked eh-frame range must not be null"); + Err = joinErrors(std::move(Err), Registrar.deregisterEHFrames( + EHFrameRange.Addr, EHFrameRange.Size)); } + EHFrameRanges.erase(EHFrameRangeItr); + return Err; } diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp @@ -146,9 +146,7 @@ } } - auto K = R.getVModuleKey(); RuntimeDyld::MemoryManager *MemMgr = nullptr; - // Create a record a memory manager for this object. { auto Tmp = GetMemoryManager(); @@ -162,16 +160,16 @@ jitLinkForORC( object::OwningBinary(std::move(*Obj), std::move(O)), *MemMgr, Resolver, ProcessAllSections, - [this, K, SharedR, MemMgr, InternalSymbols]( + [this, SharedR, MemMgr, InternalSymbols]( const object::ObjectFile &Obj, std::unique_ptr LoadedObjInfo, std::map ResolvedSymbols) { - return onObjLoad(K, *SharedR, Obj, MemMgr, std::move(LoadedObjInfo), + return onObjLoad(*SharedR, Obj, MemMgr, std::move(LoadedObjInfo), ResolvedSymbols, *InternalSymbols); }, - [this, K, SharedR, MemMgr](object::OwningBinary Obj, - Error Err) mutable { - onObjEmit(K, *SharedR, std::move(Obj), MemMgr, std::move(Err)); + [this, SharedR, MemMgr](object::OwningBinary Obj, + Error Err) mutable { + onObjEmit(*SharedR, std::move(Obj), MemMgr, std::move(Err)); }); } @@ -191,8 +189,8 @@ } Error RTDyldObjectLinkingLayer::onObjLoad( - VModuleKey K, MaterializationResponsibility &R, - const object::ObjectFile &Obj, RuntimeDyld::MemoryManager *MemMgr, + MaterializationResponsibility &R, const object::ObjectFile &Obj, + RuntimeDyld::MemoryManager *MemMgr, std::unique_ptr LoadedObjInfo, std::map Resolved, std::set &InternalSymbols) { @@ -274,7 +272,7 @@ } if (NotifyLoaded) - NotifyLoaded(K, Obj, *LoadedObjInfo); + NotifyLoaded(Obj, *LoadedObjInfo); std::lock_guard Lock(RTDyldLayerMutex); assert(!LoadedObjInfos.count(MemMgr) && "Duplicate loaded info for MemMgr"); @@ -284,7 +282,7 @@ } void RTDyldObjectLinkingLayer::onObjEmit( - VModuleKey K, MaterializationResponsibility &R, + MaterializationResponsibility &R, object::OwningBinary O, RuntimeDyld::MemoryManager *MemMgr, Error Err) { if (Err) { @@ -316,7 +314,7 @@ } if (NotifyEmitted) - NotifyEmitted(K, std::move(ObjBuffer)); + NotifyEmitted(std::move(ObjBuffer)); } LegacyRTDyldObjectLinkingLayer::LegacyRTDyldObjectLinkingLayer( diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h --- a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h +++ b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h @@ -96,8 +96,7 @@ orc::SymbolStringPtr InitSym = nullptr, DiscardFunction Discard = DiscardFunction(), DestructorFunction Destructor = DestructorFunction()) - : MaterializationUnit(std::move(SymbolFlags), std::move(InitSym), - orc::VModuleKey()), + : MaterializationUnit(std::move(SymbolFlags), std::move(InitSym)), Materialize(std::move(Materialize)), Discard(std::move(Discard)), Destructor(std::move(Destructor)) {} diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp --- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp @@ -62,7 +62,7 @@ }; ObjLayer.setProcessAllSections(ProcessAllSections); - cantFail(ObjLayer.add(JD, std::move(Obj), ES.allocateVModule())); + cantFail(ObjLayer.add(JD, std::move(Obj))); ES.lookup(LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo), SymbolState::Resolved, OnResolveDoNothing, NoDependenciesToRegister); @@ -162,7 +162,7 @@ ObjLayer.setOverrideObjectFlagsWithResponsibilityFlags(true); - cantFail(CompileLayer.add(JD, std::move(M), ES.allocateVModule())); + cantFail(CompileLayer.add(JD, std::move(M))); ES.lookup( LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo), SymbolState::Resolved, @@ -229,7 +229,7 @@ ObjLayer.setAutoClaimResponsibilityForObjectSymbols(true); - cantFail(CompileLayer.add(JD, std::move(M), ES.allocateVModule())); + cantFail(CompileLayer.add(JD, std::move(M))); ES.lookup( LookupKind::Static, makeJITDylibSearchOrder(&JD), SymbolLookupSet(Foo), SymbolState::Resolved,