From 24c3b47010036d67e6d777d9aa37ae3ef8146254 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 5 Feb 2025 18:28:30 +0000 Subject: [PATCH 1/2] 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. --- src/kernel/CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index f30ccce388a..244f0098fdf 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -83,9 +83,25 @@ add_library(bitcoinkernel $ $ ) + +# Compiler warnings that apply only to the kernel and its dependencies. +# These can be more strict and/or warnings that only apply to shared +# libs. +add_library(kernel_warn_interface INTERFACE) +if(NOT MSVC) + try_append_cxx_flags("-Wunique-object-duplication" TARGET kernel_warn_interface SKIP_LINK) +endif() + +# Also manually apply the warnings to the kernel's internal dependencies +target_link_libraries(bitcoin_clientversion PRIVATE kernel_warn_interface) +target_link_libraries(bitcoin_crypto PRIVATE kernel_warn_interface) +target_link_libraries(leveldb PRIVATE kernel_warn_interface) +target_link_libraries(crc32c PRIVATE kernel_warn_interface) + target_link_libraries(bitcoinkernel PRIVATE core_interface + kernel_warn_interface secp256k1_objs $<$:bcrypt> $ From eafd530d20326a101be672243de68a67161ef83e Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 5 Feb 2025 18:27:23 +0000 Subject: [PATCH 2/2] 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] --- src/support/lockedpool.cpp | 7 +++++++ src/support/lockedpool.h | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/support/lockedpool.cpp b/src/support/lockedpool.cpp index cbb117fc3e1..ff3a9e69c58 100644 --- a/src/support/lockedpool.cpp +++ b/src/support/lockedpool.cpp @@ -399,3 +399,10 @@ void LockedPoolManager::CreateInstance() static LockedPoolManager instance(std::move(allocator)); LockedPoolManager::_instance = &instance; } + +LockedPoolManager& LockedPoolManager::Instance() +{ + static std::once_flag init_flag; + std::call_once(init_flag, LockedPoolManager::CreateInstance); + return *LockedPoolManager::_instance; +} diff --git a/src/support/lockedpool.h b/src/support/lockedpool.h index 7be20823fbf..c4966bbbbea 100644 --- a/src/support/lockedpool.h +++ b/src/support/lockedpool.h @@ -219,12 +219,7 @@ class LockedPoolManager : public LockedPool { public: /** Return the current instance, or create it once */ - static LockedPoolManager& Instance() - { - static std::once_flag init_flag; - std::call_once(init_flag, LockedPoolManager::CreateInstance); - return *LockedPoolManager::_instance; - } + static LockedPoolManager& Instance(); private: explicit LockedPoolManager(std::unique_ptr allocator);