[Orc][RuntimeDyld] Prevent duplicate calls to finalizeMemory on shared memory
authorLang Hames <lhames@gmail.com>
Sat, 9 Jan 2016 19:50:40 +0000 (19:50 +0000)
committerLang Hames <lhames@gmail.com>
Sat, 9 Jan 2016 19:50:40 +0000 (19:50 +0000)
commit1a41a8ee7d262acbf2846d52a43ad91bc66cb9f2
treecc9e07541d066db571c8e15d34e447b192480edf
parentcf3ea5921770bf8c58b07d7da418882897b905e3
[Orc][RuntimeDyld] Prevent duplicate calls to finalizeMemory on shared memory
managers.

Prior to this patch, recursive finalization (where finalization of one
RuntimeDyld instance triggers finalization of another instance on which the
first depends) could trigger memory access failures: When the inner (dependent)
RuntimeDyld instance and its memory manager are finalized, memory allocated
(but not yet relocated) by the outer instance is locked, and relocation in the
outer instance fails with a memory access error.

This patch adds a latch to the RuntimeDyld::MemoryManager base class that is
checked by a new method: RuntimeDyld::finalizeWithMemoryManagerLocking, ensuring
that shared memory managers are only finalized by the outermost RuntimeDyld
instance.

This allows ORC clients to supply the same memory manager to multiple calls to
addModuleSet. In particular it enables the use of user-supplied memory managers
with the CompileOnDemandLayer which must reuse the supplied memory manager for
each function that is lazily compiled.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257263 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
include/llvm/ExecutionEngine/RuntimeDyld.h
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp
unittests/ExecutionEngine/Orc/OrcTestCommon.cpp
unittests/ExecutionEngine/Orc/OrcTestCommon.h