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

Coverage is not generated when using rust-lld as linker #79555

Open
briansmith opened this issue Nov 30, 2020 · 4 comments
Open

Coverage is not generated when using rust-lld as linker #79555

briansmith opened this issue Nov 30, 2020 · 4 comments
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug.

Comments

@briansmith
Copy link
Contributor

First:

cargo init --lib

No changes to the generated crate are necessary. Then:

rm -Rf target/x86_64-unknown-linux-musl && \
CARGO_INCREMENTAL=0 RUSTFLAGS="-Zinstrument-coverage -Clink-self-contained=yes -Clinker=rust-lld" cargo +nightly test --target=x86_64-unknown-linux-musl && \
find . -name "*.profraw"

and

rm -Rf target/x86_64-unknown-linux-musl && \
CARGO_INCREMENTAL=0 RUSTFLAGS="-Zprofile -Clinker=rust-lld" cargo +nightly test --target=x86_64-unknown-linux-musl && \
find . -name "*.gcda"

I expected to see this happen:

The profiling data is generated; i.e. each find command outputs at least one result.

Instead, this happened:

No profiling data is generated.

This seems very similar to Issue #71233: "Coverage is not generated when using lld as linker" and it may be a regression.

Note that the specific combination of RUSTFLAGS that I'm trying to use is RUSTFLAGS="-Zinstrument-coverage -Clink-self-contained=yes -Clinker=rust-lld" so that I can use the new self-contained linking support for musl targets when profiling; see https://github.com/rust-lang/rust/blob/master/RELEASES.md#compiler. I think this combination of flags will become commonplace soon.

$ rustc +nightly --version --verbose
rustc 1.50.0-nightly (349b3b324 2020-11-29)
binary: rustc
commit-hash: 349b3b324dade7ca638091db93ba08bbc443c63d
commit-date: 2020-11-29
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
```
@briansmith

This comment has been minimized.

@briansmith
Copy link
Contributor Author

I forgot to add these important details:

  • Removing -Clinker=rust-lld from RUSTFLAGS causes the coverage data to be generated in both for -Zprofile and -Zinstrument-coverage
  • -Clink-self-contained=yes does not seem to affect this; only -Clinker=rust-lld affects this.
  • This should also be labeled "A-linkage" in addition to "A-code-coverage".
  • This probably blocks Use lld by default on x64 Ubuntu 20.04 LTS #71515.

@wesleywiser wesleywiser added A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-linkage Area: linking into static, shared libraries and binaries labels Nov 30, 2020
@richkadel
Copy link
Contributor

Just a follow-up regarding the implementation of -Zinstrument-coverage (I'm not sure if this is obvious): The entire rust-side of the implementation, through codegen, ends at the generation of LLVM-IR. There were no special Rust-specific mods to the linkage, so I assume the limitation is in rust-lld.

For someone familiar with rust-lld (which I am not), It may be worth looking into the Coverage Mapping Format, which does describe some linkage-specific directives, and maybe relevant assumptions/implications that aren't handled in rust-lld. Elements of the coverage map do have to be merged across libraries, etc. I don't know how that process works exactly. And there are runtime expectations, specifically things like exit hooks to write out the profiling data.

@djc
Copy link
Contributor

djc commented Oct 5, 2021

Information from https://bugs.chromium.org/p/chromium/issues/detail?id=919499#c16 suggests that passing --no-rosegment might help:

[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Clink-arg=-Wl,--no-rosegment"]

(As came up in flamegraph-rs/flamegraph#157.)

briansmith added a commit to briansmith/ring that referenced this issue May 14, 2024
We were able to add armv7-unknown-linux-gnueabihf without
rust-lang/rust#79555 being fixed.
briansmith added a commit to briansmith/ring that referenced this issue May 14, 2024
We were able to add armv7-unknown-linux-gnueabihf without
rust-lang/rust#79555 being fixed.
addd45 pushed a commit to addd45/ring_pre_digest that referenced this issue Oct 4, 2024
We were able to add armv7-unknown-linux-gnueabihf without
rust-lang/rust#79555 being fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants