Skip to content
Open
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
@@ -1,4 +1,5 @@
//@ ignore-cross-compile (need to run fake linker)
//@ ignore-backends: gcc

@antoyo antoyo Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there would be a way to make this test "generic" on whether the flag -fno-lto is present or not, but I guess it's not super important anyway.

View changes since the review


use run_make_support::{Rustc, diff, regex, rustc};

Expand Down
Loading