Skip to content

musl: 64-bit time support #4463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

musl: 64-bit time support #4463

wants to merge 11 commits into from

Conversation

xbjfk
Copy link
Contributor

@xbjfk xbjfk commented May 26, 2025

Description

This change includes time64 support for applicable architectures (x86, arm, mips and powerpc). This is based on the previous PRs to this repo as well as the musl changelog from 1.1.24 -> 1.2. It can be enabled with the environment variable
RUST_LIBC_UNSTABLE_MUSL_TIME64 only when musl_v1_2_3 is enabled and the architecture is supported.

A lot of structures, especially ones with mixed endian became excessively complicated, so I used cfg_if to separate them. It looks like you can only nest s! {} in cfg_if! {}, but not vice versa.

As a note, I'm considering removing musl_not_time64, and just keeping the old logic of allowing deprecated for function definitions involving time_t as it introduces necessary complexity.

When libc 1.0 is released, I believe the best path would be to remove the musl_v1_2_3 feature, making it unconditionally enabled, keeping musl_time64 which will expand to (musl && time64_arch).

Tested through QEMU for all architectures.

Sources

Sources are located on each commit, in the form of upstream commits

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see rust-lang/libc#3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot rustbot added A-CI Area: CI-related items O-arm O-linux O-linux-like O-mips O-musl O-unix O-x86 S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels May 26, 2025
@xbjfk xbjfk changed the title musl: time64 musl: 64-bit time support May 26, 2025
@xbjfk xbjfk mentioned this pull request May 26, 2025
5 tasks
@xbjfk
Copy link
Contributor Author

xbjfk commented May 26, 2025

Hmm, seems like the style checker isn't happy with mixing s! {} and cfg_if! {}, and putting cfg_if! {} inside an s! {} block does not seem to work either. I'm not sure what the best course of action is regarding this.

@xbjfk
Copy link
Contributor Author

xbjfk commented May 30, 2025

Since #4433 seems close to merging, I can rebase on top of it once merged.

xbjfk added 2 commits June 3, 2025 07:53
This feature is enabled with independently from musl_v1_2_3 to support
time64. This also sets a musl_not_time64 feature to make `cfg`
statements easier to read.

Defining linux_time_bits64 makes this roughly equivalent to upstream
commit bminor/musl@f12bd8e.
xbjfk added 2 commits June 3, 2025 07:59
This corresponds to upstream commit bminor/musl@1febd21 (most symbols)
and bminor/musl@22daaea (only dlsym)
A bunch of properties were removed upstream and set to reserved.

This matches upstream commit bminor/musl@827aa8f and bminor/musl@2d69fcf
@xbjfk xbjfk force-pushed the musl-time64 branch 3 times, most recently from 44fe8c9 to 8b32bb3 Compare June 3, 2025 08:21
xbjfk added 7 commits June 3, 2025 08:26
Change time_t type to i64
Change struct stat, msqid_ds and shmid_ds to reflect

This commit follows upstream bminor/musl@3814333 and bminor/musl@d6dcfe4
It also implements a fix from bminor/musl@0fbd7d6
This is primarily based on a small part of bminor/musl@3814333.

This also integrates bminor/musl@3c02bac, which update MSG_STAT,
SEM_STAT, SEM_STAT_ANY. These are based on the value of IPC_STAT,
however we can just use `cfg` as it is effectively the same.
This was incorrectly named in upstream musl and fixed in
bminor/musl@cabc369
This is because the struct is different depending on whether time64 is
enabled.
@xbjfk
Copy link
Contributor Author

xbjfk commented Jun 3, 2025

Rebased on top of the GNU changes :)

@tgross35
Copy link
Contributor

tgross35 commented Jun 3, 2025

Thanks! Sorry it's taken me a while, I'll try to look at this very soon

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Left a few comments here.

For the style check, are the changes it is suggesting possible? If not, that will probably have to be updated unfortunately (hopefully we will be able to reorganize things at some point so it's less annoying...)

Comment on lines +100 to +110
if ((musl_v1_2_3 || target_os == "loongarch64") && target_env == "musl") || target_env == "ohos"
{
set_cfg("musl_v1_2_3");
if musl_time64 && MUSL_TIME64_ARCHS.contains(&target_arch.as_str()) {
set_cfg("musl_time64");
set_cfg("linux_time_bits64");
} else {
set_cfg("musl_not_time64");
}
} else if target_env == "musl" || target_env == "ohos" {
set_cfg("musl_not_time64");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is musl_not_time64 needed? not(musl_time64) should be usable everywhere.

Comment on lines 46 to 51
--env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \
--env RUST_LIBC_UNSTABLE_GNU_TIME_BITS \
--env RUST_LIBC_UNSTABLE_MUSL_V1_2_3 \
--env RUST_LIBC_UNSTABLE_MUSL_TIME64 \
--env CARGO_HOME=/cargo \
--env CARGO_TARGET_DIR=/checkout/target \
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this should match the indentation

Copy link
Contributor

Choose a reason for hiding this comment

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

I think musl_time64 as it is used should be named something like musl_time64_on_32. We probably don't need an env to set this independently, build.rs should just set it when musl_time64 is set and target_ptr_width is 32.

Comment on lines +2853 to 2856
#[cfg(musl_time64)]
pub const IPC_STAT: c_int = 0x102;
#[cfg(not(musl_time64))]
pub const IPC_STAT: c_int = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Style nit: these should be writeable as pub const IPC_STAT: c_int = if cfg!(musl_time64) { 0x102 } else { 2 } to get the else fallback and reduce the amount of code that is cfged out on some platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI Area: CI-related items O-arm O-linux O-linux-like O-mips O-musl O-unix O-x86 S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants