Repository navigation
feat(relinker): write Mach-O output for macOS with --macos - #1597
Conversation
The guest image reader and the module builder already produce a platform-neutral GuestImage; --macos adds a third writer next to the ELF and PE ones. The executable and every bundled module become x86-64 Mach-O files (modules as dylibs in app0/sce_module) that run under Rosetta on Apple silicon. FreeBSD code reaches its thread pointer through %fs, which macOS cannot set, so the writer rewrites each %fs access into a stub that reads the image's 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. Imports bind by NID to the prx libraries beside the output, exports and TLS imports use the dynamic symbol names, and the image's metadata lives in __APS5DATA,__meta. --macos conflicts with --windows. The macOS runtime that consumes the output (TLS allocation, libraries built for macOS) comes in separate changes.
|
Checked the build and the relinker ctest scope on Linux (43/43, |
|
Tried
Still 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 |
feat(relinker): write Mach-O output for macOS with --macos
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 (#1 (comment)).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 feat(libc): exception runtime on macOS hosts #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)