Skip to content

Commit 2f38304

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: Make libbpf_version.h non-auto-generated
Turn previously auto-generated libbpf_version.h header into a normal header file. This prevents various tricky Makefile integration issues, simplifies the overall build process, but also allows to further extend it with some more versioning-related APIs in the future. To prevent accidental out-of-sync versions as defined by libbpf.map and libbpf_version.h, Makefile checks their consistency at build time. Simultaneously with this change bump libbpf.map to v0.6. Also undo adding libbpf's output directory into include path for kernel/bpf/preload, bpftool, and resolve_btfids, which is not necessary because libbpf_version.h is just a normal header like any other. Fixes: 0b46b75 ("libbpf: Add LIBBPF_DEPRECATED_SINCE macro for scheduling API deprecations") Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20210913222309.3220849-1-andrii@kernel.org
1 parent dbd7eb1 commit 2f38304

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

kernel/bpf/preload/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ LIBBPF_OUT = $(abspath $(obj))
1010
$(LIBBPF_A):
1111
$(Q)$(MAKE) -C $(LIBBPF_SRCS) O=$(LIBBPF_OUT)/ OUTPUT=$(LIBBPF_OUT)/ $(LIBBPF_OUT)/libbpf.a
1212

13-
userccflags += -I$(LIBBPF_OUT) -I $(srctree)/tools/include/ \
14-
-I $(srctree)/tools/include/uapi \
13+
userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi \
1514
-I $(srctree)/tools/lib/ -Wno-unused-result
1615

1716
userprogs := bpf_preload_umd
1817

19-
clean-files := $(userprogs) libbpf_version.h bpf_helper_defs.h FEATURE-DUMP.libbpf staticobjs/ feature/
20-
21-
$(obj)/iterators/iterators.o: $(LIBBPF_A)
18+
clean-files := $(userprogs) bpf_helper_defs.h FEATURE-DUMP.libbpf staticobjs/ feature/
2219

2320
bpf_preload_umd-objs := iterators/iterators.o
2421
bpf_preload_umd-userldlibs := $(LIBBPF_A) -lelf -lz

tools/bpf/bpftool/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
6060
CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS))
6161
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
6262
-I$(if $(OUTPUT),$(OUTPUT),.) \
63-
$(if $(LIBBPF_OUTPUT),-I$(LIBBPF_OUTPUT)) \
6463
-I$(srctree)/kernel/bpf/ \
6564
-I$(srctree)/tools/include \
6665
-I$(srctree)/tools/include/uapi \

tools/bpf/resolve_btfids/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/l
4747
CFLAGS := -g \
4848
-I$(srctree)/tools/include \
4949
-I$(srctree)/tools/include/uapi \
50-
-I$(LIBBPF_OUT) \
5150
-I$(LIBBPF_SRC) \
5251
-I$(SUBCMD_SRC)
5352

tools/lib/bpf/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
libbpf_version.h
32
libbpf.pc
43
libbpf.so.*
54
TAGS

tools/lib/bpf/Makefile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ SHARED_OBJDIR := $(OUTPUT)sharedobjs/
113113
STATIC_OBJDIR := $(OUTPUT)staticobjs/
114114
BPF_IN_SHARED := $(SHARED_OBJDIR)libbpf-in.o
115115
BPF_IN_STATIC := $(STATIC_OBJDIR)libbpf-in.o
116-
VERSION_HDR := $(OUTPUT)libbpf_version.h
117116
BPF_HELPER_DEFS := $(OUTPUT)bpf_helper_defs.h
118-
BPF_GENERATED := $(BPF_HELPER_DEFS) $(VERSION_HDR)
117+
BPF_GENERATED := $(BPF_HELPER_DEFS)
119118

120119
LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
121120
LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
@@ -165,12 +164,6 @@ $(BPF_HELPER_DEFS): $(srctree)/tools/include/uapi/linux/bpf.h
165164
$(QUIET_GEN)$(srctree)/scripts/bpf_doc.py --header \
166165
--file $(srctree)/tools/include/uapi/linux/bpf.h > $(BPF_HELPER_DEFS)
167166

168-
$(VERSION_HDR): force
169-
$(QUIET_GEN)echo "/* This file was auto-generated. */" > $@
170-
@echo "" >> $@
171-
@echo "#define LIBBPF_MAJOR_VERSION $(LIBBPF_MAJOR_VERSION)" >> $@
172-
@echo "#define LIBBPF_MINOR_VERSION $(LIBBPF_MINOR_VERSION)" >> $@
173-
174167
$(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
175168

176169
$(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN_SHARED) $(VERSION_SCRIPT)
@@ -189,7 +182,7 @@ $(OUTPUT)libbpf.pc:
189182
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
190183
< libbpf.pc.template > $@
191184

192-
check: check_abi
185+
check: check_abi check_version
193186

194187
check_abi: $(OUTPUT)libbpf.so $(VERSION_SCRIPT)
195188
@if [ "$(GLOBAL_SYM_COUNT)" != "$(VERSIONED_SYM_COUNT)" ]; then \
@@ -215,6 +208,21 @@ check_abi: $(OUTPUT)libbpf.so $(VERSION_SCRIPT)
215208
exit 1; \
216209
fi
217210

211+
HDR_MAJ_VERSION := $(shell grep -oE '^\#define LIBBPF_MAJOR_VERSION ([0-9]+)$$' libbpf_version.h | cut -d' ' -f3)
212+
HDR_MIN_VERSION := $(shell grep -oE '^\#define LIBBPF_MINOR_VERSION ([0-9]+)$$' libbpf_version.h | cut -d' ' -f3)
213+
214+
check_version: $(VERSION_SCRIPT) libbpf_version.h
215+
@if [ "$(HDR_MAJ_VERSION)" != "$(LIBBPF_MAJOR_VERSION)" ]; then \
216+
echo "Error: libbpf major version mismatch detected: " \
217+
"'$(HDR_MAJ_VERSION)' != '$(LIBBPF_MAJOR_VERSION)'" >&2; \
218+
exit 1; \
219+
fi
220+
@if [ "$(HDR_MIN_VERSION)" != "$(LIBBPF_MINOR_VERSION)" ]; then \
221+
echo "Error: libbpf minor version mismatch detected: " \
222+
"'$(HDR_MIN_VERSION)' != '$(LIBBPF_MINOR_VERSION)'" >&2; \
223+
exit 1; \
224+
fi
225+
218226
define do_install_mkdir
219227
if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
220228
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
@@ -234,8 +242,9 @@ install_lib: all_cmd
234242
cp -fpR $(LIB_FILE) $(DESTDIR)$(libdir_SQ)
235243

236244
INSTALL_HEADERS = bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h xsk.h \
237-
bpf_helpers.h $(BPF_GENERATED) bpf_tracing.h \
238-
bpf_endian.h bpf_core_read.h skel_internal.h
245+
bpf_helpers.h $(BPF_GENERATED) bpf_tracing.h \
246+
bpf_endian.h bpf_core_read.h skel_internal.h \
247+
libbpf_version.h
239248

240249
install_headers: $(BPF_GENERATED)
241250
$(call QUIET_INSTALL, headers) \
@@ -255,7 +264,7 @@ clean:
255264
$(addprefix $(OUTPUT), \
256265
*.o *.a *.so *.so.$(LIBBPF_MAJOR_VERSION) *.pc)
257266

258-
PHONY += force cscope tags
267+
PHONY += force cscope tags check check_abi check_version
259268
force:
260269

261270
cscope:

tools/lib/bpf/libbpf.map

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,6 @@ LIBBPF_0.5.0 {
386386
btf_dump__dump_type_data;
387387
libbpf_set_strict_mode;
388388
} LIBBPF_0.4.0;
389+
390+
LIBBPF_0.6.0 {
391+
} LIBBPF_0.5.0;

tools/lib/bpf/libbpf_version.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2+
/* Copyright (C) 2021 Facebook */
3+
#ifndef __LIBBPF_VERSION_H
4+
#define __LIBBPF_VERSION_H
5+
6+
#define LIBBPF_MAJOR_VERSION 0
7+
#define LIBBPF_MINOR_VERSION 6
8+
9+
#endif /* __LIBBPF_VERSION_H */

0 commit comments

Comments
 (0)