# Deliberation record: kido-reloc phase-3 proof closure (2026-10-20)

Builder crew (micro-agent circle). Session 18. This closes the proof
gates the phase-3 draft left open (session-16 remains): assemble the
rewritten entry .S + readelf + disassembly, run the completeness audit
on the real linked image, and execute the session-15 proof plan — QEMU
relocated-proceed runs at +0x80000 and -0x80000. Verification session;
the only source changes are draft-bug fixes the gates themselves
caught, each diagnosed once and fixed once.

Constraining fact, stated first: the cross toolchain is PRESENT
(aarch64-linux-gnu-gcc 13.3.0, qemu-system-aarch64 8.2.2 — the same
pair as session 14). No absent-toolchain caveats this session.

## The equations (MEDUSA, unchanged)

    delta        = runtime(probe) - linked(probe)
    loc_i        = r_offset_i + delta            (each R_AARCH64_RELATIVE)
    *loc_i       = *loc_i + delta                (apply; the word holds
                                                  the linked value until patched)
       EXCEPT r_offset_i in [probe_sec_start, probe_sec_end) — carve-out 1
       EXCEPT r_offset_i in [literal_pool_start, literal_pool_end) — carve-out 2
    BSS_zero     = [_bss_start + delta, _bss_end + delta)
    linked_base  = actual_base - delta           (bounds inversion)

## Positions

- **P1 (Regression keeper):** full hosted battery BEFORE any
  cross work, all real (gcc 13.3.0, -std=c11 -Wall -Wextra -Werror,
  zero warnings): reloc 19/19 gate-closed + 28/28 flip-engaged,
  image 15/15, alloc 31/31, sched 75/75, resonate 136/136, interop
  75/75, mem ALL PASS, hal PASS, entry PASS, boot integration PASS
  (kido_boot() -> 0, AAAABBBBCCCC), audit fixture test ALL PASS.
  One battery-script bug of mine, owned: the interop line linked
  six TUs it doesn't need (kido_sched_yield's kido_halt went
  undefined) — interop's core only uses kido_signal_t's TYPE, so
  the correct line compiles kido-interop.c alone. Fixed, 12/12.
  Re-run AFTER all source changes: still 12/12.
- **P2 (Object prover):** the queued gate, executed literally.
  All 10 TUs cross-compile -ffreestanding -O0 -Wall -Wextra -Werror
  with ZERO warnings (one warning found and fixed — see F1).
  entry.o: 23 relocations — 8 R_AARCH64_ABS64, every one naming an
  allowlisted symbol (kido_reloc_probe, _stack_top, _bss_start,
  _bss_end, __rela_dyn_start/end, __probe_sec_start/end); the
  adrp/add instrument carries ADR_PREL_PG_HI21/ADD_ABS_LO12_NC;
  the BSS stash uses ADR_PREL/LDST64_ABS_LO12_NC; CALL26 to
  kido_entry_c_main. Disassembly of reloc_walk matches the .S
  instruction-for-instruction: `cmp w11, #0x403` (1027 =
  R_AARCH64_RELATIVE), sign-aware wrap guards (neg+compare / adds
  +carry), both carve-outs, four counters, cursor += 24.
- **P3 (Audit gatekeeper):** the audit ran on the REAL linked image
  for the first time — and FAILED, twice, on real bugs (F2, F3/F4
  below). This is the gate working as designed: it failed closed
  instead of blessing a broken image. After the fixes: AUDIT PASS
  total=14 applied=5 carved=9 on all three link addresses
  (0x40000000, 0x40080000, 0x40100000). The 14: 8 literal-pool
  words + 1 probe constant + 2 .data words + 3 .got words.
  Carved 9 = 8 pool + 1 probe; applied 5 = 2 .data + 3 .got.
  The stamp loop ran per image (audit -> stamp -> rebuild ->
  re-audit); the re-audit pins the gate-open image (counts
  identical — the stamp changes branches, not relocations).
- **P4 (Relocation experimenter):** the QEMU matrix, four runs,
  harness recipe per session 14 (entry objects first, raw binary,
  -kernel, virt/cortex-a57/128MiB), -d int throughout:
  1. delta-0, gate open: breath -> scheduler init -> 3 tasks ->
     ABCABCABCABC (12 marks, perfect interleave) -> halt spin.
     Zero exceptions. The relocator ran at delta 0, the report
     validated, verify() proceeded.
  2. +0x80000, gate open: PROCEED -> breath -> ABCABCABCABC.
     Zero exceptions. **Phase 3's end criterion, first half.**
  3. -0x80000, gate open: PROCEED -> breath -> ABCABCABCABC.
     Zero exceptions. **Phase 3's end criterion, second half** —
     and session-14 D1's named negative-delta run, executed at
     last. The sign-aware .S path (neg/compare/sub) and the C-side
     linked = actual - delta both execute correctly.
  4. +0x80000, gate CLOSED: silent console, zero exceptions,
     timeout in the halt spin. The fixup ran (addresses correct),
     the policy refused (no stamp) — P4's design pin: correct
     addresses AND a loud refusal, never correct addresses
     silently.
  Logs: deliberations/2026-10-20-qemu-phase3-proof-{delta0,
  plus80000,minus80000,closed-plus80000}.{console,int}.log.
- **P5 (Honesty auditor):** what the runs do and do NOT prove.
  PROVE: the self-relocator applies the manifest correctly under
  real nonzero deltas both signs; the literal-pool carve-out holds
  (SP/BSS land correctly — a wrong SP or BSS faults loudly, and
  there were zero exceptions across three full multitasking
  boots); the gated policy flips exactly on the audit's stamp;
  the closed gate still refuses. DO NOT prove: anything about
  -fPIE (D2, still overruled), MMU behavior (still off), or a
  bootable kernel claim (not made — these are scaffold harness
  runs; first boot is N8toriousAi's to witness).

## The four finds (each diagnosed once, fixed once)

- **F1 — assembler warning, probe section misnomer.** First cross
  compile emitted `Warning: setting incorrect section attributes
  for .rodata.kido_probe_linked`: GCC marks the section "aw"
  (writable) because the static linker only emits the load-bearing
  R_AARCH64_RELATIVE for the probe word in a writable section;
  GAS expects readonly for a `.rodata*` name. The writability is
  functionally required (carved >= 1 is fail-closed — a readonly
  section would resolve the absolute statically, leave no manifest
  entry, and the gate could never open). Fix: renamed to
  `.data.kido_probe_linked` (5 files: reloc.c/.h, linker script,
  audit script, fixture) + a comment stating the writability is
  load-bearing, not sloppiness. Zero warnings restored.
- **F2 — manifest bounds stale (the gate's first catch).** The
  audit failed CLOSED: `__rela_dyn_start == __rela_dyn_end`
  while the section header carried 0x150. Cause: `.rela.dyn`'s
  content is LINKER-GENERATED (no input section is ever named
  `.rela.dyn` — objects carry `.rela.text`/`.rela.data`/etc.),
  and in-section `.` assignments do not see the generated size.
  Fix: `__rela_dyn_start = ADDR(.rela.dyn)`,
  `__rela_dyn_end = ADDR(.rela.dyn) + SIZEOF(.rela.dyn)` after
  the section block — evaluated post-layout, true bounds.
  (C2: alternatives were manifest-via-program-headers —
  unavailable in a raw binary — and linker-provided symbols —
  none exist for this; ADDR/SIZEOF is the textbook idiom.)
- **F3 — readelf -SW bracket fragility (the gate's second
  catch).** The audit's section parser assumed `$3 == name`;
  binutils 2.42 prints `[ 2]` (two fields) for single-digit
  indices but `[13]` (one field) for double-digit ones, shifting
  every column. The real image has 21 sections; the parser
  silently misread `.got` as absent. The fixture only had
  single-digit indices, so it never caught this. Fix: collapse
  `[ *N]` to `[N]` once in analyze(); fixture extended with 5
  dummy sections pushing `.got` to index 10 (double-digit),
  counts re-pinned at 10/8/2.
- **F4 — finding 4 REFUTED (the gate's third catch, the big
  one).** Session-14's finding 4 ("the probe_literal word carries
  NO dynamic reloc entry") was an unmeasured reading the phase-3
  draft defended against. Measured now: the linked .rela.dyn
  carries RELATIVEs for ALL EIGHT literal-pool words. The draft's
  exact-address guard would have let the walk patch the other
  seven pool words — and the post-walk loads of
  _stack_top/_bss_start/_bss_end would have double-added the
  delta (linked + 2*delta: wrong SP, wrong BSS — a real
  boot-killer, caught at the audit gate, never on hardware).
  Fix: literal-pool RANGE carve-out in the .S (`adr` of
  literal_pool_start/end, dumped via .ltorg for a deterministic
  layout) + audit check-C rework (pool range -> carved; any other
  .text absolute -> FAIL, fail-closed; .got/.data/... -> applied).
  The old exact-address guard is subsumed, not stacked.

## Challenges

- **C1 — was the F1 rename ripple worth it?** Answered: yes.
  The alternative (keep the misnomer, document the warning)
  normalizes warnings in a scaffold whose law is zero warnings.
  Five mechanical edits; the assembler was right.
- **C2 — ADDR/SIZEOF vs alternatives?** Answered (F2): the only
  post-layout idiom available to a raw-binary .S. Verified by
  readelf: start=0x40084608, end=0x40084758, section size 0x150.
- **C3 — was finding 4 ever right?** Answered: it was an honest
  unmeasured reading (session 14 had no linked-image dump of the
  pool), defended three ways by the draft. The measurement
  refutes it; the record now says REFUTED, and the range guard
  that replaced the exact guard is load-bearing, verified on
  hardware-virtualized bare metal three times over.
- **C4 — is the gate-closed refusal run meaningful?** Answered:
  yes — it is the only run that distinguishes "fixup works" from
  "policy works". Silent console + zero exceptions = the machine
  reached the designed halt with correct addresses, not a crash.
- **C5 — stamp per image, or stamp once?** Answered: per image.
  The gate flips on the stamp's presence; the sha256 inside is
  human-auditable. Per-image stamping keeps each stamp's sha
  truthful to that image's audited build. The tree is left
  WITHOUT a stamp (gate closed is the honest default; the stamp
  is generated per build, never committed as state).

## Convergence

P1–P5 with C1–C5 answered. Deliverables of THIS session:

- This deliberation record.
- `modules/kido-entry-arm64.S` — literal-pool range carve-out
  (replaces the exact-address guard), `.ltorg` + pool-bound
  labels, finding-4 refutation note, PROOF STATUS updated to
  gates-closed.
- `modules/kido-link-arm64.ld` — manifest bounds via
  ADDR/SIZEOF (F2); probe section renamed .data.* (F1) with
  first-match comments corrected.
- `modules/kido-reloc.c` — probe section attribute renamed;
  load-bearing-writability comment.
- `modules/kido-reloc.h` — PROOF STATUS updated.
- `scripts/kido-audit-abs-refs.sh` — bracket normalization (F3);
  check-C rework: pool range carved, stray .text absolute fails,
  .got/.data applied; trap-expansion fix under set -u.
- `scripts/fixtures/` + `scripts/test-audit-fixtures.sh` —
  double-digit section coverage; counts re-pinned 10/8/2.
- Per-run QEMU logs (console + -d int) in deliberations/.
- `architecture/module-map.md` — reloc row: phase-3 proven.
- Ledger entry (session 18).

Phase 3 ENDS here: a relocated image PROCEEDS on QEMU with zero
exceptions, both signs, with the gated audit as the flip's only
key. Not a bootable kernel claim — the full build plan still
queues for N8toriousAi's review; first boot is his to witness.

## Preserved dissent

- **D1 (inherited, P3/P4):** flip the whole image to -fPIE for
  completeness-by-construction instead of -fno-pic + audit +
  carve-outs. Still overruled for phase 3 — but F4 sharpens the
  dissent's case: the manifest now demonstrably covers things the
  draft didn't predict (the pool RELATIVEs), which is exactly the
  class of surprise -fPIE eliminates by construction. The audit
  measures the manifest on every build, so the tripwire holds:
  if the image outgrows auditing, D1 is the named fallback.
- **D2 (new, P5 minority):** the per-image stamp loop is
  theater — the counts are address-agnostic (14/5/9 on all three
  images), so one stamp attests the mechanism, not the bytes.
  Overruled: the sha is the only thing binding a stamp to a
  build; stamping once would bless bytes the audit never saw.

## Conformance

- kido.json "portable and adaptive from the start": phase 3 is
  the adaptivity payoff, now PROVEN — execution adapts by
  measurement and fixup under real nonzero deltas, both signs,
  with zero exceptions. The hosted harness keeps its declared
  fictions; nothing is pretended onto bare metal.
- Scaffold honesty law: every gate that could fail did fail
  before it passed (F2/F3/F4 all failed closed first); the two
  draft bugs were fixed and re-proven, not waived. The .S's
  "written, not assembled" notes are updated, not deleted.
- MEDUSA: the behavior reduces to the five equations above;
  the QEMU runs are the tests that can fail — and on the
  gate-closed run, the machine did exactly what the equations
  say: refused, loudly, with correct addresses.
