From 0ded70ec7cf003281e646cb375270aa81079f359 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 4 Dec 2002 06:04:07 +0000 Subject: [PATCH] Implement external function support llvm-svn: 4902 --- llvm/tools/jello/VM.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/llvm/tools/jello/VM.cpp b/llvm/tools/jello/VM.cpp index b5a8ca1c22d7..85c1f2a1e1f6 100644 --- a/llvm/tools/jello/VM.cpp +++ b/llvm/tools/jello/VM.cpp @@ -10,6 +10,7 @@ #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/Function.h" #include +#include // 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