atMost in GHC.Event.PSQ causes seqfault or bus error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

atMost in GHC.Event.PSQ causes seqfault or bus error

Kazu Yamamoto (山本和彦)
Hi,

threadDelay of GHC head causes seqfault or bus error on 32bit machine
including Mac and Linux. This bug does not exist as least in GHC
7.4.2.

This bug is due to atMost of GHC.Event.PSQ. After modifying
libraries/base/base.cabal to export GHC.Event and building GHC head,
the following code (compiled by the GHC head with -threaded) causes
segfault or bus error:

main :: IO ()
main = do
    s <- newSource
    ents <- replicateM 100 (entry s)
    let q = fold ents
    print $ Q.atMost 1.5 q

fold :: [(Q.Key, Q.Prio)] -> Q.PSQ ()
fold [] = Q.empty
fold ((u,r):xs) = Q.insert u r () $ fold xs

entry :: UniqueSource -> IO (Q.Key, Q.Prio)
entry s = do
    u <- newUnique s
    r <- randomIO
    return (u,r)

But if I copy GHC.Event.PSQ and GHC.Event.Unique, modify their module
names, and compile the above code with them, no segfault/bus error
happens.

I have been tracking this for a long time but I have no idea why this
happens. Any advice would be highly appreciated.

For more information, please refer to:

        http://hackage.haskell.org/trac/ghc/ticket/7715

--Kazu


Reply | Threaded
Open this post in threaded view
|

atMost in GHC.Event.PSQ causes seqfault or bus error

Kazu Yamamoto (山本和彦)
Hi,

After a long fight, I found that this is a bug of the "-O2" option of
GHC head on 32bit machine. Now, it is easy to reproduce this
segfault. Please read and try this:

        https://github.com/kazu-yamamoto/buggy-psq

Note that this segfault does not occur when "-O' is specified.

--Kazu

> Hi,
>
> threadDelay of GHC head causes seqfault or bus error on 32bit machine
> including Mac and Linux. This bug does not exist as least in GHC
> 7.4.2.
>
> This bug is due to atMost of GHC.Event.PSQ. After modifying
> libraries/base/base.cabal to export GHC.Event and building GHC head,
> the following code (compiled by the GHC head with -threaded) causes
> segfault or bus error:
>
> main :: IO ()
> main = do
>     s <- newSource
>     ents <- replicateM 100 (entry s)
>     let q = fold ents
>     print $ Q.atMost 1.5 q
>
> fold :: [(Q.Key, Q.Prio)] -> Q.PSQ ()
> fold [] = Q.empty
> fold ((u,r):xs) = Q.insert u r () $ fold xs
>
> entry :: UniqueSource -> IO (Q.Key, Q.Prio)
> entry s = do
>     u <- newUnique s
>     r <- randomIO
>     return (u,r)
>
> But if I copy GHC.Event.PSQ and GHC.Event.Unique, modify their module
> names, and compile the above code with them, no segfault/bus error
> happens.
>
> I have been tracking this for a long time but I have no idea why this
> happens. Any advice would be highly appreciated.
>
> For more information, please refer to:
>
> http://hackage.haskell.org/trac/ghc/ticket/7715
>
> --Kazu


Reply | Threaded
Open this post in threaded view
|

atMost in GHC.Event.PSQ causes seqfault or bus error

Ian Lynagh-2

Hi Kazu,

On Fri, May 31, 2013 at 03:16:22PM +0900, Kazu Yamamoto wrote:
>
> After a long fight, I found that this is a bug of the "-O2" option of
> GHC head on 32bit machine. Now, it is easy to reproduce this
> segfault. Please read and try this:
>
> https://github.com/kazu-yamamoto/buggy-psq

Great, thanks for your work in boiling this down! I've filed a ticket
for it here:
    http://hackage.haskell.org/trac/ghc/ticket/7953


Thanks
Ian
--
Ian Lynagh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com/