From 29dff9837af24e05e1424bd4d803d907e07aa25b Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 2 Feb 2015 04:32:17 +0000 Subject: [PATCH] [Orc] Make the ObjectLinkingLayer take ownership of object files until finalization time. As currently implemented, RuntimeDyldELF requires the original object file to be avaible when relocations are being resolved. This patch ensures that the ObjectLinkingLayer preserves it until then. In the future RuntimeDyldELF should be rewritten to remove this requirement, at which point this patch can be reverted. Regression test cases for Orc (which include coverage of this bug) will be committed shortly. llvm-svn: 227778 --- .../llvm/ExecutionEngine/Orc/IRCompileLayer.h | 7 ++++++- .../llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h index f81af6f..e16ff8d 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h @@ -76,7 +76,12 @@ public: Buffers.push_back(std::move(Buffer)); } - return BaseLayer.addObjectSet(std::move(Objects), std::move(MM)); + ModuleSetHandleT H = + BaseLayer.addObjectSet(Objects, std::move(MM)); + + BaseLayer.takeOwnershipOfBuffers(H, std::move(Buffers)); + + return H; } /// @brief Remove the module set associated with the handle H. diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h index 03b43aa..957fec4 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h @@ -61,6 +61,7 @@ protected: RTDyld->resolveRelocations(); RTDyld->registerEHFrames(); MM->finalizeMemory(); + OwnedBuffers.clear(); State = Finalized; } @@ -70,10 +71,19 @@ protected: RTDyld->mapSectionAddress(LocalAddress, TargetAddress); } + void takeOwnershipOfBuffer(std::unique_ptr B) { + OwnedBuffers.push_back(std::move(B)); + } + private: std::unique_ptr MM; std::unique_ptr RTDyld; enum { Raw, Finalizing, Finalized } State; + + // FIXME: This ownership hack only exists because RuntimeDyldELF still + // wants to be able to inspect the original object when resolving + // relocations. As soon as that can be fixed this should be removed. + std::vector> OwnedBuffers; }; typedef std::list LinkedObjectSetListT; @@ -81,6 +91,16 @@ protected: public: /// @brief Handle to a set of loaded objects. typedef LinkedObjectSetListT::iterator ObjSetHandleT; + + // Ownership hack. + // FIXME: Remove this as soon as RuntimeDyldELF can apply relocations without + // referencing the original object. + template + void takeOwnershipOfBuffers(ObjSetHandleT H, OwningMBSet MBs) { + for (auto &MB : MBs) + H->takeOwnershipOfBuffer(std::move(MB)); + } + }; /// @brief Default (no-op) action to perform when loading objects. -- 2.7.4