<div dir="ltr"><br><br><div class="gmail_quote">On Thu, Jul 12, 2012 at 7:30 PM, Tristan Ravitch <span dir="ltr">&lt;<a href="mailto:travitch@cs.wisc.edu" target="_blank">travitch@cs.wisc.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="HOEnZb"><div class="h5">On Thu, Jul 12, 2012 at 07:20:39PM +0300, Michael Snoyman wrote:<br>
&gt; On Jul 12, 2012 7:13 PM, &quot;Tristan Ravitch&quot; &lt;<a href="mailto:travitch@cs.wisc.edu">travitch@cs.wisc.edu</a>&gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt; On Thu, Jul 12, 2012 at 11:07:05AM -0500, Tristan Ravitch wrote:<br>
&gt; &gt; &gt; Are you trying this on a 32 bit system?  And when you compiled that C<br>
&gt; &gt; &gt; program, did you try to add<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;   -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; to the compile command?  When I define those the resulting object file<br>
&gt; &gt; &gt; from your example correctly references stat64 instead of stat.<br>
&gt; &gt;<br>
&gt; &gt; Er sorry, saw your earlier email now.  Could this be a mismatch<br>
&gt; &gt; between how your sqlite.so is compiled and how the cbits in<br>
&gt; &gt; persistent-sqlite are compiled, particularly with largefile support?<br>
&gt;<br>
&gt; I don&#39;t think so. The test case I put together had nothing to do with<br>
&gt; sqlite. Also, persistent-sqlite will either use sqlite.so _or_ the included<br>
&gt; sqlite3.c file (based on a compile-time flag). The former works perfectly,<br>
&gt; only the latter causes problems.<br>
&gt;<br>
&gt; Michael<br>
<br>
</div></div>I was looking at the symbols in libc and noticed that it doesn&#39;t<br>
actually export stat64/stat, so that would explain something at least.<br>
I think your idea about the switch to function pointers versus direct<br>
calls is probably right - the linker probably does some rewriting of<br>
calls to stat into __fxstat and company, but for some reason doesn&#39;t<br>
handle references to function pointers.<br>
<br>
I also ran across this stackoverflow post that mentions something<br>
similar:<br>
<br>
  <a href="http://stackoverflow.com/questions/5478780/c-and-ld-preload-open-and-open64-calls-intercepted-but-not-stat64" target="_blank">http://stackoverflow.com/questions/5478780/c-and-ld-preload-open-and-open64-calls-intercepted-but-not-stat64</a><br>


<br>
So stat64 is actually special and in this libc_nonshared.a library (it<br>
is on my system at least).  It would be ugly to have to link that<br>
manually - not sure what the right answer is, but at least this might<br>
explain it.<br>
</blockquote></div><br><div>That&#39;s a great find, and it really explains a lot. It seems then that:</div><div><br></div><div>* GNU ld has some black magic do know about the stat/stat64 hack.</div><div>* Compiling via GHC just uses GNU ld, which is able to make the hack work.</div>

<div>* Interpreting with GHC doesn&#39;t get to take advantage of GNU ld&#39;s hack.</div><div><br></div><div>I&#39;ve opened a trac ticket[1] for this issue, thank you very much for the help!</div><div><br></div><div>Michael</div>

<div><br></div><div>[1] <a href="http://hackage.haskell.org/trac/ghc/ticket/7072">http://hackage.haskell.org/trac/ghc/ticket/7072</a></div></div>