summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2010-08-30 14:00:29 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2010-08-30 14:00:29 +0000
commit9c0e59de64de9f6d52eac8b4701baafc7034aaf7 (patch)
tree37f66480ad42eb91605d962f8b83e943f3e9a963 /llvm/lib/ExecutionEngine
parent8199447851be0eab5c020589e7d49184b743d2ab (diff)
downloadbcm5719-llvm-9c0e59de64de9f6d52eac8b4701baafc7034aaf7.tar.gz
bcm5719-llvm-9c0e59de64de9f6d52eac8b4701baafc7034aaf7.zip
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. llvm-svn: 112474
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r--llvm/lib/ExecutionEngine/JIT/Intercept.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/Intercept.cpp b/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
index b367033d32b..c8872e433f3 100644
--- a/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
+++ b/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
@@ -89,6 +89,10 @@ static int jit_atexit(void (*Fn)()) {
return 0; // Always successful
}
+static int jit_noop() {
+ return 0;
+}
+
//===----------------------------------------------------------------------===//
//
/// getPointerToNamedFunction - This method returns the address of the specified
@@ -104,6 +108,14 @@ 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 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;
OpenPOWER on IntegriCloud