[Haskell-cafe] ghci and TH cannot: unknown symbol `stat64`
michael at snoyman.com
Thu Jul 12 17:44:31 CEST 2012
On Thu, Jul 12, 2012 at 6:29 PM, Michael Snoyman <michael at snoyman.com>wrote:
> On Wed, Jul 11, 2012 at 9:55 PM, Bardur Arantsson <spam at scientician.net>wrote:
>> On 07/11/2012 05:12 PM, Michael Snoyman wrote:
>> > Thanks for the feedback. However, looking at sqlite3.c, I see the
>> > necessary #include statements:
>> > #include <sys/types.h>
>> > #include <sys/stat.h>
>> > #include <unistd.h>
>> > I'm confident that none of my code is making calls to stat/stat64 via
>> > the FFI. In case it makes a difference, this problem also disappears
>> > if I compile the library against the system copy of sqlite3 instead of
>> > using the C source.
>> You may need some extra defines, see the comments in "man stat64".
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
> I've come up with a minimal example that demonstrates this problem. The
> crux of the matter is the following C code:
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <unistd.h>
> #include <stdio.h>
> typedef int stat_func(const char*, struct stat*);
> stat_func *foo = &stat;
> void stat_test(void)
> struct stat buf;
> printf("About to stat-test.c\n");
> foo("stat-test.c", &buf);
> 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:
> * Unpack the attached tarball
> * `cabal install` in that folder
> * `runghc main.hs` from the `exe` folder
> On my system at least, I get:
> unknown symbol `stat'
> main.hs: main.hs: unable to load package `stat-test-0.1.0.0'
> 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's making the system call directly). But using a
> function pointer, we'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.
> Does this expose any other possibilities?
Actually, I just came up with a workaround: declare some local wrappers to
the stat and fstat functions, and use those in place of stat and fstat in
the rest of the code. You can see the change here.
Obviously this is a hack, not a real fix. At this point it looks like a GHC
bug to me. Does anything think otherwise? If not, I'll open a ticket.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe