From c73f05b0521b06171617e90960cc95006723652e Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 13 Sep 2026 09:15:50 +0700 Subject: [PATCH] Disassembly on request, and it is a debugging aid rather than evidence SPIKE_DISASM=1 objdumps the exact buffers that ran. Kept behind a flag and kept out of the pass/fail path: a disassembly that reads correctly beside a function answering the wrong number is the normal outcome of hand-encoding. --- spike/backend/driver.ml | 19 +++++++++++++------ spike/backend/run.sh | 12 +++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/spike/backend/driver.ml b/spike/backend/driver.ml index 99deda9..fde8ce4 100644 --- a/spike/backend/driver.ml +++ b/spike/backend/driver.ml @@ -96,12 +96,19 @@ let run src = Hashtbl.iter (fun n c -> Printf.printf " %-20s %4d bytes at %nx\n" n (String.length c) (Hashtbl.find addrs n)) bytes; - (* Dumped so oracle.sh can disassemble exactly the bytes that ran. *) - (try - let oc = open_out_bin (Filename.concat (Filename.dirname Sys.argv.(0)) "spike-add.bin") in - output_string oc (Hashtbl.find bytes "spike-add"); - close_out oc - with Not_found -> ()); + (* The bytes that actually ran, dumped where run.sh can objdump them. + A debugging aid and not the evidence: a disassembly that reads correctly + next to a function that answers 656 when it should answer 650 is the + normal outcome of hand-encoding, which is why the checks below compare + numbers. *) + (match Sys.getenv_opt "SPIKE_DUMP" with + | None -> () + | Some dir -> + Hashtbl.iter + (fun n c -> + let oc = open_out_bin (Filename.concat dir (n ^ ".bin")) in + output_string oc c; close_out oc) + bytes); (* ── The SysV boundary ────────────────────────────────────────────── Three synthetic functions, built as Tast by hand rather than written in diff --git a/spike/backend/run.sh b/spike/backend/run.sh index 1ed4a01..bdef39b 100644 --- a/spike/backend/run.sh +++ b/spike/backend/run.sh @@ -32,7 +32,17 @@ ocamlfind ocamlopt -thread -package unix,threads.posix -linkpkg \ test -x "$out/spike" || { echo "build failed"; exit 1; } -"$out/spike" "$here/probe.flan" +SPIKE_DUMP=$out "$out/spike" "$here/probe.flan" rc=$? + +# Disassembly on request. objdump over the raw buffer, which is what to reach +# for when a function answers the wrong number -- not what proves it answers +# the right one. +if [ "${SPIKE_DISASM:-}" = 1 ]; then + for f in "$out"/*.bin; do + echo; echo "== $(basename "$f" .bin)" + objdump -D -b binary -m i386:x86-64 -M intel "$f" | tail -n +7 + done +fi echo "exit: $rc" exit $rc