<div dir="ltr"><br><br><div class="gmail_quote">On Thu, Jul 12, 2012 at 7:07 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 06:29:41PM +0300, Michael Snoyman wrote:<br>
&gt; I&#39;ve come up with a minimal example that demonstrates this problem. The<br>
&gt; crux of the matter is the following C code:<br>
&gt;<br>
&gt;     #include &lt;sys/types.h&gt;<br>
&gt;     #include &lt;sys/stat.h&gt;<br>
&gt;     #include &lt;unistd.h&gt;<br>
&gt;     #include &lt;stdio.h&gt;<br>
&gt;<br>
&gt;     typedef int stat_func(const char*, struct stat*);<br>
&gt;<br>
&gt;     stat_func *foo = &amp;stat;<br>
&gt;<br>
&gt;     void stat_test(void)<br>
&gt;     {<br>
&gt;     struct stat buf;<br>
&gt;<br>
&gt;     printf(&quot;About to stat-test.c\n&quot;);<br>
&gt;     foo(&quot;stat-test.c&quot;, &amp;buf);<br>
&gt;     printf(&quot;Done\n&quot;);<br>
&gt;     }<br>
&gt;<br>
&gt; As you can see, all of the include statements are present as necessary. The<br>
&gt; code compiles just fine with -Wall -Werror. And when you compile the<br>
&gt; Haskell code as well, everything works just fine. But if you follow these<br>
&gt; steps, you can reproduce the error I saw:<br>
&gt;<br>
&gt; * Unpack the attached tarball<br>
&gt; * `cabal install` in that folder<br>
&gt; * `runghc main.hs` from the `exe` folder<br>
&gt;<br>
&gt; On my system at least, I get:<br>
&gt;<br>
&gt;     main.hs:<br>
&gt; /home/ubuntu/.cabal/lib/stat-test-0.1.0.0/ghc-7.4.1/HSstat-test-0.1.0.0.o:<br>
&gt; unknown symbol `stat&#39;<br>
&gt;     main.hs: main.hs: unable to load package `stat-test-0.1.0.0&#39;<br>
&gt;<br>
&gt; One thing I noticed is that I needed to use a function pointer to trigger<br>
&gt; the bug. When I called `stat` directly the in stat_test function, gcc<br>
&gt; automatically inlined the call, so that the disassessmbled code just showed<br>
&gt; a `moveq` (i.e., it&#39;s making the system call directly). But using a<br>
&gt; function pointer, we&#39;re avoiding the inlining. I believe this is why this<br>
&gt; issue only came up with the sqlite3 upgrade: previous versions did not use<br>
&gt; a function pointer, but rather hard-coded in how to make a stat call.<br>
&gt;<br>
&gt; Does this expose any other possibilities?<br>
&gt;<br>
&gt; Michael<br>
<br>
</div></div>Are you trying this on a 32 bit system?  And when you compiled that C<br>
program, did you try to add<br>
<br>
  -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE<br>
<br>
to the compile command?  When I define those the resulting object file<br>
from your example correctly references stat64 instead of stat.<br>
</blockquote></div><br><div>I&#39;m compiling on a 64 bit system. If I add those definitions, the program uses stat64 instead, but the only difference is that runghc now prints:</div><div><br></div><div><div>    main.hs: /home/ubuntu/.cabal/lib/stat-test-0.1.0.0/ghc-7.4.1/HSstat-test-0.1.0.0.o: unknown symbol `stat64&#39;</div>

<div>    main.hs: main.hs: unable to load package `stat-test-0.1.0.0&#39;</div></div><div><br></div><div>In other words, it&#39;s not the symbol that the object file is referencing (stat vs stat64) that&#39;s the problem: runghc is not able to resolve either one.</div>

<div><br></div><div>Michael</div></div>