build(libkernel): compile NativeStat and Rtld on macOS #11240

Closed
iamthehimansh wants to merge 2 commits from upstream-pr/11240 into main
iamthehimansh commented 2026-10-25 22:28:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-25T22:28:15Z.


What

Next part of splitting #8658: two libkernel files that do not compile on macOS. Each change is macOS-only; Linux and Windows compile the same code as before.

  • File/src/NativeStat.cpp: copy the Darwin st_atimespec / st_mtimespec / st_ctimespec fields, since Darwin's struct stat has no st_atim / st_mtim / st_ctim. Also stat through a directory descriptor when the host path reaches PATH_MAX. That is 1024 on Darwin, the same as the guest limit, so a guest path near the limit no longer fits once the host root is prepended.
  • System/src/Rtld.cpp: macOS has no <link.h>. Find the image with dladdr and take the extra reference with dlopen(RTLD_NOLOAD), skipping the main executable as the Linux path does.

@marion909's #7201 also changes these two files, inside a 100-file port; this PR carries only these two so they can land separately.

DirectMemory.cpp, SharedMemory.cpp, Stdio.cpp, DynamicLoader.cpp, ModuleInfo.cpp, Thread.cpp, Exception.cpp, Process.cpp and libc's GuestAllocations.cpp still fail on macOS; they follow in separate PRs.

Tested

macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on main at b90d009d9: both objects compile, where main fails them. The libkernel tests cannot run on macOS until the files above build, so this is a compile check only. Both files passed the stat and module tests on #8658's branch. For Linux and Windows, I checked each file's view under unifdef -U__APPLE__, with -D__linux__ and with -D_WIN32: it equals main. python3 tools/check_conventions.py --base origin/main passes.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Cana)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009353059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11240). Originally posted by [iamthehimansh](https://github.com/iamthehimansh) on 2026-10-25T22:28:15Z. --- ### What Next part of splitting #8658: two `libkernel` files that do not compile on macOS. Each change is macOS-only; Linux and Windows compile the same code as before. - `File/src/NativeStat.cpp`: copy the Darwin `st_atimespec` / `st_mtimespec` / `st_ctimespec` fields, since Darwin's `struct stat` has no `st_atim` / `st_mtim` / `st_ctim`. Also stat through a directory descriptor when the host path reaches `PATH_MAX`. That is 1024 on Darwin, the same as the guest limit, so a guest path near the limit no longer fits once the host root is prepended. - `System/src/Rtld.cpp`: macOS has no `<link.h>`. Find the image with `dladdr` and take the extra reference with `dlopen(RTLD_NOLOAD)`, skipping the main executable as the Linux path does. @marion909's #7201 also changes these two files, inside a 100-file port; this PR carries only these two so they can land separately. `DirectMemory.cpp`, `SharedMemory.cpp`, `Stdio.cpp`, `DynamicLoader.cpp`, `ModuleInfo.cpp`, `Thread.cpp`, `Exception.cpp`, `Process.cpp` and libc's `GuestAllocations.cpp` still fail on macOS; they follow in separate PRs. ### Tested macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on `main` at `b90d009d9`: both objects compile, where `main` fails them. The `libkernel` tests cannot run on macOS until the files above build, so this is a compile check only. Both files passed the stat and module tests on #8658's branch. For Linux and Windows, I checked each file's view under `unifdef -U__APPLE__`, with `-D__linux__` and with `-D_WIN32`: it equals `main`. `python3 tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes ([Cana](https://cana.build))
MarcZX10 commented 2026-10-25 22:35:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:35:26Z.

Review: CHANGES_REQUESTED


The rest of the macOS changes are scoped to the platform, and the reported compile checks are useful. I found one permission regression in the long-path fallback; see the inline note. git diff --check and the current-main conventions check pass. Hosted eligibility, conventions, intake, labels and report pass; all product build jobs are skipped. I did not run the macOS behavior locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645700928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11240#pullrequestreview-5645700928). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:35:26Z. **Review:** CHANGES_REQUESTED --- The rest of the macOS changes are scoped to the platform, and the reported compile checks are useful. I found one permission regression in the long-path fallback; see the inline note. `git diff --check` and the current-main conventions check pass. Hosted eligibility, conventions, intake, labels and report pass; all product build jobs are skipped. I did not run the macOS behavior locally.
MarcZX10 commented 2026-10-25 22:49:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:49:17Z.

Review: APPROVED


Rechecked exact head 0783152995bab8ecac72893e9a8e116e4a0a80f9 against current main b90d009d9f73354cbea239a74a8f7e2dcd138772. Replacing O_RDONLY | O_DIRECTORY with Darwin O_SEARCH addresses the execute-only intermediate-directory regression. The author reports a focused x86_64 run on a 1,472-byte path through seven 0111 directories: the old flags returned EACCES, and O_SEARCH succeeded. I did not run that Darwin-only scenario locally, and no automated regression was added; the existing macOS runtime suite remains blocked on the other in-progress port PRs. Exact-worktree git diff --check and conventions pass; hosted eligibility, labels and conventions pass, the progress report is still running, and product build/test jobs are skipped by path policy. No other blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645753351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11240#pullrequestreview-5645753351). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:49:17Z. **Review:** APPROVED --- Rechecked exact head `0783152995bab8ecac72893e9a8e116e4a0a80f9` against current `main` `b90d009d9f73354cbea239a74a8f7e2dcd138772`. Replacing `O_RDONLY | O_DIRECTORY` with Darwin `O_SEARCH` addresses the execute-only intermediate-directory regression. The author reports a focused x86_64 run on a 1,472-byte path through seven `0111` directories: the old flags returned `EACCES`, and `O_SEARCH` succeeded. I did not run that Darwin-only scenario locally, and no automated regression was added; the existing macOS runtime suite remains blocked on the other in-progress port PRs. Exact-worktree `git diff --check` and conventions pass; hosted eligibility, labels and conventions pass, the progress report is still running, and product build/test jobs are skipped by path policy. No other blocking issue found.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11240
No description provided.