<div dir="ltr">Hi Eugene,<div><br></div><div>Returning null addresses to the linker is unusual enough that I'd prefer to keep it as an error.</div><div><br></div><div>Could you return a non-zero marker value, e.g. all-ones? If not, we should add an option to RuntimeDyld like "AllowUnresolvedSymbols" and change the error condition to if '(!Addr && !AllowUnresolvedSymbols)'.</div><div><br></div><div>Cheers,</div><div>Lang.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 25, 2015 at 6:35 PM, Eugene Rozenfeld <span dir="ltr"><<a href="mailto:Eugene.Rozenfeld@microsoft.com" target="_blank">Eugene.Rozenfeld@microsoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Hi Lang,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Can you please let me know you think it would be right to modify
</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RuntimeDyldImpl</span><span style="font-size:10.0pt;font-family:Consolas;color:black">::resolveExternalSymbols
</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#002060">to allow resolvers to return 0 addresses? Something
<span style="background:yellow">like this</span> would be ideal for me:<u></u><u></u></span></p><div><div class="h5">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#002060"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RuntimeDyldImpl</span><span style="font-size:10.0pt;font-family:Consolas;color:black">::resolveExternalSymbols() {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">while</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> (!ExternalSymbolRelocations.empty()) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">StringMap</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RelocationList</span><span style="font-size:10.0pt;font-family:Consolas;color:black">>::</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">iterator</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> i = ExternalSymbolRelocations.begin();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">StringRef</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> Name = i->first();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">if</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> (Name.size() == 0) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// This is an absolute symbol, use an address of zero.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#6f008a">DEBUG</span><span style="font-size:10.0pt;font-family:Consolas;color:black">(dbgs() << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"Resolving absolute relocations."</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"\n"</span><span style="font-size:10.0pt;font-family:Consolas;color:black">);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RelocationList</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> &Relocs = i->second;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> resolveRelocationList(Relocs, 0);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> } </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">else</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">uint64_t</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> Addr = 0;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RTDyldSymbolTable</span><span style="font-size:10.0pt;font-family:Consolas;color:black">::</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">const_iterator</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> Loc = GlobalSymbolTable.find(Name);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">if</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> (Loc == GlobalSymbolTable.end()) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// This is an external symbol, try to get its address from the symbol</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// resolver.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> Addr = Resolver.findSymbol(Name.data()).getAddress();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// The call to getSymbolAddress may have caused additional modules to</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// be loaded, which may have added new entries to the</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// ExternalSymbolRelocations map. Consquently, we need to update our</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// iterator. This is also why retrieval of the relocation list</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// associated with this symbol is deferred until below this point.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// New entries may have been added to the relocation list.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> i = ExternalSymbolRelocations.find(Name);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> } </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">else</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// We found the symbol in our global table. It was probably in a</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// Module that we loaded previously.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">const</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">auto</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> &SymInfo = Loc->second;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> Addr = getSectionLoadAddress(SymInfo.getSectionID()) +<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> SymInfo.getOffset();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
</div></div><p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue;background:yellow">if</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> (Addr) {<u></u><u></u></span></p><span class="">
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black">
</span><span style="font-size:10.0pt;font-family:Consolas;color:#6f008a;background:yellow">DEBUG</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow">(dbgs() << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515;background:yellow">"Resolving relocations Name: "</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> << Name << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515;background:yellow">"\t"</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> << format(</span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515;background:yellow">"0x%lx"</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow">, Addr) << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515;background:yellow">"\n"</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow">);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green;background:yellow">// This list may have been updated when we called getSymbolAddress, so</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green;background:yellow">// don't change this code to get the list earlier.</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af;background:yellow">RelocationList</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> &Relocs = i->second;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> resolveRelocationList(Relocs, Addr);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> }</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> ExternalSymbolRelocations.erase(i);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black">}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#002060"><u></u> <u></u></span></p>
</span><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Eugene<u></u><u></u></span></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Eugene Rozenfeld
<br>
<b>Sent:</b> Wednesday, June 24, 2015 4:47 PM<br>
<b>To:</b> 'Lang Hames'<br>
<b>Cc:</b> <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>
<b>Subject:</b> RE: ORC and relocations<u></u><u></u></span></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Hi Lang,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Thank you for your reply. I tried to supply a custom Resolver that just returns 0 for the symbols I want to handle manually, but that results in a
<span style="background:yellow">fatal error</span> below. If that can be changed, then yes,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">it would be sufficient for my use case.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Eugene<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:blue">void</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RuntimeDyldImpl</span><span style="font-size:10.0pt;font-family:Consolas;color:black">::resolveExternalSymbols() {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">while</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> (!ExternalSymbolRelocations.empty()) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">StringMap</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RelocationList</span><span style="font-size:10.0pt;font-family:Consolas;color:black">>::</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">iterator</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> i = ExternalSymbolRelocations.begin();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">StringRef</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> Name = i->first();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">if</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> (Name.size() == 0) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// This is an absolute symbol, use an address of zero.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#6f008a">DEBUG</span><span style="font-size:10.0pt;font-family:Consolas;color:black">(dbgs() << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"Resolving absolute relocations."</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"\n"</span><span style="font-size:10.0pt;font-family:Consolas;color:black">);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RelocationList</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> &Relocs = i->second;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> resolveRelocationList(Relocs, 0);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> } </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">else</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">uint64_t</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> Addr = 0;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RTDyldSymbolTable</span><span style="font-size:10.0pt;font-family:Consolas;color:black">::</span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">const_iterator</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> Loc = GlobalSymbolTable.find(Name);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">if</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> (Loc == GlobalSymbolTable.end()) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// This is an external symbol, try to get its address from the symbol</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// resolver.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> Addr = Resolver.findSymbol(Name.data()).getAddress();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// The call to getSymbolAddress may have caused additional modules to</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// be loaded, which may have added new entries to the</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// ExternalSymbolRelocations map. Consquently, we need to update our</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// iterator. This is also why retrieval of the relocation list</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// associated with this symbol is deferred until below this point.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// New entries may have been added to the relocation list.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> i = ExternalSymbolRelocations.find(Name);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> } </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">else</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// We found the symbol in our global table. It was probably in a</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// Module that we loaded previously.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">const</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue">auto</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> &SymInfo = Loc->second;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> Addr = getSectionLoadAddress(SymInfo.getSectionID()) +<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> SymInfo.getOffset();<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// FIXME: Implement error handling that doesn't kill the host program!</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:blue;background:yellow">if</span><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> (!Addr) {<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black;background:yellow"> </span><span style="font-size:10.0pt;font-family:Consolas;background:yellow">report_fatal_error("Program used external function '" + Name +<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;background:yellow"> "' which could not be resolved!");<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:green;background:yellow"> }</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#6f008a">DEBUG</span><span style="font-size:10.0pt;font-family:Consolas;color:black">(dbgs() << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"Resolving relocations Name: "</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> << Name << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"\t"</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> << format(</span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"0x%lx"</span><span style="font-size:10.0pt;font-family:Consolas;color:black">, Addr) << </span><span style="font-size:10.0pt;font-family:Consolas;color:#a31515">"\n"</span><span style="font-size:10.0pt;font-family:Consolas;color:black">);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// This list may have been updated when we called getSymbolAddress, so</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:green">// don't change this code to get the list earlier.</span><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span style="font-size:10.0pt;font-family:Consolas;color:#2b91af">RelocationList</span><span style="font-size:10.0pt;font-family:Consolas;color:black"> &Relocs = i->second;<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> resolveRelocationList(Relocs, Addr);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> ExternalSymbolRelocations.erase(i);<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:Consolas;color:black">}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Lang Hames [<a href="mailto:lhames@gmail.com" target="_blank">mailto:lhames@gmail.com</a>]
<br>
<b>Sent:</b> Wednesday, June 24, 2015 4:42 PM<br>
<b>To:</b> Eugene Rozenfeld<br>
<b>Cc:</b> <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>
<b>Subject:</b> Re: ORC and relocations<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div></div><div>
<p class="MsoNormal">Hi Eugene,<u></u><u></u></p><div><div class="h5">
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">There's no way to 'skip' application of a relocation.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">You could use the NotifyLoadedFtor and libObject to scan the object ahead of time and record the relocations that you'd like to override, then you could supply a custom Resolver that just returns '0' for the symbols that you want to handle
manually. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">There's no way to handle distinct relocations for the same symbol differently: For performance reasons we only look up each symbol once and re-use the supplied address to apply every relocation for that symbol.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Is that sufficient to support your use-case?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Lang.<u></u><u></u></p>
</div>
</div></div></div><div><div class="h5">
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Wed, Jun 24, 2015 at 12:03 AM, Eugene Rozenfeld <<a href="mailto:Eugene.Rozenfeld@microsoft.com" target="_blank">Eugene.Rozenfeld@microsoft.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal">Hello,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">I’m working on LLILC (a jit for the CoreCLR built on ORC), in particular, on using LLILC as an ngen jit. I would like to have an ability to be notified of relocations that ObjectLinkingLayer
is applying and to be able to tell the linking layer not to resolve certain relocations for external symbols (so that the client can do some custom resolutions later). The only way I found of looking at relocations in the client is via NotifyLoadedFtor notifications
but I couldn’t find a way of blocking a relocation resolution.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">One way to achieve that is to change the Resolver::findSymbol api to allow clients to indicate that the relocations for the symbol shouldn’t be resolved and update RuntimeDyldImpl::resolveExternalSymbols
accordingly. Would this be a reasonable approach?<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Eugene<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>
</blockquote></div><br></div>