Skip to content

On Windows, runtime linker can't find function defined in GHC's RTS

This is an annoyance I discovered when working with the atomic-primops package on Windows. Here is a simplified test case:

module Main (main) where

foreign import ccall unsafe "store_load_barrier"
  storeLoadBarrier :: IO ()

main :: IO ()
main = do
  putStrLn "1"
  storeLoadBarrier
  putStrLn "2"

Compiling and running this program works without issue. But when run as GHCi bytecode, it fails. I've reproduced this with GHC 8.0.1 and HEAD (but based on this, the issue is likely much older than 8.0.1).

$ runghc Bug.hs
Bug.hs:
ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
  store_load_barrier
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session.  Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
  glasgow-haskell-bugs@haskell.org

To work around this issue, atomic-primops currently links against a separate C file that contains an exact duplicate of the store_load_barrier function from GHC's RTS when build on Windows.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System (Linker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC Phyx-
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information