Skip to content

fix(relinker): analyze referenced code beyond SCE scan boundaries - #10861

Open
Felipebmaitan wants to merge 28 commits into
boykopovar:mainfrom
Felipebmaitan:feat/relinker-analysis-relocation
Open

Felipebmaitan wants to merge 28 commits into
boykopovar:mainfrom
Felipebmaitan:feat/relinker-analysis-relocation

Conversation

@Felipebmaitan

@Felipebmaitan Felipebmaitan commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What

SCE scan cutoffs can omit explicitly referenced code, leaving TLS instructions unchanged or forbidden syscalls unchecked. Follow supported entry/lifecycle/function/control-flow roots beyond the cutoff and use the discovered ranges for syscall checks and Windows/macOS TLS processing. Strong code roots inside recognized data tables retain the tested refusal.

Current head ef92693f7218066d9eb983d1c4bb4171994daaba merges main bab5bc6b9828b24b799add9dac6b768365f82125 into published 6f07b2b376aaf3e7c5e53bef4719e0a4048c27c6, preserving published history and authorship. This addresses the integration part of Dean's November 11 request and adriadam10's review.

The resolutions keep main's LEA code-pointer/data classification with this PR's narrow-address reference protection and separate ordinary/authoritative traversal; retain numbered pathconf-191 routing with main's SDK-stub diagnostics and interrupt-table handling; and register both the routing and new address-data regressions. Main's deprecated-option documentation and this PR's routing documentation are combined. Existing jump-table masking, function-symbol roots, generated-trap continuations and strong-root regression remain.

Merge order: #10792 lands first, then #10861. The pathconf-routing prerequisite remains bundled until it lands; it is not being split out or presented as a separate implementation. #10479 and #9549 have now landed in main. No other author's branch was modified and no new author agreement is asserted.

Tested

Windows 11 Pro 10.0.26300, Ryzen 7 9800X3D, supported WinLibs GCC 15.2.0 r7, Python 3.11, Ninja Release, relinker-only. Main and candidate builds were serialized with at most two compiler jobs.

  • Exact head ef92693f7218066d9eb983d1c4bb4171994daaba: full registered relinker suite 281/281 passed, zero failures/skips, 113.81 seconds. This includes sce_referenced_code_*, code extent/gaps, relative jump tables, syscall_scanner, SDK/guest syscall routing/traps, code_analysis_address_data, function-symbol roots, strong-root conversion controls and TLS coverage. Windows-native execution is included where registered; Linux/Mach-O format checks do not establish guest execution on those OSes.

  • Pinned main bab5bc6b9828b24b799add9dac6b768365f82125: the 19-test focused SCE/code-analysis/syscall/function-root/control-flow selection 19/19 passed, 7.83 seconds.

  • python tools/check_conventions.py --base origin/main and git diff --check origin/main...HEAD: pass.

  • Refreshed overlap scan: 1,569 open heads, 71 shared-file candidates, exit 2. Direct rows include the declared feat(relinker): route ps5-payload-dev pathconf stub to libkernel export #10792 prerequisite and shared-line changes in fix(relinker): accept identical repeated dynamic tags in code analysis #14411/fix(relinker): report PLT stubs replaced after linking #18085; 35 base-conflicted comparisons remain inconclusive. No blanket overlap clearance or new merge-order agreement is claimed. Read-only composition with newer main 752c0f776bfa689bac02aca3c30afac4b0b8378d is clean; no files under core/relinker changed between the pinned and newer main.

Remaining conversion evidence: the requested fresh Sonic Superstars PPSA06888 and Dead Cells PPSA15552 comparison is pending. Their original games/ and build-relinker/resume-20261107/inputs directories are absent from the replacement checkout. Current input locations have been requested. The November 7 result (six bundle pairs, 198 byte-identical output files) applies only to its recorded old head/main; it is not reused as evidence for this integration. The separately unnamed gate-image manifest remains unavailable.

No title gameplay, console behavior, fresh native Linux/macOS execution, GPU or performance qualification. Fresh hosted checks and collaborator re-review remain pending. Requesting adriadam10, oneandonlydean and MarcZX10 again was rejected by GitHub: Felipebmaitan does not have the correct permissions to execute RequestReviewsByLogin. A collaborator must request the re-review; no review was dismissed.

Executed relinker commands and artifact hashes

cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DPython3_EXECUTABLE=<Python 3.11>

cmake --build build-relinker --parallel 2

ctest --test-dir build-relinker/core/relinker -j 2 --output-on-failure --no-tests=error

SHA-256: candidate converter 5b2931b9851c4b8e92ddb572ae9b9d2f5f5d8950a8ef5cd0b54313ec2c553a57; main converter 182c67ed433ed2e9c3526fe19471192ed9fc8098e6def47a50b1979f2808e00e; candidate CTest log 7e09d6fb748126797f0de230a2cc3dcaaf067107b2f3ae90a22f19892fecd022.

Overlap notification reviewed: November 13, 23:21 UTC

The refreshed bot report adds no overlap relative to the pre-push scan. The remaining direct peer heads are unchanged: #14411 6527e2ff82d023f0ee501bd8e29828c4d17a9a58, #18085 68df14da9cdf15ee9b79f71aa7e30719c604e6de.

Inspected their shared changes. #14411 changes the public code-analysis policy for identical dynamic tags; this branch currently relaxes that check only in its internal auxiliary scans. A later composition must retain the chosen public policy, conflicting-value rejection and referenced-code traversal. #18085 adds replaced-PLT diagnostics around the syscall scan; a later composition must preserve those diagnostics alongside this branch's routed-stub output and tail scan. Neither supplies a helper this head requires, so no new functional dependency is established by these shared lines.

#10792 and #11628/#11661/#11689/#11698 disappeared from the report but are all confirmed OPEN at unchanged heads. Their absence is not evidence of a merge or clearance. #10792 remains the declared predecessor. The 30 remaining base-conflicted comparisons are inconclusive; no combined-runtime pass or new author ordering agreement is claimed. This notification requires no source change or repeated runtime tests.

Checklist

  • Based on current main; no other open PR implements the same functions

  • One topic per PR; follow-ups go in a new PR

  • No comments in code except technical debt

  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file

  • No notes, investigation .md files or images added to the repository (attach them to this PR)

  • New third-party code is a submodule built from source

  • Generic behaviour, not specific to one title

  • Depends on: feat(relinker): route ps5-payload-dev pathconf stub to libkernel export #10792

  • Fixes: none

  • Unblocks: none

  • GPUs tested: n/a

  • AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the exact head f1b6e32c18f7de1606dc3956ac27388dd9761d3c. The relinker-only Release configure and full build pass on this Linux host. The eight focused SCE/extent/scanner tests pass, including all three new sce_referenced_code_{linux,windows,macos} cases. The full relinker CTest suite passes 178/180; masked_store_lowering and amd64_only_converter terminate with SIGILL on this Xeon E5-1620 v2 host, and neither test's source is changed here, so I cannot attribute those two failures to this patch. Hosted eligibility, conventions, intake, labels, Ubuntu/macOS relinker and ASan checks pass; Windows relinker was still pending at my check. Product jobs are skipped by path policy.

I found one repository-rule blocker in the overlap with #10792. Although this PR's body says merge-order coordination and composition testing remain necessary and the new scanner interface must preserve #10792's guest routing, its checklist currently says Depends on: none. I tested the two current heads with git merge-tree --write-tree; the composition has content conflicts in core/relinker/relinker/include/relinker/domain/ISyscallScanner.hpp and core/relinker/relinker/src/analysis/SyscallScanner.cpp. Please agree a merge order with #10792's author and update the affected checklist line(s) to show the dependency, then rebase and rerun the focused route/scanner tests on the composed result. The PR does merge cleanly with current main by itself; this request concerns the confirmed open-PR composition conflict.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI update for the exact head remains green: the Windows relinker job has now completed successfully. Together with the already-passing Ubuntu/macOS relinker matrix and relinker ASan, all four hosted relinker platform jobs and ASan pass. The local focused tests and full-suite result are recorded in my review above; the two local SIGILL failures remain limited to unchanged instruction-lowering tests on this host. The only outstanding review request is the confirmed composition conflict with #10792 and the missing agreed dependency/order in the checklist.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4847 docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6149 core/relinker/CMakeLists.txt
PR 6924 docs/user/USAGE.md
PR 7173 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7531 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7642 docs/user/USAGE.md
PR 9345 docs/user/USAGE.md
PR 9508 docs/user/USAGE.md
PR 10193 docs/user/USAGE.md
PR 12678 core/relinker/CMakeLists.txt
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 12746 docs/user/USAGE.md
PR 12863 docs/user/USAGE.md
PR 12910 docs/dev/debt/relinker.md
PR 13928 docs/user/USAGE.md
PR 13929 docs/user/USAGE.md
PR 14241 docs/dev/debt/relinker.md
PR 15456 docs/user/USAGE.md
PR 15642 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 15973 docs/user/USAGE.md
PR 16354 docs/user/USAGE.md
PR 16571 docs/user/USAGE.md
PR 17259 docs/user/USAGE.md
PR 17557 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 17558 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
docs/user/USAGE.md
PR 18082 docs/user/USAGE.md
PR 18373 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
PR 18432 core/relinker/relinker/include/relinker/analysis/UnusedNidFilter/IControlFlowGraph.hpp
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/analysis/UnusedNidFilter/ControlFlowGraph.cpp
PR 18449 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
PR 18523 core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
docs/dev/debt/relinker.md
PR 18693 docs/user/USAGE.md
PR 19532 docs/user/USAGE.md
PR 21211 docs/user/USAGE.md
PR 22434 docs/user/USAGE.md
PR 22546 docs/user/USAGE.md
PR 22647 docs/user/USAGE.md
PR 23636 core/relinker/CMakeLists.txt
docs/user/USAGE.md
PR 23747 core/relinker/CMakeLists.txt
PR 23781 core/relinker/CMakeLists.txt
docs/user/USAGE.md
PR 23842 core/relinker/CMakeLists.txt
docs/user/USAGE.md
PR 23975 docs/user/USAGE.md
PR 24200 core/relinker/relinker/tests/SyscallScannerTests.cpp
PR 24277 core/relinker/elfpatcher/include/elfpatcher/macos/MacOsImage.hpp
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
docs/user/USAGE.md
PR 24472 core/relinker/CMakeLists.txt
docs/user/USAGE.md
PR 24756 docs/user/USAGE.md
PR 24915 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsMachOPatcher.cpp
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/user/USAGE.md
PR 25483 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/tests/ConversionTests.cpp
docs/user/USAGE.md
PR 26232 core/relinker/CMakeLists.txt
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 27133 docs/user/USAGE.md
PR 27255 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 27809 core/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 27825 core/relinker/elfpatcher/src/macos/MacOsImage.cpp
core/relinker/elfpatcher/src/macos/MacOsMachOPatcher.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
PR 27848 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/include/elfpatcher/windows/WindowsTlsBuilder.hpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
core/relinker/elfpatcher/src/windows/WindowsTlsBuilder.cpp
PR 27866 core/relinker/domain/include/domain/Types.hpp
core/relinker/elfpatcher/include/elfpatcher/macos/MacOsImage.hpp
core/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
core/relinker/elfpatcher/src/macos/MacOsMachOPatcher.cpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
PR 28161 core/relinker/relinker/src/analysis/SyscallScanner.cpp
PR 28164 docs/user/USAGE.md
PR 28178 core/relinker/CMakeLists.txt
core/relinker/domain/include/domain/Types.hpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
PR 28276 core/relinker/relinker/tests/test_sce_code_extent.py
PR 28277 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/SyscallScanner.cpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
core/relinker/relinker/tests/SyscallScannerTests.cpp
core/relinker/relinker/tests/test_guest_syscall_route.py
docs/user/USAGE.md
PR 28372 docs/user/USAGE.md
PR 28384 docs/user/USAGE.md
PR 28417 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
PR 28445 core/relinker/CMakeLists.txt
PR 28453 core/relinker/CMakeLists.txt
PR 28488 docs/user/USAGE.md
PR 28671 core/relinker/CMakeLists.txt
PR 28770 core/relinker/CMakeLists.txt
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
docs/user/USAGE.md
PR 28805 docs/user/USAGE.md
PR 28961 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
PR 29000 docs/user/USAGE.md
PR 29053 docs/user/USAGE.md
PR 29207 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
PR 29212 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
core/relinker/relinker/tests/test_sce_code_extent.py
PR 29259 core/relinker/CMakeLists.txt
PR 29262 core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
PR 29310 core/relinker/relinker/tests/ConversionTests.cpp

@mzaeemnasir

Copy link
Copy Markdown
Contributor

Hi @Felipebmaitan, #11033 fixes the signed overflow at CodeInstructionCollector.cpp:499 that this PR also rewrites (your addTransferRoot already uses the unsigned form), and adds a regression test, branchAcrossSignedBoundary. I propose #11033 goes first, since it is one line: the rebase here is then taking your side of that hunk. I checked that composition: #11033 rebased on main 5a2744c55e with this PR's head merged on top, conflict resolved to your version, passes all 298 relinker-only tests on Windows (MSYS2 GCC 14.2), and relinker_conversion also passes with -fsanitize=signed-integer-overflow -fsanitize-trap=undefined. If you'd rather land first, I'll rebase #11033 down to just the test. Does that order work for you?

@wachi35676

Copy link
Copy Markdown
Contributor

Tested head f1b6e32 merged onto main aeff26b (clean) on Windows 11 (Ryzen 5 9600X), WinLibs GCC 15.2.0, Release.

  • The focused set (sce_*, *syscall*, tls_*, relinker_conversion) passes: 54/54.
  • Negative control: with the PR's 17 non-test sources at main and the tests kept, sce_code_extent and sce_referenced_code_{linux,windows,macos} fail (4/4).
  • Real homebrew: PPSA99005, PPSA47402, PPSA99581 and PPSA99995, converted to Windows, macOS (--to-rosetta) and Linux with --trap-sdk-syscall-stubs. All exit 0, every output file is byte-identical to main's, and the logs match apart from the output path. So none of these four has entry/lifecycle-reachable code past the SCE scan boundary that main misses. Under the intake hold, a title that shows the gap would still be needed.

AI-assisted: yes (Claude Code); results above were run on this machine.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
Recognize FreeBSD syscall 191 (pathconf) exact 13-byte numbered stubs emitted by ps5-payload-dev libc and rewrite them to an indirect tail jump (FF 25 <disp32> followed by 7 NOPs) directly into the libkernel pathconf import relocation slot.

When pathconf is imported, routing applies without requiring --trap-sdk-syscall-stubs, allowing homebrew like Apotris to run out-of-the-box. If pathconf is not imported, the relinker continues to refuse the binary unless --trap-sdk-syscall-stubs is passed, under which it falls back to a UD2 trap.

Closes boykopovar#10219.
@Queuse

Queuse commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

#20900 has merged, completing the merge order I proposed above. When refreshing this branch, please keep its 32-bit effective-address wrapping before target classification and the address-size LEA regression. The native probe in #20900 still needs the REX.W form to reach code classification.

This was referenced Dec 2, 2026

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built the exact head in relinker-only mode. sce_code_extent and the Linux, Windows, and macOS referenced-code output tests passed on Linux. Native Windows and macOS execution were outside this run. A trial merge against main at 67962e3245 conflicts in the code collector, syscall scanner, and PE patcher, among other files.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs needs rebase Conflicts with main, rebase needed relinker

Projects

None yet

Development

Successfully merging this pull request may close these issues.