Repository navigation
Harden and oracle-validate the single-core x86-64 JIT - #12
Merged
Merged
Conversation
jit_test's x86 execute-vs-oracle section was skipped, so the single-core x86 emitters had never been run against the interpreter -- the same blind spot that hid the ARM64 bugs until PR #11. Enabled an x86 execute-against-oracle harness (runs under x86/QEMU, cleanly skipped on arm64 hosts) and audited every single-core x86 emitter. Fixed: LD8 emitted MOV r8,[rdi+off] (writes only bits 0-7) plus a 64-bit self-move, leaving bits 8-63 as register-allocator garbage so compares after LD8 diverged -- now MOVZX r32,byte (zero-extends the full 64-bit reg). LD16 used a 16-bit MOV plus BSWAP r16 (architecturally undefined for a 16-bit operand) -- now MOVZX r32,word plus ROR r16,8 for ntohs. LD32 verified (32-bit MOV auto-zero-extends; BSWAP r32 = ntohl). All three loads now emit a packet-bounds check returning VFM_ERROR_BOUNDS to match the interpreter on out-of-bounds offsets instead of reading adjacent memory. Also fixed two latent silent-wrong-code bugs found in the audit: the register allocator (a monotonic counter) aliased every allocation past the 8th onto R8 for programs with >8 cumulative pushes -- now liveness-based and declines on exhaustion; and the prologue/epilogue did not preserve callee-saved R12-R15 (an ABI violation at stack depth >= 5) -- now preserved. Demoted to interpreter fallback (return NULL via a shared decline path: free + munmap) rather than emit wrong code: DIV (DIV r64 raises #DE/SIGFPE on a packet-driven zero divisor where the interpreter returns DIVISION_BY_ZERO); JEQ/JNE/JGT/JLT/JMP (the target was computed as offset*16 -- an arbitrary address -- with signed jumps for the interpreter's unsigned compares; correct branching needs a two-pass pc->offset fixup not implemented here); LD128/EQ128 (stack-slot order and hard-coded relative displacements diverged). PUSH/ADD/SUB/MUL/AND/OR/XOR/SHL/SHR/NOT/NEG/DUP/SWAP/POP/RET validated correct against the oracle. Updated test_jit_declines_unsupported_opcode's x86 'supported' sample to branch-free opcodes {LD16,PUSH,ADD,RET}: the old sample only compiled non-NULL because the broken branch emitter produced a non-NULL page of wrong code (the blind spot itself). The JGE unsupported->NULL assertion is unchanged. Single-core ARM64 compiler, the multicore path, and the interpreter are untouched. Verified on Docker linux/amd64 (gcc, QEMU executes x86): 16/16, the x86 JIT==interpreter oracle across loads/arith/compare incl. proto==6 LD8+XOR and an OOB load, ASan clean, and an LD8 before(diverges: returns a dirtied high-bits value)/after(matches: 6) check. macOS/arm64: 16/16, the x86 harness cleanly skipped, the x86 emitters still compile, no regression to ARM64 execution / multicore / cache-UAF tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #11. The x86
jit_testexecute-vs-oracle section was skipped, so the single-core x86 emitters had never been run against the interpreter — the exact blind spot that hid the ARM64 bugs. This enables that harness (x86/QEMU; cleanly skipped on arm64) and audits every single-core x86 emitter.Fixed
MOV r8,[rdi+off](writes only bits 0–7) + a 64-bit self-move, leaving bits 8–63 as register-allocator garbage so compares afterLD8diverged. NowMOVZX r32, byte(full zero-extend). This is the x86 twin of the ARM64 bug Fix JIT silently dropping unsupported opcodes (port/proto filters wrong on Apple Silicon) #10 fixed.MOV+BSWAP r16(architecturally undefined for a 16-bit operand). NowMOVZX r32, word+ROR r16,8for ntohs.BSWAP r32= ntohl). All three loads now bounds-check and returnVFM_ERROR_BOUNDSon OOB offsets, matching the interpreter instead of reading adjacent memory.R8(silent wrong code for >8 cumulative pushes); now liveness-based, declines on exhaustion.R12–R15(was an ABI violation at stack depth ≥ 5).Demoted to interpreter fallback (decline → NULL) instead of emitting wrong code
offset * 16(an arbitrary address), with signed jumps for the interpreter's unsigned compares. Correct branching needs a two-pass pc→offset fixup not implemented here.DIV r64raises #DE/SIGFPE on a packet-driven zero divisor where the interpreter returnsDIVISION_BY_ZERO.Net: the x86 JIT now runs its proven-safe subset (loads + arithmetic + stack ops) and falls back to the interpreter for the rest — same posture as ARM64. The single-core ARM64 compiler, the multicore path, and the interpreter are untouched.
Tests
test_jit_declines_unsupported_opcode's x86 "supported" sample changed to branch-free{LD16,PUSH,ADD,RET}(the old sample only compiled non-NULL because of the broken branch emitter). New x86 execute-vs-oracle suite in jit_test.Verification
proto==6LD8+XOR and an OOB load; ASan clean;LD8before (diverges) / after (matches 6).