feat(libc): implement getopt_long_only #6533
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6533"
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 ArjenS-LA on 2026-10-15T19:06:11Z.
What
A PS5 ABI conformance homebrew importing getopt_long_only stops at startup because its NID is absent. Extend the existing parser with single-dash long options, short-option fallback, exact-match precedence and long-only ambiguity rules. Tests also cover arguments, flag pointers, permutation, termination, diagnostics and restart while retaining the existing getopt/getopt_long cases.
Contract: FreeBSD getopt_long.c. The signature/export is also present in the open PS5 payload SDK. This is general library behavior; no title-specific workaround.
Tested
Windows 11 Pro 10.0.26200 x64, Intel Core i7-10700K, supported WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, Python 3.13.7. The full suite's Vulkan tests select an NVIDIA GeForce RTX 4070 SUPER, Windows driver 32.0.16.1088. Baseline
b7cedd900d67a94453b8a45eec9b5623532a0441; branchfeat/guest-getopt-long-only; tested head725ad5649c237bd62729f4edf2dea3664b20f02a.Executed purpose-built PS5 ABI homebrew: identical ELF input is relinked and launched against baseline and rebuilt patched libraries. Baseline stops at the expected unresolved
getopt_long_onlyimport (exit0xC0000139). Fixed reaches the ELF entry point, executes the behavioral checks and exits0. The input is compiled with clang 23 targetingx86_64-sie-ps5, with NID imports/SCE module metadata and a freestanding entry. Link-time stubs are not deployed; no trap or implementation substitution is used. This establishes module load, entry and conformance completion for this probe, not shipped-title, physical-console or gameplay compatibility.The full build was attempted on baseline and both fixes. All three hit the same unrelated upstream MinGW error in
GpuIndirectArgumentsMisalignedWriterAhead.cpp:25: requested alignment 65536 exceeds the object-file maximum 8192. Continuing Ninja with-k 0built the remaining available targets; the separatelibstarget and focused regression tests passed. The same new regression test cannot link on baseline specifically becausegetopt_long_only_nid_postfixis absent. Conventions andgit diff --checkpass. A clean full build is not claimed.Full CTest results (unrelated failures/skips are disclosed):
Failed on both:
windows_trace_imports. Baseline-only failures:agc_driver_store_over_untracked. Fixed-only failures: none. Skipped on this PR:agc_host_import_sparse,agc_driver_sparse_dma_buf_import,agc_driver_stencil_ref_export,guest_video_out_high_frame_rate,video_out_flip_labels,video_out_flip_labels_main,video_out_flip_lifetime,video_out_flip_reopen,video_out_flip_controls,video_out_flip_overlay,video_out_flip_unopened,video_out_flip_eop,video_out_flip_eop_main,video_out_flip_eop_aftergpu,guest_video_out_wqhd_detection_no_vulkan,long_paths. Native Linux/macOS were not tested locally. GitHub full builds require a collaborator-triggered run under current contribution rules.Unavailable on this PR:
agc_driver_gpu_indirect_arguments_misaligned_writer_ahead. The alignment build error above explains the unavailable AGC executable. Baselinewindows_trace_importsfails with WinError 225 because Defender blocks its separate generated fixture; no protection settings were changed. Neither unavailable nor skipped tests are execution evidence.Reproducer, input/build hashes and library artifacts
Save the C source below as
getopt.cand the Python recipe asbuild_probe.py. SetLLVM_BINto thebindirectory of LLVM MinGW 20261006, then runpython build_probe.py getopt getopt_long_only optind optarg puts. The generated input layout isprobes/getopt/probe.elfwith an emptysce_module/; system-link stubs remain outside that module directory. The script preserves the input after construction.Build each checkout with:
Place the toolchain's
libgcc_s_seh-1.dll,libstdc++-6.dllandlibwinpthread-1.dllbeside the patched PRXs. Convert each variant with the baseline relinker:Startup diagnostics recorded the selected library paths.
--trace-importswas present but the optionalAPS5_TRACE_CALLSring was not enabled; no per-call trace capture is claimed. Execution is demonstrated by the probe's checks and successful return through the converted entry.Input ELF SHA256:
769696de542b449fc27e6348a29f36a7637a6bf81dbefb8a5957d114d18842b2. Relinker SHA256:a4babf4b9154c44b64676011724911b6fa38451b96923d7d596f48eaaf191f1a.59a0ec0a34c68c0c547d8a3e825abee36e0fe1165c6ed9a17a7620128c3daaa859a0ec0a34c68c0c547d8a3e825abee36e0fe1165c6ed9a17a7620128c3daaa8d56fba282a0e9f2a85af9ee1db7037611b2dcc8f35e176aadd1696cd9c845b5b2e62dd356c43c01eab759ee257ff7913097182f41fb798ae793447bdf69b4ace9b799f8d27051476ebfdc91f92461374fd4526eac142168af3ff30023d34dad16fbb16df66b86c39c578423d72ec2f59d839dba330f2abc552addee1f8d9c57dOpen-PR overlap check
Complete paginated inventory: 631 open PRs. Main checked:
44df21632125dbe3113a19173e7ebb879da53003. Exact changed-file lists and every shared-file implementation were inspected; Git tree-only previews normalize both sides to that main as the explicit merge base. 0 reliable clean shared-file comparisons; 0 inconclusive because those peers already conflict with main. No duplicate implementation or reliable pairwise conflict found. The two proposed topics also merge cleanly together; this does not claim combined runtime testing.The tested base is
b7cedd900d67a94453b8a45eec9b5623532a0441. Main advanced during validation; the newer main above was checked for integration conflicts, not claimed as the runtime-tested baseline.Checklist
mainsnapshotb7cedd900d67a94453b8a45eec9b5623532a0441; refreshed current-main merge check above; no other open PR implements the same functionsImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T19:06:56Z.
Progress report (
44df216→725ad56)➖ System libraries: 88.8% (+0.0%, +1 implemented functions)
✅ 1 implemented
getopt_long_only_nid_postfixImported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T14:13:12Z.
Review: COMMENTED
Windows check of head
725ad5649(together with #6532), onmain5d9dcc42d. Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release.guest_getoptpasses.Code: I compared it with FreeBSD 11's
getopt_long.cand it follows that code:-in long-only mode, withD_PREFIXas the dash;short_toowhen the character is a short option other than:;short_toois set;(flags & FLAG_LONGONLY) || …);short_too,--optindand-1, so the element is reparsed as short options;-WpassesshortToo = false, asparse_long_optionsis called there with0.No issues.
Evidence: both descriptions use a purpose-built probe. In earlier rounds maintainers held back functions that no shipped title or released homebrew imports yet, so a real importer would help. I checked the two released websrv payloads built with the same ps5-payload-dev SDK. Neither Mari0 (
Mari0.zipfrom websrv v0.34, SHA-256e0331ed5…2ce3, the bundle in #6239) nor the Quake homebrew (#6698) importsbcopyorgetopt_long_only, inlove.elf/quake.elfor in theirlibOSMesa.so.8. If a released title or homebrew does, naming it would make the case.Build note: with the same WinLibs GCC 15.2.0 r7, a full build of
main5d9dcc42dplus this PR (and #6532/#6533 together) completes here without theGpuIndirectArgumentsMisalignedWriterAhead.cpp:25alignment error, so that error looks specific to your tree or setup.AI-assisted: yes. I ran the build and tests above and read the import tables of the two bundles.