mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Willy Tarreau <w@1wt.eu>
Cc: Benjamin Berg <benjamin@sipsolutions.net>,
	 linux-um@lists.infradead.org, linux-kselftest@vger.kernel.org,
	 Arnaldo Carvalho de Melo <acme@redhat.com>,
	linux-kernel@vger.kernel.org,
	 Benjamin Berg <benjamin.berg@intel.com>
Subject: Re: [PATCH v2 03/11] tools/nolibc/stdio: remove perror if NOLIBC_IGNORE_ERRNO is set
Date: Sun, 21 Sep 2025 18:37:30 +0200	[thread overview]
Message-ID: <c10503a9-5c63-44a8-9ea7-a7bf6c4ed3fb@t-8ch.de> (raw)
In-Reply-To: <20250921075511.GA16684@1wt.eu>

On 2025-09-21 09:55:11+0200, Willy Tarreau wrote:
> Hi Benjamin,
> 
> On Fri, Sep 19, 2025 at 05:34:12PM +0200, Benjamin Berg wrote:
> > From: Benjamin Berg <benjamin.berg@intel.com>
> > 
> > There is no errno variable when NOLIBC_IGNORE_ERRNO is defined. As such,
> > the perror function does not make any sense then and cannot compile.
> > 
> > Fixes: acab7bcdb1bc ("tools/nolibc/stdio: add perror() to report the errno value")
> > Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
> > Acked-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> >  tools/include/nolibc/stdio.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
> > index 7630234408c5..c512159b8374 100644
> > --- a/tools/include/nolibc/stdio.h
> > +++ b/tools/include/nolibc/stdio.h
> > @@ -597,11 +597,13 @@ int sscanf(const char *str, const char *format, ...)
> >  	return ret;
> >  }
> >  
> > +#ifndef NOLIBC_IGNORE_ERRNO
> >  static __attribute__((unused))
> >  void perror(const char *msg)
> >  {
> >  	fprintf(stderr, "%s%serrno=%d\n", (msg && *msg) ? msg : "", (msg && *msg) ? ": " : "", errno);
> >  }
> > +#endif
> 
> Please instead place the ifndef inside the function so that code calling
> perror() continues to build. The original goal of that macro was to
> further shrink programs at the expense of losing error details. But we
> should be able to continue to build working programs with that macro
> defined. There's nothing hard set in stone regarding this but here it's
> easy to preserve a working behavior by having something like this for
> example:
> 
>   static __attribute__((unused))
>   void perror(const char *msg)
>   {
>  +#ifdef NOLIBC_IGNORE_ERRNO
>  + 	fprintf(stderr, "%s\n", (msg && *msg) ? msg : "unknown error");
>  +#else
>   	fprintf(stderr, "%s%serrno=%d\n", (msg && *msg) ? msg : "", (msg && *msg) ? ": " : "", errno);
>  +#endif
>   }

For the plain `errno` variable and printf(%m) we don't have such
fallbacks. With NOLIBC_IGNORE_ERRNO the compilation either fails or the
results are undefined. Personally I prefer not defining perror() here.


Thomas

  reply	other threads:[~2025-09-21 16:37 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-19 15:34 [PATCH v2 00/11] Start porting UML to nolibc Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 01/11] tools compiler.h: fix __used definition Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 02/11] um: use tools/include for user files Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 03/11] tools/nolibc/stdio: remove perror if NOLIBC_IGNORE_ERRNO is set Benjamin Berg
2025-09-21  7:55   ` Willy Tarreau
2025-09-21 16:37     ` Thomas Weißschuh [this message]
2025-09-21 17:05       ` Benjamin Berg
2025-09-21 17:13         ` Willy Tarreau
2025-09-21 17:16           ` Benjamin Berg
2025-09-21 17:23             ` Willy Tarreau
2025-09-21 18:26           ` Thomas Weißschuh
2025-09-21 18:28             ` Willy Tarreau
2025-09-21 17:09       ` Willy Tarreau
2025-09-19 15:34 ` [PATCH v2 04/11] tools/nolibc/dirent: avoid errno in readdir_r Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 05/11] tools/nolibc: use __fallthrough__ rather than fallthrough Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 06/11] tools/nolibc: add option to disable runtime Benjamin Berg
2025-09-20  9:08   ` Thomas Weißschuh
2025-09-19 15:34 ` [PATCH v2 07/11] um: add infrastructure to build files using nolibc Benjamin Berg
2025-09-21  8:13   ` Willy Tarreau
2025-09-22  7:11     ` Berg, Benjamin
2025-09-19 15:34 ` [PATCH v2 08/11] um: use nolibc for the --showconfig implementation Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 09/11] tools/nolibc: add uio.h with readv and writev Benjamin Berg
2025-09-20  9:11   ` Thomas Weißschuh
2025-09-19 15:34 ` [PATCH v2 10/11] tools/nolibc: add ptrace support Benjamin Berg
2025-09-20  9:27   ` Thomas Weißschuh
2025-09-21  8:19     ` Willy Tarreau
2025-09-19 15:34 ` [PATCH v2 11/11] um: switch ptrace FP register access to nolibc Benjamin Berg
2025-09-19 20:50   ` kernel test robot
2025-09-19 15:40 ` [PATCH v2 00/11] Start porting UML " Christoph Hellwig
2025-09-22  7:41   ` Johannes Berg
2025-09-23 23:58     ` Hajime Tazaki
2025-09-24  3:32       ` Willy Tarreau
2025-09-24  7:55         ` Benjamin Berg
2025-09-25  1:05         ` Hajime Tazaki
2025-09-20  9:30 ` Thomas Weißschuh

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=c10503a9-5c63-44a8-9ea7-a7bf6c4ed3fb@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=acme@redhat.com \
    --cc=benjamin.berg@intel.com \
    --cc=benjamin@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --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

all inboxes | Powered by JetHome®