samples/bpf: Build the BPF programs with -fms-extensions

Commit 835a507535 ("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@virtuozzo.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20260925154937.3677406-1-eva.kurchatova@virtuozzo.com
This commit is contained in:
Eva Kurchatova authored and Alexei Starovoitov committed 2026-09-26 08:06:13 +00:00
1 parent 34354db1b1
commit 12aa64bbce
1 file changed
+1
+1
View File
@@ -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) \