Ticket #6146 (closed bug: fixed)

Opened 12 months ago

Last modified 10 months ago

Segmentation fault with eager blackholing

Reported by: emcdowell Owned by: simonmar
Priority: high Milestone: 7.4.3
Component: Runtime System Version: 7.4.1
Keywords: eager blackholing Cc:
Operating System: Windows Architecture: x86
Type of failure: Runtime crash Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

When very simple programs are compiled using the -feager-blackholing and -threaded flags in GHC 7.4.1 on Windows 7 and XP a segmentation fault frequently occurs during execution. This happens in programs that read a line from the keyboard and print a response. The problem occurs running the executable file directly, through ghci, and through runghc.

The problem is resolved by compiling without the -feager-blackholing flag.

Attachments

Main.hs Download (260 bytes) - added by emcdowell 12 months ago.
Main.hs
Main.2.hs Download (1.5 KB) - added by emcdowell 12 months ago.
Pi.hs

Change History

Changed 12 months ago by emcdowell

In trying to reproduce this I got different erroneous behavior. When entering small input values the code behaves as expected. When entering larger values, part of the output is truncated. The following problem is easily reproduced on Windows XP.

H:\user\haskell\Test>type Main.hs
module Main (main) where

main :: IO ()
main = do
    putStrLn "First number?  "
    num1 <- readLn :: IO Int
    putStrLn "Second number? "
    num2 <- readLn :: IO Int
    let total = num1 + num2
    putStrLn $ "The sum is " ++ (show total) ++ "."

H:\user\haskell\Test>ghc -feager-blackholing -threaded --make Main.hs
[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main.exe ...

H:\user\haskell\Test>main +RTS -N
First number?
2
Second number?
3
The sum is 5.

H:\user\haskell\Test>main +RTS -N
First number?
2000000
Second number?
3000000
5000000.

Changed 12 months ago by emcdowell

Main.hs

Changed 12 months ago by emcdowell

Pi.hs

Changed 12 months ago by emcdowell

I have attached the original program where I encountered the problem. You should be able to reproduce this.

H:\user\haskell\Pi>ghc -threaded -feager-blackholing --make Pi.hs
[1 of 1] Compiling Main             ( Pi.hs, Pi.o )
Linking Pi.exe ...

H:\user\haskell\Pi>Pi.exe +RTS -N
Terms?  1000
Tasks?  2
3.141603544913

H:\user\haskell\Pi>Pi.exe +RTS -N
Terms?  10000000
Segmentation fault/access violation in generated code

H:\user\haskell\Pi>ghc -threaded --make Pi.hs

H:\user\haskell\Pi>erase Pi.o

H:\user\haskell\Pi>erase Pi.hi

H:\user\haskell\Pi>erase Pi.exe

H:\user\haskell\Pi>ghc -threaded --make Pi.hs
[1 of 1] Compiling Main             ( Pi.hs, Pi.o )
Linking Pi.exe ...

H:\user\haskell\Pi>Pi.exe +RTS -N
Terms?  10000000
Tasks?  2
3.141592653601

H:\user\haskell\Pi>

Changed 12 months ago by simonmar

  • owner set to simonmar
  • difficulty set to Unknown
  • priority changed from normal to high
  • component changed from Compiler to Runtime System
  • milestone set to 7.4.2

Changed 12 months ago by marlowsd@…

commit 21a53a1cd5a9784aca7b78cc972f917e71938124

Author: Simon Marlow <marlowsd@gmail.com>
Date:   Thu Jun 7 15:45:32 2012 +0100

    Fix for earger blackholing of thunks with no free variables (#6146)
    
    A thunk with no free variables was not getting blackholed when
    -feager-blackholing was on, but we were nevertheless pushing the
    stg_bh_upd_frame version of the update frame that expects to see a
    black hole.
    
    I fixed this twice for good measure:
    
     - we now call blackHoleOnEntry when pushing the update frame to check
       whether the closure was actually blackholed, and so that we use the
       same predicate in both places
    
     - we now black hole thunks even if they have no free variables.
       These only occur when optimisation is off, but presumably if you say
       -feager-blackholing then that's what you want to happen.

 compiler/codeGen/CgClosure.lhs    |    7 ++++---
 compiler/codeGen/ClosureInfo.lhs  |    2 +-
 compiler/codeGen/StgCmmBind.hs    |   17 ++++++++++-------
 compiler/codeGen/StgCmmClosure.hs |    2 +-
 4 files changed, 16 insertions(+), 12 deletions(-)

Changed 12 months ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

Thanks, nice bug.

Changed 12 months ago by simonmar

  • status changed from closed to merge

duh, keep forgetting to set these to merge, sorry for the spam.

Changed 12 months ago by pcapriotti

  • status changed from merge to closed

Merged as 3b9d1750b6823dfc9f2d1fb7ff883b81bf746c33.

Changed 10 months ago by simonmar

  • milestone changed from 7.4.2 to 7.4.3
Note: See TracTickets for help on using tickets.