Skip to content
Merged
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
13 changes: 8 additions & 5 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ impl<'this> RustcCodegenFlags<'this> {
// https://doc.rust-lang.org/rustc/codegen-options/index.html#control-flow-guard
"-Ccontrol-flow-guard" => self.control_flow_guard = value.or(Some("true")),
// https://doc.rust-lang.org/rustc/codegen-options/index.html#lto
//
// This variable is currently unused, we just keep it in case we need it in future
"-Clto" => self.lto = value.or(Some("true")),
// https://doc.rust-lang.org/rustc/linker-plugin-lto.html
"-Clinker-plugin-lto" => self.linker_plugin_lto = Some(true),
Expand Down Expand Up @@ -322,11 +324,12 @@ impl<'this> RustcCodegenFlags<'this> {
// https://doc.rust-lang.org/rustc/linker-plugin-lto.html
if self.linker_plugin_lto.unwrap_or(false) {
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-flto
let cc_val = match self.lto {
Some("thin") => "thin",
_ => "full",
};
push_if_supported(format!("-flto={cc_val}").into());
// In order to use linker-plugin-lto to achieve cross-lang lto, cc has to use thin LTO
// to compile the c/c++ libraries because llvm linker plugin/lld uses thin LTO by default.
// And for thin LTO in linker plugin to work, the archive also has to be compiled using thin LTO,
// since thin LTO generates extra information that fat LTO does not generate that
// is required for thin LTO process.
Copy link
Contributor

Choose a reason for hiding this comment

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

Six "thin LTO" in two sentences. Well, not that I care that much, but it does sting the eye. It also feels that it would look worse in isolation, i.e. not in the diff context. I mean

- push_if_supported(format!("-flto={cc_val}").into());
+ // It has to be thin LTO because llvm linker plugin/lld uses thin LTO by default.

looks like meaningful "rebuttal," while

// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-flto
// It has to be thin LTO because llvm linker plugin/lld uses thin LTO by default.

feels like "wow, where does it come from?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks updated

Copy link
Contributor

Choose a reason for hiding this comment

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

Five "thin LTO"-s, only one down... But what does second sentence add now? It's basically the first sentence... Again, not that I care that much :-) Just do you :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm if it can be understood by another maintainer with no context before hand, then I think it's good

Choose a reason for hiding this comment

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

FWIW, I think this might become problematic with rustc_codegen_gcc, as GCC has -flto but not -flto=thin (the way GCC does LTO is different). I believe rustc_codegen_gcc already has some support for cross-language LTO so it's not just theoretical. cc @antoyo

Copy link
Contributor Author

@NobodyXu NobodyXu Oct 21, 2025

Choose a reason for hiding this comment

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

-flto is only enabled for clang, it's currently always disabled for gcc

push_if_supported("-flto=thin".into());
}
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mguard
if let Some(value) = self.control_flow_guard {
Expand Down
Loading