Skip to contentSkip to conversation

luajit: Set TARGET_SYS to Linux for musl targets

PATCH New Khem Raj 1 participant 8 messages Oct 19

Subsystems (2)
lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/8 luajit: Set TARGET_SYS to Linux for musl targets

TARGET_OS is linux-musl on musl, which matched none of the LUA_TARGET_OS overrides, so TARGET_SYS was Unknown and LuaJIT was built for LUAJIT_OS_OTHER, losing Linux-specific features such as the profiler (LJ_HASPROFILE).

AI-Generated: Uses Claude Code

---
 meta-oe/recipes-devtools/luajit/luajit_git.bb | 1 +
 1 file changed, 1 insertion(+)
meta-oe/recipes-devtools/luajit/luajit_git.bb +1 -0
index 707cea5766..a929d832e4 100644
@@ -44,6 +44,7 @@ LUA_TARGET_OS = "Unknown"
 LUA_TARGET_OS:darwin = "Darwin"
 LUA_TARGET_OS:linux = "Linux"
 LUA_TARGET_OS:linux-gnueabi = "Linux"
+LUA_TARGET_OS:linux-musl = "Linux"
 LUA_TARGET_OS:mingw32 = "Windows"
 
 # We don't want the lua buildsystem's compiler optimizations, or its
author
#1 lore raw

PATCH 2/8 luajit: Enable riscv64 using the plctlab LuaJIT fork

Upstream LuaJIT v2.1 has no riscv64 backend, so fetch the plctlab v2.1-riscv64 branch on riscv64, with the recipe's patches rebased onto it, and drop the riscv64 COMPATIBLE_HOST restriction.

Tested by building for qemuriscv64 (musl, clang) and running a JIT-ed loop under qemu-riscv64 (jit.status() is true).

AI-Generated: Uses Claude Code

---
 ...omatically-this-leaves-the-stripping.patch | 27 +++++++++++++++++++
 .../0001-Use-builtin-for-clear_cache.patch    | 24 +++++++++++++++++
 meta-oe/recipes-devtools/luajit/luajit_git.bb |  9 ++++---
 3 files changed, 57 insertions(+), 3 deletions(-)
 create mode 100644 meta-oe/recipes-devtools/luajit/luajit/riscv64/0001-Do-not-strip-automatically-this-leaves-the-stripping.patch
 create mode 100644 meta-oe/recipes-devtools/luajit/luajit/riscv64/0001-Use-builtin-for-clear_cache.patch
meta-oe/recipes-devtools/luajit/luajit/riscv64/0001-Do-not-strip-automatically-this-leaves-the-stripping.patch new file +27 -0
new file mode 100644
index 0000000000..e3760836af
@@ -0,0 +1,27 @@
+From 528009f5ca0685c95ef27f6c8957160499c0576a Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Fri, 10 May 2013 10:42:45 -0700
+Subject: [PATCH] Do not strip automatically, this leaves the stripping busines to OE
+
+Upstream-Status: Inappropriate [OE-Specific]
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+ src/Makefile |    2 --
+ 1 file changed, 2 deletions(-)
+
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -754,12 +754,10 @@ $(LUAJIT_A): $(LJVMCORE_O)
+ $(LUAJIT_SO): $(LJVMCORE_O)
+ 	$(E) "DYNLINK   $@"
+ 	$(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
+-	$(Q)$(TARGET_STRIP) $@
+
+ $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
+ 	$(E) "LINK      $@"
+ 	$(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
+-	$(Q)$(TARGET_STRIP) $@
+ 	$(E) "OK        Successfully built LuaJIT"
+
+ ##############################################################################
meta-oe/recipes-devtools/luajit/luajit/riscv64/0001-Use-builtin-for-clear_cache.patch new file +24 -0
new file mode 100644
index 0000000000..6b91016b06
@@ -0,0 +1,24 @@
+From ca8f7d968a212f2da64492faac4f80384a5ba395 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sun, 11 Sep 2022 13:23:19 -0700
+Subject: [PATCH] Use builtin for clear_cache
+
+This makes it compile on mips/clang and also portable across platforms
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <[email protected]>
+---
+ src/lj_mcode.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/src/lj_mcode.c
++++ b/src/lj_mcode.c
+@@ -70,7 +70,7 @@ void lj_mcode_sync(void *start, void *en
+   syscall(__NR_riscv_flush_icache, start, end, 0UL);
+ #endif
+ #elif defined(__GNUC__) || defined(__clang__)
+-  __clear_cache(start, end);
++  __builtin___clear_cache(start, end);
+ #else
+ #error "Missing builtin to flush instruction cache"
+ #endif
meta-oe/recipes-devtools/luajit/luajit_git.bb +6 -3
index a929d832e4..5a4bffb108 100644
@@ -3,13 +3,17 @@ LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=a2c43bf4a9ea63755af2131b0ae59ff3"
 HOMEPAGE = "http://luajit.org"
 
-SRC_URI = "git://luajit.org/git/luajit-2.0.git;protocol=http;branch=v2.1 \
+FORK ?= "git://luajit.org/git/luajit-2.0.git;protocol=http;branch=v2.1"
+FORK:riscv64 = "git://github.com/plctlab/LuaJIT.git;protocol=https;branch=v2.1-riscv64"
+SRC_URI = "${FORK} \
            file://0001-Do-not-strip-automatically-this-leaves-the-stripping.patch \
            file://0001-Use-builtin-for-clear_cache.patch \
            "
 
 PV = "2.1"
 SRCREV = "659a61693aa3b87661864ad0f12eee14c865cd7f"
+SRCREV:riscv64 = "2c509ee67e20772bce3a11ce8f53b6b14b4980bb"
+
 # The v2.1 branch is rolling with no tags; track commits.
 UPSTREAM_CHECK_COMMITS = "1"
 
@@ -111,10 +115,9 @@ FILES:${PN}-dev += "${libdir}/libluajit-5.1.a \
 "
 FILES:luajit-common = "${datadir}/${BPN}-${PV}"
 
-# ppc64/riscv64/riscv32 is not supported in this release
+# ppc64/riscv32 is not supported in this release
 COMPATIBLE_HOST:powerpc64 = "null"
 COMPATIBLE_HOST:powerpc64le = "null"
-COMPATIBLE_HOST:riscv64 = "null"
 COMPATIBLE_HOST:riscv32 = "null"
 
 CVE_STATUS[CVE-2024-25176] = "fixed-version: The used revision contains the fix already."
author
#2 lore raw

PATCH 3/8 x265: Apply the patches with right patch level.

In reply to Khem Raj
---
 meta-multimedia/recipes-multimedia/x265/x265_4.3.bb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta-multimedia/recipes-multimedia/x265/x265_4.3.bb +2 -2
index 6459fbc8cf..01edc1dc42 100644
@@ -10,8 +10,8 @@ DEPENDS = "nasm-native gnutls zlib libpcre numactl"
 
 SRC_URI = " \
     git://github.com/Multicorewareinc/x265.git;protocol=https;branch=master;tag=${PV} \
-    file://0001-fix-dynamicHDR10-undefined-uint8_t.patch \
-    file://0002-x265-fix-build-with-cmake-4.patch \
+    file://0001-fix-dynamicHDR10-undefined-uint8_t.patch;patchdir=.. \
+    file://0002-x265-fix-build-with-cmake-4.patch;patchdir=.. \
 "
 SRCREV = "e9b88125dc21393b3fd8d68e98083bdfb89778a8"
 S = "${UNPACKDIR}/x265-${PV}/source"
author
#3 lore raw

PATCH 4/8 bpftool: Set ARCH for the kernel tools build

In reply to Khem Raj

kernel-arch.bbclass no longer sets ARCH (oe-core 635f85b7b8), so ARCH=${ARCH} expanded to an empty value and tools/scripts/Makefile.arch fell back to the build host's uname -m. libbpf was then built with tools/arch/x86/include, breaking cross builds, e.g. on riscv64:

tools/arch/riscv/include/asm/barrier.h:13:10: fatal error: asm/fence.h: No such file or directory

Set ARCH from map_kernel_arch() as perf.bb does.

---
 meta-oe/recipes-kernel/bpftool/bpftool.bb | 2 ++
 1 file changed, 2 insertions(+)
meta-oe/recipes-kernel/bpftool/bpftool.bb +2 -0
index 419be18d99..6a9fcc256d 100644
@@ -9,6 +9,8 @@ inherit bash-completion kernelsrc kernel-arch
 
 do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
 
+ARCH = "${@oe.kernel.map_kernel_arch(d)}"
+
 EXTRA_OEMAKE = "\
     V=1 \
     -C ${S}/tools/bpf/bpftool \
author
#4 lore raw

PATCH 5/8 clight: Fix build with musl

In reply to Khem Raj

log.c uses open() and O_* flags without including <fcntl.h>, which glibc pulls in indirectly but musl does not, so clang fails with -Wimplicit-function-declaration.

AI-Generated: Uses Claude Code

---
 ...nclude-fcntl.h-for-open-and-O_-flags.patch | 27 +++++++++++++++++++
 .../recipes-multimedia/clight/clight_4.11.bb  |  1 +
 2 files changed, 28 insertions(+)
 create mode 100644 meta-multimedia/recipes-multimedia/clight/clight/0001-log-Include-fcntl.h-for-open-and-O_-flags.patch
meta-multimedia/recipes-multimedia/clight/clight/0001-log-Include-fcntl.h-for-open-and-O_-flags.patch new file +27 -0
new file mode 100644
index 0000000000..0faeb84402
@@ -0,0 +1,27 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sun, 18 Oct 2026 17:05:19 -0700
+Subject: [PATCH] log: Include fcntl.h for open() and O_* flags
+
+open(), O_CREAT and O_WRONLY are declared in <fcntl.h>, which glibc
+happens to pull in through other headers but musl does not, so the
+build fails with clang:
+
+  src/utils/log.c:33:14: error: call to undeclared function 'open'
+
+Upstream-Status: Pending
+AI-Generated: Uses Claude Code
+Signed-off-by: Khem Raj <[email protected]>
+---
+ src/utils/log.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/utils/log.c b/src/utils/log.c
+index 0ec38a5..8d46b90 100644
+--- a/src/utils/log.c
++++ b/src/utils/log.c
+@@ -1,3 +1,4 @@
++#include <fcntl.h>
+ #include <sys/file.h>
+ #include <sys/stat.h>
+ #include "utils.h"
meta-multimedia/recipes-multimedia/clight/clight_4.11.bb +1 -0
index 6280bd21b0..6f797ad601 100644
@@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
 
 SRCREV = "6a5ad96ce7643c433ea2f6bd597bc52dcc744120"
 SRC_URI = "git://github.com/FedeDP/${BPN};protocol=https;branch=master;tag=${PV} \
+           file://0001-log-Include-fcntl.h-for-open-and-O_-flags.patch \
 "
 
 inherit cmake pkgconfig features_check
author
#5 lore raw

PATCH 6/8 sockperf: Add RISC-V support

In reply to Khem Raj

configure rejected riscv hosts as not ported, and the TSC read fell back to x86 rdtsc. Patch both, reading the time CSR with rdtime.

Tested by building for qemuriscv64 (musl, clang) and running a loopback ping-pong under qemu-riscv64.

AI-Generated: Uses Claude Code

---
 .../files/0002-Add-RISC-V-support.patch       | 66 +++++++++++++++++++
 .../sockperf/sockperf_git.bb                  |  1 +
 2 files changed, 67 insertions(+)
 create mode 100644 meta-oe/recipes-benchmark/sockperf/files/0002-Add-RISC-V-support.patch
meta-oe/recipes-benchmark/sockperf/files/0002-Add-RISC-V-support.patch new file +66 -0
new file mode 100644
index 0000000000..ce0cd306c9
@@ -0,0 +1,66 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sun, 18 Oct 2026 17:20:00 -0700
+Subject: [PATCH] Add RISC-V support
+
+configure rejects riscv hosts with "it has not been ported", and
+os_gettimeoftsc() falls back to the x86 rdtsc instruction for any
+unknown architecture.
+
+Accept riscv* hosts and read the time CSR with rdtime, which Linux lets
+user mode access (unlike the cycle CSR). On rv32 read the high half
+around the low half and retry on carry.
+
+Upstream-Status: Pending
+AI-Generated: Uses Claude Code
+Signed-off-by: Khem Raj <[email protected]>
+---
+ configure.ac   |  2 ++
+ src/ticks_os.h | 14 ++++++++++++++
+ 2 files changed, 16 insertions(+)
+
+diff --git a/configure.ac b/configure.ac
+index 258bbb0..13900cf 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -29,6 +29,7 @@ case "$host" in
+   i386-*-freebsd*) TARGET=FREEBSD; TARGETDIR=x86;;
+   aarch64-*-*) TARGET=AARCH64; TARGETDIR=aarch64;;
+   s390*-*-*) TARGET=S390; TARGETDIR=s390;;
++  riscv*-*-*) TARGET=RISCV; TARGETDIR=riscv;;
+ esac
+
+ AC_SUBST(AM_RUNTESTFLAGS)
+@@ -48,6 +49,7 @@ AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
+ AM_CONDITIONAL(FREEBSD, test x$TARGET = xFREEBSD)
+ AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
+ AM_CONDITIONAL(S390, test x$TARGET = xS390)
++AM_CONDITIONAL(RISCV, test x$TARGET = xRISCV)
+
+ AC_SUBST(TARGET)
+ AC_SUBST(TARGETDIR)
+diff --git a/src/ticks_os.h b/src/ticks_os.h
+index 46e313c..023be3a 100644
+--- a/src/ticks_os.h
++++ b/src/ticks_os.h
+@@ -100,6 +100,20 @@ inline ticks_t os_gettimeoftsc() {
+     asm volatile("isb" : : : "memory");
+     asm volatile("mrs %0, cntvct_el0" : "=r" (ret));
+     return ret;
++#elif defined(__riscv)
++    // Linux allows user mode to read the time CSR, but not cycle
++#if __riscv_xlen == 64
++    uint64_t ret;
++    asm volatile("rdtime %0" : "=r"(ret));
++    return (ticks_t)ret;
++#else
++    uint32_t tmp;
++    do {
++        asm volatile("rdtimeh %0" : "=r"(upper_32));
++        asm volatile("rdtime %0" : "=r"(lower_32));
++        asm volatile("rdtimeh %0" : "=r"(tmp));
++    } while (upper_32 != tmp);
++#endif
+ #elif defined(__arm__)
+     // so the compiler will not complain. for
+     // AArch32 compile, this inline is not used
meta-oe/recipes-benchmark/sockperf/sockperf_git.bb +1 -0
index fe285465e6..f4a113ee1c 100644
@@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = "file://copying;md5=b4563b57c98bc23c8cecbc0b6d9546e9"
 
 SRC_URI = "git://github.com/Mellanox/sockperf;branch=sockperf_v2;protocol=https \
            file://0001-src-fix-missing-includes-for-musl-struct-timeval-ss.patch \
+           file://0002-Add-RISC-V-support.patch \
            "
 SRCREV = "3c65ad99cd385e18f8a2a655c19826e81a4d17e8"
 
author
#6 lore raw

PATCH 7/8 zbar: Fix test build with musl

In reply to Khem Raj

test/meson.build assumed libc provides argp whenever argp.h exists, but on musl the header comes from argp-standalone, pulled into the sysroot via v4l-utils, and test_decode/test_video failed to link argp_parse. Backport the upstream fix that also checks for argp_parse and falls back to the bundled non_argp.c.

AI-Generated: Uses Claude Code

---
 ...build-better-detect-if-libc-has-argp.patch | 31 +++++++++++++++++++
 meta-oe/recipes-support/zbar/zbar_0.23.95.bb  |  4 ++-
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-support/zbar/zbar/0001-test-meson.build-better-detect-if-libc-has-argp.patch
meta-oe/recipes-support/zbar/zbar/0001-test-meson.build-better-detect-if-libc-has-argp.patch new file +31 -0
new file mode 100644
index 0000000000..6bab32b05b
@@ -0,0 +1,31 @@
+From 77ad19ae9bc3d0fa0f2208be99e562fb96a6e392 Mon Sep 17 00:00:00 2001
+From: Mauro Carvalho Chehab <[email protected]>
+Date: Wed, 14 Oct 2026 09:21:42 +0200
+Subject: [PATCH] test/meson.build: better detect if libc has argp
+
+On some cases, the build system is not properly detecting if
+argp is there or not, because on non-Linux systems, they may
+require the location of the libraries containing it.
+
+As we have our own simplified version of argp here, and currently
+we use it only on tests, if the library is not there, simply fall
+back to non_argp.c.
+
+Upstream-Status: Backport [https://github.com/mchehab/zbar/commit/77ad19ae9bc3d0fa0f2208be99e562fb96a6e392]
+Signed-off-by: Mauro Carvalho Chehab <[email protected]>
+Signed-off-by: Khem Raj <[email protected]>
+---
+ test/meson.build | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/test/meson.build b/test/meson.build
+index 656c8aa2..42905b80 100644
+--- a/test/meson.build
++++ b/test/meson.build
+@@ -1,5 +1,5 @@
+ argp_compat = []
+-if not cc.has_header('argp.h')
++if not cc.has_header('argp.h') or not cc.has_function('argp_parse')
+   argp_compat = files('non_argp.c')
+ endif
+
meta-oe/recipes-support/zbar/zbar_0.23.95.bb +3 -1
index 489615721a..e3e337d50e 100644
@@ -9,7 +9,9 @@ SECTION = "graphics"
 LICENSE = "LGPL-2.1-only"
 LIC_FILES_CHKSUM = "file://LICENSE.md;md5=5e9ee833a2118adc7d8b5ea38e5b1cef"
 
-SRC_URI = "git://github.com/mchehab/zbar.git;branch=master;protocol=https;tag=${PV}"
+SRC_URI = "git://github.com/mchehab/zbar.git;branch=master;protocol=https;tag=${PV} \
+           file://0001-test-meson.build-better-detect-if-libc-has-argp.patch \
+           "
 SRCREV = "dc19fcc7da58e8cf84ba1ec417e24b04609feb23"
 
 DEPENDS += "xmlto-native"
author
#7 lore raw

PATCH 8/8 ptyxis: Fix build with musl

In reply to Khem Raj

W_EXITCODE() is a glibc extension that musl does not provide, so clang fails with -Wimplicit-function-declaration. Define it when missing, using the glibc definition.

AI-Generated: Uses Claude Code

---
 ...n-Define-W_EXITCODE-if-libc-lacks-it.patch | 33 +++++++++++++++++++
 .../recipes-gnome/ptyxis/ptyxis_50.1.bb       |  1 +
 2 files changed, 34 insertions(+)
 create mode 100644 meta-gnome/recipes-gnome/ptyxis/ptyxis/0001-application-Define-W_EXITCODE-if-libc-lacks-it.patch
meta-gnome/recipes-gnome/ptyxis/ptyxis/0001-application-Define-W_EXITCODE-if-libc-lacks-it.patch new file +33 -0
new file mode 100644
index 0000000000..bd7ccc0f01
@@ -0,0 +1,33 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sun, 18 Oct 2026 17:40:00 -0700
+Subject: [PATCH] application: Define W_EXITCODE() if libc lacks it
+
+W_EXITCODE() is a glibc extension in <sys/wait.h> that musl does not
+provide, so the build fails with clang:
+
+  src/ptyxis-application.c:1926:34: error: call to undeclared function 'W_EXITCODE'
+
+Fall back to the same definition glibc uses.
+
+Upstream-Status: Pending
+AI-Generated: Uses Claude Code
+Signed-off-by: Khem Raj <[email protected]>
+---
+ src/ptyxis-application.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+--- a/src/ptyxis-application.c
++++ b/src/ptyxis-application.c
+@@ -26,6 +26,11 @@
+ #include <sys/utsname.h>
+ #include <sys/wait.h>
+
++/* musl does not provide W_EXITCODE(), use the glibc definition */
++#ifndef W_EXITCODE
++# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
++#endif
++
+ #include "ptyxis-action-group.h"
+ #include "ptyxis-application.h"
+ #include "ptyxis-build-ident.h"
meta-gnome/recipes-gnome/ptyxis/ptyxis_50.1.bb +1 -0
index 5b80c7dd15..15a122d704 100644
@@ -19,6 +19,7 @@ DEPENDS = " \
     vte \
 "
 
+SRC_URI += "file://0001-application-Define-W_EXITCODE-if-libc-lacks-it.patch"
 SRC_URI[archive.sha256sum] = "73f4b76480644b2840415859a51d20cd7487b0619714f8defcd38212c3ddcffe"
 
 FILES:${PN} += "${datadir}"