libc: __umodti3 is absent (Kart PS5's stop after __divti3, PS5CEMU-HAR); fix branch ready #4460

Closed
opened 2026-10-12 12:22:46 +00:00 by screamm · 1 comment
screamm commented 2026-10-12 12:22:46 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-12T12:22:46Z.


libc lacks __umodti3 (NID ELSr5qm4K1M). Kart PS5 (PPSA99611) stops on it right after __divti3, as open #4037 reports in its body ("with this change it passes __divti3 and stops at ELSr5qm4K1M (__umodti3)"); PS5CEMU-HAR (PPSA99360) imports it too (registry index 359, predicted FAIL: unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx).

Fix branch ready: screamm:feat/libc-umodti3 (2d3ac3d5, one commit on main ffa19840). I cannot open it as a PR under the intake rule while #4081 is open; anyone eligible is welcome to carry it, keeping the commit as is. It is the natural follow-up to #4037 (__divti3): both add a function after SonyUdivti3 in SonyCrt.hpp and extend GuestCrt.cpp at the same spot, so whichever merges second gets a small conflict; #4037's SonyDivti3 still works on top of this refactor.

  • The division loop of the existing SonyUdivti3 moves into a shared SonyUdivmod128 helper returning quotient and remainder (SonyUdivti3 unchanged, same throw); SonyUmodti3 returns the remainder, per compiler-rt lib/builtins/umodti3.c at 0ee439b7 (the commit #3161 cited). A zero divisor throws __umodti3: integer divide by zero (0x<dividend> % 0), where compiler-rt's udivmodti4 would reach a native divide that traps. Exported from libc next to __udivti3 (the relinker routes libSceLibcInternal imports to libc.prx); __modti3/__udivmodti4 are not added because no title imports them. TechnicalDebt bullet beside the __udivti3 one.
  • guest_crt checks literal remainders: small cases, 2^100 % 3, (2^128-1) % 10, (2^128-1) % 2^64, two divisors above 2^64, divisor 1, equal operands, a dividend below the divisor, (2^128-1) % 2^127, and the zero-divisor message through the export.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_crt 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 606/606; with main's SonyCrt.hpp the branch no longer compiles (the export needs the helper), so the negative check is by construction; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux; the titles were not relinked.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5813645253 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4460). Originally posted by [screamm](https://github.com/screamm) on 2026-10-12T12:22:46Z. --- libc lacks `__umodti3` (NID `ELSr5qm4K1M`). Kart PS5 (PPSA99611) stops on it right after `__divti3`, as open #4037 reports in its body ("with this change it passes `__divti3` and stops at `ELSr5qm4K1M` (`__umodti3`)"); PS5CEMU-HAR (PPSA99360) imports it too (registry index 359, predicted `FAIL: unresolved ELF import ELSr5qm4K1M from libSceLibcInternal.prx`). **Fix branch ready:** [`screamm:feat/libc-umodti3`](https://github.com/screamm/AnyPS5/tree/feat/libc-umodti3) (`2d3ac3d5`, one commit on `main` `ffa19840`). I cannot open it as a PR under the intake rule while #4081 is open; anyone eligible is welcome to carry it, keeping the commit as is. It is the natural follow-up to #4037 (`__divti3`): both add a function after `SonyUdivti3` in `SonyCrt.hpp` and extend `GuestCrt.cpp` at the same spot, so whichever merges second gets a small conflict; #4037's `SonyDivti3` still works on top of this refactor. - The division loop of the existing `SonyUdivti3` moves into a shared `SonyUdivmod128` helper returning quotient and remainder (`SonyUdivti3` unchanged, same throw); `SonyUmodti3` returns the remainder, per compiler-rt `lib/builtins/umodti3.c` at `0ee439b7` (the commit #3161 cited). A zero divisor throws `__umodti3: integer divide by zero (0x<dividend> % 0)`, where compiler-rt's `udivmodti4` would reach a native divide that traps. Exported from libc next to `__udivti3` (the relinker routes `libSceLibcInternal` imports to `libc.prx`); `__modti3`/`__udivmodti4` are not added because no title imports them. TechnicalDebt bullet beside the `__udivti3` one. - `guest_crt` checks literal remainders: small cases, 2^100 % 3, (2^128-1) % 10, (2^128-1) % 2^64, two divisors above 2^64, divisor 1, equal operands, a dividend below the divisor, (2^128-1) % 2^127, and the zero-divisor message through the export. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_crt` 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 606/606; with `main`'s `SonyCrt.hpp` the branch no longer compiles (the export needs the helper), so the negative check is by construction; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux; the titles were not relinked. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
milescoviello commented 2026-10-12 12:28:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-12T12:28:23Z.


Carried in #4462, keeping your commit and authorship. #4037 had merged in the meantime, so I resolved the conflict you expected in SonyCrt.hpp and GuestCrt.cpp (the PR lists exactly what changed) and checked it on Linux with GCC 13.3: guest_crt passes, it doesn't link without your __umodti3, and all 304 guest_* tests pass. Thanks for the branch.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124265237 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4460#issuecomment-6124265237). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-12T12:28:23Z. --- Carried in #4462, keeping your commit and authorship. #4037 had merged in the meantime, so I resolved the conflict you expected in `SonyCrt.hpp` and `GuestCrt.cpp` (the PR lists exactly what changed) and checked it on Linux with GCC 13.3: `guest_crt` passes, it doesn't link without your `__umodti3`, and all 304 `guest_*` tests pass. Thanks for the branch. AI-assisted: yes
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#4460
No description provided.