fix(relinker): accept short unwind ranges and name .esbak modules after their SELF #25483
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25483"
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 relativespace2K on 2026-11-22T05:11:06Z.
What
The two relinker defects reported in simnJS/AnyPS5#187, ported to
main..eh_framedecoding.CodeInstructionCollectordecoded each unwind range with only the FDE's bytes, so an FDE that ends inside its last instruction made the decoder throw and aborted the conversion. It now decodes up to the end of the executable segment and finishes the crossing instruction only when it is a terminator (jmp, indirectjmp,ret,ud2), ends before the next FDE starts and is not a TLS access. Any other crossing range is skipped as unreliable and logged; a TLS access split across the boundary still fails the conversion.RedZoneFramer::frameSegmentscans 15 bytes past the range end and applies the same rule; a range whose tail call leaves it is still skipped asbranch leaves the function, but the framer no longer decodes a truncated tail instruction..esbakmodules. A SELFXand an ELFX.esbakare now paired: the.esbakbytes are converted asX, so the output isX.guest.prxinstead ofX.esbak.guest.prxwith the SELF skipped. One line reports that the.esbakstood in for the SELF; excludingX.esbakstill keeps it out.Both are generic: any FDE that ends mid-instruction and any SELF with an unwrapped
.esbakbeside it takes the same path.pr_overlapreports #19336, #20387 and #21221 on the same files. None is a dependency: #20387 handles the opposite boundary (a range that begins inside a decoded instruction), #19336 changes the same body scan forint3padding, and #21221 touches the module loop. The later merge of each pair needs a small rebase.Tested
Windows 11, GCC 15.2.0, CMake 4.4.5, Ninja, relinker-only build (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON).ctest -R '^(function_symbol_roots_|tls_function_coverage_|guest_module_directories$|native_modules$|red_zone_framer$|relinker_conversion$|red_zone_framer_execution$)': 42/42 passed. This includesfunction_symbol_roots_executable,function_symbol_roots_module,tls_function_coverage_metadataandguest_module_directories; the.esbakexpectation in the last one is updated to the SELF name.python tools/check_conventions.py --base upstream/main: passed.stopsAtAShortFdeWithoutLosingTheNextFunctionbuilds an FDE cut 3 bytes inside a 5-bytejmp rel32, with the next FDE after it, and checks that the framer reports both functions, frames the next one and skips the short one as a branch out without decoding past its bytes.crossing_casescovers the same crossing with--function-symbol-rootsoff. Thenative_modulestest writes a fake SELFXand a minimal ELFX.esbak, then checks the module keeps the nameXand the.esbakbytes.9af60ce13b:crossing_casesadds a terminator that overruns the next FDE, a non-terminator crossing, and a TLS crossing placed after NOPs with no earlier terminator; the collector now fails a TLS crossing in every position and bounds the decode withrange(header.Offset, header.FileSize). The truncated case istruncatedExecutableSegmentInCodeInstructionCollectorinrelinker_conversion_tests. On Linux,relinker_conversion_tests,test_function_symbol_roots.py executable(Linux, Windows and macOS targets) andcheck_conventions.pypass.relinker.exe --windows --frame-red-zoneconverts The Witcher 3 (PPSA03977, 04.040.100).EXIT=0,Converted modules: 2,libREDGalaxy64.prx.guest.prxandlibc.prx.guest.prx. The previousInstruction truncated after prefixes (offset 0x3957a)is gone.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
.esbakbackup can be relinked using the SELF’s filename, producing an output named after the SELF..esbakbackups are handled and how exclusions affect them.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T05:12:30Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
e48bb9a525:tools/check_conventions.pypassed.native_modules_tests,red_zone_framer_testsbuilt cleanly.native_modules,red_zone_framer):core/relinker/cli/src/NativeModules.cpp,core/relinker/codegen/src/x86/RedZoneFramer.cpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.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-22T05:23:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code supports the stated short-FDE and
.esbakhandling, and the author reports targeted tests passing.What I ran
Reviewed head
e48bb9a52552b4e1840ed0c1519b192308244d86using the prepared diff and pinned repository reader,repo_read.py. No build or tests were run during this review; test results in the description are author-reported. Read the full changed-line ranges for all six changed files, with targeted surrounding source forNativeModules.cpp,RedZoneFramer.cpp, andCodeInstructionCollector.cpp.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build, test, convention-check, and end-to-end results were not independently verified. The review bundle lists all six changed files as included; their added lines were read. No excluded changed files were listed.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T05:50:13Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7c6374045b:tools/check_conventions.pypassed.native_modules_tests,red_zone_framer_testsbuilt cleanly.native_modules,red_zone_framer):core/relinker/cli/src/NativeModules.cpp,core/relinker/codegen/src/x86/RedZoneFramer.cpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.address + match.Length > nextBegincompares a segment-relative offset against an absolute virtual address.addressis computed asstart + match.Offset(wherestart = function.Begin - ph.MappedAddress), makingaddress + match.Lengthan offset relative toph.MappedAddress([0, segSize]). In contrast,nextBeginis populated fromfunction.BegininfunctionBegins, which is an absolute virtual address (ph.MappedAddress + ...). For any ELF/PRX image whereph.MappedAddress != 0,address + match.Length > nextBeginis always false, failing to detect instructions that overrun past the beginning of the subsequent function.continue;inside thefor (const auto& match : scanner->ScanCodeSection(...))loop continues the inner instruction scan rather than aborting framing for the currentfunction. When a crossing instruction is invalid (non-terminator, TLS access, or overrunningnextBegin),skip("instruction crosses the range end")incrementsreport.Skipped, but the loop merely advances to the next match or breaks atlimit. If the function already collected at least three instructions (body.size() >= 3),frameSegmentproceeds to frame the incomplete function body and emit red-zone trampolines for it instead of skipping the function.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T05:56:53Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7c6374045b:tools/check_conventions.pypassed.native_modules_tests,red_zone_framer_testsbuilt cleanly.native_modules,red_zone_framer):core/relinker/cli/src/NativeModules.cpp,core/relinker/codegen/src/x86/RedZoneFramer.cpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.address + match.Length > nextBegincompares segment-relative offsetaddress(start + match.Offset) with absolute virtual addressnextBegin(fromfunctionBegins, populated withfunction.Begin). Whenph.MappedAddress != 0,addressis offset-based whilenextBeginis virtual-address-based, causing the comparisonaddress + match.Length > nextBeginto fail to detect crossings into the next function. The check should compareph.MappedAddress + address + match.Length > nextBegin.skip("instruction crosses the range end"); continue;. Because this continues thefor (const auto& match : scanner->ScanCodeSection(...))loop instead of breaking/aborting the function, subsequent instructions (if any) or existing instructions inbodyare retained. Ifbody.size() >= 3,frameSegmentproceeds to frame the incomplete function body rather than abandoning framing for the entire function. It shouldbreak;(or flag the function as skipped) so the incomplete function is not framed.codeEnd,header.MappedAddress + header.FileSizeis computed without verifying whetherheader.Offset + header.FileSize <= bytes.size(). If an ELF header specifies aFileSizeextending beyond the inputbytesbuffer,decoder.DecodeInstruction(bytes.data() + offset + address - begin, availableEnd - address)can read past the end ofbytes.availableEndshould be bounded byheader.MappedAddress + std::min<std::uint64_t>(header.FileSize, bytes.size() > header.Offset ? bytes.size() - header.Offset : 0).end,const bool tls = info.HasMemoryOperand && (info.SegmentPrefix == 0x64 || info.SegmentPrefix == 0x65);causes an exception to be thrown only iftls && (address == begin || sawTerminator). If a TLS instruction crossing the function boundary is encountered mid-function after non-terminator instructions, it is silently skipped viaskipped.emplace_back(address, end); break;instead of throwingRelinkerException, contradicting the requirement that a crossing TLS access always fails the conversion.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T05:59:31Z.
Review: APPROVED
Reviewed — looks good
The changes address the two described relinker defects in the reviewed diff; no verified blocking defect was found in the changed source.
What I ran
Reviewed head
7c6374045b3fa69e5dafe790197fa40309eedc94. No build or tests were run in this review. Author-reported test and build results are summarized separately below.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests, build, convention check, or end-to-end conversion were run in this review. The reported Windows 11 behavior was not independently confirmed. All eight files listed as reviewed in the manifest were read; no changed files were excluded.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T06:12:15Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
413d45e8f1:tools/check_conventions.pypassed.native_modules_tests,red_zone_framer_testsbuilt cleanly.native_modules,red_zone_framer):core/relinker/cli/src/NativeModules.cpp,core/relinker/codegen/src/x86/RedZoneFramer.cpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T06:21:44Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes at head
413d45e8f168806f2a1e1b00d1b11088212af1a0show no verified blocking defect; source review is complete, but no commands or tests were run in this environment.What I ran
No commands or tests were run. I read the prepared diff and all changed source and test files listed as reviewed in the manifest.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build, tests, convention check, and end-to-end conversion were not run. The author reports passing results in the PR description; these were not independently verified. No files were excluded by the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T06:35:27Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
9af60ce13b:tools/check_conventions.pypassed.native_modules_tests,red_zone_framer_tests,relinker_conversion_testsbuilt cleanly.native_modules,relinker_conversion,red_zone_framer):core/relinker/cli/src/NativeModules.cpp,core/relinker/codegen/src/x86/RedZoneFramer.cpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.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-22T06:42:49Z.
Review: COMMENTED
Reviewed — no blocking findings
The source review found no verified blocking defects; tests were not run, so a formal approval is not justified.
What I ran
Reviewed head
9af60ce13bbc5d11ec4ed89200a57fb51ea49354usingrepo_read.pyto inspect the prepared diff, manifest, and targeted source context. No commands or tests were run.Results
Negative control
Not run; no code-under-test change was made for a negative control.
Findings
Blocking
None.
Non-blocking
None.
Sources
Behavior claims were checked against the changed code at the pinned head: NativeModules.cpp, CodeInstructionCollector.cpp, and RedZoneFramer.cpp.
Not verified
Automated tests, build, and convention checks were not run. The manifest lists 9 changed files, all included; their changed lines were inspected. No excluded-file inventory was available to inspect.
To get this to a good state
Nothing is required. Optional: run the reported relinker tests and convention check on this head before merging.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T19:48:14Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected code supports the stated short-range decoding and
.esbakbehavior, with no verified blocking defect.What I ran
Reviewed head
d054754ac29e01f05b9764da0f637801dde487d4. I read the prepared description, commits, manifest, diff, and all 10 changed files listed in the manifest. No commands or tests were run; the reported test results are author supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the build, tests, convention checker, or end-to-end conversion. No files were excluded from the manifest’s reviewed set.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T23:38:14Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the prepared review bundle and targeted source reads support the fixes, while execution checks were not run here.
What I ran
c42af52e13a130a059be70278014e922647d459eusing the prepared diff and pinned repository reader.review/README.md; read relevant surrounding code inNativeModules.cpp,CodeInstructionCollector.cpp, andRedZoneFramer.cpp.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
files.jsonwas not available by that path in the reader. The review folder README listed ten changed files, and each listed changed line range was read; no excluded changed files were identified in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T00:11:06Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
35ea70df9f:tools/check_conventions.pypassed.native_modules_tests,red_zone_framer_tests,relinker_conversion_testsbuilt cleanly.native_modules,relinker_conversion,red_zone_framer):core/relinker/cli/src/NativeModules.cpp,core/relinker/codegen/src/x86/RedZoneFramer.cpp,core/relinker/relinker/src/analysis/CodeInstructionCollector.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 coderabbitai[bot] on 2026-11-28T00:18:49Z.
Review: COMMENTED
Actionable comments posted: 4
7ff82fc2-d566-4e94-a94b-cb6429b52ddaReviewing files that changed from the base of the PR and between
750a5234edand35ea70df9f.core/relinker/CMakeLists.txtcore/relinker/cli/src/NativeModules.cppcore/relinker/cli/tests/NativeModulesTests.cppcore/relinker/codegen/src/x86/RedZoneFramer.cppcore/relinker/codegen/tests/RedZoneFramerTests.cppcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/relinker/tests/ConversionTests.cppcore/relinker/relinker/tests/test_function_symbol_roots.pycore/relinker/relinker/tests/test_guest_module_directories.pydocs/user/USAGE.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T13:03:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the checks listed below were reported by the author and were not run in this review.
What I ran
Reviewed head
35ea70df9ff1513af3be3b56af6738d1d23fffddusing the prepared diff andrepo_read.py. I did not run build or test commands. The author reports relinker tests and convention checks passed; those results were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the changed implementation and related call sites in
NativeModules.cpp,RedZoneFramer.cpp,CodeInstructionCollector.cpp, andmain.cpp, alongside the changed test and documentation hunks indiff.patch.Not verified
No commands or tests were run. The description reports Windows 11/GCC 15.2/CMake 4.4.5 test results, Linux test results, and an end-to-end Witcher 3 conversion; these were not reproduced. All ten changed files listed in the manifest were included in the prepared diff, but no full-text files were available under
review/files; targeted source ranges were read through the pinned reader. Behavior outside the inspected ranges and physical-console behavior were not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T07:51:41Z.
Review: COMMENTED
native_modules,relinker_conversion,red_zone_framer, andguest_module_directoriespassed in the Linux relinker-only build. The run exercises.esbaknaming and short unwind range handling through the repository fixtures.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T16:46:07Z.
Review: COMMENTED
Actionable comments
cb5b6cd7-d6a8-4f26-80e4-bcd8cdea8508Reviewing files that changed from the base of the PR and between
35ea70df9fand8e014925be.core/relinker/codegen/src/x86/RedZoneFramer.cppcore/relinker/codegen/tests/RedZoneFramerTests.cppcore/relinker/relinker/tests/test_function_symbol_roots.pycore/relinker/relinker/tests/test_guest_module_directories.pyIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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.