-
Notifications
You must be signed in to change notification settings - Fork 13.3k
make the core::raw struct representation defined #18316
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
Conversation
I don't see why this is necessary. These structures are guaranteed to match whatever the compiler decides to represent their related built-in types as. It's the compiler's responsibility to make sure that it does the right thing with the resulting layout of these types. What does that have to do with a C-ABI equivalent layout? |
@sfackler: The layout is entirely implementation defined. The compiler can use a different representation for |
The standard library is incorrect whenever it relies on the compiler to order the fields in a certain way. It defines these built-in types as having a specific order / layout which is what |
I am aware of implementation defined layout. It's true in general that libraries can't depend on the result of undefined layout. However, these types exist to specify the otherwise unspecified layout of builtin types. They already directly rely on implementation details of the compiler, and will continue to do so even if they're tagged with |
@cgaebel: That's not why I'm marking them this way. |
Then why are you? As long as the layouts match what the compiler generates, it shouldn't be a problem to re-order. |
@sfackler: They need to be marked with |
@sfackler: The fact that it's implementation defined does not mean that it will represent |
@cgaebel: It will not match what the compiler generates when struct randomization is used. It has a chance of matching the representation. Any code using these has undefined behaviour and is blocking the implementation of the features laid out in the RFC. |
If randomized struct layout is implemented, is there any reason we wouldn't want to randomize layout of |
@sfackler: It's think we would eventually want to randomize the layout of built-in types. However, I think the layout of those types is considered well-defined right now. There's a lot of low-level Rust code in the wild depending on the order and I think it would require an RFC amendment extending it to certain built-in types rather than just |
(this is just intended to be make it well-defined today and unblock implementing randomization) |
Cool, SGTM. |
Closes #18313