fix(relinker): keep the interpreter path out of the scanned code #7996
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7996"
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 javierUDP on 2026-10-19T17:09:46Z.
What
The code analysis trims an interpreter path from the start of an executable segment only for images that have a
PT_SCE_DYNLIBDATAblock. An executable without one keeps that path in the scanned range./libexec/ld-elf.so.1then gets walked as code: aR_X86_64_RELATIVErelocation with addend 0 roots the control flow graph at the first byte of the segment, and the0x64ofld-elfdecodes as an FS-prefixed instruction, which the Windows and macOS TLS rewriters refuse:Linux output is unaffected because it keeps the guest
%fsaccesses. The trim now runs for both layouts, ending at the segment for an image without the block. This is thePT_INTERPitem of the remaining PS4 work in #3093.Tested
Apple M5, macOS 26.4, AppleClang 21.0.0, relinker-only build of current
main.The public OpenOrbis homebrew samples reproduce it, so no title dump is needed:
samples-elf-llvm-18.zipfrom OpenOrbis-PS4-Toolchain v0.5.3 (GPL-3.0). Their executable segment starts with the interpreter path at vaddr 0, and they carry the addend-0 relocation.--windows, 21 sample imagesmaingraphics,SDL2,hello_world,piglet,font,input,networking, …)libc,libSceFios2,right)--macosrefuses and converts the same way;graphicsconverts on all three targets with the change.interpreter_in_codetest: an image without an SCE block whose executable segment begins with the interpreter path, reached through an addend-0 RELATIVE relocation. It fails onmainwith the message above and passes here, for--windowsand--macos, with a second image that has no interpreter path as the control.python3 tools/check_conventions.py --base origin/mainpasses.No Linux or Windows host was available, so the converted images were not executed; the change only narrows what the analysis scans.
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: n/a.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T17:33:36Z.
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.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/analysis/CodeInstructionCollector.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T23:18:09Z.
Verdict: confirmed on Windows and Linux, with one edge case below.
Environment: Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release build. This PR was merged onto
main9127ea36d. Linux: WSL Ubuntu 24.04, GCC 13.3.samples-elf-llvm-18.zipfrom the official v0.5.3 release, all 21 ELFs, converted withrelinker --skip-sce-moduleand--windowsor--macos:mainwithUnsupported Windows guest TLS instruction (bytes: 64 2d 65 6c 66 2e) (offset 0x400a), or the macOS equivalent. All of them convert with this PR, on both targets.libc,libSceFios2,right) convert on both, and their outputs are byte-identical tomain.PT_INTERP: PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with its 16 Wine modules. Relinked with--windows --to-intel,--macos --to-rosettaand Linux--to-intel, all 12 output sets are byte-identical tomain.CodeInstructionCollector.cppreverted tomain,interpreter_in_codefails withUnsupported Windows guest TLS instruction (bytes: 64 2d 65 6c 66 2e) (offset 0x100a).ctest: Windows 213/213, after a serial rerun of 10 tests that timed out under-j4because of host load. WSL 218/218.Edge case:
trimToCodesets the start of the analyzed code to the end of anyPT_INTERPthat lies inside the executable segment, not only one at its start. Before this PR, only SCE images got that trim. Now an image without an SCE block whosePT_INTERPfollows the code in the same executable segment loses the code in front of it. Probe: themake_image("register", "unwind")image fromtest_tls_function_coverage.py, plus a sixth program headerPT_INTERPat 0x1f00 (size 21,/libexec/ld-elf.so.1) inside the executable segment 0x1000-0x2000, with the code at 0x1200.--windowsmainPT_INTERPPT_INTERPat segment start 0x1000PT_INTERPat 0x1f00, after the codeCode analysis: invalid function range (offset 0x1200)It fails loudly, and linkers normally put
.interpbefore.text. Trimming only when the interpreter range starts at the segment start would avoid it.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-19T23:51:38Z.
Confirmed and fixed in
32b2a9196. You are right, and the probe reproduces here: Apple M5, macOS 26.4, AppleClang 21.0.0, relinker-only build.--windows,make_image("register", "unwind")main7db5ba1d732b2a9196PT_INTERPPT_INTERPat the segment startPT_INTERPat 0x1f00, after the codetrimToCodenow takes an interpreter only when it starts the segment, and the SCE path keeps taking any interpreter inside the scanned range, so nothing changes for images with an SCE block. I kept it to that rather than reordering the scan, since the trim is only meant to skip a path that precedes the code.interpreter_in_codegained a third image whosePT_INTERPfollows the code. It fails on7db5ba1d7withCode analysis: no code entry pointsand passes on32b2a9196, so the case is covered from here on. The suite is 207/207 and the 17 OpenOrbis executables still convert on--windowsand--macos.Thanks for the Windows and Linux runs, and for the byte-identical check on the PS5 homebrew: that covers the ground I could not, since I have neither host.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T00:23:56Z.
Re-tested
32b2a9196. The edge case is fixed, and nothing else moved.Environment: Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 r7, relinker-only Release build. The PR is merged onto
main3aa35dc01, and thatmainis the baseline. Linux: WSL Ubuntu 24.04, GCC 13.3,-DBUILD_TESTING=ON.Same probe as before:
make_image("register", "unwind")plus aPT_INTERP(size 21,/libexec/ld-elf.so.1), converted with--skip-sce-module --windows.--windowsmain3aa35dc017db5ba1d732b2a9196PT_INTERPPT_INTERPat the segment start 0x1000PT_INTERPat 0x1f00, after the codeinvalid function range (offset 0x1200)In every rc 0 case, the original TLS bytes at 0x1240 appear once in the output, as they do on
main.samples-elf-llvm-18.zip,--skip-sce-module: all 17 executables convert with--windowsand with--macos. Onmainthey still fail withUnsupported Windows guest TLS instruction (bytes: 64 2d 65 6c 66 2e) (offset 0x400a). The 3 modules give the same bytes asmain. All 40 outputs are also byte-identical to the ones from7db5ba1d7.PT_INTERP(PPSA99005, PPSA47402, PPSA99581, and PPSA99995 with its Wine modules): relinked with--windows --to-intel,--macos --to-rosettaand Linux--to-intel. All 12 output sets are byte-identical tomain.CodeInstructionCollector.cppset back to7db5ba1d7,interpreter_in_codefails on the newtrailingimage withCode analysis: no code entry points. It passes on32b2a9196.ctest, Windows: 213/214 under-j4.guest_none_relocationstimed out under host load and passed on a serial rerun, so 214/214.ctest, WSL: 218/219.shader_cache_runtime_sourcesfailed because its nestedcmakeconfigure timed out after 15 s while other work was loading the host. This PR does not touch that test. It passed twice on a rerun, so 219/219.tools/check_conventions.py: passes.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-20T04:43:35Z.
@wachi35676 thanks for the second round, and for diffing all 40 outputs against
7db5ba1d7byte for byte: that is what shows the edge-case fix changed nothing else. The Windows and Linux runs and the PS5 homebrew checks cover the ground I cannot, since I have neither host.On the overlap notice: I checked the one pull request in it that shares
CodeInstructionCollector.cpp, #6618. It does not merge intomainon its own. Merged intomain49fd13a74by itself it conflicts inCodeInstructionCollector.cppandRelinkerPipeline.cpp, the same two files it conflicts in when merged on top of this branch, and this branch does not touchRelinkerPipeline.cppat all. So the conflict is between #6618 andmainrather than with this pull request, and it needs a rebase either way.The other pull requests in the notice share only
core/relinker/CMakeLists.txt, where this branch adds oneadd_testblock next to the other relinker Python tests.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T16:39:43Z.
Thanks. This now conflicts with
mainincore/relinker/relinker/src/analysis/CodeInstructionCollector.cpp, after #8166 (which changes how the code roots and the syscall scan treat data between PS4 unwind functions) merged today. Could you rebase onto currentmain, keeping both rules (the new SCE gap handling and your interpreter trim for images withoutPT_SCE_DYNLIBDATA)? Once it merges cleanly we'll run the relinker CI and a relink-identity check on our test titles, since this path runs for PS5 executables too.Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-20T17:59:37Z.
@oneandonlydean rebased onto current
mainas you asked, keeping both rules: thesceFunctionsand merged unwind ranges from #8166, and the interpreter trim for images withoutPT_SCE_DYNLIBDATA.This pull request closed when I republished its branch, and GitHub will not reopen it, so the rebased work is in #8599. Apologies for the churn — the two commits and the discussion here are unchanged.
Pull request closed