Skip to content

Invalid LLVM coverage data produced with crate brotli_decompressor #82875

Closed
@catenacyber

Description

@catenacyber

I tried this code:

use std::io;
use brotli_decompressor;

fn main() {
    match brotli_decompressor::BrotliDecompress(&mut io::stdin(), &mut io::stdout()) {
        Ok(_) => {},
        Err(e) => panic!("Error {:?}", e),
    }
}

compiled with RUSTFLAGS="-Zinstrument-coverage"
and Cargo.toml having

[dependencies]
brotli-decompressor = "2.3.1"

I expected to see this happen:
Running echo 123 | ./target/debug/rustcov then llvm-profdata merge -j=1 -sparse, then llvm-cov should give me a coverage report

Instead, this happened:
llvm-cov fails with `Failed to load coverage: Malformed instrumentation profile data

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (476acbf1e 2021-03-03)
binary: rustc
commit-hash: 476acbf1e9965b5e95c90f0d7d658709812b7003
commit-date: 2021-03-03
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Backtrace

There is no backtrace here as the failure happens with llvm-cov
I used the following clang

clang --version
clang version 12.0.0 (https://github.com/llvm/llvm-project.git 4918a3d138b907a571f496661b5367e090e1e8bb)

Using this patch in llvm

diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 1acdcb4bebb9..b985ea11138d 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -544,8 +544,11 @@ class VersionedCovMapFuncRecordReader : public CovMapFuncRecordReader {
       StringRef FuncName;
       if (Error Err = CFR->template getFuncName<Endian>(ProfileNames, FuncName))
         return Err;
-      if (FuncName.empty())
-        return make_error<InstrProfError>(instrprof_error::malformed);
+      if (FuncName.empty()) {
+       FuncName = "ossfuzz_llvm_rust_coverage_warning";
+       printf("function with hash %lx has no name", FuncHash);
+        //return make_error<InstrProfError>(instrprof_error::eof);
+      }
       ++CovMapNumUsedRecords;
       Records.emplace_back(Version, FuncName, FuncHash, Mapping,
                            FileRange.StartingIndex, FileRange.Length);

I get more information with, as llvm-cov prints
function with hash 66eebda9c13062cc has no name

cc @richkadel
Might end up as a duplicate of #82144
But I do not see any optimization in cargo build -vv

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions