Add support for EXTRA_BPF_FLAGS in the eBPF skeleton build, allowing
users to pass additional Clang options such as --sysroot or custom
include paths when cross-compiling perf.
This is primarily intended for cross-build scenarios where the default
host include paths do not match the target kernel version.
Example usage:
make perf ARCH="arm64" EXTRA_BPF_FLAGS="--sysroot=..."
Change history:
v5:
- Update commit message
v4:
- Apply EXTRA_BPF_FLAGS directly to BPF skeleton build command
instead of modifying CLANG_OPTIONS
v3:
- Move the variable description comment to the top of Makefile.perf
- Update commit message
v2:
- Rename EXTRA_CLANG_FLAGS to EXTRA_BPF_FLAGS
- Update commit message
v1:
- Introduce EXTRA_CLANG_FLAGS to allow passing extra Clang options
Signed-off-by: hupu <hupu.gm@gmail.com>
---
tools/perf/Makefile.perf | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index b3f481a626af..8b8647fd4f41 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -35,6 +35,9 @@ include ../scripts/utilities.mak
#
# Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds.
#
+# Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for
+# cross-compiling BPF skeletons
+#
# Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated
# EXTLIBS.
#
@@ -1250,7 +1253,7 @@ endif
$(SKEL_TMP_OUT)/%.bpf.o: $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h | $(SKEL_TMP_OUT)
$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h
$(QUIET_CLANG)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \
- $(CLANG_OPTIONS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
+ $(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
-include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \
-c $(filter util/bpf_skel/%.bpf.c,$^) -o $@
--
2.43.0
Hello, On Tue, Dec 23, 2025 at 04:43:34PM +0800, hupu wrote: > Add support for EXTRA_BPF_FLAGS in the eBPF skeleton build, allowing > users to pass additional Clang options such as --sysroot or custom > include paths when cross-compiling perf. > > This is primarily intended for cross-build scenarios where the default > host include paths do not match the target kernel version. > > Example usage: > make perf ARCH="arm64" EXTRA_BPF_FLAGS="--sysroot=..." > > Change history: > v5: > - Update commit message > v4: > - Apply EXTRA_BPF_FLAGS directly to BPF skeleton build command > instead of modifying CLANG_OPTIONS > v3: > - Move the variable description comment to the top of Makefile.perf > - Update commit message > v2: > - Rename EXTRA_CLANG_FLAGS to EXTRA_BPF_FLAGS > - Update commit message > v1: > - Introduce EXTRA_CLANG_FLAGS to allow passing extra Clang options > > Signed-off-by: hupu <hupu.gm@gmail.com> Reviewed-by: Namhyung Kim <namhyung@kernel.org> Thanks, Namhyung > --- > tools/perf/Makefile.perf | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf > index b3f481a626af..8b8647fd4f41 100644 > --- a/tools/perf/Makefile.perf > +++ b/tools/perf/Makefile.perf > @@ -35,6 +35,9 @@ include ../scripts/utilities.mak > # > # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds. > # > +# Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for > +# cross-compiling BPF skeletons > +# > # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated > # EXTLIBS. > # > @@ -1250,7 +1253,7 @@ endif > $(SKEL_TMP_OUT)/%.bpf.o: $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h | $(SKEL_TMP_OUT) > $(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h > $(QUIET_CLANG)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \ > - $(CLANG_OPTIONS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \ > + $(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \ > -include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \ > -c $(filter util/bpf_skel/%.bpf.c,$^) -o $@ > > -- > 2.43.0 >
© 2016 - 2026 Red Hat, Inc.