[GHC] #7072: GHC interpreter does not find stat64 symbol on Linux

GHC cvs-ghc at haskell.org
Fri Jul 13 11:22:56 CEST 2012


#7072: GHC interpreter does not find stat64 symbol on Linux
------------------------+---------------------------------------------------
 Reporter:  snoyberg    |          Owner:                
     Type:  bug         |         Status:  new           
 Priority:  normal      |      Component:  GHCi          
  Version:  7.4.2       |       Keywords:                
       Os:  Linux       |   Architecture:  x86_64 (amd64)
  Failure:  GHCi crash  |       Testcase:                
Blockedby:              |       Blocking:                
  Related:              |  
------------------------+---------------------------------------------------
 Mailing list discussion available at: [http://www.haskell.org/pipermail
 /haskell-cafe/2012-July/102253.html]. The issue is that, when using runghc
 against a library using the sqlite3 C library (persistent-sqlite), the
 stat64 symbol is not resolved. After some research, I came up with the
 following minimal reproducing 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);
         printf("Done\n");
 }
 }}}

 When using stat directly, gcc inlines the call and produces assembly which
 simply makes a system call, thereby avoiding the need for the stat symbol.
 However, when using a function pointer (as sqlite3 does), the symbol is
 retained, and then runghc does not resolve it.

 In the linked mailing list discussion, Tristan Ravitch found a Stack
 Overflow thread ([http://stackoverflow.com/questions/5478780/c-and-ld-
 preload-open-and-open64-calls-intercepted-but-not-stat64]) which explains
 that the GNU linker has special handling for the stat, stat64, and a few
 other library functions. glibc itself does not provide those symbols
 directly, relying on the linker to fix the references. (I could not find
 reference to this in any official documentation.)

 As a workaround, I declared some local functions which call stat and
 stat64 (patch available at
 [https://github.com/yesodweb/persistent/commit/d7daf0b2fa401fd97ef62e4e74228146d15d8601]).
 So there is a workaround available, and therefore this isn't high priority
 for me. But I do think it's worth some kind of fix.

 Without having a good understanding of the GHC interpreter, my guess would
 be that it needs to replicate the stat/stat64/etc hack that the GNU linker
 is performing. Of course, this guess may be incorrect.

 Tested on Ubuntu 12.04 64-bit, though I believe it will affect any recent
 version of Linux, whether 32- or 64-bit.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7072>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list