diff options
author | Lang Hames <lhames@gmail.com> | 2016-01-19 21:06:38 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-01-19 21:06:38 +0000 |
commit | 2fe7acb7737e8131cc0368f1f1d642124fc93fa6 (patch) | |
tree | 64fc194354a19f7096b4e6577706bda5314dd2c1 /llvm/lib/ExecutionEngine/Orc | |
parent | 29a4b5dc0d754c9a45f62a8af0cc36e8de4f968d (diff) | |
download | bcm5719-llvm-2fe7acb7737e8131cc0368f1f1d642124fc93fa6.tar.gz bcm5719-llvm-2fe7acb7737e8131cc0368f1f1d642124fc93fa6.zip |
[Orc] Refactor ObjectLinkingLayer::addObjectSet to defer loading objects until
they're needed.
Prior to this patch objects were loaded (via RuntimeDyld::loadObject) when they
were added to the ObjectLinkingLayer, but were not relocated and finalized until
a symbol address was requested. In the interim, another object could be loaded
and finalized with the same memory manager, causing relocation/finalization of
the first object to fail (as the first finalization call may have marked the
allocated memory for the first object read-only).
By deferring the loadObject call (and subsequent memory allocations) until an
object file is needed we can avoid prematurely finalizing memory.
llvm-svn: 258185
Diffstat (limited to 'llvm/lib/ExecutionEngine/Orc')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h index 2ab70a9fee8..896c184d440 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h +++ b/llvm/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h @@ -178,11 +178,10 @@ public: } void addObjectFile(object::OwningBinary<object::ObjectFile> O) override { - std::unique_ptr<object::ObjectFile> Obj; - std::unique_ptr<MemoryBuffer> Buf; - std::tie(Obj, Buf) = O.takeBinary(); - std::vector<std::unique_ptr<object::ObjectFile>> Objs; - Objs.push_back(std::move(Obj)); + std::vector<std::unique_ptr<object::OwningBinary<object::ObjectFile>>> Objs; + Objs.push_back( + llvm::make_unique<object::OwningBinary<object::ObjectFile>>( + std::move(O))); ObjectLayer.addObjectSet(std::move(Objs), &MemMgr, &Resolver); } @@ -284,12 +283,12 @@ private: class NotifyObjectLoadedT { public: - typedef std::vector<std::unique_ptr<object::ObjectFile>> ObjListT; typedef std::vector<std::unique_ptr<RuntimeDyld::LoadedObjectInfo>> LoadedObjInfoListT; NotifyObjectLoadedT(OrcMCJITReplacement &M) : M(M) {} + template <typename ObjListT> void operator()(ObjectLinkingLayerBase::ObjSetHandleT H, const ObjListT &Objects, const LoadedObjInfoListT &Infos) const { @@ -298,10 +297,21 @@ private: assert(Objects.size() == Infos.size() && "Incorrect number of Infos for Objects."); for (unsigned I = 0; I < Objects.size(); ++I) - M.MemMgr.notifyObjectLoaded(&M, *Objects[I]); + M.MemMgr.notifyObjectLoaded(&M, getObject(*Objects[I])); } private: + + static const object::ObjectFile& getObject(const object::ObjectFile &Obj) { + return Obj; + } + + template <typename ObjT> + static const object::ObjectFile& + getObject(const object::OwningBinary<ObjT> &Obj) { + return *Obj.getBinary(); + } + OrcMCJITReplacement &M; }; |