diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-02-13 04:36:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-13 04:36:59 +0100 |
| commit | 1c1d2e44c53b578b99d1ec34a1a6e69c5386fe4d (patch) | |
| tree | da6973fc442f652f2e9d6fd534ec396b27f4cd0a /src/librustc_codegen_llvm/back | |
| parent | 0ab1057a56097e73f26a1c27b4fc05b551b5737a (diff) | |
| parent | 3a9d171b0a118d8f0ecda1bf44775ec4ba9bb79d (diff) | |
| download | rust-1c1d2e44c53b578b99d1ec34a1a6e69c5386fe4d.tar.gz rust-1c1d2e44c53b578b99d1ec34a1a6e69c5386fe4d.zip | |
Rollup merge of #58057 - michaelwoerister:stabilize-xlto, r=alexcrichton
Stabilize linker-plugin based LTO (aka cross-language LTO) This PR stabilizes [linker plugin based LTO](https://github.com/rust-lang/rust/issues/49879), also known as "cross-language LTO" because it allows for doing inlining and other optimizations across language boundaries in mixed Rust/C/C++ projects. As described in the tracking issue, it works by making `rustc` emit LLVM bitcode instead of machine code, the same as `clang` does. A linker with the proper plugin (like LLD) can then run (Thin)LTO across all modules. The feature has been implemented over a number of pull requests and there are various [codegen](https://github.com/rust-lang/rust/blob/master/src/test/codegen/no-dllimport-w-cross-lang-lto.rs) and [run](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/cross-lang-lto-clang)-[make](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/cross-lang-lto-upstream-rlibs) [tests](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/cross-lang-lto) that make sure that it keeps working. It also works for building big projects like [Firefox](https://treeherder.mozilla.org/#/jobs?repo=try&revision=2ce2d5ddcea6fbff790503eac406954e469b2f5d). The PR makes the feature available under the `-C linker-plugin-lto` flag. As discussed in the tracking issue it is not cross-language specific and also not LLD specific. `-C linker-plugin-lto` is descriptive of what it does. If someone has a better name, let me know `:)`
Diffstat (limited to 'src/librustc_codegen_llvm/back')
| -rw-r--r-- | src/librustc_codegen_llvm/back/link.rs | 4 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/back/lto.rs | 2 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/back/write.rs | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/src/librustc_codegen_llvm/back/link.rs b/src/librustc_codegen_llvm/back/link.rs index 725009e1377..548c94abc07 100644 --- a/src/librustc_codegen_llvm/back/link.rs +++ b/src/librustc_codegen_llvm/back/link.rs @@ -857,7 +857,7 @@ fn link_args(cmd: &mut dyn Linker, codegen_results: &CodegenResults) { // Linker plugins should be specified early in the list of arguments - cmd.cross_lang_lto(); + cmd.linker_plugin_lto(); // The default library location, we need this to find the runtime. // The location of crates will be determined as needed. @@ -1491,7 +1491,7 @@ fn are_upstream_rust_objects_already_included(sess: &Session) -> bool { Lto::Thin => { // If we defer LTO to the linker, we haven't run LTO ourselves, so // any upstream object files have not been copied yet. - !sess.opts.debugging_opts.cross_lang_lto.enabled() + !sess.opts.cg.linker_plugin_lto.enabled() } Lto::No | Lto::ThinLocal => false, diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index be7733bf554..ac55244d8d9 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -159,7 +159,7 @@ pub(crate) fn run_thin(cgcx: &CodegenContext<LlvmCodegenBackend>, let symbol_white_list = symbol_white_list.iter() .map(|c| c.as_ptr()) .collect::<Vec<_>>(); - if cgcx.opts.debugging_opts.cross_lang_lto.enabled() { + if cgcx.opts.cg.linker_plugin_lto.enabled() { unreachable!("We should never reach this case if the LTO step \ is deferred to the linker"); } diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index 47637f3c5d7..e7871531972 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -366,7 +366,7 @@ pub(crate) unsafe fn optimize(cgcx: &CodegenContext<LlvmCodegenBackend>, let opt_level = config.opt_level.map(|x| to_llvm_opt_settings(x).0) .unwrap_or(llvm::CodeGenOptLevel::None); let prepare_for_thin_lto = cgcx.lto == Lto::Thin || cgcx.lto == Lto::ThinLocal || - (cgcx.lto != Lto::Fat && cgcx.opts.debugging_opts.cross_lang_lto.enabled()); + (cgcx.lto != Lto::Fat && cgcx.opts.cg.linker_plugin_lto.enabled()); with_llvm_pmb(llmod, &config, opt_level, prepare_for_thin_lto, &mut |b| { llvm::LLVMPassManagerBuilderPopulateFunctionPassManager(b, fpm); llvm::LLVMPassManagerBuilderPopulateModulePassManager(b, mpm); |
