fix(relinker): collect --to-intel branch targets without signed overflow #10680
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10680"
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 dkdhanda8 on 2026-10-24T17:21:59Z.
What
_collectBranchTargetsadded the branch displacement to the next instruction address asstd::int64_t. For an executable segment mapped at or above 2^63 the sum overflows and is undefined behaviour; the fuzzer repro attached to #10653 reportssigned integer overflowatAmd64OnlyConverter.cpp:282. The addresses now add as unsigned values: a target that wraps past 2^64 is dropped, and every other target — including ones at or above 2^63, which the oldtarget >= 0check always dropped — goes through the same past-prefix and AMD-only checks as at lower addresses. The LEA jump-table path adds its displacement unsigned too; that is bit-identical to before without the overflow.The consequence noted in the issue is also gone: a branch into an AMD-only instruction in a segment mapped across 2^63 was silently accepted before, and is now refused as at lower addresses.
Changed:
core/relinker/codegen/src/Amd64OnlyConverter.cpp. The regression case inAmd64OnlyConverterTests.cppmapssegmentFixtureat0x8000000000000000and asserts that the plain fixture still converts, a branch into the INSERTQ site is refused, and a backward branch whose sum stays below 2^64 does not change the conversion.Method: the
overflow-repro.elfattached to #10653 (SHA-2563636a37f7422a0eaf3b247a22a65fdb730101666cdea934bda996daeda1cc2c4, verified) run under a relinker built with-fsanitize=undefined -fsanitize-undefined-trap-on-error: it traps onmainand converts without a trap with this change. The new test case fails onmain(the branch was accepted) and passes with the change, also under the trap-on-error build.Fixes: #10653
Branch:
fix/relinker-to-intel-branch-target-overflow, based onmain137a8fab8.Tested
amd64_only_converter_testspasses with the change and fails without it on the new case; the whole converter suite also passes under-fsanitize=undefined -fsanitize-undefined-trap-on-error.relinker --skip-sce-module --to-intel overflow-repro.elf outproduces identical output onmainand with the change (exit 2,FAIL: ET_NONE inputs do not specify an ELF object type).cteston the relinker-only build (Windows 11, MinGW-w64 GCC 15.2.0x86_64-ucrt-posix-sehr7, Ninja, Release): the failure set is identical tomainand is caused by this machine's Application Control policy refusing to execute freshly relinked outputs (WinError 4551), not by the change; the converter test binaries additionally pass under the trap-on-error UBSan build.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repository (attach them to this PR)AI-assisted (ZCode): the fix, the regression test and the local verification were prepared with AI assistance; every line was reviewed and the fuzzer repro and sanitizer runs were executed locally.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T18:48:18Z.
Review: APPROVED
Reviewed head
bec41e57aed60eb9eedfd8724d4098d4cde22be7against currentmain(0ea0f25e1bfbf63e90bc28a3ca1bc4cd2a3972f6). The unsigned conversion and direction-specific wrap test avoid signed-overflow UB while preserving modulo address arithmetic; the backward-branch case crosses the signed boundary and the forward case still rejects a branch into the AMD-only instruction. I verified the exact-head relinker-only target builds. The full registered converter CTest executable aborts withSIGILLon this host; in the isolated worktree I narrowed its test entry point to the newconverterSegmentMappedAtInt64Maxregression, ran that through CTest (1/1 passed), and restored the source. The PR also reports the full converter suite and fuzzer reproduction under trap-on-error UBSan on Windows.git diff --check, the current-main conventions checker, and merge-tree pass; the current base has not changed either modified converter file. Automatic hosted relinker jobs are absent for this contributor, and I do not have repository admin rights to dispatch them. No blocking source issue found.