fix(libs): find the executable directory on macOS #4014
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4014"
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 ahir061 on 2026-10-11T21:16:25Z.
What
macOS has no
/proc, sostd::filesystem::read_symlink("/proc/self/exe")throws (filesystem_error, No such file or directory). libSceFont'sExecutableDirectory()and libSceNpEntitlementAccess'sEntitlementsPath()use it on every non-Windows host, so finding the system fonts and the entitlements file threw on macOS.Both now have an
__APPLE__branch: the path from_NSGetExecutablePath(size queried first), resolved withstd::filesystem::canonical. That gives the same real folder/proc/self/exegives on Linux, also when the executable is launched through a symlink or a relative path. A failure throws the message each file already uses on Windows. Linux and Windows are unchanged, and theANYPS5_ENTITLEMENTSoverride still comes first.Not changed here:
ShaderDiskCache.cppalso reads/proc/self/exe, but with anerror_code, so on macOS the shader and pipeline disk caches are silently disabled instead of throwing (unlessANYPS5_SHADER_CACHE_DIRis set).ModuleInfo.cpp,GuestAllocations.cppand theGuestImageAnonymoustest also read it. Those are separate topics.Tested
read_symlink("/proc/self/exe")throwsfilesystem_error(No such file or directory), the failure this fixes../programfrom its folder, and through a symlink in another folder (it resolves to the target's folder).clang++ -std=c++20 -arch x86_64 -fsyntax-only). The only warnings are the existing-Wreturn-type-c-linkageones fromGeneral.hpp.tools/check_conventions.py --base upstream/mainpasses.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 repositoryImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T01:37:44Z.
The fix is correct and the API usage is right. Both
read_symlink("/proc/self/exe")call sites genuinely had no macOS branch before this, and the new__APPLE__path queries_NSGetExecutablePath's required buffer size first rather than guessing a fixed size — which matters, since the real API only fills the buffer when it's already large enough and otherwise just reports the needed size, so a fixed-size guess could have silently truncated a long path. Running the result throughstd::filesystem::canonicalis the right call too, since Apple's own documentation for this API says the returned path "may be a symbolic link and not the real file" — canonical resolution is what actually makes this equivalent to what/proc/self/exegives on Linux. TheANYPS5_ENTITLEMENTSoverride still runs first, and the Linux/Windows branches are untouched (purely additive diff).No overlap with #4019 (reviewed earlier tonight) — that PR only touches
ShaderDiskCache.cpp, which this PR's own body explicitly and correctly scopes out as a separate topic. Worth flagging instead: the real file-level conflicts here are with two other open PRs — #3891 and #4156 — which the repo's own overlap bot already lists as touching these same lines inSystemFont.cppandExport.cpp. The checklist's "no other open PR implements the same functions" doesn't hold against those two; worth a look at whether they're duplicate attempts at the same fix or something narrower.One edge case worth a mention, not a blocker:
canonicalresolves a relative launch path against the process's current working directory, so if the processchdir()s after launch, the result could diverge from what/proc/self/exegives on Linux (which stays correct regardless of cwd changes). Untested in the PR, low-risk for this project's actual launch patterns.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-12T07:20:13Z.
Thanks for the review.
Overlap: you're right, and I missed it. #3891 (a draft adding the native ARM64 AOT path, 210 files) includes the same lookup for these two call sites and for ShaderDiskCache.cpp, through a shared
MacOsExecutablePath()helper in libc, and #4156 is stacked on it. This PR and #4019 are that fix on its own, so they can land independently of the AOT work. @yabanana, if one of these merges first, the matching hunks can drop out of #3891 on its next rebase; if maintainers would rather have the shared helper, I'm happy to switch to it or close these in favour of #3891.chdir: in the tests above,
_NSGetExecutablePathalready returned an absolute path in every launch mode, including./programand./symlinkfrom their folders (for example/private/tmp/macos_exedir/real/exedir), socanonicaldid not depend on the working directory there. Apple doesn't document that the path is always absolute, so the concern holds in principle.