diff options
author | Lang Hames <lhames@gmail.com> | 2015-07-29 23:12:33 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2015-07-29 23:12:33 +0000 |
commit | 3393cfdef8d2ecdbe93ea97d1d912abc83644cbe (patch) | |
tree | cc784bfbdfbba8e28173a5941ac7c62fee4a5097 /llvm/unittests/ExecutionEngine | |
parent | e0d68e381b72c6e9d68de305874669a63cccc35d (diff) | |
download | bcm5719-llvm-3393cfdef8d2ecdbe93ea97d1d912abc83644cbe.tar.gz bcm5719-llvm-3393cfdef8d2ecdbe93ea97d1d912abc83644cbe.zip |
[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
Diffstat (limited to 'llvm/unittests/ExecutionEngine')
-rw-r--r-- | llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
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<void*>(&localTestFunc)); + + buildAndRunPasses(); + + uint64_t raw = LLVMGetFunctionAddress(Engine, "test_fn"); + int (*usable)() = (int (*)()) raw; + + EXPECT_EQ(42, usable()); +} |