From nobody Sun Jun 14 19:01:34 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 B62E6C8E6 for ; Sat, 4 Apr 2026 15:26:11 +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=1775316373; cv=none; b=e6jk2VirfHQ29R22MuSwg32WIHV36X1huh4hmdnqeC/SLHsQ8882y1xHQ15C+yQOpj+9TG5wAbtV+H9FmSOrQ5Yp921IqCVjeEauCxGZwYsa98lHoekm3NRonQ3h6b+Q6LB/9vTS9o8L1HB1PvwSbpevoHrPwiXWjNmbIBecUME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775316373; c=relaxed/simple; bh=pO9bRi49KNqeswgP1aqJ3TTT/tnGtuyrIcbpUfFhLvg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=mAZ0mYnt7UkGfFkkef0sdDT6m89bqd4lgGenHCmynQsT6lcXhXmZK/j8AwovuDg+1HDiGPF9xLiFeNx/H4nqnEn8tt1U7A/wRZaivzhrchH76k+uVzzq2VbpQsEMLJGInrv6Db/3ctb5de5V6p4bJmP2kJlypp5CWcZYo/B6F54= 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=gMQPgTOF; 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="gMQPgTOF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1775316369; bh=pO9bRi49KNqeswgP1aqJ3TTT/tnGtuyrIcbpUfFhLvg=; h=From:Date:Subject:To:Cc:From; b=gMQPgTOFiWbWeOk/UnyFTNvtPWN51F18u5u0oPIqggZeZJhQIMSHmR44jxiAs16ff y+EZ9c7uv5xQWgnUwzlcDPLnSJjcUMvJRUNcCtP79fogVcBZbOw5NPtpwZS8Fon5K4 2FZY22PM5hoRVWrbIoEhTOLFyE0WudSqdE6wAfv4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sat, 04 Apr 2026 17:26:05 +0200 Subject: [PATCH] tools/nolibc: make __nolibc_enosys() a compile time error 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: <20260404-nolibc-enosys-v1-1-e0aba47bdee4@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDEwMT3bz8nMykZN3UvPziymLdFDMDw+Rkc9PEJCNLJaCegqLUtMwKsHn RsRB+cWlSVmpyCcgQpdpaAGwAghlxAAAA X-Change-ID: 20260404-nolibc-enosys-d601cc75ab29 To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775316369; l=3834; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=pO9bRi49KNqeswgP1aqJ3TTT/tnGtuyrIcbpUfFhLvg=; b=1B2PEkJrN3h8j1hK1UapyYpEMw3/4BNfhWRRA/D9SlOA8FzfqWeFJpJqBSjyfJcBYugfLScxu 4bhYZvvXHnWB3WONMvyFapLnlsUufxpvd7mOK1/R5D7aLc6dZyb9Kta X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Functions which are known at compile-time to result in ENOSYS can be surprising to the user. For example using old UAPI headers might mean that stat() will always fail although the kernel would have the system call available at runtime. Nowadays __nolibc_enosys() should never be called for normal applications. Switch the silent ENOSYS return into a compile-time error, so the user is aware about the issue. Prefer the 'error' attribute as it provides the best diagnostics. If the users defines NOLIBC_COMPILE_TIME_ENOSYS the old, silent fallback is kept. Also add a test which validates that the error can be optimized away. Reported-by: Willy Tarreau Closes: https://lore.kernel.org/lkml/acizRIq2xrFUNHNS@1wt.eu/ Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau --- This should probably go into the next cycle. --- tools/include/nolibc/sys.h | 18 ++++++++++++++++-- tools/testing/selftests/nolibc/nolibc-test.c | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 6335fd51f07f..fd7a2ee780e8 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -45,16 +45,30 @@ : __sysret_arg; /* return original value */ \ }) =20 -/* Syscall ENOSYS helper: Avoids unused-parameter warnings and provides a - * debugging hook. +/* Syscall ENOSYS helper: Avoids unused-parameter warnings, provides compi= le + * time validation and a debugging hook. */ =20 +#if defined(NOLIBC_COMPILE_TIME_ENOSYS) static __inline__ int __nolibc_enosys(const char *syscall, ...) { (void)syscall; return -ENOSYS; } =20 +#elif __nolibc_has_attribute(error) +__attribute__((error("system call not implemented"))) +extern int __nolibc_enosys(const char *syscall, ...); + +#else +static __inline__ int __nolibc_enosys(const char *syscall, ...) +{ + extern int __nolibc_enosys_error; + (void)syscall; + + return __nolibc_enosys_error; +} +#endif =20 /* Functions in this file only describe syscalls. They're declared static = so * that the compiler usually decides to inline them while still being allo= wed diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index dd10402267ee..fb7eaa26ca93 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1300,6 +1300,23 @@ int test_openat(void) return 0; } =20 +int test_nolibc_enosys(void) +{ + if (true) + return 0; + +#if defined(NOLIBC) + /* + * __nolibc_enosys() will fail the compilation. + * Make sure it can be optimized away if not actually called. + */ + if (__nolibc_enosys("something") !=3D -ENOSYS) + return 1; +#endif + + return 0; +} + int test_namespace(void) { int original_ns, new_ns, ret; @@ -1468,6 +1485,7 @@ int run_syscall(int min, int max) CASE_TEST(munmap_bad); EXPECT_SYSER(1, munmap(NULL, 0), -1, EINVA= L); break; CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break; CASE_TEST(nanosleep); ts.tv_nsec =3D -1; EXPECT_SYSER(1, nanosle= ep(&ts, NULL), -1, EINVAL); break; + CASE_TEST(nolibc_enosys); EXPECT_ZR(is_nolibc, test_nolibc_enosys())= ; break; CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp =3D open("/dev/null", = O_RDONLY), -1); if (tmp !=3D -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp =3D open("/proc/self/b= lah", O_RDONLY), -1, ENOENT); if (tmp !=3D -1) close(tmp); break; CASE_TEST(openat_dir); EXPECT_SYSZR(1, test_openat()); break; --- base-commit: 74986b90eaf3f0ec38bd54de4851063616b49486 change-id: 20260404-nolibc-enosys-d601cc75ab29 Best regards, -- =20 Thomas Wei=C3=9Fschuh