Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd -C link-dead-code option (to improve kcov code coverage) #31368
Conversation
rust-highfive
assigned
jroesch
Feb 2, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jroesch (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
|
See also https://internals.rust-lang.org/t/disabling-gc-sections-when-test-is-specified/2163 for some discussion of doing this. |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the link @sfackler! I'm glad there's some documentation on this topic. Based on the thread, this might not be the best solution for everybody. Then, I guess I can close this PR, until a there's a consensus. |
alexcrichton
assigned
alexcrichton
and unassigned
jroesch
Feb 2, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR @JohanLorenzo! I'm always happy to see movement on this :). I think that the best option that came out of @sfackler's link is that for now it's probably best to not have I think that we can end up passing this down to Cargo via either the profile idea that @huonw mentioned or perhaps the |
This comment has been minimized.
This comment has been minimized.
|
Oh and it looks like a flag like that has even been requested before! |
This comment has been minimized.
This comment has been minimized.
|
Thanks for the feedback @alexcrichton. Here's a new revision that implements -C no-gc-sections asked in #17141. |
pnkfelix
reviewed
Feb 3, 2016
| // reduction. | ||
| } else if !is_dylib { | ||
| self.cmd.arg("-Wl,--gc-sections"); | ||
| if !self.sess.opts.cg.no_gc_sections { |
This comment has been minimized.
This comment has been minimized.
pnkfelix
Feb 3, 2016
Member
This diff would be very short if you just did
if !self.sess.opts.cg.no_gc_sections {
return;
}
This comment has been minimized.
This comment has been minimized.
pnkfelix
Feb 3, 2016
Member
(but also, I am the kind of person that would put the conditional check around the call-site to linker.gc_sections(..); this change is making this function act more like fn maybe_gc_sections(..))
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@JohanLorenzo If you're interested in trying to make a test of this functionality, I bet you might be able to do it with a |
JohanLorenzo
reviewed
Feb 3, 2016
|
|
||
| # Should contain gc-sections... | ||
| $(RUSTC) -Z print-link-args dummy.rs 2>&1 | \ | ||
| grep '"-Wl,--gc-sections"' |
This comment has been minimized.
This comment has been minimized.
JohanLorenzo
Feb 3, 2016
Author
Contributor
I discussed with @pnkfelix about testing also on IRC. A better approach would be to use
objdump --disassemble $(TMPDIR)/dummy | grep 'unused_function'I tried to implement this check, but it turns out $(TMPDIR)/dummy is not accessible when run in the Makefile. When I ran the same command locally, it works like a charm. I'm under the impression there's a race condition within the Makefile.
I git grep'd to find if a similar case existed in the code base, but I didn't manage to find any. Then, here's another proposal, closer to what already exist in the current Makefile.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Feb 3, 2016
Member
This check will probably need to be guarded based on platform as well. I do agree that objdump would probably be the best way to go here, but it's probably only reliably available on Linux (and maybe some BSDs). By default it's not on OSX and I doubt it's available on Windows much.
Same with checking for --gc-sections as well, unfortunately that's only the name of the argument on Linux. On OSX it's -Wl,-dead_strip and on MSVC it's something different as well.
alexcrichton
reviewed
Feb 3, 2016
| @@ -501,6 +501,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)"), | |||
| no_gc_sections: bool = (false, parse_bool, | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Feb 3, 2016
Member
I'd personally prefer to call this just gc_sections with a default of true, it helps avoid double negatives later on. That way to turn it off you specify -C gc-sections=no or whatever we interpret as "falsey" values
This comment has been minimized.
This comment has been minimized.
JohanLorenzo
reviewed
Feb 3, 2016
|
|
||
| # Should contain gc-sections... | ||
| $(RUSTC) -Z print-link-args dummy.rs 2>&1 | \ | ||
| grep -e '--gc-sections\|-dead_strip' |
This comment has been minimized.
This comment has been minimized.
JohanLorenzo
Feb 3, 2016
Author
Contributor
I didn't grep on any other value because only 2 are defined in gc_sections()
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thanks! Can you squash these commits down into one as well? |
JohanLorenzo
changed the title
Prevent stripping if we're producing test builds
Add -C gc-sections=no option (to improve kcov code coverage)
Feb 4, 2016
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Thank you for the help and the review. Here's the squashed commit. I have a couple of questions remaining: How would it be possible to pass this flag to cargo? I looked up and saw |
This comment has been minimized.
This comment has been minimized.
|
Currently there's not a fantastic way to pass this sort of option down through Cargo to the compiler, but something like Ideally I'd like a |
alexcrichton
added
the
T-tools
label
Feb 4, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @rust-lang/tools |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
lgtm |
This comment has been minimized.
This comment has been minimized.
|
I idly wonder if this argument might be better phrased as |
This comment has been minimized.
This comment has been minimized.
|
@huonw I was thinking something similar as well, yeah. I think that anything relating to stripping dead code, however, may also be a bit of a misnomer for a few reasons:
Not that the points are really much in favor of |
This comment has been minimized.
This comment has been minimized.
|
Ok, the tools team talked about this during triage today and the conclusion was that this is a good option to have, but we likely want to not call it I'm personally kinda leaning towards "link-dead-code" as it matches what happens on OSX and MSVC (the linker just literally strips dead code) and the interpretation on Linux basically just ends up being the same thing. @JohanLorenzo what do you think? |
This comment has been minimized.
This comment has been minimized.
|
|
JohanLorenzo
changed the title
Add -C gc-sections=no option (to improve kcov code coverage)
Add -C link-dead-code=yes option (to improve kcov code coverage)
Feb 11, 2016
JohanLorenzo
changed the title
Add -C link-dead-code=yes option (to improve kcov code coverage)
Add -C link-dead-code option (to improve kcov code coverage)
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks @JohanLorenzo! |
bors
added a commit
that referenced
this pull request
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Thu, Feb 11, 2016 at 2:18 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Thu, Feb 11, 2016 at 8:14 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
@bors: force |
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Thu, Feb 11, 2016 at 11:04 PM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
merged commit 274f27a
into
rust-lang:master
Feb 12, 2016
This comment has been minimized.
This comment has been minimized.
|
Yay |
tamird
reviewed
Feb 12, 2016
| @@ -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)"), | |||
This comment has been minimized.
This comment has been minimized.
tamird
Feb 12, 2016
Contributor
this description is not right, seems it should be "let the linker link dead code" or simply "link dead code"
JohanLorenzo commentedFeb 2, 2016
Tools which rely on DWARF for generating code coverage report, don't generate accurate numbers on test builds. For instance, this sample main returns 100% coverage when 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!