document -Zrandomize-layout in the unstable book · rust-lang/rust@ebb9a38 (original) (raw)
File tree
1 file changed
lines changed
- src/doc/unstable-book/src/compiler-flags
1 file changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
1 | +# `randomize-layout` | |
2 | + | |
3 | +The tracking issue for this feature is: [#106764](https://github.com/rust-lang/rust/issues/106764). | |
4 | + | |
5 | +------------------------ | |
6 | + | |
7 | +The `-Zrandomize-layout` flag changes the layout algorithm for `repr(Rust)` types defined in the current crate from its normal | |
8 | +optimization goals to pseudorandomly rearranging fields within the degrees of freedom provided by the largely unspecified | |
9 | +default representation. This also affects type sizes and padding. | |
10 | +Downstream intantiations of generic types defined in a crate with randomization enabled will also be randomized. | |
11 | + | |
12 | +It can be used to find unsafe code that accidentally relies on unspecified behavior. | |
13 | + | |
14 | +Randomization is not guaranteed to use a different permutation for each compilation session. | |
15 | +`-Zlayout-seed=` can be used to supply additional entropy. | |
16 | + | |
17 | +Randomization only approximates the intended freedom of repr(Rust). Sometimes two distinct types may still consistently | |
18 | +result in the same layout due to limitations of the current implementation. Randomization may become | |
19 | +more aggressive over time as our coverage of the available degrees of freedoms improves. | |
20 | +Corollary: Randomization is not a safety oracle. Two struct layouts being observably the same under different layout seeds | |
21 | +on the current compiler version does not guarantee that future compiler versions won't give them distinct layouts. | |
22 | + | |
23 | +Randomization may also become less aggressive in the future if additional guarantees get added to the default layout. |