ty: Use underlying layout of typedefs if available. - #3453
Conversation
|
cc @ojeda |
This fixes struct layout issues with over-aligned typedefs, which rust can't represent, see #3449 for context and some other discussion. This is kinda ugly tho, but as far as I can tell there's no good way of getting the right ABI and struct layout at the same time...
5e6308c to
447f5f4
Compare
|
A few more cases for your tests/future considerations: struct Inner { long long a, b; };
typedef struct Inner AlignedInner __attribute__((aligned(16)));
struct Outer {
long long before;
AlignedInner inner[1];
};(and the same with struct Inner { long long a, b; };
typedef struct Inner AlignedInner __attribute__((aligned(16)));
struct Outer {
long long before;
AlignedInner inner[0];
char tail;
};enum __attribute__((aligned(16))) AlignedEnum { Value = 1 };
struct Outer {
long long before;
enum AlignedEnum inner;
};typedef unsigned int U __attribute__((aligned(2)));
struct Outer {
char before;
U bits : 31;
char mid;
U inner;
char tail;
};All these changed w.r.t. 0.72.1. I hope that helps & thanks! |
|
@ojeda just to check, is any of those actively blocking the kernel? Those hit issues that are all pre-existing afaict: Support for aligned enums (which can't on the default enum representation, because we just typedef to the underlying type, ugh), and same for arrays. These are all fixable, but rather hackily (this was already a bit of a hack). Not impossible tho. |
|
It's a bit sad that even on the rustified enum style, |
This fixes most of the test-cases discussed in #3453.
This fixes most of the test-cases discussed in #3453. The remaining one is related to bitfields and needs a bit more thought (I think we currently don't pad bitfields based on the clang-reported offset and maybe should).
This fixes most of the test-cases discussed in #3453. The remaining one is related to bitfields and needs a bit more thought (I think we currently don't pad bitfields based on the clang-reported offset and maybe should).
Not that I have seen reported yet, but it is hard to say -- that is why I was trying to look at it from the perspective of differences w.r.t. 0.72.1, since that is where we have confidence, especially for cases that were matching C in the past (the cases I pasted above, except the last one, matched Clang in 0.72.1 as far as I can see, so they could have broken someone). |
This fixes the bitfield cases discussed in #3453.
|
Ok, I came up with a fix for the bitfield stuff that isn't super complicated, so I'll land a fix for that too before doing a dot release. |
This fixes most of the test-cases discussed in rust-lang#3453. The remaining one is related to bitfields and needs a bit more thought (I think we currently don't pad bitfields based on the clang-reported offset and maybe should).
This fixes the bitfield cases discussed in rust-lang#3453.
This fixes struct layout issues with over-aligned typedefs, which rust can't represent, see #3449 for context and some other discussion.
This is kinda ugly tho, but as far as I can tell there's no good way of getting the right ABI and struct layout at the same time...