From nobody Tue Apr 7 19:50:52 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA39930C35F; Wed, 11 Mar 2026 22:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; cv=none; b=iM7G0563c9HWpSpcOhy1F31k6ZKHFuM2ER2DezC64CnMHAnLRmDm/cBxwFS4bDKiktAaZ/vrh7t0BBoAQwPmJjcbfFJTi+7BMzj+R5/Z0fBNTwLCuqQNhxPuC5u8NDx+T7ziin0FBfCxJhomxhCa6EGinMHZn20XgW0fnxhKDS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; c=relaxed/simple; bh=K/p/6td6qQEvWG9AhaOSyDEDNlhhNk5HXL1E1wSA3s8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IsEEsR1MIj63K/6eufsBpD+S8CrhkIsfiyQg5ZBZtL8GGOQLdMhK5LAMEoe1BLIWufdna2hoR5gM0QCTrbC94ICTbeF+ay8WnN1NTxT6TMeH/vEZKx3sMbdA/pLnA0MWDq9gmkG2txyISJQwiyW22bvBXa7zCkgt0u8izInC5+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=dGT0lr30; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="dGT0lr30" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1773266488; bh=K/p/6td6qQEvWG9AhaOSyDEDNlhhNk5HXL1E1wSA3s8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dGT0lr304xSrDnbq7H73UlI/O9oXgAKF5tG+qW/gMv5gAd7Hl50nQ/N5/6c7l4CQ7 mBhuuC70gN342M9xUL7+79NIyH8D+l7a3Z6D6FZzr/IbI+hs+KE5bSxkmUInij9ahS Nt59abswR0BFj9nXgjOHvkJE5qO3nREImDv2Gp1U= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Mar 2026 23:00:49 +0100 Subject: [PATCH 1/4] selftests/nolibc: add a variable for nolibc-test source files Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-nolibc-err-h-v1-1-735a9de7f15d@weissschuh.net> References: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> In-Reply-To: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773266488; l=3019; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=K/p/6td6qQEvWG9AhaOSyDEDNlhhNk5HXL1E1wSA3s8=; b=390NenVbU3rNlFf0ICz3LEitM6PQpYWwFUcVK2fZj9Bk2e/wj7tNxkqWek84vtUGc0l8PkztX NRRfuYV/hxsAxAHLwbSqvLjm5eH5eJUsmfvtWq2SSmtw23wrtPyeI0O X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The list of the nolibc-test source files is repeated many times. Another source file is about to be added, adding to the mess. Introduce a common variable instead. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/nolibc/Makefile | 4 ++-- tools/testing/selftests/nolibc/Makefile.include | 2 ++ tools/testing/selftests/nolibc/Makefile.nolibc | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selfte= sts/nolibc/Makefile index 0370489d938b..6bace04227a7 100644 --- a/tools/testing/selftests/nolibc/Makefile +++ b/tools/testing/selftests/nolibc/Makefile @@ -13,9 +13,9 @@ $(OUTPUT)/nolibc-test: CFLAGS =3D -nostdlib -nostdinc -st= atic \ -isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/i= nclude \ $(CFLAGS_NOLIBC_TEST) $(OUTPUT)/nolibc-test: LDLIBS =3D $(if $(LLVM),,-lgcc) -$(OUTPUT)/nolibc-test: nolibc-test.c nolibc-test-linkage.c | headers +$(OUTPUT)/nolibc-test: $(NOLIBC_TEST_SOURCES) | headers =20 -$(OUTPUT)/libc-test: nolibc-test.c nolibc-test-linkage.c +$(OUTPUT)/libc-test: $(NOLIBC_TEST_SOURCES) $(call msg,CC,,$@) $(Q)$(LINK.c) $^ -o $@ =20 diff --git a/tools/testing/selftests/nolibc/Makefile.include b/tools/testin= g/selftests/nolibc/Makefile.include index 66287fafbbe0..6455373d56be 100644 --- a/tools/testing/selftests/nolibc/Makefile.include +++ b/tools/testing/selftests/nolibc/Makefile.include @@ -8,3 +8,5 @@ _CFLAGS_SANITIZER ?=3D $(call cc-option,-fsanitize=3Dundefi= ned -fsanitize-trap=3Dall) CFLAGS_NOLIBC_TEST ?=3D -Os -fno-ident -fno-asynchronous-unwind-tables -s= td=3Dc89 -W -Wall -Wextra \ $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-protot= ypes) \ $(_CFLAGS_STACKPROTECTOR) $(_CFLAGS_SANITIZER) + +NOLIBC_TEST_SOURCES :=3D nolibc-test.c nolibc-test-linkage.c diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing= /selftests/nolibc/Makefile.nolibc index f5704193038f..2d32cec1105f 100644 --- a/tools/testing/selftests/nolibc/Makefile.nolibc +++ b/tools/testing/selftests/nolibc/Makefile.nolibc @@ -302,12 +302,12 @@ sysroot/$(ARCH)/include: $(Q)$(MAKE) -C $(srctree)/tools/include/nolibc ARCH=3D$(ARCH) OUTPUT=3D$(= CURDIR)/sysroot/ headers_standalone headers_check $(Q)mv sysroot/sysroot sysroot/$(ARCH) =20 -nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include +nolibc-test: $(NOLIBC_TEST_SOURCES) sysroot/$(ARCH)/include $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ - -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nol= ibc-test-linkage.c $(LIBGCC) + -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $(NOLIBC_TEST_SOU= RCES) $(LIBGCC) =20 -libc-test: nolibc-test.c nolibc-test-linkage.c - $(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c +libc-test: $(NOLIBC_TEST_SOURCES) + $(QUIET_CC)$(HOSTCC) -o $@ $(NOLIBC_TEST_SOURCES) =20 # local libc-test run-libc-test: libc-test --=20 2.53.0 From nobody Tue Apr 7 19:50:52 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D9C935B658; Wed, 11 Mar 2026 22:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; cv=none; b=nMq+wDUp5N75U2iQfqZ6Td0TjY1zkVppECMKDHtWCHoThapWCAsCSmviksxBC7TxPMdECfGfYADZidc9BZ6LAt0+8czUzNFsPPIe6jCFu1mVJM6nxB8TBVqySqldAjMHSBPa/b6pQampMbIumfxJnVh7i4emSSjbg+7Hj2D3hvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; c=relaxed/simple; bh=+yVXS7454Sh1Jf02UggP0hD9+jM4HyKK2AjFU+7L+bg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nZp4pQmJMbjEW6NHy1PoOpRcy+lS2cyZs5+MZay4JoiPlyDH30tZnqjtRSoz3oS4e0SWOtltN1r2GxGfMjuMUAkBarBpnW6of6yxKekglkreciU3qiwX8DBPzU9MDA4B6mpn8i75FB+HGYyAsytGED7YbM5c3pcR5KCtjsKdOXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Fk/lcCyz; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Fk/lcCyz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1773266488; bh=+yVXS7454Sh1Jf02UggP0hD9+jM4HyKK2AjFU+7L+bg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Fk/lcCyzEEl7qmAJQWdJCiLppRjFzFZicCGVxHIetiBF/d+IGgmKIFEBk/HZgOW3C Kvx02UJmeZzDj/VA40jP87Vt/Mw6aRPVlZ5PmzdJMXjglfK+Jn45oT3g5rwO3bt3cg PCvirqKy2XH7t8NU3UuF5y6dLdoYio9KgtduvzPI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Mar 2026 23:00:50 +0100 Subject: [PATCH 2/4] selftests/nolibc: validate NOLIBC_IGNORE_ERRNO compilation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-nolibc-err-h-v1-2-735a9de7f15d@weissschuh.net> References: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> In-Reply-To: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773266488; l=1549; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=+yVXS7454Sh1Jf02UggP0hD9+jM4HyKK2AjFU+7L+bg=; b=thwH4L4fgLg7KziPs99NZupYfcCePC9XK0/7V/hDHbdEJ70fLlfCz23InMdNh8HZEQv/+pYjD s/g3GQtIs3RCBnkkLcz6lYgylSo9kPs8Slgp+RkrH2W2f9M/U1uGDb6 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= When NOLIBC_IGNORE_ERRNO is set, various bits of nolibc are disabled. Make sure that all the ifdeffery does not result in any compilation errors by compiling a dummy source file. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/nolibc/Makefile.include | 2 +- tools/testing/selftests/nolibc/nolibc-test-ignore-errno.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile.include b/tools/testin= g/selftests/nolibc/Makefile.include index 6455373d56be..41a0039f774c 100644 --- a/tools/testing/selftests/nolibc/Makefile.include +++ b/tools/testing/selftests/nolibc/Makefile.include @@ -9,4 +9,4 @@ CFLAGS_NOLIBC_TEST ?=3D -Os -fno-ident -fno-asynchronous-u= nwind-tables -std=3Dc89 - $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-protot= ypes) \ $(_CFLAGS_STACKPROTECTOR) $(_CFLAGS_SANITIZER) =20 -NOLIBC_TEST_SOURCES :=3D nolibc-test.c nolibc-test-linkage.c +NOLIBC_TEST_SOURCES :=3D nolibc-test.c nolibc-test-linkage.c nolibc-test-i= gnore-errno.c diff --git a/tools/testing/selftests/nolibc/nolibc-test-ignore-errno.c b/to= ols/testing/selftests/nolibc/nolibc-test-ignore-errno.c new file mode 100644 index 000000000000..aea816da4fca --- /dev/null +++ b/tools/testing/selftests/nolibc/nolibc-test-ignore-errno.c @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#define NOLIBC_IGNORE_ERRNO + +/* Include all of nolibc and make sure everything compiles */ +#include --=20 2.53.0 From nobody Tue Apr 7 19:50:52 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A284F1C2AA; Wed, 11 Mar 2026 22:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; cv=none; b=H2zZyEcM6hKJAeRxsRd/YDjKoBzlheAbVG5+voBXdcXJma5Y700Wd6rjNQMBy1oLKvABWM0VafjXACbN+opfaR4oUraVSF46xeEQd2Pnuka98r2N/4v+LSqcst72nbGH501/oce5Rh6C0PGGoeJE02z8poFC5dZ7kCH/O0U3GYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; c=relaxed/simple; bh=gckXH9wN4WIXeY1+31lpvhL4hO7sn1D+zyGAFN9lD04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u1z6A4jMz52ozPKraiF+ytz2k5VmgpKcNQh3EQSYAsjxIx82kQ8NQ6YPiFPJdIbs60ZcOGZjNGzyw6XzTE4CAtO1jLX0ixnboPYVD+KHuuP5jrGDoGgq3Eom3zqVteMNWtjfB7Fb/YkZS96lHRhDA1Zw7CW3Wro8/c349N02fG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=ptdQ1Fpg; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="ptdQ1Fpg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1773266488; bh=gckXH9wN4WIXeY1+31lpvhL4hO7sn1D+zyGAFN9lD04=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ptdQ1FpgBWytOzshHGOcgwcsDv9s7MPz8PPjN9cYIHH54GFqe6IG8nKLtDSlkNaJt 74YdNdx1OmcEqi60YVibNuzMOEmbKRg1qWNuoRJQe5t9bN/Et3iuiCSIZCkWiLKzVm NRhsqRQgmHPkEJ9ta+jrB5pgHRcYt5ypyO4M0gec= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Mar 2026 23:00:51 +0100 Subject: [PATCH 3/4] tools/nolibc: add support for program_invocation_{,short_}name Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-nolibc-err-h-v1-3-735a9de7f15d@weissschuh.net> References: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> In-Reply-To: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773266488; l=3886; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=gckXH9wN4WIXeY1+31lpvhL4hO7sn1D+zyGAFN9lD04=; b=fE2YwWpNIEJqNHEcb/GNbND+fPrZJi0Dxw0sZFtCzCJRSBxmYa/j320jSibGoGHwaKvBbPFuc hB9T2qdhpO4BMnB+yppak8bFPFhsQEh04qKDsaB3ondZn6oPAjEKQFr X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add support for the GNU extensions 'program_invocation_name' and 'program_invocation_short_name'. These are useful to print error messages, which by convention include the program name. As these are global variables which take up memory even if not used, similar to 'errno', gate them behind NOLIBC_IGNORE_ERRNO. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/crt.h | 26 ++++++++++++++++++++++++= ++ tools/include/nolibc/errno.h | 2 ++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 3 files changed, 30 insertions(+) diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index d9262998dae9..842f86e41f2f 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -17,6 +17,7 @@ const unsigned long *_auxv __attribute__((weak)); void _start(void); static void __stack_chk_init(void); static void exit(int); +static char *strrchr(const char *s, int c); =20 extern void (*const __preinit_array_start[])(int, char **, char**) __attri= bute__((weak)); extern void (*const __preinit_array_end[])(int, char **, char**) __attribu= te__((weak)); @@ -27,6 +28,24 @@ extern void (*const __init_array_end[])(int, char **, ch= ar**) __attribute__((wea extern void (*const __fini_array_start[])(void) __attribute__((weak)); extern void (*const __fini_array_end[])(void) __attribute__((weak)); =20 +extern char *program_invocation_name __attribute__((weak)); +extern char *program_invocation_short_name __attribute__((weak)); + +static __inline__ +char *__nolibc_program_invocation_short_name(char *long_name) +{ + char *short_name; + + if (!long_name) + return NULL; + + short_name =3D strrchr(long_name, '/'); + if (!short_name || !short_name[0]) + return NULL; + + return short_name + 1; +} + void _start_c(long *sp); __attribute__((weak,used)) #if __nolibc_has_feature(undefined_behavior_sanitizer) @@ -76,6 +95,13 @@ void _start_c(long *sp) ; _auxv =3D auxv; =20 +#ifndef NOLIBC_IGNORE_ERRNO + if (argc > 0) { + program_invocation_name =3D argv[0]; + program_invocation_short_name =3D __nolibc_program_invocation_short_name= (argv[0]); + } +#endif /* NOLIBC_IGNORE_ERRNO */ + for (ctor_func =3D __preinit_array_start; ctor_func < __preinit_array_end= ; ctor_func++) (*ctor_func)(argc, argv, envp); for (ctor_func =3D __init_array_start; ctor_func < __init_array_end; ctor= _func++) diff --git a/tools/include/nolibc/errno.h b/tools/include/nolibc/errno.h index 08a33c40ec0c..64d9f9bc6539 100644 --- a/tools/include/nolibc/errno.h +++ b/tools/include/nolibc/errno.h @@ -15,6 +15,8 @@ #ifndef NOLIBC_IGNORE_ERRNO #define SET_ERRNO(v) do { errno =3D (v); } while (0) int errno __attribute__((weak)); +char *program_invocation_name __attribute__((weak)); +char *program_invocation_short_name __attribute__((weak)); #else #define SET_ERRNO(v) do { } while (0) #endif diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index a140c54e4d72..5565ada679cc 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -754,6 +754,8 @@ int run_startup(int min, int max) CASE_TEST(constructor); EXPECT_EQ(is_nolibc, constructor_test_value= , 0x3); break; CASE_TEST(linkage_errno); EXPECT_PTREQ(1, linkage_test_errno_addr(), = &errno); break; CASE_TEST(linkage_constr); EXPECT_EQ(1, linkage_test_constructor_test_= value, 0x3); break; + CASE_TEST(prog_name_nolibc); EXPECT_STREQ(is_nolibc, program_invocation_= short_name, "nolibc-test"); break; + CASE_TEST(prog_name_libc); EXPECT_STREQ(!is_nolibc, program_invocation= _short_name, "libc-test"); break; case __LINE__: return ret; /* must be last */ /* note: do not set any defaults so as to permit holes above */ --=20 2.53.0 From nobody Tue Apr 7 19:50:52 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D95835A387; Wed, 11 Mar 2026 22:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; cv=none; b=H5GVXKDYw5WlJ2KW6py71e7X/H8ZBV57CnJRX3tFvu89VSTI7m7M6jL2Q1QnspvF7R0Z5PMPyLuJSQB08acmVpad23HOatLwbr90SYmgMs7/MbMI9lky/iHuVBfn8IpCUTi6y4Jom9KOC8Uda5va+Z5PrI9kJYmwobMQiViqWdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773266492; c=relaxed/simple; bh=DQ9Zc0Q7xc6dZOq15nfDtuT6wEnkMqTtKK6Bhc6CYPI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RzUAQqYt0feDkv2DKg3h8xt8lStoWjvTEZJclQISciSe1kIUC9uHJE4gf2dawS0BVZTwhlbpEoEWyXdH02CbTUFe6eP6xUou6W34jjS/7VZjy69I/1GFb06QwJDrkQZeDZDEEQzQrkfFZqX1jlCA8OxSK0kaLg6mouA4g0/xENc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=Z1QaMm+U; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="Z1QaMm+U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1773266488; bh=DQ9Zc0Q7xc6dZOq15nfDtuT6wEnkMqTtKK6Bhc6CYPI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Z1QaMm+ULA5QJ+M8hUnN1h45YC142/a9fJMeBY/w66uB91mKSG3oPPF06la2fpDWz /7oK8QrPrO1UiVyNzf8/TcbRKrX/Df6CA+WCwHGQkhR6cFIv/zrxeLtBpkKPzHrQ94 0zjwMTSigBflEWaqaR6zRDvScrPGRGQHvYd4/O8g= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 11 Mar 2026 23:00:52 +0100 Subject: [PATCH 4/4] tools/nolibc: add err.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260311-nolibc-err-h-v1-4-735a9de7f15d@weissschuh.net> References: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> In-Reply-To: <20260311-nolibc-err-h-v1-0-735a9de7f15d@weissschuh.net> To: Willy Tarreau , Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773266488; l=3075; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=DQ9Zc0Q7xc6dZOq15nfDtuT6wEnkMqTtKK6Bhc6CYPI=; b=Ns1nx88qAYwjYB7FtBsijU3e5BA1Kgpt9MbVs6r0CCOKTnwwXVE3bstzF0UCqIb7hf0I8YgAg EMC8+Q5wZ8BDRN3Q0pCLQMAjJyrUqr7KnhdEh5Jm/mGILfjXN+0w03L X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Add a few convenient helpers to print error and warning messages. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/err.h | 91 +++++++++++++++++++++++++++++++++++++++= ++++ tools/include/nolibc/nolibc.h | 1 + 3 files changed, 93 insertions(+) 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 :=3D \ ctype.h \ dirent.h \ elf.h \ + err.h \ errno.h \ fcntl.h \ getopt.h \ diff --git a/tools/include/nolibc/err.h b/tools/include/nolibc/err.h new file mode 100644 index 000000000000..2373c4999b71 --- /dev/null +++ b/tools/include/nolibc/err.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * formatted error message for NOLIBC + * Copyright (C) 2026 Thomas Wei=C3=9Fschuh + */ + +/* make sure to include all global symbols */ +#include "nolibc.h" + +#ifndef _NOLIBC_ERR_H +#define _NOLIBC_ERR_H + +#include "errno.h" +#include "stdarg.h" +#include "sys.h" + +static __attribute__((unused)) +void vwarn(const char *fmt, va_list args) +{ +#ifndef NOLIBC_IGNORE_ERRNO + fprintf(stderr, "%s: ", program_invocation_short_name); +#endif + vfprintf(stderr, fmt, args); + fprintf(stderr, ": %m\n"); +} + +static __attribute__((unused)) +void vwarnx(const char *fmt, va_list args) +{ +#ifndef NOLIBC_IGNORE_ERRNO + fprintf(stderr, "%s: ", program_invocation_short_name); +#endif + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); +} + +static __attribute__((unused)) +void warn(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vwarn(fmt, args); + va_end(args); +} + +static __attribute__((unused)) +void warnx(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vwarnx(fmt, args); + va_end(args); +} + +static __attribute__((noreturn, unused)) +void verr(int eval, const char *fmt, va_list args) +{ + vwarn(fmt, args); + exit(eval); +} + +static __attribute__((noreturn, unused)) +void verrx(int eval, const char *fmt, va_list args) +{ + warnx(fmt, args); + exit(eval); +} + +static __attribute__((noreturn, unused)) +void err(int eval, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + verr(eval, fmt, args); + va_end(args); +} + +static __attribute__((noreturn, unused)) +void errx(int eval, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + verrx(eval, fmt, args); + va_end(args); +} + +#endif /* _NOLIBC_ERR_H */ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index d1d08b7f8599..fe8195483b6d 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -130,6 +130,7 @@ #include "getopt.h" #include "poll.h" #include "math.h" +#include "err.h" =20 /* Used by programs to avoid std includes */ #define NOLIBC --=20 2.53.0