[GHC] #8371: ghci byte compiler + FFI crashes when used with embedded R

#8371: ghci byte compiler + FFI crashes when used with embedded R ----------------------------------+------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Keywords: | Operating System: Linux Architecture: x86_64 (amd64) | Type of failure: GHCi crash Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ----------------------------------+------------------------------- The ghci interpreter destroys the C stack when initializing embedded R (the statistical software system available at http://cran.r-project.org/). There is no problem using embedded R with ghc (compiled code). I have had no problems using ghci with other FFI projects, and this does not appear to be a linking problem (there are no undefined references). To reproduce the problem (under Fedora Linux using ghc 7.6.3) download the R source code, unpack, and (using haskellRtest.hs is attached): 0. cd R-3.0.2 1. ./configure --enable-R-shlib 2. make 3. make install 4. cd <haskelltestdir> 5. ghci -L/usr/local/lib64/R/lib -lR haskellRtest.hs 6. Main> main Loading... Initialize R session... Error: C stack usage is too close to the limit Notes: 1. No computations are done, the failure happens during startup. 2. The C functions called are in <R source>/src/unix/Rembedded.c 3. The error message is issued from <R source>/src/main/errors.c 4. I tried increasing the system level C stack size limit but this didn't help. 5. As noted above, there are no problems when ghc is used. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Comment (by rwbarton): Does it work when you compile with the threaded runtime, like ghci uses? (`ghc -threaded haskellRtest.hs -L/usr/local/lib64/R/lib -lR` should do it) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Comment (by dsamperi): It works with the command line you provide here, but as I noted in the report there are no problems when ghc is used. When I try to use -threaded with ghci I get the warning "-debug, -threaded and -ticky are ignored by GHCi". -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Comment (by dsamperi): This is just a stab in the dark, but while reviewing the docs on FFI I discovered that it is assumed ints can be used for 64-bit addressing, that is, the difference between two pointer values can be stored in an int. But under Windows this is not so (32-bit ints), and I think R also employs 32-bit ints. If this is the source of the problem then it should show up in both ghc and ghci, but it does not. Again, just a stab in the dark... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Comment (by carter): Have you tried testing to see if the problem also happens with ghc head ? Ghci prior to 7.7 has it's own custom linker and is the culprit behind many ghci specific bugs. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Comment (by dsamperi): Thanks for the suggestion. I tried to build from HEAD but it requires Happy 1.19, and only version 1.18 would install (due to a global constraint?). So I used the lazy method of downloading a pre-built binary for Linux from http://darcs.haskell.org/ghcBuilder/uploads/igloo-m/, specifically, I installed from ghc-7.7.20130720-x86_64-unknown-linux.tar.bz2. Unfortunately, this did not resolve the problem, as I still get the C stack usage Error. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R
-------------------------------+----------------------------------
Reporter: dsamperi | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHCi | Version: 7.6.3
Resolution: | Keywords:
Operating System: Linux | Architecture: x86_64 (amd64)
Type of failure: GHCi crash | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------+----------------------------------
Comment (by rwbarton):
I can reproduce this without ghci, by putting a forkIO around the body of
main (and adding a threadDelay in the main thread).
It seems to just be an interaction between R's method for determining the
base address of the stack and the way pthread allocates stacks for new
threads. Try this C example program `pt.c`.
{{{
#include

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Comment (by dsamperi): I accidentally replied to you in gmail (sent to ghc-devs) instead of in this comment thread, sorry! Your comment combined with the suggestion that I use ghc-7.7 provides a work-around. I tried disabling R's stack limit checks, but this leads to a segfault. A correct workaround is to use the flag -fno-ghci-sandbox, as this prevents ghci from forking a thread (all computations are run in the main thread). As noted previously R is not thread-safe. This eliminates the "C stack usage" error messages, but there is still a segfault when ghc-7.6.3 is used (and a non-trivial computation is done). Using ghc-7.7 fixes this. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8371: ghci byte compiler + FFI crashes when used with embedded R -------------------------------+---------------------------------- Reporter: dsamperi | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: invalid | Keywords: Operating System: Linux | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------+---------------------------------- Changes (by rwbarton): * status: new => closed * resolution: => invalid Comment: Great, glad you were able to get it working! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8371#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC