c7770eddbc505016f03ce1784e3154ffc20e476d
[ghc-hetmet.git] / ghc / docs / comm / the-beast / driver.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3   <head>
4     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
5     <title>The GHC Commentary - The Glorious Driver</title>
6   </head>
7
8   <body BGCOLOR="FFFFFF">
9     <h1>The GHC Commentary - The Glorious Driver</h1>
10     <p>
11       The Glorious Driver (GD) is the part of GHC that orchestrates the
12       interaction of all the other pieces that make up GHC.  It supersedes the
13       <em>Evil Driver (ED),</em> which was a Perl script that served the same
14       purpose and was in use until version 4.08.1 of GHC.  Simon Marlow
15       eventually slayed the ED and instated the GD.
16     </p>
17     <p>
18       The GD has been substantially extended for GHCi, i.e., the interactive
19       variant of GHC that integrates the compiler with a (meta-circular)
20       interpreter since version 5.00.
21     </p>
22
23     <h2>Linking the <code>RTS</code> and <code>libHSstd</code></h2>
24     <p>
25       Since the RTS and HSstd refer to each other, there is a Cunning
26       Hack to avoid putting them each on the command-line twice or
27       thrice (aside: try asking for `plaice and chips thrice' in a
28       fish and chip shop; bet you only get two lots), namely to add
29       the symbols that the RTS needs from libHSstd, such as
30       <code>PrelWeak_runFinalizzerBatch_closure</code> and
31       <code>__init_Prelude</code> to the link line with the
32       <code>-u</code> flag. The standard library appears before the
33       RTS on the link line (why? might it be better the other way
34       around? [SPJ]), and these options cause the corresponding
35       symbols to be picked up even if they haven't been already, so
36       that when the RTS is also scanned, they are resolved. This
37       avoids the linker having to read the standard library and RTS
38       multiple times.
39     </p>
40     <p>
41       This does, however, lead to a complication. Normal Haskell
42       programs do not have a <code>main</code> function, so this is
43       supplied by the RTS. It calls <code>startupHaskell</code>, which
44       itself calls <code>__init_PrelMain</code>, which is therefore,
45       since it occurs in the standard library, one of the symbols
46       passed to the linker. However, when the <code>main</code>
47       function is provided by the programmer (e.g. when there is no
48       main module, but a C module instead),
49       <code>__init_PrelMain</code> had better not be linked in,
50       because it tries to call <code>__init_Main</code>, which won't
51       exist. This case is coped with by the <code>-no-hs-main</code>
52       flag, although in some versions of the compiler (e.g. 5.00.2) it
53       didn't work.
54     </p>
55     
56     <p><small>
57 <!-- hhmts start -->
58 Last modified: Wed Aug 22 17:01:33 GMT Daylight Time 2001
59 <!-- hhmts end -->
60     </small>
61   </body>
62 </html>