about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorColin Pronovost <colin.pron@live.com>2018-05-30 16:46:56 -0400
committerColin Pronovost <colin.pron@live.com>2018-08-01 00:27:25 -0400
commit3da7c65e92e212143bafdb4adf9cfb8054209a93 (patch)
tree890f86cba2043b42fe79797a2721f7338fba509a /src/librustc_codegen_llvm
parent02190f397ecb32bca42e5b631dc235381d01b377 (diff)
downloadrust-3da7c65e92e212143bafdb4adf9cfb8054209a93.tar.gz
rust-3da7c65e92e212143bafdb4adf9cfb8054209a93.zip
Make sure we prepare for thin LTO whenever we are emitting bitcode
Emitting LLVM bitcode uses ThinLTOBuffers, so we need to prepare for
thin LTO or we will likely cause errors in LLVM.
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/back/write.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs
index db044878fe7..5cb7215a198 100644
--- a/src/librustc_codegen_llvm/back/write.rs
+++ b/src/librustc_codegen_llvm/back/write.rs
@@ -541,11 +541,23 @@ unsafe fn optimize(cgcx: &CodegenContext,
             };
 
             if config.verify_llvm_ir { assert!(addpass("verify")); }
+
+            // Some options cause LLVM bitcode to be emitted, which uses ThinLTOBuffers, so we need
+            // to make sure we run LLVM's NameAnonGlobals pass when emitting bitcode; otherwise
+            // we'll get errors in LLVM.
+            let using_thin_buffers = llvm::LLVMRustThinLTOAvailable() && (config.emit_bc
+                || config.obj_is_bitcode || config.emit_bc_compressed || config.embed_bitcode);
+            let mut have_name_anon_globals_pass = false;
             if !config.no_prepopulate_passes {
                 llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
                 llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);
                 let opt_level = config.opt_level.unwrap_or(llvm::CodeGenOptLevel::None);
                 let prepare_for_thin_lto = cgcx.lto == Lto::Thin || cgcx.lto == Lto::ThinLocal;
+                have_name_anon_globals_pass = have_name_anon_globals_pass || prepare_for_thin_lto;
+                if using_thin_buffers && !prepare_for_thin_lto {
+                    assert!(addpass("name-anon-globals"));
+                    have_name_anon_globals_pass = true;
+                }
                 with_llvm_pmb(llmod, &config, opt_level, prepare_for_thin_lto, &mut |b| {
                     llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(b, fpm);
                     llvm::LLVMPassManagerBuilderPopulateModulePassManager(b, mpm);
@@ -557,6 +569,9 @@ unsafe fn optimize(cgcx: &CodegenContext,
                     diag_handler.warn(&format!("unknown pass `{}`, ignoring",
                                             pass));
                 }
+                if pass == "name-anon-globals" {
+                    have_name_anon_globals_pass = true;
+                }
             }
 
             for pass in &cgcx.plugin_passes {
@@ -565,6 +580,22 @@ unsafe fn optimize(cgcx: &CodegenContext,
                                             `{}` but LLVM does not \
                                             recognize it", pass));
                 }
+                if pass == "name-anon-globals" {
+                    have_name_anon_globals_pass = true;
+                }
+            }
+
+            if using_thin_buffers && !have_name_anon_globals_pass {
+                // As described above, this will probably cause an error in LLVM
+                if config.no_prepopulate_passes {
+                    diag_handler.err("The current compilation is going to use thin LTO buffers \
+                                     without running LLVM's NameAnonGlobals pass. \
+                                     This will likely cause errors in LLVM. Consider adding \
+                                     -C passes=name-anon-globals to the compiler command line.");
+                } else {
+                    bug!("We are using thin LTO buffers without running the NameAnonGlobals pass. \
+                         This will likely cause errors in LLVM and shoud never happen.");
+                }
             }
         }