Skip to contentSkip to conversation

selftests/nolibc: Fix build with host headers and libc

PATCH In review [email protected] 2 participants 5 messages Feb 14 – Feb 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/nolibc: Fix build with host headers and libc

From: David Laight <[email protected]>

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")
---
 tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +9 -4
index 1b9d3b2e2491..eb2421b42e75 100644
@@ -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 {
Signature · 1 line
2.39.5
#1 lore raw
Quoted 7 lines · On 2026-02-14 11:57:24+0000, [email protected] wrote:

From: David Laight <[email protected]>

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"

Quoted 1 line

So disable "-Wdeprecated-declarations".

Could you split this into multiple patches?

Quoted 19 lines
Fixes 6fe8360b16acb ("selftests/nolibc: also test libc-test through regular selftest framework")
---
 tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +1 -2
index 1b9d3b2e2491..eb2421b42e75 100644
@@ -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

tools/testing/selftests/nolibc/nolibc-test.c static const char *argv0; · line 80

Quoted 10 lines
tools/testing/selftests/nolibc/nolibc-test.c +8 -1
-	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.

Quoted 7 lines
tools/testing/selftests/nolibc/nolibc-test.c +0 -1
-;
 
 /* definition of a series of tests */
 struct test {
Signature · 1 line
2.39.5
#2 lore raw
Quoted 39 lines · On Mon, 16 Feb 2026 19:51:24 +0100 Thomas Weißschuh <[email protected]>…
Quoted 7 lines · On 2026-02-14 11:57:24+0000, [email protected] wrote:

From: David Laight <[email protected]>

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"

Quoted 1 line

So disable "-Wdeprecated-declarations".

Could you split this into multiple patches?

Quoted 24 lines
Fixes 6fe8360b16acb ("selftests/nolibc: also test libc-test through regular selftest framework")
---
 tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +5 -3
index 1b9d3b2e2491..eb2421b42e75 100644
@@ -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
Quoted 8 lines

tools/testing/selftests/nolibc/nolibc-test.c static const char *argv0; · line 80

Quoted 5 lines
tools/testing/selftests/nolibc/nolibc-test.c +4 -0
+#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

Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/nolibc/nolibc-test.c +0 -1
-;
 
 /* definition of a series of tests */
 struct test {
Signature · 1 line
2.39.5
#3 lore raw
Quoted 51 lines · David Laight
Quoted 39 lines · On Mon, 16 Feb 2026 19:51:24 +0100 Thomas Weißschuh <[email protected]>…
Quoted 7 lines · On 2026-02-14 11:57:24+0000, [email protected] wrote:

From: David Laight <[email protected]>

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"

Quoted 1 line

So disable "-Wdeprecated-declarations".

Could you split this into multiple patches?

Quoted 24 lines
Fixes 6fe8360b16acb ("selftests/nolibc: also test libc-test through regular selftest framework")
---
 tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +5 -3
index 1b9d3b2e2491..eb2421b42e75 100644
@@ -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
Quoted 8 lines

tools/testing/selftests/nolibc/nolibc-test.c static const char *argv0; · line 80

Quoted 5 lines
tools/testing/selftests/nolibc/nolibc-test.c +4 -0
+#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.

Quoted 1 line

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.

(...)

#4 lore raw
Quoted 52 lines · On Wed, 18 Feb 2026 18:23:33 +0100 Thomas Weißschuh <[email protected]>…
Quoted 51 lines · David Laight
Quoted 47 lines · On Mon, 16 Feb 2026 19:51:24 +0100 Thomas Weißschuh <[email protected]>…
Quoted 7 lines · On 2026-02-14 11:57:24+0000, [email protected] wrote:

From: David Laight <[email protected]>

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"

Quoted 1 line

So disable "-Wdeprecated-declarations".

Could you split this into multiple patches?

Quoted 19 lines
Fixes 6fe8360b16acb ("selftests/nolibc: also test libc-test through regular selftest framework")
---
 tools/testing/selftests/nolibc/nolibc-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/nolibc/nolibc-test.c +1 -2
index 1b9d3b2e2491..eb2421b42e75 100644
@@ -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

tools/testing/selftests/nolibc/nolibc-test.c static const char *argv0; · line 80

Quoted 10 lines
tools/testing/selftests/nolibc/nolibc-test.c +8 -1
-	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.

Quoted 3 lines
Quoted 1 line

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

Quoted 2 lines

(...)