[PATCH] perf: record: Clear BPF headers if not needed

From: Mayuresh Chitale

Date: Wed Jul 01 2026 - 10:29:06 EST


When perf is compiled without libbpf support (e.g., passing NO_LIBELF=1)
and even if the user explicitly passes the '--no-bpf-event' flag, the file
header feature bitmask still unconditionally retains the BPF/BTF tracking
bits. As a result, write_bpf_prog_info() and write_bpf_btf() always get
called and display the error messages below:

ERROR: Trying to write bpf_prog_info without libbpf support.
ERROR: Trying to write btf data without libbpf support.

Fix this by clearing HEADER_BPF_PROG_INFO and HEADER_BPF_BTF from the
features bitmask, whenever the user passes the '--no-bpf-event' flag.

Fixes: 598de368375e ("perf header: Properly warn/print when libtraceevent/libbpf support is missing")
Signed-off-by: Mayuresh Chitale <mayuresh.chitale@xxxxxxxxxxxxxxxx>
---
tools/perf/builtin-record.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e91539055675..692ab7138d2c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1829,6 +1829,11 @@ static void record__init_features(struct record *rec)
if (!record__comp_enabled(rec))
perf_header__clear_feat(&session->header, HEADER_COMPRESSED);

+ if (rec->opts.no_bpf_event) {
+ perf_header__clear_feat(&session->header, HEADER_BPF_PROG_INFO);
+ perf_header__clear_feat(&session->header, HEADER_BPF_BTF);
+ }
+
perf_header__clear_feat(&session->header, HEADER_STAT);
}

--
2.43.0