failed assertion in PPCJITInfo.cpp when calling native function


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

../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?



// 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");
  ExistingModuleProvider* moduleProvider = new ExistingModuleProvider(module);
  ExecutionEngine* executionEngine =
  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() {
        call void %native( )
        ret void

main.cpp (1.36 KB)

callstack.txt (2.38 KB)