Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM IR coverage encoding aligns closer to Clang's #75416

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

richkadel
Copy link
Contributor

@richkadel richkadel commented Aug 11, 2020

I found some areas for improvement while attempting to debug the
SegFault issue when running rust programs compiled using MSVC, with
coverage instrumentation.

I discovered that LLVM's coverage writer was generating incomplete
function name variable names (that's not a typo: the name of the
variable that holds a function name).

The existing implementation used one-up numbers to distinguish
variables, and correcting the names did not fix the MSVC coverage bug,
but the fix in this PR makes the names and resulting LLVM IR easier to
follow and more consistent with Clang's implementation.

I also changed the way the -Zinstrument-coverage option is supported in
symbol_export.rs. The original implementation was incorrect, and the
corrected version matches the handling for -Zprofile-generate, as it
turns out.

(An argument could be made that maybe -Zinstrument-coverage should
automatically enable -Cprofile-generate. In fact, if
-Cprofile-generate is analagous to Clang's -fprofile-generate, as
some documentation implies, Clang always requires this flag for its
implementation of source-based code coverage. This would require a
little more validation, and if implemented, would probably require
updating some of the user-facing messages related to
-Cprofile-generate to not be so specific to the PGO use case.)

None of these changes fixed the MSVC coverage problems, but they should
still be welcome improvements.

Lastly, I added some additional FIXME comments in instrument_coverage.rs
describing issues I found with the generated LLVM IR that would be
resolved if the coverage instrumentation is injected with a Statement
instead of as a new BasicBlock. I describe seven advantages of this
change, but it requires some discussion before making a change like
this.

r? @tmandry

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 11, 2020
@richkadel richkadel force-pushed the llvm-coverage-map-gen-5.3 branch from 8d80dd3 to cbb073c Compare August 12, 2020 07:15
@richkadel
Copy link
Contributor Author

@tmandry @wesleywiser - Since this PR modifies LLVM IR without changing the final result (coverage counts), I just added a new test for LLVM IR expected patterns, using LLVM's "FileCheck" tool (and following a similar approach used to test Rust PGO).

See: src/test/run-make-fulldeps/instrument-coverage/filecheck-patterns.txt

@richkadel

This comment has been minimized.

@richkadel
Copy link
Contributor Author

I'm pasting the FIXME comment mentioned above into a PR comment here.

Actually, after discussing with Tyler offline, I'm moving this discussion about using a Statement instead of BasicBlock to Zulip.

@richkadel richkadel force-pushed the llvm-coverage-map-gen-5.3 branch from cbb073c to 799ef9c Compare August 12, 2020 18:42
@richkadel
Copy link
Contributor Author

I removed the FIXME comment, now replaced by the live Zulip thread discussing imlementing a new StatementKind.

@richkadel richkadel force-pushed the llvm-coverage-map-gen-5.3 branch from 799ef9c to a670540 Compare August 13, 2020 01:28
// @alloc4 = private unnamed_addr constant <{ [43 x i8] }> \
// <{ [43 x i8] c"C:\\msys64\\home\\richkadel\\rust\\rust_basic.rs" }>, align 1
//
// Can I flag the alloc as something not to be added to codegen? Or somehow remove it before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I'm not aware of any facility currently to do this but this might be something we should look into since MIR optimizations could also cause some allocations to no longer be needed.

@tmandry
Copy link
Member

tmandry commented Aug 14, 2020

@bors r+ rollup=never (due to the LLVM IR tests)

@bors
Copy link
Contributor

bors commented Aug 14, 2020

📌 Commit a670540017a7e61532684ef333a60c0722229190 has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2020
@bors
Copy link
Contributor

bors commented Aug 14, 2020

⌛ Testing commit a670540017a7e61532684ef333a60c0722229190 with merge b3afc68b9ff9e258b98c98a3915160f280f0e0eb...

@tmandry
Copy link
Member

tmandry commented Aug 14, 2020

@bors retry yielding to rollup

@tmandry
Copy link
Member

tmandry commented Aug 14, 2020

I actually think we should do a try run before running a CI cycle on this. Not sure if all these commands will work in one go, but let's see:

@bors r-
@bors try
@bors delegate=richkadel

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 14, 2020
@bors
Copy link
Contributor

bors commented Aug 14, 2020

✌️ @richkadel can now approve this pull request

@bors
Copy link
Contributor

bors commented Aug 14, 2020

⌛ Trying commit a670540017a7e61532684ef333a60c0722229190 with merge 0c5491bd41285af2f061dc1f496b4920fdd119c2...

@bors
Copy link
Contributor

bors commented Aug 14, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 0c5491bd41285af2f061dc1f496b4920fdd119c2 (0c5491bd41285af2f061dc1f496b4920fdd119c2)

@tmandry
Copy link
Member

tmandry commented Aug 14, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Aug 14, 2020

📌 Commit a670540017a7e61532684ef333a60c0722229190 has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2020
@bors
Copy link
Contributor

bors commented Aug 14, 2020

⌛ Testing commit a670540017a7e61532684ef333a60c0722229190 with merge 9da5d2aa6077b7b41f068a537e1968c1c3f9e946...

@tmandry
Copy link
Member

tmandry commented Aug 14, 2020

@bors retry yielding

@rust-log-analyzer
Copy link
Collaborator

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[group]Run exit 1
exit 1
shell: /bin/bash --noprofile --norc -e -o pipefail {0}
##[endgroup]
##[error]Process completed with exit code 1.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @rust-lang/infra. (Feature Requests)

@richkadel
Copy link
Contributor Author

@bors retry yielding

@bors
Copy link
Contributor

bors commented Aug 14, 2020

⌛ Testing commit a670540017a7e61532684ef333a60c0722229190 with merge 8a6c2ef7f1239c35370200c23e2d435a5bf2b54d...

@bors
Copy link
Contributor

bors commented Aug 14, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 14, 2020
@richkadel
Copy link
Contributor Author

I forgot MacOS section names are a little different. I'll compile on my Mac and fix this.

@richkadel richkadel force-pushed the llvm-coverage-map-gen-5.3 branch from a670540 to 49e5445 Compare August 14, 2020 09:13
I found some areas for improvement while attempting to debug the
SegFault issue when running rust programs compiled using MSVC, with
coverage instrumentation.

I discovered that LLVM's coverage writer was generating incomplete
function name variable names (that's not a typo: the name of the
variable that holds a function name).

The existing implementation used one-up numbers to distinguish
variables, and correcting the names did not fix the MSVC coverage bug,
but the fix in this PR makes the names and resulting LLVM IR easier to
follow and more consistent with Clang's implementation.

I also changed the way the `-Zinstrument-coverage` option is supported
in symbol_export.rs. The original implementation was incorrect, and the
corrected version matches the handling for `-Zprofile-generate`, as it
turns out.

(An argument could be made that maybe `-Zinstrument-coverage` should
automatically enable `-Cprofile-generate`. In fact, if
`-Cprofile-generate` is analagous to Clang's `-fprofile-generate`, as
some documentation implies, Clang always requires this flag for its
implementation of source-based code coverage. This would require a
little more validation, and if implemented, would probably require
updating some of the user-facing messages related to
`-Cprofile-generate` to not be so specific to the PGO use case.)

None of these changes fixed the MSVC coverage problems, but they should
still be welcome improvements.

Lastly, I added some additional FIXME comments in instrument_coverage.rs
describing issues I found with the generated LLVM IR that would be
resolved if the coverage instrumentation is injected with a `Statement`
instead of as a new `BasicBlock`. I describe seven advantages of this
change, but it requires some discussion before making a change like
this.
@richkadel richkadel force-pushed the llvm-coverage-map-gen-5.3 branch from 49e5445 to ba18978 Compare August 14, 2020 09:24
@richkadel
Copy link
Contributor Author

@bors retry yielding

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2020
@richkadel
Copy link
Contributor Author

@bors r+ rollup=never (due to the LLVM IR tests)

@bors
Copy link
Contributor

bors commented Aug 14, 2020

📌 Commit ba18978 has been approved by richkadel

@bors
Copy link
Contributor

bors commented Aug 14, 2020

⌛ Testing commit ba18978 with merge 8e21bd0...

@bors
Copy link
Contributor

bors commented Aug 14, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: richkadel
Pushing 8e21bd0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 14, 2020
@bors bors merged commit 8e21bd0 into rust-lang:master Aug 14, 2020
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants