Skip to content

Commit 6910d7d

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Ensure bpf_helper_defs.h are taken from selftests dir
Reorder includes search path to ensure $(OUTPUT) and $(CURDIR) go before libbpf's directory. Also fix bpf_helpers.h to include bpf_helper_defs.h in such a way as to leverage includes search path. This allows selftests to not use libbpf's local and potentially stale bpf_helper_defs.h. It's important because selftests/bpf's Makefile only re-generates bpf_helper_defs.h in seltests' output directory, not the one in libbpf's directory. Also force regeneration of bpf_helper_defs.h when libbpf.a is updated to reduce staleness. Fixes: fa633a0 ("libbpf: Fix build on read-only filesystems") Reported-by: Alexei Starovoitov <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 2031af2 commit 6910d7d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tools/lib/bpf/bpf_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef __BPF_HELPERS__
33
#define __BPF_HELPERS__
44

5-
#include "bpf_helper_defs.h"
5+
#include <bpf_helper_defs.h>
66

77
#define __uint(name, val) int (*name)[val]
88
#define __type(name, val) typeof(val) *name

tools/testing/selftests/bpf/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ CLANG ?= clang
2020
LLC ?= llc
2121
LLVM_OBJCOPY ?= llvm-objcopy
2222
BPF_GCC ?= $(shell command -v bpf-gcc;)
23-
CFLAGS += -g -Wall -O2 $(GENFLAGS) -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) \
24-
-I$(GENDIR) -I$(TOOLSINCDIR) -I$(CURDIR) \
23+
CFLAGS += -g -Wall -O2 $(GENFLAGS) -I$(CURDIR) -I$(APIDIR) -I$(LIBDIR) \
24+
-I$(BPFDIR) -I$(GENDIR) -I$(TOOLSINCDIR) \
2525
-Dbpf_prog_load=bpf_prog_test_load \
2626
-Dbpf_load_program=bpf_test_load_program
2727
LDLIBS += -lcap -lelf -lz -lrt -lpthread
@@ -153,7 +153,7 @@ $(BPFOBJ): force
153153
$(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
154154

155155
BPF_HELPERS := $(OUTPUT)/bpf_helper_defs.h $(wildcard $(BPFDIR)/bpf_*.h)
156-
$(OUTPUT)/bpf_helper_defs.h:
156+
$(OUTPUT)/bpf_helper_defs.h: $(BPFOBJ)
157157
$(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ $(OUTPUT)/bpf_helper_defs.h
158158

159159
# Get Clang's default includes on this system, as opposed to those seen by
@@ -174,8 +174,8 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
174174

175175
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
176176
BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
177-
-I. -I./include/uapi -I$(APIDIR) \
178-
-I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)
177+
-I$(OUTPUT) -I$(CURDIR) -I$(CURDIR)/include/uapi \
178+
-I$(APIDIR) -I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)
179179

180180
CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
181181
-Wno-compare-distinct-pointer-types
@@ -329,7 +329,7 @@ TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
329329
TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
330330
$(wildcard progs/btf_dump_test_case_*.c)
331331
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
332-
TRUNNER_BPF_CFLAGS := -I. -I$(OUTPUT) $(BPF_CFLAGS) $(CLANG_CFLAGS)
332+
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
333333
TRUNNER_BPF_LDFLAGS := -mattr=+alu32
334334
$(eval $(call DEFINE_TEST_RUNNER,test_progs))
335335

0 commit comments

Comments
 (0)