Repository navigation
cobalt: Implement the hermetic gmtime_r without ICU - #13142
Merged
Merged
Conversation
youtube#6748 replaced the whole `time_t` to `struct tm` family with ICU implementations, but only `localtime`, `localtime_r` and `mktime` need the timezone database. UTC has no offset to apply, so `gmtime_r` can use the plain computation musl already provides. This removes a deadlock: ICU initializes lazily and logs when it fails, and Starboard's logging calls `gmtime_r` to timestamp every message, so the failure reenters the initialization and spins forever inside its `pthread_once`. It was exposed by youtube#12193, which moved the ICU data from `libcobalt.so` to a file. That made AOSP hang at startup, since its apk didn't ship the file until youtube#12651 added it. Bug: 495203133
Contributor
🤖 Gemini Suggested Commit Message💡 Pro Tips for a Better Commit Message:
|
Contributor
|
Contributor
There was a problem hiding this comment.
Code Review
This pull request simplifies the gmtime implementation by removing the ICU-dependent gmtime_r override in favor of musl's upstream gmtime_r and __secs_to_tm implementations, which are now included in the build. Additionally, a __utc constant is defined in __tz.c. The review feedback recommends adding a defensive nullptr check for the input time pointer in gmtime to prevent a potential null pointer dereference.
The overflow cases used values that still fit in a `struct tm`, which the ICU-based `gmtime_r` only rejected because youtube#6748 miscalculated its limits. Test the real limits, where `tm_year` is `INT_MAX` and `INT_MIN`: each must convert, and one second past it must fail with `EOVERFLOW`. Bug: 495203133
sacuff
approved these changes
Oct 8, 2026
This was referenced Oct 8, 2026
briantting
pushed a commit
that referenced
this pull request
Oct 12, 2026
…t ICU Refer to original PR: #13142 #6748 replaced the whole `time_t` to `struct tm` family with ICU implementations, but only `localtime`, `localtime_r` and `mktime` need the timezone database. UTC has no offset to apply, so `gmtime_r` can use the plain computation musl already provides. This removes a deadlock: ICU initializes lazily and logs when it fails, and Starboard's logging calls `gmtime_r` to timestamp every message, so the failure reenters the initialization and spins forever inside its `pthread_once`. It was exposed by #12193, which moved the ICU data from `libcobalt.so` to a file. That made AOSP hang at startup, since its apk didn't ship the file until #12651 added it. The `gmtime` overflow tests used values that fit in a `struct tm`, which only the ICU implementation from #6748 rejected, so they had to be hermetic-only. They now test the real `tm_year` limits, which musl and glibc both honour, and drop that guard. Bug: 495203133 (cherry picked from commit 8d73819)
briantting
pushed a commit
that referenced
this pull request
Oct 16, 2026
…t ICU Refer to original PR: #13142 #6748 replaced the whole `time_t` to `struct tm` family with ICU implementations, but only `localtime`, `localtime_r` and `mktime` need the timezone database. UTC has no offset to apply, so `gmtime_r` can use the plain computation musl already provides. This removes a deadlock: ICU initializes lazily and logs when it fails, and Starboard's logging calls `gmtime_r` to timestamp every message, so the failure reenters the initialization and spins forever inside its `pthread_once`. It was exposed by #12193, which moved the ICU data from `libcobalt.so` to a file. That made AOSP hang at startup, since its apk didn't ship the file until #12651 added it. The `gmtime` overflow tests used values that fit in a `struct tm`, which only the ICU implementation from #6748 rejected, so they had to be hermetic-only. They now test the real `tm_year` limits, which musl and glibc both honour, and drop that guard. Bug: 495203133 (cherry picked from commit 8d73819)
briantting
pushed a commit
that referenced
this pull request
Oct 16, 2026
…t ICU Refer to original PR: #13142 #6748 replaced the whole `time_t` to `struct tm` family with ICU implementations, but only `localtime`, `localtime_r` and `mktime` need the timezone database. UTC has no offset to apply, so `gmtime_r` can use the plain computation musl already provides. This removes a deadlock: ICU initializes lazily and logs when it fails, and Starboard's logging calls `gmtime_r` to timestamp every message, so the failure reenters the initialization and spins forever inside its `pthread_once`. It was exposed by #12193, which moved the ICU data from `libcobalt.so` to a file. That made AOSP hang at startup, since its apk didn't ship the file until #12651 added it. The `gmtime` overflow tests used values that fit in a `struct tm`, which only the ICU implementation from #6748 rejected, so they had to be hermetic-only. They now test the real `tm_year` limits, which musl and glibc both honour, and drop that guard. Bug: 495203133 (cherry picked from commit 8d73819)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#6748 replaced the whole
time_ttostruct tmfamily with ICU implementations, but onlylocaltime,localtime_randmktimeneed the timezone database. UTC has no offset to apply, sogmtime_rcan use the plain computation musl already provides.This removes a deadlock: ICU initializes lazily and logs when it fails, and Starboard's logging calls
gmtime_rto timestamp every message, so the failure reenters the initialization and spins forever inside itspthread_once. It was exposed by#12193, which moved the ICU data from
libcobalt.soto a file. That made AOSP hang at startup, since its apk didn't ship the file until #12651 added it.The
gmtimeoverflow tests used values that fit in astruct tm, which only the ICU implementation from #6748 rejected, so they had to be hermetic-only. They now test the realtm_yearlimits, which musl and glibc both honour, and drop that guard.Bug: 495203133