Skip to content

Commit def3fd8

Browse files
committed
Add -Zvirtual-function-elimination flag
Adds the virtual-function-elimination unstable compiler flag and a check that this flag is only used in combination with -Clto. LLVM can only apply this optimization with fat LTO.
1 parent da895e7 commit def3fd8

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ fn test_debugging_options_tracking_hash() {
797797
tracked!(unleash_the_miri_inside_of_you, true);
798798
tracked!(use_ctors_section, Some(true));
799799
tracked!(verify_llvm_ir, true);
800+
tracked!(virtual_function_elimination, true);
800801
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
801802

802803
macro_rules! tracked_no_crate_hash {

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,9 @@ options! {
15791579
"in general, enable more debug printouts (default: no)"),
15801580
verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
15811581
"verify LLVM IR (default: no)"),
1582+
virtual_function_elimination: bool = (false, parse_bool, [TRACKED],
1583+
"enables dead virtual function elimination optimization. \
1584+
Requires `-Clto[=[fat,yes]]`"),
15821585
wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
15831586
"whether to build a wasi command or reactor"),
15841587

compiler/rustc_session/src/session.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1431,14 +1431,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
14311431
);
14321432
}
14331433

1434-
// LLVM CFI requires LTO.
1435-
if sess.is_sanitizer_cfi_enabled() {
1436-
if sess.opts.cg.lto == config::LtoCli::Unspecified
1437-
|| sess.opts.cg.lto == config::LtoCli::No
1438-
|| sess.opts.cg.lto == config::LtoCli::Thin
1439-
{
1434+
// LLVM CFI and VFE both require LTO.
1435+
if sess.lto() != config::Lto::Fat {
1436+
if sess.is_sanitizer_cfi_enabled() {
14401437
sess.err("`-Zsanitizer=cfi` requires `-Clto`");
14411438
}
1439+
if sess.opts.debugging_opts.virtual_function_elimination {
1440+
sess.err("`-Zvirtual-function-elimination` requires `-Clto`");
1441+
}
14421442
}
14431443

14441444
if sess.opts.debugging_opts.stack_protector != StackProtector::None {

0 commit comments

Comments
 (0)