LLVM JIT finalizeObject失败或getFunctionAddress失败探究

环境:windows llvm5.0.1

代码:

#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include <llvm/IRReader/IRReader.h>
#include <llvm/Support/SourceMgr.h>
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/TargetSelect.h"
#include <llvm/Support/MemoryBuffer.h>
#include "llvm/Support/raw_ostream.h"
#include <llvm/Support/DynamicLibrary.h>
#include "llvm/Support/Debug.h"


#include <cctype>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
#include <stdlib.h>
#include <iostream>
using namespace llvm;
using namespace std;
static LLVMContext *context;
typedef void(*func_type)(...);

int main(int argc, char* argv[]) {

	InitializeNativeTarget();
	InitializeNativeTargetAsmPrinter();
	InitializeNativeTargetAsmParser();

	RTDyldMemoryManager* RTDyldMM = NULL;
	
	context = new LLVMContext();
	SMDiagnostic *smd = new SMDiagnostic();
	static unique_ptr<Module> Owner = llvm::parseIRFile("external.bc", *smd, *context);
	//std::unique_ptr<Module> Owner = llvm::make_unique<Module>("test", *context);
	Module *module = Owner.get();
	std::string ErrStr;
	RTDyldMM = new SectionMemoryManager();
	ExecutionEngine *executionEngine = EngineBuilder(std::move(Owner))
		.setEngineKind(EngineKind::JIT)
		.setErrorStr(&ErrStr)
		.setVerifyModules(true)
		.setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager>(RTDyldMM))
		.setOptLevel(CodeGenOpt::Default)
		.create();

	if (!executionEngine) {
		exit(1);
	}
	executionEngine->finalizeObject();

	void *func = executionEngine->getPointerToFunction(module->getFunction("sayhello"));
//	uint64_t func = executionEngine->getFunctionAddress("islower");
	func_type f = (func_type)func;
	f();

	system("pause");
	return 0;
}

遇到的问题:

finalizeObject失败,尝试使用getFunctionAddress也失败,调用getFunctionAddress方法时会默认调用finalizeObject方法。

当注释掉finalizeObject方法时,出现如下错误:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值