Skip to content
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

Add new cfg linux_time_bits64 corresponding to __USE_TIME_BITS64 #4148

Merged
merged 5 commits into from
Dec 9, 2024

Conversation

snogge
Copy link
Contributor

@snogge snogge commented Nov 25, 2024

Description

Add a new cfg linux_time_bits64 -- corresponding to the kernels __USE_TIME_BITS64 -- with some associated changes as a base for 64bit time_t support for glibc and musl

Sources

https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/socket.h#L157
https://github.com/torvalds/linux/blob/master/arch/mips/include/uapi/asm/socket.h#L164
https://github.com/torvalds/linux/blob/master/arch/powerpc/include/uapi/asm/socket.h

https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/resource.h#L58
https://github.com/torvalds/linux/blob/master/arch/mips/include/uapi/asm/resource.h#L31

https://github.com/torvalds/linux/blob/master/include/uapi/linux/input.h#L28

https://github.com/torvalds/linux/blob/master/include/uapi/linux/time.h#L17

Checklist

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

@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2024

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tgross35
Copy link
Contributor

tgross35 commented Nov 25, 2024

Thanks! I'll need to double check the definitions but at first glance this looks good.

Could you add an internal env RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64 in build.rs to set this config? Then here

add

if [ "$os" = "linux" ]; then
    RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
fi

So we make sure the build is correct in CI

build.rs Show resolved Hide resolved
@tgross35
Copy link
Contributor

Also FYI there is a large edition refactor coming #4132 so this will probably wind up with conflicts in the near future.

src/unix/mod.rs Outdated Show resolved Hide resolved
Comment on lines 326 to 338
pub struct input_event {
pub time: ::timeval,
#[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))]
pub input_event_sec: ::time_t,
#[cfg(all(target_pointer_width = "32", linux_time_bits64))]
pub input_event_sec: ::c_ulong,

#[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))]
pub input_event_usec: ::suseconds_t,
#[cfg(all(target_pointer_width = "32", linux_time_bits64))]
pub input_event_usec: ::c_ulong,

#[cfg(target_arch = "sparc64")]
_pad1: ::c_int,
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 that we should leave the pub time: ::timeval for #[cfg(any(target_pointer_width = "64", not(linux_time_bits64)))] to minimize breakage. Maybe it's better to leave time or __sec+__usec as the fields, then make input_event_u?sec methods on the struct.

Also I believe sparc64 needs __usec/input_event_usec to be a c_uint rather than c_ulong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I choose the current struct based on the discussion starting here #3175 (review) . The input_event_X members are the platform independent way of referring to these members, even if I cannot find any documentation for this.
We can exclude the input_event change from this PR for now if we need to discuss this further,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And suseconds_t is i32 on sparc64 for glibc. As far as I can tell none of the other libc's support sparc64.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the information, that reasoning makes sense. Agreed that we should make this change but I would like to be able to backport this PR (so users can start experimenting before commiting to 1.0) so I don't think we should make this change now. Would it be possible to:

  1. Leave time with the cfg mentioned in Add new cfg linux_time_bits64 corresponding to __USE_TIME_BITS64 #4148 (comment)
  2. Just put the conflicting input_event_* in a block comment with a FIXME(1.0): ... so we make this change before that release

I think we should mark time deprecated at some point but I am hesitant to do that without a migration path, so this can be revisited later.

@rustbot rustbot added the A-CI Area: CI-related items label Nov 26, 2024
@snogge snogge force-pushed the linux_time_bits64 branch 3 times, most recently from e38313d to 34378b5 Compare November 26, 2024 19:29
@snogge
Copy link
Contributor Author

snogge commented Nov 26, 2024

I think I've addressed most of your comments. I did not change the input_event struct as I think the current version is the most compatible one.

@bors
Copy link
Contributor

bors commented Nov 27, 2024

☔ The latest upstream changes (presumably #4132) made this pull request unmergeable. Please resolve the merge conflicts.

@snogge
Copy link
Contributor Author

snogge commented Nov 28, 2024

The PR has been rebased on main, including the mentioned refactor in #4132 .

@tgross35
Copy link
Contributor

Thanks for the changes, I'll double check this within the next couple of days (the recent MSRV bump and edition change have been pretty time consuming in this repo).

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Dec 6, 2024
@tgross35
Copy link
Contributor

tgross35 commented Dec 6, 2024

One last request to defer the time field change until later and then this looks great to me.

linux_time_bits64 will be used to match __USE_TIME_BITS64 in the uapi
headers.

The environment variable RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64 can be
used by callers to enable the linux_time_bits64 config.
The actual values may be different on 32bit archs with
and without __USE_TIME_BITS64
@snogge snogge force-pushed the linux_time_bits64 branch from 2cb283e to 7572399 Compare December 9, 2024 10:05
@snogge
Copy link
Contributor Author

snogge commented Dec 9, 2024

I've updated input_event as I think you meant.

struct timeval has to be updated at least for glibc with _TIME_BITS=64.
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.

Looks great, thanks for the changes! You can run ./ci/style.sh to fix whatever the failure is.

@snogge snogge force-pushed the linux_time_bits64 branch from 7572399 to c201302 Compare December 9, 2024 10:09
@tgross35 tgross35 enabled auto-merge December 9, 2024 10:10
@tgross35 tgross35 added this pull request to the merge queue Dec 9, 2024
Merged via the queue into rust-lang:main with commit 3b458ff Dec 9, 2024
45 checks passed
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-linux O-mips O-unix 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.

4 participants