diff mbox series

[meta-python] python3-posix-ipc: fix feature probing instead of forcing -lrt

Message ID 20261016165021.2704044-1-khem.raj@oss.qualcomm.com
State New
Headers show
Series [meta-python] python3-posix-ipc: fix feature probing instead of forcing -lrt | expand

Commit Message

Khem Raj Oct. 16, 2026, 4:50 p.m. UTC
posix_ipc decides at build time whether it needs librt and whether
message queues are available by compiling small probe programs in
build_support/discover_system_info.py. Its does_build_succeed() splices
the linker option into the compiler argv verbatim, so when no extra
library is wanted the compiler is called with a literal empty argument:

  $CC -Wall -o foo foo.c '' -lpthread

GNU ld treats '' as an input file and fails ("cannot find : No such
file or directory"); lld ignores it. With the gcc toolchain every probe
without -lrt therefore fails, the prober wrongly decides librt is
required, and on a C library without a usable librt message queue
support is dropped - which is how posix_ipc.MessageQueue went missing
(issue #916). The result depends on the linker rather than on what the
C library provides.

The previous LDFLAGS += "-lrt" workaround only papered over this, and
is itself libc specific: it forces linking librt even where mq_* live
in libc (glibc >= 2.34, musl).

Fix the prober to split linker_options with shlex, like it already does
for CC, so an empty value adds no argument, and drop the forced -lrt so
the probes decide per C library.

Verified on qemux86-64 for glibc and musl, each with the clang and gcc
toolchains: src/system_info.h defines MESSAGE_QUEUE_SUPPORT_EXISTS,
SEM_GETVALUE_EXISTS and SEM_TIMEDWAIT_EXISTS, and the extension module
imports all mq_* from libc with no librt NEEDED entry.

Fixes: https://github.com/openembedded/meta-openembedded/issues/916

AI-Generated: Uses Claude Code
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
 ...-not-pass-empty-linker-option-to-the.patch | 46 +++++++++++++++++++
 .../python/python3-posix-ipc_1.3.2.bb         |  4 +-
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 meta-python/recipes-devtools/python/python3-posix-ipc/0001-build_support-do-not-pass-empty-linker-option-to-the.patch
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-posix-ipc/0001-build_support-do-not-pass-empty-linker-option-to-the.patch b/meta-python/recipes-devtools/python/python3-posix-ipc/0001-build_support-do-not-pass-empty-linker-option-to-the.patch
new file mode 100644
index 0000000000..37d801e42c
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-posix-ipc/0001-build_support-do-not-pass-empty-linker-option-to-the.patch
@@ -0,0 +1,46 @@ 
+From a2d268590cd2e8460b40438b4eff894ae472a0f2 Mon Sep 17 00:00:00 2001
+From: Khem Raj <khem.raj@oss.qualcomm.com>
+Date: Fri, 16 Oct 2026 16:26:28 +0000
+Subject: [PATCH] build_support: do not pass empty linker option to the
+ compiler
+
+does_build_succeed() builds an argv list and inserts linker_options
+verbatim. When no extra linker option is wanted it is "", so the
+compiler is invoked with a literal empty argument:
+
+  cc -Wall -o foo foo.c '' -lpthread
+
+GNU ld treats the empty argument as an input file and fails with
+"cannot find : No such file or directory", while lld silently ignores
+it. With GNU ld every probe that runs without -lrt therefore fails,
+which makes sniff_realtime_lib() wrongly conclude that librt is needed
+(or raise DiscoveryError on C libraries that have no usable librt),
+independent of what the C library actually provides. With lld the
+probes happen to give the right answer, so the outcome depends on the
+linker rather than on the target system.
+
+This regressed when the command was converted from a shell string
+(where an empty %s vanished) to an argv list.
+
+Split linker_options with shlex like CC already is, so an empty value
+contributes no argument and multi-word values still work.
+
+Upstream-Status: Submitted [https://github.com/osvenskan/posix_ipc/pull/114]
+Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
+---
+ build_support/discover_system_info.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/build_support/discover_system_info.py b/build_support/discover_system_info.py
+index 1c3741f..669c234 100644
+--- a/build_support/discover_system_info.py
++++ b/build_support/discover_system_info.py
+@@ -57,7 +57,7 @@ def does_build_succeed(filename, linker_options=""):
+            '-o',
+            f'./build_support/src/{filename[:-2]}',
+            f'./build_support/src/{filename}',
+-           linker_options,
++           *shlex.split(linker_options),
+            '-lpthread'
+            ]
+     p = subprocess.Popen(cmd, stdout=STDOUT, stderr=STDERR)
diff --git a/meta-python/recipes-devtools/python/python3-posix-ipc_1.3.2.bb b/meta-python/recipes-devtools/python/python3-posix-ipc_1.3.2.bb
index 111444580a..957580bf5d 100644
--- a/meta-python/recipes-devtools/python/python3-posix-ipc_1.3.2.bb
+++ b/meta-python/recipes-devtools/python/python3-posix-ipc_1.3.2.bb
@@ -4,9 +4,7 @@  SECTION = "devel/python"
 LICENSE = "BSD-3-Clause"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=e3d8df223c2614dbf1aabdc1ca23cc10"

+SRC_URI += "file://0001-build_support-do-not-pass-empty-linker-option-to-the.patch"
 SRC_URI[sha256sum] = "6923232111329954a8349f7d99f212b6e96b5206e77fbd39aaf1b3cb4a5e9260"

-# Message queue support requires librt for proper linking
-LDFLAGS += "-lrt"
-
 inherit pypi python_setuptools_build_meta