Skip to content

[0.2] newlib: Restore st_{a,m,c}time in the stat struct - #5662

Open
ivmarkov wants to merge 1 commit into
rust-lang:libc-0.2from
ivmarkov:fix-stat-espidf
Open

ivmarkov wants to merge 1 commit into
rust-lang:libc-0.2from
ivmarkov:fix-stat-espidf

Conversation

@ivmarkov

@ivmarkov ivmarkov commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The [0.2] backport of #5132 (#5454, commit 27fe099) (accidentally?) also carried over the newlib stat from #5061, which was stable-declined.

Renaming st_{a,m,c}time to st_{a,m,c}tim broke ESP-IDF and RTEMS, in that STD no longer builds since its bump to 0.2.191 (rust-lang/rust#164555, rust-lang/rust#164719). And neither does rustix 0.38 by the way.

This PR restores the 0.2 field names.

Additionally, I had to introduce a few extra "pad" fields, so that the 0.2.190 layout is kept, which is the correct one for 64-bit time_t, because the old struct incorrectly placed st_blksize, st_blocks and st_spare4 4 bytes too early.

(The wrong st_blksize and st_blocks were probably never found as they are not really used / read much in the ESP-IDF Rust land, to my knowledge.)

Also:

  • Horizon uses its own stat again (the generic one was shadowing it)
  • Remove newlib/generic.rs as it is seemingly unused

NOTE: A lot of the research on the topic and the final fix was done/suggested by an LLM. Mentioning because I think the rust-lang policy requires it.

@rustbot

This comment has been minimized.

@ivmarkov ivmarkov changed the title newlib: Restore st_{a,m,c}time in the stat struct [0.2] newlib: Restore st_{a,m,c}time in the stat struct Oct 23, 2026
@tgross35

Copy link
Copy Markdown
Member

This indeed snuck under the radar. LGTM, but could you put some of the context from the PR description into the commit message? Since the description doesn't make it to history.

Also I don't know if there's a way to test this target, but if so then it would be nice to add to #5209

@rustbot

This comment has been minimized.

The 0.2 backport of rust-lang#5132 also carried over
rust-lang#5061's `stat` (stable-declined), breaking std on
ESP-IDF and RTEMS (rust-lang/rust#164555) and rustix 0.38.

Restore the 0.2 names, keeping the 0.2.190 layout via private padding
(correct for 64-bit `time_t`). Also let horizon use its own `stat`
again and drop the unused `newlib/generic.rs`.
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • Pull requests are usually filed against the main branch for this repo, but this one is against libc-0.2. Please double check that you specified the right target!

@tgross35 tgross35 left a comment •

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.

Thanks! LGTM, I'll merge when it's time for the other backports

View changes since this review

@ivmarkov

Copy link
Copy Markdown
Contributor Author

Thanks! LGTM, I'll merge when it's time for the other backports

View changes since this review

Thanks! I hope the build failure for Solaris is just flaky and not specific to this PR?

@tgross35

Copy link
Copy Markdown
Member

Indeed, main has a workaround (92b0d84) but this branch only gets updated in batches.

@ivmarkov

Copy link
Copy Markdown
Contributor Author

Also I don't know if there's a way to test this target, but if so then it would be nice to add to #5209

I have something similar to ctest downstream here.

  1. (+) Does not need QEMU as it is a build-only check, comparing libc against bindgen-generated output from the ESP-IDF actual headers
  2. (-) Does not check struct types' interior, only sizeof and alignment of the whole thing, so the misaligned st_blksize and st_blocks would've not been detected I think
  3. (-) The list of types checked is manually curated
  4. (-) The main issue fixed in this PR is not even the misalignment of st_blksize and st_blocks, but rather - that we ended up with backwards-incompatible field renames inside the stat struct, which was only detected once libc got published and picked up in Rust STD downstream. And that broke the Rust STD build for ESP-IDF. So while I have a nightly CI which builds the Rust STD lib against the ESP-IDF targets, it currently only runs with whatever libc is specified in Rust STD. Ideally, I would have another variant, which builds with the libc 0.2 branch

I think before even looking at ctest, I might be able to address some of 2, 3 and 4.
4 is easy to address for sure.
Looking at 2 and 3...

Will update with a link to the CI shortly...

This branch has not been deployed

No deployments
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.

3 participants