fix(libkernel): keep a host reference to an RTLD_NODELETE module on macOS so RTLD_NOLOAD finds it #28076
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28076"
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 magnub on 2026-11-28T11:38:54Z.
What
Follow-up to #27297. On macOS, dyld keeps an
RTLD_NODELETEimage mapped after its lastdlclose, but takes it off its list of loaded images. A laterdlopen(path, RTLD_NOLOAD)then returns NULL, while FreeBSD's rtld, and glibc, still find the image.On macOS,
dlopen_nid_postfixnow takes one extra host reference withRTLD_NOLOADwhen it opens a module withRTLD_NODELETE, and never releases it. The image stays loaded and findable, as a pinned image is on the console. The change is under__APPLE__; Linux and Windows are unchanged.Tested
Apple M1 Pro, macOS 27.0.1. The libraries and tests are an x86_64 build under Rosetta 2, on main
29b14e4c5e. #17425, #11049, #26739 and #25331 were merged locally only so that main builds on macOS.RTLD_NODELETEand closes every handle. Afterwards the image is no longer in the_dyld_get_image_namelist, but its function can still be called, anddlopen(RTLD_NOLOAD)returns NULL. With one extraRTLD_NOLOADreference held, the image stays listed andRTLD_NOLOADfinds it.guest_dynamic_loader: fails 2/2 on main atGuestDynamicLoader.cpp:170(theRTLD_NOLOADreopen inCheckNoLoadAndNoDelete), passes 3/3 with this change.dynamic_loader|module|dlopen|dlsym|prx_load, before and after: no new failures.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_012LL9hfx4BY6MbUCYMduDAQ
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T11:44:02Z.
Review: COMMENTED
Actionable comments posted: 1
bd644c6d-0f48-42f7-abb2-716130f3fcbfReviewing files that changed from the base of the PR and between
045b7d7813andd3729ad4b8.core/libs/prx/libkernel/Module/src/DynamicLoader.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T11:46:45Z.
Review: COMMENTED
Reviewed — comments
This review covers the changed macOS loader call at head
d3729ad4b8f3373ce6af1d42b1f38564813cc373; it presents a potential edge case that needs clarification before a formal approval.What I ran
Read the prepared description, commit summary, manifest, diff, and the changed loader function and its
Moduledestructor. No tests were run.Results
Findings
Blocking
None.
Non-blocking
DynamicLoader.cpp:537: The extraRTLD_NOLOADcall's result is discarded, and the code does not checkdlerror(). If the call fails, the extra host reference is not acquired, so the described pinning behavior is not guaranteed. Consider checking the returned handle and treating failure as a load error (or otherwise ensuring the original successfuldlopenhandle remains retained).Not verified
The prepared bundle includes one changed file,
core/libs/prx/libkernel/Module/src/DynamicLoader.cpp, and its full text was available. Thefiles.jsonlisting was not readable through the reader; no other changed files are listed in the manifest. Tests and the author-reported macOS environment/results were not independently verified.To get this to a good state
Nothing is required. Optional: handle failure of the extra
RTLD_NOLOADcall so the pinning guarantee is explicit.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T00:24:15Z.
Review: COMMENTED
Reviewed — comments
Changes are limited to one macOS loader call; the retained host reference is not tracked or released, and the call’s failure is ignored, so the description’s guarantee is not established by the code.
What I ran
Reviewed head
4fc156b0254eba421d6df48aa9f0f61bc18c5256; no commands or tests were run. Readreview/description.md,review/commits.md,review/manifest.json,review/diff.patch, and the changed filecore/libs/prx/libkernel/Module/src/DynamicLoader.cpplines 90–160, 470–570, and 590–630.review/files.jsonwas unavailable; the prepared file listing showed the changed file was included.Results
Findings
Blocking
None verified.
Non-blocking
dlopen_nid_postfixdiscards the result of the extraRTLD_NOLOADopen. If it fails, the required extra host reference is not held, but the function still returns a successful guest handle. Since the subsequentModuledestructor only closesmodule->native, this extra reference also has no explicit release path. Consider checking and handling failure, and documenting or managing the retained reference’s lifetime. Evidence:core/libs/prx/libkernel/Module/src/DynamicLoader.cpp:537.Not verified
The author-reported macOS/Rosetta tests were not independently run. No other files were changed according to the prepared manifest; no excluded changed files were listed by the prepared file listing.
To get this to a good state
Nothing is required. Optional: check the extra open’s result and define how its retained reference is managed.
Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-11-30T23:53:40Z.
Review: APPROVED
Confirmed on macOS 15.
Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta,
BUILD_TESTING=ON. These are the OS and compiler generation of themacos-15runner; the description tested macOS 27.Tree:
main93d64f2d1e+ the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (maindoes not build on macOS without them, see #28168) + #22091 + #28369, then #28075, #28076 and #28284 merged one after another. Each merged cleanly.guest_dynamic_loader4fc156b025Full
ctest -j 6with all of them merged: 7038/7066 pass. Compared with the same tree before these PRs, no test fails that passed before.jsc_wtf_cpu_timeaborted once under the parallel load, then passed 5/5 on its own; it is unrelated JavaScriptCore CPU-time code.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:02:41Z.
Review: COMMENTED
The extra
dlopencurrently runs on every successfulRTLD_NODELETEopen. Reopening the same image and closing the returned guest handle therefore leaves another unmatched host reference each time. Can this take one permanent reference per host image? Please also check the extra call's return value before reporting the guest open as pinned, so a failed host lookup surfaces to the caller. This is a source review of the Darwin path.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.