-
Notifications
You must be signed in to change notification settings - Fork 725
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
Bad structure padding in FreeBSD's nvme.h #1563
Comments
Yes, this is a known-ish issue (see #1538). The With https://reviews.llvm.org/rC356062 we can eventually generate the right thing (since we could detect whether the alignment comes from the Does The obvious fix is making rust support both packed and aligned attributes, IMO, but if you want to give it a shot, grepping for |
Seems precisely the case. However, on properly designed structures it should not manifest. Were it 8-8-16 or 16-8-8 sequence, everything would have passed.
Yes, however - as you suspected - I had to disable alignment test. Ultimately, I removed As a side-note - I don't actually use Additionally, I'm not 100% sure, but when I generated binding last time (some 1-2 years ago), it did pass selftests - either due to older Rust compiler or older bindgen. The structure occurred as-is over 4 years ago, so it definitely was at current state. On the second thoughts - as I don't use it, I probably should |
Right, if we don't support
... this sounds probably wise :-) I'll close this as a dupe of #1538, thanks for the report! |
I reported this nuance also to FreeBSD folk as bug 237940. Report got a very positive reaction:
So it seems the problem was attacked from both sides and the world just go a bit better. Well, at least for programmers. OK, some programmers. Have a nice weekend. |
Input C/C++ Header
Used on
FreeBSD MaxBSD-2 12.0-RELEASE-p4 FreeBSD 12.0-RELEASE-p4 GENERIC amd64
File
mycam.h
:Structure causing trouble here is
nvme_health_information_page
from /usr/include/dev/nvme/nvme.h.Yes, I know a sequence of
uint8_t
-uint16_t
-uint8_t
is bad karma, but this is NVMe structure beyond negotiation :)Bindgen Invocation
Actual Results
and/or
Expected Results
Insight
Everything tests out properly, when you replace
#[repr(C, packed(4))]
with#[repr(C, packed)]
and correct alignment test accordingly. The true solution would be#[repr(C, packed, align(4))]
, but Rust explicitly forbids that:I think
__packed __aligned(4)
in C code definitely shouldn't be treated aspacked(4)
in Rust which has a totally different meaning.__packed
works elementwise and__aligned(4)
works structure-wise (that is the whole structure is 32-bit aligned, not individual elements). On the other hand, what is the sense in__aligned(4)
in packed structure of unaligned values?The text was updated successfully, but these errors were encountered: