Skip to content

callgrind_annotate broken after cmake migration? #31957

Closed

Description

@maflcko

Steps to reproduce on a fresh install of Ubuntu LTS 24.04:

  • Install packages and clone repo: ( export DEBIAN_FRONTEND=noninteractive && apt update && apt install git ccache make build-essential libtool cmake autotools-dev automake pkg-config bsdmainutils python3 libevent-dev libboost-dev libsqlite3-dev valgrind -y && git clone https://github.com/bitcoin/bitcoin.git b-c ) && cd b-c
  • git checkout 338bc2cd261ba3daf7fb494f8cb4a534762e292c # cmake migration (allows to test autotools and cmake on the same commit)
  • Apply a diff to create more function calls in one hotspot (optional):
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index c2c725d676..704c060749 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -273,13 +273,15 @@ BOOST_AUTO_TEST_CASE(util_ReplaceAll)
         ReplaceAll(test, search, substitute);
         BOOST_CHECK_EQUAL(test, expected);
     };
-
+    int i{10000};
+while (i-->0){
     test_replaceall("", "foo", original);
     test_replaceall(original, "foo", "foo");
     test_replaceall("%s", "foo", "A test \"foo\" string 'foo'.");
     test_replaceall("\"", "foo", "A test foo%sfoo string '%s'.");
     test_replaceall("'", "foo", "A test \"%s\" string foo%sfoo.");
 }
+}
 
 BOOST_AUTO_TEST_CASE(util_TrimString)
 {
  • Then create two out-of-tree builds, run a test in callgrind, and annotate it:
  • ./autogen.sh && rm -rf ./bld-a && mkdir bld-a && ( cd bld-a && ../configure && make -j$(nproc) )
  • rm -rf ./bld-c && cmake -B ./bld-c && cmake --build ./bld-c -j $(nproc)
  • valgrind --tool=callgrind --callgrind-out-file=cg-a-%p.out ./bld-a/src/test/test_bitcoin -t util_tests/util_ReplaceAll
  • valgrind --tool=callgrind --callgrind-out-file=cg-c-%p.out ./bld-c/src/test/test_bitcoin -t util_tests/util_ReplaceAll
  • callgrind_annotate ./cg-a-40328.out
  • callgrind_annotate ./cg-c-39984.out

The cmake version of the last call will print a warning:

--------------------------------------------------------------------------------
The following files chosen for auto-annotation could not be found:
--------------------------------------------------------------------------------
  ./bld-c/src/crypto/./src/compat/byteswap.h
  ./bld-c/src/crypto/./src/crypto/sha256.cpp
  ./bld-c/src/crypto/./src/crypto/sha512.cpp
  ./bld-c/src/test/./src/test/crypto_tests.cpp
  ./bld-c/src/test/./src/test/util_tests.cpp
  ./bld-c/src/util/./src/random.cpp
  ./bld-c/src/util/./src/util/string.cpp
...

It also seems not possible to fix with --include=dir, as the path look a bit odd (non-existing)

Activity

  1. hebasto commented on Mar 26, 2025

    @hebasto
    Member

    Are there any requirements for debug info when using the valgrind --tool=callgrind + callgrind_annotate toolset? Are there any incompatible or unsupported compiler flags?

  2. hebasto commented on Mar 26, 2025

    @hebasto
    Member

    I've tested the master branch @ c0b7159 with the diff from #31957 (comment) on Ubuntu 24.04:

    $ callgrind_annotate ./cg-c-72381.out
    <snip>
    ...
    --------------------------------------------------------------------------------
    The following files chosen for auto-annotation could not be found:
    --------------------------------------------------------------------------------
      ./elf/../sysdeps/generic/dl-new-hash.h
      ./elf/../sysdeps/x86_64/dl-machine.h
      ./elf/./elf/dl-lookup.c
      ./elf/./elf/dl-reloc.c
      ./elf/./elf/do-rel.h
      ./malloc/./malloc/arena.c
      ./malloc/./malloc/malloc.c
      ./string/../sysdeps/x86_64/multiarch/../multiarch/strcmp-sse2.S
      ./string/../sysdeps/x86_64/multiarch/memcmp-avx2-movbe.S
      ./string/../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
      ./string/../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
      ./string/../sysdeps/x86_64/multiarch/strchr-avx2.S
    
    --------------------------------------------------------------------------------
    Ir                   
    --------------------------------------------------------------------------------
    787,159,045 (83.13%)  events annotated
    
    

    UPD. When configured -DWITH_CCACHE=OFF:

    --------------------------------------------------------------------------------
    The following files chosen for auto-annotation could not be found:
    --------------------------------------------------------------------------------
      ./elf/../sysdeps/generic/dl-new-hash.h
      ./elf/../sysdeps/x86_64/dl-machine.h
      ./elf/./elf/dl-lookup.c
      ./elf/./elf/dl-reloc.c
      ./elf/./elf/do-rel.h
      ./malloc/./malloc/arena.c
      ./malloc/./malloc/malloc.c
      ./string/../sysdeps/x86_64/multiarch/../multiarch/strcmp-sse2.S
      ./string/../sysdeps/x86_64/multiarch/memcmp-avx2-movbe.S
      ./string/../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
      ./string/../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
      ./string/../sysdeps/x86_64/multiarch/strchr-avx2.S
      build/./compat/byteswap.h
      build/./crypto/sha256.cpp
      build/./crypto/sha512.cpp
      build/./random.cpp
      build/./test/crypto_tests.cpp
      build/./test/util_tests.cpp
      build/./util/string.cpp
    
    --------------------------------------------------------------------------------
    
  3. maflcko commented on Mar 26, 2025

    @maflcko
    MemberAuthor

    I've tested the master branch @ c0b7159 with the diff from #31957 (comment) on Ubuntu 24.04:

    I can't reproduce. What are the exact steps to reproduce from a fresh install of the operating system, like in OP?

  4. maflcko commented on Nov 18, 2025

    @maflcko
    MemberAuthor

    Ah, looks like this is related to the prefix-map and the following workaround fixes it:

    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index f264acc..9ed5b46 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -488,12 +488,6 @@ try_append_cxx_flags("-fno-extended-identifiers" TARGET core_interface SKIP_LINK
     # which can cause issues with coverage builds, particularly when using
     # Clang in the OSS-Fuzz environment due to its use of other options
     # and a third party script, or with GCC.
    -try_append_cxx_flags("-fdebug-prefix-map=A=B" TARGET core_interface SKIP_LINK
    -  IF_CHECK_PASSED "-fdebug-prefix-map=${PROJECT_SOURCE_DIR}/src=."
    -)
    -try_append_cxx_flags("-fmacro-prefix-map=A=B" TARGET core_interface SKIP_LINK
    -  IF_CHECK_PASSED "-fmacro-prefix-map=${PROJECT_SOURCE_DIR}/src=."
    -)
     
     # GCC versions 13.2 (and earlier) are subject to a class of bugs, see
     # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348 and the meta bug
  5. maflcko commented on Nov 18, 2025

    @maflcko
    MemberAuthor

    Maybe the prefix-map can be disabled by default or an option could be added to disable it, or it could be disabled on -DWITH_CCACHE=NO, as there is no need for it then?

  6. hebasto commented on Nov 23, 2025

    @hebasto
    Member

    Maybe the prefix-map can be disabled by default or an option could be added to disable it, or it could be disabled on -DWITH_CCACHE=NO, as there is no need for it then?

    788c132 could be considered for reverting. However, doing so would resurface #30799.

  7. hebasto commented on Nov 23, 2025

    @hebasto
    Member

    Maybe the prefix-map can be disabled by default or an option could be added to disable it, or it could be disabled on -DWITH_CCACHE=NO, as there is no need for it then?

    788c132 could be considered for reverting. However, doing so would resurface #30799.

    And the latter could be addressed using another approach:

    --- a/src/logging.cpp
    +++ b/src/logging.cpp
    @@ -410,7 +410,7 @@ void BCLog::Logger::FormatLogStrInPlace(std::string& str, BCLog::LogFlags catego
         str.insert(0, GetLogPrefix(category, level));
     
         if (m_log_sourcelocations) {
    -        str.insert(0, strprintf("[%s:%d] [%s] ", RemovePrefixView(source_loc.file_name(), "./"), source_loc.line(), source_loc.function_name()));
    +        str.insert(0, strprintf("[%s:%d] [%s] ", RemovePrefixView(RemovePrefixView(source_loc.file_name(), "./"), "src/"), source_loc.line(), source_loc.function_name()));
         }
     
         if (m_log_threadnames) {
  8. maflcko commented on Jan 14, 2026

    @maflcko
    MemberAuthor

    For reference, the current steps to test on a fresh install of Ubuntu 26.04 LTS:

        1  ( export DEBIAN_FRONTEND=noninteractive && apt update && apt install git ccache make build-essential libtool cmake autotools-dev automake pkg-config bsdmainutils python3     libevent-dev libboost-dev  libsqlite3-dev valgrind  -y && git clone https://github.com/bitcoin/bitcoin.git b-c ) && cd b-c 
        7  git apply /tmp/a  # apply optional patch
        9  rm -rf ./bld-c && cmake -DENABLE_IPC=OFF -B ./bld-c && cmake --build ./bld-c -j $(nproc) 
       10  valgrind --tool=callgrind --callgrind-out-file=cg-c-%p.out ./bld-c/bin/test_bitcoin -t util_tests/util_ReplaceAll 
       11  callgrind_annotate ./cg-c-19826.out 
    

    This allows testing with and without #34281 to confirm it is fixed.

  9. added a commit that references this issue on Jan 26, 2026
  10. added a commit that references this issue on Jun 28, 2026
  11. added a commit that references this issue on Jun 30, 2026
  12. added a commit that references this issue on Aug 19, 2026
  13. added a commit that references this issue on Nov 18, 2026
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