Ports cmd/6l/{dyn,dynout}.c into selfhost/cmd/6l/{dyn,dynout}.ww:
ET_DYN .so loading + PT_INTERP/PT_DYNAMIC ELF emission with .rela.plt,
.gnu.version_r, BIND_NOW. lsym grows dyn fields; pass.ww promotes
undefs to dyn; out.ww dispatches; main.ww takes -L/-l. The ww driver
forwards -L/-l to 6l_ww so 'ww_ww build snake.ww -L /usr/lib -l ncurses
-l c' runs without cc.
Test 996 pins byte-identical output to C-6l on snake.
'make bootstrap' gains a fourth stage with cmp ww3 == ww4, proving
ww3 is byte-stable when used as a compiler — not just a coincidental
two-stage equilibrium.
Four wwstage 6c cgen quirks surfaced and are documented in dynout.ww's
header (two-level field-write through a pointer field, (scalar, str)
tuple returns, def : str, ≤6 arg calling convention).
4.0 KiB
BOOTSTRAP
How ww builds itself.
ww is self-hosted: the ww-side compiler/assembler/linker/driver live
under selfhost/cmd/ and reach a byte-identical fixed point under
make bootstrap. But the first ww binary on a fresh checkout has to
come from somewhere. Today, that "somewhere" is a small C bootstrap
toolchain — the Cstage:
cmd/wwc/ frontend library (lex, parse, check) → libwwc.a
cmd/6c/ amd64 compiler .ww → .s
cmd/6a/ amd64 assembler .s → .o
cmd/6l/ amd64 linker .o → static ELF
cmd/ww/ user-facing driver (orchestrates 6c → 6a → 6l)
Cstage is built with cc. Once it exists, it compiles the
ww-rewritten tools (the wwstage) under selfhost/cmd/, which then
self-compile to a byte-identical fixed point. After that, no C is
involved.
Build flow
cstage (cc → C tools, one-time)
│
├──→ ww1 wwstage tools, built by Cstage
│ │
│ └──→ ww2 wwstage self-compiles
│ │
│ └──→ ww3 ww2 self-compiles
│ │
│ ↓
│ cmp ww2 ww3 → fixed point ✓
↑
└ from here on, no C is invoked
Make targets
make builds cstage + wwstage + libs
make cstage Cstage only (cc → ww, 6c, 6a, 6l, wwdump, libs)
make wwstage wwstage only (assumes cstage)
make bootstrap three-stage build; gates on cmp ww2 == ww3
make test runs all tests, including 990–995 (ww-side
tools vs C-side tools, byte-for-byte, plus
the wwstage rebuilding itself in 995)
Without cc:
make bootstrap-snapshot populate bootstrap/$(ARCH)/ from the
currently-built wwstage (gitignored
by default)
make nocc cold-start from bootstrap/$(ARCH)/,
rebuild the wwstage from source, gate
on `stage-0 == rebuilt` byte-for-byte.
cc is never invoked.
Status
Phase 10 of PLAN.md is at its first exit criterion: the bootstrap is
green and selfhost/cmd/{wwc,6c,6a,6l,ww} are byte-identical to their
Cstage counterparts. Test 995 pins the stronger property — the
wwstage rebuilds every one of its own tools through ww_ww + 6c_ww + 6a_ww + 6l_ww, byte-for-byte. Test 996 pins the equivalent for the
dynamic linker: 6l_ww with -L/-l produces a byte-identical
PT_INTERP+PT_DYNAMIC binary to C-side 6l on snake.
make nocc is wired and verifies stage-0 self-reproduction locally;
the stage-0 binaries under bootstrap/$(ARCH)/ are gitignored until
ready to commit. The second exit criterion — deleting the C trees —
is still deferred to v1.0: shipping the stage-0 binaries is a
one-way door (they become the project's new trust surface), and the
compiler is still churning. A git clone today still requires cc
unless the local working copy has already done make bootstrap-snapshot once.
What "no C" looks like
The pieces are already wired; only the binary commit is held back. When the compiler stabilises:
- On each supported arch, run
make wwstage && make bootstrap-snapshotto populatebootstrap/<arch>/{ww,6c,6a,6l}from the current wwstage. Verify withmake nocc. git add -f bootstrap/<arch>/{ww,6c,6a,6l}— explicit because the dir is gitignored. The binary SHAs become the new trust surface.- Delete
cmd/wwc/,cmd/6c/,cmd/6a/,cmd/6l/,cmd/ww/. DropCC/ARC-tool dependencies from the top-level Makefile. - Move
selfhost/cmd/*tocmd/*andmake noccbecomes the defaultmake. - Build path: stage-0 binary → ww1 → ww2 → fixed point, same as
today, just without
cc.
This is the standard self-hosting story (Go, Rust, OCaml all do variants of it). The bootstrap binaries become the new "trusting trust" surface.