bench: fix `InputType` ODR violation #36966

pull fanquake wants to merge 2 commits into bitcoin:master from fanquake:bench_odr_anon_namespace changing 3 files +7 −1
  1. fanquake commented at 3:01 PM on November 24, 2026: member

    Introduced in #36475:

    /ci_container_base/src/bench/bip352.cpp:22:12: error: type ‘InputType’ violates the C++ One Definition Rule [-Werror=odr]
       22 | enum class InputType {
          |            ^
    /ci_container_base/src/bench/sign_transaction.cpp:24:12: note: an enum with different value name is defined in another translation unit
       24 | enum class InputType {
          |            ^
    /ci_container_base/src/bench/bip352.cpp:23:5: note: name ‘P2PKH’ differs from name ‘P2WPKH’ defined in another translation unit
       23 |     P2PKH,           // legacy pubkey-hash
          |     ^
    /ci_container_base/src/bench/sign_transaction.cpp:25:5: note: mismatching definition
       25 |     P2WPKH, // segwitv0, witness-pubkey-hash (ECDSA signature)
          |     ^
    

    There's a commit here that adds a CI config, using GCC and LTO, which uses -Wodr. The existing LTO config uses Clang, and I'm not sure about adding LTO to any existing job. However I do think we should be catching ODR violations in CI.

  2. DrahtBot added the label Tests on Nov 24, 2026
  3. DrahtBot commented at 3:01 PM on November 24, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK maflcko, hebasto

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. DrahtBot added the label CI failed on Nov 24, 2026
  5. in ci/test/00_setup_env_native_gcc_lto.sh:16 in 9f9c5b9349 outdated
      11 | +export PIP_PACKAGES="--break-system-packages pycapnp"
      12 | +export NO_DEPENDS=1
      13 | +printf -v BITCOIN_CONFIG "%q " \
      14 | + --preset=dev-mode \
      15 | + -DREDUCE_EXPORTS=ON \
      16 | + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
    


    maflcko commented at 4:05 PM on November 24, 2026:

    Could add to the ci/test/00_setup_env_native_alpine_musl.sh, which already uses gcc and more likely will be using a more recent gcc than some Ubuntu LTS?


    fanquake commented at 4:46 PM on November 24, 2026:

    Looks like they are currently using the same version (15.2.0). I can push that up to compare runtime to master.


    fanquake commented at 5:36 PM on November 24, 2026:

    20 minutes uncached seems reasonable. Have dropped the other config, if we're happy adding this to Alpine.

  6. DrahtBot removed the label CI failed on Nov 24, 2026
  7. bench: put InputType enums in anonymous namespaces
    Fixes an ODR violation.
    307b22b59d
  8. fanquake force-pushed on Nov 24, 2026
  9. ci: add CMAKE_INTERPROCEDURAL_OPTIMIZATION to Alpine job 66654bc5ce
  10. fanquake force-pushed on Nov 24, 2026
  11. in ci/test/00_setup_env_native_alpine_musl.sh:18 in 66654bc5ce
      12 | @@ -13,7 +13,9 @@ export DEP_OPTS="DEBUG=1"
      13 |  printf -v BITCOIN_CONFIG "%q " \
      14 |   --preset=dev-mode \
      15 |   -DREDUCE_EXPORTS=ON \
      16 | - -DCMAKE_BUILD_TYPE=Debug
      17 | + -DCMAKE_BUILD_TYPE=Debug \
      18 | + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
      19 | + -DCMAKE_LINK_WARNING_AS_ERROR=ON
    


    maflcko commented at 6:14 AM on November 25, 2026:

    maybe in a new commit: Should this be enabled globally in CI like:

    ci/test/03_test_script.sh:98:BITCOIN_CONFIG_ALL=(-DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_INSTALL_PREFIX="$BASE_OUTDIR" -Werror=dev)
    .github/ci-test-each-commit-exec.py:41:        "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
    .github/ci-windows.py:32:        "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
    .github/ci-windows.py:38:        "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
    

    fanquake commented at 9:06 AM on November 25, 2026:

    Yea. We could add -DCMAKE_LINK_WARNING_AS_ERROR=ON to jobs with CMake 4.0+, just need to avoid the macOS cross jobs due to upstream bugs: #35756 (comment).


    maflcko commented at 9:33 AM on November 25, 2026:

    Ok, I see. Let's wait for the upstream bug to be fixed first and then just add -DCMAKE_LINK_WARNING_AS_ERROR=ON globally? IIUC older cmake will just ignore it, which should be fine to avoid the verbosity here of having to place it in every ci task one-by-one?

  12. maflcko approved
  13. maflcko commented at 7:01 AM on November 25, 2026: member

    lgtm. Tested:

    [ 64%] Linking CXX executable ../../bin/bench_bitcoin
    cd "/ci_container_base/ci/scratch_ ₿🧪_/build-x86_64-pc-linux-musl/src/bench" && /usr/bin/cmake -E cmake_link_script CMakeFiles/bench_bitcoin.dir/link.txt --verbose=1
    /usr/bin/g++ -O0 -ftrapv -O1 -g3 -g3 -flto=auto -fno-fat-lto-objects -fstack-reuse=none -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wl,-z,relro -Wl,-z,now -Wl,-z,separate-code -Wl,--exclude-libs,ALL -fPIE -pie -Werror -Wl,--fatal-warnings -Wl,--dependency-file=CMakeFiles/bench_bitcoin.dir/link.d CMakeFiles/bench_bitcoin.dir/bench_bitcoin.cpp.o CMakeFiles/bench_bitcoin.dir/bench.cpp.o CMakeFiles/bench_bitcoin.dir/nanobench.cpp.o CMakeFiles/bench_bitcoin.dir/addrman.cpp.o CMakeFiles/bench_bitcoin.dir/base58.cpp.o CMakeFiles/bench_bitcoin.dir/bech32.cpp.o CMakeFiles/bench_bitcoin.dir/bip324_ecdh.cpp.o CMakeFiles/bench_bitcoin.dir/bip352.cpp.o CMakeFiles/bench_bitcoin.dir/block_assemble.cpp.o CMakeFiles/bench_bitcoin.dir/blockencodings.cpp.o CMakeFiles/bench_bitcoin.dir/ccoins_caching.cpp.o CMakeFiles/bench_bitcoin.dir/chacha20.cpp.o CMakeFiles/bench_bitcoin.dir/checkblock.cpp.o CMakeFiles/bench_bitcoin.dir/checkblockindex.cpp.o CMakeFiles/bench_bitcoin.dir/checkqueue.cpp.o CMakeFiles/bench_bitcoin.dir/cluster_linearize.cpp.o CMakeFiles/bench_bitcoin.dir/connectblock.cpp.o CMakeFiles/bench_bitcoin.dir/crypto_hash.cpp.o CMakeFiles/bench_bitcoin.dir/descriptors.cpp.o CMakeFiles/bench_bitcoin.dir/disconnected_transactions.cpp.o CMakeFiles/bench_bitcoin.dir/duplicate_inputs.cpp.o CMakeFiles/bench_bitcoin.dir/ellswift.cpp.o CMakeFiles/bench_bitcoin.dir/examples.cpp.o CMakeFiles/bench_bitcoin.dir/gcs_filter.cpp.o CMakeFiles/bench_bitcoin.dir/hashpadding.cpp.o CMakeFiles/bench_bitcoin.dir/index_blockfilter.cpp.o CMakeFiles/bench_bitcoin.dir/load_external.cpp.o CMakeFiles/bench_bitcoin.dir/lockedpool.cpp.o CMakeFiles/bench_bitcoin.dir/logging.cpp.o CMakeFiles/bench_bitcoin.dir/mempool_ephemeral_spends.cpp.o CMakeFiles/bench_bitcoin.dir/mempool_eviction.cpp.o CMakeFiles/bench_bitcoin.dir/mempool_stress.cpp.o CMakeFiles/bench_bitcoin.dir/merkle_root.cpp.o CMakeFiles/bench_bitcoin.dir/obfuscation.cpp.o CMakeFiles/bench_bitcoin.dir/parse_hex.cpp.o CMakeFiles/bench_bitcoin.dir/peer_eviction.cpp.o CMakeFiles/bench_bitcoin.dir/poly1305.cpp.o CMakeFiles/bench_bitcoin.dir/pool.cpp.o CMakeFiles/bench_bitcoin.dir/prevector.cpp.o CMakeFiles/bench_bitcoin.dir/random.cpp.o CMakeFiles/bench_bitcoin.dir/readwriteblock.cpp.o CMakeFiles/bench_bitcoin.dir/rollingbloom.cpp.o CMakeFiles/bench_bitcoin.dir/rpc_blockchain.cpp.o CMakeFiles/bench_bitcoin.dir/rpc_mempool.cpp.o CMakeFiles/bench_bitcoin.dir/sign_transaction.cpp.o CMakeFiles/bench_bitcoin.dir/streams_findbyte.cpp.o CMakeFiles/bench_bitcoin.dir/strencodings.cpp.o CMakeFiles/bench_bitcoin.dir/txgraph.cpp.o CMakeFiles/bench_bitcoin.dir/txorphanage.cpp.o CMakeFiles/bench_bitcoin.dir/uint256_blob.cpp.o CMakeFiles/bench_bitcoin.dir/util_time.cpp.o CMakeFiles/bench_bitcoin.dir/verify_script.cpp.o CMakeFiles/bench_bitcoin.dir/asmap.cpp.o CMakeFiles/bench_bitcoin.dir/coin_selection.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_balance.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_create.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_create_tx.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_encrypt.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_loading.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_ismine.cpp.o CMakeFiles/bench_bitcoin.dir/wallet_migration.cpp.o -o ../../bin/bench_bitcoin  ../../lib/libtest_util.a ../../lib/libbitcoin_node.a ../../lib/libbitcoin_wallet.a ../../lib/libbitcoin_zmq.a /ci_container_base/depends/x86_64-pc-linux-musl/lib/libzmq.a ../libleveldb.a ../libcrc32c.a ../libminisketch.a /ci_container_base/depends/x86_64-pc-linux-musl/lib/libsqlite3.a ../../lib/libbitcoin_common.a ../univalue/libunivalue.a ../../lib/libbitcoin_util.a ../../lib/libbitcoin_clientversion.a ../../lib/libbitcoin_consensus.a ../../lib/libbitcoin_crypto.a ../secp256k1/lib/libsecp256k1.a /ci_container_base/src/bench/bip352.cpp:22:12: error: type 'InputType' violates the C++ One Definition Rule [-Werror=odr]
       22 | enum class InputType {
          |            ^
    /ci_container_base/src/bench/sign_transaction.cpp:24:12: note: an enum with different value name is defined in another translation unit
       24 | enum class InputType {
          |            ^
    /ci_container_base/src/bench/bip352.cpp:23:5: note: name 'P2PKH' differs from name 'P2WPKH' defined in another translation unit
       23 |     P2PKH,           // legacy pubkey-hash
          |     ^
    /ci_container_base/src/bench/sign_transaction.cpp:25:5: note: mismatching definition
       25 |     P2WPKH, // segwitv0, witness-pubkey-hash (ECDSA signature)
          |     ^
    lto1: all warnings being treated as errors
    lto-wrapper: fatal error: /usr/bin/g++ returned 1 exit status
    compilation terminated.
    /usr/lib/gcc/x86_64-alpine-linux-musl/15.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: error: lto-wrapper failed
    collect2: error: ld returned 1 exit status
    
    gmake[2]: *** [src/bench/CMakeFiles/bench_bitcoin.dir/build.make:1088: bin/bench_bitcoin] Error 1
    gmake[2]: Leaving directory '/ci_container_base/ci/scratch_ ₿🧪_/build-x86_64-pc-linux-musl'
    gmake[1]: *** [CMakeFiles/Makefile2:3291: src/bench/CMakeFiles/bench_bitcoin.dir/all] Error 2
    gmake[1]: Leaving directory '/ci_container_base/ci/scratch_ ₿🧪_/build-x86_64-pc-linux-musl'
    gmake: *** [Makefile:146: all] Error 2
    
    
  14. maflcko commented at 7:04 AM on November 25, 2026: member

    review ACK 66654bc5ce9b1cf9613346107b9520ad003a68c4 🐨

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: review ACK 66654bc5ce9b1cf9613346107b9520ad003a68c4 🐨
    rqivzpu250VjPa54pZci92+ktdflJMSjPmbQIYdIj2oNmd1//vmWGbnv+pVMFeIRvlcTJudppEVHviEc7ulzBg==
    

    </details>

  15. fanquake requested review from willcl-ark on Nov 25, 2026
  16. hebasto approved
  17. hebasto commented at 10:52 AM on November 25, 2026: member

    ACK 66654bc5ce9b1cf9613346107b9520ad003a68c4, tested on Fedora 45.

    nit: The INTERPROCEDURAL_OPTIMIZATION target property, which CMAKE_INTERPROCEDURAL_OPTIMIZATION initializes, is a CMake abstraction that is designed to be used along with the CheckIPOSupported module. Now that we are about to start using CMAKE_INTERPROCEDURAL_OPTIMIZATION in the regular CI builds, I believe we should add that check to the build system.

    Note: -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON is already used in ci/test/00_setup_env_native_chimera_lto.sh, but that config is not part of the regular CI builds.

  18. hebasto merged this on Nov 25, 2026
  19. hebasto closed this on Nov 25, 2026

  20. fanquake commented at 10:57 AM on November 25, 2026: member

    I believe we should add that check to the build system.

    Can you elaborate? Not sure I'm following in why we need to add more custom checks/machinery to our build system, to just use normal CMake config options? (also not sure why CI use makes a difference here, because the option can be used, and is already being used, by anyone, outside the CI?)

  21. fanquake deleted the branch on Nov 25, 2026
  22. hebasto commented at 11:07 AM on November 25, 2026: member

    I believe we should add that check to the build system.

    Can you elaborate? Not sure I'm following in why we need to add more custom checks/machinery to our build system, to just use normal CMake config options?

    From https://cmake.org/cmake/help/latest/policy/CMP0069.html:

    Use the CheckIPOSupported module to detect whether IPO is supported by the current compiler, environment, and CMake version.

  23. fanquake commented at 11:15 AM on November 25, 2026: member

    From https://cmake.org/cmake/help/latest/policy/CMP0069.html:

    Ok. Seems like the build will error in any case, if someone passes CMAKE_INTERPROCEDURAL_OPTIMIZATION and their compiler doesn't support it, but adding a call to CheckIPOSupported would also cause an error for anyone not using LTO, if their compiler didn't support it (which even if unlikely, I'm not sure we want). Can be discussed in a new PR if needed.


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-12-05 03:51 UTC

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