netbsd: Fix statvfs struct layout and add symbol versioning for NetBSD 10.x#5243
netbsd: Fix statvfs struct layout and add symbol versioning for NetBSD 10.x#5243fraggerfox wants to merge 3 commits into
Conversation
|
LGTM @fraggerfox can you please add the stable-nominated flag to this PR so it gets added to the stable version of |
| // This type is updated in a future version | ||
| f_spare: [u32; 4], | ||
| __pad1: Padding<u32>, | ||
| pub f_spare: [u64; 4], |
There was a problem hiding this comment.
No need to make this public. Where does __pad1 come from?
There was a problem hiding this comment.
I have removed the pub from f_spare.
Without the padding between f_owner and f_spare caused the Rust struct to be misaligned by 4 bytes, here is the output of the sample program that I used for testing (generated by AI)
=== STRUCT LAYOUT COMPARISON ===
WITH padding (correct):
Total size: 3296 bytes
f_owner offset: 152
f_spare offset: 160
Gap after owner: 4 bytes
WITHOUT padding (packed, wrong):
Total size: 3292 bytes
f_owner offset: 152
f_spare offset: 156
Gap after owner: 0 bytes
=== CALLING statvfs() WITH BOTH STRUCTS ===
CORRECT struct (with padding):
f_fstypename: 'ffs'
f_mntonname: '/'
f_mntfromname: '/dev/ld0a'
f_spare[0]: 0x0000000000000000
PACKED struct (without padding - WRONG):
f_fstypename: ''
f_mntonname: ''
f_mntfromname: ''
f_spare[0]: 0x0000000000000000
The size of the struct when taken from a native C program matches 3296 bytes.
There was a problem hiding this comment.
Hmm, I will need to debug further to see why the CI is failing without the pub. will do that once I get a bit more free time.
Seems like a transient failure, @tgross35 can you help retrigger the CI?
+ /usr/sbin/pkg_add curl
pkg_add: Can't process [http://cdn.NetBSD.org:80/pub/pkgsrc/packages/NetBSD/x86_64/10.1/All//curl*:](http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/x86_64/10.1/All//curl*:)
pkg_add: no pkg found for 'curl', sorry.
pkg_add: 1 package addition failed
There was a problem hiding this comment.
Without the padding between
f_ownerandf_sparecaused the Rust struct to be misaligned by 4 bytes, here is the output of the sample program that I used for testing (generated by AI)
That doesn't really track - why would they be mismatched? There are no alignment attributes on either, so did another field change sizes or something?
Seems like a transient failure, @tgross35 can you help retrigger the CI?
* https://github.com/rust-lang/libc/actions/runs/28645611965/job/84951914997?pr=5243#step:5:243+ /usr/sbin/pkg_add curl pkg_add: Can't process [http://cdn.NetBSD.org:80/pub/pkgsrc/packages/NetBSD/x86_64/10.1/All//curl*:](http://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/x86_64/10.1/All//curl*:) pkg_add: no pkg found for 'curl', sorry. pkg_add: 1 package addition failed
We hit this error all the time, I don't know why. @0323pin do you happen to have any ideas here?
There was a problem hiding this comment.
Without the padding between
f_ownerandf_sparecaused the Rust struct to be misaligned by 4 bytes, here is the output of the sample program that I used for testing (generated by AI)That doesn't really track - why would they be mismatched? There are no alignment attributes on either, so did another field change sizes or something?
Nothing changed, this is definitely an alignment issue of the types in struct. My best guess is gcc is probably padding it in someway when generating the struct, hence the size mismatch between C and Rust. I am not too familiar with how gcc pads the struct (neither in Rust), but I can investigate and get back.
There was a problem hiding this comment.
GCC doesn't insert padding out of nowhere, it uses the same layout calculations as rust with #[repr(C)]. If you just run libc-test without the padding it may give a hint.
There was a problem hiding this comment.
@tgross35 : Alright, let me run these tests in a NetBSD environment and get back to you.
There was a problem hiding this comment.
@tgross35 : I have removed the explict padding. It seems I had a bug in implementation for bottom that was reading the values wrongly (since I was using bottom as a test harness to check if libc changes were working).
I wrote an independent test directly calling statvfs struct and it seems to work, my mistake was the small test program I was working with was explicitly recreating the structs and checking if field was it was correct and there was a mistake in that approach.
TL;DR, I have removed the explicit padding, the CI also looks green, thank you @tgross35 for pushing me to check it correctly.
There was a problem hiding this comment.
Note that we aren't actually testing this type so CI should be green regardless :)
Lines 1427 to 1428 in e98332b
If you're interested, I think you could move that from skip_struct to skip_struct_field and only exclude the fields that differ among versions so we test the rest. But do that in a separate PR preferably.
|
Reminder, once the PR becomes ready for a review, use |
|
I'm actually not sure we should do this; per https://doc.rust-lang.org/rustc/platform-support/netbsd.html we support down to 8.x in some cases. |
At any given moment in time, NetBSD only supports the current latest + latest-1. 8 is officially not supported anymore. Besides, Rust doesn't even build on 8. 9 will follow the same path as soon as 11 is released. But, do you @0-wiz-0 feel differently about it? |
This was handwritten, I put in stuff there for context, but I can always cut down on the content. I put in the link to the The reason I put in a verbose description is because I spent quite a lot of time tracking down the historical changes done for NetBSD previously for making this PR (tracking down the exact commit was not easy either) The aim of the description was so that people in the future can find such a change done more easily. |
a7cbba5 to
81e85cd
Compare
The policy seems reasonable to me, would be good to update the platform docs to clarify N-1 is supported. In that case though, we should hold off here right? If it was just the field changes I wouldn't be concerned, but the link name changes will cause link failures for anybody building on NetBSD 9. It's also possible to do something like FreeBSD and add an unstable config to toggle things. We really need rust-lang/rfcs#3905... |
|
In case that's just how network errors show up, I'm going to try a retry with #5246. |
4d93348 to
3a033fb
Compare
|
Some changes occurred in a NetBSD-like module cc @semarie |
|
This looks technically correct at this point, but it sounds like 9.x is still supported so I think we should hold off, given AIUI there isn't any rush. So for this to be ready I think we need:
Seems like 11.0 is in RC so let's revisit in a couple months? Unless @0323pin you feel strongly that there's a reason to ship this now. @rustbot blocked |
|
(https://snoozeth.is/wmRMPHBukiA) I will wait until Sun, 04 Oct 2026 10:20:42 UTC and then add label S-waiting-on-review and remove label S-blocked. @rustbot claim. |
Good to know and thank you!
I am fine with maintaining this patch for now in the |
|
What exactly is the issue in |
The |
|
I'm still not sure I follow - |
|
It's fine by me, especially since it looks like 9.0 is pretty old, but would prefer https://github.com/rust-lang/rust/blob/main/src/doc/rustc/src/platform-support/netbsd.md gets updated first. Usually that's where we point people if they have questions about what we try to support if there's ever any version confusion. |
The problem is not
My understanding from @0-wiz-0 's explanation when were discussing this is, the I am not sure if the explanation is sufficient and answers your question. Note: I do not have much experience dealing with linkers, so most of my understanding is based on reading the code, so there may be mistakes |
Changes: 1. Fixed statvfs struct in new API (src/new/netbsd/sys/statvfs.rs): - Changed f_spare from [u32; 4] to [u64; 4] (16 → 32 bytes) - Added Padding<u32> after f_owner for correct alignment - Added f_mntfromlabel field ([c_char; 1024]) 2. Added symbol versioning for syscalls (src/unix/bsd/netbsdlike/netbsd/mod.rs): - Added __getmntinfo90 link_name for getmntinfo() 3. Added symbol versioning for syscalls (src/unix/mod.rs): - Added __statvfs190 link_name for statvfs() - Added __fstatvfs190 link_name for fstatvfs()
3a033fb to
09a7d3b
Compare
|
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. |
Ah! That makes a lot more sense, thanks. How is anything using Could you just link |
I am not sure how many consumers of that call are there in pkgsrc, and more importantly who all are using those packages 😅
This was the change done by @0-wiz-0, which got removed in this
And then when discussing with @0323pin and @0-wiz-0 we came to the conclusion of sticking to the I could raise another one line change PR to restore the old linking to restore functionality to any existing consumers of this API in pkgsrc, until this PR is ready to merge. What do you think? |
That's my fault, I guess I misunderstood something about the comment at the time. Sorry about that, but I'd be happy to accept a change back You can do that in a separate PR if you'd like and keep this one around to change to |
Here you go #5251 |



Description
Fixes the
statvfsstructure layout and adds symbol versioning for NetBSD10.x(and above) compatibility.NetBSD 10.0 changed the
statvfsstructure:f_sparechanged from[u32; 4]to[u64; 4]f_mntfromlabelfield (1024 bytes)Without explicit
link_nameattributes, Rust bindings resolve to compatibility wrappers (__compat_statvfs) that expect the old struct layout, causing data corruption even with the correct struct definition.statvfs()→__statvfs190fstatvfs()→__fstatvfs190getmntinfo()→__getmntinfo90Previous changes
1816f6061
This PR removed the deprecated symbol, which was previously added by @0-wiz-0 and tries to maintain compatibility from NetBSD
9.xand above.The current PR, bumps compatibility for NetBSD
10.xand above.Discovery
The problem with
getmntinfo()was discovered when debugging why bottom was not populating theDiskspanel correctly in NetBSD.Sources
NetBSD
statvfsstructure definition:NetBSD symbol versioning documentation:
Checklist
libc-test/semverhave been updatedstatvfs/fstatvfsalready inunix.txt,getmntinfoalready innetbsd.txt*LASTor*MAXare includedcd libc-test && cargo test --target mytarget)CC=cc cargo test --target x86_64-unknown-netbsd --workspace@rustbot label +stable-nominated
cc: @0323pin