diff mbox series

[meta-networking,04/29] rdma-core: Link libmana with libatomic when needed

Message ID 20261023065350.3228996-4-khem.raj@oss.qualcomm.com
State New
Headers show
Series [meta-oe,01/29] castxml: upgrade 0.7.0 -> 0.8.0 | expand

Commit Message

Khem Raj Oct. 23, 2026, 6:53 a.m. UTC
libmana uses 64-bit C11 atomics, which riscv32 lowers to
__atomic_load_8/__atomic_store_8 libcalls, so linking libmana fails:

  ld.lld: error: undefined symbol: __atomic_load_8
  ld.lld: error: undefined symbol: __atomic_store_8

Add a patch that checks at configure time whether 64-bit atomics need
libatomic and links libmana with it only in that case.

AI-Generated: Uses Claude Code
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
 ...ibatomic-when-64-bit-atomics-need-it.patch | 69 +++++++++++++++++++
 .../rdma-core/rdma-core_65.0.bb               |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta-networking/recipes-support/rdma-core/rdma-core/0002-mana-Link-with-libatomic-when-64-bit-atomics-need-it.patch
diff mbox series

Patch

diff --git a/meta-networking/recipes-support/rdma-core/rdma-core/0002-mana-Link-with-libatomic-when-64-bit-atomics-need-it.patch b/meta-networking/recipes-support/rdma-core/rdma-core/0002-mana-Link-with-libatomic-when-64-bit-atomics-need-it.patch
new file mode 100644
index 0000000000..6817904790
--- /dev/null
+++ b/meta-networking/recipes-support/rdma-core/rdma-core/0002-mana-Link-with-libatomic-when-64-bit-atomics-need-it.patch
@@ -0,0 +1,69 @@ 
+From: Khem Raj <khem.raj@oss.qualcomm.com>
+Date: Tue, 20 Oct 2026 22:00:00 -0700
+Subject: [PATCH] mana: Link with libatomic when 64-bit atomics need it
+
+shadow_queue.h keeps the producer and consumer indexes in
+_Atomic(uint64_t). On 32-bit targets without native 64-bit atomic
+instructions, such as riscv32, the compiler lowers these to
+__atomic_load_8/__atomic_store_8 libcalls, and libmana fails to link:
+
+  ld.lld: error: undefined symbol: __atomic_load_8
+  ld.lld: error: undefined symbol: __atomic_store_8
+
+Check whether a 64-bit atomic load/store links on its own, and if not,
+whether it links with -latomic. Link libmana with libatomic and add it
+to the libmana.pc private libs only when it is needed, so targets with
+native 64-bit atomics are unchanged.
+
+Upstream-Status: Submitted [https://github.com/linux-rdma/rdma-core/pull/1831]
+Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
+---
+ CMakeLists.txt                | 21 +++++++++++++++++++++
+ providers/mana/CMakeLists.txt |  5 ++++-
+ 2 files changed, 25 insertions(+), 1 deletion(-)
+
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -510,6 +510,27 @@
+   RDMA_DoFixup("${HAVE_STDATOMIC}" "stdatomic.h")
+ endif()
+
++# 64-bit C11 atomics are not lock free on some 32-bit targets (e.g. riscv32)
++# and the compiler emits __atomic_* libcalls that libatomic provides.
++set(ATOMIC64_CHECK_PROGRAM "
++#include <stdatomic.h>
++#include <stdint.h>
++_Atomic(uint64_t) v;
++int main(int argc, const char *argv[]) {
++  atomic_store(&v, (uint64_t)argc);
++  return (int)atomic_load(&v);
++}")
++CHECK_C_SOURCE_COMPILES("${ATOMIC64_CHECK_PROGRAM}" HAVE_ATOMIC64_WITHOUT_LIBATOMIC)
++set(ATOMIC_LIBRARIES "")
++if (NOT HAVE_ATOMIC64_WITHOUT_LIBATOMIC)
++  set(CMAKE_REQUIRED_LIBRARIES "-latomic")
++  CHECK_C_SOURCE_COMPILES("${ATOMIC64_CHECK_PROGRAM}" HAVE_ATOMIC64_WITH_LIBATOMIC)
++  unset(CMAKE_REQUIRED_LIBRARIES)
++  if (HAVE_ATOMIC64_WITH_LIBATOMIC)
++    set(ATOMIC_LIBRARIES "-latomic")
++  endif()
++endif()
++
+ CHECK_INCLUDE_FILE("linux/dma-heap.h" HAVE_LINUX_DMA_HEAP_H)
+
+ RDMA_Check_SSE(HAVE_TARGET_SSE)
+--- a/providers/mana/CMakeLists.txt
++++ b/providers/mana/CMakeLists.txt
+@@ -8,8 +8,11 @@
+   wr.c
+ )
+
++# shadow_queue.h uses 64-bit atomics
++target_link_libraries(mana LINK_PRIVATE ${ATOMIC_LIBRARIES})
++
+ publish_headers(infiniband
+   manadv.h
+ )
+
+-rdma_pkg_config("mana" "libibverbs" "${CMAKE_THREAD_LIBS_INIT}")
++rdma_pkg_config("mana" "libibverbs" "${CMAKE_THREAD_LIBS_INIT} ${ATOMIC_LIBRARIES}")
diff --git a/meta-networking/recipes-support/rdma-core/rdma-core_65.0.bb b/meta-networking/recipes-support/rdma-core/rdma-core_65.0.bb
index a465bda583..39b5690d39 100644
--- a/meta-networking/recipes-support/rdma-core/rdma-core_65.0.bb
+++ b/meta-networking/recipes-support/rdma-core/rdma-core_65.0.bb
@@ -7,6 +7,7 @@  RDEPENDS:${PN} = "bash perl"

 SRC_URI = "git://github.com/linux-rdma/rdma-core.git;branch=master;protocol=https;tag=v${PV} \
            file://0001-cmake-Allow-SYSTEMCTL_BIN-to-be-overridden-from-envi.patch \
+           file://0002-mana-Link-with-libatomic-when-64-bit-atomics-need-it.patch \
 "
 SRCREV = "58e40801bfed5a8befc0881594820fa0a0baa4a1"