kernel: Avoid duplicating symbols in the kernel library #34546

pull sedited wants to merge 2 commits into bitcoin:master from sedited:warn_dupe_symbols changing 3 files +24 −6
  1. sedited commented at 9:35 am on February 10, 2026: contributor

    This is a revival of #31807

    Introduces the -Wunique-object-duplication warning flag available in clang-21 for usage when building the kernel library. It warns of potential duplicate objects in shared libraries. REDUCE_EXPORTS needs to be ON to trigger it.

    Though we have a C API now that manages exporting symbols, I think it is prudent to also avoid any duplicate symbols on the internal c++ side in case we ever to decide to expose some of its headers. It also not clear that all linkers would handle these cases correctly even in the current internal usage.

  2. DrahtBot added the label Validation on Feb 10, 2026
  3. DrahtBot commented at 9:35 am on February 10, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, fanquake
    Approach ACK w0xlt
    Stale ACK theuni

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #28690 (build: Introduce internal kernel library by sedited)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. ?
    added_to_project_v2 fanquake
  5. ?
    project_v2_item_status_changed github-project-automation[bot]
  6. w0xlt commented at 5:55 pm on February 10, 2026: contributor
    Approach ACK
  7. theuni commented at 6:29 pm on February 10, 2026: member

    Sorry for losing track of the other PR, and thanks for picking it up.

    ACK 289f1203510223430c8768d4d2ebe79f971f917c.

    I’m curious to see if any of our c-i would currently pick this up. Any interest in popping off the “fix” commit as a test?

  8. hebasto commented at 0:39 am on February 11, 2026: member
    Concept ACK.
  9. hebasto commented at 1:03 am on February 11, 2026: member
    I’ve reverted 289f1203510223430c8768d4d2ebe79f971f917c with the expectation of reproducing the -Wunique-object-duplication using Clang 21.1.8. However, no warnings were observed. Could you provide the exact reproduction steps please?
  10. in src/kernel/CMakeLists.txt:92 in 289f120351
    87+# Compiler warnings that apply only to the kernel and its dependencies.
    88+# These can be more strict and/or warnings that only apply to shared
    89+# libs.
    90+add_library(kernel_warn_interface INTERFACE)
    91+if(MSVC)
    92+else()
    


    hebasto commented at 1:10 am on February 11, 2026:
    1. Why not
    0if(NOT MSVC)
    

    ?

    1. Since the MSVC variable is true for both cl.exe and clang-cl.exe, I propose using CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" to explicitly exclude clang-cl, consistent with #31507.

    fanquake commented at 11:49 am on February 11, 2026:
    I think that can just be done in #31507, if needed.
  11. sedited commented at 6:55 am on February 11, 2026: contributor

    However, no warnings were observed. Could you provide the exact reproduction steps please?

    I’m guessing you did not use REDUCE_EXPORTS? I mention it in the commit message, will add to PR descritpion.

    I’m curious to see if any of our c-i would currently pick this up. Any interest in popping off the “fix” commit as a test?

    Doesn’t look like it: https://github.com/sedited/bitcoin/tree/warn_dupe_symbols_no_patch

  12. hebasto commented at 7:58 am on February 11, 2026: member

    However, no warnings were observed. Could you provide the exact reproduction steps please?

    I’m guessing you did not use REDUCE_EXPORTS? I mention it in the commit message, will add to PR descritpion.

    Indeed. Thanks!

    I’m curious to see if any of our c-i would currently pick this up. Any interest in popping off the “fix” commit as a test?

    Doesn’t look like it: https://github.com/sedited/bitcoin/tree/warn_dupe_symbols_no_patch

    Then maybe we should use -DREDUCE_EXPORTS=ON in some job, say “tidy”?

  13. sedited commented at 8:14 am on February 11, 2026: contributor

    Then maybe we should use -DREDUCE_EXPORTS=ON in some job, say “tidy”?

    We do have REDUCE_EXPORTS=ON on a bunch of them, but maybe none of them use clang-21? Not sure if the tidy job is the best choice for this though, cc @maflcko.

  14. sedited commented at 11:16 am on February 11, 2026: contributor

    Then maybe we should use -DREDUCE_EXPORTS=ON in some job, say “tidy”?

    Doing so would indeed trigger the warning in the CI: https://github.com/sedited/bitcoin/actions/runs/21897419740/job/63218273428

  15. maflcko commented at 1:46 pm on February 11, 2026: member

    Not sure if tidy is the right choice, given that there is effort to remove the compilation from it? (https://github.com/bitcoin/bitcoin/pull/32953)

    Maybe one of the other tasks?

    0ci/test/00_setup_env_native_asan.sh:export APT_LLVM_V="21"
    1ci/test/00_setup_env_native_fuzz.sh:export APT_LLVM_V="21"
    2ci/test/00_setup_env_native_fuzz_with_msan.sh:export APT_LLVM_V="21"
    3ci/test/00_setup_env_native_msan.sh:export APT_LLVM_V="21"
    4ci/test/00_setup_env_native_tsan.sh:export APT_LLVM_V="21"
    

    I guess -Wunique-object-duplication doesn’t care about sanitizers during the build?

  16. theuni commented at 1:53 pm on February 11, 2026: member

    I’m curious to see if any of our c-i would currently pick this up. Any interest in popping off the “fix” commit as a test?

    This was a fleeting thought, I don’t think it’s worth worrying too much about unless there’s some future where we’re actually shipping c++ headers.

  17. fanquake requested review from stickies-v on Feb 11, 2026
  18. in src/kernel/CMakeLists.txt:99 in 289f120351 outdated
    94+endif()
    95+
    96+# Also manually apply the warnings to the kernel's internal dependencies
    97+target_link_libraries(bitcoin_clientversion PRIVATE kernel_warn_interface)
    98+target_link_libraries(bitcoin_crypto PRIVATE kernel_warn_interface)
    99+target_link_libraries(leveldb PRIVATE kernel_warn_interface)
    


    hebasto commented at 4:42 pm on February 11, 2026:
    Why is crc32c missed here?

    theuni commented at 5:05 pm on February 11, 2026:
    Good catch!

    sedited commented at 2:54 pm on February 12, 2026:
    Mmh, does this even work? I don’t think the flags are propagating correctly like this. Should we just add them unconditionally to these libraries?

    w0xlt commented at 11:54 pm on February 12, 2026:

    I don’t think the flags are propagating correctly like this.

    core_interface works similar throughout the build system (e.g., target_link_libraries(crc32c PRIVATE core_interface) in cmake/crc32c.cmake.


    sedited commented at 7:57 am on February 13, 2026:
    Posted that while afk. Yes, this seems correct to me.

    hebasto commented at 9:54 am on February 13, 2026:
    The most straightforward way to ensure it works is to observe compiler invocations in --verbose mode.
  19. hebasto approved
  20. hebasto commented at 4:42 pm on February 11, 2026: member

    ACK 289f1203510223430c8768d4d2ebe79f971f917c.

    Happy to re-ACK, once the first nit in #34546 (review) is addressed.

  21. DrahtBot requested review from w0xlt on Feb 12, 2026
  22. build: add kernel-specific warnings
    In some cases, we'll want to be more aggressive or care about different things
    when building the kernel. In this case, a warning is added for symbols which
    may be duplicated between the kernel and downstream users.
    
    This warning was introduced in clang 21, which is not yet the minimum
    supported compiler version. REDUCE_EXPORTS needs to be ON to trigger it.
    24c3b47010
  23. kernel: avoid potential duplicate object in shared library/binary
    Fixes warning and potential bug whereby init_flag may exist in both
    libbitcoinkernel as well as a downstream user, as opposed to being shared as
    intended.
    
    src/support/lockedpool.h:224:31:
    warning: 'init_flag' may be duplicated when built into a shared library: it is mutable, has hidden visibility, and external linkage [-Wunique-object-duplication]
    eafd530d20
  24. sedited force-pushed on Feb 13, 2026
  25. sedited commented at 8:01 am on February 13, 2026: contributor

    Updated 289f1203510223430c8768d4d2ebe79f971f917c -> eafd530d20326a101be672243de68a67161ef83e (warn_dupe_symbols_0 -> warn_dupe_symbols_1, compare)

  26. bitcoin deleted a comment on Feb 13, 2026
  27. hebasto approved
  28. hebasto commented at 9:52 am on February 13, 2026: member
    ACK eafd530d20326a101be672243de68a67161ef83e.
  29. DrahtBot requested review from theuni on Feb 13, 2026
  30. fanquake commented at 10:35 am on February 13, 2026: member

    Guix Build (aarch64):

     02b0b06d073a1e554f2536bbe577df265a0f2542e8bb08e37de4d35e06b10707b  guix-build-eafd530d2032/output/aarch64-linux-gnu/SHA256SUMS.part
     12d4ebc2def626a5d33c5c5398b873a0fcc62624a27dc138e05638ad8ee8a0a50  guix-build-eafd530d2032/output/aarch64-linux-gnu/bitcoin-eafd530d2032-aarch64-linux-gnu-debug.tar.gz
     24c3d9286321d348da2eeeb39a6e3ab65d7315056b8e522bc6ac5091de2e10116  guix-build-eafd530d2032/output/aarch64-linux-gnu/bitcoin-eafd530d2032-aarch64-linux-gnu.tar.gz
     36f0cd34783382d1efc2f266c8e70a0f88559032e78cf6f1969fad9feb5727022  guix-build-eafd530d2032/output/arm-linux-gnueabihf/SHA256SUMS.part
     4ebc4f3c50faeb719c924cfb81548ab94c47b1240f67c7aab416a99e8eade9c36  guix-build-eafd530d2032/output/arm-linux-gnueabihf/bitcoin-eafd530d2032-arm-linux-gnueabihf-debug.tar.gz
     5c78af85374e91767fb8be27128cdc41132681d9040a694760ef2a7a38bb44723  guix-build-eafd530d2032/output/arm-linux-gnueabihf/bitcoin-eafd530d2032-arm-linux-gnueabihf.tar.gz
     67e7fd8fc7329d260434fd61d7528ec6630ce76d2459a24cbf2f04ee869c79f6b  guix-build-eafd530d2032/output/arm64-apple-darwin/SHA256SUMS.part
     791c87a7d0fd6deee8c6fdaff6f942e2627d0a1f8a9c807896abec7206d0fc2b9  guix-build-eafd530d2032/output/arm64-apple-darwin/bitcoin-eafd530d2032-arm64-apple-darwin-codesigning.tar.gz
     81cfc74c139a6eb2d464630bfddd50e0ef37855fe1f732ba2df384e0c48fbdc74  guix-build-eafd530d2032/output/arm64-apple-darwin/bitcoin-eafd530d2032-arm64-apple-darwin-unsigned.tar.gz
     9d69a1e005ed0a470ba3e2023b5a1bb750be57fa03d9bf26b3024ecf3bcedcf87  guix-build-eafd530d2032/output/arm64-apple-darwin/bitcoin-eafd530d2032-arm64-apple-darwin-unsigned.zip
    1085e35c4dad56b628c9d754e03dbb2e5d9f4108565d1574980a1db8ac9a83a3c5  guix-build-eafd530d2032/output/dist-archive/bitcoin-eafd530d2032.tar.gz
    11a65a4ffde35aafea7364ac04af5cd3ad3907a1875cca797ca65c776846a4ec36  guix-build-eafd530d2032/output/powerpc64-linux-gnu/SHA256SUMS.part
    1281f1a235820cd2c0a365a03c93a513970a3e15d540d083a9a485ff4524ba3a5b  guix-build-eafd530d2032/output/powerpc64-linux-gnu/bitcoin-eafd530d2032-powerpc64-linux-gnu-debug.tar.gz
    13096b2a85b202e20a593e7091ff5a91878db1eae302c20d61f450af521c4f9b58  guix-build-eafd530d2032/output/powerpc64-linux-gnu/bitcoin-eafd530d2032-powerpc64-linux-gnu.tar.gz
    140bd6953a171960de00036ad767ee045036beddd825240db06572812270533636  guix-build-eafd530d2032/output/riscv64-linux-gnu/SHA256SUMS.part
    152b25c4a94330bd9e5bfa16cadbe6982dfe6b5d7778c1c592376ceedee4cb2997  guix-build-eafd530d2032/output/riscv64-linux-gnu/bitcoin-eafd530d2032-riscv64-linux-gnu-debug.tar.gz
    16ec9e34151d3b61885ab67270e0f654416bb9b301995953168844a4b9c547d17d  guix-build-eafd530d2032/output/riscv64-linux-gnu/bitcoin-eafd530d2032-riscv64-linux-gnu.tar.gz
    177df686a97de1f54efc5fc2184fd6a0566241c62d4600bcddb24bdaa1f31765df  guix-build-eafd530d2032/output/x86_64-apple-darwin/SHA256SUMS.part
    18725058e64f4d886c360a15724471f9ad292d96a6dc389559f354cb2bc48c0546  guix-build-eafd530d2032/output/x86_64-apple-darwin/bitcoin-eafd530d2032-x86_64-apple-darwin-codesigning.tar.gz
    19f7fc090c0bf236c77b6c06d154d040146b1fbedd2a6a9dfbe23b770cd0e22e02  guix-build-eafd530d2032/output/x86_64-apple-darwin/bitcoin-eafd530d2032-x86_64-apple-darwin-unsigned.tar.gz
    20d7d643a7948656088b91ed8514a211c4349e9b80e91d007bd3f2a06bba278818  guix-build-eafd530d2032/output/x86_64-apple-darwin/bitcoin-eafd530d2032-x86_64-apple-darwin-unsigned.zip
    21d1aa947737baec627877e066d56b9cd89b8767fd9c06585f54758cea4dc725b5  guix-build-eafd530d2032/output/x86_64-linux-gnu/SHA256SUMS.part
    22b72e8a0aa581fcd2bd6a32084c6d8a458b820062a02f5da2aafad14d6191258d  guix-build-eafd530d2032/output/x86_64-linux-gnu/bitcoin-eafd530d2032-x86_64-linux-gnu-debug.tar.gz
    2372c155075b2cb4d195fb0451f156fc529bcd31e7601041d3e351a1ccaad8823f  guix-build-eafd530d2032/output/x86_64-linux-gnu/bitcoin-eafd530d2032-x86_64-linux-gnu.tar.gz
    2434ea26e1ce31de034109a55ed57ef406c8e715a6484d5f775e474976625658ba  guix-build-eafd530d2032/output/x86_64-w64-mingw32/SHA256SUMS.part
    255b1905e430741bedc70896d38b07921767781a98eb22de01a2b48f88aaa881c2  guix-build-eafd530d2032/output/x86_64-w64-mingw32/bitcoin-eafd530d2032-win64-codesigning.tar.gz
    26877c560bbd385faa234d18d109e24474a78545e117c7933c109753f9339dfcce  guix-build-eafd530d2032/output/x86_64-w64-mingw32/bitcoin-eafd530d2032-win64-debug.zip
    27f10863f0290daf8d6219d015e9faf30e0e9343917c992b132645c24567b00e91  guix-build-eafd530d2032/output/x86_64-w64-mingw32/bitcoin-eafd530d2032-win64-setup-unsigned.exe
    28bd770470970005be75fa81ae69d1652c64827d968fc1bb9cc5db28b0d50de8fc  guix-build-eafd530d2032/output/x86_64-w64-mingw32/bitcoin-eafd530d2032-win64-unsigned.zip
    
  31. fanquake commented at 10:36 am on February 13, 2026: member
    ACK eafd530d20326a101be672243de68a67161ef83e
  32. fanquake merged this on Feb 13, 2026
  33. fanquake closed this on Feb 13, 2026

  34. ?
    project_v2_item_status_changed github-project-automation[bot]

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-02-17 06:13 UTC

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