Merge bitcoin/bitcoin#34546: kernel: Avoid duplicating symbols in the kernel library

eafd530d20326a101be672243de68a67161ef83e kernel: avoid potential duplicate object in shared library/binary (Cory Fields)
24c3b47010036d67e6d777d9aa37ae3ef8146254 build: add kernel-specific warnings (Cory Fields)

Pull request description:

  This is a revival of https://github.com/bitcoin/bitcoin/pull/31807

  Introduces the [-Wunique-object-duplication](https://clang.llvm.org/docs/DiagnosticsReference.html#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.

ACKs for top commit:
  fanquake:
    ACK eafd530d20326a101be672243de68a67161ef83e
  hebasto:
    ACK eafd530d20326a101be672243de68a67161ef83e.

Tree-SHA512: 81961b50f0268dbe076497e130857f5b4b9151c748d107ec15158d1511dd25bce745e0beeb127b9cea51cb2edd78032735600606a75f7ff8a3fd572acced42e0
This commit is contained in:
merge-script 2026-02-13 11:11:14 +00:00
commit 309c51d89d
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
3 changed files with 24 additions and 6 deletions

View File

@ -83,9 +83,25 @@ add_library(bitcoinkernel
$<TARGET_OBJECTS:leveldb>
$<TARGET_OBJECTS:crc32c>
)
# 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
$<$<PLATFORM_ID:Windows>:bcrypt>
$<TARGET_NAME_IF_EXISTS:USDT::headers>

View File

@ -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;
}

View File

@ -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<LockedPageAllocator> allocator);