Skip to content

Commit 1842efb

Browse files
committed
Auto merge of #37994 - upsuper:msvc-link-opt, r=alexcrichton
Don't apply msvc link opts for non-opt build `/OPT:REF,ICF` sometimes takes lots of time. It makes no sense to apply them when doing debug build. MSVC's linker by default disables these optimizations when `/DEBUG` is specified, unless they are explicitly passed.
2 parents 1692c0b + 257f643 commit 1842efb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/librustc_trans/back/linker.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,16 @@ impl<'a> Linker for MsvcLinker<'a> {
321321
}
322322

323323
fn gc_sections(&mut self, _keep_metadata: bool) {
324-
self.cmd.arg("/OPT:REF,ICF");
324+
// MSVC's ICF (Identical COMDAT Folding) link optimization is
325+
// slow for Rust and thus we disable it by default when not in
326+
// optimization build.
327+
if self.sess.opts.optimize != config::OptLevel::No {
328+
self.cmd.arg("/OPT:REF,ICF");
329+
} else {
330+
// It is necessary to specify NOICF here, because /OPT:REF
331+
// implies ICF by default.
332+
self.cmd.arg("/OPT:REF,NOICF");
333+
}
325334
}
326335

327336
fn link_dylib(&mut self, lib: &str) {

src/test/run-make/codegen-options-parsing/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ all:
2525

2626
# Should not link dead code...
2727
$(RUSTC) -Z print-link-args dummy.rs 2>&1 | \
28-
grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF,ICF'
28+
grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF'
2929
# ... unless you specifically ask to keep it
3030
$(RUSTC) -Z print-link-args -C link-dead-code dummy.rs 2>&1 | \
31-
(! grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF,ICF')
31+
(! grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF')

0 commit comments

Comments
 (0)