summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/RuntimeDyld
diff options
context:
space:
mode:
authorAndrew Kaylor <andrew.kaylor@intel.com>2013-10-21 17:42:06 +0000
committerAndrew Kaylor <andrew.kaylor@intel.com>2013-10-21 17:42:06 +0000
commit6169453ba37ac353655f2475f336e66f31276752 (patch)
tree41bbad7ba9a1eb1b2afbc0157de173b7ab893733 /lib/ExecutionEngine/RuntimeDyld
parent770530babc78e444bb6d0aadc87702ef138293fd (diff)
downloadllvm-6169453ba37ac353655f2475f336e66f31276752.tar.gz
llvm-6169453ba37ac353655f2475f336e66f31276752.tar.bz2
llvm-6169453ba37ac353655f2475f336e66f31276752.tar.xz
Improving MCJIT/RuntimeDyld thread safety
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/RuntimeDyld')
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp6
-rw-r--r--lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h13
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 07de4ba8cd..f40bed1b3f 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -19,6 +19,7 @@
#include "RuntimeDyldMachO.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/MutexGuard.h"
#include "llvm/Object/ELF.h"
using namespace llvm;
@@ -37,6 +38,8 @@ void RuntimeDyldImpl::deregisterEHFrames() {
// Resolve the relocations for all symbols we currently know about.
void RuntimeDyldImpl::resolveRelocations() {
+ MutexGuard locked(lock);
+
// First, resolve relocations associated with external symbols.
resolveExternalSymbols();
@@ -57,6 +60,7 @@ void RuntimeDyldImpl::resolveRelocations() {
void RuntimeDyldImpl::mapSectionAddress(const void *LocalAddress,
uint64_t TargetAddress) {
+ MutexGuard locked(lock);
for (unsigned i = 0, e = Sections.size(); i != e; ++i) {
if (Sections[i].Address == LocalAddress) {
reassignSectionAddress(i, TargetAddress);
@@ -73,6 +77,8 @@ ObjectImage *RuntimeDyldImpl::createObjectImage(ObjectBuffer *InputBuffer) {
}
ObjectImage *RuntimeDyldImpl::loadObject(ObjectBuffer *InputBuffer) {
+ MutexGuard locked(lock);
+
OwningPtr<ObjectImage> obj(createObjectImage(InputBuffer));
if (!obj)
report_fatal_error("Unable to create object image from memory buffer!");
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
index 465d05bf2c..3014b30773 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
@@ -25,6 +25,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Host.h"
+#include "llvm/Support/Mutex.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h"
@@ -186,6 +187,18 @@ protected:
Triple::ArchType Arch;
bool IsTargetLittleEndian;
+ // This mutex prevents simultaneously loading objects from two different
+ // threads. This keeps us from having to protect individual data structures
+ // and guarantees that section allocation requests to the memory manager
+ // won't be interleaved between modules. It is also used in mapSectionAddress
+ // and resolveRelocations to protect write access to internal data structures.
+ //
+ // loadObject may be called on the same thread during the handling of of
+ // processRelocations, and that's OK. The handling of the relocation lists
+ // is written in such a way as to work correctly if new elements are added to
+ // the end of the list while the list is being processed.
+ sys::Mutex lock;
+
virtual unsigned getMaxStubSize() = 0;
virtual unsigned getStubAlignment() = 0;