<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
 /* List Definitions */
 @list l0
        {mso-list-id:447630503;
        mso-list-type:hybrid;
        mso-list-template-ids:-403900276 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1
        {mso-list-id:1536119802;
        mso-list-type:hybrid;
        mso-list-template-ids:-1106182392 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
        {mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Hola LLVMers,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I’m having a tricky time diagnosing something that is
going on in my program and am hoping some of you might have used LLVM in a
similar way before.  All of this is using LLVM 1.9 on Mac OSX.  Here
is our usage pattern:<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<ol style='margin-top:0in' start=1 type=1>
 <li class=MsoNormal style='mso-list:l0 level1 lfo1'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Read in a program in a language
     we are designing<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l0 level1 lfo1'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Transform it into LLVM IR using
     the llvm class hierarchy<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l0 level1 lfo1'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Link this module to a set of
     support functions written offline in C and compiled using the llvm
     compiler into LLVM IR bytecode<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l0 level1 lfo1'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Construct a JIT execution
     environment for X86<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l0 level1 lfo1'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Run the function<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l0 level1 lfo1'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Destroy the execution
     environment, module, linker, etc.  Note this doesn’t destroy
     all LLVM state as there are some things static to classes such as the
     machine code emitters.<o:p></o:p></span></font></li>
</ol>

<p class=MsoNormal style='margin-left:.25in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Under the hood, the JIT callbacks are occurring and are
doing the native compilation on the necessary support functions from the
read-in bytecode.  The first few times this process is done, everything
works fine.  Repeating this process for the same program and
support-function combination resulted in crashing on the second iteration. 
Stepping through the program got me as far as having it<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<ol style='margin-top:0in' start=1 type=1>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Run through the whole process
     as described above with correct results<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>In iteration #32, compile the
     primary function I want to run<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Compiling the stub function to
     turn my primary function into a null-ary function<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Getting to the X86 JIT callback<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Compiling the first support
     function via JITter<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Entry into the first support
     function<o:p></o:p></span></font></li>
 <li class=MsoNormal style='mso-list:l1 level1 lfo2'><font size=2 face=Arial><span
     style='font-size:10.0pt;font-family:Arial'>Crashing somewhere before
     getting back to the next callback.  Specifically we get a “Program
     received signal: ‘EXC_BAD_ACCESS’” message and then
     loose all stack info.  It won’t break on the offending
     instruction, only after the game is already lost.<o:p></o:p></span></font></li>
</ol>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Unfortunately, XCode is fairly uninformative when you step
into code you’ve just created, so you have to go on memory dumps,
watching the registers, and doing the disassembly in your head.  Once it
calls back into the callbacks its brain resets and gives you a real debugging
environment again.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I realize this description isn’t effective as a
repro-case, but I’m dealing with a fairly large system and before I go
about hacking things apart to try and construct one I was hoping that some of
you may have had experience with this kind of thing.  What tools do you
all use to deal with crashes like these?  Is there a more robust
alternative than XCode for dealing with low level debugging with on-the-fly
generated code?  Have many changes occurred between 1.9 in this area that
I should just abandon 1.9 in favor of the CVS sources?<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Any help is greatly appreciated.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Thanks,<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Chuck.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal style='margin-left:.25in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>

</div>

</body>

</html>