GHCi crash when loading a mix of bytecode and object code and then unloading them
Summary
This is an issue when we don't use dynamically-linked GHCi. To describe in details, when there's a mix of bytecode and object code loaded in GHCi and if there are references from the bytecode module to cafs in the object code, unloading them may cause crashes.
Steps to reproduce
We can start with the patch here caf_crash.patch which contain the relevant Haskell modules to reproduce the problem (A.hs
, B.hs
and D.hs
). We can then fire up GHCi,load the file D.hs, run the code, unload it with :l []
, and the crash can be observed consistently. This is the console output on my machine
root@7036d062b430:/fbghc/testsuite/tests/ghci/caf_crash# /fbghc/inplace/bin/ghc-stage2 --interactive -fexternal-interpreter
GHCi, version 8.4.4.20190402: http://www.haskell.org/ghc/ :? for help
Prelude> :set -fobject-code
Prelude> :l D
[1 of 3] Compiling B ( B.hs, B.o ) [Prelude changed]
[2 of 3] Compiling A ( A.hs, A.o ) [Data.Foldable changed]
[3 of 3] Compiling D ( D.hs, D.o ) [Data.Foldable changed]
Ok, three modules loaded.
Prelude D> :set -fbyte-code
Prelude D> :add *D
[3 of 3] Compiling D ( D.hs, interpreted )
Ok, three modules loaded.
*D> main
100000242441852
Hello
World
1
"square"
I'm a square
12
*D> :l []
Ok, no modules loaded.
Prelude> :l []
ghc-stage2: ghc-iserv terminated (-11)
Leaving GHCi.
Please note that ghc has to be built with DYNAMIC_GHC_PROGRAMS = NO
, this bug wouldn't happen if we don't try to unload the loaded objects.
Expected behavior
There shouldn't be any crash in the ghc-iserv process
Environment
- GHC version used: ghc-8.4.4,
Optional:
- Operating System: Linux
- System Architecture: x86_64