Repository navigation
feat(libkernel): implement rtld_printf - #9383
DavidSamir wants to merge 3 commits into
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
The PS5 3.20 export lists have rtld_printf in libkernel as well as libkernel_sys, and on Windows a libkernel import never reaches libkernel_sys. The implementation moves unchanged to libkernel/System/src/RtldPrintf.cpp.
|
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine. |
There was a problem hiding this comment.
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 upstream main in git 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 with main. Please rebase this branch onto current main and 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.
|
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 The branch is now up to date with Merge commit AI-assisted: yes |
harisibrar1
left a comment
There was a problem hiding this comment.
Checked against main b786b90 and FreeBSD 11.4 libexec/rtld-elf/rtld_printf.c:
- I compared
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. - The 0 return and
%nstoring 0 match too, becausePCHARnever incrementsretval. So does the dropped character on a full buffer (snprintf_funccallsprintf_outwithout storing it). - The
__builtin_sysv_va_list+__builtin_va_arguse matches the existing pattern inlibSceLibcInternal/UserContext.cppon main, and thewrite_nid_postfixdeclaration matches its definition inStdio.cpp. - No defects found. The trailing-
%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.
|
I’ve noticed that my earlier request to hold this PR based on #5239 was unnecessary. It’s fine to keep submitting PRs; maintainers will handle them in due course. Please disregard that request. |
Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.
|
@DavidSamir this conflicts with main in core/libs/CMakeLists.txt and core/libs/prx/libkernel/CMakeLists.txt (source and test lists). Please merge main. One more fix while you are there: main declares the export once, as |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The implementation does not honor the advertised + flag and mishandles %tn by writing an int through a ptrdiff_t pointer.
What I ran
Reviewed head 70401ab80bfe6c4f9bf0395ee2ef8a3e116d8683 using the provided read-only PR reader. No tests or builds were run; no merged-preview check was performed.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed source review | passed | All changed paths were included and read |
| Build and tests | not run | Author-reported results were not independently verified |
| Negative control | not run | No negative-control test was run during this review |
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.json was 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 of Export.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 %tn using the correct ptrdiff_t pointer type and add a corresponding test. Then rerun the build and guest_kernel_sys_rtld_printf test on the new head.
|
I am closing this for now. After moving rtld_printf into libkernel, the public Api.hpp still declares a no-argument signature for a function defined with a format string and varargs, which needs to match the one declaration rule on main. There has been no push since 22 Oct and the branch conflicts. Feel free to reopen or push a rebased branch at any time and we will look at it again. |
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)