[llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/Intercept.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Jun 1 16:53:01 PDT 2004


Changes in directory llvm/lib/ExecutionEngine/JIT:

Intercept.cpp updated: 1.15 -> 1.16

---
Log message:

Implement PR315: http://llvm.cs.uiuc.edu/PR315 : abort, don't warn, when missing external functions encountered

This fixes some critical problems building libstdc++ on cygwin.



---
Diffs of the changes:  (+17 -9)

Index: llvm/lib/ExecutionEngine/JIT/Intercept.cpp
diff -u llvm/lib/ExecutionEngine/JIT/Intercept.cpp:1.15 llvm/lib/ExecutionEngine/JIT/Intercept.cpp:1.16
--- llvm/lib/ExecutionEngine/JIT/Intercept.cpp:1.15	Wed Mar 10 11:38:28 2004
+++ llvm/lib/ExecutionEngine/JIT/Intercept.cpp	Tue Jun  1 16:49:00 2004
@@ -60,8 +60,13 @@
 };
 #endif // __linux__
 
-// NoopFn - Used if we have nothing else to call...
-static void NoopFn() {}
+// __mainFunc - If the program does not have a linked in __main function, allow
+// it to run, but print a warning.
+static void __mainFunc() {
+  fprintf(stderr, "WARNING: Program called __main but was not linked to "
+          "libcrtend.a.\nThis probably won't hurt anything unless the "
+          "program is written in C++.\n");
+}
 
 // jit_exit - Used to intercept the "exit" library call.
 static void jit_exit(int Status) {
@@ -86,13 +91,16 @@
   if (Name == "exit") return (void*)&jit_exit;
   if (Name == "atexit") return (void*)&jit_atexit;
 
+  // If the program does not have a linked in __main function, allow it to run,
+  // but print a warning.
+  if (Name == "__main") return (void*)&__mainFunc;
+
   // If it's an external function, look it up in the process image...
   void *Ptr = GetAddressOfSymbol(Name);
-  if (Ptr == 0) {
-    std::cerr << "WARNING: Cannot resolve fn '" << Name
-	      << "' using a dummy noop function instead!\n";
-    Ptr = (void*)NoopFn;
-  }
-  
-  return Ptr;
+  if (Ptr) return Ptr;
+
+  std::cerr << "ERROR: Program used external function '" << Name
+            << "' which could not be resolved!\n";
+  abort();
+  return 0;
 }





More information about the llvm-commits mailing list