From 1a27d92f5f4b91bb44f56fff6df4fc6d04911717 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Tue, 20 Oct 2026 23:30:58 -0700 Subject: [PATCH] poco: Fix libatomic detection with optimized builds CheckAtomic.cmake tests whether libatomic is needed with a program that loads from a local std::atomic. With -O2 clang folds the load away, so the check passes on riscv32 even though 64-bit atomics need libatomic, and linking fails later: ld.lld: error: undefined reference: __atomic_fetch_add_8 ld.lld: error: undefined symbol: __atomic_load_8 Add a patch that makes the test programs use a global atomic with a read-modify-write operation so they cannot be optimized away. AI-Generated: Uses Claude Code Signed-off-by: Khem Raj --- ...-atomic-test-programs-from-being-opt.patch | 62 +++++++++++++++++++ meta-oe/recipes-support/poco/poco_1.15.4.bb | 1 + 2 files changed, 63 insertions(+) create mode 100644 meta-oe/recipes-support/poco/poco/0004-CheckAtomic-Keep-atomic-test-programs-from-being-opt.patch diff --git a/meta-oe/recipes-support/poco/poco/0004-CheckAtomic-Keep-atomic-test-programs-from-being-opt.patch b/meta-oe/recipes-support/poco/poco/0004-CheckAtomic-Keep-atomic-test-programs-from-being-opt.patch new file mode 100644 index 0000000000..0cc17d7dbb --- /dev/null +++ b/meta-oe/recipes-support/poco/poco/0004-CheckAtomic-Keep-atomic-test-programs-from-being-opt.patch @@ -0,0 +1,62 @@ +From: Khem Raj +Date: Tue, 20 Oct 2026 23:30:00 -0700 +Subject: [PATCH] CheckAtomic: Keep atomic test programs from being optimized + away + +The libatomic checks load from a local std::atomic that never escapes. +When CMAKE_CXX_FLAGS contain -O2, as distro builds usually do, clang +folds the load to a constant, so the test program links without +libatomic even on targets that need it for 64-bit atomics, such as +riscv32. Poco_ATOMIC_LIBRARIES then stays empty and the build fails +later when linking against PocoFoundation: + + ld.lld: error: undefined reference: __atomic_fetch_add_8 + ld.lld: error: undefined symbol: __atomic_load_8 + +Make the atomic variables global and modify them with a +read-modify-write operation that depends on argc, so the compiler has +to emit the atomic operations at any optimization level. + +Upstream-Status: Submitted [https://github.com/pocoproject/poco/pull/5585] +Signed-off-by: Khem Raj +--- + cmake/CheckAtomic.cmake | 18 ++++++++++++------ + 1 file changed, 12 insertions(+), 6 deletions(-) + +--- a/cmake/CheckAtomic.cmake ++++ b/cmake/CheckAtomic.cmake +@@ -8,12 +8,17 @@ + + # MSVC and Apple don't ship/need a separate libatomic. + if(NOT MSVC AND NOT APPLE) ++ # The atomic variables in the test programs are global and modified with ++ # a read-modify-write operation, otherwise the compiler can fold them away ++ # when optimizing and the check passes even though libatomic is needed. ++ + # 1) 32-bit atomics + check_cxx_source_compiles(" + #include +- int main() { +- std::atomic x(0); +- return x.load(std::memory_order_relaxed); ++ std::atomic x(0); ++ int main(int argc, char **) { ++ x.fetch_add(argc); ++ return x.load(); + } + " POCO_HAVE_CXX_ATOMICS32) + +@@ -28,9 +33,10 @@ + check_cxx_source_compiles(" + #include + #include +- int main() { +- std::atomic x(0); +- return (int)x.load(std::memory_order_relaxed); ++ std::atomic x(0); ++ int main(int argc, char **) { ++ x.fetch_add(static_cast(argc)); ++ return static_cast(x.load()); + } + " POCO_HAVE_CXX_ATOMICS64) + diff --git a/meta-oe/recipes-support/poco/poco_1.15.4.bb b/meta-oe/recipes-support/poco/poco_1.15.4.bb index f4c572d4ae..0751165267 100644 --- a/meta-oe/recipes-support/poco/poco_1.15.4.bb +++ b/meta-oe/recipes-support/poco/poco_1.15.4.bb @@ -12,6 +12,7 @@ SRC_URI = "git://github.com/pocoproject/poco.git;branch=poco-${PV};protocol=http file://0001-cppignore.lnx-Ignore-PKCS12-and-testLaunch-test.patch \ file://0002-DataTest-disable-testSQLChannel-test.patch \ file://0003-quill-rdtsc-fallback-for-32-bit-powerpc.patch \ + file://0004-CheckAtomic-Keep-atomic-test-programs-from-being-opt.patch \ file://run-ptest \ " SRCREV = "6a5667f432e1c5fe5591025ab03a2f8df37116b4"