From nobody Thu Oct 9 04:14:05 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7863D25F963 for ; Fri, 20 Jun 2025 10:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; cv=none; b=uv16rNHIwSU4sLoQA1YRfLw3dQC31doOdVHqmRSjharD4zc4gmRllP0gQfhrFt1eino/hgNidBA2WbDEzZemz+IlIDgMyk/xKY+gqJWKTYQLbmQwc1KgTpicBpa6hu1l2UnFZSShrTojHYwJGputFNeulCCPMWQU5tymsXv72XM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; c=relaxed/simple; bh=WyPgnZVhINH4Sx2MORlz0cYf8AmxrXffi5h9YKVbBJY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Q2A6bSG+XGzTaxZtvJHXV+5yoEvm016Isit9+jtttzR37RBNTvhU5lntB3fHkEJZ/g9xpbBOqwpFlXrmYO+d1b3E2SmCviy7RoZyTtc16GO2IINgXMWjH6annfizcPUp7z49Vn5qlNd7fFxb9eA7pY2L6O25r8z46YGAhnDAzpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KA2vxs009924; Fri, 20 Jun 2025 12:02:57 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 1/4] tools/nolibc: fix misleading help message regarding installation path Date: Fri, 20 Jun 2025 12:02:48 +0200 Message-Id: <20250620100251.9877-2-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620100251.9877-1-w@1wt.eu> References: <20250620100251.9877-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The help message says the headers are going to be installed into tools/include/nolibc but this is only the default if $OUTPUT is not set, so better clarify this (the current value of $OUTPUT is already shown). Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index c335ce0bd195c..f91d29705733a 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -80,7 +80,7 @@ help: @echo "Supported targets under nolibc:" @echo " all call \"headers\"" @echo " clean clean the sysroot" - @echo " headers prepare a sysroot in tools/include/nolibc/sy= sroot" + @echo " headers prepare a sysroot in \$${OUTPUT}sysroot" @echo " headers_standalone like \"headers\", and also install kernel he= aders" @echo " help this help" @echo "" --=20 2.17.5 From nobody Thu Oct 9 04:14:05 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7875027CCE4 for ; Fri, 20 Jun 2025 10:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; cv=none; b=Mapy+hqOU+n7fxOSulLOp7EZHFnNAHQfRZ6v8zem59DO2UDvkLzM0Sj5NsHJGwHtIxt+BcuZo1Roq69pXV2Ay/uPHv31+XCW0N+gK8W/K/hRA5D8Jjgns+BNrFYapFNR+UmlHYpz6UcrJZDCTpb4M+AyOrnlIZsVGdcoI/BK/9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; c=relaxed/simple; bh=bYfC2Vp6/4HomcxJ4kr8vJzTAiXmvotjcZmSeB8lQ/4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=o7gycr6DDTzMZJhvdpSweokycxaP040NlaScezbucQvtsUhmyD4qZPTywco3GddrQ3pRiIzqc3qmW4qOqkbesedWIRXVi06cbKqXdwZlaA1yI+wP6sFmDMHmkDP/pTSEJA4qv7+9vb20d4CfGyh/yVTGRzIsCHrjEJsvVXT3K7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KA2vJ0009925; Fri, 20 Jun 2025 12:02:57 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 2/4] tools/nolibc: add the more portable inttypes.h Date: Fri, 20 Jun 2025 12:02:49 +0200 Message-Id: <20250620100251.9877-3-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620100251.9877-1-w@1wt.eu> References: <20250620100251.9877-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's often recommended to only use inttypes.h instead of stdint.h for portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when including inttypes.h. Let's add one that simply includes stdint.h to better support these programs. Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/inttypes.h | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tools/include/nolibc/inttypes.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index f91d29705733a..725cf49516185 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -34,6 +34,7 @@ all_files :=3D \ errno.h \ fcntl.h \ getopt.h \ + inttypes.h \ limits.h \ math.h \ nolibc.h \ diff --git a/tools/include/nolibc/inttypes.h b/tools/include/nolibc/inttype= s.h new file mode 100644 index 0000000000000..1088034ef7cca --- /dev/null +++ b/tools/include/nolibc/inttypes.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#ifndef _NOLIBC_INTTYPES_H +#define _NOLIBC_INTTYPES_H + +#include "stdint.h" + +#endif /* _NOLIBC_INTTYPES_H */ --=20 2.17.5 From nobody Thu Oct 9 04:14:05 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7856130E826 for ; Fri, 20 Jun 2025 10:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; cv=none; b=bjJJnOp7ACbCucVhGGb28Miu3mE8pUTM3kcpIDSkLOoIhrSEomuBTS9mfxEhArjVEvwm8L7YdkwVMC8wcTPokgQ3CHcf9IykE4jSuw4SpmphsQCFXb1dN0Eiy/0JyRpvTcWS2njieYX6KHMHRVPUIUVC381jnrXjnrnEFw+5YOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; c=relaxed/simple; bh=/aUnQfYabeNvvoe0oidkYA3K4X8wFvr0KL7JCbKdbHg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=YTYyxMHnnmEML4sSCsW9SbTaezK7He2DtpOnlXeSGA+95olD36IOCB35rNiTv7xg3YGMN83nkpG2BxZbcW8cmzFk70XNwLRuwMyDc9XnsSQ2R0HqffpJdnpRk2kN+wCWJiziMRG5tn4gEhv4OmIXeD3ByO6Yix5qYurS25ONBOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KA2vF8009926; Fri, 20 Jun 2025 12:02:57 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 3/4] tools/nolibc: move FD_* definitions to sys/select.h Date: Fri, 20 Jun 2025 12:02:50 +0200 Message-Id: <20250620100251.9877-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620100251.9877-1-w@1wt.eu> References: <20250620100251.9877-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Modern programs tend to include sys/select.h to get FD_SET() and FD_CLR() definitions as well as struct fd_set, but in our case it didn't exist. Let's move these definitions from types.h to sys/select.h to help port existing programs. Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/sys/select.h | 56 +++++++++++++++++++++++++++++++ tools/include/nolibc/types.h | 48 +------------------------- 3 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 tools/include/nolibc/sys/select.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 725cf49516185..823bfa08c6756 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -58,6 +58,7 @@ all_files :=3D \ sys/random.h \ sys/reboot.h \ sys/resource.h \ + sys/select.h \ sys/stat.h \ sys/syscall.h \ sys/sysmacros.h \ diff --git a/tools/include/nolibc/sys/select.h b/tools/include/nolibc/sys/s= elect.h new file mode 100644 index 0000000000000..a7481592c76f4 --- /dev/null +++ b/tools/include/nolibc/sys/select.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +/* make sure to include all global symbols */ +#include "../nolibc.h" + +#ifndef _NOLIBC_SYS_SELECT_H +#define _NOLIBC_SYS_SELECT_H + +/* commonly an fd_set represents 256 FDs */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 256 +#endif + +#define FD_SETIDXMASK (8 * sizeof(unsigned long)) +#define FD_SETBITMASK (8 * sizeof(unsigned long)-1) + +/* for select() */ +typedef struct { + unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK]; +} fd_set; + +#define FD_CLR(fd, set) do { \ + fd_set *__set =3D (set); \ + int __fd =3D (fd); \ + if (__fd >=3D 0) \ + __set->fds[__fd / FD_SETIDXMASK] &=3D \ + ~(1U << (__fd & FD_SETBITMASK)); \ + } while (0) + +#define FD_SET(fd, set) do { \ + fd_set *__set =3D (set); \ + int __fd =3D (fd); \ + if (__fd >=3D 0) \ + __set->fds[__fd / FD_SETIDXMASK] |=3D \ + 1 << (__fd & FD_SETBITMASK); \ + } while (0) + +#define FD_ISSET(fd, set) ({ \ + fd_set *__set =3D (set); \ + int __fd =3D (fd); \ + int __r =3D 0; \ + if (__fd >=3D 0) \ + __r =3D !!(__set->fds[__fd / FD_SETIDXMASK] & \ +1U << (__fd & FD_SETBITMASK)); \ + __r; \ + }) + +#define FD_ZERO(set) do { \ + fd_set *__set =3D (set); \ + int __idx; \ + int __size =3D (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\ + for (__idx =3D 0; __idx < __size; __idx++) \ + __set->fds[__idx] =3D 0; \ + } while (0) + +#endif /* _NOLIBC_SYS_SELECT_H */ diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 16c6e9ec9451f..0b51ede4e0a9c 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -10,6 +10,7 @@ #ifndef _NOLIBC_TYPES_H #define _NOLIBC_TYPES_H =20 +#include "sys/select.h" #include "std.h" #include #include @@ -70,11 +71,6 @@ #define DT_LNK 0xa #define DT_SOCK 0xc =20 -/* commonly an fd_set represents 256 FDs */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 256 -#endif - /* PATH_MAX and MAXPATHLEN are often used and found with plenty of differe= nt * values. */ @@ -115,48 +111,6 @@ #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 =20 -#define FD_SETIDXMASK (8 * sizeof(unsigned long)) -#define FD_SETBITMASK (8 * sizeof(unsigned long)-1) - -/* for select() */ -typedef struct { - unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK]; -} fd_set; - -#define FD_CLR(fd, set) do { \ - fd_set *__set =3D (set); \ - int __fd =3D (fd); \ - if (__fd >=3D 0) \ - __set->fds[__fd / FD_SETIDXMASK] &=3D \ - ~(1U << (__fd & FD_SETBITMASK)); \ - } while (0) - -#define FD_SET(fd, set) do { \ - fd_set *__set =3D (set); \ - int __fd =3D (fd); \ - if (__fd >=3D 0) \ - __set->fds[__fd / FD_SETIDXMASK] |=3D \ - 1 << (__fd & FD_SETBITMASK); \ - } while (0) - -#define FD_ISSET(fd, set) ({ \ - fd_set *__set =3D (set); \ - int __fd =3D (fd); \ - int __r =3D 0; \ - if (__fd >=3D 0) \ - __r =3D !!(__set->fds[__fd / FD_SETIDXMASK] & \ -1U << (__fd & FD_SETBITMASK)); \ - __r; \ - }) - -#define FD_ZERO(set) do { \ - fd_set *__set =3D (set); \ - int __idx; \ - int __size =3D (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\ - for (__idx =3D 0; __idx < __size; __idx++) \ - __set->fds[__idx] =3D 0; \ - } while (0) - /* for getdents64() */ struct linux_dirent64 { uint64_t d_ino; --=20 2.17.5 From nobody Thu Oct 9 04:14:06 2025 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 785CE25EFBD for ; Fri, 20 Jun 2025 10:02:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; cv=none; b=FczQBwZKyztd2JHnQ4RFspNpwpfwoIKdpIu2DU8e4Ox3LQkC426g2AseFJxa8lKGv0HJM40VPnQcvERCAwjOZiegoYoz2tsmsca6k8lhj8nrotJbQyxPplH+FYyhahv7WcQCaCz9+chCBGcXCyv8Ve6EslpSD9mVMlGniNElkZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750413782; c=relaxed/simple; bh=n6jcWGmhWCJZZlTLzZwwm6ZZLht7nq06BcTktwIUmuc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Wtfa71ZVMu8PaSEcnRb2I+FN88JvlF6cV2bNi5JVC3ZiRcXUgZUdLolwzCW80jNNt8Ankyd7evHqNPUQURymO1MmMxB+IqEZkBbAxl+yCP1tay9XvBbI99yWaWWSG1FxlN+jJa9tY0YnV7x0Jp2Ml6PXxm9qWmFJXQFwuOj/xUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; arc=none smtp.client-ip=163.172.96.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 55KA2vB0009927; Fri, 20 Jun 2025 12:02:57 +0200 From: Willy Tarreau To: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Cc: linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH 4/4] tools/nolibc: add missing memchr() to string.h Date: Fri, 20 Jun 2025 12:02:51 +0200 Message-Id: <20250620100251.9877-5-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20250620100251.9877-1-w@1wt.eu> References: <20250620100251.9877-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Surprisingly we forgot to add this common one. It was added with a per-arch guard allowing to later implement it in arch-specific asm code like was done for a few other ones. The test verifies that we don't search past the indicated length. Signed-off-by: Willy Tarreau --- tools/include/nolibc/string.h | 15 +++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index 163a17e7dd38b..4000926f44ac4 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -93,6 +93,21 @@ void *memset(void *dst, int b, size_t len) } #endif /* #ifndef NOLIBC_ARCH_HAS_MEMSET */ =20 +#ifndef NOLIBC_ARCH_HAS_MEMCHR +static __attribute__((unused)) +void *memchr(const void *s, int c, size_t len) +{ + char *p =3D (char *)s; + + while (len--) { + if (*p =3D=3D (char)c) + return p; + p++; + } + return NULL; +} +#endif /* #ifndef NOLIBC_ARCH_HAS_MEMCHR */ + static __attribute__((unused)) char *strchr(const char *s, int c) { diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index dbe13000fb1ac..d832566265296 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1524,6 +1524,8 @@ int run_stdlib(int min, int max) CASE_TEST(abs); EXPECT_EQ(1, abs(-10), 10); break; CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break; CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break; + CASE_TEST(memchr_foobar6_o); EXPECT_STREQ(1, memchr("foobar", 'o'= , 6), "oobar"); break; + CASE_TEST(memchr_foobar3_b); EXPECT_STRZR(1, memchr("foobar", 'b'= , 3)); break; =20 case __LINE__: return ret; /* must be last */ --=20 2.17.5