GHCi linker does not honor alignment of sections.
This is a very elusive bug that I noticed when running an
hmatrix example under GHCi on Windows. Luckily, this example can be reduced down to a couple of
.hs files and a single
.c file (with no other Haskell or C dependencies). Unfortunately, I can't quite figure out a way to reproduce this bug without
cabal, so I've put the source code at https://github.com/RyanGlScott/hmatrix-segfault. You can reproduce this bug by doing the following:
$ git clone https://github.com/RyanGlScott/hmatrix-segfault $ git reset 2bfe38f964fca64dd776993c89ec59d35fb368a5 $ cd hmatrix-segfault/ $ cabal install $ runghc exe/Main.hs Access violation in generated code when reading ffffffffffffffff
Main.hs in GHCi crashes, whereas compiling it works:
$ ghc exe/Main.hs $ ./exe/Main.exe [1,1,1,1,1,1,1,1,1,1,1,1]
I've reproduced this with GHC 7.10.3, 8.0.2, and 8.2.1-rc1.
There are a couple of things that appear to be necessary to trigger the segfault:
- You need to have
- You need to define the FunCodeS datatype.
Removing either of these things causes the program to work again under GHCi.