Skip to content

Windows: runtime linker regression (isatty) with GHC 9.4.5+

(Originally spun off from #23309 (comment 497937) )

Given the following two files, distilled from the text-ansi library:

-- A.hs
module A where

import Foreign.C.Types
import System.IO.Unsafe

isatty :: Bool
isatty =
  unsafePerformIO (c_isatty 1) == 1
{-# NOINLINE isatty #-}

foreign import ccall unsafe "isatty"
  c_isatty :: CInt -> IO CInt
-- B.hs
{-# LANGUAGE TemplateHaskell #-}
module B where

import Foreign.C.String
import Language.Haskell.TH

import A

$(do runIO $ print isatty
     return [])

If you compile this with GHC 9.4.4 or earlier, it will run as expected:

$ ghc-9.2.7 -fforce-recomp B.hs
[1 of 2] Compiling A                ( A.hs, A.o )
[2 of 2] Compiling B                ( B.hs, B.o )
False

If you compile this with GHC 9.4.5 or later, however, the runtime linker will crash on the isatty symbol:

$ ghc-9.4.5 -fforce-recomp B.hs
[1 of 2] Compiling A                ( A.hs, A.o )
[2 of 2] Compiling B                ( B.hs, B.o )
ghc-9.4.5.exe:  | C:\Users\winferno\Documents\Hacking\Haskell\A.o: unknown symbol `isatty'
ghc-9.4.5.exe: Could not load Object Code C:\Users\winferno\Documents\Hacking\Haskell\A.o.


<no location info>: error:

(Also, the error message appears before the "error:" part, which is odd. That isn't the main point of this issue, however.)

This is almost certainly an unintended side effect of !9475 (closed). A similar issue was diagnosed in #23309, but unlike that issue, the issue here is not caused by a missing mingwex dependency. If you compile the program with -lmingwex, the same runtime linker crash still occurs. The patch in !10360 (closed) does not fix the issue here either.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information