diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 3747fb5eca0..30a29ed6ed3 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -797,6 +797,7 @@ macro_rules! tracked { tracked!(unleash_the_miri_inside_of_you, true); tracked!(use_ctors_section, Some(true)); tracked!(verify_llvm_ir, true); + tracked!(virtual_function_elimination, true); tracked!(wasi_exec_model, Some(WasiExecModel::Reactor)); macro_rules! tracked_no_crate_hash { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 007fa87189f..0f60ffda2ee 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1579,6 +1579,9 @@ pub(crate) fn parse_branch_protection( "in general, enable more debug printouts (default: no)"), verify_llvm_ir: bool = (false, parse_bool, [TRACKED], "verify LLVM IR (default: no)"), + virtual_function_elimination: bool = (false, parse_bool, [TRACKED], + "enables dead virtual function elimination optimization. \ + Requires `-Clto[=[fat,yes]]`"), wasi_exec_model: Option = (None, parse_wasi_exec_model, [TRACKED], "whether to build a wasi command or reactor"), diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index b2c23cda6aa..18aa717f676 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1431,14 +1431,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) { ); } - // LLVM CFI requires LTO. - if sess.is_sanitizer_cfi_enabled() { - if sess.opts.cg.lto == config::LtoCli::Unspecified - || sess.opts.cg.lto == config::LtoCli::No - || sess.opts.cg.lto == config::LtoCli::Thin - { + // LLVM CFI and VFE both require LTO. + if sess.lto() != config::Lto::Fat { + if sess.is_sanitizer_cfi_enabled() { sess.err("`-Zsanitizer=cfi` requires `-Clto`"); } + if sess.opts.debugging_opts.virtual_function_elimination { + sess.err("`-Zvirtual-function-elimination` requires `-Clto`"); + } } if sess.opts.debugging_opts.stack_protector != StackProtector::None {