callgrind_annotate broken after cmake migration? #31957

issue maflcko opened this issue on February 26, 2025
  1. maflcko commented at 3:48 PM on February 26, 2025: member

    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)

  2. maflcko added the label Build system on Feb 26, 2025
  3. maflcko added the label Tests on Feb 26, 2025
  4. hebasto commented at 1:47 PM on March 26, 2025: 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?

  5. hebasto commented at 1:52 PM on March 26, 2025: member

    I've tested the master branch @ c0b7159de47592c95c6db061de682b4af4058102 with the diff from #31957#issue-2882058716 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
    
    --------------------------------------------------------------------------------
    
  6. maflcko commented at 3:28 PM on March 26, 2025: member

    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?

  7. maflcko commented at 3:07 PM on November 18, 2025: member

    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
    
  8. maflcko commented at 3:10 PM on November 18, 2025: 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?

  9. hebasto commented at 10:43 AM on November 23, 2025: 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?

    https://github.com/bitcoin/bitcoin/commit/788c1324f3d840f7a39b8bc3537dcff26ca0b552 could be considered for reverting. However, doing so would resurface #30799.

  10. hebasto commented at 11:08 AM on November 23, 2025: 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) {
    
  11. maflcko commented at 2:58 PM on January 14, 2026: member

    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.

  12. hebasto closed this on Jan 26, 2026

  13. hebasto referenced this in commit 1cc58d3a0c on Jan 26, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-01 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me