Skip to content

Commit

Permalink
Disable ICF opt of MSVC for non-opt build
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Dec 4, 2016
1 parent c80c31a commit 257f643
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make/codegen-options-parsing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 257f643

Please sign in to comment.