cvs commit: fptools/ghc/docs/comm/the-beast driver.html

Manuel M. T. Chakravarty chak@cse.unsw.edu.au
Fri, 24 Aug 2001 15:56:32 +1000


"Simon Marlow" <simonmar@microsoft.com> wrote,

> > >    This does, however, lead to a complication. Normal
> > >    Haskell programs do not have a main function, so this is
> > >    supplied by the RTS. It calls startupHaskell, which
> > >    itself calls __init_PrelMain, which is therefore, since
> > >    it occurs in the standard library, one of the symbols
> > >    passed to the linker. However, when the main  function is
> > >    provided by the programmer (e.g. when there is no main
> > >    module, but a C module instead), __init_PrelMain had
> > >    better not be linked in, because it tries to call
> > >    __init_Main, which won't exist.
> > >
> > > This reads to me as if the complication arises only because
> > > of the business of breaking the cycle between the RTS and
> > > HSstd.  However, I think, this is not true.  The RTS has to
> > > be linked in anyway.  So, it will include a `main()', which
> > > overall leads to `__init_Main' being linked in (with or
> > > without cycle).
> > >
> > > Have I misunderstood you or do I misunderstand the setup
> > > itself?
> > 
> > Well, there's extra complication owing to the -u's, but 
> > basically I think
> > you're right. The main() stuff leads to even more complications under
> > DLLized systems on Windows, after all. Perhaps I should write 
> > something
> > about that too...
> 
> The RTS's main() refers to __init_PrelMain which in turn refers to
> __init_Main.  Although the RTS's main() might not be linked in if the
> program provides its own, the driver will normally force __init_PrelMain
> to be linked in anyway, using -u, because it's a back-reference from the
> RTS to HSstd.  The -no-hs-main flag causes the driver not to do this.

So, the driver arranges that the C program providing the
main() that we want to use appears in the link line after
the RTS.  Therefore, the RTS's main is never used and
without the -u the label __init_PrelMain wouldn't be
linked.  Ok, got it.  

I'll edit the explanation in the commentary a bit to make
this explicit.

Manuel