From 3393cfdef8d2ecdbe93ea97d1d912abc83644cbe Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 29 Jul 2015 23:12:33 +0000 Subject: [MCJIT] Fix PR20656 by teaching MCJIT to honor ExecutionEngine's global mapping. This is important for users of the C API who can't supply custom symbol resolvers yet. llvm-svn: 243589 --- .../ExecutionEngine/MCJIT/MCJITCAPITest.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'llvm/unittests/ExecutionEngine') diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index c7d4dd757cf..16530293270 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -488,3 +488,36 @@ TEST_F(MCJITCAPITest, yield) { EXPECT_TRUE(didCallYield); } +static int localTestFunc() { + return 42; +} + +TEST_F(MCJITCAPITest, addGlobalMapping) { + SKIP_UNSUPPORTED_PLATFORM; + + Module = LLVMModuleCreateWithName("testModule"); + LLVMTypeRef FunctionType = LLVMFunctionType(LLVMInt32Type(), NULL, 0, 0); + LLVMValueRef MappedFn = LLVMAddFunction(Module, "mapped_fn", FunctionType); + + Function = LLVMAddFunction(Module, "test_fn", FunctionType); + LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, ""); + LLVMBuilderRef Builder = LLVMCreateBuilder(); + LLVMPositionBuilderAtEnd(Builder, Entry); + LLVMValueRef RetVal = LLVMBuildCall(Builder, MappedFn, NULL, 0, ""); + LLVMBuildRet(Builder, RetVal); + + LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error); + LLVMDisposeMessage(Error); + + buildMCJITOptions(); + buildMCJITEngine(); + + LLVMAddGlobalMapping(Engine, MappedFn, reinterpret_cast(&localTestFunc)); + + buildAndRunPasses(); + + uint64_t raw = LLVMGetFunctionAddress(Engine, "test_fn"); + int (*usable)() = (int (*)()) raw; + + EXPECT_EQ(42, usable()); +} -- cgit v1.2.3