Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,14 @@ impl<'a> Linker for GccLinker<'a> {
fn linker_plugin_lto(&mut self) {
match self.sess.opts.cg.linker_plugin_lto {
LinkerPluginLto::Disabled => {
// Nothing to do
// GCC, when used as a linker, will perform LTO even without -flto when it sees
// object files with the GCC IR (which can happen when using rustc_codegen_gcc).
// Since the std is compiled with -Cembed-bitcode=yes, any program using the std
// will have the linker do LTO.
// So, we disable this with -fno-lto when linker plugin LTO is not requested.
if self.is_cc() && self.codegen_backend == "gcc" {
self.cc_arg("-fno-lto");
}
}
LinkerPluginLto::LinkerPluginAuto => {
self.push_linker_plugin_lto_args(None);
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/fno-lto/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
17 changes: 17 additions & 0 deletions tests/run-make/fno-lto/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ needs-target-std
//@ ignore-msvc
//@ ignore-wasm
//@ needs-backends: gcc

use run_make_support::rustc;

fn main() {
rustc().input("main.rs").print("link-args").run_unchecked().assert_stdout_contains("-fno-lto");

rustc()
.input("main.rs")
.arg("-Clinker-plugin-lto")
.print("link-args")
.run_unchecked()
.assert_stdout_not_contains("-fno-lto");
}
1 change: 1 addition & 0 deletions tests/run-make/linker-warning/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fn main() {
.normalize("libpanic_abort", "libpanic_unwind")
.normalize(r#""[^"]*\/symbols.o""#, "\"/symbols.o\"")
.normalize(r#""[^"]*\/raw-dylibs""#, "\"/raw-dylibs\"")
.normalize("\"-fno-lto\" ", "")
.run();
}

Expand Down
Loading