I started working on a similar VM-based bootstrap for getting from bare metal to C compiler. If anyone is interested in collaborating let me know.<p>The idea is that you implement a simple, ASCII-based VM for your platform and that's enough to bootstrap a number of different assemblers, to a basic C compiler, to a full-fledged C compiler and (very minimal) POSIX environment.<p>The goal is twofold: a base for trusted compilation like this one, and a way to guarantee long-term executability of various archiving programs (ie: guarantee that you can unrar a file in 20 years with minimal work).<p>EDIT: very rough repo is here - <a href="https://github.com/mmastrac/bootstrap" rel="nofollow">https://github.com/mmastrac/bootstrap</a>
As for 'why bootstrap'...<p>Since Reflections on Trusting Trust has been linked already, I'm going to offer something else. Today's nightmare: <a href="https://www.teamten.com/lawrence/writings/coding-machines/" rel="nofollow">https://www.teamten.com/lawrence/writings/coding-machines/</a>
Vital details:<p>From <a href="http://git.savannah.nongnu.org/cgit/stage0.git/tree/README" rel="nofollow">http://git.savannah.nongnu.org/cgit/stage0.git/tree/README</a> (which also declares GPL3):<p>> <i>This is a set of manually created hex programs in a Cthulhu Path to madness fashion. Which only have the goal of creating a bootstrapping path to a C compiler capable of Compiling GCC, with only the explicit requirement of a single 1 KByte binary or less.</i><p>> <i>Additionally, all code must be able to be understood by 70% of the population of programmers.
If the code can not be understood by that volume, it needs to be altered until it satifies the above requirement.</i><p>From <a href="https://savannah.nongnu.org/projects/stage0/" rel="nofollow">https://savannah.nongnu.org/projects/stage0/</a>:<p>> <i>A class of minimal bootstrap binaries that has a reproducible build on all platforms. Providing a verifiable base for defeating the trusting trust attack.</i><p><i>Cooooooool.</i>
It would be kind of cool to start small with entirely verifiable hardware for the first bootstrapping stages.<p>I am phantasizing about a sort of ceremony in which the whole bootstrap process is done live in front of an audience starting with a discrete computer (using e.g. this board as a CPU <a href="https://monster6502.com" rel="nofollow">https://monster6502.com</a>), absolutely no electronic non-volatile memory and the first programs read into the computer from punch cards or punch tape. This would be used to create later stages for more powerful hardware and the end result (after maybe one or two hardware switches) is hopefully a minimal C compiler or similar that can be used to bootstrap production compilers like GCC. Ideally, this binary is shown to be completely identical to a binary built by a typical build process.<p>Even if such a ceremony is ultimately not very useful, it could still be seen as a kind of artistic performance.
Very, very nice. Not often you get to study non-trivial assembly programs.<p>Some context is this: <a href="https://bootstrapping.miraheze.org/wiki/Stage0" rel="nofollow">https://bootstrapping.miraheze.org/wiki/Stage0</a>
Bootstrapping a compiler is fun. I wrote a self-hosting compiler for the Oberon-07 language, targeting the JVM: <a href="https://github.com/lboasso/oberonc" rel="nofollow">https://github.com/lboasso/oberonc</a><p>Initially the project was written in Java, after enough features were working the bootstrap phase could start.
If someone is interesting about how to bootstrapping, this[0][1] tutorial is just awesome, tiny compiler from nothing (raw machine codes and hex!) to the self-hosting!<p>[0] <a href="https://web.archive.org/web/20120712111627/http://www.rano.org/bcompiler.html" rel="nofollow">https://web.archive.org/web/20120712111627/http://www.rano.o...</a>
[1] <a href="https://github.com/certik/bcompiler" rel="nofollow">https://github.com/certik/bcompiler</a> (Fork in GitHub)<p>Also worth check - <a href="https://www.t3x.org/t3x/book.html" rel="nofollow">https://www.t3x.org/t3x/book.html</a> :-)
I don't recognise the architecture despite it saying x86, but it reminds me of ARM.<p>Recursive descent seems to be the go-to parsing technique for compilers both big and small now. I like how all the repetitive functions for each level have been refactored into a "general_recursion" function, but if you want to make it even simpler and yet more extendable, table-driven precedence climbing would be ideal:<p><a href="http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing" rel="nofollow">http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing</a>
This program looks interesting. Maybe it could help in the bootstrap process of tcc, though I don't know if it is written in ANSI C. On a related note, I will try to test compiling lua's runtime environment and interpreter, because I'm sure it is written using standard C already.
Just a few hours ago there was a conversation in #gentoo-chat about the Thompson attack. I wondered how difficult it would be to write a C compiler that can compile GCC. How far away is this?
This is super impressive. What might be some compelling technical reasons to use this over existing C implementations? I just don't know so I thought I'd ask.
I'd appreciate a bare minimum C compiler capable of building gcc written in either assembly or x86 machine code that can be trivially audited in as-executed form.