Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 767a5aa

Browse files
authoredDec 3, 2024
Rollup merge of rust-lang#133777 - the8472:document-randomize-layout, r=jieyouxu
document -Zrandomize-layout in the unstable book tracking issue: rust-lang#106764 fixes rust-lang#130462
2 parents e1f1031 + ebb9a38 commit 767a5aa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 
Original file line numberDiff line numberDiff 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=<u64>` 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.

0 commit comments

Comments
 (0)
Please sign in to comment.