[GHC] #14669: Executable finishing via unhandled exception results in segmentation fault on 32 bit Windows

GHC ghc-devs at haskell.org
Sun Jan 14 15:45:30 UTC 2018


#14669: Executable finishing via unhandled exception results in segmentation fault
on 32 bit Windows
--------------------------------------+----------------------------------
           Reporter:  sergv           |             Owner:  (none)
               Type:  bug             |            Status:  new
           Priority:  normal          |         Milestone:
          Component:  Runtime System  |           Version:  8.2.1
           Keywords:                  |  Operating System:  Windows
       Architecture:  x86             |   Type of failure:  Runtime crash
          Test Case:                  |        Blocked By:
           Blocking:                  |   Related Tickets:
Differential Rev(s):                  |         Wiki Page:
--------------------------------------+----------------------------------
 It seems that 32 bit Windows GHC version 8.2.1 onwards (I can reproduce it
 with 8.2.1, 8.2.2 and 8.4.1-alpha, but not with 8.0.2) has some issues in
 Runtime System related to exception handling. The symptom is that
 executable exiting via unhandled exception ends with a segmentation fault
 and non-zero exit code. It would be okay-ish if not for the fact that this
 bug causes tools like `ghc-pkg` or `hsc2hs` to exit with non-zero exit
 code when asked for their `--version`. In turn, this breaks cabal-the-
 executable which interprets non-zero exit code of the `--version` call as
 a failure and refuses to `configure` further.

 Why do those executables segfault when invoked with `--version`? It's
 because they call `exitSuccess` after printing a version, which throws an
 `ExitSuccess` exception. Thus executables exit with unhandled exception
 and this bit seems to be faulty. Please see minimalistic example below:

 {{{
 $ cat HW.hs
 import System.Exit

 main :: IO ()
 main = do
   putStrLn "Situation normal"
   exitWith ExitSuccess
 $ ghc HW.hs
 [1 of 1] Compiling Main             ( HW.hs, HW.o )
 Linking HW.exe ...
  ./HW.exe
 Situation normal
 Segmentation fault
 $ echo $?
 139
 }}}

 If exception is caught then everything's ok. But then it's hard to signal
 non-zero exit code:
 {{{
 $ cat HWCatch.hs
 {-# LANGUAGE ScopedTypeVariables #-}

 import Control.Exception
 import System.Exit

 main :: IO ()
 main = do
   (res :: Either SomeException ()) <- try $ do
     putStrLn "Situation normal"
     exitWith ExitSuccess
   print res
 $ ghc HWCatch.hs
 [1 of 1] Compiling Main             ( HWCatch.hs, HWCatch.o )
 Linking HWCatch.exe ...
 $ ./HWCatch.exe
 Situation normal
 Left ExitSuccess
 $ echo $?
 0
 }}}

 System info:
 {{{
 $ uname -a
 MINGW64_NT-6.1 box 2.9.0(0.318/5/3) 2017-09-13 23:16 x86_64 Msys
 $ ghc --version
 The Glorious Glasgow Haskell Compilation System, version 8.2.2
 $ ghc --info
  [("Project name","The Glorious Glasgow Haskell Compilation System")
  ,("GCC extra via C opts"," -fwrapv -fno-builtin")
  ,("C compiler command","$topdir/../mingw/bin/gcc.exe")
  ,("C compiler flags"," -U__i686 -march=i686 -fno-stack-protector")
  ,("C compiler link flags"," ")
  ,("C compiler supports -no-pie","YES")
  ,("Haskell CPP command","$topdir/../mingw/bin/gcc.exe")
  ,("Haskell CPP flags","-E -undef -traditional")
  ,("ld command","$topdir/../mingw/bin/ld.exe")
  ,("ld flags","")
  ,("ld supports compact unwind","YES")
  ,("ld supports build-id","YES")
  ,("ld supports filelist","NO")
  ,("ld is GNU ld","YES")
  ,("ar command","$topdir/../mingw/bin/ar.exe")
  ,("ar flags","q")
  ,("ar supports at file","YES")
  ,("touch command","$topdir/bin/touchy.exe")
  ,("dllwrap command","$topdir/../mingw/bin/dllwrap.exe")
  ,("windres command","$topdir/../mingw/bin/windres.exe")
  ,("libtool command","")
  ,("perl command","$topdir/../perl/perl.exe")
  ,("cross compiling","NO")
  ,("target os","OSMinGW32")
  ,("target arch","ArchX86")
  ,("target word size","4")
  ,("target has GNU nonexec stack","False")
  ,("target has .ident directive","True")
  ,("target has subsections via symbols","False")
  ,("target has RTS linker","YES")
  ,("Unregisterised","NO")
  ,("LLVM llc command","llc")
  ,("LLVM opt command","opt")
  ,("Project version","8.2.2")
  ,("Project Git commit id","0156a3d815b784510a980621fdcb9c5b23826f1e")
  ,("Booter version","8.2.1")
  ,("Stage","2")
  ,("Build platform","i386-unknown-mingw32")
  ,("Host platform","i386-unknown-mingw32")
  ,("Target platform","i386-unknown-mingw32")
  ,("Have interpreter","YES")
  ,("Object splitting supported","YES")
  ,("Have native code generator","YES")
  ,("Support SMP","YES")
  ,("Tables next to code","YES")
  ,("RTS ways","l debug thr thr_debug thr_l thr_p ")
  ,("RTS expects libdw","NO")
  ,("Support dynamic-too","NO")
  ,("Support parallel --make","YES")
  ,("Support reexported-modules","YES")
  ,("Support thinning and renaming package flags","YES")
  ,("Support Backpack","YES")
  ,("Requires unified installed package IDs","YES")
  ,("Uses package keys","YES")
  ,("Uses unit IDs","YES")
  ,("Dynamic by default","NO")
  ,("GHC Dynamic","NO")
  ,("GHC Profiled","NO")
  ,("Leading underscore","YES")
  ,("Debug on","False")
  ,("LibDir","C:\\home\\ghc\\ghc-8.2.2-x32\\lib")
  ,("Global Package
 DB","C:\\home\\ghc\\ghc-8.2.2-x32\\lib\\package.conf.d")
  ]
 $ ghc-pkg --version # This is a sign of the problem
 GHC package manager version 8.2.2
 Segmentation fault
 $ echo $?
 139
 }}}

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


More information about the ghc-tickets mailing list