# Deliberation record: phase-2 proof closure — .S object gate + QEMU execution (2026-10-18)

Builder crew (micro-agent circle). This session closes the two proof
gates the phase-2 work left open: (a) the .S object proof
(assemble + readelf ABS64 on the probe literal + disassembly of the
adrp/add instrument — queued since 2026-10-17 for the toolchain's
return), and (b) the relocated-load QEMU execution proof (queued in
the session-12 ledger as "the .S's first execution proof"). The
toolchain is back (aarch64-linux-gnu-gcc 13.3.0, qemu-system-aarch64).
Verification session; pristine scaffold sources throughout — the only
file edits are comment-only proof-status updates (see Convergence).

## The equations (MEDUSA)

    delta       = runtime(probe) - linked(probe)   (both instruments)
    SP          = _stack_top + delta               (entry .S, registers only)
    actual_base = linked_base + delta              (kido_image_actual_bounds)

## Positions

- **P1 (Object prover):** the queued gate, executed literally.
  `aarch64-linux-gnu-gcc -ffreestanding -c kido-entry-arm64.S`:
  assembles clean, zero warnings. `readelf -r` on the object shows
  `R_AARCH64_ABS64` on the literal-pool entry for `kido_reloc_probe`
  (offset 0x90) — the linker's absolute truth, exactly as the gate
  demanded; the adrp/add pair carries `R_AARCH64_ADR_PREL` /
  `R_AARCH64_ADD_ABS` (PC-relative, the runtime truth). Disassembly
  of the object shows the instrument verbatim: `adrp x9` / `add x9`
  (runtime probe), `ldr x10, [literal]` (linked probe),
  `sub x20, x9, x10` (delta); then `ldr x0, =_stack_top` /
  `add x0, x0, x20` / `mov sp, x0` (delta-aware SP); then the BSS
  loop; then `adrp` stores of x20 (delta) and #1 (valid) to the BSS
  slots. The .S does what the phase-2 deliberation said it does,
  instruction for instruction.
- **P2 (Addressing auditor):** the empirical addressing model of the
  linked image — read, not reasoned. Findings: (1) Same-TU globals
  (`kido_reloc_entry_delta/valid`, `kido_reloc_last_cache`) compile
  to direct PC-relative `adrp`/`add` — relocation-TRUE: the C
  crosscheck reads the ACTUAL BSS slot, the same word the .S wrote.
  (2) Cross-TU globals (`_image_start`/`_image_end` via kido-image.c)
  compile GOT-relative (`R_AARCH64_ADR_GOT`); the static EXEC link
  leaves `R_AARCH64_RELATIVE` in `.rela.dyn`, which bare metal never
  applies — so every GOT-based access resolves to the LINKED
  address, permanently. `kido_image_bounds()` therefore keeps its
  LINKED semantics under relocation: deliberation C1's premise
  ("stays LINKED forever") VERIFIED empirically, not assumed.
  (3) The `.rodata` probe constant (`kido_reloc_probe_linked`):
  session 12 proved `R_AARCH64_ABS64` at the OBJECT level; in the
  LINKED image it lands in `.data` with an unapplied RELATIVE
  reloc holding the correct linked value (`0x400036c0`, dumped).
  Same observable (linker-resolved absolute, never PC-relative);
  the gate's intent holds, the relocation's spelling changed at
  link time. Stated precisely so phase 3 doesn't misread it.
  (4) The `.rela.dyn` RELATIVE entries (10) are inert on bare metal
  today — and they are phase 3's self-relocation manifest, sitting
  in the image already. Named, not built.
- **P3 (Relocation experimenter):** OWNS THE HARNESS ERROR, then
  reports what it proved. The "control" link used a harness linker
  copy whose `sed` replaced `RAM_BASE = 0x40000000` with itself —
  the canonical script was read as already-`0x40080000`; it is not
  (sessions 8/11 linked harness copies at `0x40080000`; canonical
  is `0x40000000`). The image linked at `0x40000000`, QEMU `-kernel`
  loaded it at `0x40080000`: delta = +0x80000. The planned control
  was accidentally the relocated experiment. The register trace
  (`-d cpu`) is unambiguous: after `_start`, `X09=0x400836c0`
  (runtime probe), `X10=0x400036c0` (linked probe),
  `X20=0x00080000` (delta), `X19=0x44000000` (DTB stashed). The .S
  measured the TRUE delta in registers before SP existed. The trace
  then shows `kido_reloc_verify` → `detect` → `crosscheck` with the
  agreement branch TAKEN (both instruments measured +0x80000 —
  proving P2's finding (1): the C crosscheck genuinely compares
  under relocation), then the delta policy firing (`EARLY_ENV`),
  then `kido_halt`'s spin. Console: silent (halt doesn't print —
  the signal is breath-vs-silence). `-d int`: zero exceptions.
  The tripwire path executes cleanly under a real nonzero delta:
  safe stack, true measurement, loud refusal. Session 12's declared
  exposure (relocated image dying before the tripwire) is closed
  EMPIRICALLY — the machine reached the designed halt, not a crash
  lottery. The trace also confirms the known non-PI exposure: the
  BSS loop zeroed the LINKED region (`x0=0x40004618`) while the
  stash landed in the actual BSS — harmless here (execution
  refused), phase 3's problem, stated not hidden.
- **P4 (Honesty auditor):** what the relocated run does and does
  NOT prove. PROVES: the entry sequence (delta measure → SP →
  BSS loop → stash → verify → halt) runs exception-free under a
  real nonzero delta; both instruments agree (register + branch
  evidence); the refusal is loud and by design. DOES NOT prove:
  the exact SP value was the shifted one (both candidate SPs were
  in-RAM; no distinguishing fault possible on this harness), or
  which loud path would fire at other deltas. The deliberate
  delta-0 control (see below) covers the agreement path the other
  way. No claim beyond the trace.
- **P5 (Regression keeper):** full hosted battery BEFORE any QEMU,
  all real (gcc 13.3.0, `-std=c11 -Wall -Wextra -Werror`, zero
  warnings): reloc 21/21, image 15/15, alloc 31/31, sched 75/75,
  resonate 59/59, interop 75/75, mem ALL PASS, hal PASS, entry
  PASS, boot integration PASS (`kido_boot()` → 0, `AAAABBBBCCCC`).
  Then the TRUE delta-0 control: harness linker copy with the
  single-line diff `RAM_BASE 0x40000000 → 0x40080000`
  (diff-verified; canonical untouched), entry objects first in the
  link line (session-11 lesson; `_start == _image_start ==
  0x40080000` readelf-verified), raw binary, `-kernel`. Result:
  breath → `arch: arm64` → `kido_main: scheduler init` →
  `3 tasks created` → `ABCABCABCABC` (12 marks, perfect interleave
  — the assembled switch EXECUTED on allocator-backed stacks) →
  timeout 124 in the designed halt spin. ZERO exceptions. This
  re-proves the CURRENT tree on bare metal — sessions 12/13
  (reloc detect, phase-2 .S, actual-bounds, shifted carve) had
  never been QEMU-run; now they have, and the tripwire's delta-0
  path (measure 0, crosscheck agree, proceed) is proven by the
  boot proceeding past it.

## Challenges

- **C1 — the accidental run: salvage or discard?** Answered:
  salvage, with the error owned in the record (P3). The evidence
  (register trace + branch trace + zero exceptions) doesn't care
  about intent; discarding a real relocated proof because it was
  unplanned would be the dishonest move. It is labeled
  "accidental" everywhere it appears.
- **C2 — object ABS64 vs linked RELATIVE on the probe constant:
  does the session-12 gate still count as passed?** Answered (P2):
  yes, with the nuance recorded. The gate's intent was "the linker
  resolved this as an absolute, not a PC-relative value" — true in
  both spellings (ABS64 in the object; unapplied RELATIVE holding
  the linked value in the image; dumped `0x400036c0`). A relative
  relocation would have been `ADR_PREL`-family. The technique is
  sound; the record now states both spellings.
- **C3 — under relocation, does the C world read linked or actual
  for the BSS slots?** Answered empirically (P2/P3): same-TU
  globals are direct PC-relative → ACTUAL. The crosscheck's
  agreement on the relocated run is the proof. The earlier worry
  (GOT → linked slot → permanent stale-slot path) was wrong; the
  disassembly corrected it before any claim was made.
- **C4 — is a second, deliberate relocated run needed?**
  Answered: no. The accidental run's register trace is the
  strongest evidence the harness can produce (actual register
  values, not inferred behavior); replicating at another delta
  would add no new information. Dissent preserved below (D1).

## Convergence

P1–P5 with C1–C4 answered. Deliverables:

- This deliberation record.
- `deliberations/2026-10-18-qemu-phase2-proof.log` — console
  transcripts of both QEMU runs + the register-trace evidence.
- Comment-only updates (no logic changes, pristine sources
  otherwise):
  - `modules/kido-entry-arm64.S` — PROOF STATUS header: the
    "written, not assembled" note is replaced with the closed
    gate (assembled + readelf + disassembly + QEMU, 2026-10-18).
  - `modules/kido-reloc.h` — PROOF STATUS note: the queued
    readelf gate is closed; the ABS64→RELATIVE nuance recorded.
- `architecture/module-map.md` — reloc row: phase-2 proofs
  closed (object gate + delta-0 control + relocated tripwire run).
- Ledger entry (session 14).

Closed by this session: the phase-2 object proof gate (queued
2026-10-17); the relocated-load execution proof (queued in the
session-12 ledger); session-12's declared exposure (relocated
image dying before the tripwire) — empirically; the "current tree
never QEMU-run since session 11" gap.

## Preserved dissent

- **D1 (P3):** a deliberate second relocated run (e.g. link at
  `0x41000000`, delta −0x800000) would exercise the negative-delta
  path on bare metal. Overruled: the negative path is proven on
  hosted (reloc self-test 9–10, image 12, sched shifted-carve),
  and the register trace already gave ground-truth evidence for
  the positive path; a second run would replicate, not extend.
  Named for the phase-3 proof plan instead.

## Conformance

- kido.json "portable and adaptive from the start": the
  relocation machinery is now proven at every level the scaffold
  can reach without N8toriousAi — object encoding, bare-metal
  measurement (both instruments, agreeing), loud refusal, and the
  delta-0 working path. The C world is honestly non-PI
  (GOT-bound, never fixed up); the .S is honestly PC-relative;
  the probe trick is honestly a true delta. No silent invention:
  the one surprise (the harness sed) is owned in the record, and
  the evidence it produced is labeled accidental.
- Scaffold honesty law: nothing booted that N8toriousAi hasn't
  witnessed — these are harness QEMU runs of scaffold drafts, the
  full build plan still queues for his review, and first boot is
  his to witness. The "written, not assembled" notes are updated,
  not deleted: the history stays legible.
- MEDUSA: the behavior reduces to the three equations above; the
  register trace (`X20=0x80000`) is the test that can fail — and
  on the delta-0 run, `X20` would read `0x0` and the boot
  proceeds, which is exactly what happened.
