Skip to content

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

Open
@briansmith

Description

@briansmith

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
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions