Patching GHC

posted Dec 12, 2008, 2:55 AM by Wei Hu   [ updated Dec 12, 2008, 3:12 AM ]
A Haskell program needs three supporting pieces: Haskell runtime system (RTS), base Haskell libraries (e.g. Prelude definitions), and C libraries (libc, libm, libgmp, etc). The RTS and the Haskell libs have to be patched to run on bare metal, and the tiny C libraries under support/ replace real ones.

Compared to the original monolithic patch file, the updated version divides the patch into a set of individual patch files. This is good, but the division itself is done in a somewhat confusing way. The Makefile first applies a set of patches in "halvm" and then applies patches in "house" that depends on "halvm". It looks like the halvm patches are there to port ghc to Xen, so we shouldn't be concerned. Also, some of the patches seem unnecessary. I tried to figure out the minimal patches required to support House:
  1. build-related configs and makefiles. They add a new backend target i386-unknown-house to ghc. This way all changes can be limited to this target only. They also disable certain features such as SMP, and avoids dependency on certain libraries such as gmp and readline.
  2. Haskell libraries. boot-packages is changed to remove some libraries that require OS. Makefile is changed to skip building some libraries. The base library's Prelude.hs is changed to get rid of some IO functions. base.cabal is changed to remove dependencies on some libs. Some concurrency-related files are changed. Due to the changes in the base library, other libs affected by the changes also need adjustments.
  3. rts is changed to remove file IO operations, profiling support, etc.
  4. misc files.
  5. Missing functions are defined in patches/new/rts/house/, and external libraries in support/.
House is compiled by ghc stage1. It would be really interesting to bootstrap ghc and make ghci runnable on House. Think about it: House's shell is ghci, and House's editor is Yi. Native APIs are Haskell functions. All processes share the RTS code. How exciting it will be! It's like the Lisp Machine resurrected!

The boot process is rougly:
Vbe-patched GRUB -> start (cbits/start.S) -> c_start (cbits/c_start.c) -> main (ghc-6.8.2/rts/Main.c in libHSrts.a) -> ... -> main (House.hs)
Comments