Skip to content

Commit 527024f

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
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
1 parent 186d1a8 commit 527024f

4 files changed

Lines changed: 12 additions & 21 deletions

File tree

‎samples/bpf/Makefile‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
328328
$(src)/*.c: verify_target_bpf $(LIBBPF)
329329

330330
libbpf_hdrs: $(LIBBPF)
331-
$(obj)/$(TRACE_HELPERS): | libbpf_hdrs
331+
$(obj)/$(TRACE_HELPERS) $(obj)/$(CGROUP_HELPERS) $(obj)/$(XDP_SAMPLE): | libbpf_hdrs
332332

333333
.PHONY: libbpf_hdrs
334334

@@ -343,6 +343,17 @@ $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
343343
$(obj)/hbm.o: $(src)/hbm.h
344344
$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
345345

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
356+
346357
-include $(BPF_SAMPLES_PATH)/Makefile.target
347358

348359
VMLINUX_BTF_PATHS ?= $(abspath $(if $(O),$(O)/vmlinux)) \

‎samples/bpf/Makefile.target‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,3 @@ quiet_cmd_tprog-cobjs = CC $@
7373
cmd_tprog-cobjs = $(CC) $(tprogc_flags) -c -o $@ $<
7474
$(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE
7575
$(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 $@ $<

‎samples/bpf/hbm_kern.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* Include file for sample Host Bandwidth Manager (HBM) BPF programs
1010
*/
1111
#define KBUILD_MODNAME "foo"
12-
#include <stddef.h>
13-
#include <stdbool.h>
1412
#include <uapi/linux/bpf.h>
1513
#include <uapi/linux/if_ether.h>
1614
#include <uapi/linux/if_packet.h>

‎samples/bpf/lwt_len_hist_kern.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
#include <uapi/linux/in.h>
1717
#include <bpf/bpf_helpers.h>
1818

19-
# define printk(fmt, ...) \
20-
({ \
21-
char ____fmt[] = fmt; \
22-
bpf_trace_printk(____fmt, sizeof(____fmt), \
23-
##__VA_ARGS__); \
24-
})
25-
2619
struct bpf_elf_map {
2720
__u32 type;
2821
__u32 size_key;

0 commit comments

Comments
 (0)