Skip to contentSkip to conversation

protobuf-c: Link with libatomic on riscv32

PATCH New Khem Raj 1 participant 12 messages Sep 17, 2024

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/12 protobuf-c: Link with libatomic on riscv32

No 64bit atomic builtins provided by compiler

---
 meta-oe/recipes-devtools/protobuf/protobuf-c_1.5.0.bb | 3 +++
 1 file changed, 3 insertions(+)
meta-oe/recipes-devtools/protobuf/protobuf-c_1.5.0.bb +3 -0
index 24de6b8119..82aaf1bae6 100644
@@ -36,3 +36,6 @@ RDEPENDS:${PN}-compiler = "protobuf-compiler"
 RDEPENDS:${PN}-dev += "${PN}-compiler"
 
 BBCLASSEXTEND = "native nativesdk"
+
+# No 64bit atomics
+LDFLAGS:append:riscv32 = " -latomic"
author
#1 lore raw

PATCH 2/12 highway: Disable RVV on RISCV-32

RISCV support in highway is assuming RVV and RISCV64 however, there is RISCV32 which perhaps does not have RVV yet

---
 meta-oe/recipes-extended/highway/highway_1.2.0.bb | 3 +++
 1 file changed, 3 insertions(+)
meta-oe/recipes-extended/highway/highway_1.2.0.bb +3 -0
index 5d74941245..020116d864 100644
@@ -12,6 +12,9 @@ SRCREV = "457c891775a7397bdb0376bb1031e6e027af1c48"
 S = "${WORKDIR}/git"
 
 EXTRA_OECMAKE = "-DBUILD_TESTING=0 -DCMAKE_BUILD_TYPE=Release"
+# RVV is enabled by default and highway cmake system assumes that RISCV64 = RISCV
+EXTRA_OECMAKE:append:riscv32 = " -DHWY_CMAKE_RVV=OFF"
+
 CXXFLAGS:append:arm = " -mfp16-format=ieee"
 # Option not supported with clang and its default format for __fp16 anyway with clang
 CXXFLAGS:remove:toolchain-clang = "-mfp16-format=ieee"
author
#2 lore raw

PATCH 3/12 liburing: Upgrade to 2.7 and fix build on riscv32

In reply to Khem Raj
---
 ...ibc.c-only-when-CONFIG_NOLIBC-is-set.patch | 43 +++++++++++++++++++
 .../{liburing_2.6.bb => liburing_2.7.bb}      |  8 ++--
 2 files changed, 48 insertions(+), 3 deletions(-)
 create mode 100644 meta-oe/recipes-support/liburing/liburing/0001-test-Compile-nolibc.c-only-when-CONFIG_NOLIBC-is-set.patch
 rename meta-oe/recipes-support/liburing/{liburing_2.6.bb => liburing_2.7.bb} (83%)
meta-oe/recipes-support/liburing/liburing/0001-test-Compile-nolibc.c-only-when-CONFIG_NOLIBC-is-set.patch new file +43 -0
new file mode 100644
index 0000000000..32e788123d
@@ -0,0 +1,43 @@
+From 7ea4e55a91e6d5564c6de762c2d1afc78ff9cfd3 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Mon, 16 Sep 2024 22:58:38 +0000
+Subject: [PATCH] test: Compile nolibc.c only when CONFIG_NOLIBC is set
+
+building nolibc.c fails for non nolibc targets
+
+Fixes
+In file included from nolibc.c:33:
+./../src/lib.h:20:2: error: "This arch doesn't support building liburing without libc"
+   20 | #error "This arch doesn't support building liburing without libc"
+      |  ^
+1 error generated.
+
+Upstream-Status: Submitted [https://github.com/axboe/liburing/pull/1232]
+Signed-off-by: Khem Raj <[email protected]>
+---
+ test/Makefile | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/test/Makefile b/test/Makefile
+index 0538a75..0dfecb8 100644
+--- a/test/Makefile
++++ b/test/Makefile
+@@ -126,7 +126,6 @@ test_srcs := \
+ 	msg-ring-overflow.c \
+ 	multicqes_drain.c \
+ 	no-mmap-inval.c \
+-	nolibc.c \
+ 	nop-all-sizes.c \
+ 	nop.c \
+ 	ooo-file-unreg.c \
+@@ -221,6 +220,10 @@ test_srcs := \
+ all_targets :=
+ include ../Makefile.quiet
+ 
++ifeq ($(CONFIG_NOLIBC),y)
++	test_srcs += nolibc.c
++endif
++
+ ifdef CONFIG_HAVE_STATX
+ 	test_srcs += statx.c
+ else ifdef CONFIG_HAVE_GLIBC_STATX
meta-oe/recipes-support/liburing/liburing_2.7.bb renamed from meta-oe/recipes-support/liburing/liburing_2.6.bb +5 -3
similarity index 83%
rename from meta-oe/recipes-support/liburing/liburing_2.6.bb
rename to meta-oe/recipes-support/liburing/liburing_2.7.bb
index fc3fe1cac1..7ef182ffae 100644
@@ -9,8 +9,9 @@ SECTION = "libs"
 LICENSE = "LGPL-2.1-only | MIT"
 LIC_FILES_CHKSUM = "file://README;beginline=41;endline=44;md5=2b0e9926530c269f5ae95560370195af"
 
-SRC_URI = "git://github.com/axboe/liburing.git;branch=master;protocol=https"
-SRCREV = "f7dcc1ea60819475dffd3a45059e16f04381bee7"
+SRC_URI = "git://github.com/axboe/liburing.git;branch=master;protocol=https \
+           file://0001-test-Compile-nolibc.c-only-when-CONFIG_NOLIBC-is-set.patch"
+SRCREV = "5227d48b28ad8671e61d444b72678da584d2e6c3"
 
 S = "${WORKDIR}/git"
 
@@ -19,10 +20,11 @@ XCFLAGS = "-pthread"
 XCFLAGS:append:libc-musl = " -lucontext"
 
 USELIBC = ""
-# clang-18 on RV64 emits memset for arch/riscv64/syscall.h provided __do_syscall4 macro
+# clang-18+ on RV64 emits memset for arch/riscv64/syscall.h provided __do_syscall4 macro
 # this does not happen for gcc or older clang, so link with libc since we need memset API
 # -fno-builtin-memset does not help
 USELIBC:riscv64:toolchain-clang = "--use-libc"
+USELIBC:riscv32 = "--use-libc"
 EXTRA_OEMAKE = "'CC=${CC}' 'RANLIB=${RANLIB}' 'AR=${AR}' 'CFLAGS=${CFLAGS} -I${S}/include -DWITHOUT_XATTR' 'LDFLAGS=${LDFLAGS}' 'XCFLAGS=${XCFLAGS}' 'BUILDDIR=${S}'"
 do_configure() {
     ${S}/configure --prefix=${prefix} --libdir=${libdir} --libdevdir=${libdir} --mandir=${mandir} --datadir=${datadir} --includedir=${includedir} ${USELIBC}
author
#3 lore raw

PATCH 4/12 dav1d: Disable asm code on rv32

In reply to Khem Raj
---
 meta-multimedia/recipes-multimedia/dav1d/dav1d_1.4.3.bb | 3 +++
 1 file changed, 3 insertions(+)
meta-multimedia/recipes-multimedia/dav1d/dav1d_1.4.3.bb +3 -0
index 43056e9a46..6b7f3090a3 100644
@@ -15,3 +15,6 @@ DEPENDS:append:x86 = " nasm-native"
 DEPENDS:append:x86-64 = " nasm-native"
 
 inherit meson pkgconfig
+
+# RVV assembler routines are not yet available for RISCV32
+EXTRA_OEMESON:append:riscv32 = " -Denable_asm=false"
author
#4 lore raw

PATCH 5/12 mosh: Use libatomic on rv32 for atomics

In reply to Khem Raj

Fixes
riscv32-yoe-linux-ld.lld: error: undefined reference: __atomic_store_8

---
 meta-oe/recipes-connectivity/mosh/mosh_1.4.0.bb | 1 +
 1 file changed, 1 insertion(+)
meta-oe/recipes-connectivity/mosh/mosh_1.4.0.bb +1 -0
index 693ec12d3c..bea22b18e2 100644
@@ -48,3 +48,4 @@ RDEPENDS:${PN}-server += "openssh-sshd"
 ARM_INSTRUCTION_SET = "arm"
 
 CXXFLAGS:append = " -std=c++17"
+LDFLAGS:append:riscv32 = " -latomic"
author
#5 lore raw

PATCH 6/12 dlm: Disable fcf-protection on riscv32

In reply to Khem Raj

Its not available on RISCV

---
 meta-networking/recipes-extended/dlm/dlm_4.2.0.bb | 1 +
 1 file changed, 1 insertion(+)
meta-networking/recipes-extended/dlm/dlm_4.2.0.bb +1 -0
index ee006efe28..93d293493c 100644
@@ -37,6 +37,7 @@ SYSTEMD_AUTO_ENABLE = "enable"
 export EXTRA_OEMAKE = ""
 
 CFPROTECTION ?= "-fcf-protection=full"
+CFPROTECTION:riscv32 = ""
 CFPROTECTION:riscv64 = ""
 CFPROTECTION:arm = ""
 CFPROTECTION:aarch64 = ""
author
#6 lore raw

PATCH 7/12 usbguard: Link with libatomic on rv32

In reply to Khem Raj

Provides needed atomic intrinsics that compiler needs.

---
 meta-oe/recipes-security/usbguard/usbguard_1.1.3.bb | 2 ++
 1 file changed, 2 insertions(+)
meta-oe/recipes-security/usbguard/usbguard_1.1.3.bb +2 -0
index 752938057a..ede9a5f058 100644
@@ -27,6 +27,8 @@ EXTRA_OECONF += "\
     --with-bundled-pegtl \
 "
 
+LDFLAGS:append:riscv32 = " -latomic"
+
 PACKAGECONFIG ?= "\
     openssl \
     ${@bb.utils.filter('DISTRO_FEATURES', 'polkit', d)} \
author
#7 lore raw

PATCH 8/12 transmission: Link with libatomic on riscv32

In reply to Khem Raj
---
 meta-oe/recipes-connectivity/transmission/transmission_4.0.6.bb | 2 ++
 1 file changed, 2 insertions(+)
meta-oe/recipes-connectivity/transmission/transmission_4.0.6.bb +2 -0
index 7b68cb0613..199a7c6d6f 100644
@@ -19,6 +19,8 @@ S = "${WORKDIR}/git"
 
 inherit cmake gettext update-rc.d pkgconfig systemd mime-xdg
 
+LDFLAGS:append:riscv32 = " -latomic"
+
 PACKAGECONFIG = "${@bb.utils.contains('DISTRO_FEATURES', 'x11', 'gtk', '', d)} \
                  ${@bb.utils.contains('DISTRO_FEATURES','systemd','systemd','',d)}"
 
author
#8 lore raw

PATCH 9/12 ot-br-posix: Link with libatomic on rv32

In reply to Khem Raj
---
 .../recipes-connectivity/openthread/ot-br-posix_git.bb          | 2 ++
 1 file changed, 2 insertions(+)
meta-networking/recipes-connectivity/openthread/ot-br-posix_git.bb +2 -0
index e5f8db24d4..ec930de275 100644
@@ -29,6 +29,8 @@ inherit pkgconfig cmake systemd
 #    for (uint8_t i = 0;; i++)
 CXXFLAGS:append:libc-musl:toolchain-clang = " -Wno-error=sign-compare -Wno-error=unused-but-set-variable"
 
+LDFLAGS:append:riscv32 = " -latomic"
+
 EXTRA_OECMAKE = "-DBUILD_TESTING=OFF \
                  -DOTBR_DBUS=ON \
                  -DOTBR_REST=ON \
author
#9 lore raw

PATCH 10/12 opentelemetry-cpp: Link with libatomic on rv32

In reply to Khem Raj
---
 .../recipes-support/opentelemetry/opentelemetry-cpp_1.16.1.bb   | 2 ++
 1 file changed, 2 insertions(+)
meta-oe/recipes-support/opentelemetry/opentelemetry-cpp_1.16.1.bb +2 -0
index c7004cc78d..1d86f1abce 100644
@@ -15,6 +15,8 @@ SRCREV = "baecbb95bd63df53e0af16e87bc683967962c5f8"
 S = "${WORKDIR}/git"
 inherit cmake pkgconfig lib_package
 
+LDFLAGS:append:riscv32 = " -latomic"
+
 PACKAGECONFIG ?= "opentelemety_install otlp_api"
 
 PACKAGECONFIG[opentelemety_install]="-DOPENTELEMETRY_INSTALL=ON,-DOPENTELEMETRY_INSTALL=OFF"
author
#10 lore raw

PATCH 11/12 mozjs-115: Fix build on riscv32

In reply to Khem Raj

Link with libatomic explicitly, fixes riscv32-yoe-linux-ld.lld: error: undefined symbol: __atomic_store_8

---
 meta-oe/recipes-extended/mozjs/mozjs-115_115.11.0.bb | 2 ++
 1 file changed, 2 insertions(+)
meta-oe/recipes-extended/mozjs/mozjs-115_115.11.0.bb +2 -0
index 4a0baf5fa6..f25c5a8f95 100644
@@ -67,6 +67,8 @@ ICU ?= "--with-system-icu"
 ICU:mipsarch = ""
 ICU:powerpc:toolchain-clang = ""
 
+LDFLAGS:append:riscv32 = " -latomic"
+
 do_configure() {
     cd ${B}
     python3 ${S}/configure.py \
author
#11 lore raw

PATCH 12/12 netdata: Add checks for 64-bit atomic builtins

In reply to Khem Raj

This helps in passing correct flags to h2o module compilation

---
 ...-Add-check-for-64bit-builtin-atomics.patch | 51 +++++++++++++++++++
 .../netdata/netdata_1.47.1.bb                 |  1 +
 2 files changed, 52 insertions(+)
 create mode 100644 meta-webserver/recipes-webadmin/netdata/netdata/0001-cmake-Add-check-for-64bit-builtin-atomics.patch
meta-webserver/recipes-webadmin/netdata/netdata/0001-cmake-Add-check-for-64bit-builtin-atomics.patch new file +51 -0
new file mode 100644
index 0000000000..d8ad69ceca
@@ -0,0 +1,51 @@
+From 1e8fbb6da4e5ee44fe24c078aae1930d759f0ba3 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Tue, 17 Sep 2024 05:29:13 +0000
+Subject: [PATCH] cmake: Add check for 64bit builtin atomics
+
+Compilers for some architectures e.g. RISCV32 do not have 64bit atomics
+therefore, its important to deduce that and use it to pass right flags to
+compiler to use them, e.g. h2o module
+
+Fixes
+nection.c.o): in function `h2o_create_connection':
+| /usr/src/debug/netdata/1.47.1/src/web/server/h2o/libh2o/include/h2o.h:1917:(.text.create_conn+0x5e): undefined reference to `__sync_add_and_fetch_8'
+| collect2: error: ld returned 1 exit status
+
+Upstream-Status: Submitted [https://github.com/netdata/netdata/pull/18565]
+Signed-off-by: Khem Raj <[email protected]>
+---
+ CMakeLists.txt | 13 +++++++++++++
+ 1 file changed, 13 insertions(+)
+
+Index: netdata-v1.47.1/CMakeLists.txt
+===================================================================
+--- netdata-v1.47.1.orig/CMakeLists.txt
++++ netdata-v1.47.1/CMakeLists.txt
+@@ -448,6 +448,15 @@ int main() {
+ }
+ " HAVE_BUILTIN_ATOMICS)
+ 
++check_cxx_source_compiles("
++#include <stdint.h>
++int main(void) {
++        uint64_t a;
++        __sync_add_and_fetch(&a, 1);
++        return 0;
++}
++" ARCH_SUPPORTS_64BIT_ATOMICS)
++
+ check_c_source_compiles("
+ void my_printf(char const *s, ...) __attribute__((format(gnu_printf, 1, 2)));
+ int main() { return 0; }
+@@ -523,6 +532,10 @@ if(OS_FREEBSD OR OS_MACOS)
+         set(HAVE_BUILTIN_ATOMICS True)
+ endif()
+ 
++if (ENABLE_H2O AND NOT ARCH_SUPPORTS_64BIT_ATOMICS)
++       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DH2O_NO_64BIT_ATOMICS")
++endif (NOT ARCH_SUPPORTS_64BIT_ATOMICS)
++
+ # openssl/crypto
+ set(ENABLE_OPENSSL True)
+ pkg_check_modules(TLS IMPORTED_TARGET openssl)
meta-webserver/recipes-webadmin/netdata/netdata_1.47.1.bb +1 -0
index e134c06b06..5b38d401cd 100644
@@ -9,6 +9,7 @@ DEPENDS += "json-c libuv libyaml util-linux zlib lz4"
 
 SRC_URI = "\
     https://github.com/${BPN}/${BPN}/releases/download/v${PV}/${BPN}-v${PV}.tar.gz \
+    file://0001-cmake-Add-check-for-64bit-builtin-atomics.patch \
     file://netdata.conf \
     file://netdata.service \
     file://netdata-volatiles.conf \