在LLVM 2.8中调用LLVM bitcode函数(Calling LLVM bitcode function in LLVM 2.8)
我正在尝试读取并调用从LLVM 2.8中的LLVM bitcode解析的函数。 我的一切都与实际的通话有关,这会使程序崩溃。
首先我有这个C代码:
void hello() {}
我编译了这个:
llvm-gcc -c -emit-llvm hello.c -o hello.bc
这是一个应该读取的代码的精简版本:
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); }
我已经包含了大量的LLVM头文件,包括ExecutionEngine / JIT.h,以及每一步的代码检查,以确保值不为NULL。 它解析了bitcode,我检查了它发现的函数,以确认它是否符合预期。
我也尝试过自己构建一个模块和函数,它按预期工作,所以问题肯定来自于函数是由bitcode产生的。
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.
原文:https://stackoverflow.com/questions/4755172