fix(relinker): find relative jump tables across 2^63 without signed overflow #23003
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23003"
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 descambiado on 2026-11-18T16:38:10Z.
What
FindRelativeJumpTablesforms a branch or lea target asstatic_cast<std::int64_t>(address) + displacement. For a segment mapped at or above 2^63 and a negative displacement the sum overflows. UBSan reports it onmain:RelativeJumpTables.cpp:335:28: runtime error: signed integer overflow: -9223372036854775806 + -16 cannot be represented in type 'long int'.It is the same class as #10653 and #11198, in four sites of this file:
IsValid64BitInstruction, the function walk, the gap walk and the lea candidate search. The signed comparisons also misjudge a segment that straddles 2^63.FindRelativeJumpTablesruns for every executable segment inRelinkerPipeline.cpp, not only with--to-intel.The four sites now add as unsigned and reject a wrapped target through
RelativeTarget, as #10680 did inAmd64OnlyConverter. The two offset-only sites in the file (TableEntriesand the load scan) work on code offsets, not virtual addresses, and are unchanged.Tested
Ubuntu 24.04 (WSL2), GCC 13.3, relinker-only build with
-fsanitize=undefined -fno-sanitize-recover=undefined, head2058bcdonmain01c8c4c.control_flow_graph_testswith the newCheckRelativeJumpTablesAtHighBasesand without the fix aborts atRelativeJumpTables.cpp:335:28. With the fix it passes.conventions_unknown_nids, timed out at 20 s under the load of 14 parallel UBSan jobs and passes alone in 2.4 s.tools/check_conventions.py --base upstream/mainpasses.shader_ir_use_rewrite_tests,request_serializer_tests) do not link with this plain-fsanitize=undefinedflag set. They do not use the changed code.Not tested: Windows, macOS, any title, and no end-to-end run of the CLI on a crafted ELF. I reached the function by calling
FindRelativeJumpTablesdirectly; its caller isRelinkerPipeline.cpp:508.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-18T16:39:30Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
2058bcd7db:tools/check_conventions.pypassed.control_flow_graph_testsbuilt cleanly.control_flow_graph):core/relinker/relinker/src/analysis/RelativeJumpTables.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-19T13:17:24Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the high-address target arithmetic and its regression coverage look sound based on the files reviewed.
What I ran
Reviewed head
2058bcd7db77a135fc480d1e57d5a6881bae85e0using the prepared description, commit list, manifest, diff, andrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. The author reports UBSan and relinker test results; these were not independently verified. No CLI run, Windows or macOS run, or physical-console behavior was verified. The complete contents of both changed files were read;
files.jsonwas not available in the prepared bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by edglz on 2026-11-20T22:40:12Z.
Review: APPROVED
Summary
static_cast<std::int64_t>(address) + displacementoverflows for segments at or above 2^63, and the signed comparisons misjudge segments straddling 2^63.RelativeTargetadds in unsigned arithmetic and detects wrap by comparing against the next-instruction address, which is the same approach as #10680 inAmd64OnlyConverter, applied to all four sites.Verification
Environment: macOS 26, Apple M4 (arm64), Apple clang 21.0.0, CMake relinker-only Release build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON), PR diff applied on currentmain.control_flow_graph_testswith UBSan (-fsanitize=undefined -fno-sanitize-recover=undefined) andRelativeJumpTables.cpprevertedRelativeJumpTables.cpp:335: signed integer overflow: -9223372036854775806 + -16Notes
As the description says, the new test only guards the change in sanitizer builds; in Release the overflow wraps silently.
Verdict
Approved.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T01:59:44Z.
Review: APPROVED
Reviewed — looks good
The changed address calculations use unsigned wrap detection, and the added tests cover high virtual address bases; the review found no verified blocking defects.
What I ran
Reviewed head
d61121a16f1c674e20b22d486af14a5edc0b5142. I inspected the prepared diff and both changed files, plus theVirtualAddressalias. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Builds, tests, Windows and macOS behavior, and end-to-end CLI behavior were not independently verified.
files.jsonwas unavailable; the manifest lists both changed files as included, and both were read. No files were excluded in the manifest.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.