<div dir="rtl"><div dir="ltr">Hi Andy,</div><div dir="ltr"><br></div><div dir="ltr">I have updated the patch to latest SVN with your multi-module patch, attached. </div><div dir="ltr"><br></div><div dir="ltr">These are the issues fixed in this patch:</div>

<div dir="ltr"><br></div><div dir="ltr">1) Dynamic load of __register_frame and __deregister_frame at runtime. This makes EH work in cross-compilation where these functions are not available at compile time but are available at runtime. Including (but not limited to) to building clang with Visual C++ and running with MingW headers and runtime which is the configuration I'm using now.</div>

<div dir="ltr"><br></div><div dir="ltr">2) deregisterEHFrames() in all relevant places finally calling __register_frame(). I have implemented a separate function per your suggestion, it does cause some code duplication.</div>

<div dir="ltr"><br></div><div dir="ltr">3) ~MCJIT() calling Dyld.deregisterEHFrames();. </div><div dir="ltr"><br></div><div dir="ltr">4) Call __registerframe once only in non-Apple platforms. According to </div><div dir="ltr">

<br></div><div dir="ltr"><a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-April/061768.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-April/061768.html</a> </div><div dir="ltr"><br></div><div dir="ltr">this is the right thing to do. I have tested this change on Windows only where it indeed makes exceptions work right.</div>

<div dir="ltr"><br></div><div dir="ltr">These are the issues not yet fixed:</div><div dir="ltr"><br></div><div dir="ltr">5) As you write, (de)registerEHFrames() should be done per-module but we do not keep the module-specific EH information. Maybe RuntimeDyldELF should keep a map of (modules, EH frames) so we can load and unload EH for specific module ?</div>

<div dir="ltr"><br></div><div dir="ltr">6) The four final zero bytes in .eh_frame issue. Currently (in Windows) it works as there are zeros following .eh_frame. I don't know if it's pure luck or some other frame following in memory with zeros but we need to make sure these four zeros are always there.</div>

<div dir="ltr"><br></div><div dir="ltr">Where would be the right place to append these bytes between the creation of .eh_frame (without zeros) and the usage of .eh_frame in __register_frame requiring zeros)?</div><div dir="ltr">

Maybe in RuntimeDyldELF::finalizeLoad()? <br></div><div dir="ltr"><br></div><div dir="ltr">Yaron</div><div dir="ltr"><br></div><div dir="ltr"><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div dir="ltr">

2013/10/9 Kaylor, Andrew <span dir="ltr"><<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>></span></div><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 Yaron,<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">I’m in the process of updating the EH frame support in MCJIT and RuntimeDyld to handle registration of multiple generated or loaded objects.  These changes
 involve an update to the memory manager and RuntimeDyld interfaces for registering EH frame data.  They will also highlight complications which would need to be considered in your patch with regard to deregistration of frame data.<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">In addition, I would prefer to have a separate “deregister” function rather than overloading the behavior of the registerFrames function.<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">I’m attaching my current patch so you can see where this is going.  Also feel free to provide feedback on the patch.<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">Please wait for my multiple object patch to be committed.  After that we can discuss the details of how deregistration should work.<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">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"><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""> <a href="mailto:llvm-commits-bounces@cs.uiuc.edu" target="_blank">llvm-commits-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvm-commits-bounces@cs.uiuc.edu" target="_blank">llvm-commits-bounces@cs.uiuc.edu</a>]
<b>On Behalf Of </b>Yaron Keren<br>
<b>Sent:</b> Wednesday, October 09, 2013 10:22 AM<br>
<b>To:</b> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<b>Subject:</b> [PATCH]Unload EH frames in ~MCJIT<u></u><u></u></span></p><div class="im">
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Module loaded with MCJIT register its EH frames with __register_frame to the runtime library. After MCJIT destructs and the module unloaded,  the runtime stays with invalid frames of the module, leading to faulty EH behaviour next time.<u></u><u></u></p>


</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">This patch calls __deregister_frame upon MCJIT destruction to keep proper runtime library EH state.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Yaron<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div></div>
</div>

</blockquote></div><br></div>