Skip to content

coverage: Consolidate creation of covmap/covfun records - #132124

Merged
bors merged 4 commits into
rust-lang:masterfrom
Zalathar:consolidate-covstar
Oct 26, 2024
Merged

coverage: Consolidate creation of covmap/covfun records#132124
bors merged 4 commits into
rust-lang:masterfrom
Zalathar:consolidate-covstar

Conversation

@Zalathar

Copy link
Copy Markdown
Member

This code for creating covmap/covfun records during codegen was split across multiple functions and files for dubious historical reasons. Having it all in one place makes it easier to follow.

This PR also includes two semi-related cleanups:

  • Getting the codegen context's coverage_cx state is made infallible, since it should always exist when running the code paths that need it.
  • The value of covfun_section_name is saved in the codegen context, since it never changes at runtime, and the code that needs it has access to the context anyway.

Background: Coverage instrumentation generates two kinds of metadata that are embedded in the final binary. There is per-CGU information that goes in the __llvm_covmap linker section, and per-function information that goes in the __llvm_covfun section (except on Windows, where slightly different section names are used).

There is no need for this code to be split across multiple functions in
multiple files.
In all the situations where this context is needed, it should always be
available.
Adding an extra `OnceCell` to `CrateCoverageContext` is much nicer than trying
to thread this string through multiple layers of function calls that already
have access to the context.
@ZalatharZalathar added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Oct 25, 2024
@Zalathar

Copy link
Copy Markdown
MemberAuthor

I was originally planning to do #131962 (comment), but doing this first will make that a little cleaner.

@Zalathar

Copy link
Copy Markdown
MemberAuthor

Rustbot is sleepy.

r? compiler

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 25, 2024
@ZalatharZalathar added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2024

@jieyouxujieyouxu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this LGTM, minor docs nit. Feel free to r=me with or without addressing those.

Comment threadcompiler/rustc_codegen_llvm/src/context.rs
Comment threadcompiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Comment threadcompiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
@jieyouxujieyouxu assigned jieyouxu and unassigned pnkfelixOct 26, 2024
@jieyouxu

Copy link
Copy Markdown
Member

Thanks, you can r=me after PR CI is green.

@Zalathar

Copy link
Copy Markdown
MemberAuthor

🟩
@bors r=jieyouxu

@bors

bors commented Oct 26, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 0d653a5 has been approved by jieyouxu

It is now in the queue for this repository.

@borsbors 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 Oct 26, 2024
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 26, 2024
…eyouxu
coverage: Consolidate creation of covmap/covfun records
This code for creating covmap/covfun records during codegen was split across multiple functions and files for dubious historical reasons. Having it all in one place makes it easier to follow.
This PR also includes two semi-related cleanups:
- Getting the codegen context's `coverage_cx` state is made infallible, since it should always exist when running the code paths that need it.
- The value of `covfun_section_name` is saved in the codegen context, since it never changes at runtime, and the code that needs it has access to the context anyway.
---
Background: Coverage instrumentation generates two kinds of metadata that are embedded in the final binary. There is per-CGU information that goes in the `__llvm_covmap` linker section, and per-function information that goes in the `__llvm_covfun` section (except on Windows, where slightly different section names are used).
@ZalatharZalathar mentioned this pull request Oct 26, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 26, 2024
…eyouxu
coverage: Consolidate creation of covmap/covfun records
This code for creating covmap/covfun records during codegen was split across multiple functions and files for dubious historical reasons. Having it all in one place makes it easier to follow.
This PR also includes two semi-related cleanups:
- Getting the codegen context's `coverage_cx` state is made infallible, since it should always exist when running the code paths that need it.
- The value of `covfun_section_name` is saved in the codegen context, since it never changes at runtime, and the code that needs it has access to the context anyway.
---
Background: Coverage instrumentation generates two kinds of metadata that are embedded in the final binary. There is per-CGU information that goes in the `__llvm_covmap` linker section, and per-function information that goes in the `__llvm_covfun` section (except on Windows, where slightly different section names are used).
@jieyouxujieyouxu mentioned this pull request Oct 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 26, 2024
Rollup of 4 pull requests
Successful merges:
- rust-lang#132124 (coverage: Consolidate creation of covmap/covfun records)
- rust-lang#132167 (Replace some LLVMRust wrappers with calls to the LLVM C API)
- rust-lang#132169 (Deny calls to non-`#[const_trait]` methods in MIR constck)
- rust-lang#132174 (x86 target features: make pclmulqdq imply sse2)
r? `@ghost`
`@rustbot` modify labels: rollup
@jieyouxujieyouxu mentioned this pull request Oct 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 26, 2024
Rollup of 5 pull requests
Successful merges:
- rust-lang#132124 (coverage: Consolidate creation of covmap/covfun records)
- rust-lang#132140 (Enable LSX feature for LoongArch Linux targets)
- rust-lang#132169 (Deny calls to non-`#[const_trait]` methods in MIR constck)
- rust-lang#132174 (x86 target features: make pclmulqdq imply sse2)
- rust-lang#132180 (Print unsafety of attribute in AST pretty print)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit c26280a into rust-lang:masterOct 26, 2024
@rustbotrustbot added this to the 1.84.0 milestone Oct 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 26, 2024
Rollup merge of rust-lang#132124 - Zalathar:consolidate-covstar, r=jieyouxu
coverage: Consolidate creation of covmap/covfun records
This code for creating covmap/covfun records during codegen was split across multiple functions and files for dubious historical reasons. Having it all in one place makes it easier to follow.
This PR also includes two semi-related cleanups:
- Getting the codegen context's `coverage_cx` state is made infallible, since it should always exist when running the code paths that need it.
- The value of `covfun_section_name` is saved in the codegen context, since it never changes at runtime, and the code that needs it has access to the context anyway.
---
Background: Coverage instrumentation generates two kinds of metadata that are embedded in the final binary. There is per-CGU information that goes in the `__llvm_covmap` linker section, and per-function information that goes in the `__llvm_covfun` section (except on Windows, where slightly different section names are used).
@Zalathar
Zalathar deleted the consolidate-covstar branch October 26, 2024 22:14
@Zalathar

Copy link
Copy Markdown
MemberAuthor

I've seen at least one report of coverage_cx() causing an ICE in the wild, so it looks like I'll need to revert that part until I have a better idea of what's going on.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2024
coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable
In rust-lang#132124, `coverage_cx()` was changed to panic if the context was unavailable, under the assumption that it would always be available whenever coverage instrumentation is enabled.
However, there have been reports of this change causing ICEs in `polars` CI.
I don't yet understand why this is happening, but for now it seems wisest to revert that part of the change, restoring the two early returns that had been replaced with panics.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2024
coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable
In rust-lang#132124, `coverage_cx()` was changed to panic if the context was unavailable, under the assumption that it would always be available whenever coverage instrumentation is enabled.
However, there have been reports of this change causing ICEs in `polars` CI.
I don't yet understand why this is happening, but for now it seems wisest to revert that part of the change, restoring the two early returns that had been replaced with panics.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 31, 2024
Rollup merge of rust-lang#132395 - Zalathar:coverage-cx-ice, r=jieyouxu
coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable
In rust-lang#132124, `coverage_cx()` was changed to panic if the context was unavailable, under the assumption that it would always be available whenever coverage instrumentation is enabled.
However, there have been reports of this change causing ICEs in `polars` CI.
I don't yet understand why this is happening, but for now it seems wisest to revert that part of the change, restoring the two early returns that had been replaced with panics.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Zalathar@jieyouxu@bors@pnkfelix@rustbot