windows: build failure with GCC 14.2 & `-D_GLIBCXX_DEBUG` #31436

issue fanquake opened this issue on December 6, 2024
  1. fanquake commented at 11:38 AM on December 6, 2024: member

    Initially seen building using depends & DEBUG=1, which adds -D_GLIBCXX_DEBUG.

    # x86_64-w64-mingw32-g++ (GCC) 14.2.0 on Alpine x86_64
    make -C depends/ HOST=x86_64-w64-mingw32 -j12 NO_QT=1 NO_ZMQ=1 NO_WALLET=1
    cmake -B build --toolchain /bitcoin/depends/x86_64-w64-mingw32/toolchain.cmake -DAPPEND_CPPFLAGS="-D_GLIBCXX_DEBUG"
    cmake --build build
    <snip>
    [ 25%] Building CXX object src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.obj
    cd /bitcoin/build/src && /usr/bin/ccache /usr/bin/x86_64-w64-mingw32-g++ -DNOMINMAX -DSECP256K1_STATIC -DWIN32 -DWIN32_LEAN_AND_MEAN -D_MT -D_WIN32_IE=0x0A00 -D_WIN32_WINNT=0x0A00 -D_WINDOWS [@CMakeFiles](/bitcoin-bitcoin/contributor/cmakefiles/)/bitcoin_consensus.dir/includes_CXX.rsp -pipe -std=c++20 -O2 -O2 -g -std=c++20 -Wa,-muse-unaligned-vector-move -fno-extended-identifiers -fdebug-prefix-map=/bitcoin/src=. -fmacro-prefix-map=/bitcoin/src=. -fstack-reuse=none -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -MD -MT src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.obj -MF CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.obj.d -o CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.obj -c /bitcoin/src/pubkey.cpp -D_GLIBCXX_DEBUG
    In file included from /usr/x86_64-w64-mingw32/include/c++/14.2.0/debug/debug.h:90,
                     from /usr/x86_64-w64-mingw32/include/c++/14.2.0/bits/stl_algobase.h:69,
                     from /usr/x86_64-w64-mingw32/include/c++/14.2.0/string:51,
                     from /bitcoin/src/crypto/sha256.h:10,
                     from /bitcoin/src/hash.h:12,
                     from /bitcoin/src/pubkey.h:10,
                     from /bitcoin/src/pubkey.cpp:6:
    /bitcoin/src/pubkey.cpp:195:116:   in 'constexpr' expansion of 'std::span<const unsigned char>(util::hex_literals::operator""_hex_u8<util::detail::Hex<65>{std::array<std::byte, 32>{std::__array_traits<std::byte, 32>::_Type{(std::byte)80, (std::byte)146, (std::byte)155, (std::byte)116, (std::byte)193, (std::byte)160, (std::byte)73, (std::byte)84, (std::byte)183, (std::byte)139, (std::byte)75, (std::byte)96, (std::byte)53, (std::byte)233, (std::byte)122, (std::byte)94, (std::byte)7, (std::byte)138, (std::byte)90, (std::byte)15, (std::byte)40, (std::byte)236, (std::byte)150, (std::byte)213, (std::byte)71, (std::byte)191, (std::byte)238, (std::byte)154, (std::byte)206, (std::byte)128, (std::byte)58, (std::byte)192}}}>())'
    /usr/x86_64-w64-mingw32/include/c++/14.2.0/span:202:57:   in 'constexpr' expansion of '((std::span<const unsigned char>*)this)->std::span<const unsigned char>::span<const unsigned char*>((& __arr)->std::array<unsigned char, 32>::data(), 32)'
    /usr/x86_64-w64-mingw32/include/c++/14.2.0/span:165:11: error: '__builtin_expect(((long int)(! __gnu_debug::__valid_range<const unsigned char*>(__first, (__first + ((sizetype)__count))))), 0)' is not a constant expression
      165 |           __glibcxx_requires_valid_range(__first, __first + __count);
          |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    gmake[2]: *** [src/CMakeFiles/bitcoin_consensus.dir/build.make:170: src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.obj] Error 1
    
  2. smokeytempo commented at 12:00 PM on December 6, 2024: none

    You can remove the _GLIBCXX_DEBUG using:

    cmake -B build --toolchain /bitcoin/depends/x86_64-w64-mingw32/toolchain.cmake cmake --build build

    or:

    downgrade the version of GCC, well upgrade or downgrade

    or:

    Use alternative debugging tools

    or lastly:

    Isolate the debugging build from the production one to ensure no errors

  3. maflcko commented at 1:37 PM on December 9, 2024: member

    Possible workaround:

    diff --git a/src/pubkey.cpp b/src/pubkey.cpp
    index 0849d2a..a02c6e6 100644
    --- a/src/pubkey.cpp
    +++ b/src/pubkey.cpp
    @@ -192,7 +192,8 @@ int ecdsa_signature_parse_der_lax(secp256k1_ecdsa_signature* sig, const unsigned
      *  For an example script for calculating H, refer to the unit tests in
      *  ./test/functional/test_framework/crypto/secp256k1.py
      */
    -constexpr XOnlyPubKey XOnlyPubKey::NUMS_H{"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"_hex_u8};
    +constexpr auto val{"50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"_hex_u8};
    +constexpr XOnlyPubKey XOnlyPubKey::NUMS_H{val};
     
     std::vector<CKeyID> XOnlyPubKey::GetKeyIDs() const
     {
    

    Minimal reproducer https://godbolt.org/z/E4YafE9Pd:

    #include <array>
    #include <span>
    
    struct A {
        constexpr A(std::span<const unsigned char>) {}
    };
    constexpr A val{std::array<unsigned char, 2>{0x11, 0x22}};
    
  4. maflcko added the label Build system on Dec 9, 2024
  5. maflcko added the label Upstream on Dec 9, 2024
  6. maflcko commented at 2:40 PM on December 9, 2024: member
  7. maflcko commented at 7:58 AM on December 10, 2024: member

    This will also start hitting in CI, with:

    diff --git a/ci/test/00_setup_env_native_previous_releases.sh b/ci/test/00_setup_env_native_previous_releases.sh
    index 19a33f1..8b17e3b 100755
    --- a/ci/test/00_setup_env_native_previous_releases.sh
    +++ b/ci/test/00_setup_env_native_previous_releases.sh
    @@ -8,9 +8,9 @@ export LC_ALL=C.UTF-8
     
     export CONTAINER_NAME=ci_native_previous_releases
     export CI_IMAGE_NAME_TAG="docker.io/ubuntu:22.04"
    -# Use minimum supported python3.10 and gcc-11, see doc/dependencies.md
    -export PACKAGES="gcc-11 g++-11 python3-zmq"
    -export DEP_OPTS="DEBUG=1 CC=gcc-11 CXX=g++-11"
    +# Use minimum supported python3.10 and gcc-12, see doc/dependencies.md
    +export PACKAGES="gcc-12 g++-12 python3-zmq"
    +export DEP_OPTS="DEBUG=1 CC=gcc-12 CXX=g++-12"
     export TEST_RUNNER_EXTRA="--previous-releases --coverage --extended --exclude feature_dbcrash"  # Run extended tests so that coverage does not fail, but exclude the very slow dbcrash
     export RUN_UNIT_TESTS_SEQUENTIAL="true"
     export RUN_UNIT_TESTS="false"
    
    [  4%] Building CXX object src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.o
    cd /ci_container_base/ci/scratch/build-x86_64-pc-linux-gnu/src && /usr/bin/ccache /usr/bin/g++-12 -DABORT_ON_FAILED_ASSUME -DDEBUG -DDEBUG_LOCKCONTENTION -DDEBUG_LOCKORDER -DRPC_DOC_CHECK -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -I/ci_container_base/ci/scratch/build-x86_64-pc-linux-gnu/src -I/ci_container_base/src -I/ci_container_base/src/secp256k1/include -funsigned-char -g0 -O2 -fPIC -fvisibility=hidden -fno-extended-identifiers -fdebug-prefix-map=/ci_container_base/src=. -fmacro-prefix-map=/ci_container_base/src=. -fstack-reuse=none -Werror -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wno-unused-parameter -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -std=c++20 -MD -MT src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.o -MF CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.o.d -o CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.o -c /ci_container_base/src/pubkey.cpp -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE 
    In file included from /usr/include/c++/12/debug/stl_iterator.h:32,
                     from /usr/include/c++/12/bits/stl_iterator.h:2623,
                     from /usr/include/c++/12/string:47,
                     from /ci_container_base/src/crypto/sha256.h:10,
                     from /ci_container_base/src/hash.h:12,
                     from /ci_container_base/src/pubkey.h:10,
                     from /ci_container_base/src/pubkey.cpp:6:
    /ci_container_base/src/pubkey.cpp:195:116:   in ‘constexpr’ expansion of ‘std::span<const unsigned char>(util::hex_literals::operator""_hex_u8<util::detail::Hex<65>{std::array<std::byte, 32>{std::__array_traits<std::byte, 32>::_Type{(std::byte)80, (std::byte)146, (std::byte)155, (std::byte)116, (std::byte)193, (std::byte)160, (std::byte)73, (std::byte)84, (std::byte)183, (std::byte)139, (std::byte)75, (std::byte)96, (std::byte)53, (std::byte)233, (std::byte)122, (std::byte)94, (std::byte)7, (std::byte)138, (std::byte)90, (std::byte)15, (std::byte)40, (std::byte)236, (std::byte)150, (std::byte)213, (std::byte)71, (std::byte)191, (std::byte)238, (std::byte)154, (std::byte)206, (std::byte)128, (std::byte)58, (std::byte)192}}}>())’
    /usr/include/c++/12/span:200:57:   in ‘constexpr’ expansion of ‘((std::span<const unsigned char>*)this)->std::span<const unsigned char>::span<const unsigned char*>((& __arr)->std::array<unsigned char, 32>::data(), 32)’
    /usr/include/c++/12/span:163:4:   in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range<const unsigned char*>(__first, (__first + ((sizetype)__count)))’
    /usr/include/c++/12/debug/helper_functions.h:257:31:   in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (_Integral(), _Integral()))’
    /usr/include/c++/12/debug/helper_functions.h:189:31:   in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (std::__iterator_category<const unsigned char*>(__first), std::iterator_traits<const unsigned char*>::iterator_category()))’
    /usr/include/c++/12/debug/helper_functions.h:176:19:   in ‘constexpr’ expansion of ‘__gnu_debug::__valid_range_aux<const unsigned char*>(__first, __last, (std::input_iterator_tag(), std::input_iterator_tag()))’
    /usr/include/c++/12/debug/helper_functions.h:136:20: error: ‘(((std::array<unsigned char, 32>::const_pointer)(&<anonymous>.std::array<unsigned char, 32>::_M_elems)) == 0)’ is not a constant expression
      136 |     { return __ptr == 0; }
          |              ~~~~~~^~~~
    gmake[2]: *** [src/CMakeFiles/bitcoin_consensus.dir/build.make:160: src/CMakeFiles/bitcoin_consensus.dir/pubkey.cpp.o] Error 1
    gmake[2]: Leaving directory '/ci_container_base/ci/scratch/build-x86_64-pc-linux-gnu'
    gmake[1]: *** [CMakeFiles/Makefile2:786: src/CMakeFiles/bitcoin_consensus.dir/all] Error 2
    gmake[1]: Leaving directory '/ci_container_base/ci/scratch/build-x86_64-pc-linux-gnu'
    gmake: *** [Makefile:146: all] Error 2
    
  8. maflcko added the label Tests on Dec 10, 2024
  9. maflcko added the label CI failed on Dec 10, 2024
  10. maflcko commented at 7:18 AM on December 12, 2024: member

    Fixed in gcc-15. There may be backports to 12-14, but I wouldn't count on it.

  11. maflcko closed this on Dec 12, 2024

  12. maflcko commented at 11:20 AM on December 17, 2024: member
  13. fanquake referenced this in commit af65fd1a33 on May 20, 2025
  14. bitcoin locked this on Dec 17, 2025

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