fix(relinker): limit --to-intel conversion to code extent in SCE binaries #20389
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20389"
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 Gag21 on 2026-11-15T04:13:55Z.
What
In binaries with a
PT_SCE_DYNLIBDATAsegment (PS4 executables and modules), read-only data is packed into the executable segment after the code and between functions.Amd64OnlyConverterscanned the entire segment up toph.FileSizewithout passing unwind ranges toInstructionScanner, causingX64InstructionDecoderto throw when encountering non-code bytes (e.g. consecutive0xF0bytes exceeding instruction length).This change exposes
FindCodeSegmentExtentsinSceCodeExtent, usingFindSceCodeEndand unwind ranges to determine the valid code extents and gaps in SCE segments.IAmd64OnlyConverter::Convertnow accepts optionalCodeSegmentExtents, which the pipeline andGuestModuleBuilderpass when converting for Intel/Rosetta/AVX.InstructionScanneris configured with unwind ranges so that gap data between functions is skipped, and scanning stops at the code end before trailing data.Tested
Windows 11:
amd64_only_converter_testspassed with new test coverage for code segment extents skipping trailing non-code data; verified relinker--windows --to-intelon a PS4 game dump with post-code read-only data in the executable segment completes 100% without decoder failure.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T04:55:21Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
49b5b3e357:tools/check_conventions.pypassed;git diff --checkclean.amd64_only_converter_testsbuilt cleanly.amd64_only_converter):core/relinker/codegen/include/codegen/IAmd64OnlyConverter.hpp,core/relinker/codegen/src/Amd64OnlyConverter.cpp,core/relinker/relinker/include/relinker/analysis/SceCodeExtent.hpp,core/relinker/relinker/src/analysis/SceCodeExtent.cpp,core/relinker/relinker/src/guest/GuestModuleBuilder.cpp,core/relinker/relinker/src/pipeline/Conversion.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by babuakhil on 2026-11-15T16:13:50Z.
Review: APPROVED
Windows check of head
49b5b3e357, applied ontomain08de9f4f1f(clean apply).Setup: Windows 11 Pro 10.0.26200, AMD Ryzen 7 5700X, WinLibs GCC 15.2.0 (
x86_64-ucrt-posix-seh, r7), CMake 4.5.0, Ninja 1.13.2, Release, relinker-only build withBUILD_TESTING=ON.amd64_only_converter,amd64_only_windows,sce_code_extent,sce_module_code_extent,to_intel_linux_stubs,guest_intel_trampolinesandguest_intel_trampolines_executionpass in 3 of 3 runs.Amd64OnlyConverter::_convertSegmentput back to the whole segment (ScanCodeSection(seg, 0, seg.size())instead ofcodeSize), the interface and the rest of the change kept,amd64_only_converterbuilds and fails inconverterCodeSegmentExtentswithCannot decode instruction: Instruction exceeds 15 bytes, the 0xF0 trailing-data failure from the description. Restoring the line makes it pass again.Not checked: a
--to-intelconversion of a PS4 title.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by babuakhil on 2026-11-15T16:21:12Z.
Review: COMMENTED
Follow-up to my Windows check, from reading the rest of the diff at
49b5b3e357. The tests above still hold; one point on scope and two small ones.Unwind ranges are also passed for non-SCE images.
FindCodeSegmentExtentscomputesunwindRangeswheneverhasEhFrameis true, andhasEhFrameissceImage || PT_GNU_EH_FRAME present. So a PS5 executable or module withoutPT_SCE_DYNLIBDATAbut withPT_GNU_EH_FRAMEnow gets unwind ranges in the--to-intelscan. With unwind ranges,InstructionScannerskips bytes outside every unwind function that do not decode and ends a decoding outside them at the next unwind function, where before this change such a decode failure stopped the conversion. The two existing scans limit this to SCE images:RelinkerPipeline.cpp:segmentUnwindRanges[index] = SceUnwindRanges(...)is set only insideif (sceImage).GuestModuleBuilder.cpp:scanUnwindRanges = sceImage ? SceUnwindRanges(...) : std::vector<CodeRange>{}.The title, the description and the updated
relinker.mdentry describe SCE binaries only. Unless the PS5 case is intended,if (sceImage)instead ofif (hasEhFrame)around the unwind ranges inFindCodeSegmentExtentswould match the other two scans. This is from reading the code; I have no PS5 image that shows a difference.Smaller points:
FindCodeSegmentExtentsor the wiring inConversion.cppandGuestModuleBuilder.cpp:converterCodeSegmentExtentspasses a hand-made extent to the converter. A case for an SCE image (code size clipped at the code end) and a non-SCE image (full size, and whichever unwind ranges are intended) would pin both.Conversion.cppreadsDT_SCE_PLTGOT/DT_PLTGOTandDT_SCE_PLTRELSZ/DT_PLTRELSZby taking the last matching tag, whileRelinkerPipelinerequires exactly one of each pair. It only feedsFindSceCodeEndhere, so it is minor.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T03:59:12Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
49b5b3e357b925f3eb093c13badebfe9908fbd77, basemain. Read from the pinned diff; no merge preview.The two alternation searches returned no matches.
Results
converterCodeSegmentExtentsFindings
Blocking
None.
Non-blocking
core/relinker/relinker/src/pipeline/Conversion.cpp:92:--to-intelnow callsFindCodeSegmentExtents, which callsFindSceCodeEndfor every SCE executable segment (core/relinker/relinker/src/analysis/SceCodeExtent.cpp:68).FindSceCodeEndthrows when no PLT is found or when the PLT overlaps an unwind function (SceCodeExtent.cpp:33,:40,:44,:47). Before this change--to-intelnever reached that code, so an image that converted before could now fail. I did not reproduce this, and I do not know whether such images exist. Either fall back to the full segment when that throw happens, or confirm on a real dump that the PLT is always found.core/relinker/relinker/src/guest/GuestModuleBuilder.cpp:479: the unwind table is now read from the bytes before conversion. Before, it was read after. This is a behaviour change with no test, and the description does not mention it. It is probably the safer order, but say so in the description or confirm that the unwind table never sits inside a rewritten range.Not verified
converterCodeSegmentExtentstest were not run. Reading the fixture (core/relinker/codegen/tests/Amd64OnlyConverterTests.cpp,segmentFixture): the 20 bytes of code end at offset 0x213, and the extent is 20 bytes, so the trailing0xF0bytes lie outside it. The expected counts (one replacement, two reports, one trampoline) were not checked.--windows --to-intelrun on a PS4 dump are author-reported. I did not repeat them.FindSceCodeEndthrow in point 1.To get this to a good state
Nothing is required.
Optional:
FindSceCodeEndthrow on the--to-intelpath (point 1).Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T12:19:07Z.
Review: COMMENTED
Actionable comments posted: 1
509e641e-69b1-44be-b153-b4c0829bd390Reviewing files that changed from the base of the PR and between
f51f7fec91and3e60875939.core/relinker/codegen/include/codegen/IAmd64OnlyConverter.hppcore/relinker/codegen/src/Amd64OnlyConverter.cppcore/relinker/codegen/tests/Amd64OnlyConverterTests.cppcore/relinker/relinker/include/relinker/analysis/SceCodeExtent.hppcore/relinker/relinker/src/analysis/SceCodeExtent.cppcore/relinker/relinker/src/guest/GuestModuleBuilder.cppcore/relinker/relinker/src/pipeline/Conversion.cppdocs/dev/debt/relinker.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:28:54Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes consistently pass code extents and unwind ranges to Intel conversion, but I did not run the tests, so a formal approval is not justified.
What I ran
Reviewed head
3e6087593910471bae6c6996e2646aaac9f2f6d3. Read the prepared description, commit list, manifest, diff, and all eight changed files at relevant sections. No commands or tests were run; the Windows test and game dump run are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests and the reported PS4 game dump conversion were not independently verified. All eight changed files listed in the manifest were read at relevant sections; no changed files were excluded.
repo_read.pywas not run because the provided reader interface was available directly.To get this to a good state
Nothing is required. Optionally, run
amd64_only_converter_testson this head and verify--windows --to-intelagainst the reported game dump.Pull request closed