boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

commit 01a04a7e5bb40b5987cfb63291b193535e09d7b6
parent bbed6357a8627b47f9fc30f48f60fb5e63d38a88
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Wed, 29 Apr 2026 18:11:55 -0700

mk: more verbose build logs

Diffstat:
MMakefile | 2+-
Mscripts/boot-build-p1.sh | 48++++++++++++++++++++++++++++++++++++++++++------
Mscripts/boot-build-p1pp.sh | 62+++++++++++++++++++++++++++++++++++++++++++++-----------------
Mscripts/run-tests.sh | 1-
4 files changed, 88 insertions(+), 25 deletions(-)

diff --git a/Makefile b/Makefile @@ -276,7 +276,7 @@ $(TCC_BOOT2_BINS): build/%/tcc-boot2/tcc-boot2: \ build/%/tcc-boot2/tcc.flat.P1pp build/%/vendor/mes-libc/libc.P1pp \ P1/entry-libc.P1pp P1/elf-end.P1pp \ $(P1PP_BUILD_DEPS) - $(call PODMAN,$*) env P1PP_TRACE=1 WORK_SUBPATH=tcc-boot2/tcc-boot2 \ + $(call PODMAN,$*) env WORK_SUBPATH=tcc-boot2/tcc-boot2 \ sh scripts/boot-build-p1pp.sh $@ \ P1/entry-libc.P1pp build/$*/vendor/mes-libc/libc.P1pp \ $< P1/elf-end.P1pp diff --git a/scripts/boot-build-p1.sh b/scripts/boot-build-p1.sh @@ -26,6 +26,31 @@ set -eu +# Per-stage tracing is always on. Stage0 tools (M0, hex2-0) print +# nothing on success and almost nothing on failure, so we narrate which +# step is running, snapshot intermediates to $WORK after each one, and +# print a clear FAIL banner so the user knows where it died. +ARCH_LBL=${ARCH:-?} +CURRENT_STEP= +trap 'rc=$? +if [ "$rc" -ne 0 ] && [ -n "$CURRENT_STEP" ]; then + echo "[p1 $ARCH_LBL] FAIL at: $CURRENT_STEP (exit $rc)" >&2 + if [ -n "${WORK:-}" ]; then + echo "[p1 $ARCH_LBL] partial intermediates in $WORK" >&2 + fi +fi' EXIT + +trace() { + label=$1; path=$2 + sz=$(wc -c < "$path" 2>/dev/null || echo "?") + printf '[p1 %s] %s (%s bytes) %s\n' "$ARCH_LBL" "$label" "$sz" "$path" >&2 +} + +step() { + CURRENT_STEP=$1 + printf '[p1 %s] >> %s\n' "$ARCH_LBL" "$CURRENT_STEP" >&2 +} + : "${ARCH:?ARCH must be set}" [ "$#" -eq 2 ] || { echo "usage: ARCH=<arch> $0 <src> <out>" >&2; exit 2; } @@ -39,16 +64,27 @@ NAME=${SRC%.*} WORK=build/$ARCH/.work/$NAME mkdir -p "$WORK" "$(dirname "$OUT")" +step "cat: P1 table + $SRC -> combined.M1" cat "$TABLE" "$SRC" > /tmp/combined.M1 +cp /tmp/combined.M1 "$WORK/combined.M1" +trace "combined.M1" /tmp/combined.M1 + +step "M0: combined.M1 -> prog.hex2" "$TOOLS/M0" /tmp/combined.M1 /tmp/prog.hex2 +cp /tmp/prog.hex2 "$WORK/prog.hex2" +trace "prog.hex2" /tmp/prog.hex2 +step "catm: ELF header + prog.hex2 -> linked.hex2" cp "$ELF_HDR" /tmp/elf.hex2 -"$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 -"$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin - -cp /tmp/combined.M1 "$WORK/combined.M1" -cp /tmp/prog.hex2 "$WORK/prog.hex2" +"$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 cp /tmp/linked.hex2 "$WORK/linked.hex2" -cp /tmp/prog.bin "$OUT" +trace "linked.hex2" /tmp/linked.hex2 + +step "hex2-0: linked.hex2 -> $OUT" +"$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin +cp /tmp/prog.bin "$OUT" chmod 0700 "$OUT" +trace "$OUT" "$OUT" + printf '%s\n' "$WORK" > "$OUT.workdir" +CURRENT_STEP= diff --git a/scripts/boot-build-p1pp.sh b/scripts/boot-build-p1pp.sh @@ -41,18 +41,33 @@ ## WORK_SUBPATH=<repo-relative-path-without-ext> — overrides the ## work-dir name; required when the first src isn't ## the logical primary source. -## P1PP_TRACE=1 — print a one-line marker (phase, in/out path, size) -## before each pipeline stage so the failing tool is -## obvious. Off by default to keep test runs quiet. ## Usage: boot-build-p1pp.sh <out> <srcs...> set -eu +# Per-stage tracing is always on. The stage0 tools (M0, hex2-0) print +# nothing on success and almost nothing on failure, so we narrate which +# step is running, snapshot intermediates to $WORK before exiting, and +# print a clear FAIL banner on error so the user knows where it died. +ARCH_LBL=${ARCH:-?} +CURRENT_STEP= +trap 'rc=$? +if [ "$rc" -ne 0 ] && [ -n "$CURRENT_STEP" ]; then + echo "[p1pp $ARCH_LBL] FAIL at: $CURRENT_STEP (exit $rc)" >&2 + if [ -n "${WORK:-}" ]; then + echo "[p1pp $ARCH_LBL] partial intermediates in $WORK" >&2 + fi +fi' EXIT + trace() { - [ "${P1PP_TRACE:-0}" = "1" ] || return 0 label=$1; path=$2 sz=$(wc -c < "$path" 2>/dev/null || echo "?") - printf '[p1pp %s] %s (%s bytes) %s\n' "$ARCH" "$label" "$sz" "$path" >&2 + printf '[p1pp %s] %s (%s bytes) %s\n' "$ARCH_LBL" "$label" "$sz" "$path" >&2 +} + +step() { + CURRENT_STEP=$1 + printf '[p1pp %s] >> %s\n' "$ARCH_LBL" "$CURRENT_STEP" >&2 } : "${ARCH:?ARCH must be set}" @@ -75,23 +90,36 @@ fi WORK=build/$ARCH/.work/$NAME mkdir -p "$WORK" "$(dirname "$OUT")" +# Snapshot each intermediate to $WORK as soon as it's produced, so a +# failure leaves the most-recent good artifact on disk for triage. With +# the trap above, the user sees both the failing stage and where to +# look. +step "cat: combined.M1pp <- backend + frontend + libp1pp + $#" cat "$BACKEND" "$FRONTEND" "$LIBP1PP" "$@" > /tmp/combined.M1pp -trace "cat: combined" /tmp/combined.M1pp +cp /tmp/combined.M1pp "$WORK/combined.M1pp" +trace "combined.M1pp" /tmp/combined.M1pp + +step "m1pp: combined.M1pp -> expanded.M1" "$M1PP_BIN" /tmp/combined.M1pp /tmp/expanded.M1 -trace "m1pp: expanded" /tmp/expanded.M1 +cp /tmp/expanded.M1 "$WORK/expanded.M1" +trace "expanded.M1" /tmp/expanded.M1 + +step "M0: expanded.M1 -> prog.hex2" "$TOOLS/M0" /tmp/expanded.M1 /tmp/prog.hex2 -trace "M0: prog.hex2" /tmp/prog.hex2 +cp /tmp/prog.hex2 "$WORK/prog.hex2" +trace "prog.hex2" /tmp/prog.hex2 +step "catm: ELF header + prog.hex2 -> linked.hex2" cp "$ELF_HDR" /tmp/elf.hex2 -"$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 -trace "catm: linked" /tmp/linked.hex2 -"$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin -trace "hex2-0: out" /tmp/prog.bin +"$TOOLS/catm" /tmp/linked.hex2 /tmp/elf.hex2 /tmp/prog.hex2 +cp /tmp/linked.hex2 "$WORK/linked.hex2" +trace "linked.hex2" /tmp/linked.hex2 -cp /tmp/combined.M1pp "$WORK/combined.M1pp" -cp /tmp/expanded.M1 "$WORK/expanded.M1" -cp /tmp/prog.hex2 "$WORK/prog.hex2" -cp /tmp/linked.hex2 "$WORK/linked.hex2" -cp /tmp/prog.bin "$OUT" +step "hex2-0: linked.hex2 -> $OUT" +"$TOOLS/hex2-0" /tmp/linked.hex2 /tmp/prog.bin +cp /tmp/prog.bin "$OUT" chmod 0700 "$OUT" +trace "$OUT" "$OUT" + printf '%s\n' "$WORK" > "$OUT.workdir" +CURRENT_STEP= diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh @@ -74,7 +74,6 @@ run_in_container() { -e "ARCH=$arch" \ -e "CC_TRACE_EMIT=${CC_TRACE_EMIT:-0}" \ -e "CC_DEBUG=${CC_DEBUG:-0}" \ - -e "P1PP_TRACE=${P1PP_TRACE:-0}" \ -v "$REPO":/work -w /work \ "boot2-busybox:$arch" "$@" }