From 257f643ee327252a4cd6dba25f64ac3768adcb45 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 25 Nov 2016 19:17:21 +1100 Subject: [PATCH] Disable ICF opt of MSVC for non-opt build --- src/librustc_trans/back/linker.rs | 11 ++++++++++- src/test/run-make/codegen-options-parsing/Makefile | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/librustc_trans/back/linker.rs b/src/librustc_trans/back/linker.rs index 860903d259fe5..0080dfb7ecac6 100644 --- a/src/librustc_trans/back/linker.rs +++ b/src/librustc_trans/back/linker.rs @@ -320,7 +320,16 @@ impl<'a> Linker for MsvcLinker<'a> { } fn gc_sections(&mut self, _keep_metadata: bool) { - self.cmd.arg("/OPT:REF,ICF"); + // MSVC's ICF (Identical COMDAT Folding) link optimization is + // slow for Rust and thus we disable it by default when not in + // optimization build. + if self.sess.opts.optimize != config::OptLevel::No { + self.cmd.arg("/OPT:REF,ICF"); + } else { + // It is necessary to specify NOICF here, because /OPT:REF + // implies ICF by default. + self.cmd.arg("/OPT:REF,NOICF"); + } } fn link_dylib(&mut self, lib: &str) { diff --git a/src/test/run-make/codegen-options-parsing/Makefile b/src/test/run-make/codegen-options-parsing/Makefile index 9543fad8e533b..2b8b0712cc7de 100644 --- a/src/test/run-make/codegen-options-parsing/Makefile +++ b/src/test/run-make/codegen-options-parsing/Makefile @@ -25,7 +25,7 @@ all: # Should not link dead code... $(RUSTC) -Z print-link-args dummy.rs 2>&1 | \ - grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF,ICF' + grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF' # ... unless you specifically ask to keep it $(RUSTC) -Z print-link-args -C link-dead-code dummy.rs 2>&1 | \ - (! grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF,ICF') + (! grep -e '--gc-sections' -e '-dead_strip' -e '/OPT:REF')