<div dir="ltr">Hi Aaron,<div><br></div><div>Thanks for spotting this. I've committed a fix in 243891.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 31, 2015 at 1:13 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wed, Jul 29, 2015 at 7:12 PM, Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:<br>
> Author: lhames<br>
> Date: Wed Jul 29 18:12:33 2015<br>
> New Revision: 243589<br>
><br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D243589-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=MUlKSiOQQDdWb2pn7yO5VDXMdUzO-My3R1KQWC3V1Sc&s=2nV6UnxDi4GaVdqXWQ3uV1B_FqHbMMiI5iMpKTdGd9I&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243589&view=rev</a><br>
> Log:<br>
> [MCJIT] Fix PR20656 by teaching MCJIT to honor ExecutionEngine's global mapping.<br>
><br>
> This is important for users of the C API who can't supply custom symbol<br>
> resolvers yet.<br>
><br>
><br>
> Modified:<br>
>     llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp<br>
>     llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
>     llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp<br>
><br>
> Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_ExecutionEngine_ExecutionEngine.cpp-3Frev-3D243589-26r1-3D243588-26r2-3D243589-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=MUlKSiOQQDdWb2pn7yO5VDXMdUzO-My3R1KQWC3V1Sc&s=hq8gp2WcFr1Bd95FrcbyE5rEqE22aqv3149Sb9FiSC8&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=243589&r1=243588&r2=243589&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)<br>
> +++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Wed Jul 29 18:12:33 2015<br>
> @@ -189,10 +189,17 @@ uint64_t ExecutionEngineState::RemoveMap<br>
>  }<br>
><br>
>  std::string ExecutionEngine::getMangledName(const GlobalValue *GV) {<br>
> +  assert(GV->hasName() && "Global must have name.");<br>
> +<br>
>    MutexGuard locked(lock);<br>
> -  Mangler Mang;<br>
>    SmallString<128> FullName;<br>
> -  Mang.getNameWithPrefix(FullName, GV, false);<br>
> +<br>
> +  const DataLayout &DL =<br>
> +    GV->getParent()->getDataLayout().isDefault()<br>
> +      ? getDataLayout()<br>
> +      : GV->getParent()->getDataLayout();<br>
> +<br>
> +  Mangler::getNameWithPrefix(FullName, GV->getName(), DL);<br>
>    return FullName.str();<br>
>  }<br>
><br>
><br>
> Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_ExecutionEngine_MCJIT_MCJIT.cpp-3Frev-3D243589-26r1-3D243588-26r2-3D243589-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=MUlKSiOQQDdWb2pn7yO5VDXMdUzO-My3R1KQWC3V1Sc&s=q_-VKD3UzM051jkOA_HDU10-rVPrjjSRg11tTlwWqdo&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=243589&r1=243588&r2=243589&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)<br>
> +++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp Wed Jul 29 18:12:33 2015<br>
> @@ -270,6 +270,12 @@ void MCJIT::finalizeModule(Module *M) {<br>
>  RuntimeDyld::SymbolInfo MCJIT::findExistingSymbol(const std::string &Name) {<br>
>    SmallString<128> FullName;<br>
>    Mangler::getNameWithPrefix(FullName, Name, getDataLayout());<br>
> +<br>
> +  if (void *Addr = getPointerToGlobalIfAvailable(FullName))<br>
> +    return RuntimeDyld::SymbolInfo(static_cast<uint64_t>(<br>
> +                                     reinterpret_cast<uintptr_t>(Addr)),<br>
> +                                   JITSymbolFlags::Exported);<br>
> +<br>
>    return Dyld.getSymbol(FullName);<br>
>  }<br>
><br>
><br>
> Modified: llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_unittests_ExecutionEngine_MCJIT_MCJITCAPITest.cpp-3Frev-3D243589-26r1-3D243588-26r2-3D243589-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=MUlKSiOQQDdWb2pn7yO5VDXMdUzO-My3R1KQWC3V1Sc&s=CQq6hFHb5Yr98AAOTxLPy06NoOlhvgj9XvIaDqd2k-M&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp?rev=243589&r1=243588&r2=243589&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp (original)<br>
> +++ llvm/trunk/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp Wed Jul 29 18:12:33 2015<br>
> @@ -488,3 +488,36 @@ TEST_F(MCJITCAPITest, yield) {<br>
>    EXPECT_TRUE(didCallYield);<br>
>  }<br>
><br>
> +static int localTestFunc() {<br>
> +  return 42;<br>
> +}<br>
> +<br>
> +TEST_F(MCJITCAPITest, addGlobalMapping) {<br>
> +  SKIP_UNSUPPORTED_PLATFORM;<br>
> +<br>
> +  Module = LLVMModuleCreateWithName("testModule");<br>
> +  LLVMTypeRef FunctionType = LLVMFunctionType(LLVMInt32Type(), NULL, 0, 0);<br>
> +  LLVMValueRef MappedFn = LLVMAddFunction(Module, "mapped_fn", FunctionType);<br>
> +<br>
> +  Function = LLVMAddFunction(Module, "test_fn", FunctionType);<br>
> +  LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "");<br>
> +  LLVMBuilderRef Builder = LLVMCreateBuilder();<br>
> +  LLVMPositionBuilderAtEnd(Builder, Entry);<br>
> +  LLVMValueRef RetVal = LLVMBuildCall(Builder, MappedFn, NULL, 0, "");<br>
> +  LLVMBuildRet(Builder, RetVal);<br>
> +<br>
> +  LLVMVerifyModule(Module, LLVMAbortProcessAction, &Error);<br>
> +  LLVMDisposeMessage(Error);<br>
> +<br>
> +  buildMCJITOptions();<br>
> +  buildMCJITEngine();<br>
> +<br>
> +  LLVMAddGlobalMapping(Engine, MappedFn, reinterpret_cast<void*>(&localTestFunc));<br>
<br>
</div></div>This is currently causing a warning:<br>
<br>
/opt/llvm/build-llvm/src/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp:<br>
In member function ‘virtual void<br>
MCJITCAPITest_addGlobalMapping_Test::TestBody()’:<br>
/opt/llvm/build-llvm/src/llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp:517:80:<br>
warning: ISO C++ forbids casting between pointer-to-function and<br>
pointer-to-object [enabled by default]<br>
<br>
Any chance you can take care of this one?<br>
<br>
Thanks!<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> +<br>
> +  buildAndRunPasses();<br>
> +<br>
> +  uint64_t raw = LLVMGetFunctionAddress(Engine, "test_fn");<br>
> +  int (*usable)() = (int (*)()) raw;<br>
> +<br>
> +  EXPECT_EQ(42, usable());<br>
> +}<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>