Skip to content

fix(relinker): skip prefixed decodings inside an earlier instruction in the macOS TLS scan - #6410

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
DavidSamir:fix/relinker-macos-tls-overlapping-decode
Oct 18, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
DavidSamir:fix/relinker-macos-tls-overlapping-decode

Conversation

@DavidSamir

@DavidSamir DavidSamir commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

27 catalog titles cannot be converted for macOS on main, among them SuperTuxKart (PPSA69421), PSXS5 (PPSA97510), SwanStationPS5 (PPSA98510), ProsperoStore (PPSA99000), ProsperoRadio (PPSA99001), ProsperoTV (PPSA99003), SymphonyStation5 (PPSA17641) and OpenNOW (PPSA99082). Each fails on the same two bytes:

FAIL: Unsupported macOS guest TLS instruction (bytes: 65 6e) (offset 0xbabf4d)

They are not code. The titles link OpenSSL, whose assembly keeps CRYPTOGAMS by <appro@openssl.org> in the code segment; at PSXS5's offset 0xbabf4d the bytes are the en of openssl (... 6f 70 | 65 6e 73 73 6c ...). A function range that begins inside an instruction makes the code analysis collect a second decoding from the middle of it, and here that decoding starts with a GS prefix. The Windows TLS rewriter skips a non-FS segment-prefixed decoding inside an earlier collected instruction (90dcd62, "tolerate unwind ranges that split an instruction"), so the same titles convert for Windows. The macOS scan in MacOsImage.cpp has no such check and refuses the module.

The macOS scan now tracks the end of the decodings it has seen, as the Windows rewriter does, and skips a segment-prefixed decoding that starts inside an earlier one unless the prefix is FS. A GS access at an instruction start is still refused.

With this PR 25 of the 27 convert. The other two get past this refusal and stop on unrelated ones, each with its own PR: Mortalfin (PPSA99141) on Guest TLS access without a non-empty PT_TLS (#6448) and PS5MC (PPSA99420) on the stack-protector check sub %fs:0x28,%rax (#6419).

Three commits:

  1. fix(relinker): skip prefixed decodings inside an earlier instruction in the macOS TLS scan.
  2. test(relinker): convert a function that begins inside an instruction for macOS: a new macos_tls_overlap test converts the Windows coverage group's function-begins-inside-instruction fixture with --macos. A symbol starts inside a movabs whose immediate holds a GS-prefixed decoding (65 2e 62 69 6e). It converts, and the movabs is unchanged in the output.
  3. test(relinker): keep refusing a GS access at an instruction start for macOS.

There is no fourth step to split out.

Tested

Windows host (be5dfd6 on main 0afa6a6, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release). The relinker writes macOS output on any host:

  • tools/check_conventions.py --base origin/main: passed. tools/pr_overlap.py: no overlap with open pull requests.

  • Each of the three commits builds, and the relinker tests pass at each (macos|tls_function_coverage|tls_diagnostics|guest_tls|empty_tls, 35/36/36 tests; run on main d92a8da before rebasing onto 0afa6a6, which changes nothing under core/relinker).

  • macos_tls_overlap fails without the fix: with MacOsImage.cpp as on main, function-begins-inside-instruction stops with Unsupported macOS guest TLS instruction (bytes: 65 2e 62 69 6e c3 c3 c3).

  • Full build and full ctest: 1250/1258 passed. Seven of the eight failures were timeouts or crashes under load early in the run (guest_needed_modules, windows_diagnostic_fixture_isolation, guest_gnu_hash, guest_video_out_resolution_status, agc_shader_mode_register, guest_none_relocations, guest_avplayer); all seven pass when rerun alone. The eighth, check_main_sync, fails the same way on main on this host: its Unicode file name test reads git's UTF-8 output as cp1252 (sp ace é.txt).

  • Linux (WSL2 Ubuntu 24.04, GCC 13.3.0): the relinker builds and the macos|tls tests pass (38/39; guest_force_tls_destructor is not run because only the relinker target was built).

  • macOS conversion of every catalog title (79) with main's relinker and with this branch's, same arguments:

    titles
    byte-identical output 54
    refused on main with (bytes: 65 6e), converted with this PR 25
    refused on main with (bytes: 65 6e), now stopping on a later, unrelated refusal 2 (PPSA99141, PPSA99420)
    output that differs otherwise 0
  • The bytes the refusal named stay in place. In 23 of the converted titles, CRYPTOGAMS by <appro@openssl.org> occurs as often in the macOS output as in the input (20 times each); in the 24th, PPSA99039, the string is present in both input and output.

macOS 26.7.1, Apple M2, MoltenVK 1.4.2, x86-64 under Rosetta, added 2026-10-16: head be5dfd6, converted with --macos --to-rosetta and run 20 s each against the runtime of a local tree of main with the macOS port work merged. 20 of the 25 titles were run, and each loads and runs its own code. Three keep running: PSXS5 (PPSA97510) draws its interface at about 11 ms a frame, SwanStationPS5 (PPSA98510) runs with only its network downloads failing (curl 77), and Nuvio PS5 (PPSA99997) is still running at 20 s. The other 17 run until the AGC driver stops on a GPU feature MoltenVK lacks:

Not run there: SuperTuxKart (PPSA69421, 712 MB). PPSA99004, PPSA99008, PPSA99288 and PPSA99360 stopped on Forbidden syscall instruction, since these runs didn't pass --skip-syscall-check.

Limits of this Mac's GPU. vulkaninfo on Apple M2 with MoltenVK 1.4.2 reports no geometry shaders, no shaderFloat64, no VK_EXT_depth_range_unrestricted and no VK_EXT_provoking_vertex. AnyPS5 turns MoltenVK's VK_KHR_fragment_shader_barycentric off (5333a20), so barycentric pixel shaders need the geometry-shader fallback. These are limits of the device, so this PR can't remove them. A title named here as stopping on one of them is not tested past that stop:

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: macOS conversion of PPSA17641, PPSA69421, PPSA74126, PPSA97510, PPSA98427, PPSA98510, PPSA99000, PPSA99001, PPSA99002, PPSA99003, PPSA99004, PPSA99008, PPSA99009, PPSA99039, PPSA99082, PPSA99177, PPSA99288, PPSA99360, PPSA99474, PPSA99505, PPSA99515, PPSA99600, PPSA99773, PPSA99930, PPSA99997; PPSA99141 with fix(relinker): convert stack-guard and thread-pointer reads with an empty PT_TLS for macOS #6448 and PPSA99420 with fix(relinker): rewrite ALU reads of guest TLS through %fs in macOS output #6419
  • AI-assisted: yes

…in the macOS TLS scan

A function range that begins inside an instruction makes the code analysis
collect a second decoding from the middle of it. The Windows TLS rewriter
skips a non-FS segment-prefixed decoding there (90dcd62); the macOS scan
did not, and refused the module. OpenSSL's assembly keeps its
"CRYPTOGAMS by <appro@openssl.org>" string in the code segment, where the
"en" of "openssl" decodes as a GS-prefixed instruction, so 24 catalog
titles could not be converted for macOS: "Unsupported macOS guest TLS
instruction (bytes: 65 6e)". The scan now skips such decodings as the
Windows rewriter does.
…for macOS

macos_tls_overlap converts the Windows coverage group's function-begins-inside-instruction fixture with --macos: a symbol starts inside a movabs whose immediate holds a GS-prefixed decoding. It converts, and the movabs is unchanged in the output.
… macOS

Only a segment-prefixed decoding inside an earlier instruction is skipped; a GS load that begins an instruction is still refused.
@github-actions

github-actions Bot commented Oct 15, 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 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7173 core/relinker/CMakeLists.txt
PR 7450 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/macos/MacOsImage.cpp
PR 7531 core/relinker/CMakeLists.txt

@DavidSamir

Copy link
Copy Markdown
Contributor Author

Hardware run on Apple silicon, as asked in the handoff.

macOS 26.7.1, Apple M2 (8 GB), Rosetta 2, AppleClang 21.0.0. Relinkers built (-DANYPS5_RELINKER_ONLY=ON, Release) from main 5d9dcc4 alone and with this branch merged; catalog releases, sha256 checked, eboot and modules unwrapped with tools/unwrap_self.py, converted with --macos --to-rosetta. For the runs, libraries from a local tree of main ce991f1 with #4627, #4630, #6124, #6028, #6135 and mugurc's macOS branches merged, so they build on macOS; MoltenVK from the LunarG SDK 1.4.363.

AI-assisted: yes

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 18, 2026
@adriadam10 adriadam10 self-assigned this Oct 18, 2026
@adriadam10
adriadam10 merged commit ea41ee4 into boykopovar:main Oct 18, 2026
14 checks passed
ycarogabriel-lgtm added a commit to ycarogabriel-lgtm/AnyPS5 that referenced this pull request Oct 19, 2026
The branch no longer merged cleanly with main, which jotitadev reported
after rechecking 57bccfb on the M2 Max; this brings in 183 upstream
commits, among them boykopovar#6410, boykopovar#6419 and boykopovar#6458, which this branch carried.

Conflicts:
- recompile request serialization: main moved to version 34 for pixel
  sample iteration and locations, this branch to 33 for the fragment
  barycentric built-ins flag. Both fields are kept and the version
  becomes 35; the barycentric flag is read from 35 on, so a version 34
  request written by main still parses. The serializer tests, and
  main's new version 30 and 32 cases in ShaderMemory, account for the
  extra trailing byte.
- ShaderInfoCollector: main folds the center and sample barycentric
  kinds into one input and adds gl_SampleID for sample iteration; the
  gl_FragCoord input that keeps Apple GPUs' barycentrics normalized is
  kept for all three kinds.
- QuadSampleMasks keeps this branch's per-sample masks beside main's
  sample iteration fields; DynamicLoader keeps the macOS image field
  beside main's Windows load order; the relinker keeps its macOS
  fixture and fixed-base tests; the GS trap debt line is main's newer
  wording from boykopovar#6458.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build relinker unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants