Skip to content

windows(gnu): link to 32-bit time routines in x86 and add test#5059

Merged
tgross35 merged 1 commit into
rust-lang:mainfrom
dybucc:fix-time32-windows-x86-gnu
Jun 26, 2026
Merged

windows(gnu): link to 32-bit time routines in x86 and add test#5059
tgross35 merged 1 commit into
rust-lang:mainfrom
dybucc:fix-time32-windows-x86-gnu

Conversation

@dybucc

@dybucc dybucc commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Description

Until #5032, whenever libc was running under Windows x86 with GNU, the default
bit-width of time_t values was 32-bits. This doesn't quite align with the defaults in MSVC and
mingw, but that's been addressed in that PR.

This PR is a quick patch for stable, as the changes in #5032 are not
backwards-compatible. It separates the routines that under Windows use time_t values and changes
their link-time symbols to the 32-bit variants exposed in both MSVC and mingw, for the affected
target platform/environment.

It also adds a test, akin to the one in #5032, that should ensure the correct
bit-widths are in use for both the types and the linked routine symbols.

Note that if both #5062 and this PR are to be merged, it's preferable to merge first #5062, as this
PR will then incorporate support for the cfg introduced in that PR.

Sources

None. If any, the same as #5032 as this stems from it.

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 label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Apr 14, 2026
@rustbot

This comment has been minimized.

@dybucc dybucc mentioned this pull request Apr 14, 2026
3 tasks
@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch 2 times, most recently from 9a434dd to c8cb7bc Compare April 14, 2026 17:31
@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch 2 times, most recently from 5a75a87 to a5c7202 Compare April 18, 2026 06:40
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch 2 times, most recently from 0021301 to 4e83e2d Compare April 18, 2026 07:31
@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 4e83e2d to 8c5047b Compare April 27, 2026 13:53
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 8c5047b to 320bd3c Compare April 28, 2026 15:35
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 320bd3c to f858022 Compare April 29, 2026 13:41
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from f858022 to 2bd4191 Compare May 2, 2026 07:34
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 2bd4191 to cdbd6e6 Compare May 5, 2026 12:47
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from cdbd6e6 to b7c9250 Compare May 6, 2026 06:56
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from b7c9250 to 0ef0992 Compare May 7, 2026 14:36
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 0ef0992 to 61d8568 Compare May 13, 2026 07:01
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 61d8568 to f1fd3c7 Compare May 14, 2026 07:00
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from ebdef8a to 8b5714c Compare June 25, 2026 10:22
Comment thread libc-test/tests/windows_time.rs Outdated
Comment on lines +24 to +25
assert_ne!(time_values[0], 123);
assert_eq!(time_values[1], 456);

@tgross35 tgross35 Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested comment based on #5032 (comment):

If only the first array value is written, libc's time_t is accurate for what the function time expects. If both array values wind up overwritten, we are probably linking a version of time that expects 64-bit time_t while our time_t is only 32 bits.

Also can you confirm that this fails with the current version?

View changes since the review

@dybucc dybucc Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can. CI doesn't catch this because we skip over time_t on Windows. I removed that in #5062.

Comment thread src/windows/mod.rs Outdated
// Under Windows x86 with GNU, `time_t` is still 32-bit wide on stable, so
// these routines have to link with their 32-bit variants.
cfg_if! {
if #[cfg(all(target_arch = "x86", target_env = "gnu", not(gnu_time_bits64)))] {

@tgross35 tgross35 Jun 26, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move anything gnu_time_bits64 bit to #5062, since it's not getting fully tested here and that PR doesn't currently do anything on its own.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I meant only the not(gnu_time_bits64) bit of the config, given the test failures and lack of it being tested. The link fixes are fine, that should be in this PR because it's a standalone fix.

Though if it's easier for you at this point to roll the two PRs together, that's fine too

@dybucc dybucc Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted and done. This PR should then be merged first. I'll solve the conflicts in #5062 then.

EDIT: No good. Reverted again. The linking issues remain solved in this PR. The other one will have to add the condition to the predicate once this one gets merged.

@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 8b5714c to b0393bb Compare June 26, 2026 08:01
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from b0393bb to 875f211 Compare June 26, 2026 08:05
@dybucc dybucc changed the title windows(gnu): link correct 32-bit time_t functions windows(gnu): add test on to ensure bit width of time_t Jun 26, 2026
@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from 875f211 to a9ee123 Compare June 26, 2026 09:15
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch 3 times, most recently from 3dcc67c to 9bfedc2 Compare June 26, 2026 09:40
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One nit and history cleanup then LGTM

View changes since this review

Comment thread libc-test/tests/windows_time.rs Outdated
Link to the correct routines in Windows x86 GNU. These were not linked
before. They expected a 64-bit `time_t`. This is not the bit width
exposed in `libc` for `time_t` in that target triple.
@dybucc dybucc force-pushed the fix-time32-windows-x86-gnu branch from a07e2c5 to c5d3c12 Compare June 26, 2026 15:09
@dybucc dybucc changed the title windows(gnu): add test on to ensure bit width of time_t windows(gnu): link to 32-bit time routines in x86 and add test Jun 26, 2026
@tgross35 tgross35 added this pull request to the merge queue Jun 26, 2026
@tgross35

Copy link
Copy Markdown
Contributor

Question: why doesn't this cause the function pointer comparison tests to fail on win32-gnu?

Merged via the queue into rust-lang:main with commit 5bbfc84 Jun 26, 2026
54 checks passed
@dybucc

dybucc commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Question: why doesn't this cause the function pointer comparison tests to fail on win32-gnu?

Function pointer checks are skipped on Windows [1]. I've tried to look into this. I haven't found the reason why stuff is failing. The decorated names in MSVC seem to use cdecl but the unresolved errors to all exposed routines also happen in x86_64. I've experimented adding cdecl under x86. This does not seem to work. Function pointer checks still fail in x86_64 when they shouldn't. This includes non-time_t routines. There's no documentation on the linking of decorated names in MSVC either.

@tgross35

Copy link
Copy Markdown
Contributor

Only on MSVC or on GNU as well? We could at least limit the skips if it's the former.

Calling convention shouldn't affect the function pointer checks regarding address mismatches. It would be nice if we could check calling convention in ctest somehow but I don't believe those mismatches show up anywhere.

You might get a hint if you make a Rust library where you call a libc symbol and a C library where you call the same symbol, then llvm-nm them if there's a mismatch in the undefined symbols list. But I don't think it's worth digging into too much.

@tgross35

Copy link
Copy Markdown
Contributor

Mind just opening a new issue with your findings so we don't lose this?

@dybucc

dybucc commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

It happens on both MSVC and GNU. Just opened the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author 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