public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Willy Tarreau <w@1wt.eu>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: make __nolibc_enosys() a compile time error
Date: Tue, 7 Apr 2026 12:02:50 +0100	[thread overview]
Message-ID: <20260407120250.515db167@pumpkin> (raw)
In-Reply-To: <adSvEI9M9rfS5bzd@1wt.eu>

On Tue, 7 Apr 2026 09:15:28 +0200
Willy Tarreau <w@1wt.eu> wrote:

> 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 <w@1wt.eu>
> > Closes: https://lore.kernel.org/lkml/acizRIq2xrFUNHNS@1wt.eu/
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> > 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!

Look at __compiletime_assert() in include/linux/compiler_types.h

If you try a bit harder it should be possible to get the system call
name into the error message.
Perhaps something like:
#define __nolibc__enosys(syscall, name, ...) ({ \
	void __nolibc_enosys_##name(...) __attribute__((error("system call " #name " not implemented"))); \
	__nolibc_enosys_##name(__VA_ARGS__); \
	-ENOSYS; \
})

	David

      reply	other threads:[~2026-04-07 11:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-04 15:26 [PATCH] tools/nolibc: make __nolibc_enosys() a compile time error Thomas Weißschuh
2026-04-07  7:15 ` Willy Tarreau
2026-04-07 11:02   ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260407120250.515db167@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox