fix(libc): find guest image pages through dyld on macOS hosts #10366

Merged
krishalivaibhav merged 1 commit from upstream-pr/10366 into main 2026-10-27 05:23:04 +00:00
krishalivaibhav commented 2026-10-23 19:33:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-23T19:33:52Z.


What

Build fix: GuestAllocations.cpp collected image pages with dl_iterate_phdr from <link.h>, which macOS does not have, so libc did not compile there. On macOS it now walks the loaded images with _dyld_image_count / _dyld_get_image_header and reads the LC_SEGMENT_64 load commands (collectMachImagePages). The Linux/Windows path is unchanged. The Linux-only anonymous re-backing of the main image (/proc/self/maps, mremap) is excluded on macOS.

Extracted from the feat/macos-port branch (#8658) as iamthehimansh asked there; the first standalone piece of that split. Commit 0f15e1baa is theirs.

Tested

macOS: Apple Silicon M2, x86_64 build, Release, Vulkan SDK 1.4.363.0. Integration of main d7948b09f + #4627 + #10362 + this commit (the first two are needed for the rest of libc to compile on macOS). The libc target builds, and guest_exit_order, guest_path_lifetime, guest_libc_static_imports, guest_libc_mutex_init_with_name, guest_libc_cnd_init_default_name and guest_libc_cnd_timed_wait pass. ninja libs -k 0 has 10 failed objects, all in libkernel (outside this PR). guest_libc_threads needs libkernel and was not run.

No test covers this file on macOS: guest_image_anonymous_tests is not built there and the memory tests live in libkernel.

Linux/Windows: unchanged code path; not built locally, CI will build them.

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: #8658 (macOS port split)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4988240582 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10366). Originally posted by [krishalivaibhav](https://github.com/krishalivaibhav) on 2026-10-23T19:33:52Z. --- ### What Build fix: `GuestAllocations.cpp` collected image pages with `dl_iterate_phdr` from `<link.h>`, which macOS does not have, so `libc` did not compile there. On macOS it now walks the loaded images with `_dyld_image_count` / `_dyld_get_image_header` and reads the `LC_SEGMENT_64` load commands (`collectMachImagePages`). The Linux/Windows path is unchanged. The Linux-only anonymous re-backing of the main image (`/proc/self/maps`, `mremap`) is excluded on macOS. Extracted from the `feat/macos-port` branch (#8658) as iamthehimansh asked there; the first standalone piece of that split. Commit `0f15e1baa` is theirs. ### Tested macOS: Apple Silicon M2, x86_64 build, Release, Vulkan SDK 1.4.363.0. Integration of `main` d7948b09f + #4627 + #10362 + this commit (the first two are needed for the rest of `libc` to compile on macOS). The `libc` target builds, and `guest_exit_order`, `guest_path_lifetime`, `guest_libc_static_imports`, `guest_libc_mutex_init_with_name`, `guest_libc_cnd_init_default_name` and `guest_libc_cnd_timed_wait` pass. `ninja libs -k 0` has 10 failed objects, all in `libkernel` (outside this PR). `guest_libc_threads` needs `libkernel` and was not run. No test covers this file on macOS: `guest_image_anonymous_tests` is not built there and the memory tests live in `libkernel`. Linux/Windows: unchanged code path; not built locally, CI will build them. ### 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: #8658 (macOS port split) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-23 19:35:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T19:35:37Z.

Review: APPROVED


Reviewed current head 0f15e1baa3. The Apple path uses dyld's loaded-image headers and LC_SEGMENT_64 protections, while the existing ELF path remains unchanged; the Linux-only /proc and mremap path is correctly excluded on macOS. Segment page permissions are accumulated consistently with the existing ELF collector, including shared boundary pages. The author reports a macOS libc build and focused guest_libc tests in an integration stack that supplies the separately tracked macOS prerequisites; I did not build it locally. Hosted eligibility, conventions, intake, labels and progress-report checks pass; product Linux/Windows jobs are skipped by path policy, and the relinker/memory jobs were still running when I reviewed. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5633526154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10366#pullrequestreview-5633526154). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T19:35:37Z. **Review:** APPROVED --- Reviewed current head 0f15e1baa3756ca9de89901d79a32360e7d01e6b. The Apple path uses dyld's loaded-image headers and LC_SEGMENT_64 protections, while the existing ELF path remains unchanged; the Linux-only /proc and mremap path is correctly excluded on macOS. Segment page permissions are accumulated consistently with the existing ELF collector, including shared boundary pages. The author reports a macOS libc build and focused guest_libc tests in an integration stack that supplies the separately tracked macOS prerequisites; I did not build it locally. Hosted eligibility, conventions, intake, labels and progress-report checks pass; product Linux/Windows jobs are skipped by path policy, and the relinker/memory jobs were still running when I reviewed. No blocking issue found.
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!10366
No description provided.