Re: [PATCH v4 29/30] selftests/nolibc: Append extra cflags

From: Leo Yan

Date: Tue Mar 17 2026 - 07:03:54 EST


On Mon, Mar 16, 2026 at 11:27:41PM +0100, Thomas Weißschuh wrote:
> On 2026-03-11 08:29:54+0000, Leo Yan wrote:
> > Include tools/scripts/Makefile.include, which may provide additional
> > flags in EXTRA_CFLAGS, and append to CFLAGS.
> >
> > Since Makefile.include already defines cc-option, remove the redundant
> > definition and include.
> >
> > Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
> > ---
> > tools/testing/selftests/nolibc/Makefile | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
> > index 0370489d938b540721a4fb814ebb68c463760e73..d1a9c1d5988bdc6a8778ef418aaa4c5ac1d26a10 100644
> > --- a/tools/testing/selftests/nolibc/Makefile
> > +++ b/tools/testing/selftests/nolibc/Makefile
> > @@ -3,15 +3,13 @@
> > TEST_GEN_PROGS := nolibc-test libc-test
> >
> > include ../lib.mk
> > -include $(top_srcdir)/scripts/Makefile.compiler
> > -
> > -cc-option = $(call __cc-option, $(CC),,$(1),$(2))
> > +include $(top_srcdir)/tools/scripts/Makefile.include
> >
> > include Makefile.include
> >
> > $(OUTPUT)/nolibc-test: CFLAGS = -nostdlib -nostdinc -static \
> > -isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/include \
> > - $(CFLAGS_NOLIBC_TEST)
> > + $(CFLAGS_NOLIBC_TEST) $(EXTRA_CFLAGS)
> > $(OUTPUT)/nolibc-test: LDLIBS = $(if $(LLVM),,-lgcc)
> > $(OUTPUT)/nolibc-test: nolibc-test.c nolibc-test-linkage.c | headers
>
> The rule for "libc-test", which uses the standard $(LINK.c) to invoke
> the compiler, does not respect $(EXTRA_CFLAGS) automatically.
> Is this intentional?

Thanks for the review. Is the change below OK with you? I can update it
before sending a new series.

diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index 0370489d938b..7b65e6f9840b 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -3,18 +3,17 @@
TEST_GEN_PROGS := nolibc-test libc-test

include ../lib.mk
-include $(top_srcdir)/scripts/Makefile.compiler
-
-cc-option = $(call __cc-option, $(CC),,$(1),$(2))
+include $(top_srcdir)/tools/scripts/Makefile.include

include Makefile.include

$(OUTPUT)/nolibc-test: CFLAGS = -nostdlib -nostdinc -static \
-isystem $(top_srcdir)/tools/include/nolibc -isystem $(top_srcdir)/usr/include \
- $(CFLAGS_NOLIBC_TEST)
+ $(CFLAGS_NOLIBC_TEST) $(EXTRA_CFLAGS)
$(OUTPUT)/nolibc-test: LDLIBS = $(if $(LLVM),,-lgcc)
$(OUTPUT)/nolibc-test: nolibc-test.c nolibc-test-linkage.c | headers

+$(OUTPUT)/libc-test: CFLAGS += $(EXTRA_CFLAGS)
$(OUTPUT)/libc-test: nolibc-test.c nolibc-test-linkage.c
$(call msg,CC,,$@)
$(Q)$(LINK.c) $^ -o $@

> It also affects all other users of lib.mk which
> don't have any custom cflags handling.

Many projects include lib.mk, but most do not include
tools/scripts/Makefile.include. Without it, the appended EXTRA_CFLAGS
cannot be inherited. This is why I did not touch those projects.

Appending EXTRA_CFLAGS in lib.mk may not be a good idea ? as such a
global change could break some builds.

Thanks,
Leo