-
Notifications
You must be signed in to change notification settings - Fork 701
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
Support 128-bit aligned unions #412
Comments
So the idea is that if all the inner fields can derive debug, the union should be able to debug too (since its alignment depends on the alignment of the fields). This could break, I guess, if you explicitly align the union to a given width, so it's a bug (though arguable a pretty corner-case-y one). |
Do you have the code that generated this? Is it this one? http://dpdk.org/doc/api-2.1/rte__ip_8h_source.html |
Well, this one, I guess: http://dpdk.org/doc/api-2.1/rte__thash_8h_source.html |
I can't replicate this with that code, and the code that adds the |
Ohh, ok, there it is. typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
struct rte_ipv4_tuple {
uint32_t src_addr;
uint32_t dst_addr;
union {
struct {
uint16_t dport;
uint16_t sport;
};
uint32_t sctp_tag;
};
};
struct rte_ipv6_tuple {
uint8_t src_addr[16];
uint8_t dst_addr[16];
union {
struct {
uint16_t dport;
uint16_t sport;
};
uint32_t sctp_tag;
};
};
union rte_thash_tuple {
struct rte_ipv4_tuple v4;
struct rte_ipv6_tuple v6;
} __attribute__((aligned(16))); So the problem boils down to us not being able to generate 128-bit aligned structs. This is kind of a rust limitation until |
In any case, we shouldn't generate invalid code. Our alignment checker assumes we can build an array of |
With the patch in #413 this won't generate invalid code. Still you need to make sure it's properly aligned before passing the struct to C. |
I meant that the generated code contains The alignment field is added later and not Debug-able, but it is not checked.
This is the generated code:
My opinion is that Debug trait should be removed from struct rte_thash_tuple |
If 128bit aligntmnets are possible, and the resulting alignment is longer than 32 entries, is there any checking mechanism that removes Debug from the struct? |
Yes, that checking exists. It's added before the field, but not without checking. Our checking just didn't account for unknown alignments (that's what #413 fixes) |
Thank you! This hotfix #413 works for me! |
This is partially fixed, the remaining work is figuring out what to do with stuff with >64bit alignment, which is #550. Thanks for the report! (for all the reports, actually :)) |
When
https://github.com/servo/rust-bindgen/blob/4ac39de18b96bd9488a17cf2650994a3584d440c/libbindgen/src/codegen/mod.rs#L1092
this inserts new field into a struct definition, Debug or Clone is not removed if the bindgen_union_field is too large.
This is the generated code. (without unstable rust)
#[repr(C)] #[derive(Debug, Copy)] pub struct rte_thash_tuple { pub v4: __BindgenUnionField<rte_ipv4_tuple>, pub v6: __BindgenUnionField<rte_ipv6_tuple>, pub bindgen_union_field: [u8; 48usize], } impl Clone for rte_thash_tuple { fn clone(&self) -> Self { *self } }
I think can_derive_debug should be checked later or
inserted attribute should be removed later.
The text was updated successfully, but these errors were encountered: