Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/bpf: Clean up samples/bpf build failes

Remove xdp_samples_user.o rule redefinition which generates Makefile
warning and instead override TPROGS_CFLAGS. This seems to work fine when
building inside selftests/bpf.

That was one big head-scratcher before I found that generic
Makefile.target hid this surprising specialization for for xdp_samples_user.o.

Main change is to use actual locally installed libbpf headers.

Also drop printk macro re-definition (not even used!).

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211201232824.3166325-8-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
527024f7 186d1a86

+12 -21
+12 -1
samples/bpf/Makefile
··· 328 328 $(src)/*.c: verify_target_bpf $(LIBBPF) 329 329 330 330 libbpf_hdrs: $(LIBBPF) 331 - $(obj)/$(TRACE_HELPERS): | libbpf_hdrs 331 + $(obj)/$(TRACE_HELPERS) $(obj)/$(CGROUP_HELPERS) $(obj)/$(XDP_SAMPLE): | libbpf_hdrs 332 332 333 333 .PHONY: libbpf_hdrs 334 334 ··· 342 342 $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h 343 343 $(obj)/hbm.o: $(src)/hbm.h 344 344 $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h 345 + 346 + # Override includes for xdp_sample_user.o because $(srctree)/usr/include in 347 + # TPROGS_CFLAGS causes conflicts 348 + XDP_SAMPLE_CFLAGS += -Wall -O2 -lm \ 349 + -I$(src)/../../tools/include \ 350 + -I$(src)/../../tools/include/uapi \ 351 + -I$(LIBBPF_INCLUDE) \ 352 + -I$(src)/../../tools/testing/selftests/bpf 353 + 354 + $(obj)/$(XDP_SAMPLE): TPROGS_CFLAGS = $(XDP_SAMPLE_CFLAGS) 355 + $(obj)/$(XDP_SAMPLE): $(src)/xdp_sample_user.h $(src)/xdp_sample_shared.h 345 356 346 357 -include $(BPF_SAMPLES_PATH)/Makefile.target 347 358
-11
samples/bpf/Makefile.target
··· 73 73 cmd_tprog-cobjs = $(CC) $(tprogc_flags) -c -o $@ $< 74 74 $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE 75 75 $(call if_changed_dep,tprog-cobjs) 76 - 77 - # Override includes for xdp_sample_user.o because $(srctree)/usr/include in 78 - # TPROGS_CFLAGS causes conflicts 79 - XDP_SAMPLE_CFLAGS += -Wall -O2 -lm \ 80 - -I./tools/include \ 81 - -I./tools/include/uapi \ 82 - -I./tools/lib \ 83 - -I./tools/testing/selftests/bpf 84 - $(obj)/xdp_sample_user.o: $(src)/xdp_sample_user.c \ 85 - $(src)/xdp_sample_user.h $(src)/xdp_sample_shared.h 86 - $(CC) $(XDP_SAMPLE_CFLAGS) -c -o $@ $<
-2
samples/bpf/hbm_kern.h
··· 9 9 * Include file for sample Host Bandwidth Manager (HBM) BPF programs 10 10 */ 11 11 #define KBUILD_MODNAME "foo" 12 - #include <stddef.h> 13 - #include <stdbool.h> 14 12 #include <uapi/linux/bpf.h> 15 13 #include <uapi/linux/if_ether.h> 16 14 #include <uapi/linux/if_packet.h>
-7
samples/bpf/lwt_len_hist_kern.c
··· 16 16 #include <uapi/linux/in.h> 17 17 #include <bpf/bpf_helpers.h> 18 18 19 - # define printk(fmt, ...) \ 20 - ({ \ 21 - char ____fmt[] = fmt; \ 22 - bpf_trace_printk(____fmt, sizeof(____fmt), \ 23 - ##__VA_ARGS__); \ 24 - }) 25 - 26 19 struct bpf_elf_map { 27 20 __u32 type; 28 21 __u32 size_key;