From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 E701A3CC7CA for ; Wed, 13 May 2026 23:32:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778715133; cv=none; b=YJc9iIllQiio0Li/lqBuHP54EeBYXz7qGf4n4Fo3O/+RwAQqEFVsp7fO1ND0tUIsMHMwHcls8WgYecHFfDUw91xRlz85DNgaHx0jCXNInK2+zB7E4AZka7h+lTo9WmHHLt4LWBcpKjLXWkN5Az783cgHE9V8qXgqge80eKu35SQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778715133; c=relaxed/simple; bh=VQN7eQD/+oxvUlLTjVh+JUlI+PEdTOpgV9wFpdUhHvY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mWpH3phGaBDsk6svCsgm+K4cXhIOOJASrSq0l0nRV2z7YrXmCjauTHTskIYxcxIGKooDQQ5zby6zDt7YXxLArbC4jCGXutWVRFAfP0YEIUUOyVIPlb6PhzBgFkPYQ75Hh+ucC6IxhjDs9OJn4T8QJ5vi6X2Chx4MhPIRu6nxkks= 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=J39SqqFl; arc=none smtp.client-ip=74.125.82.74 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="J39SqqFl" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-1306c2f7037so7836374c88.0 for ; Wed, 13 May 2026 16:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778715130; x=1779319930; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=64Gh3XXwwXs+LgEftAHmElSN2hvQJzq0J5o3E2PYSCw=; b=J39SqqFlgBO1Zoqg9ZwWKU2DKk4OENup/c0bKd8B/ulrVOP7trOGaozbHDH42032JC qQ9LnFgeBkjbk6nDicMy1Lq3qlYD3yCpUULAFSa+udUVTsDfLgZAMSr+a98z5UVNVIZ6 x7uWdtT0Gmd98By3lyy2LOYGUx9t6JkLRV2YI7jBf3+zBiDybu1wByhm7DdrAzjLv0pB pYX2Yt3aQp14clnV9qL4i5ZvIKksLOBCH4jeHKqW3vLpw2nrrJEYlPYzbLs164a60oPl lpvYgVxiQcroU0hcg6rohPAr8c1GWD79lRB5j5N8lQlFlbqdCftp/I0FIPWt8oSYUcvI Lpxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778715130; x=1779319930; h=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; bh=64Gh3XXwwXs+LgEftAHmElSN2hvQJzq0J5o3E2PYSCw=; b=f/BYpwVR7eGtIG/O2LMqey+rjXchjy4OHuY3lNDMFnuqEa3swDZ+RLn4kCgXSSKuXf K9zwgMP3BTdVwhBb32xmldwsgp2vHre+mmoNGBVe65Sf32Pa35mkAqxkmOkIVoqP6hHm mmstpibWGLoj5uR22V602uO7pYS1fGQBb4WlVQal8DYm2Dx5q1Pczr1PeVaRsR+S/VHt mD0DrxeWeMZhpJZzfeZKzLzIItpZ9UExLIE3TSkaAVHZWgEXjJePk3mnn+aAQW7xElDu Q/Oqb/Oeb6Hg8rZtVRLRD2IUysIVNhlQq1REVNAF2RBNfud08aXVImN7MJdSTwC8Pjip jkqg== X-Forwarded-Encrypted: i=1; AFNElJ9xdFwEkTuCE8+rUatCscgoe94ouyXdlIz46OpP7vmHY9zyEE8+ZvDSyUwcf0VI1emEYYFI26QiKKSznXxzeE6K@vger.kernel.org X-Gm-Message-State: AOJu0YxJfq88CMq1JTvSwe6VDWyh8hTuIpMgshbF1KM4dl70VFDJNI0A fdxQLgxIheXPC04lMudGBsflWh5SBql/zVf9eGJPlGmKRgDd253BatgDBeJpfMImFz7aOHkbs2O brjIxsxv27A== X-Received: from dlbbo27.prod.google.com ([2002:a05:7022:439b:b0:12d:e33d:70da]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:252b:b0:133:1c42:f5d6 with SMTP id a92af1059eb24-1349ae99352mr3027978c88.41.1778715129802; Wed, 13 May 2026 16:32:09 -0700 (PDT) Date: Wed, 13 May 2026 16:31:47 -0700 In-Reply-To: <20260513233151.572332-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260413024805.1316480-1-irogers@google.com> <20260513233151.572332-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260513233151.572332-4-irogers@google.com> Subject: [PATCH v5 3/7] perf build: Be more programmatic when setting up libunwind variables From: Ian Rogers To: acme@kernel.org, adrian.hunter@intel.com, dapeng1.mi@linux.intel.com, james.clark@linaro.org, namhyung@kernel.org, Florian Fainelli , Li Guan Cc: 9erthalion6@gmail.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, andrew.jones@oss.qualcomm.com, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, howardchu95@gmail.com, john.g.garry@oracle.com, jolsa@kernel.org, leo.yan@linux.dev, libunwind-devel@nongnu.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, mingo@redhat.com, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, shimin.guo@skydio.com, tglozar@redhat.com, tmricht@linux.ibm.com, will@kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Iterate LIBUNWIND_ARCHS when setting up CONFIG_ and HAVE_ definitions rather than treating each architecture individually. This sets up the libunwind build variables and C definitions beyond x86 and arm/aarch64. The existing naming convention is followed for compatibility. Signed-off-by: Ian Rogers --- tools/perf/Makefile.config | 226 ++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 126 deletions(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 06d7a3f9990c..7a0e372824c6 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -65,95 +65,83 @@ $(call detected_var,SRCARCH) CFLAGS += -I$(OUTPUT)arch/$(SRCARCH)/include/generated -# Additional ARCH settings for ppc -ifeq ($(SRCARCH),powerpc) - ifndef NO_LIBUNWIND - LIBUNWIND_LIBS := -lunwind -lunwind-ppc64 - endif -endif - # Additional ARCH settings for x86 ifeq ($(SRCARCH),x86) $(call detected,CONFIG_X86) ifeq (${IS_64_BIT}, 1) CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S - ifndef NO_LIBUNWIND - LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma - endif $(call detected,CONFIG_X86_64) - else - ifndef NO_LIBUNWIND - LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind - endif endif endif -ifeq ($(SRCARCH),arm) - ifndef NO_LIBUNWIND - LIBUNWIND_LIBS = -lunwind -lunwind-arm - endif +ifeq ($(ARCH),s390) + CFLAGS += -fPIC endif -ifeq ($(SRCARCH),arm64) - ifndef NO_LIBUNWIND - LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 - endif +ifneq ($(LIBUNWIND),1) + NO_LIBUNWIND := 1 endif -ifeq ($(SRCARCH),loongarch) - ifndef NO_LIBUNWIND +ifndef NO_LIBUNWIND + ifeq ($(SRCARCH),arm) + LIBUNWIND_LIBS = -lunwind -lunwind-arm + endif + ifeq ($(SRCARCH),arm64) + LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 + endif + ifeq ($(SRCARCH),loongarch) LIBUNWIND_LIBS = -lunwind -lunwind-loongarch64 endif -endif - -ifeq ($(ARCH),s390) - CFLAGS += -fPIC -endif - -ifeq ($(ARCH),mips) - ifndef NO_LIBUNWIND + ifeq ($(ARCH),mips) LIBUNWIND_LIBS = -lunwind -lunwind-mips endif + ifeq ($(SRCARCH),powerpc) + LIBUNWIND_LIBS := -lunwind -lunwind-ppc64 + endif + ifeq ($(SRCARCH),riscv) + LIBUNWIND_LIBS := -lunwind -lunwind-riscv + endif + ifeq ($(SRCARCH),s390) + LIBUNWIND_LIBS := -lunwind -lunwind-s390x + endif + ifeq ($(SRCARCH),x86) + ifeq (${IS_64_BIT}, 1) + LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma + else + LIBUNWIND_LIBS = -lunwind-x86 -lunwind -llzma + endif + endif + ifeq ($(LIBUNWIND_LIBS),) + NO_LIBUNWIND := 1 + endif endif -ifneq ($(LIBUNWIND),1) - NO_LIBUNWIND := 1 -endif - -ifeq ($(LIBUNWIND_LIBS),) - NO_LIBUNWIND := 1 -endif # # For linking with debug library, run like: # # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/ # - -libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code)) -define libunwind_arch_set_flags_code - FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include - FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib -endef - -ifdef LIBUNWIND_DIR - LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include - LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib - LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64 loongarch - $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch))) -endif +LIBUNWIND_ARCHS:=aarch64 arm loongarch64 mips ppc32 ppc64 riscv s390x x86 x86_64 ifndef NO_LIBUNWIND - # Set per-feature check compilation flags FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS) FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS) FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS) - - FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm - FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64 - FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86 - FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64 + + ifdef LIBUNWIND_DIR + LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include + LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib + + define libunwind_arch_set_flags + FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include + FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib -lunwind -lunwind-$(1) + endef + $(foreach arch,$(LIBUNWIND_ARCHS), \ + $(eval $(call libunwind_arch_set_flags,$(arch))) \ + ) + endif endif ifdef CSINCLUDES @@ -638,49 +626,6 @@ ifeq ($(SRCARCH),powerpc) endif endif -ifndef NO_LIBUNWIND - have_libunwind := - - $(call feature_check,libunwind) - - $(call feature_check,libunwind-x86) - ifeq ($(feature-libunwind-x86), 1) - $(call detected,CONFIG_LIBUNWIND_X86) - CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT - LDFLAGS += -lunwind-x86 - EXTLIBS_LIBUNWIND += -lunwind-x86 - have_libunwind = 1 - endif - - $(call feature_check,libunwind-aarch64) - ifeq ($(feature-libunwind-aarch64), 1) - $(call detected,CONFIG_LIBUNWIND_AARCH64) - CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT - LDFLAGS += -lunwind-aarch64 - EXTLIBS_LIBUNWIND += -lunwind-aarch64 - have_libunwind = 1 - $(call feature_check,libunwind-debug-frame-aarch64) - ifneq ($(feature-libunwind-debug-frame-aarch64), 1) - $(warning No debug_frame support found in libunwind-aarch64) - CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64 - endif - endif - - ifneq ($(feature-libunwind), 1) - $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR and set LIBUNWIND=1 in the make command line as it is opt-in now) - NO_LOCAL_LIBUNWIND := 1 - else - have_libunwind := 1 - $(call detected,CONFIG_LOCAL_LIBUNWIND) - endif - - ifneq ($(have_libunwind), 1) - NO_LIBUNWIND := 1 - endif -else - NO_LOCAL_LIBUNWIND := 1 -endif - ifndef NO_LIBBPF ifneq ($(feature-bpf), 1) $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.) @@ -739,6 +684,60 @@ ifndef GEN_VMLINUX_H VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h endif +ifndef NO_LIBUNWIND + have_libunwind := + + $(call feature_check,libunwind) + ifneq ($(feature-libunwind), 1) + $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR and set LIBUNWIND=1 in the make command line as it is opt-in now) + NO_LOCAL_LIBUNWIND := 1 + else + have_libunwind := 1 + $(call detected,CONFIG_LOCAL_LIBUNWIND) + CFLAGS += -DHAVE_LIBUNWIND_SUPPORT + CFLAGS += $(LIBUNWIND_CFLAGS) + LDFLAGS += $(LIBUNWIND_LDFLAGS) + EXTLIBS_LIBUNWIND := $(LIBUNWIND_LIBS) + $(call feature_check,libunwind-debug-frame) + ifneq ($(feature-libunwind-debug-frame), 1) + CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME + endif + endif + + define PROCESS_REMOTE_LIBUNWIND_ARCH + $(call feature_check,libunwind-$(1)) + + ifeq ($$(feature-libunwind-$(1)), 1) + upper_arch := $$(shell echo $(1) | tr '[:lower:]' '[:upper:]') + $$(call detected,CONFIG_LIBUNWIND_$$(upper_arch)) + + CFLAGS += -DHAVE_LIBUNWIND_$$(upper_arch)_SUPPORT + LDFLAGS += -lunwind-$(1) + EXTLIBS_LIBUNWIND += -lunwind-$(1) + have_libunwind := 1 + + $$(call feature_check,libunwind-debug-frame-$(1)) + ifneq ($$(feature-libunwind-debug-frame-$(1)), 1) + CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_$$(upper_arch) + endif + endif + endef + $(foreach arch,$(LIBUNWIND_ARCHS), \ + $(eval $(call PROCESS_REMOTE_LIBUNWIND_ARCH,$(arch))) \ + ) + + EXTLIBS += $(EXTLIBS_LIBUNWIND) + + ifeq ($(findstring -static,${LDFLAGS}),-static) + # gcc -static links libgcc_eh which contains piece of libunwind + LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition + endif + + ifneq ($(have_libunwind), 1) + NO_LIBUNWIND := 1 + endif +endif + dwarf-post-unwind := 1 dwarf-post-unwind-text := BUG @@ -761,31 +760,6 @@ ifeq ($(dwarf-post-unwind),1) $(call detected,CONFIG_DWARF_UNWIND) endif -ifndef NO_LIBUNWIND - ifndef NO_LOCAL_LIBUNWIND - ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64)) - $(call feature_check,libunwind-debug-frame) - ifneq ($(feature-libunwind-debug-frame), 1) - $(warning No debug_frame support found in libunwind) - CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME - endif - else - # non-ARM has no dwarf_find_debug_frame() function: - CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME - endif - EXTLIBS += $(LIBUNWIND_LIBS) - LDFLAGS += $(LIBUNWIND_LIBS) - endif - ifeq ($(findstring -static,${LDFLAGS}),-static) - # gcc -static links libgcc_eh which contans piece of libunwind - LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition - endif - CFLAGS += -DHAVE_LIBUNWIND_SUPPORT - CFLAGS += $(LIBUNWIND_CFLAGS) - LDFLAGS += $(LIBUNWIND_LDFLAGS) - EXTLIBS += $(EXTLIBS_LIBUNWIND) -endif - ifneq ($(NO_LIBTRACEEVENT),1) $(call detected,CONFIG_TRACE) endif -- 2.54.0.563.g4f69b47b94-goog