[LLVMdev] failed assertion in PPCJITInfo.cpp when calling native function

Andreas Eriksson aeriksson at gmail.com
Sat Sep 16 09:39:12 PDT 2006


Hi,

I am trying to generate LLVM code that calls a "native" function in the parent
program (the program hosting the JIT). I think that I have figured out how to
do this, but I get the following assertion failure when the LLVM code is
executed:

../llvm/lib/Target/PowerPC/PPCJITInfo.cpp:206: failed assertion
`ResultPtr >= -(1 << 23) && ResultPtr < (1 << 23) && "Relocation out of range!"'

I am running LLVM 1.8 and MacOSX Tiger on a PowerPC G4.

I have attached a complete, minimal program that reproduces the error and the
call-stack. However, the relevant part of the program looks as follows. Am I
doing something wrong, or is this a bug in the JIT?

Regards,

Andreas

// the "native" function that the llvm code should call
extern "C" { void nativeFunction() {} }

int main() {
  Module* module = new Module("module");

  FunctionType* funType =
    FunctionType::get(Type::VoidTy, vector<const Type*>(), false);
  Function* nativeFunction = new Function(
    funType, GlobalValue::ExternalLinkage, "native", module);
  Function* llvmFunction = new Function(funType, GlobalValue::ExternalLinkage,
    "llvmFunction", module);
  BasicBlock* block = new BasicBlock("Entry", llvmFunction);
  new CallInst(nativeFunction, vector<Value*>(), "", block);
  new ReturnInst(block);

  sys::DynamicLibrary dynamicLibrary;
  void* nativePointer = dynamicLibrary.GetAddressOfSymbol("nativeFunction");
  assert(nativePointer);
  ExistingModuleProvider* moduleProvider = new ExistingModuleProvider(module);
  ExecutionEngine* executionEngine =
ExecutionEngine::create(moduleProvider);
  executionEngine->addGlobalMapping(nativeFunction, nativePointer);
  executionEngine->runFunction(llvmFunction, vector<GenericValue>());
}

The program generates the following LLVM code:

; ModuleID = 'module'

implementation   ; Functions:

declare void %native()

void %llvmFunction() {
Entry:
        call void %native( )
        ret void
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: application/octet-stream
Size: 1397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20060916/f591cffa/attachment.obj>
-------------- next part --------------
#0  0x9004802c in kill ()
#1  0x9012dfb4 in abort ()
#2  0x94b2d0b0 in __eprintf ()
#3  0x00074cd4 in llvm::PPCJITInfo::relocate (this=0x0, Function=0x8088004, MR=0x6604b30, NumRelocs=1, GOTBase=0x0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/Target/PowerPC/PPCJITInfo.cpp:205
#4  0x00017c00 in (anonymous namespace)::JITEmitter::finishFunction (this=0x6602f80, F=@0x6604db0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:824
#5  0x0005a984 in (anonymous namespace)::PPCCodeEmitter::runOnMachineFunction (this=0x6603f70, MF=@0x6604db0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp:88
#6  0x003ebfcc in llvm::MachineFunctionPass::runOnFunction (this=0x6603f70, F=@0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/include/llvm/CodeGen/MachineFunctionPass.h:37
#7  0x0061ab6c in llvm::FunctionPassManagerT::runPass (this=0x0, P=0x6603f70, F=0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/VMCore/PassManagerT.h:795
#8  0x006385ac in llvm::PassManagerT<llvm::FTraits>::runPasses (this=0x6602f28, M=0x6601ff0, LastUserOf=@0xbfffee08) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/VMCore/PassManagerT.h:596
#9  0x0063bca4 in llvm::PassManagerT<llvm::FTraits>::runOnUnit (this=0x6602f28, M=0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/VMCore/PassManagerT.h:282
#10 0x0061ad18 in llvm::FunctionPassManagerT::runOnFunction (this=0x8, F=@0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/VMCore/PassManagerT.h:884
#11 0x001c4868 in llvm::FunctionPass::run (this=0x6602f10, F=@0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/VMCore/Pass.cpp:256
#12 0x001c49d4 in llvm::FunctionPassManager::run (this=0x6602ec0, F=@0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/VMCore/Pass.cpp:103
#13 0x000126e0 in llvm::JIT::runJITOnFunction (this=0x6602e70, F=0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/ExecutionEngine/JIT/JIT.cpp:244
#14 0x00012b10 in llvm::JIT::getPointerToFunction (this=0x6602e70, F=0x6601ff0) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/ExecutionEngine/JIT/JIT.cpp:282
#15 0x00013580 in llvm::JIT::runFunction (this=0x6602e70, F=0x6601ff0, ArgValues=@0xbffff1dc) at /Users/andreas/build/llvm-1.8/debugBuild/../llvm/lib/ExecutionEngine/JIT/JIT.cpp:85
#16 0x00003190 in main ()


More information about the llvm-dev mailing list