1
我試圖讀取並調用LLVM 2.8中的LLVM位碼解析的函數。除了實際調用之外,我已將所有工作都分開了,這會導致程序崩潰。在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。它解析位碼,並且我檢查了它發現的功能以確認它是否如預期的那樣。
我也試過建立一個模塊和函數我自己,它按預期的方式工作,所以這個問題肯定是由於函數是由位碼產生的。
這可能有助於提供有關您所看到的確切崩潰的更多信息(例如,回溯)。 – 2011-01-23 17:14:38