Recompilation results in linking failure or program segfault
Summary
I have a small program (one newtype
, one class
, one instance
) that seems to mess with recompilation.
If I make a minor change to the source and recompile, linking will fail. However, adding a little more code (namely, a composition with id
) results in successful compilation, but SIGSEGV in runtime, when a certain thunk is evaluated. It is worth noting, that -O1
makes the issue go away.
(lldb) target create "./Main2"
Current executable set to './Main2' (x86_64).
(lldb) r
Process 22932 launched: './Main2' (x86_64)
Process 22932 stopped
* thread #1, name = 'Main2', stop reason = signal SIGSEGV: invalid address (fault address: 0x4b20)
frame #0: 0x0000000000487a38 Main2`stg_IND_STATIC_info + 8
Main2`stg_IND_STATIC_info:
-> 0x487a38 <+8>: jmpq *(%rbx)
0x487a3a: nopw (%rax,%rax)
0x487a40: addl %eax, (%rax)
0x487a42: addb %al, (%rax)
(lldb) register read
General Purpose Registers:
rax = 0x0000000000000001
rbx = 0x0000000000004b20
rcx = 0x0000000000000012
rdx = 0x00000042001ff070
rdi = 0x0000004200106179
rsi = 0x00000000004b2081 MyInteger_zdfToMyIntegerInteger_closure + 1
rbp = 0x00000042001052b8
rsp = 0x00007fffffff79a8
r8 = 0x0000004200104198
r9 = 0x0000000000000000
r10 = 0x0000004200104e00
r11 = 0x0000004200104e40
r12 = 0x00000042001061a0
r13 = 0x00000000004bd218 Main2`MainCapability + 24
r14 = 0x0000004200106179
r15 = 0x00000042001050c0
rip = 0x0000000000487a38 Main2`stg_IND_STATIC_info + 8
rflags = 0x0000000000010202
cs = 0x0000000000000033
fs = 0x0000000000000000
gs = 0x0000000000000000
ss = 0x000000000000002b
ds = 0x0000000000000000
es = 0x0000000000000000
Steps to reproduce
https://github.com/serokell/weird-ghc
git clone https://github.com/serokell/weird-ghc && cd weird-ghc
-
./bug.sh 1
or./bug.sh 2
Environment
- GHC version used: 8.2.2, 8.4.4, 8.6.4,
c9756dbf1e
(2018-12-18),b1662e812c
(2019-01-29)