Skip to content

compiler: add 'b_time64' base option - #15008

Draft
dvdhrm wants to merge 1 commit into
mesonbuild:masterfrom
dvdhrm:pr/time64
Draft

compiler: add 'b_time64' base option#15008
dvdhrm wants to merge 1 commit into
mesonbuild:masterfrom
dvdhrm:pr/time64

Conversation

@dvdhrm

@dvdhrm dvdhrm commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

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.

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.

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.
@dvdhrm

dvdhrm commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

(update: fixed get_option() invocation)

@dvdhrm

dvdhrm commented Sep 9, 2025

Copy link
Copy Markdown
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.

@bonzini

bonzini commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Can you just skip the call to get_option if you give the warning about _FILE_OFFSET_BITS?

"""
return []

def get_time64_args(self) -> T.List[str]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@bonzini bonzini modified the milestones: 1.10, 1.11 Nov 7, 2025
@bonzini bonzini modified the milestones: 1.11, 1.12 Apr 3, 2026
@bonzini bonzini modified the milestones: 1.12, 1.13 Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants