Repository navigation
feat(relinker): lower SHA-256 instructions with a memory operand - #434
Conversation
|
The memory operand handling looks right to me (the spill depth for RSP bases, R12 not treated as RSP, xmm0 kept out of the scratch). The only thing left is the TechnicalDebt line: now that #430 has landed, main's |
SHA256RNDS2/MSG1/MSG2 with a memory source made `--to-intel` fail the whole relink. The stub now spills a scratch xmm, loads the operand into it with MOVDQU (AMD does not fault on a misaligned SHA operand, so the unaligned load keeps that behaviour) and runs the register-form lowering. RSP-based operands get the spill depth added to their displacement. RIP-relative operands still fail: the stub runs at a different address. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
f0df7f2 to
d43a548
Compare
|
Thanks! Rebased onto main (with #430) and updated the TechnicalDebt line: it now says SHA-1 instructions with a memory operand and SHA-256 instructions with a RIP-relative operand fail the relink. The latter still throw in |
|
Thanks for the quick update, that covers it. I'll test it here and merge once CI is green. |
Takes the 13 gate-batch PRs that merged upstream (boykopovar#319 boykopovar#329 boykopovar#330 boykopovar#331 boykopovar#325 boykopovar#435 boykopovar#471 boykopovar#294 boykopovar#376 boykopovar#404 boykopovar#394 boykopovar#401 boykopovar#446) in place of astrobot's local versions, as integ/gate-batch cab0eab had them: boykopovar#294 and boykopovar#376 in astrobot's depth model (DepthTarget, state.depth), boykopovar#394 with the thick mip tails, boykopovar#401 over astrobot's slab pool, boykopovar#471 keeping the settled single-lane path. Also takes the rest of main since a818bee (boykopovar#532 boykopovar#340 boykopovar#486 boykopovar#484 boykopovar#316 boykopovar#243 boykopovar#334 boykopovar#434 boykopovar#437 boykopovar#470 boykopovar#373 boykopovar#452 boykopovar#455 and our upstreamed PRs, where astrobot keeps its later revisions and env switches). Resolution notes: relinker converter/matcher/tests are upstream's (boykopovar#432 decoder covers VEX RIP-relative followers); RecompileResult gains boykopovar#316's hostSubgroupSize (set from request.target.subgroupSize); shader disk cache format 9; boykopovar#452's scissor message; upstream's later live-stack and memory-copy decode tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mgp3oZvembQziVNE2xARQK
What
--to-intelthrew on SHA256RNDS2/MSG1/MSG2 with a memory source ("SHA-256 instruction with a memory operand"), so one such instruction failed the whole relink. Compilers fold loads into these instructions (sha256msg1 xmm1, [rsp+0x20]), so real code can contain them.Fix:
DecodeSha256now decodes the memory operand (DecodeMemoryOperandinStubBodyBuilder: segment/67h prefixes, REX.X/B, ModRM, SIB, displacement) instead of throwing.movdqu, runs the existing register-form lowering with that register as the source, then restores it.StubBodyBuilderkeeps track of how far its spills have movedrsp. An RSP-based operand gets that depth added to its displacement, and is always re-encoded with a disp32. R12 (base 100 with REX.B) is not treated as RSP.movdqu, notmovdqa: on this AMD host a misalignedsha256msg1 xmm1, [mem]does not fault, so the aligned load would add a fault the original didn't have.docs/dev/TechnicalDebt.mdline 55 still says SHA-256 memory forms fail the relink. #430 rewrites that same line. I left it alone so the two PRs don't conflict. Once both are merged, it should say that only RIP-relative SHA-1/SHA-256 operands fail. I can do that in a follow-up, or you can fold it into #430.Tested
Linux x86-64 (Ryzen 5 7535HS, Zen 3+, has SHA-NI), no title.
Amd64OnlyConverterTests.cpp:sha256Operands: decodes a GS + 67h + REX.R + SIB + disp8 form, R12 base vs RSP base, SIB without a base (disp32), and rejects RIP-relative and truncated operands.sha256Execution: runs each op through the stub with[rcx],[rsp+0x18],[rsp+rax*1+0x08](rax = 16),cs: [r12]and[rcx+disp32], compared against the reference. The harness now also checks that xmm1 survives (it is the scratch picked for these forms).converterSha256: the memory form now becomes a trampoline; the RIP-relative form still fails at its file offset.mainthe new execution and converter checks fail with "SHA-256 instruction with a memory operand" (the decode checks don't compile there becauseMemorydoesn't exist yet).MatchSequencethat mix them with the SSE4a and SHA-256 register forms. 0 mismatches for the memory forms (37 200 runs per op). On the full set, the only mismatches are the sequences where the fix(relinker): zero dst[127:64] in EXTRQ and INSERTQ lowerings #433 bug affects SSE4a. With fix(relinker): zero dst[127:64] in EXTRQ and INSERTQ lowerings #433 applied too: 432 720 runs, 0 mismatches. The harness catches a missing spill-depth adjustment (22 140 mismatches) and R12 treated as RSP (7 560).ctest: 125/125.git merge-treeagainst every open relinker PR (Add bounds checking for relocation entries in RelinkerPipeline and up… #298 fix(relinker): tolerate trailing data in TLS scan #299 fix(relinker): load Windows guest TLS values at signed displacements #340 fix(relinker): add icons to generated Windows executables #350 feat(relinker): write a desktop entry with the game icon for Linux executables #353 fix(relinker): reject outputs that overwrite the input file #356 fix(relinker): hand the guest the real argv on Linux #418 feat(relinker): lower SHA-1 instructions for --to-intel #430 test(relinker): add C++ end-to-end fixture and --to-intel Linux stub test #431 fix(relinker): report RIP-relative operands of VEX, EVEX and 0F38/0F3A instructions #432 fix(relinker): zero dst[127:64] in EXTRQ and INSERTQ lowerings #433): clean.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a).mdfiles or images added to the repository (attach them to this PR)