Skip to content

Commit 257f643

Browse files
committed
Disable ICF opt of MSVC for non-opt build
1 parent c80c31a commit 257f643

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
@@ -320,7 +320,16 @@ impl<'a> Linker for MsvcLinker<'a> {
320320
}
321321

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

326335
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)