goboot #
A self-chaining hex0 -> kaem -> ... bootstrap chain with a single committed
seed binary (./build) and a single human-readable build script
(src/build.kaem).
One command to bootstrap #
$ ./build
That's it. ./build is a hand-crafted i386 static ELF -- an alternative
hex0: with IN OUT arguments it is byte-identical to upstream hex0, and
with no arguments it is a self-hosting bootstrap root:
mkdir("out", 0755)(ignore EEXIST)- decode its own source:
src/build.hex0->out/build - byte-compare
./buildagainstout/build; exit 1 on any difference. This is the deterministic self-hosting proof:./buildIS a correct hex0 decoder for its own source, so decodingbuild.hex0must yield./builditself. If it doesn't, the chain stops right there. - decode
src/stage0-posix-x86/kaem-minimal.hex0->out/kaem-minimal execve("out/kaem-minimal", ["out/kaem-minimal", "src/build.kaem"], ["PATH=out", "M2LIBC_PATH=src/M2libc", "TMPDIR=out", NULL])
There is no separate out/hex0: out/build is the hex0 the chain uses
from phase 1 onward.
kaem-minimal is a 632-byte hand-written shell. Every command it runs
inherits its own envp verbatim (kaem-minimal's execve passes its own
envp register through unchanged). That fact is what lets us avoid
patching any upstream source: M2-Mesoplanet finds M2-Planet through
PATH=out, and resolves <string.h> and friends via M2LIBC_PATH.
From there src/build.kaem runs one command per line for phases 1-15 of
the stage0 chain, ending with the full mescc-tools-extra set.
The seed is not a magic binary #
./build is 672 bytes, organized as six small functions. There is no
duplicated hex0 loop: the ordinary IN OUT mode and the bootstrap share the
exact same decoder.
start- saveargv[0](for the self-check), then branch onargv[1]hex0-IN OUTmode: onecall tfile, thenexit(0)bootstrap- the no-argument path:mkdir, decode own source,compare, decode kaem-minimal,execvetfile- open in /transcribe/ open out / close: the one file-to-file decode used by every modetranscribe- the hex0 decoder, reading[in_fd]and writing[out_fd]compare- byte-compare two files,exit(1)on the first difference (the gate)
Invoked with arguments (./build IN OUT) ./build decodes IN into OUT,
byte-identical to upstream hex0. You can prove it:
$ ./build src/stage0-posix-x86/hex0_x86.hex0 /tmp/hex0-test
$ sha256sum /tmp/hex0-test # matches upstream hex0 (f74dcf9c...)
src/build.hex0 is the hand-readable source of the seed, written in the
same hex0 style as upstream: one instruction per line, real bytes with a
; mnemonic comment, #: labels carrying each address, prose between the
sections. There is no assembler that produces it -- hex0 cannot bootstrap
itself -- so the binary is committed and the file is proven to be its true
source by the seed's own runtime self-check: with no arguments, ./build
decodes src/build.hex0 and byte-compares the result against itself,
exiting 1 before any further work if any byte differs. To check the source
against the binary by hand:
$ ./build src/build.hex0 /tmp/b
$ cmp /tmp/b ./build # byte-identical -- the file IS the binary
Reproducibility #
Two clean builds in a row (rm -rf out && ./build twice) produce byte-
identical binaries for every file in the output manifest. No clock, no
randomness, no ambient env leaks: kaem-minimal gets a fresh envp, and
each subprocess sees exactly PATH=out, M2LIBC_PATH=src/M2libc,
TMPDIR=out plus nothing else.
Layout #
build- the committed seed binary (i386 static ELF)src/build.hex0- human-readable hex0 source of the seedsrc/build.kaem- one-command-per-line bootstrap scriptsrc/stage0-posix-x86/- stage0-posix subtree (x86 flavor)src/M2libc/- M2libc subtreesrc/M2-Planet/- M2-Planet subtreesrc/M2-Mesoplanet/- M2-Mesoplanet subtreesrc/mescc-tools/- mescc-tools subtreesrc/mescc-tools-extra/- mescc-tools-extra subtree
Each src/* is a git subtree add (or was originally subtree add) at
the upstream HEAD, preserving full history for license and attribution.
Output manifest #
Running ./build produces this set of executables in out/ (each
verified reproducible across clean rebuilds):
build kaem-minimal hex1 hex2-0 catm M0 cc_x86 M2 blood-elf-0 M1-0 hex2-1
M1 hex2 kaem M2-Mesoplanet blood-elf get_machine M2-Planet
sha256sum match mkdir untar ungz unbz2 unxz catm2 cp chmod rm replace wrap
The intermediates .M1, .hex2, .c scratch files also land in out/.
They aren't the artifacts, they're the byproducts of M1 assembly.
Licensing #
goboot's own files -- src/build.hex0, src/build.kaem, README.md,
hex0-to-go.md, .gitignore -- are ISC (see LICENSE). No per-file
license headers: the root LICENSE covers them.
The vendored subtrees under src/ keep their own licenses, which take
precedence over the root one for those files: each subtree ships a
LICENSE or COPYING inside its directory and preserves full upstream
history via git subtree.
One honest wrinkle: the committed seed ./build derives from upstream
hex0_x86.hex0 (GPL-3.0-or-later, Jeremiah Orians et al.). Its decode
core reuses hex0's algorithm and instruction encodings, so the seed binary
is distributed under GPL-3.0-or-later even though goboot's own sources
around it are ISC. If the seed is ever rewritten from scratch (rather
than derived from hex0) it becomes plain ISC.