[LLVMdev] Calling functions defined in .o files in LLVM code executed in lli

John van Schie jcschie at cs.uu.nl
Fri Dec 7 06:38:05 PST 2007


Hi,

This is probably an easy question, but I could not find the answer to it.

I'm working on a LLVM back-end for the EHC compiler (a Haskell
compiler). Currently there is a C back-end and I would like to reuse the
primitive library functions from this back-end.

So I have compiled C sources in a .o file and I would like to call these
from my LLVM code. If I declare these primitive functions in the LLVM
code and link the bitcode file and the .o file with llvm-ld it works
only if I generate native code. If I omit the -native flag to llvm-ld
and execute the generated shell script a.out I get the following error:

glimi at brodie:~$ llvm-ld ../../prim.o TestExist.bc && ./a.out

ERROR: Program used external function 'primPatternMatchFailure' which
could not be resolved!
lli((anonymous namespace)::PrintStackTrace()+0x15)[0x852c55]
lli((anonymous namespace)::SignalHandler(int)+0x216)[0x852fe6]
/lib/libc.so.6[0x2ada87ac87d0]
/lib/libc.so.6(gsignal+0x35)[0x2ada87ac8765]
/lib/libc.so.6(abort+0x110)[0x2ada87aca1c0]
lli(llvm::JIT::getPointerToNamedFunction(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)+0xde)[0x5c473e]
lli(llvm::JIT::getPointerToFunction(llvm::Function*)+0xf3)[0x5c5183]
lli((anonymous
namespace)::JITResolver::getFunctionStub(llvm::Function*)+0x27f)[0x5c7c6f]
lli((anonymous
namespace)::JITEmitter::getPointerToGlobal(llvm::GlobalValue*, void*,
bool)+0x192)[0x5c7f02]
lli((anonymous
namespace)::JITEmitter::finishFunction(llvm::MachineFunction&)+0x38d)[0x5c82bd]
lli[0x4af284]
lli(llvm::MachineFunctionPass::runOnFunction(llvm::Function&)+0x2c)[0x4f9bbc]
lli(llvm::FPPassManager::runOnFunction(llvm::Function&)+0x1ef)[0x805eef]
lli(llvm::FunctionPassManagerImpl::run(llvm::Function&)+0x72)[0x8063d2]
lli(llvm::FunctionPassManager::run(llvm::Function&)+0x3e)[0x80651e]
lli(llvm::JIT::runJITOnFunction(llvm::Function*)+0x48)[0x5c4848]
lli(llvm::JIT::getPointerToFunction(llvm::Function*)+0x159)[0x5c51e9]
lli((anonymous
namespace)::JITResolver::JITCompilerFn(void*)+0x2df)[0x5c774f]
lli(X86CompilationCallback2+0x43)[0x4ec053]
lli[0x4ebfaa]
Aborted (core dumped)

Is there a way to link the functions declared in the .o file in the
bitcode without compiling the C sources with llvm-gcc?

Regards,

John van Schie



More information about the llvm-dev mailing list