Skip to content

Commit 5a6ea70

Browse files
eddyz87anakryiko
authored andcommitted
samples/bpf: Remove unnecessary -I flags from libbpf EXTRA_CFLAGS
Commit [0] breaks samples/bpf build: $ make M=samples/bpf ... make -C /path/to/kernel/samples/bpf/../../tools/lib/bpf \ ... EXTRA_CFLAGS=" \ ... -fsanitize=bounds \ -I/path/to/kernel/usr/include \ ... /path/to/kernel/samples/bpf/libbpf/libbpf.a install_headers CC /path/to/kernel/samples/bpf/libbpf/staticobjs/libbpf.o In file included from libbpf.c:29: /path/to/kernel/tools/include/linux/err.h:35:8: error: 'inline' can only appear on functions 35 | static inline void * __must_check ERR_PTR(long error_) | ^ The error is caused by `objtree` variable changing definition from `.` (dot) to an absolute path: - The variable TPROGS_CFLAGS is constructed as follows: ... TPROGS_CFLAGS += -I$(objtree)/usr/include - It is passed as EXTRA_CFLAGS for libbpf compilation: $(LIBBPF): ... ... $(MAKE) -C $(LIBBPF_SRC) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" - Before commit [0], the line passed to libbpf makefile was '-I./usr/include', where '.' referred to LIBBPF_SRC due to -C flag. The directory $(LIBBPF_SRC)/usr/include does not exist and thus was never resolved by C compiler. - After commit [0], the line passed to libbpf makefile became: '<output-dir>/usr/include', this directory exists and is resolved by C compiler. - Both 'tools/include' and 'usr/include' define files err.h and types.h. - libbpf expects headers like 'linux/err.h' and 'linux/types.h' defined in 'tools/include', not 'usr/include', hence the compilation error. This commit removes unnecessary -I flags from libbpf compilation. (libbpf sets up the necessary includes at lib/bpf/Makefile:63). Changes v1 [1] -> v2: - dropped unnecessary replacement of KBUILD_OUTPUT with $(objtree) (Andrii) Changes v2 [2] -> v3: - make sure --sysroot option is set for libbpf's EXTRA_CFLAGS, if $(SYSROOT) is set (Stanislav) [0] commit 13b2548 ("kbuild: change working directory to external module directory with M=") [1] https://lore.kernel.org/bpf/[email protected]/ [2] https://lore.kernel.org/bpf/[email protected]/ Fixes: 13b2548 ("kbuild: change working directory to external module directory with M=") Signed-off-by: Eduard Zingerman <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bd74e23 commit 5a6ea70

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

samples/bpf/Makefile

+7-6
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ ifeq ($(ARCH), x86)
146146
BPF_EXTRA_CFLAGS += -fcf-protection
147147
endif
148148

149-
TPROGS_CFLAGS += -Wall -O2
150-
TPROGS_CFLAGS += -Wmissing-prototypes
151-
TPROGS_CFLAGS += -Wstrict-prototypes
152-
TPROGS_CFLAGS += $(call try-run,\
149+
COMMON_CFLAGS += -Wall -O2
150+
COMMON_CFLAGS += -Wmissing-prototypes
151+
COMMON_CFLAGS += -Wstrict-prototypes
152+
COMMON_CFLAGS += $(call try-run,\
153153
printf "int main() { return 0; }" |\
154154
$(CC) -Werror -fsanitize=bounds -x c - -o "$$TMP",-fsanitize=bounds,)
155155

156+
TPROGS_CFLAGS += $(COMMON_CFLAGS)
156157
TPROGS_CFLAGS += -I$(objtree)/usr/include
157158
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
158159
TPROGS_CFLAGS += -I$(LIBBPF_INCLUDE)
@@ -162,7 +163,7 @@ TPROGS_CFLAGS += -I$(srctree)/tools/lib
162163
TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0
163164

164165
ifdef SYSROOT
165-
TPROGS_CFLAGS += --sysroot=$(SYSROOT)
166+
COMMON_CFLAGS += --sysroot=$(SYSROOT)
166167
TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib
167168
endif
168169

@@ -229,7 +230,7 @@ clean:
229230

230231
$(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUTPUT)
231232
# Fix up variables inherited from Kbuild that tools/ build system won't like
232-
$(MAKE) -C $(LIBBPF_SRC) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \
233+
$(MAKE) -C $(LIBBPF_SRC) RM='rm -rf' EXTRA_CFLAGS="$(COMMON_CFLAGS)" \
233234
LDFLAGS="$(TPROGS_LDFLAGS)" srctree=$(BPF_SAMPLES_PATH)/../../ \
234235
O= OUTPUT=$(LIBBPF_OUTPUT)/ DESTDIR=$(LIBBPF_DESTDIR) prefix= \
235236
$@ install_headers

0 commit comments

Comments
 (0)