[PATCH bpf-next] samples/bpf: build the BPF programs with -fms-extensions

From: Eva Kurchatova

Date: Fri Sep 25 2026 - 11:54:21 EST


Commit 835a50753579 ("selftests/bpf: Add -fms-extensions to bpf build
flags") gave the selftests the flag because the kernel is built with
it, and the generated vmlinux.h carries anonymous members declared by
tag:

struct slab {
...
struct freelist_counters;
};

samples/bpf did not get it. clang without the flag reads such a line as
a declaration that declares nothing, one warning per line for every
sample that includes vmlinux.h:

./vmlinux.h:34528:3: warning: declaration does not declare anything
[-Wmissing-declarations]

and lays the struct out without the member, so the BTF of the object
describes a struct the kernel does not have, and a program that touches
the member does not build at all.

Add the flag, and -Wno-microsoft-anon-tag with it, the way the
selftests do.

Signed-off-by: Eva Kurchatova <eva.kurchatova@xxxxxxxxxxxxx>
---
samples/bpf/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 95a4fa1f1e44..c28e65046986 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -342,6 +342,7 @@ $(obj)/xdp_router_ipv4.bpf.o: $(obj)/xdp_sample.bpf.o
$(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h
@echo " CLANG-BPF " $@
$(Q)$(CLANG) -g -O2 --target=bpf -D__TARGET_ARCH_$(SRCARCH) \
+ -fms-extensions -Wno-microsoft-anon-tag \
-Wno-compare-distinct-pointer-types -I$(srctree)/include \
-I$(srctree)/samples/bpf -I$(srctree)/tools/include \
-I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
--
2.55.0