-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Deprecate windows time64_t
#5032
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
dybucc
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
dybucc:time64-windows-deprecation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+29
−18
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //! Ensures Windows `time`-related routines align with `libc`'s interface. By | ||
| //! default, both MSVC and GNU (under `mingw`) expose 64-bit symbols. `libc` | ||
| //! also does that, but there's been slight inconsistencies in the past. | ||
|
|
||
| #![cfg(windows)] | ||
|
|
||
| /// Ensures a 64-bit write is performed on values that should always be 64 bits. | ||
| /// This may fail if | ||
| /// (1) the routine links with its 32-bit variant. This only happens if | ||
| /// `_USE_32BIT_TIME_T` is defined. In theory, this should not be | ||
| /// possible when working with Rust's `libc`. | ||
| /// (2) Or `time_t` is 32-bits, and a 64-bit write overwrites both array items. | ||
| /// This should neither be possible unless the above macro is defined. | ||
| /// Support for non-64-bit values in `libc` should thus be non-existent. | ||
| #[test] | ||
| fn test_64_bit_store() { | ||
| let mut time_values: [libc::time_t; 2] = [123, 456]; | ||
| let ptr = time_values.as_mut_ptr(); | ||
| unsafe { libc::time(ptr) }; | ||
| assert!(time_values[0] != 123); | ||
| assert_eq!(time_values[1], 456); | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View changes since the review
Have you run any tests before and after this change for whether things work? I'm wondering about this group of functions where it seems like we're already linking the time64 version in some cases
libc/src/windows/mod.rs
Lines 393 to 413 in ff0e616
To test this you could use the
libcfrommainand pass a pointer to a[time_t; 2]to thetimefunction, both initialized to 0x1234abcd or whatever. If only one of them gets overwritten with the current time, there isn't a bug and things are working despite the link name. If one gets the current time and the other gets zeroed, then we have a bug.This PR would fix it but we can't backport because of the breakage, so we'll need configure the
link_nameattributes behindnot(x86+gnu).(I realize that's rather confusing, let me know if anything needs clarification)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the first question on tests, I have run the existing
libctest suiteboth before and after the changes, though admittedly I did not run it prior to
making the changes to
src/windows/mod.rs, but without skippingtime_tinbuild.rs.I'm not sure what do you mean when you say those routines may be faulty in the
current
mainworktree. From what I could gather of the Windows CRT docs (e.g.[1], as all routines explain things similarly in this respect,) there
shouldn't be any issues, considering the non-suffixed variants are just wrappers
for the suffixed, 64-bit variants. So linking the 64-bit symbol with a type that
is also 64-bits wide now should be fine. Still, I understand there may be some
concerns with GNU on Windows, as in those cases, the expected
time_t(prior tothis PR) was 32-bits wide, so that could be an issue.
Either way, I'll get back in a few hours once I actually run your test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be a bug in the current
mainworktree. Running on Windows x86 GNU,with a two-element array of 32-bit
time_t, a 64-bit store is being performedon the pointer's pointee that gets passed to one of these 64-bit-linked routines
(tested it out with
time()inlibc, which links by default on alltargets/environments to
_time64()) as one of the elements is zeroed after thecall.
I would personally say the bug is not in linking these routines by default to
their 64-bit variants, but rather in the fact that we assume a 32-bit
time_ton Windows GNU x86. By default, Rust's
libcbehaves correctly under MSVC, astime_tis always 64-bit wide unlessUSE_32BIT_TIME_Tis defined, no matterthe target triple, and in
libcwe opted out of adding support for that featuretest macro. On the other hand, when running under
mingwwith GNU in x86, wealways define
time_tto be 32-bit wide. This, according to [1] and [2], isincorrect, as behavior in
mingwis exactly like that in MSVC when it comes tobit-width; Namely, define
USE_32BIT_TIME_Tif you want 32-bittime_tandnon-suffixed variants to default to their 32-bit variants, otherwise, it's
64-bit
time_tall the way through.Running the test with the changes in this PR solves the issues, simply because
there's no 32-bit
time_texposed on Rust'slibcunder Windows anymore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be able to add that test to
libc-test/tests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.