Segfault when using GHC.Exts.Heap functions
Summary
the compiled program segfaults when run
Steps to reproduce
get this reproduction https://github.com/dten/nf-segfault
stack build
stack exec -- nf-segfault-exe
Expected behavior
not segfault
Environment
- GHC version used: 9.0.3 also tested on 8.10.7, 9.2.2
Optional:
- Operating System: ubuntu-20.04 via windows 11 wsl2
- System Architecture: x86_64
Stuff that might be useful
my assumption is that it's related to the WeakClosures related to the FFI of the regex since the last closure printed is
WeakClosure {info = StgInfoTable {entry = Nothing, ptrs = 1, nptrs = 4, tipe = WEAK, srtlen = 0, code = Nothing}, cfinalizers = 0x42001fe528, key = 0x42001fea30, value = 0x56b0d0/1, finalizer = 0x56c820, link = 0x0}
gdb backtrace (when using 8.10.7)
Program received signal SIGSEGV, Segmentation fault.
0x00000000004f8c63 in LOOKS_LIKE_CLOSURE_PTR (p=0x0) at includes/rts/storage/ClosureMacros.h:265
265 includes/rts/storage/ClosureMacros.h: No such file or directory.
(gdb) bt
#0 0x00000000004f8c63 in LOOKS_LIKE_CLOSURE_PTR (p=0x0) at includes/rts/storage/ClosureMacros.h:265
#1 0x00000000004f9a10 in evacuate (p=0x42001db0d0) at rts/sm/Evac.c:693
#2 0x0000000000515a07 in scavenge_block (bd=0x42001036c0) at rts/sm/Scav.c:584
#3 0x0000000000517bf3 in scavenge_find_work () at rts/sm/Scav.c:2101
#4 0x0000000000517cd8 in scavenge_loop () at rts/sm/Scav.c:2177
#5 0x00000000004f4a3a in scavenge_until_all_done () at rts/sm/GC.c:1235
#6 0x00000000004f3525 in GarbageCollect (collect_gen=0, do_heap_census=false, deadlock_detect=false, gc_type=0, cap=0x56f1c0 <MainCapability>, idle_cap=0x0) at rts/sm/GC.c:494
#7 0x00000000004dfd08 in scheduleDoGC (pcap=0x7fffffffce50, task=0x5a4370, force_major=false, deadlock_detect=false) at rts/Schedule.c:1851
#8 0x00000000004df24d in schedule (initialCapability=0x56f1c0 <MainCapability>, task=0x5a4370) at rts/Schedule.c:564
#9 0x00000000004e03f5 in scheduleWaitThread (tso=0x4200105388, ret=0x0, pcap=0x7fffffffcf50) at rts/Schedule.c:2609
#10 0x00000000004e348f in rts_evalLazyIO (cap=0x7fffffffcf50, p=0x559818, ret=0x0) at rts/RtsAPI.c:530
#11 0x00000000004e5ff1 in hs_main (argc=5, argv=0x7fffffffd158, main_closure=0x559818, rts_config=...) at rts/RtsMain.c:72
#12 0x00000000004069ac in main ()
valgrind error
==32272== Invalid read of size 8
==32272== at 0x4F8C63: LOOKS_LIKE_CLOSURE_PTR (ClosureMacros.h:265)
==32272== by 0x4F9A0F: evacuate (Evac.c:693)
==32272== by 0x515A06: scavenge_block (Scav.c:584)
==32272== by 0x517BF2: scavenge_find_work (Scav.c:2101)
==32272== by 0x517CD7: scavenge_loop (Scav.c:2177)
==32272== by 0x4F4A39: scavenge_until_all_done (GC.c:1235)
==32272== by 0x4F3524: GarbageCollect (GC.c:494)
==32272== by 0x4DFD07: scheduleDoGC (Schedule.c:1851)
==32272== by 0x4DF24C: schedule (Schedule.c:564)
==32272== by 0x4E03F4: scheduleWaitThread (Schedule.c:2609)
==32272== by 0x4E348E: rts_evalLazyIO (RtsAPI.c:530)
==32272== by 0x4E5FF0: hs_main (RtsMain.c:72)
==32272== by 0x4069AB: main (in nf-segfault-exe)
==32272== Address 0x0 is not stack'd, malloc'd or (recently) free'd
Edited by David Hewson