[v7,2/5] package/pocketpy: link with libatomic

Message ID 20261125161404.859000-3-dario.binacchi@amarulasolutions.com
State New
Headers
Series package: add CANopenterm and dependencies |

Commit Message

Dario Binacchi Nov. 25, 2026, 4:14 p.m. UTC
pocketpy uses C11 atomics, which require libatomic on architectures
where GCC does not provide native support, such as sparc.

The missing symbols are only exposed when linking an executable against
libpocketpy.so, so the issue is not detected by `test-pkg` when testing
pocketpy alone.

Indeed, in my use case, which was integrating the canopenterm package
into Buildroot, running:

  $ utils/test-pkg -p canopenterm -c canopenterm.config -T bootlin-sparc-uclibc

raised the following error:

  ld: .../sysroot/usr/lib/libpocketpy.so: undefined reference to `__atomic_fetch_sub_4'
  ld: .../sysroot/usr/lib/libpocketpy.so: undefined reference to `__atomic_fetch_add_4'
  collect2: error: ld returned 1 exit status

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
 package/pocketpy/pocketpy.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

-- 
2.43.0
  

Patch

diff --git a/package/pocketpy/pocketpy.mk b/package/pocketpy/pocketpy.mk
index 1150a47fc561..4d096686e9f5 100644
--- a/package/pocketpy/pocketpy.mk
+++ b/package/pocketpy/pocketpy.mk
@@ -18,6 +18,14 @@  else
 POCKETPY_CONF_OPTS += -DPK_ENABLE_THREADS=OFF
 endif
 
+# pocketpy uses C11 atomics, which on some architectures are provided by
+# libatomic
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
+POCKETPY_CONF_OPTS += \
+	-DCMAKE_EXE_LINKER_FLAGS=-latomic \
+	-DCMAKE_SHARED_LINKER_FLAGS=-latomic
+endif
+
 define POCKETPY_INSTALL_TARGET_CMDS
 	$(INSTALL) -D -m 0755 $(@D)/libpocketpy.so* $(TARGET_DIR)/usr/lib
 endef