Auto merge of #31368 - JohanLorenzo:dont-strip-if-test-build, r=alexcrichton

Tools which rely on DWARF for generating code coverage report, don't generate accurate numbers on test builds. For instance, [this sample main](757bdbf388/src/main.rs) returns [100% coverage](https://coveralls.io/builds/4940156/source?filename=main.rs) when [kcov](https://github.com/SimonKagstrom/kcov/) runs.

With @pnkfelix 's great help, we could narrow down the issue: The linker strips unused function during phase 6. Here's a patch which stops stripping when someone calls `rustc --test $ARGS`. @pnkfelix wasn't sure if we should add a new flag, or just use --test. What do you think @alexcrichton ?

Also, I'm not too sure: where is the best place to add a test for this addition?

Thanks for the help!
This commit is contained in:
bors 2016-02-12 05:53:18 +00:00
commit 77f9231818
3 changed files with 12 additions and 1 deletions

View File

@ -507,6 +507,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
"system linker to link outputs with"),
link_args: Option<Vec<String>> = (None, parse_opt_list,
"extra arguments to pass to the linker (space separated)"),
link_dead_code: bool = (false, parse_bool,
"let the linker strip dead coded (turning it on can be used for code coverage)"),
lto: bool = (false, parse_bool,
"perform LLVM link-time optimizations"),
target_cpu: Option<String> = (None, parse_opt_string,

View File

@ -976,7 +976,9 @@ fn link_args(cmd: &mut Linker,
// Try to strip as much out of the generated object by removing unused
// sections if possible. See more comments in linker.rs
cmd.gc_sections(dylib);
if !sess.opts.cg.link_dead_code {
cmd.gc_sections(dylib);
}
let used_link_args = sess.cstore.used_link_args();

View File

@ -22,3 +22,10 @@ all:
$(RUSTC) -C lto=foo dummy.rs 2>&1 | \
grep 'codegen option `lto` takes no value'
$(RUSTC) -C lto dummy.rs
# Should not link dead code...
$(RUSTC) -Z print-link-args dummy.rs 2>&1 | \
grep -e '--gc-sections\|-dead_strip\|/OPT:REF,ICF'
# ... unless you specifically ask to keep it
$(RUSTC) -Z print-link-args -C link-dead-code dummy.rs 2>&1 | \
(! grep -e '--gc-sections\|-dead_strip\|/OPT:REF,ICF')