fix(libc): honor guest TZ in time conversions #6916

Merged
MarcZX10 merged 8 commits from upstream-pr/6916 into main 2026-10-19 14:08:10 +00:00
MarcZX10 commented 2026-10-16 18:14:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T18:14:06Z.


What

Applies the guest process's TZ value to host-backed tzset, localtime, mktime and strftime conversions, so guest setenv, putenv and unsetenv changes are honored. Time zone updates and conversions are serialized, each outer conversion uses one guest TZ snapshot, and implicit changes refresh the exported tzname pointers.

Carries Hussein Kadhim's three implementation commits with his original commit authorship preserved. Adds a regression for the implicit setenv("TZ") path and moves the timezone debt note to docs/dev/debt/libc.md.

Closes #6910.

Tested

  • Linux Release: guest_time_conversion and guest_mktime pass (2/2).
  • guest_rtc_tests builds; its runtime stops at the host CPU feature guard before assertions on this Xeon E5-1620 v2.
  • Hosted checks on head c5a2f3631: Ubuntu, macOS and Windows relinker jobs pass; register-context jobs pass on Ubuntu/macOS Intel and write-watch jobs pass on macOS. Full Linux/Windows application builds were skipped by workflow filters.
  • Temporary Linux composition of #6686 and #6916 passed guest_time_conversion, retaining the original host-side region setenv; an added temporary assertion confirmed expected offsets for all four regions. No production or test changes from #6686 are included here.
  • Repository conventions and git diff --check pass locally against current main (93e54cedd).

Independent Linux validation reported by Dextroid17 on exact head 0416fb91c: CachyOS 7.2.9, i9-11900K, GCC 16.2.1, with TZ unset (host zone America/Toronto). guest_time_conversion and guest_mktime both passed in 3/3 runs; the revert control failed guest_time_conversion in 3/3 with Local epoch conversion failed; the merged build also passed with five host TZ settings. This is historical validation against main 47a266cf9; Windows/macOS runtime and other revert-arm time zones were not tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4892477676 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6916). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T18:14:06Z. --- ### What Applies the guest process's `TZ` value to host-backed `tzset`, `localtime`, `mktime` and `strftime` conversions, so guest `setenv`, `putenv` and `unsetenv` changes are honored. Time zone updates and conversions are serialized, each outer conversion uses one guest `TZ` snapshot, and implicit changes refresh the exported `tzname` pointers. Carries Hussein Kadhim's three implementation commits with his original commit authorship preserved. Adds a regression for the implicit `setenv("TZ")` path and moves the timezone debt note to `docs/dev/debt/libc.md`. Closes #6910. ### Tested - Linux Release: `guest_time_conversion` and `guest_mktime` pass (2/2). - `guest_rtc_tests` builds; its runtime stops at the host CPU feature guard before assertions on this Xeon E5-1620 v2. - Hosted checks on head `c5a2f3631`: Ubuntu, macOS and Windows relinker jobs pass; register-context jobs pass on Ubuntu/macOS Intel and write-watch jobs pass on macOS. Full Linux/Windows application builds were skipped by workflow filters. - Temporary Linux composition of #6686 and #6916 passed `guest_time_conversion`, retaining the original host-side region `setenv`; an added temporary assertion confirmed expected offsets for all four regions. No production or test changes from #6686 are included here. - Repository conventions and `git diff --check` pass locally against current `main` (`93e54cedd`). Independent Linux validation reported by Dextroid17 on exact head `0416fb91c`: CachyOS 7.2.9, i9-11900K, GCC 16.2.1, with `TZ` unset (host zone America/Toronto). `guest_time_conversion` and `guest_mktime` both passed in 3/3 runs; the revert control failed `guest_time_conversion` in 3/3 with `Local epoch conversion failed`; the merged build also passed with five host TZ settings. This is historical validation against main `47a266cf9`; Windows/macOS runtime and other revert-arm time zones were not tested. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-16 18:44:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T18:44:48Z.


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.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/src/Time.cpp
docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestMktime.cpp
core/libs/tests/GuestTimeConversion.cpp
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/src/Time.cpp
PR 7332 core/libs/prx/libc/src/Time.cpp
docs/dev/debt/libc.md
PR 7417 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7525 docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/src/Environment.cpp
docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6222384192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6916#issuecomment-6222384192). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T18:44:48Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/Time.cpp`<br>`docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestMktime.cpp`<br>`core/libs/tests/GuestTimeConversion.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Time.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/src/Time.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7525](https://www.github.com/boykopovar/AnyPS5/pull/7525) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `core/libs/prx/libc/src/Environment.cpp`<br>`docs/dev/debt/libc.md` |
Dextroid17 commented 2026-10-17 14:35:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-17T14:35:09Z.


Native Linux run of this head.

Setup: head 0416fb91c (merge-base with main 93e54cedd), BUILD_TESTING=ON, Ninja, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1, host time zone America/Toronto (TZ unset under env -i). Tests ran under env -i with only HOME and PATH set. Each arm ran 3 times. Command: ctest -R '^guest_time_conversion$|^guest_mktime$'.

  • Head: 2 of 2 pass in each of the 3 runs.
  • Revert arm: with General.hpp, Environment.cpp and Time.cpp under core/libs/prx/libc as on 93e54cedd and the PR's tests kept, guest_time_conversion aborts 3 of 3 with Local epoch conversion failed. guest_mktime passes.
  • Merged with main at 47a266cf9: the branch is 573 commits behind but merges cleanly, and 2 of 2 pass in each of the 3 runs. tools/check_conventions.py passes.
  • Host TZ sweep: the merged-build guest_time_conversion_tests also passes with host TZ set to UTC, Asia/Tokyo, Pacific/Kiritimati, America/Los_Angeles and Europe/Athens. The revert arm was run only under America/Toronto, where the guest UTC-2 and the host offset differ.

Not checked: Windows, macOS, PS5 hardware, and the revert arm under other host time zones.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235152251 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6916#issuecomment-6235152251). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-17T14:35:09Z. --- Native Linux run of this head. **Setup:** head `0416fb91c` (merge-base with `main` `93e54cedd`), `BUILD_TESTING=ON`, Ninja, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1, host time zone `America/Toronto` (`TZ` unset under `env -i`). Tests ran under `env -i` with only `HOME` and `PATH` set. Each arm ran 3 times. Command: `ctest -R '^guest_time_conversion$|^guest_mktime$'`. - **Head:** 2 of 2 pass in each of the 3 runs. - **Revert arm:** with `General.hpp`, `Environment.cpp` and `Time.cpp` under `core/libs/prx/libc` as on `93e54cedd` and the PR's tests kept, `guest_time_conversion` aborts 3 of 3 with `Local epoch conversion failed`. `guest_mktime` passes. - **Merged with `main` at `47a266cf9`:** the branch is 573 commits behind but merges cleanly, and 2 of 2 pass in each of the 3 runs. `tools/check_conventions.py` passes. - **Host TZ sweep:** the merged-build `guest_time_conversion_tests` also passes with host `TZ` set to `UTC`, `Asia/Tokyo`, `Pacific/Kiritimati`, `America/Los_Angeles` and `Europe/Athens`. The revert arm was run only under `America/Toronto`, where the guest `UTC-2` and the host offset differ. Not checked: Windows, macOS, PS5 hardware, and the revert arm under other host time zones. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. AI-assisted: yes
MarcZX10 commented 2026-10-17 18:13:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T18:13:18Z.


Thanks for running the Linux tests with TZ unset and sweeping the merged build across five host time zones. The exact-head pass and revert control give useful evidence for the TZ snapshot path, and I added those results to the PR description with their 47a266cf9 base and platform limits recorded.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6238365018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6916#issuecomment-6238365018). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T18:13:18Z. --- Thanks for running the Linux tests with `TZ` unset and sweeping the merged build across five host time zones. The exact-head pass and revert control give useful evidence for the `TZ` snapshot path, and I added those results to the PR description with their `47a266cf9` base and platform limits recorded.
MarcZX10 commented 2026-10-18 00:12:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T00:12:04Z.


Rebased this PR onto current upstream main and resolved the documentation conflict while preserving the unrelated main debt entry. The original Hussein Kadhim commits remain authored by Hussein; MarcZX100 is the committer for the rebase. The new head is mergeable and hosted eligibility, conventions, report, relinker (Ubuntu/Windows/macOS x86-64 and macOS under Rosetta), ASan relinker, register-context and write-watch jobs all pass. Broad Linux/Windows builds are skipped by the workflow path filter. Local conventions, diff check, and C++20 syntax checks for the changed time sources passed; no full local runtime test was run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243584284 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6916#issuecomment-6243584284). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T00:12:04Z. --- Rebased this PR onto current upstream main and resolved the documentation conflict while preserving the unrelated main debt entry. The original Hussein Kadhim commits remain authored by Hussein; MarcZX100 is the committer for the rebase. The new head is mergeable and hosted eligibility, conventions, report, relinker (Ubuntu/Windows/macOS x86-64 and macOS under Rosetta), ASan relinker, register-context and write-watch jobs all pass. Broad Linux/Windows builds are skipped by the workflow path filter. Local conventions, diff check, and C++20 syntax checks for the changed time sources passed; no full local runtime test was run.
adriadam10 commented 2026-10-19 14:10:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:10:09Z.


Rebased onto current main: #6686's CheckRegionZones set the host TZ directly, which no longer matches the guest-TZ model here, so I switched it (and the final EST5EDT tzname check) to setenv_nid_postfix. No production code changed.

Checked the zone lock/snapshot logic, the tzname refresh, the Windows UTC0 mapping and the debt entry against the diff; the guest-TZ tests and the revert control reported by @Dextroid17 cover the Linux behaviour; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269237260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6916#issuecomment-6269237260). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T14:10:09Z. --- Rebased onto current `main`: #6686's `CheckRegionZones` set the host `TZ` directly, which no longer matches the guest-`TZ` model here, so I switched it (and the final `EST5EDT` tzname check) to `setenv_nid_postfix`. No production code changed. Checked the zone lock/snapshot logic, the tzname refresh, the Windows `UTC0` mapping and the debt entry against the diff; the guest-TZ tests and the revert control reported by @Dextroid17 cover the Linux behaviour; merged.
Sign in to join this conversation.
No reviewers
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!6916
No description provided.