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.
This commit is contained in:
flip1995 2022-04-21 13:29:45 +01:00 committed by Philipp Krones
parent da895e7938
commit def3fd8e92
No known key found for this signature in database
GPG Key ID: 1CA0DF2AF59D68A5
3 changed files with 10 additions and 6 deletions

View File

@ -797,6 +797,7 @@ macro_rules! tracked {
tracked!(unleash_the_miri_inside_of_you, true); tracked!(unleash_the_miri_inside_of_you, true);
tracked!(use_ctors_section, Some(true)); tracked!(use_ctors_section, Some(true));
tracked!(verify_llvm_ir, true); tracked!(verify_llvm_ir, true);
tracked!(virtual_function_elimination, true);
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor)); tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
macro_rules! tracked_no_crate_hash { macro_rules! tracked_no_crate_hash {

View File

@ -1579,6 +1579,9 @@ pub(crate) fn parse_branch_protection(
"in general, enable more debug printouts (default: no)"), "in general, enable more debug printouts (default: no)"),
verify_llvm_ir: bool = (false, parse_bool, [TRACKED], verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
"verify LLVM IR (default: no)"), "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<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED], wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
"whether to build a wasi command or reactor"), "whether to build a wasi command or reactor"),

View File

@ -1431,14 +1431,14 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
); );
} }
// LLVM CFI requires LTO. // LLVM CFI and VFE both require LTO.
if sess.lto() != config::Lto::Fat {
if sess.is_sanitizer_cfi_enabled() { 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
{
sess.err("`-Zsanitizer=cfi` requires `-Clto`"); 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 { if sess.opts.debugging_opts.stack_protector != StackProtector::None {