1
Fork 0

Introduce dedicated -Zdylib-lto flag for enabling LTO on dylibs

This commit is contained in:
Jakub Beránek 2022-09-29 16:31:03 +02:00
parent cba16819a1
commit c5c86806c8
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
11 changed files with 66 additions and 13 deletions

View file

@ -82,10 +82,24 @@ fn prepare_lto(
);
return Err(e);
} else if *crate_type == CrateType::Dylib {
diag_handler.warn("LTO with dylibs may not be as effective");
if !cgcx.opts.unstable_opts.dylib_lto {
return Err(diag_handler
.fatal("lto cannot be used for `dylib` crate type without `-Zdylib-lto`"));
}
}
}
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
diag_handler
.struct_err("cannot prefer dynamic linking when performing LTO")
.note(
"only 'staticlib', 'bin', and 'cdylib' outputs are \
supported with LTO",
)
.emit();
return Err(FatalError);
}
for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
let exported_symbols =
cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");