about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2022-09-29 16:31:03 +0200
committerJakub Beránek <berykubik@gmail.com>2022-10-23 13:48:03 +0200
commitc5c86806c859048f9bfdbb92b30401ef4f3a3346 (patch)
tree80bd0586eb361e26c5f7f826ecc4f39f3eec9ef7 /compiler/rustc_codegen_llvm/src
parentcba16819a1aa2f99c861eba907847db39fea06c5 (diff)
downloadrust-c5c86806c859048f9bfdbb92b30401ef4f3a3346.tar.gz
rust-c5c86806c859048f9bfdbb92b30401ef4f3a3346.zip
Introduce dedicated `-Zdylib-lto` flag for enabling LTO on `dylib`s
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/back/lto.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs
index fb58d5f7df2..a49cc7f8d66 100644
--- a/compiler/rustc_codegen_llvm/src/back/lto.rs
+++ b/compiler/rustc_codegen_llvm/src/back/lto.rs
@@ -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");