Re: [PATCH] perf build: Support passing extra Clang options via EXTRA_BPF_FLAGS

From: Namhyung Kim
Date: Tue Nov 25 2025 - 03:16:47 EST


Hello,

On Mon, Nov 24, 2025 at 03:34:45PM +0800, hupu wrote:
> When cross-compiling perf with BPF enabled, Clang is invoked during the
> build. Some cross-compilation environments require additional compiler
> options, such as `--sysroot` or custom include paths.
>
> This patch introduces a new Make variable, `EXTRA_BPF_FLAGS`. During BPF
> skeleton builds, it appends user-provided options to `CLANG_OPTIONS`,
> allowing extra Clang flags to be set without modifying Makefile.perf
> directly.
>
> Example usage:
> make perf ARCH="arm64" EXTRA_BPF_FLAGS="--sysroot=..."
>
> Change history:
> 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@xxxxxxxxx>
> ---
> tools/perf/Makefile.perf | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 47c906b807ef..c1a66cf3d1a7 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.
> #
> @@ -1249,6 +1252,8 @@ else
> $(Q)cp "$(VMLINUX_H)" $@
> endif
>
> +CLANG_OPTIONS += $(EXTRA_BPF_FLAGS)

While it seems CLANG_OPTIONS is used only for BPF skeletons, I think
it's better to add it directly to the below lines instead of adding it
to CLANG_OPTIONS like following.

> +
> $(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) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \

Thanks,
Namhyung