feat(relinker): write Mach-O output for macOS with --macos #1597
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1597"
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 mugurc on 2026-10-08T14:03:16Z.
What
Adds
--macosto the relinker: the executable and the bundled modules are written as x86-64 Mach-O files (modules as dylibs inapp0/sce_module) that run under Rosetta on Apple silicon. This is the second piece of the macOS port after #927, as announced on #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6060813714).MacOsMachOPatcherwrites the executable andGuestModuleWriter::WriteMacOsthe modules, both throughMacOsImage. The ELF segments keep their layout (__ELF0,__ELF1, ...). Imports bind by NID to the prx libraries through@rpath, exports and TLS imports use the dynamic symbol names, and the original program headers and the image metadata go to__APS5DATA,__meta, the section the unwinder from #927 reads.%fs, which macOS cannot set. Each%fsaccess becomes a stub that reads the thread pointer from a pthread key and allocates the TLS block on a thread's first access; dynamic TLS goes through the image's descriptor instead of__tls_get_addr.Windows::WindowsLoadImageandWindowsRelocationBuilder. Moving them togeneral/is a refactor for a follow-up.--macosconflicts with--windows.--to-intelwith--macosstill uses the Intel target here; the Rosetta target comes in its own PR.The Linux and Windows output is unchanged. The Mach-O output needs the macOS runtime (TLS allocation in libkernel, libraries built for macOS), which comes in separate PRs.
Tested
macos_output: relinks two byte-built guests and reads the Mach-O back (header, segment layout and protections, entry point, dependencies, run path, binds by NID, the TLS descriptor, and that no%fsaccess is left). It needs no macOS, so it runs in the Linux and Windows jobs.macos_outputincluded.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:04:51Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/cli/src/CliArgs.cppL66-70Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:13:18Z.
Checked the build and the relinker ctest scope on Linux (43/43,
macos_outputincluded), the head's CI (conventions, eligibility, relinker on ubuntu/windows/macos), and that Linux/Windows output paths are untouched.macos_outputfails without the change. Runtime behaviour on macOS/Rosetta is not verified here (it needs the runtime pieces from the follow-up PRs); merging for the structure and the CLI. Note #2117 touches the usage line inCliArgs.cpp, whoever lands second rebases.Imported from boykopovar/AnyPS5. Originally posted by mrzacarias on 2026-10-10T02:19:31Z.
Tried
mugurc/macos-port(e9db5ebf) with Balatro (PPSA21402) on an M1 Pro, macOS 26.4, LunarG SDK 1.4.363. It gets to gameplay at ~33 FPS. On top of the branch I needed:github.com/mrzacarias/AnyPS5@d215500687github.com/mrzacarias/AnyPS5@f0fbff4c80github.com/mrzacarias/AnyPS5@cbc1bc5dc0Contents/MacOS/app0link so titles with bundled modules load (github.com/mrzacarias/AnyPS5@1571fbaa91), and saves kept in Application Support so repackaging doesn't wipe them (github.com/mrzacarias/AnyPS5@a338cf230a)github.com/mrzacarias/AnyPS5@f6f6f118ebStill open: text truncated partway through long batches with a stray triangle to (0,0); host import, draw sync, texture cache and flip pacing are ruled out. Also a crash on exit in sceKernelGetModuleInfoFromAddr (garbage st_size), and an occasional "guest protection or unmap range has a hole" at startup. Happy to send PRs once intake reopens.
Branch: https://github.com/mrzacarias/AnyPS5/tree/balatro-macos