문제

I'm trying to read and call a function parsed from LLVM bitcode in LLVM 2.8. I have everything working apart from the actual call, which crashes the program.

First I have this C code:

void hello() {}

I've compiled this with:

llvm-gcc -c -emit-llvm hello.c -o hello.bc

Here's a trimmed down version of the code that's supposed to read it:

using namespace std;
using namespace llvm;

void callFunction(string file, string function) {
  InitializeNativeTarget();

  LLVMContext context;
  string error;

  MemoryBuffer* buff = MemoryBuffer::getFile(file);
  Module* m = getLazyBitcodeModule(buff, context, &error);

  // Check the module parsed here.
  // ...

  ExecutionEngine* engine = ExecutionEngine::create(m);

  // Check the engine started up correctly here.
  // ...

  Function* func = m->getFunction(function);

  // Check the function was found here.
  // ..

  vector<GenericValue> args(0);

  // This is what crashes.
  engine->runFunction(func, args);
}

I've included plenty of LLVM headers, including ExecutionEngine/JIT.h, and the code checks at each step to make sure values aren't NULL. It parses the bitcode, and I have examined the function it finds to confirm it was as expected.

I've also tried building a module and function myself, which works as expected, so the problem definitely arises from the fact that the function is produced by the bitcode.

도움이 되었습니까?

해결책

I've managed to get this running as expected. I was curious if the problem lay in the above process, but this is obviously not the case. The system I was running this as a part of was causing the crash, and the code above does work on its own.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top