January 05, 2005
Loading GHC into GHCi
I managed to get something quite spectacular happening today. I managed to load package ghc into ghci. I'm pretty sure I'm the first to do this.
The first time I tried I got the following error message from ghci:
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
_OutOfHeapHook
whilst processing object file
/Users/sseefried/cvs-ghc/PLUGGABLE/working/ghc/compiler/HSghc.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry.
I was prepared to live with this until I realised that an inability to use GHCi would mean an inability to use package ghc with Template Haskell. It turned out that GHC redefined three RTS hooks, StackOverflowHook, defaultsHook and OutOfHeapHook to provide better error messages in GHC. The irony is that these hooks were meant to override the old ones, not conflict with them.
My solution to this problem was to strip these symbols from HSghc.o (the dynamic library for package ghc) using the following command:
ld -r -x -all_load -unexported_symbols_list strip_file HSghc.o
strip_file is simply a text file containing the entries:
_OutOfHeapHook
_defaultsHook
_StackOverflowHook
I did this on Mac OS X. This command would be a little different on Linux. I think the symbols would need to have the leading underscore removed and the -all_load option would need to be -whole-archive.