diff options
author | Chris Lattner <sabre@nondot.org> | 2002-12-04 06:04:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-12-04 06:04:07 +0000 |
commit | 75a213dbe8286a5f358ed28312696151dad92ca7 (patch) | |
tree | 2505d32d9dbcb1c263cff8eff025953dceaffbb9 | |
parent | 08053e46be0c7f2024b3df7bfad822f71ac94de3 (diff) |
Implement external function support
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4902 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | tools/jello/VM.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tools/jello/VM.cpp b/tools/jello/VM.cpp index b5a8ca1c22..85c1f2a1e1 100644 --- a/tools/jello/VM.cpp +++ b/tools/jello/VM.cpp @@ -10,6 +10,7 @@ #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/Function.h" #include <iostream> +#include <dlfcn.h> // dlsym access VM::~VM() { @@ -58,6 +59,7 @@ const std::string &VM::getFunctionReferencedName(void *RefAddr) { return FunctionRefs[RefAddr]->getName(); } +static void NoopFn() {} /// getPointerToFunction - This method is used to get the address of the /// specified function, compiling it if neccesary. @@ -67,7 +69,15 @@ void *VM::getPointerToFunction(Function *F) { if (Addr) return Addr; if (F->isExternal()) { - assert(0 && "VM::getPointerToFunction: Doesn't handle external fn's yet!"); + // If it's an external function, look it up in the process image... + void *Ptr = dlsym(0, F->getName().c_str()); + if (Ptr == 0) { + std::cerr << "WARNING: Cannot resolve fn '" << F->getName() + << "' using a dummy noop function instead!\n"; + Ptr = (void*)NoopFn; + } + + return Addr = Ptr; } // JIT all of the functions in the module. Eventually this will JIT functions |