<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Jul 11, 2012 at 9:55 PM, Bardur Arantsson <span dir="ltr">&lt;<a href="mailto:spam@scientician.net" target="_blank">spam@scientician.net</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="im">On 07/11/2012 05:12 PM, Michael Snoyman wrote:<br>
&gt;<br>
&gt; Thanks for the feedback. However, looking at sqlite3.c, I see the<br>
&gt; necessary #include statements:<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;<br>
&gt; I&#39;m confident that none of my code is making calls to stat/stat64 via<br>
&gt; the FFI. In case it makes a difference, this problem also disappears<br>
&gt; if I compile the library against the system copy of sqlite3 instead of<br>
&gt; using the C source.<br>
<br>
</div>You may need some extra defines, see the comments in &quot;man stat64&quot;.<br>
<br>
Regards,<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br><div>I&#39;ve come up with a minimal example that demonstrates this problem. The crux of the matter is the following C code:</div><div><br></div><div><div>    #include &lt;sys/types.h&gt;</div><div>

    #include &lt;sys/stat.h&gt;</div><div>    #include &lt;unistd.h&gt;</div><div>    #include &lt;stdio.h&gt;</div><div>    </div><div>    typedef int stat_func(const char*, struct stat*);</div><div>    </div><div>    stat_func *foo = &amp;stat;</div>

<div>    </div><div>    void stat_test(void)</div><div>    {</div><div>    <span class="Apple-tab-span" style="white-space:pre">        </span>struct stat buf;</div><div>    </div><div>    <span class="Apple-tab-span" style="white-space:pre">        </span>printf(&quot;About to stat-test.c\n&quot;);</div>

<div>    <span class="Apple-tab-span" style="white-space:pre">        </span>foo(&quot;stat-test.c&quot;, &amp;buf);</div><div>    <span class="Apple-tab-span" style="white-space:pre">        </span>printf(&quot;Done\n&quot;);</div><div>

    }</div></div><div><br></div><div>As you can see, all of the include statements are present as necessary. The code compiles just fine with -Wall -Werror. And when you compile the Haskell code as well, everything works just fine. But if you follow these steps, you can reproduce the error I saw:</div>

<div><br></div><div>* Unpack the attached tarball</div><div>* `cabal install` in that folder</div><div>* `runghc main.hs` from the `exe` folder</div><div><br></div><div>On my system at least, I get:</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 `stat&#39;</div><div>    main.hs: main.hs: unable to load package `stat-test-0.1.0.0&#39;</div></div><div><br></div>

<div>One thing I noticed is that I needed to use a function pointer to trigger the bug. When I called `stat` directly the in stat_test function, gcc automatically inlined the call, so that the disassessmbled code just showed a `moveq` (i.e., it&#39;s making the system call directly). But using a function pointer, we&#39;re avoiding the inlining. I believe this is why this issue only came up with the sqlite3 upgrade: previous versions did not use a function pointer, but rather hard-coded in how to make a stat call.</div>

<div><br></div><div>Does this expose any other possibilities?</div><div><br></div><div>Michael</div></div>