[GHC] #14081: 8.2.1 runghc from Windows x32 segfaults an all programs

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs --------------------------------+---------------------------------- Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | 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: --------------------------------+---------------------------------- I'd like to report pretty severe issue with `runghc` executable from latest `8.2.1` release. Namely, `runghc` does not work at all on x32 Windows - it produces segmentation faults even on hello world program {{{ $ cat HW.hs module HW (main) where main :: IO () main = do putStrLn "Hello, world" $ runghc HW.hs Access violation in generated code when reading 77dbffff }}} I managed to reproduce this issue on 3 mildly different hosts already - two of them were running `Windows 7` and the third one was `Windows Server 2008` or `2012` (I forgot which but can look it up if it's crucial). In all 3 cases I used ghc from `https://downloads.haskell.org/~ghc/8.2.1/ghc-8.2.1-i386-unknown- mingw32.tar.xz`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by bgamari): * priority: normal => highest * milestone: => 8.2.2 Comment: Thanks for your report. This sounds quite bad indeed. I'll try to have a look soon. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by bgamari): * cc: Phyx- (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): I haven't been able to reproduce the segfault yet, but there is a startup issue with the bindist.. A call that's been there since 8.0.2 is failing. But it's gracefully failing for me.. I'll start a build but in the meantime can you perhaps provide a crash dump so I can verify the two issues are related? Instructions on how to are here https://msdn.microsoft.com/en- us/library/windows/desktop/bb787181(v=vs.85).aspx -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): Oh and what environment/shell are you using? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by bgamari): Sadly I've also been unable to reproduce this as well on Windows 10. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): I can reproduce the issue using following shells: 1. x64 msys 2.0 2. x32 git-bash that's bundled with portable-git 1.9.5 3. Not too old cygwin (sorry, don't have it with me right now) I'll try to provide the dump later since just following instructions in https://blogs.msdn.microsoft.com/chaun/2013/11/12/steps-to-catch-a-simple- crash-dump-of-a-crashing-process/ does not produce any dumps for me. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): Does GHC and GHCi work? or do they all segfault? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): It's pretty strange now that I tried all of them: ghc works, compiled executable of HW.hs works but ghci segfaults with same message as runghc. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): Another update: after updating msys 2.0 the crash disappeared in both `runghc` and `ghci`. Even portable-git's `git-bash` now behaves correctly, which is really puzzling. Apparently it's somehow related to dlls that ghc distribution uses. However, the crash is still there if I use `cmd.exe`: {{{ c:\home>ghc\ghc-8.2.1-x32\bin\ghci.exe -v3 -dcore-lint GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Glasgow Haskell Compiler, Version 8.2.1, stage 2 booted by GHC version 8.0.1 Using binary package database: C:\home\ghc\ghc-8.2.1-x32\lib\package.conf.d\pack age.cache package flags [] loading package database C:\home\ghc\ghc-8.2.1-x32\lib\package.conf.d wired-in package ghc-prim mapped to ghc-prim-0.5.1.0 wired-in package integer-gmp mapped to integer-gmp-1.0.1.0 wired-in package base mapped to base-4.10.0.0 wired-in package rts mapped to rts wired-in package template-haskell mapped to template-haskell-2.12.0.0 wired-in package ghc mapped to ghc-8.2.1 wired-in package dph-seq not found. wired-in package dph-par not found. *** Parser [source]: !!! Parser [source]: finished in 0.00 milliseconds, allocated 0.067 megabytes *** Desugar: *** Simplify [expr]: !!! Simplify [expr]: finished in 0.00 milliseconds, allocated 0.051 megabytes *** CorePrep [expr]: !!! CorePrep [expr]: finished in 0.00 milliseconds, allocated 0.857 megabytes *** ByteCodeGen [Ghci1]: !!! ByteCodeGen [Ghci1]: finished in 0.00 milliseconds, allocated 0.067 megabyte s Access violation in generated code when reading 7736ffff }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): Do you have a value for LIBRARY_PATH set? Could you run strace and attach the log? Or filemon. I'm after what ghci is loading. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): I have reset `PATH` to a standard value and `LIBRARY_PATH` is not set at all. Here's output of strace in cygwin: {{{ $ echo $LIBRARY_PATH $ export PATH="/bin/:/usr/bin:/usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem" $ strace ./ghc/ghc-8.2.1-x32/bin/ghci -v3 WARNING: GHCi invoked via 'ghci.exe' in MinTTY consoles (e.g., Cygwin or MSYS) doesn't handle Ctrl-C well; use the 'ghcii.sh' shell wrapper instead GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Glasgow Haskell Compiler, Version 8.2.1, stage 2 booted by GHC version 8.0.1 Using binary package database: C:\home\ghc\ghc-8.2.1-x32\lib\package.conf.d\package.cache package flags [] loading package database C:\home\ghc\ghc-8.2.1-x32\lib\package.conf.d wired-in package ghc-prim mapped to ghc-prim-0.5.1.0 wired-in package integer-gmp mapped to integer-gmp-1.0.1.0 wired-in package base mapped to base-4.10.0.0 wired-in package rts mapped to rts wired-in package template-haskell mapped to template-haskell-2.12.0.0 wired-in package ghc mapped to ghc-8.2.1 wired-in package dph-seq not found. wired-in package dph-par not found. *** Parser [source]: !!! Parser [source]: finished in 0.00 milliseconds, allocated 0.067 megabytes *** Desugar: *** Simplify [expr]: !!! Simplify [expr]: finished in 0.00 milliseconds, allocated 0.055 megabytes *** CorePrep [expr]: !!! CorePrep [expr]: finished in 0.00 milliseconds, allocated 0.857 megabytes *** ByteCodeGen [Ghci1]: !!! ByteCodeGen [Ghci1]: finished in 0.00 milliseconds, allocated 0.070 megabytes Access violation in generated code when reading 77b2ffff --- Process 2564 created --- Process 2564 loaded C:\Windows\SysWOW64\ntdll.dll at 77b20000 --- Process 2564 unloaded DLL at 77820000 --- Process 2564 unloaded DLL at 75b10000 --- Process 2564 unloaded DLL at 77820000 --- Process 2564 unloaded DLL at 77720000 --- Process 2564 loaded C:\Windows\SysWOW64\kernel32.dll at 75b10000 --- Process 2564 loaded C:\Windows\SysWOW64\KernelBase.dll at 77150000 --- Process 2564 loaded C:\Windows\SysWOW64\msvcrt.dll at 77590000 --- Process 2564 loaded C:\Windows\SysWOW64\user32.dll at 759d0000 --- Process 2564 loaded C:\Windows\SysWOW64\gdi32.dll at 774c0000 --- Process 2564 loaded C:\Windows\SysWOW64\lpk.dll at 77580000 --- Process 2564 loaded C:\Windows\SysWOW64\usp10.dll at 76000000 --- Process 2564 loaded C:\Windows\SysWOW64\advapi32.dll at 75e60000 --- Process 2564 loaded C:\Windows\SysWOW64\sechost.dll at 77130000 --- Process 2564 loaded C:\Windows\SysWOW64\rpcrt4.dll at 760a0000 --- Process 2564 loaded C:\Windows\SysWOW64\sspicli.dll at 75620000 --- Process 2564 loaded C:\Windows\SysWOW64\cryptbase.dll at 75610000 --- Process 2564 loaded C:\Windows\SysWOW64\imm32.dll at 757c0000 --- Process 2564 loaded C:\Windows\SysWOW64\msctf.dll at 75820000 --- Process 2564 loaded C:\Windows\SysWOW64\embdtrst.dll at 75130000 --- Process 2564 loaded C:\Windows\SysWOW64\apphelp.dll at 750e0000 --- Process 2972 created --- Process 2972 loaded C:\Windows\SysWOW64\ntdll.dll at 77b20000 --- Process 2972 unloaded DLL at 77820000 --- Process 2972 unloaded DLL at 75b10000 --- Process 2972 unloaded DLL at 77820000 --- Process 2972 unloaded DLL at 77720000 --- Process 2972 loaded C:\Windows\SysWOW64\kernel32.dll at 75b10000 --- Process 2972 loaded C:\Windows\SysWOW64\KernelBase.dll at 77150000 --- Process 2972 loaded C:\Windows\SysWOW64\gdi32.dll at 774c0000 --- Process 2972 loaded C:\Windows\SysWOW64\user32.dll at 759d0000 --- Process 2972 loaded C:\Windows\SysWOW64\advapi32.dll at 75e60000 --- Process 2972 loaded C:\Windows\SysWOW64\msvcrt.dll at 77590000 --- Process 2972 loaded C:\Windows\SysWOW64\sechost.dll at 77130000 --- Process 2972 loaded C:\Windows\SysWOW64\rpcrt4.dll at 760a0000 --- Process 2972 loaded C:\Windows\SysWOW64\sspicli.dll at 75620000 --- Process 2972 loaded C:\Windows\SysWOW64\cryptbase.dll at 75610000 --- Process 2972 loaded C:\Windows\SysWOW64\lpk.dll at 77580000 --- Process 2972 loaded C:\Windows\SysWOW64\usp10.dll at 76000000 --- Process 2972 loaded C:\Windows\SysWOW64\shell32.dll at 76380000 --- Process 2972 loaded C:\Windows\SysWOW64\shlwapi.dll at 75f10000 --- Process 2972 loaded C:\Windows\SysWOW64\wsock32.dll at 74fe0000 --- Process 2972 loaded C:\Windows\SysWOW64\ws2_32.dll at 75df0000 --- Process 2972 loaded C:\Windows\SysWOW64\nsi.dll at 75ad0000 --- Process 2972 loaded C:\Windows\SysWOW64\imm32.dll at 757c0000 --- Process 2972 loaded C:\Windows\SysWOW64\msctf.dll at 75820000 --- Process 2972 thread 2824 created --- Process 2972 thread 3052 created --- Process 2972 thread 3032 created --- Process 2972 thread 2436 created --- Process 2972 loaded C:\Windows\SysWOW64\ole32.dll at 76190000 --- Process 2972 loaded C:\Windows\SysWOW64\profapi.dll at 74ff0000 --- Process 2972 thread 1276 created --- Process 2972, exception c0000005 at 7717ece7 --- Process 2972 thread 2824 exited with status 0x1 --- Process 2972 thread 3032 exited with status 0x1 --- Process 2972 thread 1276 exited with status 0x1 --- Process 2972 thread 3052 exited with status 0x1 --- Process 2972 thread 2436 exited with status 0x1 --- Process 2972 exited with status 0x1 --- Process 2564 exited with status 0x1 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by sergv): * Attachment "ghci.tar.xz" added. Procmon traces of ghci process under cygwin -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): I really can't see anything see anything very suspicious in that log, only that it hasn't loaded any static archives I expected to see. I'll really need a dump or a linker log, but the latter requires a debug version of GHC. Question do all the machine it segfaults happen on are all equipped with Cygwin? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): {{{ Question do all the machine it segfaults happen on are all equipped with Cygwin? }}} No, I opened this issue after trying on a virtual machine without Cygwin. I have removed Cygwin and tried again - crash is still there in msys 2.0. {{{ I'll really need a dump or a linker log, but the latter requires a debug version of GHC. }}} For some reason crash dumps are not collected, even though I followed the instructions you linked. I can try building a debug version of GHC and get it a go. Is this the right instructions to obtain debug ghc https://ghc.haskell.org/trac/ghc/wiki/Debugging/Compiler? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-):
For some reason crash dumps are not collected, even though I followed
the instructions you linked. I can try building a debug version of GHC and give it a go. Is this the right instructions to obtain debug ghc https://ghc.haskell.org/trac/ghc/wiki/Debugging/Compiler? If you can that would be really handy! as I can't see to reproduce it. https://ghc.haskell.org/trac/ghc/wiki/Building/Preparation/Windows are the packages you'll need installed, then just copy `mk/build.mk.in` to `mk/build.mk` and uncomment the `devel2` line. Once building finishes, just do {{{ cd ghc make re2 GhcDebugged=YES }}} and it'll relink ghc using the debug runtime. you can then run ghci as {{{ inplace/bin/ghc-stage2.exe --interactive +RTS -Dl -RTS 2> linker.log }}} to dump a linker log. You can also try attaching it to gdb and see if it happened to have segfaulted in rts code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by sergv): * Attachment "linker.log" added. Linker log produced by ghc commit 14457cf via "inplace/bin/ghc-stage2.exe --interactive +RTS -Dl -RTS 2> linker.log >&2" -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): I have managed to reproduce the issue with ghc HEAD (+/- a few days) and attached linker log as requested. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): Ah great, that's really useful, this seems to indicate the issue is in `initLinker_PEi386` during `addDLLHandle`. I just need one final piece which is where, since the segfault is in the rts and in C code this should be fairly easy. Could you run {{{ gdb --ex run --args inplace/bin/ghc-stage2.exe --interactive }}} with the debud build of ghc. once it crashes copy that trace and put that here, along with the output of running the `bt`, `info locals` and `info args` command. Finally run `gcore` to create a gdb core dump file and attach that. Should be able to figure what's wrong with those pieces. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): For some reason `gdb` does not produce a stacktrace and cannot find any symbols. Can you please check if I'm doing anything obviously wrong in the attached gdb log? I also took a look at the list of dlls loaded by the `ghc-stage2.exe` process in the process explorer and noticed that it loads two copies of `ntdll.dll`. One is loaded from `C:\Windows\System32\` and another is loaded from `C:\Windows\SysWOW64\`. Can this cause any problems? I'm attaching list of dlls as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by sergv): * Attachment "gdb.log" added. Log produced by 'gdb -ex run --args ./inplace/bin/ghc-stage2.exe --interactive +RTS -Dl' -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by sergv): * Attachment "process-explorer.txt" added. List of dll at the time ghc-stage2.exe crashed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): The list of dlls is fine, it's just the system redirecting the load. Had it somehow been able to load the 64bit one then we would have gotten an image load error. GDB not showing a trace is unfortunately quite common during the RTS's startup code. something screws up the stack frame during init. use `break addDLLHandle if ((int)strcmp(dll_name, "ntdll.dll")) == 0` and then step through the source with `next`. My guess is you'll segfault after a few steps. If you do make a note of which statement it was. restart and step to just before the segfault and run `gcore` for a dump. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by gbaz): We're running into this bug in preparing the win32 distro of the Haskell Platform as well, so I'm quite worried about this. For example, ghc-pkg exe seems to break in the same way. In fact I'm not even so sure about doing a win32 release at all for this version of ghc. Advice on if there's a workaround or we should anticipate an emergency patch (or just omit the win32 build of the platform for this reason) would be much appreciated. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): I still wasn't able to use gdb to any good, but I think I found out the problem. The tl;dr version is: `addDLLHandle` assumes that import table is always present and it is not the case for 32-bit `ntdll.dll`. The long version is: I have stumbled upon some code for reading import table - https://stackoverflow.com/questions/15960437/how-to-read-import-directory- table-in-c#17457077. The GHC currently uses somewhat different but simpler approach. In particular it doesn't use anything resembling `Rva2Offset` function. I tried to use `Rva2Offset` and friends from the post but it didn't work. I didn't manage to debug it, but while trying to I noticed that post's code explicitly checks for the case when dll has no import table. I added this check to ghc and it seems that was enough to get `ghc --interactive` working. The check is: {{{ diff --git i/rts/linker/PEi386.c w/rts/linker/PEi386.c index 42e700805e..011b0a8314 100644 --- i/rts/linker/PEi386.c +++ w/rts/linker/PEi386.c @@ -240,6 +240,13 @@ static void addDLLHandle(pathchar* dll_name, HINSTANCE instance) { (PIMAGE_IMPORT_DESCRIPTOR)((BYTE *)instance + header-> OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); + bool importTableMissing = + header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size == 0; + + if (importTableMissing) { + return; + } + /* Ignore these compatibility shims. */ const pathchar* ms_dll = WSTR("api-ms-win-"); const int len = wcslen(ms_dll); }}} @Phyx- is the fix sensible? Should we try to merge it in? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): `Rva2Offset` isn't needed because the code in `initLinker` isn't reading in an image file from disk, but rather the loaded image. So the Windows loader has already resolved any RVAs to final addresses. This is why the code is simpler. I am however confused why this fails for some and not others, I would expect the same behavior. Though the original report is for older kernel versions. Anyway nice catch! It looks sensible to me, If you want credit for the fix please attach a `git am` patch and I'll commit. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by sergv): Great! Please use following patch I'm attaching. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: new Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by sergv): * Attachment "0001-Fix-loading-of-dlls-on-32bit-windows.patch" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs
----------------------------------+------------------------------
Reporter: sergv | Owner: (none)
Type: bug | Status: new
Priority: highest | Milestone: 8.2.2
Component: Compiler | Version: 8.2.1
Resolution: | Keywords:
Operating System: Windows | Architecture: x86
Type of failure: Runtime crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
----------------------------------+------------------------------
Comment (by Tamar Christina

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: merge Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by Phyx-): * status: new => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:24 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: merge Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): @bgamari if there's an 8.2.2 could you please include this one. Thanks. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:25 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: merge Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by bgamari): Ahh, excellent. Thanks Phyx! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:26 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: merge Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Comment (by Phyx-): @sergv Did all the work on this one :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:27 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14081: 8.2.1 runghc from Windows x32 segfaults an all programs ----------------------------------+------------------------------ Reporter: sergv | Owner: (none) Type: bug | Status: closed Priority: highest | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Operating System: Windows | Architecture: x86 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------ Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged in 5a1ae9e32535fe4a891a515d44dd13968161ff27. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14081#comment:28 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC