Added -Z layout_seed for allowing user-defined randomization seeds

This commit is contained in:
Chase Wilson
2021-12-14 12:48:41 -06:00
parent 404c8471ab
commit 2b46c7c906
2 changed files with 10 additions and 1 deletions

View File

@@ -1640,7 +1640,14 @@ impl ReprOptions {
// Generate a deterministically-derived seed from the item's path hash
// to allow for cross-crate compilation to actually work
let field_shuffle_seed = tcx.def_path_hash(did).0.to_smaller_hash();
let mut field_shuffle_seed = tcx.def_path_hash(did).0.to_smaller_hash();
// If the user defined a custom seed for layout randomization, xor the item's
// path hash with the user defined seed, this will allowing determinism while
// still allowing users to further randomize layout generation for e.g. fuzzing
if let Some(user_seed) = tcx.sess.opts.debugging_opts.layout_seed {
field_shuffle_seed ^= user_seed;
}
for attr in tcx.get_attrs(did).iter() {
for r in attr::find_repr_attrs(&tcx.sess, attr) {