[PATCH v4 27/30] selftests/bpf: Append extra cflags

Leo Yan posted 30 patches 4 weeks ago
There is a newer version of this series
[PATCH v4 27/30] selftests/bpf: Append extra cflags
Posted by Leo Yan 4 weeks ago
Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to
the compiler.

urandom_read is built with clang.  Introduce URANDOM_READ_CFLAGS to copy
the compiler flags without appending EXTRA_CFLAGS, which may contain
incompatible options with clang.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/testing/selftests/bpf/Makefile | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 72a9ba41f95ebb825d25799c07ba3f0311243e45..27112f08c9a5b6cabc41902207d00897070b41b4 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -71,6 +71,12 @@ ifneq ($(LLVM),)
 CFLAGS += -Wno-unused-command-line-argument
 endif
 
+# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are
+# appended so that it does not inherit potentially incompatible options.
+URANDOM_READ_CFLAGS := $(CFLAGS)
+
+CFLAGS += $(EXTRA_CFLAGS)
+
 # Check whether bpf cpu=v4 is supported or not by clang
 ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),)
 CLANG_CPUV4 := 1
@@ -255,7 +261,7 @@ endif
 $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom_read.map
 	$(call msg,LIB,,$@)
 	$(Q)$(CLANG) $(CLANG_TARGET_ARCH) \
-		     $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \
+		     $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) \
 		     $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \
 		     -Wno-unused-command-line-argument \
 		     -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
@@ -265,7 +271,7 @@ $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom
 $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so
 	$(call msg,BINARY,,$@)
 	$(Q)$(CLANG) $(CLANG_TARGET_ARCH) \
-		     $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
+		     $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
 		     -Wno-unused-command-line-argument \
 		     -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) \
 		     -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \

-- 
2.34.1
Re: [PATCH v4 27/30] selftests/bpf: Append extra cflags
Posted by Ian Rogers 3 weeks, 6 days ago
On Wed, Mar 11, 2026 at 1:33 AM Leo Yan <leo.yan@arm.com> wrote:
>
> Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to
> the compiler.
>
> urandom_read is built with clang.  Introduce URANDOM_READ_CFLAGS to copy
> the compiler flags without appending EXTRA_CFLAGS, which may contain
> incompatible options with clang.
>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
>  tools/testing/selftests/bpf/Makefile | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 72a9ba41f95ebb825d25799c07ba3f0311243e45..27112f08c9a5b6cabc41902207d00897070b41b4 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -71,6 +71,12 @@ ifneq ($(LLVM),)
>  CFLAGS += -Wno-unused-command-line-argument
>  endif
>
> +# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are
> +# appended so that it does not inherit potentially incompatible options.
> +URANDOM_READ_CFLAGS := $(CFLAGS)

Later in the Makefile, include ../lib.mk is executed and it appends
CFLAGS like -D_GNU_SOURCE= which will be missing from
URANDOM_READ_CFLAGS here. Perhaps move these assignments below the
include?

Thanks,
Ian

> +
> +CFLAGS += $(EXTRA_CFLAGS)
> +
>  # Check whether bpf cpu=v4 is supported or not by clang
>  ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),)
>  CLANG_CPUV4 := 1
> @@ -255,7 +261,7 @@ endif
>  $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom_read.map
>         $(call msg,LIB,,$@)
>         $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \
> -                    $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \
> +                    $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) \
>                      $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \
>                      -Wno-unused-command-line-argument \
>                      -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
> @@ -265,7 +271,7 @@ $(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom
>  $(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so
>         $(call msg,BINARY,,$@)
>         $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \
> -                    $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
> +                    $(filter-out -static,$(URANDOM_READ_CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \
>                      -Wno-unused-command-line-argument \
>                      -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) \
>                      -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \
>
> --
> 2.34.1
>
Re: [PATCH v4 27/30] selftests/bpf: Append extra cflags
Posted by Leo Yan 3 weeks, 5 days ago
On Thu, Mar 12, 2026 at 10:24:48AM -0700, Ian Rogers wrote:
> On Wed, Mar 11, 2026 at 1:33 AM Leo Yan <leo.yan@arm.com> wrote:
> >
> > Append EXTRA_CFLAGS to CFLAGS so that additional flags can be applied to
> > the compiler.
> >
> > urandom_read is built with clang.  Introduce URANDOM_READ_CFLAGS to copy
> > the compiler flags without appending EXTRA_CFLAGS, which may contain
> > incompatible options with clang.
> >
> > Signed-off-by: Leo Yan <leo.yan@arm.com>
> > ---
> >  tools/testing/selftests/bpf/Makefile | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> > index 72a9ba41f95ebb825d25799c07ba3f0311243e45..27112f08c9a5b6cabc41902207d00897070b41b4 100644
> > --- a/tools/testing/selftests/bpf/Makefile
> > +++ b/tools/testing/selftests/bpf/Makefile
> > @@ -71,6 +71,12 @@ ifneq ($(LLVM),)
> >  CFLAGS += -Wno-unused-command-line-argument
> >  endif
> >
> > +# urandom_read is built with clang. Copy $(CFLAGS) before EXTRA_CFLAGS are
> > +# appended so that it does not inherit potentially incompatible options.
> > +URANDOM_READ_CFLAGS := $(CFLAGS)
> 
> Later in the Makefile, include ../lib.mk is executed and it appends
> CFLAGS like -D_GNU_SOURCE= which will be missing from
> URANDOM_READ_CFLAGS here. Perhaps move these assignments below the
> include?

Will do, thanks!