Repository navigation
Malformed coverage data when using llvm-cov #119453
Description
Activity
- addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Dec 30, 2023 StackOverflowExcept1on commented
on Dec 30, 2023 ContributorAuthorMore actions@Zalathar I don't know how to reproduce this with a minimal example, but would appreciate it if you could somehow debug this in LLVM code. As you wrote earlier this comes from
llvm-cov. It throwscoveragemap_error::malformedsomewhere but without any backtrace.- addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)Area: Source-based code coverage (-Cinstrument-coverage)and removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Dec 30, 2023 StackOverflowExcept1on commented
on Dec 30, 2023 ContributorAuthorMore actionsI debugged LLVM and this comes from the same place: https://github.com/rust-lang/llvm-project/blob/fef3d7b14ede45d051dc688aae0bb8c8b02a0566/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp#L340-L344
But I have no idea how to get source file byExpandedFileIDto provide more info.Pinpointing the LLVM error was very helpful, thanks. Without that I wouldn’t be able to do much.
Can you give me an example of the LineStart/ColumnStart/NumLines/ColumnEnd values that are present when it fails? That should give me a better idea of what’s going wrong on the Rust side.
(I might not be able to track down the underlying issue, but hopefully I should at least be able to add some extra checks to the compiler to make sure LLVM doesn’t encounter a fatal error.)
StackOverflowExcept1on commented
on Dec 31, 2023 ContributorAuthorMore actionsLineStart=652 LineStartDelta=0 ColumnStart=9 NumLines=0 ColumnEnd=10 Counter in file 0 652:9 -> 652:10, #44 LineStart=1112 LineStartDelta=460 ColumnStart=1 NumLines=4294966836 ColumnEnd=10 Counter in file 0 1112:1 -> 4294967948:10, #0 here 1112, 1652, 10 error: Failed to load coverage: 'target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/main': malformed coverage data #10Reacted by ZalatharI've submitted a possible workaround in #119460.
It doesn't address the underlying question of why we were producing improper regions in the first place, but it does at least mean that we will detect and discard those regions early, instead of emitting them and having
llvm-covfail.NumLines=4294966836is 0xFFFF_FE34, which is -460 (relative toLineStart=1112).This suggests that the original coordinates were
1112:1 -> 652:10.Spans within the compiler are always properly-ordered in terms of byte positions (enforced in
Span::new), so I believe the only way to end up with improper line/column coordinates is if the span starts and ends in different files.I'm not sure how we're ending up with a span like that. I initially suspected
fn_sig_span, but it turns out that we requirefn_sig_spanandbody_spanto start in the same file, so that probably isn't the cause.I wonder if the span adjustment in
filtered_terminator_spanforTerminatorKind::Callcould be responsible, as it combines the endpoints of two potentially-unrelated spans.Though if the resulting span crosses file boundaries, I would expect it to be discarded by
unexpand_into_body_span, unless the body span also crosses file boundaries. But we don't do any ad-hoc manipulation of the endpoints of the body span itself, so the file-crossing span would have to already be present in MIR before coverage gets involved. I don't know whether that's possible or not.StackOverflowExcept1on commented
on Dec 31, 2023 ContributorAuthorMore actions@Zalathar Is there a way to find out which source file is causing the problem? I think it's pretty easy to edit the
llvm-covsource code on the fly and then put it to~/.rustup/toolchains/<toolchain>/lib/rustlib/...2 remaining items
That looks like the source of the
1112:1, but it leaves me puzzled as to where the652:10is coming from.I don’t think those coordinates point anywhere meaningful in the same file, but I’m not sure what other file they could be trying to refer to.
StackOverflowExcept1on commented
on Dec 31, 2023 ContributorAuthorMore actionsI don’t know what the hell is going on at
652:9 -> 652:10, but I can attach the full log: coverage.txtAnother piece of information that might be useful is the name of the function that has the malformed region in its coverage mappings.
It looks like you should be able to dump it from
R.FunctionNameinBinaryCoverageReader::readNextRecord.But you might need to dump it before the call to
Reader.read(), because I believe that's the call that fails when it encounters the bad region.- added 5 commits that reference this issue
on Jan 23, 2024 - added a commit that references this issue
on Jan 24, 2024 FTR I was seeing the same issue when running
cargo llvm-covwith another Substrate based chain. rustc 1.77.0-nightly fixed it for me. Will wait for this to become stable and upgrade.@Zalathar thanks for your patch!
Did 1.77.0 fix the problem @atodorov? Is the original problem fixed @StackOverflowExcept1on? Should the issue be closed?
Reacted by Alexander TodorovStackOverflowExcept1on commented
on Apr 2, 2025 ContributorAuthorMore actions@RodBurman This was probably fixed, but it was fixed by removing bad data from LLVM.
StackOverflowExcept1on commented
on Aug 13, 2025 ContributorAuthorMore actionsI think this should be closed because no one else has referred to this issue.
I tried to fuzz our substrate runtime but getting error:
How to reproduce (on our large repo)
Meta
rustc --version --verbose: