Skip to content

fix(relinker): keep code analysis inside the code extent of PS4 executables - #5195

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
SandstromPL:fix/relinker-sce-code-analysis-extent
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
SandstromPL:fix/relinker-sce-code-analysis-extent

Conversation

@SandstromPL

@SandstromPL SandstromPL commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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 OpenOrbis graphics sample (#3094).

The code analysis that the Windows TLS builder and the macOS image run (CodeInstructionCollector) treats every byte of an executable PT_LOAD as code. In the PS4 layout that segment also holds the PT_INTERP string before the code and read-only data after the PLT. A pointer into either becomes a code root and is decoded, for example an R_X86_64_RELATIVE addend or a REX.W rip-relative lea target:

  • /libexec/ld-elf.so.1 can decode into an fs-prefixed instruction (64 2d 65 6c 66 2e, the "d-elf."), and the conversion fails with Unsupported Windows guest TLS instruction (macOS: Unsupported macOS guest TLS instruction); the error depends on the bytes after the string;
  • data after the PLT can decode into Code analysis: overlapping instruction boundaries.

For executables and guest modules with PT_SCE_DYNLIBDATA, the code analysis now follows code only from the end of PT_INTERP to 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 without PT_SCE_DYNLIBDATA are 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.py gains two cases, each converted with --windows and with --macos:

    • sce-interpreter-pointer: a PT_INTERP with /libexec/ld-elf.so.1 in front of the function, and a RELATIVE relocation pointing at it.
    • sce-data-pointer-after-plt: a REX.W lea into 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 with Code analysis: overlapping instruction boundaries. They pass here. The interpreter case uses gap=0x60 so 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. Relinker rejects PS4 executables: SCE dynamic tables and data in the code segment (two ready branches) + remaining PS4 work #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:

    • Without the PT_INTERP lower bound, the interpreter cases fail.
    • Without the PLT upper bound, or with the control-flow walk kept on the whole segment, the data cases fail.
    • With the upper bound at the last unwind function instead of the end of the PLT, the code-before-PLT case fails.
    • Without the PT_SCE_DYNLIBDATA gate, tls_function_coverage_metadata and tls_function_coverage_padding fail.
  • Inputs without PT_SCE_DYNLIBDATA convert byte-identically on main and on this branch:

    • every relinker call the test suite makes (1,771 runs);
    • a matrix of 22 fixtures × Linux, Windows and macOS × with and without --to-intel × unused-filter=0 and 1 (264 conversions).
  • The OpenOrbis sample was not run here. After fix(relinker): load a PT_SCE_RELRO segment that no PT_LOAD covers #4542 it stops on Windows and macOS at Code analysis: overlapping instruction boundaries (offset 0xde39f), which fix(relinker): load a PT_SCE_RELRO segment that no PT_LOAD covers #4542 attributes to the inline jump tables item. Whether this PR moves that stop is not known.

  • tools/check_conventions.py from main passes with this title and body.

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: none
  • Unblocks: none (a Relinker rejects PS4 executables: SCE dynamic tables and data in the code segment (two ready branches) + remaining PS4 work #3093 item for PS4 executables; no Game bring-up discussion)
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code); I reviewed and tested every line

🤖 Generated with Claude Code

…tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SandstromPL
SandstromPL force-pushed the fix/relinker-sce-code-analysis-extent branch from 1ed2915 to 78f620c Compare October 13, 2026 14:43
@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test: head 1ed29156c merged onto current main ef42c5f2a, 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/main passed for the combined tree. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

@SandstromPL

Copy link
Copy Markdown
Contributor Author

Thanks for testing on Windows! The head you tested (1ed29156c) was replaced by 78f620cf9, which only moves the new debt text onto its own line so it no longer conflicts with #4717; the code and tests are unchanged.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants