[GHC] #9130: Segmentation fault in ThreadPaused.c:223 when compiled with -O

GHC ghc-devs at haskell.org
Tue May 20 14:22:49 UTC 2014


#9130: Segmentation fault in ThreadPaused.c:223 when compiled with -O
----------------------------------+----------------------------------
       Reporter:  twi             |             Owner:  simonmar
           Type:  bug             |            Status:  new
       Priority:  high            |         Milestone:
      Component:  Runtime System  |           Version:  7.8.2
       Keywords:                  |  Operating System:  Linux
   Architecture:  x86_64 (amd64)  |   Type of failure:  Runtime crash
     Difficulty:  Unknown         |         Test Case:
     Blocked By:                  |          Blocking:
Related Tickets:                  |
----------------------------------+----------------------------------
 Compiling the following program with

 {{{ghc --make -fforce-recomp -O Tests}}}

 gives me a segmentation fault when running the resulting executable
 whereas without {{{-O}}} it runs to completion.

 {{{
 module Main where

 import Control.Concurrent.Async

 main :: IO ()
 main = test 100

 test :: Int -> IO ()
 test s = do
     mapM_ wait =<< mapM b [0 .. s]
   where
     b _ = async $ return ()
 }}}

 valgrind and gdb indicate that an invalid read in threadPaused is causing
 this:

 {{{
 $ valgrind ./Tests
 ==17550== Memcheck, a memory error detector
 ==17550== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
 ==17550== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright
 info
 ==17550== Command: ./Tests
 ==17550==
 ==17550== Invalid read of size 4
 ==17550==    at 0x46C2BE: threadPaused (ThreadPaused.c:223)
 ==17550==    by 0x48FC72: stg_returnToSched (in /tmp/xxx/Tests)
 ==17550==  Address 0x1f is not stack'd, malloc'd or (recently) free'd
 ==17550==
 ==17550==
 ==17550== Process terminating with default action of signal 11 (SIGSEGV)
 ==17550==  Access not within mapped region at address 0x1F
 ==17550==    at 0x46C2BE: threadPaused (ThreadPaused.c:223)
 ==17550==    by 0x48FC72: stg_returnToSched (in /tmp/xxx/Tests)
 ==17550==  If you believe this happened as a result of a stack
 ==17550==  overflow in your program's main thread (unlikely but
 ==17550==  possible), you can try to increase the size of the
 ==17550==  main thread stack using the --main-stacksize= flag.
 ==17550==  The main thread stack size used in this run was 8388608.
 ==17550==
 ==17550== HEAP SUMMARY:
 ==17550==     in use at exit: 76,884 bytes in 34 blocks
 ==17550==   total heap usage: 53 allocs, 19 frees, 81,122 bytes allocated
 ==17550==
 ==17550== LEAK SUMMARY:
 ==17550==    definitely lost: 0 bytes in 0 blocks
 ==17550==    indirectly lost: 0 bytes in 0 blocks
 ==17550==      possibly lost: 0 bytes in 0 blocks
 ==17550==    still reachable: 76,884 bytes in 34 blocks
 ==17550==         suppressed: 0 bytes in 0 blocks
 ==17550== Rerun with --leak-check=full to see details of leaked memory
 ==17550==
 ==17550== For counts of detected and suppressed errors, rerun with: -v
 ==17550== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 3)
 Segmentation fault (core dumped)
 }}}

 {{{
 (gdb) run
 Starting program: /tmp/xxx/Tests
 warning: Could not load shared library symbols for linux-vdso.so.1.
 Do you need "set solib-search-path" or "set sysroot"?
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library "/usr/lib/libthread_db.so.1".

 Program received signal SIGSEGV, Segmentation fault.
 0x000000000046c2be in threadPaused (cap=0x6f5dc0 <MainCapability>,
 tso=0x7ffff6b05390) at rts/ThreadPaused.c:223
 223             switch (info->i.type) {
 (gdb) info locals
 frame = 0x7ffff6b050f0
 info = 0xf
 bh_info = 0x4779fe <appendToRunQueue+155>
 bh = 0x7ffff6b10790
 stack_end = 0x7ffff6b05390
 words_to_squeeze = 0
 weight = 0
 weight_pending = 9
 prev_was_update_frame = rtsFalse
 }}}

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


More information about the ghc-tickets mailing list