Skip to content

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

Running 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:

  1. You need to have -O4 under cc-options in hmatrix-segfault.cabal.
  2. You need to define the FunCodeS datatype.

Removing either of these things causes the program to work again under GHCi.

Trac metadata
Trac field Value
Version 8.0.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC Phyx-
Operating system
Architecture
Edited by Tamar Christina
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information