Sanitize MCJIT remote execution

MCJIT remote execution (ChildTarget+RemoteTargetExternal) protocol was in
dire need of refactoring. It was fail-prone, had no error reporting and
implemented the same message logic on every single function.

This patch rectifies it, and makes it work on ARM, where it was randomly
failing. Other architectures shall profit from this change as well, making
their buildbots and releases more reliable.

llvm-svn: 199261
diff --git a/llvm/tools/lli/RemoteMemoryManager.cpp b/llvm/tools/lli/RemoteMemoryManager.cpp
index 04fc40e..c9d426a 100644
--- a/llvm/tools/lli/RemoteMemoryManager.cpp
+++ b/llvm/tools/lli/RemoteMemoryManager.cpp
@@ -129,7 +129,7 @@
 
   // Allocate space in the remote target.
   uint64_t RemoteAddr;
-  if (Target->allocateSpace(CurOffset, MaxAlign, RemoteAddr))
+  if (!Target->allocateSpace(CurOffset, MaxAlign, RemoteAddr))
     report_fatal_error(Target->getErrorMsg());
 
   // Map the section addresses so relocations will get updated in the local
@@ -155,13 +155,13 @@
     uint64_t RemoteAddr = I->first;
     const Allocation &Section = I->second;
     if (Section.IsCode) {
-      Target->loadCode(RemoteAddr, Section.MB.base(), Section.MB.size());
-
+      if (!Target->loadCode(RemoteAddr, Section.MB.base(), Section.MB.size()))
+        report_fatal_error(Target->getErrorMsg());
       DEBUG(dbgs() << "  loading code: " << Section.MB.base()
             << " to remote: 0x" << format("%llx", RemoteAddr) << "\n");
     } else {
-      Target->loadData(RemoteAddr, Section.MB.base(), Section.MB.size());
-
+      if (!Target->loadData(RemoteAddr, Section.MB.base(), Section.MB.size()))
+        report_fatal_error(Target->getErrorMsg());
       DEBUG(dbgs() << "  loading data: " << Section.MB.base()
             << " to remote: 0x" << format("%llx", RemoteAddr) << "\n");
     }