Add rust.randomize-layout config to build artifacts with -Zrandomize-layout
Additionally teach compiletest to ignore tests that rely on deterministic layout. Tests themselves aren't built with randomization but they can still observe slight changes in std or rustc
This commit is contained in:
parent
9649706ead
commit
121e9f4cc8
@ -512,6 +512,9 @@
|
||||
# are disabled statically" because `max_level_info` is enabled, set this value to `true`.
|
||||
#debug-logging = rust.debug-assertions (boolean)
|
||||
|
||||
# Whether or not to build rustc, tools and the libraries with randomized type layout
|
||||
#randomize-layout = false
|
||||
|
||||
# Whether or not overflow checks are enabled for the compiler and standard
|
||||
# library.
|
||||
#
|
||||
|
@ -1810,6 +1810,9 @@ fn run(self, builder: &Builder<'_>) {
|
||||
if builder.config.rust_optimize_tests {
|
||||
cmd.arg("--optimize-tests");
|
||||
}
|
||||
if builder.config.rust_randomize_layout {
|
||||
cmd.arg("--rust-randomized-layout");
|
||||
}
|
||||
if builder.config.cmd.only_modified() {
|
||||
cmd.arg("--only-modified");
|
||||
}
|
||||
|
@ -1614,6 +1614,10 @@ fn cargo(
|
||||
rustflags.arg("-Csymbol-mangling-version=legacy");
|
||||
}
|
||||
|
||||
if self.config.rust_randomize_layout {
|
||||
rustflags.arg("-Zrandomize-layout");
|
||||
}
|
||||
|
||||
// Enable compile-time checking of `cfg` names, values and Cargo `features`.
|
||||
//
|
||||
// Note: `std`, `alloc` and `core` imports some dependencies by #[path] (like
|
||||
|
@ -280,6 +280,7 @@ pub struct Config {
|
||||
pub rust_codegen_backends: Vec<String>,
|
||||
pub rust_verify_llvm_ir: bool,
|
||||
pub rust_thin_lto_import_instr_limit: Option<u32>,
|
||||
pub rust_randomize_layout: bool,
|
||||
pub rust_remap_debuginfo: bool,
|
||||
pub rust_new_symbol_mangling: Option<bool>,
|
||||
pub rust_profile_use: Option<String>,
|
||||
@ -1088,6 +1089,7 @@ struct Rust {
|
||||
codegen_units: Option<u32> = "codegen-units",
|
||||
codegen_units_std: Option<u32> = "codegen-units-std",
|
||||
debug_assertions: Option<bool> = "debug-assertions",
|
||||
randomize_layout: Option<bool> = "randomize-layout",
|
||||
debug_assertions_std: Option<bool> = "debug-assertions-std",
|
||||
overflow_checks: Option<bool> = "overflow-checks",
|
||||
overflow_checks_std: Option<bool> = "overflow-checks-std",
|
||||
@ -1179,6 +1181,7 @@ pub fn default_opts() -> Config {
|
||||
backtrace: true,
|
||||
rust_optimize: RustOptimize::Bool(true),
|
||||
rust_optimize_tests: true,
|
||||
rust_randomize_layout: false,
|
||||
submodules: None,
|
||||
docs: true,
|
||||
docs_minification: true,
|
||||
@ -1629,6 +1632,7 @@ fn get_table(option: &str) -> Result<TomlConfig, toml::de::Error> {
|
||||
backtrace,
|
||||
incremental,
|
||||
parallel_compiler,
|
||||
randomize_layout,
|
||||
default_linker,
|
||||
channel,
|
||||
description,
|
||||
@ -1718,6 +1722,7 @@ fn get_table(option: &str) -> Result<TomlConfig, toml::de::Error> {
|
||||
set(&mut config.lld_mode, lld_mode);
|
||||
set(&mut config.llvm_bitcode_linker_enabled, llvm_bitcode_linker);
|
||||
|
||||
config.rust_randomize_layout = randomize_layout.unwrap_or_default();
|
||||
config.llvm_tools_enabled = llvm_tools.unwrap_or(true);
|
||||
config.rustc_parallel =
|
||||
parallel_compiler.unwrap_or(config.channel == "dev" || config.channel == "nightly");
|
||||
@ -2889,6 +2894,7 @@ macro_rules! warn {
|
||||
let Rust {
|
||||
// Following options are the CI rustc incompatible ones.
|
||||
optimize,
|
||||
randomize_layout,
|
||||
debug_logging,
|
||||
debuginfo_level_rustc,
|
||||
llvm_tools,
|
||||
@ -2953,6 +2959,7 @@ macro_rules! warn {
|
||||
// otherwise, we just print a warning with `warn` macro.
|
||||
|
||||
err!(current_rust_config.optimize, optimize);
|
||||
err!(current_rust_config.randomize_layout, randomize_layout);
|
||||
err!(current_rust_config.debug_logging, debug_logging);
|
||||
err!(current_rust_config.debuginfo_level_rustc, debuginfo_level_rustc);
|
||||
err!(current_rust_config.rpath, rpath);
|
||||
|
@ -136,6 +136,7 @@
|
||||
"min-llvm-version",
|
||||
"min-system-llvm-version",
|
||||
"needs-asm-support",
|
||||
"needs-deterministic-layouts",
|
||||
"needs-dlltool",
|
||||
"needs-dynamic-linking",
|
||||
"needs-force-clang-based-tests",
|
||||
|
@ -274,6 +274,9 @@ pub struct Config {
|
||||
/// Flags to pass to the compiler when building for the target
|
||||
pub target_rustcflags: Vec<String>,
|
||||
|
||||
/// Whether the compiler and stdlib has been built with randomized struct layouts
|
||||
pub rust_randomized_layout: bool,
|
||||
|
||||
/// Whether tests should be optimized by default. Individual test-suites and test files may
|
||||
/// override this setting.
|
||||
pub optimize_tests: bool,
|
||||
|
@ -134,6 +134,11 @@ pub(super) fn handle_needs(
|
||||
condition: config.target_cfg().relocation_model == "pic",
|
||||
ignore_reason: "ignored on targets without PIC relocation model",
|
||||
},
|
||||
Need {
|
||||
name: "needs-deterministic-layouts",
|
||||
condition: !config.rust_randomized_layout,
|
||||
ignore_reason: "ignored when randomizing layouts",
|
||||
},
|
||||
Need {
|
||||
name: "needs-wasmtime",
|
||||
condition: config.runner.as_ref().is_some_and(|r| r.contains("wasmtime")),
|
||||
|
@ -99,6 +99,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
|
||||
)
|
||||
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
|
||||
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
|
||||
.optflag(
|
||||
"",
|
||||
"rust-randomized-layout",
|
||||
"set this when rustc/stdlib were compiled with randomized layouts",
|
||||
)
|
||||
.optflag("", "optimize-tests", "run tests with optimizations enabled")
|
||||
.optflag("", "verbose", "run tests verbosely, showing all output")
|
||||
.optflag(
|
||||
@ -286,6 +291,7 @@ fn make_absolute(path: PathBuf) -> PathBuf {
|
||||
host_rustcflags: matches.opt_strs("host-rustcflags"),
|
||||
target_rustcflags: matches.opt_strs("target-rustcflags"),
|
||||
optimize_tests: matches.opt_present("optimize-tests"),
|
||||
rust_randomized_layout: matches.opt_present("rust-randomized-layout"),
|
||||
target,
|
||||
host: opt_str2(matches.opt_str("host")),
|
||||
cdb,
|
||||
|
Loading…
Reference in New Issue
Block a user