From 9da0f529c089f00e6ab8b552d7407e612b7245a8 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Wed, 18 Mar 2026 16:50:17 +0100 Subject: tools/nolibc: add err.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a few convenient helpers to print error and warning messages. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau Link: https://patch.msgid.link/20260318-nolibc-err-h-v4-2-08247a694bd9@weissschuh.net --- tools/include/nolibc/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/include/nolibc/Makefile') diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 1958dda98895..5d242312943f 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -30,6 +30,7 @@ all_files := \ ctype.h \ dirent.h \ elf.h \ + err.h \ errno.h \ fcntl.h \ getopt.h \ -- cgit v1.2.3 From 5bf4b30ed49b9af281bdf11c788f382faa432cfd Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Wed, 1 Apr 2026 17:08:28 +0200 Subject: tools/nolibc: drop superfluous invocation of 'make headers' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The headers_install target of the toplevel Makefile will already make sure that the headers are up-to-date. Drop the superfluous explicit invocation. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-1-bcf4c9f5c1be@weissschuh.net --- tools/include/nolibc/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/include/nolibc/Makefile') diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 5d242312943f..76cfbfddf3c6 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -102,7 +102,6 @@ headers: $(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/" headers_standalone: headers - $(Q)$(MAKE) -C $(srctree) headers $(Q)$(MAKE) -C $(srctree) headers_install INSTALL_HDR_PATH=$(OUTPUT)sysroot CFLAGS_s390 := -m64 -- cgit v1.2.3 From 010d03d0e8fb0a2690d5a79c6580d8c4f32c937e Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Wed, 1 Apr 2026 17:08:29 +0200 Subject: tools/nolibc: drop superfluous invocation of mkdir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The call to 'mkdir -p $(OUTPUT)sysroot/include' will also create the sysroot directory. Drop the unnecessary explicit invocation of mkdir. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-2-bcf4c9f5c1be@weissschuh.net --- tools/include/nolibc/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/include/nolibc/Makefile') diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 76cfbfddf3c6..22e2f54cd5ca 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -97,7 +97,6 @@ help: # installs headers for all archs at once. headers: - $(Q)mkdir -p "$(OUTPUT)sysroot" $(Q)mkdir -p "$(OUTPUT)sysroot/include" $(Q)cp --parents $(arch_files) $(all_files) "$(OUTPUT)sysroot/include/" -- cgit v1.2.3 From b972b37cb6b8216922c1e817b0bab4cfed55fc44 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Wed, 1 Apr 2026 17:08:30 +0200 Subject: tools/nolibc: drop superfluous definition of Q MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Q is already defined by tools/scripts/Makefile.include which is included at the top of tools/include/nolibc/Makefile. Signed-off-by: Thomas Weißschuh Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-3-bcf4c9f5c1be@weissschuh.net --- tools/include/nolibc/Makefile | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tools/include/nolibc/Makefile') diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 22e2f54cd5ca..03f789b21017 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -17,12 +17,6 @@ endif # it defaults to this nolibc directory. OUTPUT ?= $(CURDIR)/ -ifeq ($(V),1) -Q= -else -Q=@ -endif - arch_files := arch.h $(wildcard arch-*.h) all_files := \ compiler.h \ -- cgit v1.2.3 From 7933969e1f733e18795a755cd9822ccf510140a1 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Wed, 1 Apr 2026 17:08:31 +0200 Subject: tools/nolibc: explicitly list architecture headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relying on $(wildcard) is brittle and non-deterministic. similar to all the other headers. Switch the list of architecture headers to an explicit list, Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-4-bcf4c9f5c1be@weissschuh.net Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools/include/nolibc/Makefile') diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 03f789b21017..db6db4e6d99e 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -17,7 +17,8 @@ endif # it defaults to this nolibc directory. OUTPUT ?= $(CURDIR)/ -arch_files := arch.h $(wildcard arch-*.h) +architectures := arm arm64 loongarch m68k mips powerpc riscv s390 sh sparc x86 +arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures))) all_files := \ compiler.h \ crt.h \ -- cgit v1.2.3 From ce834c9cb984a9b85160a2c3a3821e179fa502fa Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Sun, 5 Apr 2026 17:31:05 +0200 Subject: tools/nolibc: add byteorder conversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add some standard functions to convert between different byte orders. Conveniently the UAPI headers provide all the necessary functionality. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau Link: https://patch.msgid.link/20260405-nolibc-bswap-v1-1-f7699ca9cee0@weissschuh.net --- tools/include/nolibc/Makefile | 2 ++ tools/include/nolibc/byteswap.h | 21 ++++++++++++++++++ tools/include/nolibc/endian.h | 32 ++++++++++++++++++++++++++++ tools/include/nolibc/nolibc.h | 2 ++ tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++++ 5 files changed, 70 insertions(+) create mode 100644 tools/include/nolibc/byteswap.h create mode 100644 tools/include/nolibc/endian.h (limited to 'tools/include/nolibc/Makefile') diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index db6db4e6d99e..7455097cff69 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -20,11 +20,13 @@ OUTPUT ?= $(CURDIR)/ architectures := arm arm64 loongarch m68k mips powerpc riscv s390 sh sparc x86 arch_files := arch.h $(addsuffix .h, $(addprefix arch-, $(architectures))) all_files := \ + byteswap.h \ compiler.h \ crt.h \ ctype.h \ dirent.h \ elf.h \ + endian.h \ err.h \ errno.h \ fcntl.h \ diff --git a/tools/include/nolibc/byteswap.h b/tools/include/nolibc/byteswap.h new file mode 100644 index 000000000000..45bbf9609d7a --- /dev/null +++ b/tools/include/nolibc/byteswap.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Byte swapping for NOLIBC + * Copyright (C) 2026 Thomas Weißschuh + */ + +/* make sure to include all global symbols */ +#include "nolibc.h" + +#ifndef _NOLIBC_BYTESWAP_H +#define _NOLIBC_BYTESWAP_H + +#include "stdint.h" + +#include + +#define bswap_16(_x) __swab16(_x) +#define bswap_32(_x) __swab32(_x) +#define bswap_64(_x) __swab64(_x) + +#endif /* _NOLIBC_BYTESWAP_H */ diff --git a/tools/include/nolibc/endian.h b/tools/include/nolibc/endian.h new file mode 100644 index 000000000000..ccc016ecd5ec --- /dev/null +++ b/tools/include/nolibc/endian.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * Byte order conversion for NOLIBC + * Copyright (C) 2026 Thomas Weißschuh + */ + +/* make sure to include all global symbols */ +#include "nolibc.h" + +#ifndef _NOLIBC_ENDIAN_H +#define _NOLIBC_ENDIAN_H + +#include "stdint.h" + +#include + +#define htobe16(_x) __cpu_to_be16(_x) +#define htole16(_x) __cpu_to_le16(_x) +#define be16toh(_x) __be16_to_cpu(_x) +#define le16toh(_x) __le16_to_cpu(_x) + +#define htobe32(_x) __cpu_to_be32(_x) +#define htole32(_x) __cpu_to_le32(_x) +#define be32toh(_x) __be32_to_cpu(_x) +#define le32toh(_x) __le32_to_cpu(_x) + +#define htobe64(_x) __cpu_to_be64(_x) +#define htole64(_x) __cpu_to_le64(_x) +#define be64toh(_x) __be64_to_cpu(_x) +#define le64toh(_x) __le64_to_cpu(_x) + +#endif /* _NOLIBC_ENDIAN_H */ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 294bac1b9039..f4120f65fe79 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -131,6 +131,8 @@ #include "poll.h" #include "math.h" #include "err.h" +#include "byteswap.h" +#include "endian.h" /* Used by programs to avoid std includes */ #define NOLIBC diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 4bcf46867603..bb13f9f9aa7c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -43,6 +43,8 @@ #include #include #include +#include +#include #pragma GCC diagnostic ignored "-Wmissing-prototypes" @@ -67,6 +69,8 @@ static const char *argv0; /* will be used by constructor tests */ static int constructor_test_value; +static const int is_le = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; + static const int is_nolibc = #ifdef NOLIBC 1 @@ -1746,6 +1750,15 @@ int run_stdlib(int min, int max) CASE_TEST(major_big); EXPECT_EQ(1, major(0x1122355667734488), 0x11223344); break; CASE_TEST(minor_big); EXPECT_EQ(1, minor(0x1122355667734488), 0x55667788); break; CASE_TEST(malloc); EXPECT_ZR(1, test_malloc()); break; + CASE_TEST(bswap_16); EXPECT_EQ(1, bswap_16(0x0123), 0x2301); break; + CASE_TEST(bswap_32); EXPECT_EQ(1, bswap_32(0x01234567), 0x67452301); break; + CASE_TEST(bswap_64); EXPECT_EQ(1, bswap_64(0x0123456789abcdef), 0xefcdab8967452301); break; + CASE_TEST(htobe16); EXPECT_EQ(1, htobe16(is_le ? 0x0123 : 0x2301), 0x2301); break; + CASE_TEST(htole16); EXPECT_EQ(1, htole16(is_le ? 0x0123 : 0x2301), 0x0123); break; + CASE_TEST(htobe32); EXPECT_EQ(1, htobe32(is_le ? 0x01234567 : 0x67452301), 0x67452301); break; + CASE_TEST(htole32); EXPECT_EQ(1, htole32(is_le ? 0x01234567 : 0x67452301), 0x01234567); break; + CASE_TEST(htobe64); EXPECT_EQ(1, htobe64(is_le ? 0x0123456789000000 : 0x8967452301), 0x8967452301); break; + CASE_TEST(htole64); EXPECT_EQ(1, htole64(is_le ? 0x0123456789 : 0x8967452301000000), 0x0123456789); break; case __LINE__: return ret; /* must be last */ -- cgit v1.2.3