Skip to content

lcov usage fails with clang #12602

Closed

Description

@jamesob

When attempting to generate coverage information with make cov after configuring and building with clang, lcov/gcov (for the versions I'm using) are unable to parse the generated gcda files:

/home/james/tmp/bitcoin/src/libbitcoin_server_a-miner.gcno:version '402*', prefer 'A72*'
geninfo: ERROR: GCOV failed for /home/james/tmp/bitcoin/src/libbitcoin_server_a-miner.gcda!
Makefile:1269: recipe for target 'test_bitcoin.info' failed

We may need to special-case the effects of --enable-lcov when building with clang to use flags and commands mentioned here.

Configure output

Options used to compile and link:
  with wallet   = yes
  with gui / qt = yes
    qt version  = 5
    with qr     = auto
  with zmq      = yes
  with test     = yes
  with bench    = yes
  with upnp     = auto
  use asm       = yes
  debug enabled = no
  werror        = no

  target os     = linux
  build os      =

  CC            = /usr/bin/clang-4.0
  CFLAGS        = -g -O2
  CPPFLAGS      = -I/home/james/tmp/bitcoin/db4/include/ -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
  CXX           = /usr/bin/clang++-4.0 -std=c++11
  CXXFLAGS      = -std=c++11 -std=c++11  --coverage -Og
  LDFLAGS       = -L/home/james/tmp/bitcoin/db4/lib/ --coverage
  ARFLAGS       = cr

Versions

 $ clang++-4.0 --version

clang version 4.0.1-6 (tags/RELEASE_401/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

 $ lcov --version

lcov: LCOV version 1.13

 $ gcov --version

gcov (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

make cov failure

$ make cov
...
/usr/bin/lcov --gcov-tool=/usr/bin/gcov -c  -d /home/james/tmp/bitcoin/src -t test_bitcoin -o test_bitcoin.info
Capturing coverage data from /home/james/tmp/bitcoin/src
Found gcov version: 7.2.0
Scanning /home/james/tmp/bitcoin/src for .gcda files ...
Found 290 data files in /home/james/tmp/bitcoin/src
Processing src/libbitcoin_server_a-miner.gcda
/home/james/tmp/bitcoin/src/libbitcoin_server_a-miner.gcno:version '402*', prefer 'A72*'
geninfo: ERROR: GCOV failed for /home/james/tmp/bitcoin/src/libbitcoin_server_a-miner.gcda!
Makefile:1269: recipe for target 'test_bitcoin.info' failed
make: *** [test_bitcoin.info] Error 29
rm test_bitcoin.info baseline_filtered.info baseline.info

Activity

  1. maflcko commented on Mar 12, 2018

    @maflcko
    Member

    I always assumed that gcov only works with gcc.

  2. jamesob commented on Mar 26, 2018

    @jamesob
    ContributorAuthor

    Might preferable to warn during configuration if --enable-coverage is combined with non-gcc usage. I'll try for a PR soonish.

  3. maflcko commented on Feb 27, 2019

    @maflcko
    Member

    I'd rather add support for llvm-cov in addition to --enable-lcov

  4. maflcko commented on Dec 7, 2019

    @maflcko
    Member

    You can use llvm-cov with clang with the following diff applied:

    diff --git a/configure.ac b/configure.ac
    index 2c648b0b5c..c502543a1a 100644
    --- a/configure.ac
    +++ b/configure.ac
    @@ -87,7 +87,7 @@ dnl Check/return PATH for base programs.
     AC_PATH_TOOL(AR, ar)
     AC_PATH_TOOL(RANLIB, ranlib)
     AC_PATH_TOOL(STRIP, strip)
    -AC_PATH_TOOL(GCOV, gcov)
    +AC_PATH_TOOL(GCOV, llvm-cov_gcov)
     AC_PATH_PROG(LCOV, lcov)
     dnl Python 3.5 is specified in .python-version and should be used if available, see doc/dependencies.md
     AC_PATH_PROGS([PYTHON], [python3.5 python3.6 python3.7 python3.8 python3 python])

    Then create an executable file

    $ cat ~/bin/llvm-cov_gcov 
    #!/usr/bin/env bash
    exec llvm-cov gcov "$@"
    $ which llvm-cov_gcov
    ~/bin/llvm-cov_gcov
    
  5. added a commit that references this issue on Mar 27, 2020
  6. added a commit that references this issue on Aug 8, 2020
  7. locked as resolved and limited conversation to collaborators on Feb 15, 2022
  8. added a commit that references this issue on Jul 19, 2026
    bb808d4
  9. added a commit that references this issue on Aug 30, 2026
    c2aef3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions