[llvm-commits] [llvm] r112474 - /llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp

NAKAMURA Takumi geek4civic at gmail.com
Mon Aug 30 07:00:29 PDT 2010


Author: chapuni
Date: Mon Aug 30 09:00:29 2010
New Revision: 112474

URL: http://llvm.org/viewvc/llvm-project?rev=112474&view=rev
Log:
EE/JIT: Do not invoke parent's ctors/dtors from main()! (PR3897)

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, by callee, ExecutionEngine::runStaticConstructorsDestructors()
is called before ExecutionEngine::runFunctionAsMain() is called.

Modified:
    llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp

Modified: llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp?rev=112474&r1=112473&r2=112474&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/Intercept.cpp Mon Aug 30 09:00:29 2010
@@ -89,6 +89,10 @@
   return 0;  // Always successful
 }
 
+static int jit_noop() {
+  return 0;
+}
+
 //===----------------------------------------------------------------------===//
 //
 /// getPointerToNamedFunction - This method returns the address of the specified
@@ -104,6 +108,14 @@
     if (Name == "exit") return (void*)(intptr_t)&jit_exit;
     if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
 
+    // We shuold not invoke parent's ctors/dtors from main()! (PR3897)
+    // 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 (void*)(intptr_t)&jit_noop;
+
     const char *NameStr = Name.c_str();
     // If this is an asm specifier, skip the sentinal.
     if (NameStr[0] == 1) ++NameStr;





More information about the llvm-commits mailing list