Skip to content

Commit dabb75b

Browse files
committed
rustc_trans: Pass /LTCG to the MSVC linker
This flag, the link-time code generation flag, informs the linker that it can call the compiler to perform whole program optimization. We don't actually take advantage of this for Rust code itself (as we have LLVM as our backend), but native libraries typically compile for whole program optimization and then require this flag to be passed to the linker so they can be successfully linked together. This shouldn't slow the linker down for Rust code itself, just help perform LTCG on native code being linked in which requires it.
1 parent cb7d914 commit dabb75b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/librustc_trans/back/linker.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,16 @@ impl<'a> Linker for MsvcLinker<'a> {
233233
self.link_staticlib(lib);
234234
}
235235
fn optimize(&mut self) {
236-
// Needs more investigation of `/OPT` arguments
236+
// This flag, the link-time code generation flag, informs the linker
237+
// that it can call the compiler to perform whole program optimization.
238+
// We don't actually take advantage of this for Rust code itself (as we
239+
// have LLVM as our backend), but native libraries typically compile for
240+
// whole program optimization and then require this flag to be passed to
241+
// the linker so they can be successfully linked together.
242+
//
243+
// This shouldn't slow the linker down for Rust code itself, just help
244+
// perform LTCG on native code being linked in which requires it.
245+
self.cmd.arg("/LTCG");
237246
}
238247
fn whole_archives(&mut self) {
239248
// hints not supported?

0 commit comments

Comments
 (0)