[PATCH v4 27/30] selftests/bpf: Append extra cflags
From: Leo Yan
Date: Wed Mar 11 2026 - 04:45:47 EST
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@xxxxxxx>
---
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