compiler: add 'b_time64' base option - #15008
Draft
dvdhrm wants to merge 1 commit into
Draft
Conversation
Introduce a new base option called `b_time64`. This is a boolean option,
which defaults to `false` (in which case it has no effect). If set to
true, this will set `_TIME_BITS=64` (or equivalent) for all
compilations.
This enables a workaround for the Y2038 problem. With `_TIME_BITS=64`,
libc will switch `time_t` and other relevant time types to 64-bits, if
not already 64-bit (i.e., this usually only affects 32-bit platforms).
libc will also transparently switch to 64-bit syscalls.
For more background information, there is an LWN article about it (from
10 years ago):
https://lwn.net/Articles/664800/
Handling of this option is similar to _FILE_OFFSET_BITS=64, which meson
sets by default. Unfortunately, `time_t` is much more often used in
public APIs, and thus more likely to lead to ABI mismatches when mixing
code compiled with and without the option.
Contributor
Author
|
(update: fixed get_option() invocation) |
Contributor
Author
|
I would welcome any help in how to properly query the option without having a build target. All my attempts seem to fail so far. |
Contributor
|
Can you just skip the call to |
dcbaker
requested changes
Oct 24, 2025
| """ | ||
| return [] | ||
|
|
||
| def get_time64_args(self) -> T.List[str]: |
Member
There was a problem hiding this comment.
We usually implement these as something like:
def get_time64_args(self, enable: bool) -> T.List[str]:
return ['-D_TIME_BITS=64'] if enable else []So that you don't have to have the check in every caller.
| time64 = state.get_option('b_time64', state.subproject) | ||
| assert isinstance(time64, bool), 'for mypy' | ||
| if time64: | ||
| clang_args.append('-D_TIME_BITS=64') |
Member
There was a problem hiding this comment.
We had a recent change here that with the _FILE_OFFSET bits maybe we can add this to the same block? (it uses the CCompiler instance so we avoid the need to copy the define here)
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.
Introduce a new base option called
b_time64. This is a boolean option, which defaults tofalse(in which case it has no effect). If set to true, this will set_TIME_BITS=64(or equivalent) for all compilations.This enables a workaround for the Y2038 problem. With
_TIME_BITS=64, libc will switchtime_tand other relevant time types to 64-bits, if not already 64-bit (i.e., this usually only affects 32-bit platforms). libc will also transparently switch to 64-bit syscalls.For more background information, there is an LWN article about it (from 10 years ago):
Handling of this option is similar to _FILE_OFFSET_BITS=64, which meson sets by default. Unfortunately,
time_tis much more often used in public APIs, and thus more likely to lead to ABI mismatches when mixing code compiled with and without the option.NB: This is a draft, as I have not spent too much time figuring out whether this should be a boolean option, or a choice-option (so you can override the value with
32), and whether this needs support for other languages. This is mostly to start a discussion around the feature.