llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.9k stars 11.94k forks source link

Coverage with `GCOV_PREFIX` not working as expected #81477

Open dothebart opened 8 months ago

dothebart commented 8 months ago

I've chosen a minimal project with cmake to demonstrate this. My Host is a debian bookworm, however in ubuntu docker containers clang-16 has shown similar behaviour.

The version of the compiler:

clang++-16 --version 
Debian clang version 16.0.6 (15~deb12u1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

And its set up as the default compiler:

/usr/bin/c++ --version 
Debian clang version 16.0.6 (15~deb12u1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

along with:

/usr/bin/ld --version 
Debian LLD 16.0.6 (compatible with GNU linkers)

Now the instructions to generate a small c++ project within this environment:

git clone https://github.com/arangodb/velocypack
cd velocypack
mkdir build ; cd build
rm -rf * ; cmake .. -DCMAKE_CXX_FLAGS='-fprofile-instr-generate -fcoverage-mapping -mllvm -runtime-counter-relocation --coverage' -DCMAKE_C_FLAGS='-fprofile-instr-generate -fcoverage-mapping -mllvm -runtime-counter-relocation --coverage' -DCMAKE_LD_FLAGS='-fprofile-instr-generate -fcoverage-mapping -mllvm -runtime-counter-relocation --coverage'; make -j 32
export GCOV_PREFIX=/tmp/blub
./tools/fuzzer
export GCOV_PREFIX=/tmp/bluub
./tools/fuzzer

It seems that without --coverage in the arguments strings shows a binary containing GCOV_PREFIX, however, the functionality doesn't seem to be enabled, no profile is collected with the information specified above.

And then try to merge the two profile sets demonstrates the error:

llvm-profdata-16 merge /tmp/blub /tmp/bluub -o /tmp/234
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Builder.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Builder.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/fpconv.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/fpconv.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Exception.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Exception.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/HexDump.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/HexDump.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Options.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Options.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Value.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Value.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Dumper.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Dumper.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/asm-utf8check.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/asm-utf8check.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Utf8Helper.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Utf8Helper.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/ValueType.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/ValueType.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/xxhash.c.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/xxhash.c.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Slice.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Slice.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Parser.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Parser.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/asm-functions.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/asm-functions.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Validator.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/CMakeFiles/velocypack.dir/src/Validator.cpp.gcda: truncated profile data
warning: /tmp/blub/tmp/velocypack/build/tools/CMakeFiles/fuzzer.dir/fuzzer.cpp.gcda: truncated profile data
warning: /tmp/bluub/tmp/velocypack/build/tools/CMakeFiles/fuzzer.dir/fuzzer.cpp.gcda: truncated profile data
error: no profile can be merged

I've seen https://github.com/llvm/llvm-project/issues/50966 but am not sure whether its related.

MaskRay commented 8 months ago

--coverage / GCOV_PREFIX is for GCOV style code coverage, based on debug info.

-fprofile-instr-generate -fcoverage-mapping -mllvm -runtime-counter-relocation are for https://clang.llvm.org/docs/SourceBasedCodeCoverage.html

The two are independent implementations and generally not supposed to be used together. GCOV_PREFIX does not control the output directory of SourceBasedCodeCoverage