[llvm-commits] CVS: llvm/tools/lli/JIT/Emitter.cpp

Misha Brukman brukman at cs.uiuc.edu
Mon Jul 28 14:10:01 PDT 2003


Changes in directory llvm/tools/lli/JIT:

Emitter.cpp updated: 1.17 -> 1.18

---
Log message:

Add ability for external C code to get pointers to functions given their name.
This us used by bugpoint -- when code is compiled to a shared object to be
JITted, it must use the JIT's lazy resolution method to find function addresses,
because some functions will not be available at .so load time, as they are in
the bytecode file.


---
Diffs of the changes:

Index: llvm/tools/lli/JIT/Emitter.cpp
diff -u llvm/tools/lli/JIT/Emitter.cpp:1.17 llvm/tools/lli/JIT/Emitter.cpp:1.18
--- llvm/tools/lli/JIT/Emitter.cpp:1.17	Mon Jun 30 16:59:03 2003
+++ llvm/tools/lli/JIT/Emitter.cpp	Mon Jul 28 14:09:06 2003
@@ -11,14 +11,13 @@
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/Target/TargetData.h"
-#include "llvm/Function.h"
+#include "llvm/Module.h"
 #include "Support/Statistic.h"
 #include <stdio.h>
 
-static VM *TheVM = 0;
-
 namespace {
   Statistic<> NumBytes("jello", "Number of bytes of machine code compiled");
+  VM *TheVM = 0;
 
   class Emitter : public MachineCodeEmitter {
     // CurBlock - The start of the current block of memory.  CurByte - The
@@ -186,3 +185,16 @@
   return (intptr_t)TheVM->getPointerToFunction(F);
 }
 
+// getPointerToNamedFunction - This function is used as a global wrapper to
+// VM::getPointerToNamedFunction for the purpose of resolving symbols when
+// bugpoint is debugging the JIT. In that scenario, we are loading an .so and
+// need to resolve function(s) that are being mis-codegenerated, so we need to
+// resolve their addresses at runtime, and this is the way to do it.
+extern "C" {
+  void *getPointerToNamedFunction(const char *Name) {
+    Module &M = TheVM->getModule();
+    if (Function *F = M.getNamedFunction(Name))
+      return TheVM->getPointerToFunction(F);
+    return TheVM->getPointerToNamedFunction(Name);
+  }
+}





More information about the llvm-commits mailing list