<div dir="ltr"><a href="http://llvm.org/bugs/show_bug.cgi?id=15130">http://llvm.org/bugs/show_bug.cgi?id=15130</a><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jan 31, 2013 at 12:28 PM, Kaylor, Andrew <span dir="ltr"><<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.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">It’s probably best to open a bug.<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">-Andy<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:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Alexey Samsonov [mailto:<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>]
<br>
<b>Sent:</b> Thursday, January 31, 2013 12:27 AM</span></p><div><div class="h5"><br>
<b>To:</b> Kaylor, Andrew<br>
<b>Cc:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> Re: Assertions in RuntimeDyldELF in ExecutionEngine/MCJIT tests<u></u><u></u></div></div><p></p><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Jan 30, 2013 at 8:34 PM, Kaylor, Andrew <<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Yes, at some point we definitely should introduce stubs as a last resort for x86-64 relocations when
the sections are too far apart, but I’d like to avoid it whenever possible.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">What I meant in my previous message was that I’d have RecordingMemoryManager use something other
than malloc (such as the memory API used by SectionMemoryManager) to keep section near one another.</span><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Ok, I see your point. Should I open the bug to track this, or you'll have a chance to look at this issue soon?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">-Andy</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Alexey Samsonov [mailto:<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>]
<br>
<b>Sent:</b> Wednesday, January 30, 2013 3:59 AM<br>
<b>To:</b> Kaylor, Andrew<br>
<b>Cc:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> Re: Assertions in RuntimeDyldELF in ExecutionEngine/MCJIT tests</span><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Hi Andrew,<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Looks like RecordingMemoryManager in lli just calls malloc() and it would be strange to make assumptions (or enforce) that the difference between two returned pointers in 64-bit<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">virtual address space will be fit into 32 bits. Can we do smth similar to what Adhemerval proposed (see the special case in processRelocationRef for ELF::R_PPC64_REL24 relocations)?<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Tue, Jan 29, 2013 at 9:40 PM, Kaylor, Andrew <<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>> wrote:<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi Alexey,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I think the most likely way to resolve this is to have the RecordingMemoryManager do something more
complex to manage its allocations in such a way as to guarantee that they are all within proximity of one another. The code that is asserting is handling a relocation where code was generated to use a 32-bit relative offset in 64-bit code. If the two sections
involved really are more than a 32-bit offset apart then the generated code will not work.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Alternatively, we could have MCJIT use whatever code generation option will prevent 32-bit relative
relocations from being generated in the first place. That would probably be preferable, but I haven’t had success trying to do that in limited efforts up to now.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">As it happens, I’m working with the ‘-use-remote’ option for lli this week trying to add support
for actual out-of-process execution. As I do, I’ll take a look at the allocation scheme in RecordingMemoryManager and see if there is something reasonable I can do there.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">In the meantime, is there any way that you can mark these tests as XFAIL in the sanitizer case?</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Andy</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span><u></u><u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Alexey Samsonov [mailto:<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>]
<br>
<b>Sent:</b> Tuesday, January 29, 2013 3:36 AM<br>
<b>To:</b> LLVM Developers Mailing List<br>
<b>Cc:</b> Kaylor, Andrew<br>
<b>Subject:</b> Assertions in RuntimeDyldELF in ExecutionEngine/MCJIT tests</span><u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Hi!<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I'm trying to run LLVM test suite under AddressSanitizer and get test failures in:<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> LLVM :: ExecutionEngine/MCJIT/simpletest-remote.ll<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> LLVM :: ExecutionEngine/MCJIT/test-data-align-remote.ll<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> LLVM :: ExecutionEngine/MCJIT/test-fp-no-external-funcs-remote.ll<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> LLVM :: ExecutionEngine/MCJIT/test-global-init-nonzero-remote.ll<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">All of them fail with assertion:<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">lli: /usr/local/google/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:230: void llvm::RuntimeDyldELF::resolveX86_64Relocation(const llvm::SectionEntry &, uint64_t, uint64_t,
uint32_t, int64_t): Assertion `RealOffset <= (2147483647) && RealOffset >= (-2147483647-1)' failed.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">The reason is that AddressSanitizer replaces system malloc with its own allocator, which<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">allocates memory at "unusual" parts of heap and the difference between pointers can be significant<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">(and doesn't fit in 32 bytes).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">I add debug output to calculation of RealOffset in resolveX86_64Relocation:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"> uint64_t FinalAddress = Section.LoadAddress + Offset;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> int64_t RealOffset = *Placeholder + Value + Addend - FinalAddress;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> fprintf(stderr, "%x + %lx + %lx - %lx = %lx\n",<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> *Placeholder, Value, Addend, FinalAddress, RealOffset);<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> assert(RealOffset <= INT32_MAX && RealOffset >= INT32_MIN);<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<pre style="line-height:13.5pt;white-space:pre-wrap"> <u></u><u></u></pre>
<pre style="line-height:13.5pt"><span style="font-family:"Arial","sans-serif";color:#222222">This is what I get for system malloc:</span><u></u><u></u></pre>
<pre style="line-height:13.5pt;white-space:pre-wrap"> <u></u><u></u></pre>
<pre style="line-height:13.5pt">0 + 7fec9867a000 + 0 - 7fec9867a040 = ffffffffffffffc0<u></u><u></u></pre>
<p class="MsoNormal">This is what I get for ASan allocator (which results in assert failure):<u></u><u></u></p>
<pre style="line-height:13.5pt;white-space:pre-wrap"> <u></u><u></u></pre>
<pre style="line-height:13.5pt">0 + 600c0000a8a0 + 0 - 6018000090a0 = fffffff400001800<u></u><u></u></pre>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">--<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Alexey Samsonov, MSK<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal">--
<u></u><u></u></p>
<div>
<p class="MsoNormal">Alexey Samsonov, MSK<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<p class="MsoNormal">Alexey Samsonov, MSK<u></u><u></u></p>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div>