Quantcast

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

classic Classic list List threaded Threaded
2 messages Options
GHC
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

GHC
#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

_______________________________________________
Glasgow-haskell-bugs mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
GHC
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

GHC
#7072: GHC interpreter does not find stat64 symbol on Linux
-------------------------------+--------------------------------------------
    Reporter:  snoyberg        |       Owner:            
        Type:  bug             |      Status:  new      
    Priority:  normal          |   Milestone:  7.8.1    
   Component:  GHCi            |     Version:  7.4.2    
    Keywords:                  |          Os:  Linux    
Architecture:  x86_64 (amd64)  |     Failure:  GHCi crash
  Difficulty:  Unknown         |    Testcase:            
   Blockedby:  3658            |    Blocking:            
     Related:                  |  
-------------------------------+--------------------------------------------
Changes (by igloo):

  * difficulty:  => Unknown
  * milestone:  => 7.8.1


Comment:

 Thanks for the report. I get this:
 {{{
 ghc --make Setup
 ./Setup configure
 ./Setup build
 ./Setup register --inplace
 cd exe
 ghci main.hs
 GHCi, version 7.7.20121020: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer-gmp ... linking ... done.
 Loading package base ... linking ... done.
 [1 of 1] Compiling Main             ( main.hs, interpreted )
 Ok, modules loaded: Main.
 *Main> main
 Loading package stat-test-0.1.0.0 ... linking ... <interactive>:
 /home/ian/work/ghc/tmp/7072/stat-test-0.1.0.0/dist/build/libHSstat-
 test-0.1.0.0.a: unknown symbol `stat'
 ghc-stage2: unable to load package `stat-test-0.1.0.0'
 *Main>
 }}}
 but with dynamic-by-default:
 {{{
 *Main> main
 Loading package stat-test-0.1.0.0 ... linking ... done.
 About to stat-test.c
 Done
 *Main>
 }}}
 so this will be fixed when we move to dynamic-by-default.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
Loading...