fix(relinker): preserve EIP-relative jump-table destinations #15639
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15639"
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 boykopovar/AnyPS5. Originally posted by PolkadotDom on 2026-11-03T22:47:51Z.
What
The AMD-only converter misses relative jump tables addressed by
67 LEAwhen the effective address wraps to 32 bits. It then treats a table destination as an instruction it can move into a conversion stub. In the regression, Rosetta conversion of a four-byte vector store consumes the following instruction even though the jump table enters it.For example, an eight-byte LEA at
0x1000with displacement bits0x80000008forms0x80001010. Main looks for the table at0xffffffff80001010instead. The table's second entry targets0x1019, which main moves into the store's stub. With this fix the converter takes the preceding instruction into the stub and leaves the destination at0x1019intact.Truncate the computed table address to 32 bits when the decoder reports the address-size override. Normal RIP-relative table addresses retain their existing behavior. The architecture rule is Intel SDM Volume 2A, §2.2.1.6, reproduced in the Intel documentation changes PDF: the address-size prefix truncates and zero-extends the effective address.
Tested
Base
1c8c0efc8c; candidate8a0ce96cba.relinker,amd64_only_converter_tests,amd64_only_windows_tests,relinker_conversion_testsandrelinker_game_patch_tests.amd64_only_converter,amd64_only_windows,relinker_conversion,relinker_game_patch,relinker_executables,mulx_conversion, andto_rosetta.amd64_only_converter_testsbuilt and its CTest passed.A jump table's address size did not protect the instruction after a 256-bit store.Synthetic code/conversion validation. No PS5 title, Apple/Rosetta execution, GPU testing or full product build was performed.
Native x86-64 jump-table probe
Compile with
g++ -std=c++20 -O2 probe.cpp -o probe, then run./probeon Linux x86-64. The mappings useMAP_FIXED_NOREPLACEand are private to the probe. It verifies the input instruction/addressing semantics; it does not execute the converter's Rosetta output.November 9 overlap follow-up
The later #15903 (
d1166c4c8e) now changes the same table-address expression. A combinedgit merge-treepreview reports a content conflict inAmd64OnlyConverter.cpp. These patches are not interchangeable: its unconditional negative-displacement guard skips a valid EIP-relative table before the address can wrap to 32 bits.Verified on Windows x86-64 with GCC 12.2, using this PR's unchanged head
8a0ce96cba: built and ranamd64_only_convertersuccessfully; temporarily inserted exactly the two displacement guards from #15903 before this PR's table calculation; rebuilt and the existing regression failed withA jump table's address size did not protect the instruction after a 256-bit store. Restored the source byte-for-byte, rebuilt, and the test passed again. This is a focused interaction test, not a build or review of all of #15903.For the documented example,
next = 0x1008and signed displacement-0x7ffffff8form the valid 32-bit address0x80001010; rejecting the intermediate negative 64-bit sum loses that table. The overlap requires an explicit resolution preserving address-size wrapping and this regression. This PR does not depend on #15903 and remains independently applicable; no merge order has been agreed. No production code changed in this follow-up.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T01:53:22Z.
Review: APPROVED
@PolkadotDom thanks, the fix looks right to me. With a
67prefix in 64-bit mode, the RIP-relative form becomes EIP-relative: next-instruction address plusdisp32, truncated to 32 bits (Intel SDM Vol. 2A, §2.2.1.6). Casting the sum tostd::uint32_t(Amd64OnlyConverter.cpp:327) does that and leaves the plain RIP case unchanged.leacomputes only the offset and ignores the segment (SDM Vol. 2A, LEA), and the FS and GS rows in the new test (Amd64OnlyConverterTests.cpp:117) expect the same placement as the unprefixed ones. The0x3000rows check that RIP-relative tables still resolve, and the0x80001010row without67checks that wrapping isn't applied to them.What I ran: head
8a0ce96cbamerged ontomain1c8c0efc8c, Windows 11, WinLibs GCC, relinker-only Release build:amd64_only_converter,amd64_only_windows,relinker_conversion,mulx_conversionandto_rosettapass (5 of 5);Amd64OnlyConverter.cpptaken frommainwith the new test kept:amd64_only_converterfails with "A jump table's address size did not protect the instruction after a 256-bit store";tools/check_conventions.py --base upstream/mainon the head: all checks passed;tools/pr_overlap.py --branch: no shared lines or exports. The tool reported #11192 and #13486 as conflicting withmainand left them uncompared. #13486's diff changes no lines ofsrc/Amd64OnlyConverter.cpp, and #11192 touches only the test file, as you found.Approving.