[llvm-commits] [PATCH] PR3897: suppress invoking __main() from JIT on Cygwin and Mingw

NAKAMURA Takumi geek4civic at gmail.com
Sun Aug 29 20:23:42 PDT 2010


EE/JIT: We don't want to invoke parent's ctors/dtors from main(), to fix PR3897.

--
http://llvm.org/bugs/show_bug.cgi?id=3897
Please review it. Now I can commit it as chapuni.
Confirmed on Cygwin-1.7-(shared,static) and Cygwin-1.5-static.

...Takumi
-------------- next part --------------
diff --git a/lib/ExecutionEngine/JIT/Intercept.cpp b/lib/ExecutionEngine/JIT/Intercept.cpp
index b367033..6ffec0a 100644
--- a/lib/ExecutionEngine/JIT/Intercept.cpp
+++ b/lib/ExecutionEngine/JIT/Intercept.cpp
@@ -89,6 +89,12 @@ static int jit_atexit(void (*Fn)()) {
   return 0;  // Always successful
 }
 
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+static int jit_noop() {
+  return 0;
+}
+#endif
+
 //===----------------------------------------------------------------------===//
 //
 /// getPointerToNamedFunction - This method returns the address of the specified
@@ -104,6 +110,11 @@ void *JIT::getPointerToNamedFunction(const std::string &Name,
     if (Name == "exit") return (void*)(intptr_t)&jit_exit;
     if (Name == "atexit") return (void*)(intptr_t)&jit_atexit;
 
+    // We don't want to invoke parent's ctors/dtors from main()! (PR3897)
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+    if (Name == "__main") return (void*)(intptr_t)&jit_noop;
+#endif
+
     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