llvm.org GIT mirror llvm / 0a50900
Merging r243589 and r243609: ------------------------------------------------------------------------ r243589 | lhames | 2015-07-29 16:12:33 -0700 (Wed, 29 Jul 2015) | 6 lines [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. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r243609 | lhames | 2015-07-29 19:05:37 -0700 (Wed, 29 Jul 2015) | 2 lines [MCJIT] Fix a memory leak in a unit test that was introduced in r243589. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@243655 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 5 years ago
3 changed file(s) with 49 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
179179 }
180180
181181 std::string ExecutionEngine::getMangledName(const GlobalValue *GV) {
182 assert(GV->hasName() && "Global must have name.");
183
182184 MutexGuard locked(lock);
183 Mangler Mang;
184185 SmallString<128> FullName;
185 Mang.getNameWithPrefix(FullName, GV, false);
186
187 const DataLayout &DL =
188 GV->getParent()->getDataLayout().isDefault()
189 ? *getDataLayout()
190 : GV->getParent()->getDataLayout();
191
192 Mangler::getNameWithPrefix(FullName, GV->getName(), DL);
186193 return FullName.str();
187194 }
188195
265265 RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) {
266266 SmallString<128> FullName;
267267 Mangler::getNameWithPrefix(FullName, Name, *TM->getDataLayout());
268
269 if (void *Addr = getPointerToGlobalIfAvailable(FullName))
270 return RuntimeDyld::SymbolInfo(static_cast(
271 reinterpret_cast(Addr)),
272 JITSymbolFlags::Exported);
273
268274 return Dyld.getSymbol(FullName);
269275 }
270276
487487 EXPECT_TRUE(didCallYield);
488488 }
489489
490 static int localTestFunc() {
491 return 42;
492 }
493
494 TEST_F(MCJITCAPITest, addGlobalMapping) {
495 SKIP_UNSUPPORTED_PLATFORM;
496
497 Module = LLVMModuleCreateWithName("testModule");
498 LLVMTypeRef FunctionType = LLVMFunctionType(LLVMInt32Type(), NULL, 0, 0);
499 LLVMValueRef MappedFn = LLVMAddFunction(Module, "mapped_fn", FunctionType);
500
501 Function = LLVMAddFunction(Module, "test_fn", FunctionType);
502 LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "");
503 LLVMBuilderRef Builder = LLVMCreateBuilder();
504 LLVMPositionBuilderAtEnd(Builder, Entry);
505 LLVMValueRef RetVal = LLVMBuildCall(Builder, MappedFn, NULL, 0, "");
506 LLVMBuildRet(Builder, RetVal);
507 LLVMDisposeBuilder(Builder);
508
509 LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);
510 LLVMDisposeMessage(Error);
511
512 buildMCJITOptions();
513 buildMCJITEngine();
514
515 LLVMAddGlobalMapping(Engine, MappedFn, reinterpret_cast(&localTestFunc));
516
517 buildAndRunPasses();
518
519 uint64_t raw = LLVMGetFunctionAddress(Engine, "test_fn");
520 int (*usable)() = (int (*)()) raw;
521
522 EXPECT_EQ(42, usable());
523 }