Skip to content

Commit 11432ba

Browse files
committed
Auto merge of #51230 - nikic:no-verify-lto, r=pnkfelix
Disable LLVM verification by default Currently -Z no-verify only controls IR verification prior to LLVM codegen, while verification is performed unconditionally both before and after linking with (Thin)LTO. Also wondering what the sentiment is on disabling verification by default (and e.g. only enabling it on ALT builds with assertions). This does not seem terribly useful outside of rustc development and it does seem to show up in profiles (at something like 3%). **EDIT:** A table showing the various configurations and what is enabled when. | Configuration | Dynamic verification performed | LLVM static assertions compiled in | | --- | --- | --- | | alt builds | | yes | | nightly builds | | no | | stable builds | | no | | CI builds | | | | dev builds in a checkout | | |
2 parents 989fa05 + 3f18a41 commit 11432ba

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@
360360
# Print backtrace on internal compiler errors during bootstrap
361361
#backtrace-on-ice = false
362362

363+
# Whether to verify generated LLVM IR
364+
#verify-llvm-ir = false
365+
363366
# =============================================================================
364367
# Options for specific targets
365368
#

src/bootstrap/bin/rustc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ fn main() {
283283
cmd.arg("--cfg").arg("parallel_queries");
284284
}
285285

286+
if env::var_os("RUSTC_VERIFY_LLVM_IR").is_some() {
287+
cmd.arg("-Z").arg("verify-llvm-ir");
288+
}
289+
286290
let color = match env::var("RUSTC_COLOR") {
287291
Ok(s) => usize::from_str(&s).expect("RUSTC_COLOR should be an integer"),
288292
Err(_) => 0,

src/bootstrap/builder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,10 @@ impl<'a> Builder<'a> {
922922
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
923923
}
924924

925+
if self.config.rust_verify_llvm_ir {
926+
cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
927+
}
928+
925929
cargo.env("RUSTC_VERBOSE", format!("{}", self.verbosity));
926930

927931
// in std, we want to avoid denying warnings for stage 0 as that makes cfg's painful.

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub struct Config {
105105
pub rust_dist_src: bool,
106106
pub rust_codegen_backends: Vec<Interned<String>>,
107107
pub rust_codegen_backends_dir: String,
108+
pub rust_verify_llvm_ir: bool,
108109

109110
pub build: Interned<String>,
110111
pub hosts: Vec<Interned<String>>,
@@ -312,6 +313,7 @@ struct Rust {
312313
llvm_tools: Option<bool>,
313314
deny_warnings: Option<bool>,
314315
backtrace_on_ice: Option<bool>,
316+
verify_llvm_ir: Option<bool>,
315317
}
316318

317319
/// TOML representation of how each build target is configured.
@@ -543,6 +545,7 @@ impl Config {
543545
config.save_toolstates = rust.save_toolstates.clone().map(PathBuf::from);
544546
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
545547
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
548+
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
546549

547550
if let Some(ref backends) = rust.codegen_backends {
548551
config.rust_codegen_backends = backends.iter()

src/librustc/session/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11511151
"gather codegen statistics"),
11521152
asm_comments: bool = (false, parse_bool, [TRACKED],
11531153
"generate comments into the assembly (may change behavior)"),
1154-
no_verify: bool = (false, parse_bool, [TRACKED],
1155-
"skip LLVM verification"),
1154+
verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
1155+
"verify LLVM IR"),
11561156
borrowck_stats: bool = (false, parse_bool, [UNTRACKED],
11571157
"gather borrowck statistics"),
11581158
no_landing_pads: bool = (false, parse_bool, [TRACKED],
@@ -3114,7 +3114,7 @@ mod tests {
31143114
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
31153115

31163116
opts = reference.clone();
3117-
opts.debugging_opts.no_verify = true;
3117+
opts.debugging_opts.verify_llvm_ir = true;
31183118
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
31193119

31203120
opts = reference.clone();

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ impl Session {
516516
pub fn asm_comments(&self) -> bool {
517517
self.opts.debugging_opts.asm_comments
518518
}
519-
pub fn no_verify(&self) -> bool {
520-
self.opts.debugging_opts.no_verify
519+
pub fn verify_llvm_ir(&self) -> bool {
520+
self.opts.debugging_opts.verify_llvm_ir
521521
}
522522
pub fn borrowck_stats(&self) -> bool {
523523
self.opts.debugging_opts.borrowck_stats

src/librustc_codegen_llvm/back/lto.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,12 @@ fn run_pass_manager(cgcx: &CodegenContext,
461461
unsafe {
462462
let pm = llvm::LLVMCreatePassManager();
463463
llvm::LLVMRustAddAnalysisPasses(tm, pm, llmod);
464-
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
465-
assert!(!pass.is_null());
466-
llvm::LLVMRustAddPass(pm, pass);
464+
465+
if config.verify_llvm_ir {
466+
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
467+
assert!(!pass.is_null());
468+
llvm::LLVMRustAddPass(pm, pass);
469+
}
467470

468471
// When optimizing for LTO we don't actually pass in `-O0`, but we force
469472
// it to always happen at least with `-O1`.
@@ -494,9 +497,11 @@ fn run_pass_manager(cgcx: &CodegenContext,
494497
}
495498
});
496499

497-
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
498-
assert!(!pass.is_null());
499-
llvm::LLVMRustAddPass(pm, pass);
500+
if config.verify_llvm_ir {
501+
let pass = llvm::LLVMRustFindAndCreatePass("verify\0".as_ptr() as *const _);
502+
assert!(!pass.is_null());
503+
llvm::LLVMRustAddPass(pm, pass);
504+
}
500505

501506
time_ext(cgcx.time_passes, None, "LTO passes", ||
502507
llvm::LLVMRunPassManager(pm, llmod));

src/librustc_codegen_llvm/back/write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub struct ModuleConfig {
232232
emit_obj: bool,
233233
// Miscellaneous flags. These are mostly copied from command-line
234234
// options.
235-
no_verify: bool,
235+
pub verify_llvm_ir: bool,
236236
no_prepopulate_passes: bool,
237237
no_builtins: bool,
238238
time_passes: bool,
@@ -271,7 +271,7 @@ impl ModuleConfig {
271271
embed_bitcode_marker: false,
272272
no_integrated_as: false,
273273

274-
no_verify: false,
274+
verify_llvm_ir: false,
275275
no_prepopulate_passes: false,
276276
no_builtins: false,
277277
time_passes: false,
@@ -283,7 +283,7 @@ impl ModuleConfig {
283283
}
284284

285285
fn set_flags(&mut self, sess: &Session, no_builtins: bool) {
286-
self.no_verify = sess.no_verify();
286+
self.verify_llvm_ir = sess.verify_llvm_ir();
287287
self.no_prepopulate_passes = sess.opts.cg.no_prepopulate_passes;
288288
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
289289
self.time_passes = sess.time_passes();
@@ -542,7 +542,7 @@ unsafe fn optimize(cgcx: &CodegenContext,
542542
true
543543
};
544544

545-
if !config.no_verify { assert!(addpass("verify")); }
545+
if config.verify_llvm_ir { assert!(addpass("verify")); }
546546
if !config.no_prepopulate_passes {
547547
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
548548
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);

0 commit comments

Comments
 (0)