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 `:)`
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user