lli/RemoteMemoryManager.cpp: Resurrect __main stuff removed in r192504 to unbreak...
authorNAKAMURA Takumi <geek4civic@gmail.com>
Sat, 26 Oct 2013 13:52:31 +0000 (13:52 +0000)
committerNAKAMURA Takumi <geek4civic@gmail.com>
Sat, 26 Oct 2013 13:52:31 +0000 (13:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193472 91177308-0d34-0410-b5e6-96231b3b80d8

tools/lli/RemoteMemoryManager.cpp
tools/lli/RemoteMemoryManager.h

index 04fc40e426f0c90323859a79df6ac4350bbd0528..f730f0984f4445b5c65d73edaa97469fe4b4e311 100644 (file)
@@ -204,3 +204,19 @@ uint8_t *RemoteMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment)
 void RemoteMemoryManager::deallocateFunctionBody(void *Body) {
   llvm_unreachable("Unexpected!");
 }
+
+static int jit_noop() {
+  return 0;
+}
+
+uint64_t RemoteMemoryManager::getSymbolAddress(const std::string &Name) {
+  // We should not invoke parent's ctors/dtors from generated main()!
+  // On Mingw and Cygwin, the symbol __main is resolved to
+  // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
+  // (and register wrong callee's dtors with atexit(3)).
+  // We expect ExecutionEngine::runStaticConstructorsDestructors()
+  // is called before ExecutionEngine::runFunctionAsMain() is called.
+  if (Name == "__main") return (uintptr_t)&jit_noop;
+
+  return 0;
+}
index 5d0456f509802cb6e1bdc370b459f8638221730e..3368b30ed6a5fea220585d9c5da390e330276568 100644 (file)
@@ -78,7 +78,7 @@ public:
   // interface does support this, but clients must provide their own
   // mechanism for finding remote symbol addresses.  MCJIT will resolve
   // symbols from Modules it contains.
-  uint64_t getSymbolAddress(const std::string &Name) { return 0; }
+  uint64_t getSymbolAddress(const std::string &Name);
 
   void notifyObjectLoaded(ExecutionEngine *EE, const ObjectImage *Obj);