<div dir="ltr">Hi Axel,<div><br></div><div>the problem is that weak symbols are not handled in RuntimeDyld at all.</div><div>The proper solution is probably to add a separate case for weak symbols</div><div>(where we're already taking care of common symbols) in RuntimeDyld::loadObjectImpl and then adjust the other methods to not</div><div>bail out two quickly when encountering a weak symbol. </div><div><br></div><div>Please let me know if you're planning to work on a patch for this, otherwise I'll have a go tomorrow. </div><div><br></div><div>Thanks,</div><div>Keno</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 12, 2015 at 11:45 AM, Axel Naumann <span dir="ltr"><<a href="mailto:Axel.Naumann@cern.ch" target="_blank">Axel.Naumann@cern.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm finally moving cling to MCJIT - and MCJIT is wonderful! So far I<br>
only ran into this issue:<br>
<br>
$ cat linkonceodr.cxx<br>
extern "C" int printf(const char*,...);<br>
<br>
template <class T> struct StaticStuff {<br>
static T s_data;<br>
};<br>
template <class T> T StaticStuff<T>::s_data = 42;<br>
<br>
int compareAddr(int* mcjit);<br>
<br>
#ifdef BUILD_SHARED<br>
int compareAddr(int* mcjit) {<br>
if (mcjit != &StaticStuff<int>::s_data) {<br>
printf("Wrong address, %ld in shared lib, %ld in mcjit!\n",<br>
(long)&StaticStuff<int>::s_data, (long)mcjit);<br>
return 1;<br>
}<br>
return 0;<br>
}<br>
#else<br>
int main(int, char**) {<br>
return compareAddr(&StaticStuff<int>::s_data);<br>
}<br>
#endif<br>
<br>
<br>
$ clang++ -fPIC -shared -DBUILD_SHARED -o liblinkonceodr.so linkonceodr.cxx<br>
$ clang++ -emit-llvm -c linkonceodr.cxx -o - |<br>
LD_PRELOAD=./liblinkonceodr.so lli -<br>
Wrong address, 140449908087496 in shared lib, 140449908076544 in mcjit!<br>
<br>
<br>
I.e. while compareAddr is resolved from the dylib, this:<br>
<br>
@_ZN11StaticStuffIiE6s_dataE = linkonce_odr global i32 42, align 4<br>
<br>
is not: it is re-emitted by the MCJIT. When building a binary and<br>
linking against that dylib, _ZN11StaticStuffIiE6s is correctly picked up<br>
from the dylib. I would expect MCJIT to behave the same.<br>
<br>
I'll try to fix that myself, but I'd appreciate a hint where to do that.<br>
Should I collect linkonce_odr-s and "replace" their emitted code as part<br>
of llvm::RuntimeDyldImpl::resolveRelocations()? Or is this just a<br>
missing case somewhere?<br>
<br>
That's e.g. with<br>
<br>
$ lli --version<br>
LLVM (<a href="http://llvm.org/" target="_blank">http://llvm.org/</a>):<br>
LLVM version 3.6.0svn<br>
Optimized build.<br>
Built Jan 12 2015 (10:52:59).<br>
Default target: x86_64-unknown-linux-gnu<br>
Host CPU: corei7-avx<br>
<br>
<br>
Cheers, Axel.<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>