summaryrefslogtreecommitdiff
path: root/tools/lli
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-01-08 07:36:34 +0000
committerChris Lattner <sabre@nondot.org>2007-01-08 07:36:34 +0000
commitc0974a1344f0c565f0200d28537806bf07b68acf (patch)
tree476c1397893e41de9d69b5525250625a70caea14 /tools/lli
parentb801a27121aac7fe25436f1f5febfad1d4a9df79 (diff)
downloadllvm-c0974a1344f0c565f0200d28537806bf07b68acf.tar.gz
llvm-c0974a1344f0c565f0200d28537806bf07b68acf.tar.bz2
llvm-c0974a1344f0c565f0200d28537806bf07b68acf.tar.xz
fix atexit. This is an overcomplex way of calling exit, but it is required,
as the jit intercepts exit calls to implement atexit handlers. This fixes SingleSource/UnitTests/2003-05-14-AtExit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33008 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli')
-rw-r--r--tools/lli/lli.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 998e761681..9f1ecc2978 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -118,9 +118,22 @@ int main(int argc, char **argv, char * const *envp) {
// Run static destructors.
EE->runStaticConstructorsDestructors(true);
- exit(Result);
- std::cerr << "ERROR: exit(" << Result << ") returned!\n";
- abort();
+ // If the program didn't explicitly call exit, call exit now, for the
+ // program. This ensures that any atexit handlers get called correctly.
+ Constant *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy,
+ Type::Int32Ty, NULL);
+ if (Function *ExitF = dyn_cast<Function>(Exit)) {
+ std::vector<GenericValue> Args;
+ GenericValue ResultGV;
+ ResultGV.Int32Val = Result;
+ Args.push_back(ResultGV);
+ EE->runFunction(ExitF, Args);
+ std::cerr << "ERROR: exit(" << Result << ") returned!\n";
+ abort();
+ } else {
+ std::cerr << "ERROR: exit defined with wrong prototype!\n";
+ abort();
+ }
} catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n";
} catch (...) {