feat(libkernel): implement rtld_printf #9383
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9383"
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 DavidSamir on 2026-10-21T19:58:00Z.
What
Implements
rtld_printf(fmt, ...)in libkernel, inlibkernel/System/src/RtldPrintf.cpp, and removes thelibkernel_sysdiscovery stub. It follows FreeBSD 11libexec/rtld-elf/rtld_printf.c, wherertld_printfisrtld_vfdprintf(STDOUT_FILENO, ...)over rtld's ownkvprintf. This is a separate implementation of that behaviour, not a copy of the code.d i u o x X c s p %, plus rtld'sb(bit names),D(hex dump with a separator),r(radix 10),y(signed hex) andn.# + - 0 . *, with a negative*width toggling left adjustment.h hh l ll q j t z, withlong64-bit, as on the console.Moved to libkernel so libkernel imports reach it on Windows. The PS5 3.20 export lists have
rtld_printfin libkernel as well as libkernel_sys, and on Windows a libkernel import never searches libkernel_sys (WindowsEntryStubBuilder.cpp:175). With the libkernel export and no libkernel_sys stub, both imports reach it, and the duplicate-export rule holds.FreeBSD's quirks are kept:
kvprintfnever counts output, and%nstores 0.%prints literally.(fmt null)\n.One divergence: a format that ends in a lone
%prints the%and the terminating NUL, then stops. FreeBSD'skvprintfinstead keeps reading past the end of the string.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved.
New test
guest_kernel_sys_rtld_printf, which captures descriptor 1 throughdup2and covers:%pwith and without a width,*widths,%b,%3D,%rand%y;%nstoring 0, the unknown-conversion literal mode, the NULL format, the trailing%, and the dropped character at the flush.Results:
tools/check_conventions.pypasses, and there are no warnings.%nstore 1 fails it at line 69.RtldPrintf.cppremoved from libkernel's sources, the test fails to link (undefined reference to rtld_printf_nid_postfix), so it reaches libkernel's export, which is the only one.tools/pr_overlap.pycrashes on this machine's partial clone, so I rangit merge-treeagainst every open PR that touches these files. It merges cleanly with all of them. The test is registered at a spot incore/libs/CMakeLists.txtthat no open PR edits.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T19:58:56Z.
Progress report (
7e2ba73→70401ab)📈 System libraries: 43.24% (+0.01%, +1 implemented, -1 removed functions)
✅ 1 implemented
rtld_printf_nid_postfix🗑️ 1 removed
rtld_printf_nid_postfixImported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:26Z.
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
e9c12f71cmerged ontomain8c26eac3c.guest_kernel_sys_rtld_printfpasses 3/3.rtld_printf_nid_postfixrenamed inRtldPrintf.cpp(instead of removing the file from the sources), the test fails to link:undefined reference to rtld_printf_nid_postfix, as listed.Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T06:31:53Z.
Review: DISMISSED
I reviewed the implementation against the FreeBSD 11 rtld formatter behavior and the stated export resolution path. The formatter's buffer boundary behavior, conversion coverage, and documented quirks are internally consistent with the PR description; I did not find a reproducible code correctness defect in the reviewed diff. The test exercises the formatting output and export link path, and the PR includes useful negative controls. Validation on this host: -
python3 tools/check_conventions.py --base upstream/main --head refs/review/9383: passed. -git diff --check upstream/main...refs/review/9383: passed. -guest_kernel_sys_rtld_printf_tests: target was already built. CTest aborts before reaching test assertions because this host Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA, which AnyPS5 requires to run guest tests. This is an environment limitation, not a failure attributed to this change. - I see an independent Windows/WSL report on this head with 3/3 passing runs and a link negative control. - The PR head merges cleanly with current upstreammainingit merge-tree, but is 483 commits behind it. There is one contribution-process blocker before merge: CONTRIBUTING.md says branches should be kept up to date withmain. Please rebase this branch onto currentmainand rerun the required checks before requesting merge. I am leaving this review as changes requested for the documented branch-freshness requirement only, not because I found a formatter defect. The queue comment is not a reason to hold this PR; it is fine to keep submitting PRs and they will be handled in due course.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:48:08Z.
Thanks for the careful review, @MarcZX10, and for checking the code path itself.
On the intake point: this PR implements a documented export (FreeBSD 11's rtld_printf formatter), with a focused test and negative controls, and replaces a throwing stub. I searched the import tables of the 98 homebrew titles I convert: none imports
rtld_printf(NIDu8M56qpqTtw) today, soUnblocksstaysnonefor now. I'll add the title the moment one is known to stop on it. If a maintainer asks on this PR to hold it, I'll convert it to a draft right away.The branch is now up to date with
main(new merge commit, no force-push). The focused tests rerun on it are listed below.Merge commit
70401ab80b(currentmaind6eafa54d0), Windows 11 + WinLibs GCC 15.2: guest_kernel_sys_rtld_printf passes; check_conventions.py passes.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:32:19Z.
Review: APPROVED
Checked against main
b786b907c8and FreeBSD 11.4libexec/rtld-elf/rtld_printf.c:RtldFormatline by line withkvprintf. Flag, width and precision parsing, the size modifiers (includinghhh→short and%tn→int*, since FreeBSD's%nignorestflag),%p's width-dependent0x,%r(radix 10, signed only with+),%y,%band%Dall match.%nstoring 0 match too, becausePCHARnever incrementsretval. So does the dropped character on a full buffer (snprintf_funccallsprintf_outwithout storing it).__builtin_sysv_va_list+__builtin_va_arguse matches the existing pattern inlibSceLibcInternal/UserContext.cppon main, and thewrite_nid_postfixdeclaration matches its definition inStdio.cpp.%divergence is safer than FreeBSD's read past the end.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T11:03:48Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation does not honor the advertised
+flag and mishandles%tnby writing anintthrough aptrdiff_tpointer.What I ran
Reviewed head
70401ab80bfe6c4f9bf0395ee2ef8a3e116d8683using the provided read-only PR reader. No tests or builds were run; no merged-preview check was performed.Results
Findings
Blocking
+is parsed intospec.sign, but signed conversions set that same flag regardless, andRtldNumberemits a sign only for negative values. Thus%+dwith a positive value omits the required+. The test includes%+dbut expects5, so it codifies the defect. See RtldPrintf.cpp at the pinned head and the test expectation.%tnfalls through to theint*case inRtldStoreCount, althoughtmarks aptrdiff_targument. On the 64-bit target this writes only part of the pointed-to value and accesses it through the wrong type. HandleptrdiffSizewith the correct pointer type. See RtldPrintf.cpp at the pinned head.Non-blocking
None.
Not verified
The build, tests, author-reported negative controls, Windows runtime behavior, and merge overlap were not independently verified. The review folder’s
files.jsonwas unavailable; the file listing showed all five changed paths included. I read the complete diff and the added implementation, test, and CMake ranges; I did not read the full unchanged context ofExport.Discovery.cpp.To get this to a good state
Implement the positive sign behavior for
+and add a test that expects it for positive signed values. Handle%tnusing the correctptrdiff_tpointer type and add a corresponding test. Then rerun the build andguest_kernel_sys_rtld_printftest on the new head.Pull request closed