From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 1C5D4260592 for ; Tue, 7 Apr 2026 07:15:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775546139; cv=none; b=SLwT/iM1a9WGY8M//Qnr70DmWyCrEABnv8DyZu4O9jfb236lJkOwGW864illCUl+AV4H9pnoNIju2vNQntNPgeU3VQQs3gqK9uw6sQprEX0joNDgFMRnT3YM0Kq+2PxitJqkdZuOUn3Syri6tPWAaw9sR9Kg8ObTbX1M7UvI9no= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775546139; c=relaxed/simple; bh=cK722I2NJspQ7RvZY0TIfwKGto6ERrDhyoe1QpS3JwU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YXpenoqr/d+KJu6kbsrfRviH5k7NyzCawLchU25QBtZX7uaBL9KrXBDDo+GqXlvyfcq+Y7FfSLtWRMCwT5HAJvwkpmWfNW8rPcEUMAa+UXv6fvQdfjCoEyO3qKu2a0l8t+6EU+F4Nowe/IzwK83o5z6a8+JMC3bW4h2mYKaB+i4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=M8j4Xqfu; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="M8j4Xqfu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1775546128; bh=FnIwBZYAHQDjBAOO+tD1uvoPZFjgnTfasE7YREfVhb0=; h=From:Message-ID:From; b=M8j4XqfuVdsA9MYG24Evu1ikdcCrDoyouZ8ioPFdF902liTRWhyEXXU7LzlXy5BN1 T0xdUIjHGSMf6v5KE7L13Yd+qldddww+21eSBZRPYtQwhSrr0EvMEuiyYh0SL7hLWH E/tZH3THDLnAdyujEbKc2qQLT8CAq5p4fESpZMkI= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 913FCC0A92; Tue, 07 Apr 2026 09:15:28 +0200 (CEST) Date: Tue, 7 Apr 2026 09:15:28 +0200 From: Willy Tarreau To: Thomas =?iso-8859-1?Q?Wei=DFschuh?= Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/nolibc: make __nolibc_enosys() a compile time error Message-ID: References: <20260404-nolibc-enosys-v1-1-e0aba47bdee4@weissschuh.net> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260404-nolibc-enosys-v1-1-e0aba47bdee4@weissschuh.net> Hi Thomas, On Sat, Apr 04, 2026 at 05:26:05PM +0200, Thomas Weißschuh wrote: > 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ßschuh > --- > 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 */ \ > }) > > -/* Syscall ENOSYS helper: Avoids unused-parameter warnings and provides a > - * debugging hook. > +/* Syscall ENOSYS helper: Avoids unused-parameter warnings, provides compile > + * time validation and a debugging hook. > */ > > +#if defined(NOLIBC_COMPILE_TIME_ENOSYS) > static __inline__ int __nolibc_enosys(const char *syscall, ...) > { > (void)syscall; > return -ENOSYS; > } > > +#elif __nolibc_has_attribute(error) > +__attribute__((error("system call not implemented"))) > +extern int __nolibc_enosys(const char *syscall, ...); I didn't know it was possible to force the error message like this, I like it! > +#else > +static __inline__ int __nolibc_enosys(const char *syscall, ...) > +{ > + extern int __nolibc_enosys_error; > + (void)syscall; > + > + return __nolibc_enosys_error; > +} > +#endif > > /* Functions in this file only describe syscalls. They're declared static so > * that the compiler usually decides to inline them while still being allowed > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/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; > } > > +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") != -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, EINVAL); break; > CASE_TEST(mmap_munmap_good); EXPECT_SYSZR(1, test_mmap_munmap()); break; > CASE_TEST(nanosleep); ts.tv_nsec = -1; EXPECT_SYSER(1, nanosleep(&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 = open("/dev/null", O_RDONLY), -1); if (tmp != -1) close(tmp); break; > CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", O_RDONLY), -1, ENOENT); if (tmp != -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, > -- > Thomas Weißschuh Acked-by: Willy Tarreau Thanks! Willy