[llvm-commits] CVS: llvm/tools/lli/lli.cpp
Chris Lattner
sabre at nondot.org
Sun Jan 7 23:36:49 PST 2007
Changes in directory llvm/tools/lli:
lli.cpp updated: 1.64 -> 1.65
---
Log message:
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
---
Diffs of the changes: (+16 -3)
lli.cpp | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
Index: llvm/tools/lli/lli.cpp
diff -u llvm/tools/lli/lli.cpp:1.64 llvm/tools/lli/lli.cpp:1.65
--- llvm/tools/lli/lli.cpp:1.64 Sun Jan 7 00:43:08 2007
+++ llvm/tools/lli/lli.cpp Mon Jan 8 01:36:34 2007
@@ -118,9 +118,22 @@
// 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 (...) {
More information about the llvm-commits
mailing list