Skip to content

Commit 4407fa0

Browse files
committed
Merge branch 'bpftool: Switch to new versioning scheme (align on libbpf's)'
Quentin Monnet says: ==================== Hi, this set aims at updating the way bpftool versions are numbered. Instead of copying the version from the kernel (given that the sources for the kernel and bpftool are shipped together), align it on libbpf's version number, with a fixed offset (6) to avoid going backwards. Please refer to the description of the second commit for details on the motivations. The patchset also adds the number of the version of libbpf that was used to compile to the output of "bpftool version". Bpftool makes such a heavy usage of libbpf that it makes sense to indicate what version was used to build it. v3: - Compute bpftool's version at compile time, but from the macros exposed by libbpf instead of calling a shell to compute $(BPFTOOL_VERSION) in the Makefile. - Drop the commit which would add a "libbpfversion" target to libbpf's Makefile. This is no longer necessary. - Use libbpf's major, minor versions with jsonw_printf() to avoid offsetting the version string to skip the "v" prefix. - Reword documentation change. v2: - Align on libbpf's version number instead of creating an independent versioning scheme. - Use libbpf_version_string() to retrieve and display libbpf's version. - Re-order patches (1 <-> 2). ==================== Signed-off-by: Andrii Nakryiko <[email protected]>
2 parents 4cc0991 + 9910a74 commit 4407fa0

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

tools/bpf/bpftool/Documentation/common_options.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
Print short help message (similar to **bpftool help**).
55

66
-V, --version
7-
Print version number (similar to **bpftool version**), and optional
8-
features that were included when bpftool was compiled. Optional
9-
features include linking against libbfd to provide the disassembler
10-
for JIT-ted programs (**bpftool prog dump jited**) and usage of BPF
11-
skeletons (some features like **bpftool prog profile** or showing
12-
pids associated to BPF objects may rely on it).
7+
Print bpftool's version number (similar to **bpftool version**), the
8+
number of the libbpf version in use, and optional features that were
9+
included when bpftool was compiled. Optional features include linking
10+
against libbfd to provide the disassembler for JIT-ted programs
11+
(**bpftool prog dump jited**) and usage of BPF skeletons (some
12+
features like **bpftool prog profile** or showing pids associated to
13+
BPF objects may rely on it).
1314

1415
-j, --json
1516
Generate JSON output. For commands that cannot produce JSON, this

tools/bpf/bpftool/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ LIBBPF_BOOTSTRAP := $(LIBBPF_BOOTSTRAP_OUTPUT)libbpf.a
3939
LIBBPF_INTERNAL_HDRS := $(addprefix $(LIBBPF_HDRS_DIR)/,hashmap.h nlattr.h)
4040
LIBBPF_BOOTSTRAP_INTERNAL_HDRS := $(addprefix $(LIBBPF_BOOTSTRAP_HDRS_DIR)/,hashmap.h)
4141

42-
ifeq ($(BPFTOOL_VERSION),)
43-
BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
44-
endif
45-
4642
$(LIBBPF_OUTPUT) $(BOOTSTRAP_OUTPUT) $(LIBBPF_BOOTSTRAP_OUTPUT) $(LIBBPF_HDRS_DIR) $(LIBBPF_BOOTSTRAP_HDRS_DIR):
4743
$(QUIET_MKDIR)mkdir -p $@
4844

@@ -83,7 +79,9 @@ CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
8379
-I$(srctree)/kernel/bpf/ \
8480
-I$(srctree)/tools/include \
8581
-I$(srctree)/tools/include/uapi
82+
ifneq ($(BPFTOOL_VERSION),)
8683
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
84+
endif
8785
ifneq ($(EXTRA_CFLAGS),)
8886
CFLAGS += $(EXTRA_CFLAGS)
8987
endif

tools/bpf/bpftool/main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ static int do_help(int argc, char **argv)
7171
return 0;
7272
}
7373

74+
#ifndef BPFTOOL_VERSION
75+
/* bpftool's major and minor version numbers are aligned on libbpf's. There is
76+
* an offset of 6 for the version number, because bpftool's version was higher
77+
* than libbpf's when we adopted this scheme. The patch number remains at 0
78+
* for now. Set BPFTOOL_VERSION to override.
79+
*/
80+
#define BPFTOOL_MAJOR_VERSION (LIBBPF_MAJOR_VERSION + 6)
81+
#define BPFTOOL_MINOR_VERSION LIBBPF_MINOR_VERSION
82+
#define BPFTOOL_PATCH_VERSION 0
83+
#endif
84+
7485
static int do_version(int argc, char **argv)
7586
{
7687
#ifdef HAVE_LIBBFD_SUPPORT
@@ -88,7 +99,15 @@ static int do_version(int argc, char **argv)
8899
jsonw_start_object(json_wtr); /* root object */
89100

90101
jsonw_name(json_wtr, "version");
102+
#ifdef BPFTOOL_VERSION
91103
jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
104+
#else
105+
jsonw_printf(json_wtr, "\"%d.%d.%d\"", BPFTOOL_MAJOR_VERSION,
106+
BPFTOOL_MINOR_VERSION, BPFTOOL_PATCH_VERSION);
107+
#endif
108+
jsonw_name(json_wtr, "libbpf_version");
109+
jsonw_printf(json_wtr, "\"%d.%d\"",
110+
libbpf_major_version(), libbpf_minor_version());
92111

93112
jsonw_name(json_wtr, "features");
94113
jsonw_start_object(json_wtr); /* features */
@@ -101,7 +120,13 @@ static int do_version(int argc, char **argv)
101120
} else {
102121
unsigned int nb_features = 0;
103122

123+
#ifdef BPFTOOL_VERSION
104124
printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
125+
#else
126+
printf("%s v%d.%d.%d\n", bin_name, BPFTOOL_MAJOR_VERSION,
127+
BPFTOOL_MINOR_VERSION, BPFTOOL_PATCH_VERSION);
128+
#endif
129+
printf("using libbpf %s\n", libbpf_version_string());
105130
printf("features:");
106131
if (has_libbfd) {
107132
printf(" libbfd");

0 commit comments

Comments
 (0)