relinker --to-rosetta: signed integer overflow in Amd64OnlyConverter island placement for a code segment mapped across 2^63 #11198
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 zaryabzip on 2026-10-25T21:41:24Z.
What happens
In
--to-rosetta256-bit store lowering,_islandAtand_buildIslandsubtract addresses asstd::int64_t. In a code segment that crosses 2^63 this overflows:Amd64OnlyConverter.cpp:169:66: runtime error: signed integer overflow: -9223372036854775804 - 9223372036854775799 cannot be represented in type 'std::int64_t'.Title, test or build step
The island case of
converterWideStoreWindows(core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp:853-865), run with the code segment mapped at0x8000000000000000 - 0x10instead of0x1000. No retail title.AnyPS5 commit
main9c6d153dec, with no PRs on top.System
macOS 27.0 arm64, Apple clang 21.0.0,
-fsanitize=undefined -fno-sanitize-recover=undefined. The converter runs as plain C++ here, so no x86-64 host was needed.Steps to reproduce
IslandRepro.cpp. It uses the same bytes as the existing island case and converts them at both base addresses:core/relinker, compile it with the sources of theamd64_only_converter_teststarget (core/relinker/CMakeLists.txt) in place of the test file, then run it: It stops at once.Log
Built with
-fsanitize=signed-integer-overflow, so that it carries on after each report, the same run also reports the other three subtractions in the island path:What was checked
The four sites:
reachin_islandAt.Seekback to the store in_buildIsland.JumpToafter the store.In every case the store is just below 2^63 and the island is just above it. The true distance is a few bytes, but the signed operands have opposite signs, so the difference cannot be represented.
Without sanitizers (
-O2), both bases print2 trampolines, short jump EB 0D, the same bytes as the existing test expects at 0x1000. The wrapped difference is correct in practice, so this is undefined behaviour in a malformed-address case, with no wrong output seen.The fixture's
E8andEB FDbranches stay below 2^63, so_collectBranchTargetsline 282 (#10653, fixed in #10680 and #11033) is not reached first. #10680 changes only lines 277-290, so this path is separate.I reproduced this through
Convertdirectly, not through a crafted ELF on therelinkercommand line.Same result every run.
One possible fix is to subtract the addresses as
std::uint64_tand check the range afterwards, as thedisplacementhelper inelfpatcher/src/linux/LinuxGuestModuleWriter.cpp:255-266does.