[Mono-list] how to compile itself
Jonathan Pryor
jonpryor@vt.edu
20 Feb 2003 14:17:31 -0500
What language do you think GCC is written in? Or Microsoft Visual
Studio? They're written in C or C++. But they're compilers for the
language they're written in, so how does that work?
Simple. You use the current version to build the next version. In
effect, you teach the compiler more and more about the language it's
supposed to accept, using what's available to build the next version.
The only problem comes from getting the initial version to start the
whole process. Some languages (I forget which) had the initial version
hand-translated to machine language. Other languages have their initial
version written in another language. The first C compiler, IIRC, was
written in PDP-11 assembly, and was later re-written in C.
MCS was written in C#. To compile it, .NET's C# compiler, csc.exe, was
used to compile the first versions of mcs. After lots of work, mcs was
able to accept itself as an input program, and later was able to
generate code, which allows it to generate the "next" version, starting
the process stated above.
There can be problems with this. It becomes possible to "hide" stuff in
the compiler, even when there's no source code for the "hidden" stuff.
Ken Thompson wrote an excellent article about this, "Reflections on
Trusting Trust," available here:
http://www.acm.org/classics/sep95/
- Jon
On Thu, 2003-02-20 at 12:24, Kozlovsky, Oleg wrote:
> Hello guys!
>
> I read on your site that
> "MCS was able to parse itself on April 2001, MCS compiled itself for the
> first time on December 28 2001. MCS became self hosting on January 3rd,
> 2002.
> "
> Forgive me please my ignorance but I just can't comprehend how bunch of
> programming code (which is text) can compile itself? As far as I understand
> one needs to have executable which is collection of pointers and op codes (
> primitively saying) to at least be run by operation system. But how text
> files can bootstrap themselves and turn themselves into executable code I
> cannot understand. Could you explain this to me please. Is there anything
> that I can read about it?
>
> Thank you very much
> Take Care
>
> Olegh
>
> _______________________________________________
> Mono-list maillist - Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list