tooling: add direct-call generators to the CPU fuzz test #1157
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1164"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-24T02:09:47Z.
Refs #446
Adds the direct-call generator claimed in #446 after #927: framed callers that make direct calls and tail jumps to callees from the existing leaf and fixed-frame generators, shared callees reached with different values, a case that observes the expected volatile-register clobbers, and a planted wrong-callee fault. No recursion and no call chains deeper than one level.
Coordination: as agreed in #446 (owner's note and https://github.com/R0Y00/Xbox2Windows/issues/446#issuecomment-7119501743), this is the first direct-call PR. @tedin7 opened #1129 for the same generator; a review of the shared-callee and tail-jump cases, or an independent run of the wrong-callee mutation on Linux/LLVM, would be welcome, and deeper call chains could follow on top.
Change
tools/fuzz_cpu.py --area callsgenerates callers and callees for the sharedcpu_switch_aotlifter from its own seed, in one MASM DLL and one translation. The new CTest iscpu_aot_fuzz_calls; the default is seed0xCA11with 16 callers.fuzz_clobber(below). They keep their generator names, are exported, and are compared on their own as well.PUSHand 32 or 48 bytes are allocated, so RSP is 8 mod 16 from entry at every call and the callee's home space lies below the return address, as #425 requires. The prologue carries.pushregand.allocstack.CALLs. Before each one, RCX, RDX and R8 are defined again from the saved registers, or from RAX after a call. After a call the caller reads only RAX. Every callee may overwrite the volatile registers, and a frame callee also overwrites the nonvolatile registers it saves, often the caller's own.fuzz_clobber. Later calls and tail jumps reach every callee again, and a later call may repeat the previous callee with its result as an argument. RDX gets a displacement that is unique in the program, so callers that share a callee pass it different values.fuzz_call_0andfuzz_call_1first callfuzz_clobberwith different values. It overwrites RAX, RCX, RDX and R8–R11 with values derived from its arguments and writes each one to its output segment before the next replaces it, so the clobbers are compared through memory and RAX, the results a caller may observe.fuzz_clobber_read_r10andfuzz_clobber_read_rcxare in the same DLL but not run: each reads R10 or RCX after callingfuzz_clobber.checktranslates each one alone and fails unless it is refused withundefined register r10orundefined register rcx.JMP calleeafterADD RSPand thePOPs.translate --mutantbuilds a second translation in which the first call of the first caller goes to the next callee in the generated order.check --mutantruns it against native, and the test fails if it never differs. The mutant hook is now per area;frameskeepsreload_shift, and--mutantwith the leaf area is an error in bothtranslateandcheck.cpu_fuzz.asm/.def,cpu_fuzz_lifted.cpp,cpu_fuzz_frames.asm/.def,cpu_fuzz_frames_lifted.cppandcpu_fuzz_frames_mutant.cppare byte-identical tomainin dev and release, and their output lines are unchanged.Measurements
Commit
e916584ona7710b7. Intel Core i7-10700, Windows 11 build 26200, MSVC 19.44.35230, CMake/Ninja, Python 3.12.cpu_aot_fuzz_callsDefault seed contents: 16 callers and 9 callees (
fuzz_clobber, 4 leaf, 4 frame); 35 calls and 6 tail jumps; 19 reach a frame callee, 14 of them one that saves a register the caller keeps a value in; 6 calls repeat the previous callee; 17 arguments are derived from RAX; 4 callers keep a spill across their calls; every callee is reached by at least two callers. For input(0x1234, 0x5678)the two nativefuzz_clobbersegments differ, as intended.The mutant changes one call site in the generated C++ (
fuzz_call_0's call tofuzz_clobbergoes tofuzz_1) and changes all 313 results of that caller.Failure paths, run by hand against the dev build:
fuzz_call_0input 0, with the native and translated RAX, the first differing output byte, the MASM of the caller and its callees, and thereproduce:line. That command repeats the case.--mutant. Exit 1,the planted translator fault was not detected.--mutantwith the leaf area. Exit 1,no planted translator fault for --area leaf, from bothtranslateandcheck.fuzz_clobber_read_r10 refused for another reason: undefined register r10 at RVA ....... was translated; expected refusal: undefined register rcx.Longer manual run:
cmake --preset dev -DCPU_FUZZ_CALLS_SEED=<seed> -DCPU_FUZZ_CALLS_FUNCTIONS=128, then the same test.0x10x20xBEEF0xCCD1Both controls were refused as expected at every seed.
Wider checks:
ctest --preset dev --no-tests=error -R '^cpu_': 212/212 pass, with 2 capability skips (cpu_aot_fences_hints_clwb,cpu_aot_crypto_sha).tests/docs_links_check.py(15 files, 252 links),tests/bidi_controls_check.pyandgit diff --checkpass.Not run: MSVC 19.52, Linux, more than 128 callers.
Scope
Callees come only from the leaf and frame generators plus
fuzz_clobber, so the call graph is one level deep. Recursion, indirect calls, import calls, mid-body RSP changes and fault equivalence are not generated. Deeper chains and conditional calls, as in #1129, could follow on top.docs/experiments.mdgains acpu_aot_fuzz_callsparagraph in the fuzz section.AI-assisted.