Skip to content

Commit 7d05966

Browse files
committed
disable size asserts in the compiler when randomizing layouts
1 parent 7b7aadc commit 7d05966

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,6 +3816,7 @@ dependencies = [
38163816
"rustc_feature",
38173817
"rustc_hir",
38183818
"rustc_hir_pretty",
3819+
"rustc_index",
38193820
"rustc_interface",
38203821
"rustc_lint",
38213822
"rustc_log",

compiler/rustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ jemalloc = ['jemalloc-sys']
2323
llvm = ['rustc_driver/llvm']
2424
max_level_info = ['rustc_driver/max_level_info']
2525
rustc_use_parallel_compiler = ['rustc_driver/rustc_use_parallel_compiler']
26+
rustc_randomized_layouts = ['rustc_driver/rustc_randomized_layouts']

compiler/rustc_driver/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ rustc_interface = { path = "../rustc_interface" }
3030
rustc_ast = { path = "../rustc_ast" }
3131
rustc_span = { path = "../rustc_span" }
3232
rustc_typeck = { path = "../rustc_typeck" }
33+
rustc_index = { path = "../rustc_index" }
3334

3435
[target.'cfg(unix)'.dependencies]
3536
libc = "0.2"
@@ -42,3 +43,4 @@ llvm = ['rustc_interface/llvm']
4243
max_level_info = ['rustc_log/max_level_info']
4344
rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler',
4445
'rustc_middle/rustc_use_parallel_compiler']
46+
rustc_randomized_layouts = ['rustc_index/rustc_randomized_layouts']

compiler/rustc_index/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ arrayvec = { version = "0.7", default-features = false }
1111
rustc_serialize = { path = "../rustc_serialize" }
1212
rustc_macros = { path = "../rustc_macros" }
1313
smallvec = "1.8.1"
14+
15+
[features]
16+
rustc_randomized_layouts = []

compiler/rustc_index/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,19 @@ pub use rustc_macros::newtype_index;
1818

1919
/// Type size assertion. The first argument is a type and the second argument is its expected size.
2020
#[macro_export]
21+
#[cfg(not(feature = "rustc_randomized_layouts"))]
2122
macro_rules! static_assert_size {
2223
($ty:ty, $size:expr) => {
2324
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
2425
};
2526
}
27+
28+
#[macro_export]
29+
#[cfg(feature = "rustc_randomized_layouts")]
30+
macro_rules! static_assert_size {
31+
($ty:ty, $size:expr) => {
32+
// no effect other than using the statements.
33+
// struct sizes are not deterministic under randomized layouts
34+
const _: (usize, usize) = ($size, ::std::mem::size_of::<$ty>());
35+
};
36+
}

src/bootstrap/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ impl Build {
753753
if self.config.rustc_parallel {
754754
features.push("rustc_use_parallel_compiler");
755755
}
756+
if self.config.rust_randomize_layout {
757+
features.push("rustc_randomized_layouts");
758+
}
756759

757760
// If debug logging is on, then we want the default for tracing:
758761
// https://github.com/tokio-rs/tracing/blob/3dd5c03d907afdf2c39444a29931833335171554/tracing/src/level_filters.rs#L26

0 commit comments

Comments
 (0)