fix(relinker): keep code analysis inside the code extent of PS4 executables #5195
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5195"
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 SandstromPL on 2026-10-13T14:21:40Z.
What
This is the #3093 item "Keep code analysis inside the code extent and out of PT_INTERP. The CFG followed pointers into
/libexec/ld-elf.so.1." It was found in Get-fix's experimental run of the OpenOrbisgraphicssample (#3094).The code analysis that the Windows TLS builder and the macOS image run (
CodeInstructionCollector) treats every byte of an executablePT_LOADas code. In the PS4 layout that segment also holds thePT_INTERPstring before the code and read-only data after the PLT. A pointer into either becomes a code root and is decoded, for example anR_X86_64_RELATIVEaddend or a REX.W rip-relativeleatarget:/libexec/ld-elf.so.1can decode into an fs-prefixed instruction (64 2d 65 6c 66 2e, the "d-elf."), and the conversion fails withUnsupported Windows guest TLS instruction(macOS:Unsupported macOS guest TLS instruction); the error depends on the bytes after the string;Code analysis: overlapping instruction boundaries.For executables and guest modules with
PT_SCE_DYNLIBDATA, the code analysis now follows code only from the end ofPT_INTERPto the end of the PLT after the last function of the unwind table. The end is the one #3142 gave the syscall and import call-site scans. #3142's PLT search moves unchanged into one helper (FindSceCodeEnd) that the pipeline and the code analysis share. A guest module in this layout with PLT relocations and no PLT after its last unwind function now fails the same way the executable does. The narrowed headers are used only to decide what is code; data is still read through the original headers. Executables withoutPT_SCE_DYNLIBDATAare not changed. A new debt entry, next to #3142's, records the code analysis extent and what it means for code after the PLT: that code is not analyzed, and a function symbol or init/fini array entry pointing into it fails. It is a separate line so that it does not touch #4717's neighbouring entry.Linux is not affected: its patcher does not run the code analysis.
Tested
Ubuntu 24.04, GCC 13.3, relinker-only build with
BUILD_TESTING=ON: 153/153 tests pass.test_sce_code_extent.pygains two cases, each converted with--windowsand with--macos:sce-interpreter-pointer: aPT_INTERPwith/libexec/ld-elf.so.1in front of the function, and a RELATIVE relocation pointing at it.sce-data-pointer-after-plt: a REX.Wleainto read-only data after the PLT whose bytes decode as overlapping instructions.On main they fail with
Unsupported Windows guest TLS instruction (bytes: 64 2d 65 6c 66 2e)/Unsupported macOS guest TLS instruction (...)and withCode analysis: overlapping instruction boundaries. They pass here. The interpreter case usesgap=0x60so that the bytes after the string decode into the fs-prefixed instruction.A third case,
sce-code-before-plt, places an unsupported fs-prefixed instruction at the entry point between the last unwind function and the PLT. #3093 notes that the OpenOrbis sample has 680 bytes of start-up code there. It must still fail with the TLS error, which shows that code is still analyzed. It passes on main as well. The four existing cases still pass.Each part is needed:
PT_INTERPlower bound, the interpreter cases fail.PT_SCE_DYNLIBDATAgate,tls_function_coverage_metadataandtls_function_coverage_paddingfail.Inputs without
PT_SCE_DYNLIBDATAconvert byte-identically on main and on this branch:--to-intel×unused-filter=0and1(264 conversions).The OpenOrbis sample was not run here. After #4542 it stops on Windows and macOS at
Code analysis: overlapping instruction boundaries (offset 0xde39f), which #4542 attributes to the inline jump tables item. Whether this PR moves that stop is not known.tools/check_conventions.pyfrom main passes with this title and body.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T14:56:51Z.
Windows test: head
1ed29156cmerged onto currentmainef42c5f2a, together with 9 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest for the tests this change adds or touches: sce_code_extent passed;python tools/check_conventions.py --base upstream/mainpassed for the combined tree. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-13T15:42:49Z.
Thanks for testing on Windows! The head you tested (
1ed29156c) was replaced by78f620cf9, which only moves the new debt text onto its own line so it no longer conflicts with #4717; the code and tests are unchanged.