From 148d8f259c7fda8f1dcf692ff4573f545e9d5ef23f6a1d0179850b5d99626a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Fri, 3 May 2024 11:22:58 +0200 Subject: [PATCH] Sync from SUSE:SLFO:Main bpftool revision faa1a6fb084ea3f97ec1683dfa982ade --- .gitattributes | 23 +++ ...cal-copy-of-perf_event-to-fix-access.patch | 63 +++++++++ ...-local-bpf_perf_link-to-fix-accessin.patch | 70 ++++++++++ ...cal-bpf_perf_event_value-to-fix-acce.patch | 131 ++++++++++++++++++ ...cal-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch | 51 +++++++ binutils-2.40.patch | 13 ++ bpftool-libbpf-v7.2.0-sources.tar.gz | 3 + bpftool.changes | 55 ++++++++ bpftool.spec | 90 ++++++++++++ 9 files changed, 499 insertions(+) create mode 100644 .gitattributes create mode 100644 0001-bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch create mode 100644 0002-bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch create mode 100644 0003-bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch create mode 100644 0004-bpftool-Use-a-local-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch create mode 100644 binutils-2.40.patch create mode 100644 bpftool-libbpf-v7.2.0-sources.tar.gz create mode 100644 bpftool.changes create mode 100644 bpftool.spec diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/0001-bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch b/0001-bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch new file mode 100644 index 0000000..873f9b5 --- /dev/null +++ b/0001-bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch @@ -0,0 +1,63 @@ +From 6acb32f72618dbaa9d4938fc3007b0ff7ca151c4 Mon Sep 17 00:00:00 2001 +From: Alexander Lobakin +Date: Thu, 21 Apr 2022 00:38:45 +0000 +Subject: [PATCH] bpftool: use a local copy of perf_event to fix accessing + ::bpf_cookie + +When CONFIG_PERF_EVENTS is not set, struct perf_event remains empty. +However, the structure is being used by bpftool indirectly via BTF. +This leads to: + +skeleton/pid_iter.bpf.c:49:30: error: no member named 'bpf_cookie' in 'struct perf_event' + return BPF_CORE_READ(event, bpf_cookie); + ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ + +... + +skeleton/pid_iter.bpf.c:49:9: error: returning 'void' from a function with incompatible result type '__u64' (aka 'unsigned long long') + return BPF_CORE_READ(event, bpf_cookie); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Tools and samples can't use any CONFIG_ definitions, so the fields +used there should always be present. +Define struct perf_event___local with the `preserve_access_index` +attribute inside the pid_iter BPF prog to allow compiling on any +configs. CO-RE will substitute it with the real struct perf_event +accesses later on. + +Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") +Suggested-by: Andrii Nakryiko +Signed-off-by: Alexander Lobakin +Signed-off-by: Quentin Monnet +--- + tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/src/skeleton/pid_iter.bpf.c b/src/skeleton/pid_iter.bpf.c +index eb05ea53afb1..e2af8e5fb29e 100644 +--- a/src/skeleton/pid_iter.bpf.c ++++ b/src/skeleton/pid_iter.bpf.c +@@ -15,6 +15,10 @@ enum bpf_obj_type { + BPF_OBJ_BTF, + }; + ++struct perf_event___local { ++ u64 bpf_cookie; ++} __attribute__((preserve_access_index)); ++ + extern const void bpf_link_fops __ksym; + extern const void bpf_map_fops __ksym; + extern const void bpf_prog_fops __ksym; +@@ -41,8 +45,8 @@ static __always_inline __u32 get_obj_id(void *ent, enum bpf_obj_type type) + /* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ + static __u64 get_bpf_cookie(struct bpf_link *link) + { ++ struct perf_event___local *event; + struct bpf_perf_link *perf_link; +- struct perf_event *event; + + perf_link = container_of(link, struct bpf_perf_link, link); + event = BPF_CORE_READ(perf_link, perf_file, private_data); +-- +2.40.0 + diff --git a/0002-bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch b/0002-bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch new file mode 100644 index 0000000..01606f1 --- /dev/null +++ b/0002-bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch @@ -0,0 +1,70 @@ +From cf4dcbae4799415fc5a85f9bb9f31bbf036f2994 Mon Sep 17 00:00:00 2001 +From: Alexander Lobakin +Date: Thu, 21 Apr 2022 00:38:58 +0000 +Subject: [PATCH] bpftool: define a local bpf_perf_link to fix accessing its + fields + +When building bpftool with !CONFIG_PERF_EVENTS: + +skeleton/pid_iter.bpf.c:47:14: error: incomplete definition of type 'struct bpf_perf_link' + perf_link = container_of(link, struct bpf_perf_link, link); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:74:22: note: expanded from macro 'container_of' + ((type *)(__mptr - offsetof(type, member))); \ + ^~~~~~~~~~~~~~~~~~~~~~ +tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:68:60: note: expanded from macro 'offsetof' + #define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER) + ~~~~~~~~~~~^ +skeleton/pid_iter.bpf.c:44:9: note: forward declaration of 'struct bpf_perf_link' + struct bpf_perf_link *perf_link; + ^ + +&bpf_perf_link is being defined and used only under the ifdef. +Define struct bpf_perf_link___local with the `preserve_access_index` +attribute inside the pid_iter BPF prog to allow compiling on any +configs. CO-RE will substitute it with the real struct bpf_perf_link +accesses later on. +container_of() is not CO-REd, but it is a noop for +bpf_perf_link <-> bpf_link and the local copy is a full mirror of +the original structure. + +Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") +Suggested-by: Andrii Nakryiko +Signed-off-by: Alexander Lobakin +Signed-off-by: Quentin Monnet +--- + tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/src/skeleton/pid_iter.bpf.c b/src/skeleton/pid_iter.bpf.c +index e2af8e5fb29e..3a4c4f7d83d8 100644 +--- a/src/skeleton/pid_iter.bpf.c ++++ b/src/skeleton/pid_iter.bpf.c +@@ -15,6 +15,11 @@ enum bpf_obj_type { + BPF_OBJ_BTF, + }; + ++struct bpf_perf_link___local { ++ struct bpf_link link; ++ struct file *perf_file; ++} __attribute__((preserve_access_index)); ++ + struct perf_event___local { + u64 bpf_cookie; + } __attribute__((preserve_access_index)); +@@ -45,10 +50,10 @@ static __always_inline __u32 get_obj_id(void *ent, enum bpf_obj_type type) + /* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ + static __u64 get_bpf_cookie(struct bpf_link *link) + { ++ struct bpf_perf_link___local *perf_link; + struct perf_event___local *event; +- struct bpf_perf_link *perf_link; + +- perf_link = container_of(link, struct bpf_perf_link, link); ++ perf_link = container_of(link, struct bpf_perf_link___local, link); + event = BPF_CORE_READ(perf_link, perf_file, private_data); + return BPF_CORE_READ(event, bpf_cookie); + } +-- +2.40.0 + diff --git a/0003-bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch b/0003-bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch new file mode 100644 index 0000000..a2bc5fc --- /dev/null +++ b/0003-bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch @@ -0,0 +1,131 @@ +From bf5a83d6f1a9851cd1471fba06a58abbab5bc4c4 Mon Sep 17 00:00:00 2001 +From: Alexander Lobakin +Date: Thu, 21 Apr 2022 00:39:04 +0000 +Subject: [PATCH] bpftool: use a local bpf_perf_event_value to fix accessing + its fields + +Fix the following error when building bpftool: + + CLANG profiler.bpf.o + CLANG pid_iter.bpf.o +skeleton/profiler.bpf.c:18:21: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_perf_event_value' + __uint(value_size, sizeof(struct bpf_perf_event_value)); + ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint' +tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helper_defs.h:7:8: note: forward declaration of 'struct bpf_perf_event_value' +struct bpf_perf_event_value; + ^ + +struct bpf_perf_event_value is being used in the kernel only when +CONFIG_BPF_EVENTS is enabled, so it misses a BTF entry then. +Define struct bpf_perf_event_value___local with the +`preserve_access_index` attribute inside the pid_iter BPF prog to +allow compiling on any configs. It is a full mirror of a UAPI +structure, so is compatible both with and w/o CO-RE. +bpf_perf_event_read_value() requires a pointer of the original type, +so a cast is needed. + +Fixes: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command") +Suggested-by: Andrii Nakryiko +Signed-off-by: Alexander Lobakin +Signed-off-by: Quentin Monnet +--- + tools/bpf/bpftool/skeleton/profiler.bpf.c | 27 ++++++++++++++--------- + 1 file changed, 17 insertions(+), 10 deletions(-) + +diff --git a/src/skeleton/profiler.bpf.c b/src/skeleton/profiler.bpf.c +index ce5b65e07ab1..2f80edc682f1 100644 +--- a/src/skeleton/profiler.bpf.c ++++ b/src/skeleton/profiler.bpf.c +@@ -4,6 +4,12 @@ + #include + #include + ++struct bpf_perf_event_value___local { ++ __u64 counter; ++ __u64 enabled; ++ __u64 running; ++} __attribute__((preserve_access_index)); ++ + /* map of perf event fds, num_cpu * num_metric entries */ + struct { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); +@@ -15,14 +21,14 @@ struct { + struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(key_size, sizeof(u32)); +- __uint(value_size, sizeof(struct bpf_perf_event_value)); ++ __uint(value_size, sizeof(struct bpf_perf_event_value___local)); + } fentry_readings SEC(".maps"); + + /* accumulated readings */ + struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(key_size, sizeof(u32)); +- __uint(value_size, sizeof(struct bpf_perf_event_value)); ++ __uint(value_size, sizeof(struct bpf_perf_event_value___local)); + } accum_readings SEC(".maps"); + + /* sample counts, one per cpu */ +@@ -39,7 +45,7 @@ const volatile __u32 num_metric = 1; + SEC("fentry/XXX") + int BPF_PROG(fentry_XXX) + { +- struct bpf_perf_event_value *ptrs[MAX_NUM_MATRICS]; ++ struct bpf_perf_event_value___local *ptrs[MAX_NUM_MATRICS]; + u32 key = bpf_get_smp_processor_id(); + u32 i; + +@@ -53,10 +59,10 @@ int BPF_PROG(fentry_XXX) + } + + for (i = 0; i < num_metric && i < MAX_NUM_MATRICS; i++) { +- struct bpf_perf_event_value reading; ++ struct bpf_perf_event_value___local reading; + int err; + +- err = bpf_perf_event_read_value(&events, key, &reading, ++ err = bpf_perf_event_read_value(&events, key, (void *)&reading, + sizeof(reading)); + if (err) + return 0; +@@ -68,14 +74,14 @@ int BPF_PROG(fentry_XXX) + } + + static inline void +-fexit_update_maps(u32 id, struct bpf_perf_event_value *after) ++fexit_update_maps(u32 id, struct bpf_perf_event_value___local *after) + { +- struct bpf_perf_event_value *before, diff; ++ struct bpf_perf_event_value___local *before, diff; + + before = bpf_map_lookup_elem(&fentry_readings, &id); + /* only account samples with a valid fentry_reading */ + if (before && before->counter) { +- struct bpf_perf_event_value *accum; ++ struct bpf_perf_event_value___local *accum; + + diff.counter = after->counter - before->counter; + diff.enabled = after->enabled - before->enabled; +@@ -93,7 +99,7 @@ fexit_update_maps(u32 id, struct bpf_perf_event_value *after) + SEC("fexit/XXX") + int BPF_PROG(fexit_XXX) + { +- struct bpf_perf_event_value readings[MAX_NUM_MATRICS]; ++ struct bpf_perf_event_value___local readings[MAX_NUM_MATRICS]; + u32 cpu = bpf_get_smp_processor_id(); + u32 i, zero = 0; + int err; +@@ -102,7 +108,8 @@ int BPF_PROG(fexit_XXX) + /* read all events before updating the maps, to reduce error */ + for (i = 0; i < num_metric && i < MAX_NUM_MATRICS; i++) { + err = bpf_perf_event_read_value(&events, cpu + i * num_cpu, +- readings + i, sizeof(*readings)); ++ (void *)(readings + i), ++ sizeof(*readings)); + if (err) + return 0; + } +-- +2.40.0 + diff --git a/0004-bpftool-Use-a-local-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch b/0004-bpftool-Use-a-local-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch new file mode 100644 index 0000000..f1ab219 --- /dev/null +++ b/0004-bpftool-Use-a-local-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch @@ -0,0 +1,51 @@ +From a9a8284ebebfdad29f4596c14cc9d5ae07b33430 Mon Sep 17 00:00:00 2001 +From: Quentin Monnet +Date: Wed, 10 May 2023 18:22:50 +0100 +Subject: [PATCH] bpftool: Use a local copy of BPF_LINK_TYPE_PERF_EVENT in + pid_iter.bpf.c + +In order to allow the BPF program in bpftool's pid_iter.bpf.c to compile +correctly on hosts where vmlinux.h does not define +BPF_LINK_TYPE_PERF_EVENT (running kernel versions lower than 5.15, for +example), define and use a local, CO-RE compatible copy of the enum +value. + +Signed-off-by: Quentin Monnet +--- + tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 11 +++++++++-- + 1 file changed, 9 insertions(+), 2 deletions(-) + +diff --git a/src/skeleton/pid_iter.bpf.c b/src/skeleton/pid_iter.bpf.c +index 3a4c4f7d83d8..26004f0c5a6a 100644 +--- a/src/skeleton/pid_iter.bpf.c ++++ b/src/skeleton/pid_iter.bpf.c +@@ -24,6 +24,10 @@ struct perf_event___local { + u64 bpf_cookie; + } __attribute__((preserve_access_index)); + ++enum bpf_link_type___local { ++ BPF_LINK_TYPE_PERF_EVENT___local = 7, ++}; ++ + extern const void bpf_link_fops __ksym; + extern const void bpf_map_fops __ksym; + extern const void bpf_prog_fops __ksym; +@@ -93,10 +97,13 @@ int iter(struct bpf_iter__task_file *ctx) + e.pid = task->tgid; + e.id = get_obj_id(file->private_data, obj_type); + +- if (obj_type == BPF_OBJ_LINK) { ++ if (obj_type == BPF_OBJ_LINK && ++ bpf_core_enum_value_exists(enum bpf_link_type___local, ++ BPF_LINK_TYPE_PERF_EVENT___local)) { + struct bpf_link *link = (struct bpf_link *) file->private_data; + +- if (BPF_CORE_READ(link, type) == BPF_LINK_TYPE_PERF_EVENT) { ++ if (link->type == bpf_core_enum_value(enum bpf_link_type___local, ++ BPF_LINK_TYPE_PERF_EVENT___local)) { + e.has_bpf_cookie = true; + e.bpf_cookie = get_bpf_cookie(link); + } +-- +2.40.0 + diff --git a/binutils-2.40.patch b/binutils-2.40.patch new file mode 100644 index 0000000..7546510 --- /dev/null +++ b/binutils-2.40.patch @@ -0,0 +1,13 @@ +diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile +index f610e184ce02..21cd7505e871 100644 +--- a/src/Makefile ++++ b/src/Makefile +@@ -154,6 +154,8 @@ else + # Fall back on libbfd + ifeq ($(feature-libbfd),1) + LIBS += -lbfd -ldl -lopcodes ++ else ifeq ($(feature-libbfd-liberty-sframe),1) ++ LIBS += -lbfd -ldl -lopcodes -liberty -lsframe -lzstd + else ifeq ($(feature-libbfd-liberty),1) + LIBS += -lbfd -ldl -lopcodes -liberty + else ifeq ($(feature-libbfd-liberty-z),1) diff --git a/bpftool-libbpf-v7.2.0-sources.tar.gz b/bpftool-libbpf-v7.2.0-sources.tar.gz new file mode 100644 index 0000000..9fa4065 --- /dev/null +++ b/bpftool-libbpf-v7.2.0-sources.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:baa1e1c2a79c06a1f3112be3e47a6b4e00df0dc07a1e9117f2213a96fb37bf8a +size 2643306 diff --git a/bpftool.changes b/bpftool.changes new file mode 100644 index 0000000..b894ad5 --- /dev/null +++ b/bpftool.changes @@ -0,0 +1,55 @@ +------------------------------------------------------------------- +Wed Mar 29 17:35:09 UTC 2023 - Michal Suchanek + +- Update to out-of-tree version 7.2.0 +- Use release tarball that includes the specific copy of libbpf that is needed + to build bpftool +- Fix build on Linux 5.14 + + 0001-bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch + + 0002-bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch + + 0003-bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch + + 0004-bpftool-Use-a-local-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch + +------------------------------------------------------------------- +Wed Mar 1 08:15:33 UTC 2023 - Martin Liška + +- Add -lzstd as libbfd is linked against the compression library. + +------------------------------------------------------------------- +Wed Feb 22 08:21:22 UTC 2023 - Martin Liška + +- Rebase binutils-2.40.patch for v6.2. + +------------------------------------------------------------------- +Wed Feb 15 09:11:12 UTC 2023 - Martin Liška + +- Add binutils-2.40.patch where we need to explicitly link against + -lsframe. It's a workaround for an existing issue: + https://github.com/libbpf/bpftool/issues/73. + +------------------------------------------------------------------- +Fri Oct 7 16:22:21 UTC 2022 - Callum Farmer + +- Move bash-completion to subpackage so it isn't installed when + not needed + +------------------------------------------------------------------- +Fri Apr 8 15:15:39 UTC 2022 - Dirk Müller + +- add rebuild subpackage to ensure rebuild in TW + +------------------------------------------------------------------- +Thu Oct 14 11:40:44 UTC 2021 - Shung-Hsi Yu + +- Enable libbfd feature to support dumping jited form of BPF programs + +------------------------------------------------------------------- +Wed Jan 8 16:28:37 UTC 2020 - Ludwig Nussel + +- use optflags for building +- build and install man pages + +------------------------------------------------------------------- +Thu May 9 14:41:11 UTC 2019 - Michal Rostecki + +- Initial release diff --git a/bpftool.spec b/bpftool.spec new file mode 100644 index 0000000..b92309f --- /dev/null +++ b/bpftool.spec @@ -0,0 +1,90 @@ +# +# spec file for package bpftool +# +# Copyright (c) 2023 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Name: bpftool +Version: 7.2.0 +Release: 0 +Summary: Tool for inspection and manipulation of BPF programs and maps +License: GPL-2.0-only +Group: Development/Tools/Other +URL: https://www.kernel.org/ +Source0: https://github.com/libbpf/bpftool/releases/download/v%{version}/bpftool-libbpf-v%{version}-sources.tar.gz +Patch0: binutils-2.40.patch +Patch1: 0001-bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch +Patch2: 0002-bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch +Patch3: 0003-bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch +Patch4: 0004-bpftool-Use-a-local-copy-of-BPF_LINK_TYPE_PERF_EVENT.patch +BuildRequires: binutils-devel +%if 0%{?suse_version} && 0%{?suse_version} <= 1500 +%if 0%{?sle_version} < 150400 +BuildRequires: clang12-devel +%else +BuildRequires: clang13-devel +%endif +%else +BuildRequires: clang-devel +%endif +BuildRequires: docutils +BuildRequires: libcap-devel +BuildRequires: libelf-devel +BuildRequires: libzstd-devel + +%description +bpftool allows for inspection and simple modification of BPF objects (programs +and maps) on the system. + +%package bash-completion +Summary: Bash completion for bpftool +Group: System/Shells +Requires: %{name} +Requires: bash-completion +Supplements: (%{name} and bash-completion) + +%description bash-completion +bash command line completion support for bpftool. + +%prep +%autosetup -p1 -n %{name} +sed -i -e 's/CFLAGS += -O2/CFLAGS = $(RPM_OPT_FLAGS)/' src/Makefile + +%build +%make_build -C src V=1 \ + feature-reallocarray=1 \ + feature-libbfd-liberty=1 \ +%if %(if gcc -lsframe -shared 2>/dev/null ; then echo 1 ; else echo 0; fi; ) + feature-libbfd-liberty-sframe=1 \ +%endif + feature-disassembler-four-args=1 \ + all +%make_build -C docs V=1 \ + man + +%install +make -C src V=1 install DESTDIR=%{buildroot} prefix=%{_prefix} mandir=%{_mandir} +make -C docs V=1 install DESTDIR=%{buildroot} prefix=%{_prefix} mandir=%{_mandir} + +%files +%license LICENSE LICENSE.BSD-2-Clause LICENSE.GPL-2.0 +%doc README.md CHECKPOINT-COMMIT BPF-CHECKPOINT-COMMIT +%{_sbindir}/bpftool +%{_mandir}/man?/*.gz + +%files bash-completion +%{_datadir}/bash-completion/completions/bpftool + +%changelog