fix(relinker): preserve jump tables formed by 32-bit LEA #19569
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19569"
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-13T15:08:54Z.
What
The AMD-only converter's jump-table scan accounts for 32-bit addressing but not for LEA's 32-bit destination. A RIP-relative
lea ..., %ecxtruncates the result to 32 bits even without67. Missing that table allows a vector-store conversion to move an instruction that the table jumps to.Truncate the table address when LEA has a 32-bit operand, in addition to the existing address-size rule. REX.W takes precedence over
66; a partial 16-bit destination is not newly interpreted as a zero-extended 32-bit address. The existing test matrix now covers default 32-bit operands, REX.W, and66plus REX.W, with RIP/EIP, no segment/FS/GS, and normal/wrapping displacements.For the six-byte LEA at
0x1000, the displacement to table0x8000100esign-extends to an intermediate high address; the ECX result is0x8000100e. The converter must preserve the second table destination after the four-byte store. The regression checks both placement and destination bytes.Semantics: Intel SDM Volume 2A, LEA, 64-bit Mode LEA Operation with Address and Operand Size Attributes (Intel manual).
Tested
Updated November 21 on main
e60b2f74ad. The table-address overflow guard now applies to full-width arithmetic. A 32-bit operand or address size still truncates the table base. Relative entries retain main’s existing checks. Rebuilt the Windows converter target and passedamd64_only_converter, including the 36-case matrix. The November 15 overlap notes below describe the earlier base.Updated November 15: rebased onto current main
03f9083042ascc723fb7f6. The rebase applied without a manual conflict resolution; the LEA-width fix and its 36-case regression are unchanged. Rebuilt the relinker and converter, Windows converter, conversion and game-patch targets on Windows (GCC 12.2, Release relinker-only); all seven focused CTests below pass. Rebuilt and passedamd64_only_converteron Ubuntu/WSL (GCC 11.4). A fresh negative control using this main's production file fails the regression (CTest exit 8); restoring this head passes. Conventions and whitespace pass. Earlier results and the overlap assessment below retain their original pins.Base
19ba356e59; candidatef46a0a31ec.amd64_only_converter,amd64_only_windows,relinker_conversion,relinker_game_patch,relinker_executables,mulx_conversion,to_rosetta.amd64_only_converter_testsand its CTest passes.amd64_only_converterfail withA jump table's address or operand size did not protect the instruction after a 256-bit store. Restoring the fix and rebuilding passes.c612c4c9e8is clean. The overlap scan checked 1,515 current open PRs, verifying 1,512 cached head hashes and fetching three changed/missing heads plus main. Exit 2 reports three branches already conflicting with main; all shared-file diffs were inspected manually. #11525 changes embedded-data masking and its separate test; #12678 adds the bit-permutation option. Neither changes LEA operand-width handling. #15903 adds unconditional displacement-wrap rejection in this same routine and already conflicts with the merged #15639 address-size fix. Those guards would skip valid wrapping LEAs; this PR does not adopt or depend on them. Their interaction still requires explicit resolution when #15903 is rebased; no clean combined merge or agreed ordering is claimed.Synthetic conversion and native input-instruction validation only; no PS5 binary/title, Apple/Rosetta execution, GPU run or full product build.
Native jump-table probe
Compile with
g++ -std=c++20 -O2 probe.cpp -o probeand run on Linux x86-64. Its mappings are private and useMAP_FIXED_NOREPLACE.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 PrivacyOnion on 2026-11-13T17:47:19Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f46a0a31ec:tools/check_conventions.pypassed;git diff --checkclean.amd64_only_converter_testsbuilt cleanly.amd64_only_converter):core/relinker/codegen/src/Amd64OnlyConverter.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:59:44Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation and regression tests support the stated LEA width handling.
What I ran
Reviewed head
cc723fb7f6554cd65b57e545fd41d7052f0f16e3usingrepo_read.pyto read the prepared diff and relevant source ranges. No tests were run by me.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were executed during this review. The author reports passing focused tests and a negative control in the PR description; those runs were not independently verified. No PS5 binary, title, Apple/Rosetta execution, GPU run, or full product build was inspected. The review folder’s
files.jsonwas not available through the reader; manifest lists two changed files, both included and read. Excluded files: not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T01:15:22Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed change adds LEA operand-width handling to jump-table discovery, and the inspected code supports the stated 32-bit truncation behavior.
What I ran
Inspected head
dbe2b6c7e8443ff6ee63a98fad7739bf1a7421ausingrepo_read.py; no commands or tests were run in this environment.Read the prepared description, commits, manifest, diff, and the changed functions and relevant decoder definitions in
core/relinker/codegen/src/Amd64OnlyConverter.cpp,core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp,core/relinker/codegen/src/x86/X64InstructionDecoder.cpp, andcore/relinker/codegen/include/codegen/x86/X64OpcodeConstants.hpp. The manifest lists both changed files as included; no changed files are listed as excluded.Results
Negative control
Not run in this environment. The description reports that reverting the production change makes the regression fail.
Findings
Blocking
None.
Non-blocking
None.
Sources
The changed logic derives 32-bit table-address truncation from address size or default-width LEA, while REX.W takes precedence over the operand-size prefix (
core/relinker/codegen/src/Amd64OnlyConverter.cpp:327-337). The added matrix covers default-width LEA, REX.W, REX.W with66, address-size override, segment prefixes, and low and high table addresses (core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp:1211-1245).Not verified
The reported Windows and Ubuntu/WSL builds, CTests, native probe, and negative control were not independently run. No PS5 binary or title, Apple/Rosetta execution, GPU run, or full product build was verified, as the description also notes.
To get this to a good state
Nothing is required. Optional: retain the reported focused build and test coverage when updating the PR head.