public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/nolibc: Fix build with host headers and libc
@ 2026-02-14 11:57 david.laight.linux
  2026-02-16 18:51 ` Thomas Weißschuh
  0 siblings, 1 reply; 5+ messages in thread
From: david.laight.linux @ 2026-02-14 11:57 UTC (permalink / raw)
  To: Willy Tarreau, Thomas Weißschuh, linux-kernel, Cheng Li; +Cc: David Laight

From: David Laight <david.laight.linux@gmail.com>

Many systems don't have strlcpy() or strlcat().
Change is_nolibc to a #define so that the calls are optimised out.
Create #define wrappers so the code is syntactially valid.

Additionall readdir_r() is likely to be marked deprecated.
So disable "-Wdeprecated-declarations".

Fixes: 6fe8360b16acb  ("selftests/nolibc: also test libc-test through regular selftest framework")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 1b9d3b2e2491..eb2421b42e75 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -66,13 +66,18 @@ static const char *argv0;
 /* will be used by constructor tests */
 static int constructor_test_value;
 
-static const int is_nolibc =
 #ifdef NOLIBC
-	1
+#define is_nolibc 1
 #else
-	0
+#define is_nolibc 0
+/* strlcat() and strlcpy() may not be in the system headers. */
+#undef strlcat
+#undef strlcpy
+#define strlcat(d, s, l) 0
+#define strlcpy(d, s, l) 0
+/* readdir_r() is likely to be marked deprecated */
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 #endif
-;
 
 /* definition of a series of tests */
 struct test {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests/nolibc: Fix build with host headers and libc
  2026-02-14 11:57 [PATCH] selftests/nolibc: Fix build with host headers and libc david.laight.linux
@ 2026-02-16 18:51 ` Thomas Weißschuh
  2026-02-16 22:21   ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2026-02-16 18:51 UTC (permalink / raw)
  To: david.laight.linux; +Cc: Willy Tarreau, linux-kernel, Cheng Li

On 2026-02-14 11:57:24+0000, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
> 
> Many systems don't have strlcpy() or strlcat().
> Change is_nolibc to a #define so that the calls are optimised out.
> Create #define wrappers so the code is syntactially valid.
> 
> Additionall readdir_r() is likely to be marked deprecated.

"Additionally"

> So disable "-Wdeprecated-declarations".

Could you split this into multiple patches?

> Fixes: 6fe8360b16acb  ("selftests/nolibc: also test libc-test through regular selftest framework")
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 1b9d3b2e2491..eb2421b42e75 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -66,13 +66,18 @@ static const char *argv0;
>  /* will be used by constructor tests */
>  static int constructor_test_value;
>  
> -static const int is_nolibc =
>  #ifdef NOLIBC
> -	1
> +#define is_nolibc 1
>  #else
> -	0
> +#define is_nolibc 0
> +/* strlcat() and strlcpy() may not be in the system headers. */
> +#undef strlcat
> +#undef strlcpy
> +#define strlcat(d, s, l) 0
> +#define strlcpy(d, s, l) 0
> +/* readdir_r() is likely to be marked deprecated */
> +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
>  #endif

I'd prefer to disable this via $(cc-option) in the Makefile.
Unknown pragmas tend to introduce more warnings.

> -;
>  
>  /* definition of a series of tests */
>  struct test {
> -- 
> 2.39.5
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests/nolibc: Fix build with host headers and libc
  2026-02-16 18:51 ` Thomas Weißschuh
@ 2026-02-16 22:21   ` David Laight
  2026-02-18 17:23     ` Thomas Weißschuh
  0 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2026-02-16 22:21 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Willy Tarreau, linux-kernel, Cheng Li

On Mon, 16 Feb 2026 19:51:24 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:

> On 2026-02-14 11:57:24+0000, david.laight.linux@gmail.com wrote:
> > From: David Laight <david.laight.linux@gmail.com>
> > 
> > Many systems don't have strlcpy() or strlcat().
> > Change is_nolibc to a #define so that the calls are optimised out.
> > Create #define wrappers so the code is syntactially valid.
> > 
> > Additionall readdir_r() is likely to be marked deprecated.  
> 
> "Additionally"
> 
> > So disable "-Wdeprecated-declarations".  
> 
> Could you split this into multiple patches?
> 
> > Fixes: 6fe8360b16acb  ("selftests/nolibc: also test libc-test through regular selftest framework")
> > Signed-off-by: David Laight <david.laight.linux@gmail.com>
> > ---
> >  tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 1b9d3b2e2491..eb2421b42e75 100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > @@ -66,13 +66,18 @@ static const char *argv0;
> >  /* will be used by constructor tests */
> >  static int constructor_test_value;
> >  
> > -static const int is_nolibc =
> >  #ifdef NOLIBC
> > -	1
> > +#define is_nolibc 1
> >  #else
> > -	0
> > +#define is_nolibc 0
> > +/* strlcat() and strlcpy() may not be in the system headers. */
> > +#undef strlcat
> > +#undef strlcpy
> > +#define strlcat(d, s, l) 0
> > +#define strlcpy(d, s, l) 0
> > +/* readdir_r() is likely to be marked deprecated */
> > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> >  #endif  
> 
> I'd prefer to disable this via $(cc-option) in the Makefile.
> Unknown pragmas tend to introduce more warnings.

There is already a similar pragma in the file and this one isn't a new one warning.
The other option is to disable the test for !is_nolibc and #define readir_r() away.

That may not need is_nolibc changing to be a #define.

	David

> 
> > -;
> >  
> >  /* definition of a series of tests */
> >  struct test {
> > -- 
> > 2.39.5
> >   


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests/nolibc: Fix build with host headers and libc
  2026-02-16 22:21   ` David Laight
@ 2026-02-18 17:23     ` Thomas Weißschuh
  2026-02-18 22:51       ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2026-02-18 17:23 UTC (permalink / raw)
  To: David Laight; +Cc: Willy Tarreau, linux-kernel, Cheng Li

On 2026-02-16 22:21:18+0000, David Laight wrote:
> On Mon, 16 Feb 2026 19:51:24 +0100
> Thomas Weißschuh <linux@weissschuh.net> wrote:
> 
> > On 2026-02-14 11:57:24+0000, david.laight.linux@gmail.com wrote:
> > > From: David Laight <david.laight.linux@gmail.com>
> > > 
> > > Many systems don't have strlcpy() or strlcat().
> > > Change is_nolibc to a #define so that the calls are optimised out.
> > > Create #define wrappers so the code is syntactially valid.
> > > 
> > > Additionall readdir_r() is likely to be marked deprecated.  
> > 
> > "Additionally"
> > 
> > > So disable "-Wdeprecated-declarations".  
> > 
> > Could you split this into multiple patches?
> > 
> > > Fixes: 6fe8360b16acb  ("selftests/nolibc: also test libc-test through regular selftest framework")
> > > Signed-off-by: David Laight <david.laight.linux@gmail.com>
> > > ---
> > >  tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
> > >  1 file changed, 9 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > > index 1b9d3b2e2491..eb2421b42e75 100644
> > > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > > @@ -66,13 +66,18 @@ static const char *argv0;
> > >  /* will be used by constructor tests */
> > >  static int constructor_test_value;
> > >  
> > > -static const int is_nolibc =
> > >  #ifdef NOLIBC
> > > -	1
> > > +#define is_nolibc 1
> > >  #else
> > > -	0
> > > +#define is_nolibc 0
> > > +/* strlcat() and strlcpy() may not be in the system headers. */
> > > +#undef strlcat
> > > +#undef strlcpy
> > > +#define strlcat(d, s, l) 0
> > > +#define strlcpy(d, s, l) 0
> > > +/* readdir_r() is likely to be marked deprecated */
> > > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> > >  #endif  
> > 
> > I'd prefer to disable this via $(cc-option) in the Makefile.
> > Unknown pragmas tend to introduce more warnings.
> 
> There is already a similar pragma in the file and this one isn't a new one warning.

Fair enough, then this is fine. Maybe I'll clean it up at some point.

(...)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] selftests/nolibc: Fix build with host headers and libc
  2026-02-18 17:23     ` Thomas Weißschuh
@ 2026-02-18 22:51       ` David Laight
  0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2026-02-18 22:51 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Willy Tarreau, linux-kernel, Cheng Li

On Wed, 18 Feb 2026 18:23:33 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:

> On 2026-02-16 22:21:18+0000, David Laight wrote:
> > On Mon, 16 Feb 2026 19:51:24 +0100
> > Thomas Weißschuh <linux@weissschuh.net> wrote:
> >   
> > > On 2026-02-14 11:57:24+0000, david.laight.linux@gmail.com wrote:  
> > > > From: David Laight <david.laight.linux@gmail.com>
> > > > 
> > > > Many systems don't have strlcpy() or strlcat().
> > > > Change is_nolibc to a #define so that the calls are optimised out.
> > > > Create #define wrappers so the code is syntactially valid.
> > > > 
> > > > Additionall readdir_r() is likely to be marked deprecated.    
> > > 
> > > "Additionally"
> > >   
> > > > So disable "-Wdeprecated-declarations".    
> > > 
> > > Could you split this into multiple patches?
> > >   
> > > > Fixes: 6fe8360b16acb  ("selftests/nolibc: also test libc-test through regular selftest framework")
> > > > Signed-off-by: David Laight <david.laight.linux@gmail.com>
> > > > ---
> > > >  tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
> > > >  1 file changed, 9 insertions(+), 4 deletions(-)
> > > > 
> > > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > > > index 1b9d3b2e2491..eb2421b42e75 100644
> > > > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > > > @@ -66,13 +66,18 @@ static const char *argv0;
> > > >  /* will be used by constructor tests */
> > > >  static int constructor_test_value;
> > > >  
> > > > -static const int is_nolibc =
> > > >  #ifdef NOLIBC
> > > > -	1
> > > > +#define is_nolibc 1
> > > >  #else
> > > > -	0
> > > > +#define is_nolibc 0
> > > > +/* strlcat() and strlcpy() may not be in the system headers. */
> > > > +#undef strlcat
> > > > +#undef strlcpy
> > > > +#define strlcat(d, s, l) 0
> > > > +#define strlcpy(d, s, l) 0
> > > > +/* readdir_r() is likely to be marked deprecated */
> > > > +#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
> > > >  #endif    
> > > 
> > > I'd prefer to disable this via $(cc-option) in the Makefile.
> > > Unknown pragmas tend to introduce more warnings.  
> > 
> > There is already a similar pragma in the file and this one isn't a new one warning.  
> 
> Fair enough, then this is fine. Maybe I'll clean it up at some point.

That one is actually to avoid the warnings for a visible function with no prototype.

The readir_r() test is probably best made is_nolibc only and a #define used
so that the code compiles.
Changing is_nolibc to #define isn't enough to help either.
It isn't needed if the strcpy/strlcat/readdir_r are #defined away.

	David


> 
> (...)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-18 22:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-14 11:57 [PATCH] selftests/nolibc: Fix build with host headers and libc david.laight.linux
2026-02-16 18:51 ` Thomas Weißschuh
2026-02-16 22:21   ` David Laight
2026-02-18 17:23     ` Thomas Weißschuh
2026-02-18 22:51       ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox