You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not clear if using our Coverage build type works with Clang, or not. In the linked thread there are simultaneous claims that it "works", but also that it does not work. It seems from the discussion that even using GCC with the Coverage build type is flaky.
There's been suggestions to add a Coverage mode for Clang: hebasto#233, however adding a second way of doing things, when the current way may not work properly, and (likely?) currently isn't being used by anyone, doesn't seem like a good approach, and adds even more complication to the build system. Note that devs are already using Clang for coverage regardless of if it currently exists in the build system (cc @dergoegge, @marcofleon, @vasild).
If using Clangs native coverage mode is what is preferred/is "better", then it'd seem better for us to replace the current, more GCC focussed implementation, with one that is geared towards LLVM/Clang, if the idea is to provide something that works out-of-the-box, and is generally used by the developers working on the project.
I haven't tried after the transition to CMake but I always had trouble with the build in coverage build mode (e.g. make cov). Usually there was problem with path prefixes or a lcov version mismatch. The coverage reports themselves were always hard to read and I could not find any documentation on how to read them, for example:
How is branch coverage supposed to be interpreted from this?
For me it seems best to use each compiler's native workflow. That is: gcov+lcov if using GCC and the source based coverage if using Clang.
Would be nice if that is integrated into the build system so it boils down to just cmake --i-want-coverage, but if not, then some good instructions in doc/ would be fine as well.
For me it seems best to use each compiler's native workflow.
Sure, anyone can still use whatever they like. However our build system doesn't need to (and shouldn't have to) handle all possible combinations of compiler + tooling. Providing a single convenience build type that is the same as what is used by the majority of the developers seems fine, however I don't think we need to natively support anything outside of that, given it's unlikely to be tested/used, or work properly, and just futher complicates our build system.
It's not though, because gcc compiler + gcov/lcov already encompasses more than 1 thing. i.e supporting different versions of gcov/lcov across releases.
I don't have a strong preference for which one is supported by the build system. I happened to learn about llvm-cov before coming upon the coverage section in the docs, so that's what I've been using on both macOS and Linux. It's been working well for me so far.
I liked the summary stats per folder produced by the current approach, but if others like other stuff better, I don't mind.
Maybe I misunderstand, but somehow the above implies that we have to commit to one and give up on the other method. But one can create gcc or clang coverages regardless of what is integrated into the cmake build system. That integration would be just a convenience and we could have no integration, or just gcc (the current master), or just clang or both gcc and clang.
It is using the coverage build type, which this issue is about. In any case, all mentioned projects are open-source, and I am happy to review pull requests, if there are any. Removing the cmake scripts may be fine, but I don't see it as a release blocker.
It's not clear if using our Coverage build type works with Clang, or not.
There are a few points to take into consideration:
Modern LLVM's coverage tool emulates GCC's gcov version 4.2.0, which is obviously outdated.
Recent versions of the lcov tool no longer support GCC/gcov versions older than 9.x. For example:
lcov: WARNING: (unsupported) Function begin/end line exclusions not supported with this version of GCC/gcov; require gcc/9 or newer: attempting to derive function end lines - see lcovrc man entry for 'derive_function_end_line'.
Thus, I must conclude that the answer is "No."
The current "Coverage" build type should be considered and documented as GCC-only.
I don't think so. If anything, it's even more of an indication that we should swap what has been implemented for GCC (and still not documented as such, leading to i.e #32571) for LLVM / Clang, which is clearly what (the majority of) project contributors are using, or wanting to use.
My impression is that a non-trivial part of the developers use Linux with its native compiler GCC. The current GCC-oriented method we have does work with GCC, contrary to what the OP suggests "the current way may not work properly".
So, to me it looks like that removing the current GCC-oriented way could affect some developers in a negative way. I could be wrong though. Maybe none of the Linux people generate code coverage? 👀 Or they bother to install Clang additionally and use that?
If the people that attended the IRC meeting is a representative sample, then I guess it might be ok to ditch the current GCC-oriented coverage "integration" into CMake and replace it with Clang's (which is already documented at doc/developer-notes.md / Using LLVM/Clang toolchain), instead of having to maintain both.
I guess there will be more feedback once there is a PR which does that.
I tried getting lcov working using Coverage.cmake yesterday on de92545 and I couldn't get it to work.
Both gcc and clang built the project fine, but the lcov step was generating errors.
shell.nix env
gcc is implicitly part of this environment, so I didn't need to add it.
The exported vars should not be a problem because I explicitly set compilers later.
gcc/clang + lcov
The build for clang was similar, you just need to adjust the C/CXX compiler variables, but I wouldn't expect it to work with lcov if gcc doesn't, so I'm including the gcc version.
Based on this experience, I recommend switching to clang + llvm-cov in Coverage.cmake. This configuration also has an advantage since clang and coverage are often used in fuzzing, with libFuzzer and sanitizers.
Not sure what the current status here is. Looks like there was an IRC meeting that concluded it would be fine to remove the GCC coverage cmake type. Given that there are docs for llmv, it seems fine to fully remove it without replacement, but some places need to be updated first, see #31047 (comment) for a list.
Activity
dergoegge commentedon Oct 7, 2024
I haven't tried after the transition to CMake but I always had trouble with the build in coverage build mode (e.g.
make cov). Usually there was problem with path prefixes or alcovversion mismatch. The coverage reports themselves were always hard to read and I could not find any documentation on how to read them, for example:How is branch coverage supposed to be interpreted from this?
I've switched all my coverage reports to using LLVM's native coverage tooling: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#id3. I don't use our build in command to produce coverage reports but I think it's a useful thing to have, so devs can easily produce their own coverage reports. I can recommend switching to LLVM's native coverage reporting, as that has been far less of a struggle in my experience.
vasild commentedon Oct 7, 2024
For me it seems best to use each compiler's native workflow. That is: gcov+lcov if using GCC and the source based coverage if using Clang.
Would be nice if that is integrated into the build system so it boils down to just
cmake --i-want-coverage, but if not, then some good instructions indoc/would be fine as well.fanquake commentedon Oct 7, 2024
Sure, anyone can still use whatever they like. However our build system doesn't need to (and shouldn't have to) handle all possible combinations of compiler + tooling. Providing a single convenience build type that is the same as what is used by the majority of the developers seems fine, however I don't think we need to natively support anything outside of that, given it's unlikely to be tested/used, or work properly, and just futher complicates our build system.
vasild commentedon Oct 7, 2024
It is just two:
(I think it is a waste of time and we should ignore a third option where we try to use the gcov/lcov workflow with clang).
I do not object this, but then if only 1. or only 2. is supported then the coverage build should produce an error if the compiler is the other one.
fanquake commentedon Oct 7, 2024
It's not though, because
gcc compiler + gcov/lcovalready encompasses more than 1 thing. i.e supporting different versions of gcov/lcov across releases.marcofleon commentedon Oct 7, 2024
I don't have a strong preference for which one is supported by the build system. I happened to learn about llvm-cov before coming upon the coverage section in the docs, so that's what I've been using on both macOS and Linux. It's been working well for me so far.
fanquake commentedon Oct 10, 2024
cc @maflcko. Do you have an opinion here?
maflcko commentedon Oct 10, 2024
I liked the summary stats per folder produced by the current approach, but if others like other stuff better, I don't mind.
dergoegge commentedon Oct 10, 2024
The LLVM approach also supports that:
edit: this is possible with the
-show-directory-coverageoption forllvm-cov show.vasild commentedon Oct 10, 2024
Maybe I misunderstand, but somehow the above implies that we have to commit to one and give up on the other method. But one can create gcc or clang coverages regardless of what is integrated into the cmake build system. That integration would be just a convenience and we could have no integration, or just gcc (the current
master), or just clang or both gcc and clang.maflcko commentedon Oct 10, 2024
Yeah. I guess I don't really mind either way. As long as there is at least one documented, tested and working solution.
maflcko commentedon Oct 28, 2024
I switched https://maflcko.github.io/b-c-cov/ to GCC, just to get something working again. But the config is open source and pull requests with changes are welcome: https://github.com/maflcko/b-c-cov
fanquake commentedon Nov 19, 2024
Apparently code coverage on oss-fuzz has been broken since CMake. See https://issues.oss-fuzz.com/issues/379122777. Full logs (https://oss-fuzz-build-logs.storage.googleapis.com/log-6b12c5ff-d6c4-441c-a10f-2dffff96e82c.txt):
8 remaining items
fanquake commentedon Feb 14, 2025
Looking at Corecheck, does it use our
Coverage.cmake? I can't find it being used anywhere there, seems like only calls to gcovr directly.maflcko commentedon Feb 17, 2025
It is using the coverage build type, which this issue is about. In any case, all mentioned projects are open-source, and I am happy to review pull requests, if there are any. Removing the cmake scripts may be fine, but I don't see it as a release blocker.
maflcko commentedon Feb 21, 2025
Removing the milestone for now. I am happy to review pull requests or suggestions, if there are any.
hebasto commentedon Feb 21, 2025
From the OP:
There are a few points to take into consideration:
gcovversion 4.2.0, which is obviously outdated.lcovtool no longer support GCC/gcov versions older than 9.x. For example:Thus, I must conclude that the answer is "No."
The current "Coverage" build type should be considered and documented as GCC-only.
maflcko commentedon Jun 5, 2025
Can this be closed as fixed by 31933?
fanquake commentedon Jun 6, 2025
I don't think so. If anything, it's even more of an indication that we should swap what has been implemented for GCC (and still not documented as such, leading to i.e #32571) for LLVM / Clang, which is clearly what (the majority of) project contributors are using, or wanting to use.
vasild commentedon Jun 12, 2025
My impression is that a non-trivial part of the developers use Linux with its native compiler GCC. The current GCC-oriented method we have does work with GCC, contrary to what the OP suggests "the current way may not work properly".
So, to me it looks like that removing the current GCC-oriented way could affect some developers in a negative way. I could be wrong though. Maybe none of the Linux people generate code coverage? 👀 Or they bother to install Clang additionally and use that?
Lets see if a quick poll on IRC would help bring some clarity to this: https://www.erisian.com.au/bitcoin-core-dev/log-2025-06-12.html#l-69
vasild commentedon Jun 13, 2025
If the people that attended the IRC meeting is a representative sample, then I guess it might be ok to ditch the current GCC-oriented coverage "integration" into CMake and replace it with Clang's (which is already documented at
doc/developer-notes.md/Using LLVM/Clang toolchain), instead of having to maintain both.I guess there will be more feedback once there is a PR which does that.
maflcko commentedon Jun 13, 2025
There already is (well not a replacement, but close enough), see #31394 (comment)
nkaretnikov commentedon May 29, 2026
I tried getting lcov working using
Coverage.cmakeyesterday on de92545 and I couldn't get it to work.Both gcc and clang built the project fine, but the lcov step was generating errors.
shell.nix env
gcc is implicitly part of this environment, so I didn't need to add it.
The exported vars should not be a problem because I explicitly set compilers later.
gcc/clang + lcov
The build for clang was similar, you just need to adjust the C/CXX compiler variables, but I wouldn't expect it to work with lcov if gcc doesn't, so I'm including the gcc version.clang + llvm-cov
Based on this experience, I recommend switching to clang + llvm-cov in
Coverage.cmake. This configuration also has an advantage since clang and coverage are often used in fuzzing, with libFuzzer and sanitizers.maflcko commentedon Sep 1, 2026
Not sure what the current status here is. Looks like there was an IRC meeting that concluded it would be fine to remove the GCC coverage cmake type. Given that there are docs for llmv, it seems fine to fully remove it without replacement, but some places need to be updated first, see #31047 (comment) for a list.
maflcko commentedon Sep 1, 2026
Only slightly related: Both gcov and llvm-cov seem filled with bugs, see the thread in bitcoin-core/qa-assets#292 listing a few bugs.