From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 334A55616B1 for ; Tue, 13 Oct 2026 22:16:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.70 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791929817; cv=none; b=uL1wdQ3lzj8q/YMw3T+cQ78OEU31e5f1E/EXVyykGMsrRFvvcGDhYs1BxhZNpgNxct7m2YdmX7ICunXow8rlVz1ba1vBqV8HxJ/NuKH0MHYkgzUsWOEOaaZxE1eNUJvs6Rnp49+PXlmwBmKJMcSrerQuSCBbFAx4l00+TmjPQi4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791929817; c=relaxed/simple; bh=Le3RIdFDWzXr3CmRn/RyvEvO1U2K+C02J6LcVuBqvtw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gEsNV2jYyq1ZmGpTahQUISvoyEyhMt3tIH5QRvN5UC5Fi7CpqWd7MaAT4OgUOCx8jMABSLweB48AQwMhy8vYBW7dAW6XqSVXOhT0a47SHjP2sKGVGBDxfHakv9tnHS0usSP6nh2S4hgjp3/dnoTZ6zPFH+2bU5khzAs5NdIJgHA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gCxXkrVT; arc=none smtp.client-ip=74.125.82.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gCxXkrVT" Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-147be78cd56so13515413c88.1 for ; Tue, 13 Oct 2026 15:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791929814; x=1792534614; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3YXXmBiMIQ/pkFW8VDRpK9ExuImLnICRP/QM6dS80OU=; b=gCxXkrVTVlzivLHhR2oHHBycw39eYrxg6YW5aebYbzhYtODv55+J4T6PWX1CiICho/ OlBKrZOHvX/vDiNdbZERFQ+StW6kXWTkAxOe0e8dIZD36n31wgTzIrUnf/zeCtyVnMSa p+3AYblBJ5ynPJRELVpIzlt/arjPny0YyhYclOZYzSveN1XMygYDslS8+DlCMlrnCU0t w4FcY6f4e6j9FYShPEKHzYOp/z+UWtigRW/5/MTrQonQeMDP8NTRdYADyfTXomegWbQb 4OKqLmCRsb9eOFO41dN3hwUKBuNfnYtAlQXorlsQGn5VgmbOdPpc8nOhznvKdwe8RVDu uRzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791929814; x=1792534614; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3YXXmBiMIQ/pkFW8VDRpK9ExuImLnICRP/QM6dS80OU=; b=aV/tZKw3EeoQVOJcR8YW72ZCA5m2z1hGXQETKNceRV0HhTwASmhi6hbaHJnSeSqACZ 1uYYyNJpFWSstyKdKjl2eypybiT1XnrAlmrBJgb++XgGQ80fSCOTLfqHH2UcVHYgNN2R ezE3X3PWJaIszkVMuqiCJR+f1i0RYM8V3oOctTR+lSyu29QptqKnR5XkwmjwFFJattSs YOcN9X7cNrVruz1QdRFRn7rASq8t+I62os2Xk0pVUwLxuL6/qXGAqTOjzKNeu4R/nP3w UafgyV/YVrJzpWwA+By4J9ML7f4Qjg+kD24zm54AbGd/qXmYariWSLFgHC4BSctOmNXg DGrw== X-Forwarded-Encrypted: i=1; AKwUvBzOed08weIzy3/ysTWMYkhZmW9bZZSqEWRKZ5OY5rAApmdFsJw2lAx/LjXt2S+7g6bKXVM=@vger.kernel.org X-Gm-Message-State: AFq9FYKfxy8KfTwmEHwEgvO2js4naZMoRD1xEGdsVaWlyNPWK1CJU2kz uSQ654eFniEVTtOi3gMFNQW6P/OTS1TpMiUEpwYyhvceTIIQQsKFC3LIh+oniGdolEY/259Jy/N DIkv1C3y1Kw== X-Received: from dyad4.prod.google.com ([2002:a05:693c:8344:b0:351:7ff8:2656]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ea86:b0:153:7a27:b7d with SMTP id a92af1059eb24-16a626f6e93mr17582035c88.20.1791929813756; Tue, 13 Oct 2026 15:16:53 -0700 (PDT) Date: Tue, 13 Oct 2026 15:16:42 -0700 In-Reply-To: <20261013221643.1815686-1-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20261013221643.1815686-1-irogers@google.com> X-Mailer: git-send-email 2.56.0.385.gd3acb90ef8-goog Message-ID: <20261013221643.1815686-2-irogers@google.com> Subject: [PATCH v1 1/2] perf build: Support building BPF skeletons with bpf-gcc From: Ian Rogers To: Arnaldo Carvalho de Melo , Namhyung Kim , "Jose E . Marchesi" , David Faust , Cupertino Miranda Cc: Peter Zijlstra , Ingo Molnar , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Andrii Nakryiko , Eduard Zingerman , Yonghong Song , linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to tools/testing/selftests/bpf/Makefile. When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler. In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident, -DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query system include paths from $(CC). Assisted-by: Antigravity:gemini-3.1-pro Signed-off-by: Ian Rogers --- tools/perf/Makefile.config | 81 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/scripts/Makefile.include | 1 + 4 files changed, 97 insertions(+), 29 deletions(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index cafc7be79643..6aee2665b64c 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -662,27 +662,76 @@ ifeq ($(BUILD_BPF_SKEL),1) else ifeq ($(filter -DHAVE_LIBOPENSSL_SUPPORT, $(CFLAGS)),) $(warning Warning: Disabled BPF skeletons as libopenssl is required) BUILD_BPF_SKEL := 0 - else ifeq ($(call get-executable,$(CLANG)),) - $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) - BUILD_BPF_SKEL := 0 - else - CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') - ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) - $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) - BUILD_BPF_SKEL := 0 - endif endif ifeq ($(BUILD_BPF_SKEL),1) - $(call feature_check,clang-bpf-co-re) - ifeq ($(feature-clang-bpf-co-re), 0) - $(warning Warning: Disabled BPF skeletons as clang is too old) + # Prefer bpf-gcc when building with gcc (CC_NO_CLANG=1) and clang when + # building with clang, unless CLANG or BPF_GCC was explicitly specified on + # the command line. Fall back to whichever compiler is available. + prefer_bpf_gcc := $(CC_NO_CLANG) + ifeq ($(origin BPF_GCC),command line) + ifneq ($(BPF_GCC),) + prefer_bpf_gcc := 1 + endif + else ifeq ($(origin CLANG),command line) + ifneq ($(CLANG),) + prefer_bpf_gcc := 0 + endif + endif + + have_bpf_gcc := 0 + have_clang_bpf := 0 + + define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion -dumpversion 2>/dev/null) + ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endef + + ifeq ($(prefer_bpf_gcc),1) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),0) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifeq ($(feature-clang-bpf-co-re), 1) + have_clang_bpf := 1 + endif + endif + endif + endif + + ifeq ($(prefer_bpf_gcc)$(have_clang_bpf),00) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),1) + $(call detected,CONFIG_PERF_BPF_SKEL_BPF_GCC) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else ifeq ($(have_clang_bpf),1) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else + ifeq ($(call get-executable,$(CLANG))$(call get-executable,$(BPF_GCC)),) + $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) and bpf-gcc ($(BPF_GCC)) are missing) + else ifneq ($(call get-executable,$(CLANG)),) + ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) + else + $(warning Warning: Disabled BPF skeletons as clang is too old) + endif + else + $(warning Warning: Disabled BPF skeletons as bpf-gcc ($(BPF_GCC)) needs at least version 14.0.0) + endif BUILD_BPF_SKEL := 0 endif endif - ifeq ($(BUILD_BPF_SKEL),1) - $(call detected,CONFIG_PERF_BPF_SKEL) - CFLAGS += -DHAVE_BPF_SKEL - endif endif ifndef GEN_VMLINUX_H diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 2d9379fea267..4061a79cae54 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -37,6 +37,9 @@ include ../scripts/utilities.mak # Define EXTRA_BPF_FLAGS="--sysroot=" or other custom include paths for # cross-compiling BPF skeletons # +# Define BPF_GCC to point to the bpf-gcc binary if the default `bpf-gcc' is not +# correct, or set BPF_GCC= to disable using bpf-gcc for BPF skeletons. +# # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated # EXTLIBS. # @@ -208,6 +211,7 @@ FIND = find INSTALL = install FLEX ?= flex BISON ?= bison +BPF_GCC ?= bpf-gcc AWK = awk # include Makefile.config by default and rule out @@ -321,8 +325,8 @@ ifneq ($(force_fixdep),1) endif endif -export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL +export srctree OUTPUT RM CC CXX RUSTC CLANG BPF_GCC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL CONFIG_PERF_BPF_SKEL_BPF_GCC include $(srctree)/tools/build/Makefile.include diff --git a/tools/perf/bpf_skel.mak b/tools/perf/bpf_skel.mak index f2559de39f96..7b7edf506509 100644 --- a/tools/perf/bpf_skel.mak +++ b/tools/perf/bpf_skel.mak @@ -22,21 +22,35 @@ bpf-skel-prepare: $(BPFTOOL) $(VMLINUX_H) define get_sys_includes $(shell $(1) $(2) -v -E - &1 \ | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) $(2) -dM -E -