[llvm-commits] [llvm] r165312 - /llvm/trunk/tools/lli/lli.cpp
NAKAMURA Takumi
geek4civic at gmail.com
Fri Oct 5 07:10:23 PDT 2012
Author: chapuni
Date: Fri Oct 5 09:10:23 2012
New Revision: 165312
URL: http://llvm.org/viewvc/llvm-project?rev=165312&view=rev
Log:
lli: [MCJIT] Suppress "__main" for cygming in LLIMCJITMemoryManager::getPointerToNamedFunction(), like legacy JITMemoryManager's.
CRT's __main (aka premain) invokes global ctors on cygming. See also PR3897.
Modified:
llvm/trunk/tools/lli/lli.cpp
Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=165312&r1=165311&r2=165312&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Fri Oct 5 09:10:23 2012
@@ -338,6 +338,10 @@
AllocatedCodeMem[i].size());
}
+static int jit_noop() {
+ return 0;
+}
+
void *LLIMCJITMemoryManager::getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure) {
#if defined(__linux__)
@@ -360,6 +364,14 @@
if (Name == "mknod") return (void*)(intptr_t)&mknod;
#endif // __linux__
+ // 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 (void*)(intptr_t)&jit_noop;
+
const char *NameStr = Name.c_str();
void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
if (Ptr) return Ptr;
More information about the llvm-commits
mailing list