* [PATCH 0/2] tools/nolibc: avoid -Wundef warnings
@ 2026-03-18 16:12 Thomas Weißschuh
2026-03-18 16:12 ` [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ Thomas Weißschuh
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-03-18 16:12 UTC (permalink / raw)
To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh
Make sure nolibc does not trigger -Wundef warnings.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Thomas Weißschuh (2):
tools/nolibc: avoid -Wundef warning for __STDC_VERSION__
selftests/nolibc: enable -Wundef
tools/include/nolibc/compiler.h | 8 +++++++-
tools/testing/selftests/nolibc/Makefile.include | 3 ++-
2 files changed, 9 insertions(+), 2 deletions(-)
---
base-commit: d59131de97ee69ab4e4b8926089a6e953d699b11
change-id: 20260318-nolibc-wundef-fee232c29559
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ 2026-03-18 16:12 [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Thomas Weißschuh @ 2026-03-18 16:12 ` Thomas Weißschuh 2026-03-19 10:24 ` David Laight 2026-03-18 16:12 ` [PATCH 2/2] selftests/nolibc: enable -Wundef Thomas Weißschuh 2026-03-22 8:40 ` [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Willy Tarreau 2 siblings, 1 reply; 6+ messages in thread From: Thomas Weißschuh @ 2026-03-18 16:12 UTC (permalink / raw) To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh With -std=c89 the macro __STDC_VERSION__ is not defined. While undefined identifiers in '#if' directives are assumed to be '0', with -Wundef a warning is emitted. Avoid the warning by explicitly falling back to '0' if __STDC_VERSION__ is not provided by the preprocessor. Fixes: 37219aa5b123 ("tools/nolibc: add __nolibc_static_assert()") Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- tools/include/nolibc/compiler.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h index f03f84cfadce..dac09badff0a 100644 --- a/tools/include/nolibc/compiler.h +++ b/tools/include/nolibc/compiler.h @@ -47,6 +47,12 @@ # define __nolibc_fallthrough do { } while (0) #endif /* __nolibc_has_attribute(fallthrough) */ +#ifdef __STDC_VERSION__ +# define __nolibc_stdc_version __STDC_VERSION__ +#else +# define __nolibc_stdc_version 0 +#endif + #define __nolibc_version(_major, _minor, _patch) ((_major) * 10000 + (_minor) * 100 + (_patch)) #ifdef __GNUC__ @@ -63,7 +69,7 @@ # define __nolibc_clang_version 0 #endif /* __clang__ */ -#if __STDC_VERSION__ >= 201112L || \ +#if __nolibc_stdc_version >= 201112L || \ __nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \ __nolibc_clang_version >= __nolibc_version(3, 0, 0) # define __nolibc_static_assert(_t) _Static_assert(_t, "") -- 2.53.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ 2026-03-18 16:12 ` [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ Thomas Weißschuh @ 2026-03-19 10:24 ` David Laight 2026-03-20 20:38 ` Thomas Weißschuh 0 siblings, 1 reply; 6+ messages in thread From: David Laight @ 2026-03-19 10:24 UTC (permalink / raw) To: Thomas Weißschuh; +Cc: Willy Tarreau, linux-kernel On Wed, 18 Mar 2026 17:12:42 +0100 Thomas Weißschuh <linux@weissschuh.net> wrote: > With -std=c89 the macro __STDC_VERSION__ is not defined. > While undefined identifiers in '#if' directives are assumed to be '0', > with -Wundef a warning is emitted. > > Avoid the warning by explicitly falling back to '0' if __STDC_VERSION__ > is not provided by the preprocessor. > > Fixes: 37219aa5b123 ("tools/nolibc: add __nolibc_static_assert()") > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > tools/include/nolibc/compiler.h | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h > index f03f84cfadce..dac09badff0a 100644 > --- a/tools/include/nolibc/compiler.h > +++ b/tools/include/nolibc/compiler.h > @@ -47,6 +47,12 @@ > # define __nolibc_fallthrough do { } while (0) > #endif /* __nolibc_has_attribute(fallthrough) */ > > +#ifdef __STDC_VERSION__ > +# define __nolibc_stdc_version __STDC_VERSION__ > +#else > +# define __nolibc_stdc_version 0 > +#endif How about: #ifndef __STDC_VERSION__ #define __STDC_VERSION__ 198900 #endif David > + > #define __nolibc_version(_major, _minor, _patch) ((_major) * 10000 + (_minor) * 100 + (_patch)) > > #ifdef __GNUC__ > @@ -63,7 +69,7 @@ > # define __nolibc_clang_version 0 > #endif /* __clang__ */ > > -#if __STDC_VERSION__ >= 201112L || \ > +#if __nolibc_stdc_version >= 201112L || \ > __nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \ > __nolibc_clang_version >= __nolibc_version(3, 0, 0) > # define __nolibc_static_assert(_t) _Static_assert(_t, "") > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ 2026-03-19 10:24 ` David Laight @ 2026-03-20 20:38 ` Thomas Weißschuh 0 siblings, 0 replies; 6+ messages in thread From: Thomas Weißschuh @ 2026-03-20 20:38 UTC (permalink / raw) To: David Laight; +Cc: Willy Tarreau, linux-kernel On 2026-03-19 10:24:14+0000, David Laight wrote: > On Wed, 18 Mar 2026 17:12:42 +0100 > Thomas Weißschuh <linux@weissschuh.net> wrote: > > > With -std=c89 the macro __STDC_VERSION__ is not defined. > > While undefined identifiers in '#if' directives are assumed to be '0', > > with -Wundef a warning is emitted. > > > > Avoid the warning by explicitly falling back to '0' if __STDC_VERSION__ > > is not provided by the preprocessor. > > > > Fixes: 37219aa5b123 ("tools/nolibc: add __nolibc_static_assert()") > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > > --- > > tools/include/nolibc/compiler.h | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/tools/include/nolibc/compiler.h b/tools/include/nolibc/compiler.h > > index f03f84cfadce..dac09badff0a 100644 > > --- a/tools/include/nolibc/compiler.h > > +++ b/tools/include/nolibc/compiler.h > > @@ -47,6 +47,12 @@ > > # define __nolibc_fallthrough do { } while (0) > > #endif /* __nolibc_has_attribute(fallthrough) */ > > > > +#ifdef __STDC_VERSION__ > > +# define __nolibc_stdc_version __STDC_VERSION__ > > +#else > > +# define __nolibc_stdc_version 0 > > +#endif > > How about: > #ifndef __STDC_VERSION__ > #define __STDC_VERSION__ 198900 > #endif That may break applications, so I'd rather not do it. > > + > > #define __nolibc_version(_major, _minor, _patch) ((_major) * 10000 + (_minor) * 100 + (_patch)) > > > > #ifdef __GNUC__ > > @@ -63,7 +69,7 @@ > > # define __nolibc_clang_version 0 > > #endif /* __clang__ */ > > > > -#if __STDC_VERSION__ >= 201112L || \ > > +#if __nolibc_stdc_version >= 201112L || \ > > __nolibc_gnuc_version >= __nolibc_version(4, 6, 0) || \ > > __nolibc_clang_version >= __nolibc_version(3, 0, 0) > > # define __nolibc_static_assert(_t) _Static_assert(_t, "") > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] selftests/nolibc: enable -Wundef 2026-03-18 16:12 [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Thomas Weißschuh 2026-03-18 16:12 ` [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ Thomas Weißschuh @ 2026-03-18 16:12 ` Thomas Weißschuh 2026-03-22 8:40 ` [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Willy Tarreau 2 siblings, 0 replies; 6+ messages in thread From: Thomas Weißschuh @ 2026-03-18 16:12 UTC (permalink / raw) To: Willy Tarreau; +Cc: linux-kernel, Thomas Weißschuh Users might use -Wundef, so also use it in the nolibc testsuite to ensure no warnings are triggered. The existing line with warning options is getting too long, so move all warnings to a dedicated line. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- tools/testing/selftests/nolibc/Makefile.include | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/Makefile.include b/tools/testing/selftests/nolibc/Makefile.include index 41a0039f774c..96fe2bc2191e 100644 --- a/tools/testing/selftests/nolibc/Makefile.include +++ b/tools/testing/selftests/nolibc/Makefile.include @@ -5,7 +5,8 @@ _CFLAGS_STACKPROTECTOR ?= $(call try-run, \ echo 'void foo(void) {}' | $(CC) -x c - -o - -S $(CLANG_CROSS_FLAGS) $(__CFLAGS_STACKPROTECTOR) | grep -q __stack_chk_guard, \ $(__CFLAGS_STACKPROTECTOR)) _CFLAGS_SANITIZER ?= $(call cc-option,-fsanitize=undefined -fsanitize-trap=all) -CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \ +CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \ + -W -Wall -Wextra -Wundef \ $(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \ $(_CFLAGS_STACKPROTECTOR) $(_CFLAGS_SANITIZER) -- 2.53.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] tools/nolibc: avoid -Wundef warnings 2026-03-18 16:12 [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Thomas Weißschuh 2026-03-18 16:12 ` [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ Thomas Weißschuh 2026-03-18 16:12 ` [PATCH 2/2] selftests/nolibc: enable -Wundef Thomas Weißschuh @ 2026-03-22 8:40 ` Willy Tarreau 2 siblings, 0 replies; 6+ messages in thread From: Willy Tarreau @ 2026-03-22 8:40 UTC (permalink / raw) To: Thomas Weißschuh; +Cc: linux-kernel On Wed, Mar 18, 2026 at 05:12:41PM +0100, Thomas Weißschuh wrote: > Make sure nolibc does not trigger -Wundef warnings. > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Yeah I think it's fairly reasonable like this. For the whole series: Acked-by: Willy Tarreau <w@1wt.eu> Thanks! Willy ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-22 8:40 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-18 16:12 [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Thomas Weißschuh 2026-03-18 16:12 ` [PATCH 1/2] tools/nolibc: avoid -Wundef warning for __STDC_VERSION__ Thomas Weißschuh 2026-03-19 10:24 ` David Laight 2026-03-20 20:38 ` Thomas Weißschuh 2026-03-18 16:12 ` [PATCH 2/2] selftests/nolibc: enable -Wundef Thomas Weißschuh 2026-03-22 8:40 ` [PATCH 0/2] tools/nolibc: avoid -Wundef warnings Willy Tarreau
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox