perf libunwind multiple remote support
Subsystems (3)
Ian Rogers
reviewerPATCH v4 7/8 perf unwind-libunwind: Remove libunwind-local
In reply to Ian RogersLocal unwinding only works on the machine libunwind is built for, rather than cross platform, the APIs for remote and local unwinding are similar but types like unw_word_t depend on the included header. Place the architecture specific code into the appropriate libunwind-<arch>.c file. Put generic code in unwind-libunwind.c and use libunwind-arch to choose the correct implementation based on the thread's e_machine. Structuring the code this way avoids including the unwind-libunwind-local.c for each architecture of remote unwinding. Data is moved into the struct unwind_info to simplify the architecture and generic code, trying to keep as much code as possible generic.
--- tools/perf/util/Build | 3 - .../perf/util/libunwind-arch/libunwind-arch.c | 184 ++++ .../perf/util/libunwind-arch/libunwind-arch.h | 234 +++++ .../perf/util/libunwind-arch/libunwind-arm.c | 256 ++++++ .../util/libunwind-arch/libunwind-arm64.c | 255 ++++++ .../perf/util/libunwind-arch/libunwind-i386.c | 254 ++++++ .../util/libunwind-arch/libunwind-loongarch.c | 255 ++++++ .../perf/util/libunwind-arch/libunwind-mips.c | 255 ++++++ .../util/libunwind-arch/libunwind-ppc32.c | 255 ++++++ .../util/libunwind-arch/libunwind-ppc64.c | 255 ++++++ .../perf/util/libunwind-arch/libunwind-s390.c | 255 ++++++ .../util/libunwind-arch/libunwind-x86_64.c | 253 ++++++ tools/perf/util/libunwind/arm64.c | 35 - tools/perf/util/libunwind/x86_32.c | 29 - tools/perf/util/maps.c | 10 - tools/perf/util/maps.h | 2 - tools/perf/util/unwind-libunwind-local.c | 819 ------------------ tools/perf/util/unwind-libunwind.c | 654 +++++++++++++- tools/perf/util/unwind.h | 7 - 19 files changed, 3334 insertions(+), 936 deletions(-) delete mode 100644 tools/perf/util/libunwind/arm64.c delete mode 100644 tools/perf/util/libunwind/x86_32.c delete mode 100644 tools/perf/util/unwind-libunwind-local.c
tools/perf/util/Build +0 -3
@@ -226,11 +226,8 @@ perf-util-$(CONFIG_LIBDW) += annotate-data.o perf-util-$(CONFIG_LIBDW) += libdw.o perf-util-$(CONFIG_LIBDW) += unwind-libdw.o -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind-local.o perf-util-$(CONFIG_LIBUNWIND) += unwind-libunwind.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-arch/ -perf-util-$(CONFIG_LIBUNWIND_X86) += libunwind/x86_32.o -perf-util-$(CONFIG_LIBUNWIND_AARCH64) += libunwind/arm64.o ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
tools/perf/util/libunwind-arch/libunwind-arch.c +184 -0
187 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-arch.h +234 -0
245 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-arm.c +256 -0
267 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-arm64.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-i386.c +254 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-loongarch.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-mips.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-ppc32.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-ppc64.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-s390.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-x86_64.c +253 -0
265 lines not on this page · raw message
tools/perf/util/libunwind/arm64.c deleted +0 -35
@@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* This file setups defines to compile arch specific binary from the -* generic one. -* -* The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch -* name and the definition of this function is included directly from -* 'arch/arm64/util/unwind-libunwind.c', to make sure that this function -* is defined no matter what arch the host is. -* -* Finally, the arch specific unwind methods are exported which will -* be assigned to each arm64 thread. -*/ - -#define REMOTE_UNWIND_LIBUNWIND - -#include "unwind.h" -#include "libunwind-aarch64.h" -#define perf_event_arm_regs perf_event_arm64_regs -#include <../../../arch/arm64/include/uapi/asm/perf_regs.h> -#undef perf_event_arm_regs -#include "../../arch/arm64/util/unwind-libunwind.c" - -/* NO_LIBUNWIND_DEBUG_FRAME is a feature flag for local libunwind, -* assign NO_LIBUNWIND_DEBUG_FRAME_AARCH64 to it for compiling arm64 -* unwind methods. -*/ -#undef NO_LIBUNWIND_DEBUG_FRAME -#ifdef NO_LIBUNWIND_DEBUG_FRAME_AARCH64 -#define NO_LIBUNWIND_DEBUG_FRAME -#endif -#include "util/unwind-libunwind-local.c" - -struct unwind_libunwind_ops * -arm64_unwind_libunwind_ops = &_unwind_libunwind_ops;
tools/perf/util/libunwind/x86_32.c deleted +0 -29
@@ -1,29 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* This file setups defines to compile arch specific binary from the -* generic one. -* -* The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch -* name and the definition of this function is included directly from -* 'arch/x86/util/unwind-libunwind.c', to make sure that this function -* is defined no matter what arch the host is. -* -* Finally, the arch specific unwind methods are exported which will -* be assigned to each x86 thread. -*/ - -#define REMOTE_UNWIND_LIBUNWIND - -#include "unwind.h" -#include "libunwind-x86.h" - -/* Explicitly define NO_LIBUNWIND_DEBUG_FRAME, because non-ARM has no -* dwarf_find_debug_frame() function. -*/ -#ifndef NO_LIBUNWIND_DEBUG_FRAME -#define NO_LIBUNWIND_DEBUG_FRAME -#endif -#include "util/unwind-libunwind-local.c" - -struct unwind_libunwind_ops * -x86_32_unwind_libunwind_ops = &_unwind_libunwind_ops;
tools/perf/util/maps.c +0 -10
@@ -198,16 +198,6 @@ void maps__set_addr_space(struct maps *maps, void *addr_space)RC_CHK_ACCESS (maps)->addr_space = addr_space; } -const struct unwind_libunwind_ops *maps__unwind_libunwind_ops (const struct maps *maps) -{ -return RC_CHK_ACCESS (maps)->unwind_libunwind_ops; -} - -void maps__set_unwind_libunwind_ops (struct maps *maps,const struct unwind_libunwind_ops *ops) -{ -RC_CHK_ACCESS (maps)->unwind_libunwind_ops = ops; -} -uint16_t maps__e_machine (const struct maps *maps) {return RC_CHK_ACCESS (maps)->e_machine;
tools/perf/util/maps.h +0 -2
@@ -49,8 +49,6 @@ refcount_t *maps__refcnt(struct maps *maps); /* Test only. */#ifdef HAVE_LIBUNWIND_SUPPORT void *maps__addr_space (const struct maps *maps);void maps__set_addr_space (struct maps *maps,void *addr_space); -const struct unwind_libunwind_ops *maps__unwind_libunwind_ops (const struct maps *maps); -void maps__set_unwind_libunwind_ops (struct maps *maps,const struct unwind_libunwind_ops *ops);uint16_t maps__e_machine (const struct maps *maps);void maps__set_e_machine (struct maps *maps,uint16_t e_machine);#endif
tools/perf/util/unwind-libunwind-local.c deleted +0 -819
75 lines not on this page · raw message
tools/perf/util/unwind-libunwind.c +623 -31
654 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Part of the diff is not shown here. View the raw message.
Ian Rogers
reviewerPATCH v4 8/8 perf unwind-libunwind: Add RISC-V libunwind support
In reply to Ian RogersAdd a RISC-V implementation for unwinding.
--- tools/perf/util/libunwind-arch/Build | 1 + .../perf/util/libunwind-arch/libunwind-arch.c | 21 ++ .../perf/util/libunwind-arch/libunwind-arch.h | 22 ++ .../util/libunwind-arch/libunwind-riscv.c | 297 ++++++++++++++++++ 4 files changed, 341 insertions(+) create mode 100644 tools/perf/util/libunwind-arch/libunwind-riscv.c
tools/perf/util/libunwind-arch/Build +1 -0
@@ -5,6 +5,7 @@ perf-util-$(CONFIG_LIBUNWIND) += libunwind-loongarch.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-mips.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-ppc32.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-ppc64.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-riscv.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-s390.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-i386.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-x86_64.o
tools/perf/util/libunwind-arch/libunwind-arch.c +21 -0
@@ -20,6 +20,8 @@ int get_perf_regnum_for_unw_regnum(unsigned int e_machine, int unw_regnum)return __get_perf_regnum_for_unw_regnum_ppc32 (unw_regnum);case EM_PPC64 :return __get_perf_regnum_for_unw_regnum_ppc64 (unw_regnum); +case EM_RISCV : +return __get_perf_regnum_for_unw_regnum_riscv (unw_regnum);case EM_S390 :return __get_perf_regnum_for_unw_regnum_s390 (unw_regnum);case EM_386 :
@@ -58,6 +60,9 @@ void libunwind_arch__flush_access(struct maps *maps)case EM_PPC64 :__libunwind_arch__flush_access_ppc64 (maps);break ; +case EM_RISCV : +__libunwind_arch__flush_access_riscv (maps); +break ;case EM_S390 :__libunwind_arch__flush_access_s390 (maps);break ;
@@ -98,6 +103,9 @@ void libunwind_arch__finish_access(struct maps *maps)case EM_PPC64 :__libunwind_arch__finish_access_ppc64 (maps);break ; +case EM_RISCV : +__libunwind_arch__finish_access_riscv (maps); +break ;case EM_S390 :__libunwind_arch__finish_access_s390 (maps);break ;
@@ -128,6 +136,8 @@ void *libunwind_arch__create_addr_space(unsigned int e_machine)return __libunwind_arch__create_addr_space_ppc32 ();case EM_PPC64 :return __libunwind_arch__create_addr_space_ppc64 (); +case EM_RISCV : +return __libunwind_arch__create_addr_space_riscv ();case EM_S390 :return __libunwind_arch__create_addr_space_s390 ();case EM_386 :
@@ -167,6 +177,9 @@ int libunwind_arch__dwarf_search_unwind_table(unsigned int e_machine,case EM_PPC64 :return __libunwind_arch__dwarf_search_unwind_table_ppc64 (as, ip, di, pi, need_unwind_info, arg); +case EM_RISCV : +return __libunwind_arch__dwarf_search_unwind_table_riscv (as, ip, di, pi, + need_unwind_info, arg);case EM_S390 :return __libunwind_arch__dwarf_search_unwind_table_s390 (as, ip, di, pi, need_unwind_info, arg);
@@ -211,6 +224,9 @@ int libunwind_arch__dwarf_find_debug_frame(unsigned int e_machine,case EM_PPC64 :return __libunwind_arch__dwarf_find_debug_frame_ppc64 (found, di_debug, ip, segbase, obj_name, start, end); +case EM_RISCV : +return __libunwind_arch__dwarf_find_debug_frame_riscv (found, di_debug, ip, segbase, + obj_name, start, end);case EM_S390 :return __libunwind_arch__dwarf_find_debug_frame_s390 (found, di_debug, ip, segbase, obj_name, start, end);
@@ -250,6 +266,9 @@ struct unwind_info *libunwind_arch_unwind_info__new(struct thread *thread,case EM_PPC64 :return __libunwind_arch_unwind_info__new_ppc64 (thread, sample, max_stack, best_effort, first_ip); +case EM_RISCV : +return __libunwind_arch_unwind_info__new_riscv (thread, sample, max_stack, + best_effort, first_ip);case EM_S390 :return __libunwind_arch_unwind_info__new_s390 (thread, sample, max_stack, best_effort, first_ip);
@@ -285,6 +304,8 @@ int libunwind_arch__unwind_step(struct unwind_info *ui)return __libunwind_arch__unwind_step_ppc32 (ui);case EM_PPC64 :return __libunwind_arch__unwind_step_ppc64 (ui); +case EM_RISCV : +return __libunwind_arch__unwind_step_riscv (ui);case EM_S390 :return __libunwind_arch__unwind_step_s390 (ui);case EM_386 :
tools/perf/util/libunwind-arch/libunwind-arch.h +22 -0
@@ -39,6 +39,7 @@ int __get_perf_regnum_for_unw_regnum_loongarch(int unw_regnum);int __get_perf_regnum_for_unw_regnum_mips (int unw_regnum);int __get_perf_regnum_for_unw_regnum_ppc32 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_ppc64 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_riscv (int unw_regnum);int __get_perf_regnum_for_unw_regnum_s390 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_i386 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_x86_64 (int unw_regnum);
@@ -50,6 +51,7 @@ void __libunwind_arch__flush_access_loongarch(struct maps *maps);void __libunwind_arch__flush_access_mips (struct maps *maps);void __libunwind_arch__flush_access_ppc32 (struct maps *maps);void __libunwind_arch__flush_access_ppc64 (struct maps *maps); +void __libunwind_arch__flush_access_riscv (struct maps *maps);void __libunwind_arch__flush_access_s390 (struct maps *maps);void __libunwind_arch__flush_access_i386 (struct maps *maps);void __libunwind_arch__flush_access_x86_64 (struct maps *maps);
@@ -61,6 +63,7 @@ void __libunwind_arch__finish_access_loongarch(struct maps *maps);void __libunwind_arch__finish_access_mips (struct maps *maps);void __libunwind_arch__finish_access_ppc32 (struct maps *maps);void __libunwind_arch__finish_access_ppc64 (struct maps *maps); +void __libunwind_arch__finish_access_riscv (struct maps *maps);void __libunwind_arch__finish_access_s390 (struct maps *maps);void __libunwind_arch__finish_access_i386 (struct maps *maps);void __libunwind_arch__finish_access_x86_64 (struct maps *maps);
@@ -72,6 +75,7 @@ void *__libunwind_arch__create_addr_space_loongarch(void);void *__libunwind_arch__create_addr_space_mips (void );void *__libunwind_arch__create_addr_space_ppc32 (void );void *__libunwind_arch__create_addr_space_ppc64 (void ); +void *__libunwind_arch__create_addr_space_riscv (void );void *__libunwind_arch__create_addr_space_s390 (void );void *__libunwind_arch__create_addr_space_i386 (void );void *__libunwind_arch__create_addr_space_x86_64 (void );
@@ -111,6 +115,11 @@ int __libunwind_arch__dwarf_search_unwind_table_ppc64(void *as, uint64_t ip,void *pi, int need_unwind_info, void *arg); +int __libunwind_arch__dwarf_search_unwind_table_riscv (void *as,uint64_t ip, +struct libarch_unwind__dyn_info *di, +void *pi, +int need_unwind_info, +void *arg); int __libunwind_arch__dwarf_search_unwind_table_s390(void *as, uint64_t ip, struct libarch_unwind__dyn_info *di, void *pi,
@@ -176,6 +185,13 @@ int __libunwind_arch__dwarf_find_debug_frame_ppc64(int found,const char *obj_name, uint64_t start, uint64_t end); +int __libunwind_arch__dwarf_find_debug_frame_riscv (int found, +struct libarch_unwind__dyn_info *di_debug, +uint64_t ip, +uint64_t segbase, +const char *obj_name, +uint64_t start, +uint64_t end); int __libunwind_arch__dwarf_find_debug_frame_s390(int found, struct libarch_unwind__dyn_info *di_debug, uint64_t ip,
@@ -236,6 +252,11 @@ struct unwind_info *__libunwind_arch_unwind_info__new_ppc64(struct thread *threaint max_stack, bool best_effort, uint64_t first_ip); +struct unwind_info *__libunwind_arch_unwind_info__new_riscv (struct thread *thread, +struct perf_sample *sample, +int max_stack, +bool best_effort, +uint64_t first_ip); struct unwind_info *__libunwind_arch_unwind_info__new_s390(struct thread *thread, struct perf_sample *sample, int max_stack,
@@ -266,6 +287,7 @@ int __libunwind_arch__unwind_step_loongarch(struct unwind_info *ui);int __libunwind_arch__unwind_step_mips (struct unwind_info *ui);int __libunwind_arch__unwind_step_ppc32 (struct unwind_info *ui);int __libunwind_arch__unwind_step_ppc64 (struct unwind_info *ui); +int __libunwind_arch__unwind_step_riscv (struct unwind_info *ui);int __libunwind_arch__unwind_step_s390 (struct unwind_info *ui);int __libunwind_arch__unwind_step_i386 (struct unwind_info *ui);int __libunwind_arch__unwind_step_x86_64 (struct unwind_info *ui);
tools/perf/util/libunwind-arch/libunwind-riscv.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Ian Rogers
reviewerQuoted 15 lines · Ian Rogers
Fix the libunwind build for when libdw and libunwind are feature detected, currently failing with a duplicate symbol.
Refactor the libunwind support so that whenever a remote target is available, perf functions using the ELF machine can use that remote target regardless of what the host/local machine is. Migrate existing libunwind supported architectures like powerpc, arm64 and loongarch so that they can work in a cross-architecture way. Add support for RISC-V. Make the code more regular in function names, etc. and avoid including a C-file. This increases the lines of code. It is similar in style to the unwind-libdw implementation. It is hoped that the more uniform nature of the code with help with refactoring the perf registers for SIMD/APX support.
Quoted 3 lines
Aside from local host testing these patches are under tested, in part as I'm failing to see how to build libunwind with support for multiple remote targets. Please could I get help in testing.
Hmm.. these were reposted in part for Sashiko reviews but that has failed:
https://sashiko.dev/#/log/baseline/9180/2
``` Trying baseline: perf-tools-next/perf-tools-next (4e03d6494f9504f8af46ba68a2a8b6877c196789) Patch 9180/4 (ID: 24748) failed to apply. Application failed. ```
While my local tree shows that I have perf-tools-next plus these 8 patches. I'll wait a while, rebase and repost.
Thanks,
Ian
Quoted 112 lines
v4: Rebase, in particular the
zalloc->callocchange conflicted.v3: Minor whitespace clean up and warn when a dynamic choice of libdw
or libunwind is selected for unwinding and support is missing (Arnaldo).
https://lore.kernel.org/lkml/[email protected]/v2: Move two fixes patches to position 1 and 2 in the series. Fix
struct naming inconsistency, Andrew Jones <[email protected]>. Fix other inconsistencies and potential non-x86 build issues.
https://lore.kernel.org/lkml/[email protected]/v1: https://lore.kernel.org/lkml/[email protected]/
Ian Rogers (8):
perf unwind: Refactorget_entriesto allow dynamic libdw/libunwind
selection
perf build loongarch: Remove reference to missing file tools build: Deduplicate test-libunwind for different architectures perf build: Be more programmatic when setting up libunwind variables perf unwind-libunwind: Make libunwind register reading cross platform perf unwind-libunwind: Move flush/finish access out of local perf unwind-libunwind: Remove libunwind-local
perf unwind-libunwind: Add RISC-V libunwind supporttools/build/feature/Makefile | 38 +- tools/build/feature/test-libunwind-aarch64.c | 27 - tools/build/feature/test-libunwind-arm.c | 28 - .../test-libunwind-debug-frame-aarch64.c | 17 - .../feature/test-libunwind-debug-frame-arm.c | 17 - .../feature/test-libunwind-debug-frame.c | 1 - tools/build/feature/test-libunwind-x86.c | 28 - tools/build/feature/test-libunwind-x86_64.c | 28 - tools/build/feature/test-libunwind.c | 1 - tools/perf/Makefile.config | 215 ++--- tools/perf/arch/arm/util/Build | 2 - tools/perf/arch/arm/util/unwind-libunwind.c | 50 -- tools/perf/arch/arm64/util/Build | 1 - tools/perf/arch/arm64/util/unwind-libunwind.c | 17 - tools/perf/arch/loongarch/util/Build | 3 - .../arch/loongarch/util/unwind-libunwind.c | 82 -- tools/perf/arch/mips/Build | 1 - tools/perf/arch/mips/util/Build | 1 - tools/perf/arch/mips/util/unwind-libunwind.c | 22 - tools/perf/arch/powerpc/util/Build | 1 - .../perf/arch/powerpc/util/unwind-libunwind.c | 92 -- tools/perf/arch/x86/util/Build | 3 - tools/perf/arch/x86/util/unwind-libunwind.c | 115 --- tools/perf/builtin-inject.c | 4 + tools/perf/builtin-report.c | 4 + tools/perf/builtin-script.c | 4 + tools/perf/util/Build | 5 +- tools/perf/util/libunwind-arch/Build | 11 + .../perf/util/libunwind-arch/libunwind-arch.c | 319 +++++++ .../perf/util/libunwind-arch/libunwind-arch.h | 296 +++++++ .../perf/util/libunwind-arch/libunwind-arm.c | 290 ++++++ .../util/libunwind-arch/libunwind-arm64.c | 289 ++++++ .../perf/util/libunwind-arch/libunwind-i386.c | 312 +++++++ .../util/libunwind-arch/libunwind-loongarch.c | 297 +++++++ .../perf/util/libunwind-arch/libunwind-mips.c | 299 +++++++ .../util/libunwind-arch/libunwind-ppc32.c | 301 +++++++ .../util/libunwind-arch/libunwind-ppc64.c | 303 +++++++ .../util/libunwind-arch/libunwind-riscv.c | 297 +++++++ .../perf/util/libunwind-arch/libunwind-s390.c | 299 +++++++ .../util/libunwind-arch/libunwind-x86_64.c | 320 +++++++ tools/perf/util/libunwind/arm64.c | 40 - tools/perf/util/libunwind/x86_32.c | 41 - tools/perf/util/maps.c | 29 +- tools/perf/util/maps.h | 4 +- tools/perf/util/symbol_conf.h | 10 + tools/perf/util/thread.c | 29 +- tools/perf/util/unwind-libdw.c | 2 +- tools/perf/util/unwind-libunwind-local.c | 831 ------------------ tools/perf/util/unwind-libunwind.c | 679 ++++++++++++-- tools/perf/util/unwind.c | 98 +++ tools/perf/util/unwind.h | 77 +- 51 files changed, 4549 insertions(+), 1731 deletions(-) delete mode 100644 tools/build/feature/test-libunwind-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-arm.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-arm.c delete mode 100644 tools/build/feature/test-libunwind-x86.c delete mode 100644 tools/build/feature/test-libunwind-x86_64.c delete mode 100644 tools/perf/arch/arm/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/arm64/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/loongarch/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/mips/Build delete mode 100644 tools/perf/arch/mips/util/Build delete mode 100644 tools/perf/arch/mips/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/powerpc/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/x86/util/unwind-libunwind.c create mode 100644 tools/perf/util/libunwind-arch/Build create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.h create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-i386.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-loongarch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-mips.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc32.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-riscv.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-s390.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-x86_64.c delete mode 100644 tools/perf/util/libunwind/arm64.c delete mode 100644 tools/perf/util/libunwind/x86_32.c delete mode 100644 tools/perf/util/unwind-libunwind-local.c create mode 100644 tools/perf/util/unwind.c--
2.53.0.1213.gd9a14994de-goog
Ian Rogers
reviewerv5 cover perf libunwind multiple remote support
In reply to Ian RogersFix the libunwind build for when libdw and libunwind are feature detected, currently failing with a duplicate symbol.
Refactor the libunwind support so that whenever a remote target is available, perf functions using the ELF machine can use that remote target regardless of what the host/local machine is. Migrate existing libunwind supported architectures like powerpc, arm64 and loongarch so that they can work in a cross-architecture way. Add support for RISC-V. Make the code more regular in function names, etc. and avoid including a C-file. This increases the lines of code. It is similar in style to the unwind-libdw implementation. It is hoped that the more uniform nature of the code will help with refactoring the perf registers for SIMD/APX support.
Aside from local host testing these patches are under tested, in part as I'm failing to see how to build libunwind with support for multiple remote targets. Please could I get help in testing.
v5: Rebase dropping merged loong arch fix patch. Fixes to Sashiko
review feedback:
- Patch 1: Hooked unwind__configure() into perf_default_config(). Standardized unwinder return contracts (>0 success, 0 fallback, <0 fatal). Fixed UNWIND_STYLE_UNKNOWN fallback and added memset() to clear config array on override.
- Patch 2: Dynamically populated FILES list in tools/build/feature/Makefile using LIBUNWIND_ARCHS. Added libunwind cases to FEATURE_TESTS_EXTRA in tools/build/Makefile.feature for proper FEATURE-DUMP caching.
- Patch 3: Restored core -lunwind linkage to FEATURE_CHECK_LDFLAGS. Restored NO_LIBUNWIND fallback validation, corrected EXTLIBS evaluation ordering for BIONIC/Android compatibility, and restored static linking multiple definition flags.
- Patch 4: Fixed out-of-bounds array read bugs (>= ARRAY_SIZE) in libunwind-i386.c and libunwind-x86_64.c. Fixed constant typos across LoongArch, PowerPC, and s390x.
- Patch 5: Added early EM_NONE and ops validation checks to prevent warnings and NULL dereferences. Checked return value of unwind__prepare_access() in maps__copy_from(). Corrected architecture binding in thread__insert_map() by calculating e_machine after map insertion.
- Patch 6: Aligned all remote architecture accessors to match 5-argument generic declarations (removing trailing sizeof(unw_word_t)). Prevented frame discard on stack depth limit by returning 0 instead of -1 in unwind_step(). Fixed 32-bit big-endian register corruption by replacing memcpy() with conditional type-casted assignment. Fixed max_stack == 1 fallback trigger. Fixed .debug_frame layout union corruption by changing di.u.rti to di.u.ti across all DWARF find wrappers.
- Patch 7: Applied the same corrections (5-argument accessors, u.ti union accessors, 0 return on max_ips) to the newly introduced libunwind-riscv.c.
v4: Rebase, in particular the zalloc->calloc change conflicted.
https://lore.kernel.org/linux-perf-users/[email protected]/
v3: Minor whitespace clean up and warn when a dynamic choice of libdw
or libunwind is selected for unwinding and support is missing (Arnaldo).
https://lore.kernel.org/lkml/[email protected]/
v2: Move two fixes patches to position 1 and 2 in the series. Fix
struct naming inconsistency, Andrew Jones <[email protected]>. Fix other inconsistencies and potential non-x86 build issues.
https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
Ian Rogers (7):
perf unwind: Refactor get_entries to allow dynamic libdw/libunwind
selection
tools build: Deduplicate test-libunwind for different architectures perf build: Be more programmatic when setting up libunwind variables perf unwind-libunwind: Make libunwind register reading cross platform perf unwind-libunwind: Move flush/finish access out of local perf unwind-libunwind: Remove libunwind-local
perf unwind-libunwind: Add RISC-V libunwind support
tools/build/Makefile.feature | 12 +- tools/build/feature/Makefile | 46 +- tools/build/feature/test-libunwind-aarch64.c | 27 - tools/build/feature/test-libunwind-arm.c | 28 - .../test-libunwind-debug-frame-aarch64.c | 17 - .../feature/test-libunwind-debug-frame-arm.c | 17 - .../feature/test-libunwind-debug-frame.c | 1 - tools/build/feature/test-libunwind-x86.c | 28 - tools/build/feature/test-libunwind-x86_64.c | 28 - tools/build/feature/test-libunwind.c | 1 - tools/perf/Makefile.config | 226 +++-- tools/perf/arch/arm/util/Build | 2 - tools/perf/arch/arm/util/unwind-libunwind.c | 50 -- tools/perf/arch/arm64/util/Build | 1 - tools/perf/arch/arm64/util/unwind-libunwind.c | 17 - tools/perf/arch/loongarch/util/Build | 2 - .../arch/loongarch/util/unwind-libunwind.c | 82 -- tools/perf/arch/mips/Build | 1 - tools/perf/arch/mips/util/Build | 1 - tools/perf/arch/mips/util/unwind-libunwind.c | 22 - tools/perf/arch/powerpc/util/Build | 1 - .../perf/arch/powerpc/util/unwind-libunwind.c | 92 -- tools/perf/arch/x86/util/Build | 3 - tools/perf/arch/x86/util/unwind-libunwind.c | 115 --- tools/perf/builtin-inject.c | 4 + tools/perf/builtin-report.c | 4 + tools/perf/builtin-script.c | 4 + tools/perf/util/Build | 5 +- tools/perf/util/config.c | 4 + tools/perf/util/libunwind-arch/Build | 11 + .../perf/util/libunwind-arch/libunwind-arch.c | 319 +++++++ .../perf/util/libunwind-arch/libunwind-arch.h | 296 +++++++ .../perf/util/libunwind-arch/libunwind-arm.c | 290 ++++++ .../util/libunwind-arch/libunwind-arm64.c | 289 ++++++ .../perf/util/libunwind-arch/libunwind-i386.c | 312 +++++++ .../util/libunwind-arch/libunwind-loongarch.c | 297 +++++++ .../perf/util/libunwind-arch/libunwind-mips.c | 299 +++++++ .../util/libunwind-arch/libunwind-ppc32.c | 301 +++++++ .../util/libunwind-arch/libunwind-ppc64.c | 303 +++++++ .../util/libunwind-arch/libunwind-riscv.c | 297 +++++++ .../perf/util/libunwind-arch/libunwind-s390.c | 299 +++++++ .../util/libunwind-arch/libunwind-x86_64.c | 320 +++++++ tools/perf/util/libunwind/arm64.c | 40 - tools/perf/util/libunwind/x86_32.c | 41 - tools/perf/util/maps.c | 34 +- tools/perf/util/maps.h | 4 +- tools/perf/util/symbol_conf.h | 10 + tools/perf/util/thread.c | 32 +- tools/perf/util/unwind-libdw.c | 20 +- tools/perf/util/unwind-libunwind-local.c | 831 ------------------ tools/perf/util/unwind-libunwind.c | 699 +++++++++++++-- tools/perf/util/unwind.c | 104 +++ tools/perf/util/unwind.h | 73 +- 53 files changed, 4623 insertions(+), 1739 deletions(-) delete mode 100644 tools/build/feature/test-libunwind-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-arm.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-arm.c delete mode 100644 tools/build/feature/test-libunwind-x86.c delete mode 100644 tools/build/feature/test-libunwind-x86_64.c delete mode 100644 tools/perf/arch/arm/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/arm64/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/loongarch/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/mips/Build delete mode 100644 tools/perf/arch/mips/util/Build delete mode 100644 tools/perf/arch/mips/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/powerpc/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/x86/util/unwind-libunwind.c create mode 100644 tools/perf/util/libunwind-arch/Build create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.h create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-i386.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-loongarch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-mips.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc32.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-riscv.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-s390.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-x86_64.c delete mode 100644 tools/perf/util/libunwind/arm64.c delete mode 100644 tools/perf/util/libunwind/x86_32.c delete mode 100644 tools/perf/util/unwind-libunwind-local.c create mode 100644 tools/perf/util/unwind.c
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 1/7 perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection
Currently, both libdw and libunwind define 'unwind__get_entries'. This causes a duplicate symbol build failure when both are compiled into perf.
This commit refactors the DWARF unwind post-processing to be configurable at runtime via the .perfconfig file option 'unwind.style', or using the argument '--unwind-style' in the commands 'perf report', 'perf script' and 'perf inject', in a similar manner to the addr2line or the disassembler style.
The file 'tools/perf/util/unwind.c' adds the top-level dispatch function 'unwind__get_entries'. The backend implementations are renamed to 'libdw__get_entries' and 'libunwind__get_entries'. Both are attempted as fallbacks if not configured, or if the primary backend fails.
--- tools/perf/builtin-inject.c | 4 + tools/perf/builtin-report.c | 4 + tools/perf/builtin-script.c | 4 + tools/perf/util/Build | 1 + tools/perf/util/config.c | 4 + tools/perf/util/symbol_conf.h | 10 +++ tools/perf/util/unwind-libdw.c | 18 +++- tools/perf/util/unwind-libunwind-local.c | 27 ++++-- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/unwind.c | 104 +++++++++++++++++++++++ tools/perf/util/unwind.h | 61 ++++++++----- 11 files changed, 207 insertions(+), 32 deletions(-) create mode 100644 tools/perf/util/unwind.c
tools/perf/builtin-inject.c +4 -0
@@ -26,6 +26,7 @@#include "util/synthetic-events.h" #include "util/thread.h" #include "util/namespaces.h" +#include "util/unwind.h" #include "util/util.h" #include "util/tsc.h"
@@ -2563,6 +2564,9 @@ int cmd_inject(int argc, const char **argv)OPT_STRING (0 ,"guestmount" , &symbol_conf.guestmount,"directory" ,"guest mount directory under which every guest os" " instance has a subdir" ), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_BOOLEAN (0 ,"convert-callchain" , &inject.convert_callchain,"Generate callchains using DWARF and drop register/stack data" ),OPT_END ()
tools/perf/builtin-report.c +4 -0
@@ -48,6 +48,7 @@#include "util/time-utils.h" #include "util/auxtrace.h" #include "util/units.h" +#include "util/unwind.h" #include "util/util.h" // perf_tip() #include "ui/ui.h" #include "ui/progress.h"
@@ -1449,6 +1450,9 @@ int cmd_report(int argc, const char **argv)OPT_CALLBACK (0 ,"addr2line-style" ,NULL ,"addr2line style" ,"addr2line styles (libdw,llvm,libbfd,addr2line)" , report_parse_addr2line_config), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_BOOLEAN (0 ,"demangle" , &symbol_conf.demangle,"Symbol demangling. Enabled by default, use --no-demangle to disable." ), OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
tools/perf/builtin-script.c +4 -0
@@ -63,6 +63,7 @@#include <linux/err.h> #include "util/dlfilter.h" #include "util/record.h" +#include "util/unwind.h" #include "util/util.h" #include "util/cgroup.h" #include "util/annotate.h"
@@ -4159,6 +4160,9 @@ int cmd_script(int argc, const char **argv) "Enable symbol demangling"),OPT_BOOLEAN (0 ,"demangle-kernel" , &symbol_conf.demangle_kernel,"Enable kernel symbol demangling" ), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_STRING (0 ,"addr2line" , &symbol_conf.addr2line_path,"path" ,"addr2line binary to use for line numbers" ), OPT_STRING(0, "time", &script.time_str, "str",
tools/perf/util/Build +1 -0
@@ -216,6 +216,7 @@ ifndef CONFIG_SETNS perf-util-y += setns.o endif +perf-util-y += unwind.o perf-util-$(CONFIG_LIBDW) += probe-finder.o perf-util-$(CONFIG_LIBDW) += dwarf-aux.o perf-util-$(CONFIG_LIBDW) += dwarf-regs.o
tools/perf/util/config.c +4 -0
@@ -23,6 +23,7 @@#include "build-id.h" #include "debug.h" #include "config.h" +#include "unwind.h" #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h>
@@ -525,6 +526,9 @@ int perf_default_config(const char *var, const char *value,if (strstarts (var,"addr2line." ))return addr2line_configure (var, value, dummy); +if (strstarts (var,"unwind." )) +return unwind__configure (var, value, dummy); +/* Add other config variables here. */ return 0 ; }
tools/perf/util/symbol_conf.h +10 -0
@@ -9,6 +9,15 @@struct strlist ;struct intlist ; +enum unwind_style { +UNWIND_STYLE_UNKNOWN =0 , +UNWIND_STYLE_LIBDW , +UNWIND_STYLE_LIBUNWIND , +}; + +#define MAX_UNWIND_STYLE (UNWIND_STYLE_LIBUNWIND + 1) + +enum a2l_style {A2L_STYLE_UNKNOWN =0 ,A2L_STYLE_LIBDW ,
@@ -81,6 +90,7 @@ struct symbol_conf {const char *addr2line_path;enum a2l_style addr2line_style[MAX_A2L_STYLE ];int addr2line_timeout_ms; +enum unwind_style unwind_style[MAX_UNWIND_STYLE ];unsigned long time_quantum;struct strlist *dso_list, *comm_list,
tools/perf/util/unwind-libdw.c +15 -3
@@ -339,7 +339,7 @@ frame_callback(Dwfl_Frame *state, void *arg) DWARF_CB_ABORT :DWARF_CB_OK ; } -int unwind__get_entries(unwind_entry_cb_t cb, void *arg, +int libdw__get_entries(unwind_entry_cb_t cb, void *arg, struct thread *thread, struct perf_sample *data, int max_stack,
@@ -356,7 +356,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,int err = -EINVAL , i;if (!data->user_regs || !data->user_regs->regs) -return -EINVAL ; +return 0 ; ui =zalloc (sizeof (*ui) +sizeof (ui->entries[0 ]) * max_stack);if (!ui)
@@ -430,6 +430,18 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,map_symbol__exit (&ui->entries[i].ms); dwfl_ui_ti->ui =NULL ; +int entries = (int )ui->idx;free (ui); -return 0 ; +/* +* Unwinder return contract: +* > 0 : unwinding succeeded (stops fallback). If we found frames but hit an error +* (e.g. truncated stack), report success to preserve existing frames. +* 0 : unwinding failed without yielding frames. Ignore non-fatal errors +* (e.g. missing debug info, DWARF corruption) to allow fallback unwinder or +* kernel callchain resolution to proceed. +* < 0 : fatal error (e.g. -ENOMEM). Aborts unwinding entirely. +*/ +if (err) +return (err == -ENOMEM ) ? -ENOMEM : (entries >0 ?1 :0 ); +return entries; }
tools/perf/util/unwind-libunwind-local.c +21 -6
@@ -744,7 +744,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, ret =perf_reg_value (&val,perf_sample__user_regs (ui->sample),perf_arch_reg_ip (e_machine));if (ret) -return ret; +return 0 ; ips[i++] = (unw_word_t ) val;
@@ -757,7 +757,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, addr_space =maps__addr_space (thread__maps (ui->thread));if (addr_space ==NULL ) -return -1 ; +return 0 ; ret =unw_init_remote (&c, addr_space, ui);if (ret && !ui->best_effort)
@@ -785,15 +785,30 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,/* * Display what we got based on the order setup. */ +int entries =0 ;for (i =0 ; i < max_stack && !ret; i++) {int j = i;if (callchain_param.order ==ORDER_CALLER ) j = max_stack - i -1 ; - ret = ips[j] ?entry (ips[j], ui->thread, cb, arg) :0 ; +if (ips[j]) { + ret =entry (ips[j], ui->thread, cb, arg); +if (ret) +break ; + entries++; + } } -return ret; +/* +* Unwinder return contract: +* > 0 : unwinding succeeded (stops fallback). +* 0 : unwinding failed without yielding frames. Ignore non-fatal errors +* (e.g. stepping failure) to allow fallback unwinder or kernel callchains. +* < 0 : fatal error (e.g. -ENOMEM). Aborts unwinding entirely. +*/ +if (ret == -ENOMEM ) +return -ENOMEM ; +return (entries >0 || ret ==0 ) ? entries :0 ; } static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,
@@ -809,10 +824,10 @@ static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg, };if (!data->user_regs || !data->user_regs->regs) -return -EINVAL ; +return 0 ;if (max_stack <=0 ) -return -EINVAL ; +return 0 ;return get_entries (&ui, cb, arg, max_stack); }
tools/perf/util/unwind-libunwind.c +1 -1
@@ -79,7 +79,7 @@ void unwind__finish_access(struct maps *maps) ops->finish_access (maps); } -int unwind__get_entries (unwind_entry_cb_t cb,void *arg, +int libunwind__get_entries (unwind_entry_cb_t cb,void *arg,struct thread *thread,struct perf_sample *data,int max_stack,bool best_effort)
tools/perf/util/unwind.c new file +104 -0
104 lines not on this page · raw message
tools/perf/util/unwind.h +39 -22
93 lines not on this page · raw message
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v5 1/7] perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection
Quoted 184 lines · Ian Rogers
Currently, both libdw and libunwind define '
unwind__get_entries'. This causes a duplicate symbol build failure when both are compiled into perf.This commit refactors the DWARF unwind post-processing to be configurable at runtime via the .perfconfig file option 'unwind.style', or using the argument '--unwind-style' in the commands 'perf report', 'perf script' and 'perf inject', in a similar manner to the addr2line or the disassembler style.
The file '
tools/perf/util/unwind.c' adds the top-level dispatch function 'unwind__get_entries'. The backend implementations are renamed to 'libdw__get_entries' and 'libunwind__get_entries'. Both are attempted as fallbacks if not configured, or if the primary backend fails.Fixes 2e9191573a69 ("perf build: Remove NO_LIBDW_DWARF_UNWIND option")Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-inject.c | 4 + tools/perf/builtin-report.c | 4 + tools/perf/builtin-script.c | 4 + tools/perf/util/Build | 1 + tools/perf/util/config.c | 4 + tools/perf/util/symbol_conf.h | 10 +++ tools/perf/util/unwind-libdw.c | 18 +++- tools/perf/util/unwind-libunwind-local.c | 27 ++++-- tools/perf/util/unwind-libunwind.c | 2 +- tools/perf/util/unwind.c | 104 +++++++++++++++++++++++ tools/perf/util/unwind.h | 61 ++++++++----- 11 files changed, 207 insertions(+), 32 deletions(-) create mode 100644 tools/perf/util/unwind.ctools/perf/builtin-inject.c +4
-0@@ -26,6 +26,7 @@#include "util/synthetic-events.h" #include "util/thread.h" #include "util/namespaces.h" +#include "util/unwind.h" #include "util/util.h" #include "util/tsc.h" @@ -2563,6 +2564,9 @@ int cmd_inject(int argc, const char **argv)OPT_STRING (0 ,"guestmount" , &symbol_conf.guestmount,"directory" ,"guest mount directory under which every guest os" " instance has a subdir" ), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_BOOLEAN (0 ,"convert-callchain" , &inject.convert_callchain,"Generate callchains using DWARF and drop register/stack data" ),OPT_END ()tools/perf/builtin-report.c +4
-0@@ -48,6 +48,7 @@#include "util/time-utils.h" #include "util/auxtrace.h" #include "util/units.h" +#include "util/unwind.h" #include "util/util.h" // perf_tip() #include "ui/ui.h" #include "ui/progress.h" @@ -1449,6 +1450,9 @@ int cmd_report(int argc, const char **argv)OPT_CALLBACK (0 ,"addr2line-style" ,NULL ,"addr2line style" ,"addr2line styles (libdw,llvm,libbfd,addr2line)" , report_parse_addr2line_config), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_BOOLEAN (0 ,"demangle" , &symbol_conf.demangle,"Symbol demangling. Enabled by default, use --no-demangle to disable." ), OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,tools/perf/builtin-script.c +4
-0@@ -63,6 +63,7 @@#include <linux/err.h> #include "util/dlfilter.h" #include "util/record.h" +#include "util/unwind.h" #include "util/util.h" #include "util/cgroup.h" #include "util/annotate.h" @@ -4159,6 +4160,9 @@ int cmd_script(int argc, const char **argv) "Enable symbol demangling"),OPT_BOOLEAN (0 ,"demangle-kernel" , &symbol_conf.demangle_kernel,"Enable kernel symbol demangling" ), +OPT_CALLBACK (0 ,"unwind-style" ,NULL ,"unwind style" , +"unwind styles (libdw,libunwind)" , + unwind__option),OPT_STRING (0 ,"addr2line" , &symbol_conf.addr2line_path,"path" ,"addr2line binary to use for line numbers" ), OPT_STRING(0, "time", &script.time_str, "str",tools/perf/util/Build +1
-0@@ -216,6 +216,7 @@ ifndef CONFIG_SETNS perf-util-y += setns.o endif +perf-util-y += unwind.o perf-util-$(CONFIG_LIBDW) += probe-finder.o perf-util-$(CONFIG_LIBDW) += dwarf-aux.o perf-util-$(CONFIG_LIBDW) += dwarf-regs.otools/perf/util/config.c +4
-0@@ -23,6 +23,7 @@#include "build-id.h" #include "debug.h" #include "config.h" +#include "unwind.h" #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> @@ -525,6 +526,9 @@ int perf_default_config(const char *var, const char *value,if (strstarts (var,"addr2line." ))return addr2line_configure (var, value, dummy); +if (strstarts (var,"unwind." )) +return unwind__configure (var, value, dummy); +/* Add other config variables here. */ return 0 ; }tools/perf/util/symbol_conf.h +10
-0@@ -9,6 +9,15 @@struct strlist ;struct intlist ; +enum unwind_style { +UNWIND_STYLE_UNKNOWN =0 , +UNWIND_STYLE_LIBDW , +UNWIND_STYLE_LIBUNWIND , +}; + +#define MAX_UNWIND_STYLE (UNWIND_STYLE_LIBUNWIND + 1) + +enum a2l_style {A2L_STYLE_UNKNOWN =0 ,A2L_STYLE_LIBDW ,@@ -81,6 +90,7 @@ struct symbol_conf {const char *addr2line_path;enum a2l_style addr2line_style[MAX_A2L_STYLE ];int addr2line_timeout_ms; +enum unwind_style unwind_style[MAX_UNWIND_STYLE ];unsigned long time_quantum;struct strlist *dso_list, *comm_list,tools/perf/util/unwind-libdw.c +2
-2@@ -339,7 +339,7 @@ frame_callback(Dwfl_Frame *state, void *arg) DWARF_CB_ABORT :DWARF_CB_OK ; } -int unwind__get_entries(unwind_entry_cb_t cb, void *arg, +int libdw__get_entries(unwind_entry_cb_t cb, void *arg, struct thread *thread, struct perf_sample *data, int max_stack,@@ -356,7 +356,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,int err = -EINVAL , i;if (!data->user_regs || !data->user_regs->regs) -return -EINVAL ; +return 0 ; ui =zalloc (sizeof (*ui) +sizeof (ui->entries[0 ]) * max_stack);if (!ui)
tools/perf/util/unwind-libdw.c int unwind__get_entries(unwind_entry_cb_t cb, void *arg, · line 433
Quoted 4 lines
tools/perf/util/unwind-libdw.c +1
-0@@ -430,6 +430,18 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,map_symbol__exit (&ui->entries[i].ms); dwfl_ui_ti->ui =NULL ; +int entries = (int )ui->idx;
Moved this 'entries' variable to the stgart of the function to address this on fedora 44:
CC /tmp/build/perf-tools-next/util/bpf-event.o
CC /tmp/build/perf-tools-next/util/pfm.outil/unwind-libdw.c: In function ‘libdw__get_entries’:util/unwind-libdw.c:433:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
433 | int entries = (int)ui->idx;
| ^~~cc1: all warnings being treated as errors
make[4]: *** [/home/acme/git/perf-tools-next/tools/build/Makefile.build:95: /tmp/build/perf-tools-next/util/unwind-libdw.o] Error 1
- Arnaldo
Quoted 311 lines
tools/perf/util/unwind-libdw.c +12
-1free (ui); -return 0 ; +/* +* Unwinder return contract: +* > 0 : unwinding succeeded (stops fallback). If we found frames but hit an error +* (e.g. truncated stack), report success to preserve existing frames. +* 0 : unwinding failed without yielding frames. Ignore non-fatal errors +* (e.g. missing debug info, DWARF corruption) to allow fallback unwinder or +* kernel callchain resolution to proceed. +* < 0 : fatal error (e.g. -ENOMEM). Aborts unwinding entirely. +*/ +if (err) +return (err == -ENOMEM ) ? -ENOMEM : (entries >0 ?1 :0 ); +return entries; }tools/perf/util/unwind-libunwind-local.c +21
-6@@ -744,7 +744,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, ret =perf_reg_value (&val,perf_sample__user_regs (ui->sample),perf_arch_reg_ip (e_machine));if (ret) -return ret; +return 0 ; ips[i++] = (unw_word_t ) val;@@ -757,7 +757,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb, addr_space =maps__addr_space (thread__maps (ui->thread));if (addr_space ==NULL ) -return -1 ; +return 0 ; ret =unw_init_remote (&c, addr_space, ui);if (ret && !ui->best_effort)@@ -785,15 +785,30 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,/* * Display what we got based on the order setup. */ +int entries =0 ;for (i =0 ; i < max_stack && !ret; i++) {int j = i;if (callchain_param.order ==ORDER_CALLER ) j = max_stack - i -1 ; - ret = ips[j] ?entry (ips[j], ui->thread, cb, arg) :0 ; +if (ips[j]) { + ret =entry (ips[j], ui->thread, cb, arg); +if (ret) +break ; + entries++; + } } -return ret; +/* +* Unwinder return contract: +* > 0 : unwinding succeeded (stops fallback). +* 0 : unwinding failed without yielding frames. Ignore non-fatal errors +* (e.g. stepping failure) to allow fallback unwinder or kernel callchains. +* < 0 : fatal error (e.g. -ENOMEM). Aborts unwinding entirely. +*/ +if (ret == -ENOMEM ) +return -ENOMEM ; +return (entries >0 || ret ==0 ) ? entries :0 ; } static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,@@ -809,10 +824,10 @@ static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg, };if (!data->user_regs || !data->user_regs->regs) -return -EINVAL ; +return 0 ;if (max_stack <=0 ) -return -EINVAL ; +return 0 ;return get_entries (&ui, cb, arg, max_stack); }tools/perf/util/unwind-libunwind.c +1
-1@@ -79,7 +79,7 @@ void unwind__finish_access(struct maps *maps) ops->finish_access (maps); } -int unwind__get_entries (unwind_entry_cb_t cb,void *arg, +int libunwind__get_entries (unwind_entry_cb_t cb,void *arg,struct thread *thread,struct perf_sample *data,int max_stack,bool best_effort)tools/perf/util/unwind.c new file +104
-0@@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "debug.h" +#include "symbol_conf.h" +#include "unwind.h" +#include <linux/string.h> +#include <string.h> +#include <stdlib.h> + +int unwind__get_entries (unwind_entry_cb_t cb__maybe_unused ,void *arg__maybe_unused , +struct thread *thread__maybe_unused , +struct perf_sample *data__maybe_unused , +int max_stack__maybe_unused , +bool best_effort__maybe_unused ) +{ +int ret =0 ; + +#if defined(HAVE_LIBDW_SUPPORT ) || defined(HAVE_LIBUNWIND_SUPPORT ) +if (symbol_conf.unwind_style[0 ] ==UNWIND_STYLE_UNKNOWN ) { +int i =0 ; +#ifdef HAVE_LIBDW_SUPPORT + symbol_conf.unwind_style[i++] =UNWIND_STYLE_LIBDW ; +#endif +#ifdef HAVE_LIBUNWIND_SUPPORT + symbol_conf.unwind_style[i++] =UNWIND_STYLE_LIBUNWIND ; +#endif + } +#endif //defined(HAVE_LIBDW_SUPPORT) || defined(HAVE_LIBUNWIND_SUPPORT) + +for (size_t i =0 ; i <ARRAY_SIZE (symbol_conf.unwind_style); i++) { +switch (symbol_conf.unwind_style[i]) { +case UNWIND_STYLE_LIBDW : + ret =libdw__get_entries (cb, arg, thread, data, max_stack, best_effort); +break ; +case UNWIND_STYLE_LIBUNWIND : + ret =libunwind__get_entries (cb, arg, thread, data, max_stack, best_effort); +break ; +case UNWIND_STYLE_UNKNOWN : +default : +#if !defined(HAVE_LIBDW_SUPPORT ) && !defined(HAVE_LIBUNWIND_SUPPORT ) +pr_warning_once ( +"Error: dwarf unwinding not supported, build perf with libdw or libunwind.\n" ); +#endif + ret =0 ; +break ; + } +if (ret >0 ) { + ret =0 ; +break ; + } +if (ret <0 ) +break ; + } +return ret; +} + +int unwind__configure (const char *var,const char *value,void *cb__maybe_unused ) +{ +static const char *const unwind_style_names[] = { + [UNWIND_STYLE_LIBDW ] ="libdw" , + [UNWIND_STYLE_LIBUNWIND ] ="libunwind" , +NULL + }; +char *s, *p, *saveptr; +size_t i =0 ; + +if (strcmp (var,"unwind.style" )) +return 0 ; + +if (!value) +return -1 ; + + s =strdup (value); +if (!s) +return -1 ; + +memset (symbol_conf.unwind_style,0 ,sizeof (symbol_conf.unwind_style)); + + p =strtok_r (s,"," , &saveptr); +while (p && i <ARRAY_SIZE (symbol_conf.unwind_style)) { +bool found = false; +char *q =strim (p); + +for (size_t j =UNWIND_STYLE_LIBDW ; j <MAX_UNWIND_STYLE ; j++) { +if (!strcasecmp (q, unwind_style_names[j])) { + symbol_conf.unwind_style[i++] = j; + found = true; +break ; + } + } +if (!found) +pr_warning ("Unknown unwind style: %s\n" , q); + p =strtok_r (NULL ,"," , &saveptr); + } + +free (s); +return 0 ; +} + +int unwind__option (const struct option *opt__maybe_unused , +const char *arg, +int unset__maybe_unused ) +{ +return unwind__configure ("unwind.style" , arg,NULL ); +}tools/perf/util/unwind.h +39
-22@@ -4,9 +4,10 @@#include <linux/compiler.h> #include <linux/types.h> -#include "util/map_symbol.h" +#include "map_symbol.h" struct maps ; +struct option ;struct perf_sample ;struct thread ;@@ -26,7 +27,9 @@ struct unwind_libunwind_ops { struct perf_sample *data, int max_stack, bool best_effort); }; -#ifdef HAVE_DWARF_UNWIND_SUPPORT +int unwind__configure (const char *var,const char *value,void *cb); +int unwind__option (const struct option *opt,const char *arg,int unset); +/* * When best_effort is set, don't report errors and fail silently. This could * be expanded in the future to be more permissive about things other than @@ -36,8 +39,31 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,struct thread *thread, struct perf_sample *data, int max_stack, bool best_effort); -/* libunwind specific */ + +#ifdef HAVE_LIBDW_SUPPORT +int libdw__get_entries (unwind_entry_cb_t cb,void *arg, +struct thread *thread, +struct perf_sample *data,int max_stack, +bool best_effort); +#else +#include "debug.h" +static inline int libdw__get_entries (unwind_entry_cb_t cb__maybe_unused ,void *arg__maybe_unused , +struct thread *thread__maybe_unused , +struct perf_sample *data__maybe_unused , +int max_stack__maybe_unused , +bool best_effort__maybe_unused ) +{ +pr_err ("Error: libdw dwarf unwinding not built into perf\n" ); +return 0 ; +} +#endif +#ifdef HAVE_LIBUNWIND_SUPPORT +/* libunwind specific */ +int libunwind__get_entries (unwind_entry_cb_t cb,void *arg, +struct thread *thread, +struct perf_sample *data,int max_stack, +bool best_effort);#ifndef LIBUNWIND__ARCH_REG_ID #define LIBUNWIND__ARCH_REG_ID (regnum) libunwind__arch_reg_id(regnum)#endif @@ -47,25 +73,15 @@ int unwind__prepare_access(struct maps *maps, struct map *map, bool *initializedvoid unwind__flush_access (struct maps *maps);void unwind__finish_access (struct maps *maps);#else -static inline int unwind__prepare_access (struct maps *maps__maybe_unused , -struct map *map__maybe_unused , -bool *initialized__maybe_unused ) -{ -return 0 ; -} - -static inline void unwind__flush_access (struct maps *maps__maybe_unused ) {} -static inline void unwind__finish_access (struct maps *maps__maybe_unused ) {} -#endif -#else -static inline int -unwind__get_entries (unwind_entry_cb_t cb__maybe_unused , -void *arg__maybe_unused , -struct thread *thread__maybe_unused , -struct perf_sample *data__maybe_unused , -int max_stack__maybe_unused , -bool best_effort__maybe_unused ) +#include "debug.h" +static inline int libunwind__get_entries (unwind_entry_cb_t cb__maybe_unused , +void *arg__maybe_unused , +struct thread *thread__maybe_unused , +struct perf_sample *data__maybe_unused , +int max_stack__maybe_unused , +bool best_effort__maybe_unused ) { +pr_err ("Error: libunwind dwarf unwinding not built into perf\n" );return 0 ; }@@ -78,5 +94,6 @@ static inline int unwind__prepare_access(struct maps *maps __maybe_unused,static inline void unwind__flush_access (struct maps *maps__maybe_unused ) {}static inline void unwind__finish_access (struct maps *maps__maybe_unused ) {} -#endif /* HAVE_DWARF_UNWIND_SUPPORT */ +#endif +#endif /* __UNWIND_H */ Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v5 1/7] perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection
Quoted 1 line · Arnaldo Carvalho de Melo
On Wed, May 13, 2026 at 04:31:45PM -0700, Ian Rogers wrote:
<SNIP>
Quoted 1 line
Quoted 1 line
+++
b/tools/perf/util/unwind.h
<SNIP>
Quoted 10 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+static inline int libdw__get_entries(unwind_entry_cb_t cb __maybe_unused, void *arg __maybe_unused, + struct thread *thread __maybe_unused, + struct perf_sample *data __maybe_unused, + int max_stack __maybe_unused, + bool best_effort __maybe_unused) +{ + pr_err("Error: libdw dwarf unwinding not built into perf\n"); + return 0; +} +#endif
I also addressed this local sashiko review comment:
-------------------------------------------------------------------------
Since unwinding is performed per-sample in the hot path, will using pr_err() here cause console flooding if the user explicitly configures an unsupported unwind style?
Should this use pr_warning_once() instead, similar to the UNWIND_STYLE_UNKNOWN fallback behavior in unwind.c?
-------------------------------------------------------------------------
And in one other place, please ack,
- Arnaldo
tools/perf/util/unwind.h +2 -2
@@ -53,7 +53,7 @@ static inline int libdw__get_entries(unwind_entry_cb_t cb __maybe_unused, void * int max_stack __maybe_unused, bool best_effort __maybe_unused) { -pr_err ("Error: libdw dwarf unwinding not built into perf\n" ); +pr_warning_once ("Error: libdw dwarf unwinding not built into perf\n" );return 0 ; }#endif
@@ -81,7 +81,7 @@ static inline int libunwind__get_entries(unwind_entry_cb_t cb __maybe_unused, int max_stack __maybe_unused, bool best_effort __maybe_unused) { -pr_err ("Error: libunwind dwarf unwinding not built into perf\n" ); +pr_warning_once ("Error: libunwind dwarf unwinding not built into perf\n" );return 0 ; }
Re: [PATCH v5 1/7] perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection
Quoted 31 lines · Arnaldo Carvalho de Melo
Quoted 1 line · Arnaldo Carvalho de Melo
On Wed, May 13, 2026 at 04:31:45PM -0700, Ian Rogers wrote:
<SNIP>
Quoted 1 line
Quoted 1 line
+++
b/tools/perf/util/unwind.h<SNIP>
Quoted 10 lines
Review
Quoted 10 lines
(quoted diff) +10
-0+static inline int libdw__get_entries(unwind_entry_cb_t cb __maybe_unused, void *arg __maybe_unused, + struct thread *thread __maybe_unused, + struct perf_sample *data __maybe_unused, + int max_stack __maybe_unused, + bool best_effort __maybe_unused) +{ + pr_err("Error: libdw dwarf unwinding not built into perf\n"); + return 0; +} +#endifI also addressed this local sashiko review comment:
-------------------------------------------------------------------------
Since unwinding is performed per-sample in the hot path, will usingpr_err()here cause console flooding if the user explicitly configures an unsupported unwind style?
Should this usepr_warning_once()instead, similar to theUNWIND_STYLE_UNKNOWNfallback behavior inunwind.c?
-------------------------------------------------------------------------
Quoted 1 line
And in one other place, please ack,
I think Sashiko is heavily biased toward warning about too much printing due to how the kernel handles printk, log spam, etc. For perf we have a problem that there's lots of verbose logging and logging something just once may lose the warning. This is somewhat the opposite problem to the kernel's. Do I care about the change that much? Not really. If someone is having a bad time, perhaps it makes it a little harder for them to know why but the priority is to not make people have a bad time.
Thanks,
Ian
Quoted 24 lines
- Arnaldo
tools/perf/util/unwind.h +2
-2@@ -53,7 +53,7 @@ static inline int libdw__get_entries(unwind_entry_cb_t cb __maybe_unused, void * int max_stack __maybe_unused, bool best_effort __maybe_unused) { - pr_err("Error: libdw dwarf unwinding not built into perf\n"); + pr_warning_once("Error: libdw dwarf unwinding not built into perf\n");return 0 ; }#endif @@ -81,7 +81,7 @@ static inline int libunwind__get_entries(unwind_entry_cb_t cb __maybe_unused, int max_stack __maybe_unused, bool best_effort __maybe_unused) { - pr_err("Error: libunwind dwarf unwinding not built into perf\n"); + pr_warning_once("Error: libunwind dwarf unwinding not built into perf\n");return 0 ; }
Re: [PATCH v5 1/7] perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection
In reply to Ian RogersThis series was applied to riscv/linux.git (fixes) by Arnaldo Carvalho de Melo <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Arnaldo Carvalho de Melo <[email protected]>:
Quoted 11 lines · On Wed, 13 May 2026 16:31:45 -0700 you wrote:
Currently, both libdw and libunwind define '
unwind__get_entries'. This causes a duplicate symbol build failure when both are compiled into perf.This commit refactors the DWARF unwind post-processing to be configurable at runtime via the .perfconfig file option 'unwind.style', or using the argument '--unwind-style' in the commands 'perf report', 'perf script' and 'perf inject', in a similar manner to the addr2line or the disassembler style.
[...]
Here is the summary with links:
- [v5,1/7] perf unwind: Refactor get_entries to allow dynamic libdw/libunwind selection (no matching commit)
- [v5,2/7] tools build: Deduplicate test-libunwind for different architectures
https://git.kernel.org/riscv/c/6d13d53be9dd - [v5,3/7] perf build: Be more programmatic when setting up libunwind variables https://git.kernel.org/riscv/c/444508cd7c7b - [v5,4/7] perf unwind-libunwind: Make libunwind register reading cross platform (no matching commit) - [v5,5/7] perf unwind-libunwind: Move flush/finish access out of local https://git.kernel.org/riscv/c/2723e9f8b5cf - [v5,6/7] perf unwind-libunwind: Remove libunwind-local (no matching commit) - [v5,7/7] perf unwind-libunwind: Add RISC-V libunwind support https://git.kernel.org/riscv/c/834c557167a9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Ian Rogers
reviewerPATCH v5 2/7 tools build: Deduplicate test-libunwind for different architectures
In reply to Ian RogersThe separate test files only exist to pass a different #include, instead have a single source file and pass -include to $(CC) to include the relevant header file for the architecture being tested. Generate the rules using a foreach loop. Include tests for all current libunwind architectures.
--- tools/build/Makefile.feature | 12 ++++- tools/build/feature/Makefile | 46 +++++++++---------- tools/build/feature/test-libunwind-aarch64.c | 27 ----------- tools/build/feature/test-libunwind-arm.c | 28 ----------- .../test-libunwind-debug-frame-aarch64.c | 17 ------- .../feature/test-libunwind-debug-frame-arm.c | 17 ------- .../feature/test-libunwind-debug-frame.c | 1 - tools/build/feature/test-libunwind-x86.c | 28 ----------- tools/build/feature/test-libunwind-x86_64.c | 28 ----------- tools/build/feature/test-libunwind.c | 1 - 10 files changed, 32 insertions(+), 173 deletions(-) delete mode 100644 tools/build/feature/test-libunwind-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-arm.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-arm.c delete mode 100644 tools/build/feature/test-libunwind-x86.c delete mode 100644 tools/build/feature/test-libunwind-x86_64.c
tools/build/Makefile.feature +11 -1
@@ -104,6 +104,9 @@ FEATURE_TESTS_BASIC := \ # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests + +LIBUNWIND_ARCHS:=aarch64 arm loongarch64 mips ppc32 ppc64 riscv s390x x86 x86_64 + FEATURE_TESTS_EXTRA := \ bionic \ compile-32 \
@@ -127,7 +130,10 @@ FEATURE_TESTS_EXTRA := \ libpfm4 \ libdebuginfod \ clang-bpf-co-re \ - bpftool-skeletons + bpftool-skeletons \ + libunwind \ + libunwind-debug-frame \ + $(foreach arch,$(LIBUNWIND_ARCHS),libunwind-$(arch) libunwind-debug-frame-$(arch)) FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
@@ -212,6 +218,10 @@ ifeq ($(feature-all), 1) $(call feature_check,compile-x32) $(call feature_check,bionic) $(call feature_check,libbabeltrace) + $(call feature_check,libunwind) + $(call feature_check,libunwind-debug-frame) + $(foreach arch,$(LIBUNWIND_ARCHS),$(call feature_check,libunwind-$(arch))) + $(foreach arch,$(LIBUNWIND_ARCHS),$(call feature_check,libunwind-debug-frame-$(arch))) else $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat))) endif
tools/build/feature/Makefile +21 -25
66 lines not on this page · raw message
tools/build/feature/test-libunwind-aarch64.c deleted +0 -27
@@ -1,27 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <libunwind-aarch64.h> -#include <stdlib.h> - -extern int UNW_OBJ (dwarf_search_unwind_table ) (unw_addr_space_t as, -unw_word_t ip, -unw_dyn_info_t *di, -unw_proc_info_t *pi, -int need_unwind_info,void *arg); - -#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table) - -static unw_accessors_t accessors; - -int main (void ) -{ -unw_addr_space_t addr_space; - - addr_space =unw_create_addr_space (&accessors,0 ); -if (addr_space) -return 0 ; - -unw_init_remote (NULL , addr_space,NULL ); -dwarf_search_unwind_table (addr_space,0 ,NULL ,NULL ,0 ,NULL ); - -return 0 ; -}
tools/build/feature/test-libunwind-arm.c deleted +0 -28
@@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <libunwind-arm.h> -#include <stdlib.h> - -extern int UNW_OBJ (dwarf_search_unwind_table ) (unw_addr_space_t as, -unw_word_t ip, -unw_dyn_info_t *di, -unw_proc_info_t *pi, -int need_unwind_info,void *arg); - - -#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table) - -static unw_accessors_t accessors; - -int main (void ) -{ -unw_addr_space_t addr_space; - - addr_space =unw_create_addr_space (&accessors,0 ); -if (addr_space) -return 0 ; - -unw_init_remote (NULL , addr_space,NULL ); -dwarf_search_unwind_table (addr_space,0 ,NULL ,NULL ,0 ,NULL ); - -return 0 ; -}
tools/build/feature/test-libunwind-debug-frame-aarch64.c deleted +0 -17
@@ -1,17 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <libunwind-aarch64.h> -#include <stdlib.h> - -extern int -UNW_OBJ (dwarf_find_debug_frame ) (int found,unw_dyn_info_t *di_debug, -unw_word_t ip,unw_word_t segbase, -const char *obj_name,unw_word_t start, -unw_word_t end); - -#define dwarf_find_debug_frame UNW_OBJ(dwarf_find_debug_frame) - -int main (void ) -{ -dwarf_find_debug_frame (0 ,NULL ,0 ,0 ,NULL ,0 ,0 ); -return 0 ; -}
tools/build/feature/test-libunwind-debug-frame-arm.c deleted +0 -17
@@ -1,17 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <libunwind-arm.h> -#include <stdlib.h> - -extern int -UNW_OBJ (dwarf_find_debug_frame ) (int found,unw_dyn_info_t *di_debug, -unw_word_t ip,unw_word_t segbase, -const char *obj_name,unw_word_t start, -unw_word_t end); - -#define dwarf_find_debug_frame UNW_OBJ(dwarf_find_debug_frame) - -int main (void ) -{ -dwarf_find_debug_frame (0 ,NULL ,0 ,0 ,NULL ,0 ,0 ); -return 0 ; -}
tools/build/feature/test-libunwind-debug-frame.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include <libunwind.h> #include <stdlib.h> extern int
tools/build/feature/test-libunwind-x86.c deleted +0 -28
@@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <libunwind-x86.h> -#include <stdlib.h> - -extern int UNW_OBJ (dwarf_search_unwind_table ) (unw_addr_space_t as, -unw_word_t ip, -unw_dyn_info_t *di, -unw_proc_info_t *pi, -int need_unwind_info,void *arg); - - -#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table) - -static unw_accessors_t accessors; - -int main (void ) -{ -unw_addr_space_t addr_space; - - addr_space =unw_create_addr_space (&accessors,0 ); -if (addr_space) -return 0 ; - -unw_init_remote (NULL , addr_space,NULL ); -dwarf_search_unwind_table (addr_space,0 ,NULL ,NULL ,0 ,NULL ); - -return 0 ; -}
tools/build/feature/test-libunwind-x86_64.c deleted +0 -28
@@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <libunwind-x86_64.h> -#include <stdlib.h> - -extern int UNW_OBJ (dwarf_search_unwind_table ) (unw_addr_space_t as, -unw_word_t ip, -unw_dyn_info_t *di, -unw_proc_info_t *pi, -int need_unwind_info,void *arg); - - -#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table) - -static unw_accessors_t accessors; - -int main (void ) -{ -unw_addr_space_t addr_space; - - addr_space =unw_create_addr_space (&accessors,0 ); -if (addr_space) -return 0 ; - -unw_init_remote (NULL , addr_space,NULL ); -dwarf_search_unwind_table (addr_space,0 ,NULL ,NULL ,0 ,NULL ); - -return 0 ; -}
tools/build/feature/test-libunwind.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#include <libunwind.h> #include <stdlib.h> extern int UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 3/7 perf build: Be more programmatic when setting up libunwind variables
In reply to Ian RogersIterate 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.
--- tools/perf/Makefile.config | 226 ++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 126 deletions(-)
tools/perf/Makefile.config +100 -126
@@ -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
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 4/7 perf unwind-libunwind: Make libunwind register reading cross platform
In reply to Ian RogersMove the libunwind register to perf register mapping functions in arch/../util/unwind-libunwind.c into a new libunwind-arch directory. Rename the functions to __get_perf_regnum_for_unw_regnum_<arch>. Add untested ppc32 and s390 functions. Add a get_perf_regnum_for_unw_regnum function that takes an ELF machine as well as a register number and chooses the appropriate architecture implementation.
Split the x86 and powerpc 32 and 64-bit implementations apart so that a single libunwind-<arch>.h header is included.
Move the e_machine into the unwind_info struct to make it easier to pass.
--- tools/perf/arch/arm/util/Build | 2 - tools/perf/arch/arm/util/unwind-libunwind.c | 50 -------- tools/perf/arch/arm64/util/Build | 1 - tools/perf/arch/arm64/util/unwind-libunwind.c | 17 --- tools/perf/arch/loongarch/util/Build | 2 - .../arch/loongarch/util/unwind-libunwind.c | 82 ------------- tools/perf/arch/mips/Build | 1 - tools/perf/arch/mips/util/Build | 1 - tools/perf/arch/mips/util/unwind-libunwind.c | 22 ---- tools/perf/arch/powerpc/util/Build | 1 - .../perf/arch/powerpc/util/unwind-libunwind.c | 92 -------------- tools/perf/arch/x86/util/Build | 3 - tools/perf/arch/x86/util/unwind-libunwind.c | 115 ------------------ tools/perf/util/Build | 1 + tools/perf/util/libunwind-arch/Build | 10 ++ .../perf/util/libunwind-arch/libunwind-arch.c | 32 +++++ .../perf/util/libunwind-arch/libunwind-arch.h | 16 +++ .../perf/util/libunwind-arch/libunwind-arm.c | 15 +++ .../util/libunwind-arch/libunwind-arm64.c | 14 +++ .../perf/util/libunwind-arch/libunwind-i386.c | 43 +++++++ .../util/libunwind-arch/libunwind-loongarch.c | 27 ++++ .../perf/util/libunwind-arch/libunwind-mips.c | 29 +++++ .../util/libunwind-arch/libunwind-ppc32.c | 31 +++++ .../util/libunwind-arch/libunwind-ppc64.c | 33 +++++ .../perf/util/libunwind-arch/libunwind-s390.c | 29 +++++ .../util/libunwind-arch/libunwind-x86_64.c | 52 ++++++++ tools/perf/util/libunwind/arm64.c | 5 - tools/perf/util/libunwind/x86_32.c | 12 -- tools/perf/util/unwind-libunwind-local.c | 12 +- tools/perf/util/unwind.h | 5 - 30 files changed, 338 insertions(+), 417 deletions(-) delete mode 100644 tools/perf/arch/arm/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/arm64/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/loongarch/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/mips/Build delete mode 100644 tools/perf/arch/mips/util/Build delete mode 100644 tools/perf/arch/mips/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/powerpc/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/x86/util/unwind-libunwind.c create mode 100644 tools/perf/util/libunwind-arch/Build create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.h create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-i386.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-loongarch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-mips.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc32.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-s390.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-x86_64.c
tools/perf/arch/arm/util/Build +0 -2
@@ -1,3 +1 @@ -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o - perf-util-y += pmu.o auxtrace.o cs-etm.o
tools/perf/arch/arm/util/unwind-libunwind.c deleted +0 -50
50 lines not on this page · raw message
tools/perf/arch/arm64/util/Build +0 -1
@@ -1,4 +1,3 @@ -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o perf-util-y += ../../arm/util/auxtrace.o perf-util-y += ../../arm/util/cs-etm.o perf-util-y += ../../arm/util/pmu.o
tools/perf/arch/arm64/util/unwind-libunwind.c deleted +0 -17
@@ -1,17 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <errno.h> - -#ifndef REMOTE_UNWIND_LIBUNWIND -#include <libunwind.h> -#include "perf_regs.h" -#include "../../../util/unwind.h" -#endif -#include "../../../util/debug.h" - -int LIBUNWIND__ARCH_REG_ID (int regnum) -{ -if (regnum <0 || regnum >=PERF_REG_ARM64_EXTENDED_MAX ) -return -EINVAL ; - -return regnum; -}
tools/perf/arch/loongarch/util/Build +0 -2
@@ -1,3 +1 @@ perf-util-y += header.o - -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
tools/perf/arch/loongarch/util/unwind-libunwind.c deleted +0 -82
82 lines not on this page · raw message
tools/perf/arch/mips/Build deleted +0 -1
@@ -1 +0,0 @@ -perf-util-y += util/
tools/perf/arch/mips/util/Build deleted +0 -1
@@ -1 +0,0 @@ -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
tools/perf/arch/mips/util/unwind-libunwind.c deleted +0 -22
@@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include <errno.h> -#include <libunwind.h> -#include "perf_regs.h" -#include "../../util/unwind.h" -#include "util/debug.h" - -int libunwind__arch_reg_id (int regnum) -{ -switch (regnum) { - case UNW_MIPS_R1 ... UNW_MIPS_R25: -return regnum -UNW_MIPS_R1 +PERF_REG_MIPS_R1 ; - case UNW_MIPS_R28 ... UNW_MIPS_R31: -return regnum -UNW_MIPS_R28 +PERF_REG_MIPS_R28 ; -case UNW_MIPS_PC : -return PERF_REG_MIPS_PC ; -default : -pr_err ("unwind: invalid reg id %d\n" , regnum); -return -EINVAL ; - } -}
tools/perf/arch/powerpc/util/Build +0 -1
@@ -6,5 +6,4 @@ perf-util-y += evsel.o perf-util-$(CONFIG_LIBDW) += skip-callchain-idx.o -perf-util-$(CONFIG_LIBUNWIND) += unwind-libunwind.o perf-util-y += auxtrace.o
tools/perf/arch/powerpc/util/unwind-libunwind.c deleted +0 -92
92 lines not on this page · raw message
tools/perf/arch/x86/util/Build +0 -3
@@ -8,9 +8,6 @@ perf-util-y += evlist.o perf-util-y += mem-events.o perf-util-y += evsel.o perf-util-y += iostat.o - -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o - perf-util-y += auxtrace.o perf-util-y += intel-pt.o perf-util-y += intel-bts.o
tools/perf/arch/x86/util/unwind-libunwind.c deleted +0 -115
115 lines not on this page · raw message
tools/perf/util/Build +1 -0
@@ -228,6 +228,7 @@ perf-util-$(CONFIG_LIBDW) += unwind-libdw.o perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind-local.o perf-util-$(CONFIG_LIBUNWIND) += unwind-libunwind.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-arch/ perf-util-$(CONFIG_LIBUNWIND_X86) += libunwind/x86_32.o perf-util-$(CONFIG_LIBUNWIND_AARCH64) += libunwind/arm64.o
tools/perf/util/libunwind-arch/Build new file +10 -0
@@ -0,0 +1,10 @@ +perf-util-$(CONFIG_LIBUNWIND) += libunwind-arch.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-arm64.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-arm.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-loongarch.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-mips.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-ppc32.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-ppc64.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-s390.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-i386.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-x86_64.o
tools/perf/util/libunwind-arch/libunwind-arch.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "libunwind-arch.h" +#include "../debug.h" +#include <elf.h> +#include <errno.h> + +int get_perf_regnum_for_unw_regnum (unsigned int e_machine,int unw_regnum) +{ +switch (e_machine) { +case EM_ARM : +return __get_perf_regnum_for_unw_regnum_arm (unw_regnum); +case EM_AARCH64 : +return __get_perf_regnum_for_unw_regnum_arm64 (unw_regnum); +case EM_LOONGARCH : +return __get_perf_regnum_for_unw_regnum_loongarch (unw_regnum); +case EM_MIPS : +return __get_perf_regnum_for_unw_regnum_mips (unw_regnum); +case EM_PPC : +return __get_perf_regnum_for_unw_regnum_ppc32 (unw_regnum); +case EM_PPC64 : +return __get_perf_regnum_for_unw_regnum_ppc64 (unw_regnum); +case EM_S390 : +return __get_perf_regnum_for_unw_regnum_s390 (unw_regnum); +case EM_386 : +return __get_perf_regnum_for_unw_regnum_i386 (unw_regnum); +case EM_X86_64 : +return __get_perf_regnum_for_unw_regnum_x86_64 (unw_regnum); +default : +pr_err ("ELF MACHINE %x is not supported.\n" , e_machine); +return -EINVAL ; + } +}
tools/perf/util/libunwind-arch/libunwind-arch.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LIBUNWIND_ARCH_H +#define __LIBUNWIND_ARCH_H + +int __get_perf_regnum_for_unw_regnum_arm (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_arm64 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_loongarch (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_mips (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_ppc32 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_ppc64 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_s390 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_i386 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_x86_64 (int unw_regnum); +int get_perf_regnum_for_unw_regnum (unsigned int e_machine,int unw_regnum); + +#endif /* __LIBUNWIND_ARCH_H */
tools/perf/util/libunwind-arch/libunwind-arm.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/arm/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +int __get_perf_regnum_for_unw_regnum_arm (int unw_regnum) +{ +if (unw_regnum <0 || unw_regnum >=PERF_REG_ARM_MAX ) { +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +return unw_regnum; +}
tools/perf/util/libunwind-arch/libunwind-arm64.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/arm64/include/uapi/asm/perf_regs.h" +#include <errno.h> + +int __get_perf_regnum_for_unw_regnum_arm64 (int unw_regnum) +{ +if (unw_regnum <0 || unw_regnum >=PERF_REG_ARM64_EXTENDED_MAX ) { +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +return unw_regnum; +}
tools/perf/util/libunwind-arch/libunwind-i386.c new file +43 -0
43 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-loongarch.c new file +27 -0
@@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/loongarch/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_LOONGARCH64_SUPPORT +#include <libunwind-loongarch64.h> +#endif + +int __get_perf_regnum_for_unw_regnum_loongarch (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_LOONGARCH64_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_LOONGARCH64_R1 ... UNW_LOONGARCH64_R31: +return unw_regnum -UNW_LOONGARCH64_R1 +PERF_REG_LOONGARCH_R1 ; +case UNW_LOONGARCH64_PC : +return PERF_REG_LOONGARCH_PC ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +#endif // HAVE_LIBUNWIND_LOONGARCH64_SUPPORT +}
tools/perf/util/libunwind-arch/libunwind-mips.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/mips/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_MIPS_SUPPORT +#include <libunwind-mips.h> +#endif + +int __get_perf_regnum_for_unw_regnum_mips (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_MIPS_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_MIPS_R1 ... UNW_MIPS_R25: +return unw_regnum -UNW_MIPS_R1 +PERF_REG_MIPS_R1 ; + case UNW_MIPS_R28 ... UNW_MIPS_R31: +return unw_regnum -UNW_MIPS_R28 +PERF_REG_MIPS_R28 ; +case UNW_MIPS_PC : +return PERF_REG_MIPS_PC ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +#endif // HAVE_LIBUNWIND_MIPS_SUPPORT +}
tools/perf/util/libunwind-arch/libunwind-ppc32.c new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/powerpc/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_PPC32_SUPPORT +#include <libunwind-ppc32.h> +#endif + +int __get_perf_regnum_for_unw_regnum_ppc32 (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_PPC32_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_PPC32_R0 ... UNW_PPC32_R31: +return unw_regnum -UNW_PPC32_R0 +PERF_REG_POWERPC_R0 ; +case UNW_PPC32_LR : +return PERF_REG_POWERPC_LINK ; +case UNW_PPC32_CTR : +return PERF_REG_POWERPC_CTR ; +case UNW_PPC32_XER : +return PERF_REG_POWERPC_XER ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +#endif // HAVE_LIBUNWIND_PPC32_SUPPORT +}
tools/perf/util/libunwind-arch/libunwind-ppc64.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/powerpc/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_PPC64_SUPPORT +#include <libunwind-ppc64.h> +#endif + +int __get_perf_regnum_for_unw_regnum_ppc64 (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_PPC64_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_PPC64_R0 ... UNW_PPC64_R31: +return unw_regnum -UNW_PPC64_R0 +PERF_REG_POWERPC_R0 ; +case UNW_PPC64_LR : +return PERF_REG_POWERPC_LINK ; +case UNW_PPC64_CTR : +return PERF_REG_POWERPC_CTR ; +case UNW_PPC64_XER : +return PERF_REG_POWERPC_XER ; +case UNW_PPC64_NIP : +return PERF_REG_POWERPC_NIP ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +#endif // HAVE_LIBUNWIND_PPC64_SUPPORT +}
tools/perf/util/libunwind-arch/libunwind-s390.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/s390/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_S390X_SUPPORT +#include <libunwind-s390x.h> +#endif + +int __get_perf_regnum_for_unw_regnum_s390 (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_S390X_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_S390X_R0 ... UNW_S390X_R15: +return unw_regnum -UNW_S390X_R0 +PERF_REG_S390_R0 ; + case UNW_S390X_F0 ... UNW_S390X_F15: +return unw_regnum -UNW_S390X_F0 +PERF_REG_S390_FP0 ; +case UNW_S390X_IP : +return PERF_REG_S390_PC ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); +return -EINVAL ; + } +#endif // HAVE_LIBUNWIND_S390X_SUPPORT +}
tools/perf/util/libunwind-arch/libunwind-x86_64.c new file +52 -0
52 lines not on this page · raw message
tools/perf/util/libunwind/arm64.c +0 -5
@@ -14,11 +14,6 @@#define REMOTE_UNWIND_LIBUNWIND -/* Define arch specific functions & regs for libunwind, should be -* defined before including "unwind.h" -*/ -#define LIBUNWIND__ARCH_REG_ID (regnum) libunwind__arm64_reg_id(regnum) -#include "unwind.h" #include "libunwind-aarch64.h" #define perf_event_arm_regs perf_event_arm64_regs
tools/perf/util/libunwind/x86_32.c +0 -12
@@ -14,20 +14,8 @@#define REMOTE_UNWIND_LIBUNWIND -/* Define arch specific functions & regs for libunwind, should be -* defined before including "unwind.h" -*/ -#define LIBUNWIND__ARCH_REG_ID (regnum) libunwind__x86_reg_id(regnum) -#include "unwind.h" #include "libunwind-x86.h" -#include <../../../../arch/x86/include/uapi/asm/perf_regs.h> - -/* HAVE_ARCH_X86_64_SUPPORT is used in'arch/x86/util/unwind-libunwind.c' -* for x86_32, we undef it to compile code for x86_32 only. -*/ -#undef HAVE_ARCH_X86_64_SUPPORT -#include "../../arch/x86/util/unwind-libunwind.c" /* Explicitly define NO_LIBUNWIND_DEBUG_FRAME, because non-ARM has no * dwarf_find_debug_frame() function.
tools/perf/util/unwind-libunwind-local.c +6 -6
@@ -39,6 +39,7 @@#include "debug.h" #include "asm/bug.h" #include "dso.h" +#include "libunwind-arch/libunwind-arch.h" extern int UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
@@ -95,6 +96,7 @@ struct unwind_info {struct perf_sample *sample;struct machine *machine;struct thread *thread; +uint16_t e_machine;bool best_effort; };
@@ -583,9 +585,7 @@ static int access_mem(unw_addr_space_t __maybe_unused as, } ret =perf_reg_value (&start,perf_sample__user_regs (ui->sample), -perf_arch_reg_sp (thread__e_machine (ui->thread, - ui->machine, -/*e_flags=*/ NULL ))); +perf_arch_reg_sp (ui->e_machine));if (ret)return ret;
@@ -633,7 +633,7 @@ static int access_reg(unw_addr_space_t __maybe_unused as,return 0 ; } - id =LIBUNWIND__ARCH_REG_ID (regnum); + id =get_perf_regnum_for_unw_regnum (ui->e_machine, regnum);if (id <0 )return -EINVAL ;
@@ -734,7 +734,6 @@ static void _unwind__finish_access(struct maps *maps)static int get_entries (struct unwind_info *ui,unwind_entry_cb_t cb,void *arg,int max_stack) { -uint16_t e_machine =thread__e_machine (ui->thread, ui->machine,/*e_flags=*/ NULL );u64 val;unw_word_t ips[max_stack];unw_addr_space_t addr_space;
@@ -742,7 +741,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,int ret, i =0 ; ret =perf_reg_value (&val,perf_sample__user_regs (ui->sample), -perf_arch_reg_ip (e_machine)); +perf_arch_reg_ip (ui->e_machine));if (ret)return 0 ;
@@ -820,6 +819,7 @@ static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg, .sample = data, .thread = thread, .machine = maps__machine(thread__maps(thread)), + .e_machine = thread__e_machine(thread, /*machine=*/NULL, /*e_flags=*/NULL), .best_effort = best_effort };
tools/perf/util/unwind.h +0 -5
@@ -64,11 +64,6 @@ int libunwind__get_entries(unwind_entry_cb_t cb, void *arg,struct thread *thread, struct perf_sample *data, int max_stack, bool best_effort); -#ifndef LIBUNWIND__ARCH_REG_ID -#define LIBUNWIND__ARCH_REG_ID (regnum) libunwind__arch_reg_id(regnum) -#endif - -int LIBUNWIND__ARCH_REG_ID (int regnum);int unwind__prepare_access (struct maps *maps,struct map *map,bool *initialized);void unwind__flush_access (struct maps *maps);void unwind__finish_access (struct maps *maps);
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v5 4/7] perf unwind-libunwind: Make libunwind register reading cross platform
Quoted 23 lines · Ian Rogers
tools/perf/util/libunwind-arch/libunwind-ppc32.c new file +20
-0@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/powerpc/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_PPC32_SUPPORT +#include <libunwind-ppc32.h> +#endif + +int __get_perf_regnum_for_unw_regnum_ppc32 (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_PPC32_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_PPC32_R0 ... UNW_PPC32_R31: +return unw_regnum -UNW_PPC32_R0 +PERF_REG_POWERPC_R0 ; +case UNW_PPC32_LR :
tools/perf/util/libunwind-arch/libunwind-ppc32.c line 30
Quoted 10 lines
tools/perf/util/libunwind-arch/libunwind-ppc32.c new file +10
-0+return PERF_REG_POWERPC_LINK ; +case UNW_PPC32_CTR : +return PERF_REG_POWERPC_CTR ; +case UNW_PPC32_XER : +return PERF_REG_POWERPC_XER ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); + return -EINVAL; + } +#endif // HAVE_LIBUNWIND_PPC32_SUPPORT
To address this local sashiko comment:
------------------------------------------------------------
Is the instruction pointer (NIP) intentionally omitted from this switch statement?
When libunwind attempts to read the instruction pointer, will access_reg() hit the default case here and return -EINVAL, causing stack unwinding to fail on 32-bit PowerPC architectures?
For comparison, the 64-bit implementation in libunwind-ppc64.c correctly maps UNW_PPC64_NIP to PERF_REG_POWERPC_NIP.
------------------------------------------------------------
I ammended this patch with:
⬢ [acme@toolbx perf-tools-next]$ vim tools/perf/util/libunwind-arch/libunwind-ppc32.c ⬢ [acme@toolbx perf-tools-next]$ git diff
tools/perf/util/libunwind-arch/libunwind-ppc32.c +2 -0
@@ -23,6 +23,8 @@ int __get_perf_regnum_for_unw_regnum_ppc32(int unw_regnum __maybe_unused)return PERF_REG_POWERPC_CTR ;case UNW_PPC32_XER :return PERF_REG_POWERPC_XER ; +case UNW_PPC32_NIP : +return PERF_REG_POWERPC_NIP ;default :pr_err ("unwind: invalid reg id %d\n" , unw_regnum);return -EINVAL ;
⬢ [acme@toolbx perf-tools-next]$
Ok? It was the only issue found in this patch.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v5 4/7] perf unwind-libunwind: Make libunwind register reading cross platform
Quoted 68 lines · Arnaldo Carvalho de Melo
Quoted 23 lines · Ian Rogers
tools/perf/util/libunwind-arch/libunwind-ppc32.c new file +20
-0@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include "libunwind-arch.h" +#include "../debug.h" +#include "../../../arch/powerpc/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> +#include <errno.h> + +#ifdef HAVE_LIBUNWIND_PPC32_SUPPORT +#include <libunwind-ppc32.h> +#endif + +int __get_perf_regnum_for_unw_regnum_ppc32 (int unw_regnum__maybe_unused ) +{ +#ifndef HAVE_LIBUNWIND_PPC32_SUPPORT +return -EINVAL ; +#else +switch (unw_regnum) { + case UNW_PPC32_R0 ... UNW_PPC32_R31: +return unw_regnum -UNW_PPC32_R0 +PERF_REG_POWERPC_R0 ; +case UNW_PPC32_LR :tools/perf/util/libunwind-arch/libunwind-ppc32.c line 30
Quoted 10 lines
tools/perf/util/libunwind-arch/libunwind-ppc32.c new file +10
-0+return PERF_REG_POWERPC_LINK ; +case UNW_PPC32_CTR : +return PERF_REG_POWERPC_CTR ; +case UNW_PPC32_XER : +return PERF_REG_POWERPC_XER ; +default : +pr_err ("unwind: invalid reg id %d\n" , unw_regnum); + return -EINVAL; + } +#endif // HAVE_LIBUNWIND_PPC32_SUPPORT To address this local sashiko comment:
------------------------------------------------------------
Is the instruction pointer (NIP) intentionally omitted from this switch statement?When libunwind attempts to read the instruction pointer, will
access_reg()hit the default case here and return-EINVAL, causing stack unwinding to fail on 32-bit PowerPC architectures?
For comparison, the 64-bit implementation inlibunwind-ppc64.ccorrectly mapsUNW_PPC64_NIPtoPERF_REG_POWERPC_NIP.
------------------------------------------------------------I ammended this patch with:
⬢ [acme@toolbx perf-tools-next]$ vim
tools/perf/util/libunwind-arch/libunwind-ppc32.c⬢ [acme@toolbx perf-tools-next]$ git difftools/perf/util/libunwind-arch/libunwind-ppc32.c +2
-0@@ -23,6 +23,8 @@ int __get_perf_regnum_for_unw_regnum_ppc32(int unw_regnum __maybe_unused)return PERF_REG_POWERPC_CTR ;case UNW_PPC32_XER :return PERF_REG_POWERPC_XER ; +case UNW_PPC32_NIP : +return PERF_REG_POWERPC_NIP ;default :pr_err ("unwind: invalid reg id %d\n" , unw_regnum);return -EINVAL ;⬢ [acme@toolbx perf-tools-next]$
Quoted 1 line
Ok? It was the only issue found in this patch.
Looks good, the NIP is in the original code that I copied, so I don't understand how I lost this, but good catch!
Thanks,
Ian
Quoted 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v5 4/7] perf unwind-libunwind: Make libunwind register reading cross platform
Quoted 14 lines · Ian Rogers
Quoted 11 lines · Arnaldo Carvalho de Melo
+++
b/tools/perf/util/libunwind-arch/libunwind-ppc32.ctools/perf/util/libunwind-arch/libunwind-ppc32.c +2
-0@@ -23,6 +23,8 @@ int __get_perf_regnum_for_unw_regnum_ppc32(int unw_regnum __maybe_unused)return PERF_REG_POWERPC_CTR ;case UNW_PPC32_XER :return PERF_REG_POWERPC_XER ; +case UNW_PPC32_NIP : +return PERF_REG_POWERPC_NIP ;default :pr_err ("unwind: invalid reg id %d\n" , unw_regnum);return -EINVAL ;⬢ [acme@toolbx perf-tools-next]$
Quoted 4 lines
Quoted 1 line
Ok? It was the only issue found in this patch.
Looks good, the NIP is in the original code that I copied, so I don't understand how I lost this, but good catch!
What I have is in tmp.perf-tools-next, doing a container build now, still need to look at the other findings, but they seems either trivial or complaints about making the build time more inneficient by not caching some feature tests, so I think I'll fix the trivial like I did in the above case (posting diffs to the list) and leave the build time for later so that we make progress.
Will try to do this later today so that I publish it to perf-tools-next for it to soak a bit in linux-next.
- Arnaldo
Ian Rogers
reviewerRe: [PATCH v5 4/7] perf unwind-libunwind: Make libunwind register reading cross platform
Quoted 28 lines · Arnaldo Carvalho de Melo
Quoted 14 lines · Ian Rogers
Quoted 11 lines · Arnaldo Carvalho de Melo
+++
b/tools/perf/util/libunwind-arch/libunwind-ppc32.ctools/perf/util/libunwind-arch/libunwind-ppc32.c +2
-0@@ -23,6 +23,8 @@ int __get_perf_regnum_for_unw_regnum_ppc32(int unw_regnum __maybe_unused)return PERF_REG_POWERPC_CTR ;case UNW_PPC32_XER :return PERF_REG_POWERPC_XER ; +case UNW_PPC32_NIP : +return PERF_REG_POWERPC_NIP ;default :pr_err ("unwind: invalid reg id %d\n" , unw_regnum);return -EINVAL ;⬢ [acme@toolbx perf-tools-next]$
Quoted 4 lines
Quoted 1 line
Ok? It was the only issue found in this patch.
Looks good, the NIP is in the original code that I copied, so I don't understand how I lost this, but good catch!
What I have is in tmp.perf-tools-next, doing a container build now, still need to look at the other findings, but they seems either trivial or complaints about making the build time more inneficient by not caching some feature tests, so I think I'll fix the trivial like I did in the above case (posting diffs to the list) and leave the build time for later so that we make progress.
Quoted 2 lines
Will try to do this later today so that I publish it to perf-tools-next for it to soak a bit in linux-next.
This is great! Thank you Arnaldo!
Ian
Quoted 1 line
- Arnaldo
Ian Rogers
reviewerPATCH v5 5/7 perf unwind-libunwind: Move flush/finish access out of local
In reply to Ian RogersFlush and finish access are relatively simple calls into libunwind, move them out struct unwind_libunwind_ops. So that the correct version can be called, add an e_machine variable to maps. This size regression will go away when the unwind_libunwind_ops no longer need stashing in the maps. To set the e_machine up pass it into unwind__prepare_access, which no longer needs to determine the unwind operations based on a map dso because of this. This also means the maps copying code can call unwind__prepare_access once for the e_machine rather than once per map.
--- .../perf/util/libunwind-arch/libunwind-arch.c | 82 +++++++++++++++++++ .../perf/util/libunwind-arch/libunwind-arch.h | 24 ++++++ .../perf/util/libunwind-arch/libunwind-arm.c | 19 +++++ .../util/libunwind-arch/libunwind-arm64.c | 20 +++++ .../perf/util/libunwind-arch/libunwind-i386.c | 15 ++++ .../util/libunwind-arch/libunwind-loongarch.c | 15 ++++ .../perf/util/libunwind-arch/libunwind-mips.c | 15 ++++ .../util/libunwind-arch/libunwind-ppc32.c | 15 ++++ .../util/libunwind-arch/libunwind-ppc64.c | 15 ++++ .../perf/util/libunwind-arch/libunwind-s390.c | 15 ++++ .../util/libunwind-arch/libunwind-x86_64.c | 15 ++++ tools/perf/util/maps.c | 36 +++++--- tools/perf/util/maps.h | 2 + tools/perf/util/thread.c | 32 ++------ tools/perf/util/unwind-libunwind-local.c | 12 --- tools/perf/util/unwind-libunwind.c | 59 ++++++------- tools/perf/util/unwind.h | 8 +- 17 files changed, 309 insertions(+), 90 deletions(-)
tools/perf/util/libunwind-arch/libunwind-arch.c +82 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include <elf.h> #include <errno.h>
@@ -30,3 +31,84 @@ int get_perf_regnum_for_unw_regnum(unsigned int e_machine, int unw_regnum)return -EINVAL ; } } + + +void libunwind_arch__flush_access (struct maps *maps) +{ +unsigned int e_machine =maps__e_machine (maps); + +switch (e_machine) { +case EM_NONE : +break ;// No libunwind info on the maps. +case EM_ARM : +__libunwind_arch__flush_access_arm (maps); +break ; +case EM_AARCH64 : +__libunwind_arch__flush_access_arm64 (maps); +break ; +case EM_LOONGARCH : +__libunwind_arch__flush_access_loongarch (maps); +break ; +case EM_MIPS : +__libunwind_arch__flush_access_mips (maps); +break ; +case EM_PPC : +__libunwind_arch__flush_access_ppc32 (maps); +break ; +case EM_PPC64 : +__libunwind_arch__flush_access_ppc64 (maps); +break ; +case EM_S390 : +__libunwind_arch__flush_access_s390 (maps); +break ; +case EM_386 : +__libunwind_arch__flush_access_i386 (maps); +break ; +case EM_X86_64 : +__libunwind_arch__flush_access_x86_64 (maps); +break ; +default : +pr_err ("ELF MACHINE %x is not supported.\n" , e_machine); +break ; + } +} + +void libunwind_arch__finish_access (struct maps *maps) +{ +unsigned int e_machine =maps__e_machine (maps); + +switch (e_machine) { +case EM_NONE : +break ;// No libunwind info on the maps. +case EM_ARM : +__libunwind_arch__finish_access_arm (maps); +break ; +case EM_AARCH64 : +__libunwind_arch__finish_access_arm64 (maps); +break ; +case EM_LOONGARCH : +__libunwind_arch__finish_access_loongarch (maps); +break ; +case EM_MIPS : +__libunwind_arch__finish_access_mips (maps); +break ; +case EM_PPC : +__libunwind_arch__finish_access_ppc32 (maps); +break ; +case EM_PPC64 : +__libunwind_arch__finish_access_ppc64 (maps); +break ; +case EM_S390 : +__libunwind_arch__finish_access_s390 (maps); +break ; +case EM_386 : +__libunwind_arch__finish_access_i386 (maps); +break ; +case EM_X86_64 : +__libunwind_arch__finish_access_x86_64 (maps); +break ; +default : +pr_err ("ELF MACHINE %x is not supported.\n" , e_machine); +break ; + } +}
tools/perf/util/libunwind-arch/libunwind-arch.h +24 -0
@@ -2,6 +2,8 @@#ifndef __LIBUNWIND_ARCH_H#define __LIBUNWIND_ARCH_H +struct maps ; +int __get_perf_regnum_for_unw_regnum_arm (int unw_regnum);int __get_perf_regnum_for_unw_regnum_arm64 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_loongarch (int unw_regnum);
@@ -13,4 +15,26 @@ int __get_perf_regnum_for_unw_regnum_i386(int unw_regnum);int __get_perf_regnum_for_unw_regnum_x86_64 (int unw_regnum);int get_perf_regnum_for_unw_regnum (unsigned int e_machine,int unw_regnum); +void __libunwind_arch__flush_access_arm (struct maps *maps); +void __libunwind_arch__flush_access_arm64 (struct maps *maps); +void __libunwind_arch__flush_access_loongarch (struct maps *maps); +void __libunwind_arch__flush_access_mips (struct maps *maps); +void __libunwind_arch__flush_access_ppc32 (struct maps *maps); +void __libunwind_arch__flush_access_ppc64 (struct maps *maps); +void __libunwind_arch__flush_access_s390 (struct maps *maps); +void __libunwind_arch__flush_access_i386 (struct maps *maps); +void __libunwind_arch__flush_access_x86_64 (struct maps *maps); +void libunwind_arch__flush_access (struct maps *maps); + +void __libunwind_arch__finish_access_arm (struct maps *maps); +void __libunwind_arch__finish_access_arm64 (struct maps *maps); +void __libunwind_arch__finish_access_loongarch (struct maps *maps); +void __libunwind_arch__finish_access_mips (struct maps *maps); +void __libunwind_arch__finish_access_ppc32 (struct maps *maps); +void __libunwind_arch__finish_access_ppc64 (struct maps *maps); +void __libunwind_arch__finish_access_s390 (struct maps *maps); +void __libunwind_arch__finish_access_i386 (struct maps *maps); +void __libunwind_arch__finish_access_x86_64 (struct maps *maps); +void libunwind_arch__finish_access (struct maps *maps); +#endif /* __LIBUNWIND_ARCH_H */
tools/perf/util/libunwind-arch/libunwind-arm.c +19 -0
@@ -1,10 +1,15 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/arm/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <errno.h> +#ifdef HAVE_LIBUNWIND_ARM_SUPPORT +#include <libunwind-arm.h> +#endif +int __get_perf_regnum_for_unw_regnum_arm (int unw_regnum) {if (unw_regnum <0 || unw_regnum >=PERF_REG_ARM_MAX ) {
@@ -13,3 +18,17 @@ int __get_perf_regnum_for_unw_regnum_arm(int unw_regnum) }return unw_regnum; } + +void __libunwind_arch__flush_access_arm (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_ARM_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_arm (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_ARM_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-arm64.c +20 -0
@@ -1,9 +1,15 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/arm64/include/uapi/asm/perf_regs.h" +#include <linux/compiler.h> #include <errno.h> +#ifdef HAVE_LIBUNWIND_AARCH64_SUPPORT +#include <libunwind-aarch64.h> +#endif +int __get_perf_regnum_for_unw_regnum_arm64 (int unw_regnum) {if (unw_regnum <0 || unw_regnum >=PERF_REG_ARM64_EXTENDED_MAX ) {
@@ -12,3 +18,17 @@ int __get_perf_regnum_for_unw_regnum_arm64(int unw_regnum) }return unw_regnum; } + +void __libunwind_arch__flush_access_arm64 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_AARCH64_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_arm64 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_AARCH64_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-i386.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/x86/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <linux/kernel.h>
@@ -41,3 +42,17 @@ int __get_perf_regnum_for_unw_regnum_i386(int unw_regnum __maybe_unused)return perf_i386_regnums[unw_regnum];#endif // HAVE_LIBUNWIND_X86_SUPPORT } + +void __libunwind_arch__flush_access_i386 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_X86_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_i386 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_X86_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-loongarch.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/loongarch/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <errno.h>
@@ -25,3 +26,17 @@ int __get_perf_regnum_for_unw_regnum_loongarch(int unw_regnum __maybe_unused) }#endif // HAVE_LIBUNWIND_LOONGARCH64_SUPPORT } + +void __libunwind_arch__flush_access_loongarch (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_LOONGARCH64_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_loongarch (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_LOONGARCH64_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-mips.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/mips/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <errno.h>
@@ -27,3 +28,17 @@ int __get_perf_regnum_for_unw_regnum_mips(int unw_regnum __maybe_unused) }#endif // HAVE_LIBUNWIND_MIPS_SUPPORT } + +void __libunwind_arch__flush_access_mips (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_MIPS_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_mips (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_MIPS_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-ppc32.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-or-later #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/powerpc/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <errno.h>
@@ -29,3 +30,17 @@ int __get_perf_regnum_for_unw_regnum_ppc32(int unw_regnum __maybe_unused) }#endif // HAVE_LIBUNWIND_PPC32_SUPPORT } + +void __libunwind_arch__flush_access_ppc32 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_PPC32_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_ppc32 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_PPC32_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-ppc64.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-or-later #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/powerpc/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <errno.h>
@@ -31,3 +32,17 @@ int __get_perf_regnum_for_unw_regnum_ppc64(int unw_regnum __maybe_unused) }#endif // HAVE_LIBUNWIND_PPC64_SUPPORT } + +void __libunwind_arch__flush_access_ppc64 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_PPC64_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_ppc64 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_PPC64_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-s390.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/s390/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <errno.h>
@@ -27,3 +28,17 @@ int __get_perf_regnum_for_unw_regnum_s390(int unw_regnum __maybe_unused) }#endif // HAVE_LIBUNWIND_S390X_SUPPORT } + +void __libunwind_arch__flush_access_s390 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_S390X_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_s390 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_S390X_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/libunwind-arch/libunwind-x86_64.c +15 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "libunwind-arch.h" #include "../debug.h" +#include "../maps.h" #include "../../../arch/x86/include/uapi/asm/perf_regs.h" #include <linux/compiler.h> #include <linux/kernel.h>
@@ -50,3 +51,17 @@ int __get_perf_regnum_for_unw_regnum_x86_64(int unw_regnum __maybe_unused)return perf_x86_64_regnums[unw_regnum];#endif // HAVE_LIBUNWIND_X86_64_SUPPORT } + +void __libunwind_arch__flush_access_x86_64 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_X86_64_SUPPORT +unw_flush_cache (maps__addr_space (maps),0 ,0 ); +#endif +} + +void __libunwind_arch__finish_access_x86_64 (struct maps *maps__maybe_unused ) +{ +#ifdef HAVE_LIBUNWIND_X86_64_SUPPORT +unw_destroy_addr_space (maps__addr_space (maps)); +#endif +}
tools/perf/util/maps.c +25 -11
@@ -40,6 +40,7 @@ DECLARE_RC_STRUCT(maps) {#ifdef HAVE_LIBUNWIND_SUPPORT void *addr_space;const struct unwind_libunwind_ops *unwind_libunwind_ops; +uint16_t e_machine;#endif #ifdef HAVE_LIBDW_SUPPORT void *libdw_addr_space_dwfl;
@@ -206,6 +207,16 @@ void maps__set_unwind_libunwind_ops(struct maps *maps, const struct unwind_libun {RC_CHK_ACCESS (maps)->unwind_libunwind_ops = ops; } + +uint16_t maps__e_machine (const struct maps *maps) +{ +return RC_CHK_ACCESS (maps)->e_machine; +} + +void maps__set_e_machine (struct maps *maps,uint16_t e_machine) +{ +RC_CHK_ACCESS (maps)->e_machine = e_machine; +}#endif #ifdef HAVE_LIBDW_SUPPORT void *maps__libdw_addr_space_dwfl (const struct maps *maps)
@@ -1039,6 +1050,14 @@ int maps__copy_from(struct maps *dest, struct maps *parent)down_write (maps__lock (dest));down_read (maps__lock (parent)); +#ifdef HAVE_LIBUNWIND_SUPPORT + err =unwind__prepare_access (dest,maps__e_machine (parent)); +if (err) { +up_read (maps__lock (parent)); +up_write (maps__lock (dest)); +return err; + } +#endif parent_maps_by_address =maps__maps_by_address (parent); n =maps__nr_maps (parent);if (maps__nr_maps (dest) ==0 ) {
@@ -1068,14 +1087,11 @@ int maps__copy_from(struct maps *dest, struct maps *parent)if (!new) err = -ENOMEM ;else { - err =unwind__prepare_access (dest, new,NULL ); -if (!err) { - dest_maps_by_address[i] = new; -map__set_kmap_maps (new, dest); -if (dest_maps_by_name) - dest_maps_by_name[i] =map__get (new); -RC_CHK_ACCESS (dest)->nr_maps = i +1 ; - } + dest_maps_by_address[i] = new; +map__set_kmap_maps (new, dest); +if (dest_maps_by_name) + dest_maps_by_name[i] =map__get (new); +RC_CHK_ACCESS (dest)->nr_maps = i +1 ; }if (err)map__put (new);
@@ -1093,9 +1109,7 @@ int maps__copy_from(struct maps *dest, struct maps *parent)if (!new) err = -ENOMEM ;else { - err =unwind__prepare_access (dest, new,NULL ); -if (!err) - err =__maps__insert (dest, new); + err =__maps__insert (dest, new); }map__put (new); }
tools/perf/util/maps.h +2 -0
@@ -51,6 +51,8 @@ void *maps__addr_space(const struct maps *maps);void maps__set_addr_space (struct maps *maps,void *addr_space);const struct unwind_libunwind_ops *maps__unwind_libunwind_ops (const struct maps *maps);void maps__set_unwind_libunwind_ops (struct maps *maps,const struct unwind_libunwind_ops *ops); +uint16_t maps__e_machine (const struct maps *maps); +void maps__set_e_machine (struct maps *maps,uint16_t e_machine);#endif #ifdef HAVE_LIBDW_SUPPORT void *maps__libdw_addr_space_dwfl (const struct maps *maps);
tools/perf/util/thread.c +6 -26
@@ -358,41 +358,21 @@ size_t thread__fprintf(struct thread *thread, FILE *fp)int thread__insert_map (struct thread *thread,struct map *map) {int ret; +uint16_t e_machine; - ret =unwind__prepare_access (thread__maps (thread), map,NULL ); + ret =maps__fixup_overlap_and_insert (thread__maps (thread), map);if (ret)return ret; -return maps__fixup_overlap_and_insert (thread__maps (thread), map); -} - -struct thread__prepare_access_maps_cb_args { -int err; -struct maps *maps; -}; - -static int thread__prepare_access_maps_cb (struct map *map,void *data) -{ -bool initialized = false; -struct thread__prepare_access_maps_cb_args *args = data; - - args->err =unwind__prepare_access (args->maps, map, &initialized); - -return (args->err || initialized) ?1 :0 ; + e_machine =thread__e_machine (thread,/*machine=*/ NULL ,/*e_flags=*/ NULL ); +return unwind__prepare_access (thread__maps (thread), e_machine); }static int thread__prepare_access (struct thread *thread) { -struct thread__prepare_access_maps_cb_args args = { - .err =0 , - }; - -if (dwarf_callchain_users) { - args.maps =thread__maps (thread); -maps__for_each_map (thread__maps (thread), thread__prepare_access_maps_cb, &args); - } +uint16_t e_machine =thread__e_machine (thread,/*machine=*/ NULL ,/*e_flags=*/ NULL ); -return args.err; +return unwind__prepare_access (thread__maps (thread), e_machine); }static int thread__clone_maps (struct thread *thread,struct thread *parent,bool do_maps_clone)
tools/perf/util/unwind-libunwind-local.c +0 -12
@@ -721,16 +721,6 @@ static int _unwind__prepare_access(struct maps *maps)return 0 ; } -static void _unwind__flush_access (struct maps *maps) -{ -unw_flush_cache (maps__addr_space (maps),0 ,0 ); -} - -static void _unwind__finish_access (struct maps *maps) -{ -unw_destroy_addr_space (maps__addr_space (maps)); -} -static int get_entries (struct unwind_info *ui,unwind_entry_cb_t cb,void *arg,int max_stack) {
@@ -835,8 +825,6 @@ static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,static struct unwind_libunwind_ops _unwind_libunwind_ops = { .prepare_access = _unwind__prepare_access, - .flush_access = _unwind__flush_access, - .finish_access = _unwind__finish_access, .get_entries = _unwind__get_entries, };
tools/perf/util/unwind-libunwind.c +23 -36
99 lines not on this page · raw message
tools/perf/util/unwind.h +3 -5
@@ -2,6 +2,7 @@#ifndef __UNWIND_H#define __UNWIND_H +#include <stdint.h> #include <linux/compiler.h> #include <linux/types.h> #include "map_symbol.h"
@@ -20,8 +21,6 @@ typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);struct unwind_libunwind_ops {int (*prepare_access)(struct maps *maps); -void (*flush_access)(struct maps *maps); -void (*finish_access)(struct maps *maps);int (*get_entries)(unwind_entry_cb_t cb,void *arg,struct thread *thread,struct perf_sample *data,int max_stack,bool best_effort);
@@ -64,7 +63,7 @@ int libunwind__get_entries(unwind_entry_cb_t cb, void *arg,struct thread *thread, struct perf_sample *data, int max_stack, bool best_effort); -int unwind__prepare_access (struct maps *maps,struct map *map,bool *initialized); +int unwind__prepare_access (struct maps *maps,uint16_t e_machine);void unwind__flush_access (struct maps *maps);void unwind__finish_access (struct maps *maps);#else
@@ -81,8 +80,7 @@ static inline int libunwind__get_entries(unwind_entry_cb_t cb __maybe_unused, }static inline int unwind__prepare_access (struct maps *maps__maybe_unused , -struct map *map__maybe_unused , -bool *initialized__maybe_unused ) +uint16_t e_machine__maybe_unused ) {return 0 ; }
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerPATCH v5 6/7 perf unwind-libunwind: Remove libunwind-local
In reply to Ian RogersLocal unwinding only works on the machine libunwind is built for, rather than cross platform, the APIs for remote and local unwinding are similar but types like unw_word_t depend on the included header. Place the architecture specific code into the appropriate libunwind-<arch>.c file. Put generic code in unwind-libunwind.c and use libunwind-arch to choose the correct implementation based on the thread's e_machine. Structuring the code this way avoids including the unwind-libunwind-local.c for each architecture of remote unwinding. Data is moved into the struct unwind_info to simplify the architecture and generic code, trying to keep as much code as possible generic.
--- tools/perf/util/Build | 3 - .../perf/util/libunwind-arch/libunwind-arch.c | 184 ++++ .../perf/util/libunwind-arch/libunwind-arch.h | 234 +++++ .../perf/util/libunwind-arch/libunwind-arm.c | 256 ++++++ .../util/libunwind-arch/libunwind-arm64.c | 255 ++++++ .../perf/util/libunwind-arch/libunwind-i386.c | 254 ++++++ .../util/libunwind-arch/libunwind-loongarch.c | 255 ++++++ .../perf/util/libunwind-arch/libunwind-mips.c | 255 ++++++ .../util/libunwind-arch/libunwind-ppc32.c | 255 ++++++ .../util/libunwind-arch/libunwind-ppc64.c | 255 ++++++ .../perf/util/libunwind-arch/libunwind-s390.c | 255 ++++++ .../util/libunwind-arch/libunwind-x86_64.c | 253 ++++++ tools/perf/util/libunwind/arm64.c | 35 - tools/perf/util/libunwind/x86_32.c | 29 - tools/perf/util/maps.c | 10 - tools/perf/util/maps.h | 2 - tools/perf/util/unwind-libdw.c | 4 +- tools/perf/util/unwind-libunwind-local.c | 834 ------------------ tools/perf/util/unwind-libunwind.c | 674 +++++++++++++- tools/perf/util/unwind.h | 7 - 20 files changed, 3352 insertions(+), 957 deletions(-) delete mode 100644 tools/perf/util/libunwind/arm64.c delete mode 100644 tools/perf/util/libunwind/x86_32.c delete mode 100644 tools/perf/util/unwind-libunwind-local.c
tools/perf/util/Build +0 -3
@@ -226,11 +226,8 @@ perf-util-$(CONFIG_LIBDW) += annotate-data.o perf-util-$(CONFIG_LIBDW) += libdw.o perf-util-$(CONFIG_LIBDW) += unwind-libdw.o -perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind-local.o perf-util-$(CONFIG_LIBUNWIND) += unwind-libunwind.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-arch/ -perf-util-$(CONFIG_LIBUNWIND_X86) += libunwind/x86_32.o -perf-util-$(CONFIG_LIBUNWIND_AARCH64) += libunwind/arm64.o ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-util-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
tools/perf/util/libunwind-arch/libunwind-arch.c +184 -0
187 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-arch.h +234 -0
245 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-arm.c +256 -0
267 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-arm64.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-i386.c +254 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-loongarch.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-mips.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-ppc32.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-ppc64.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-s390.c +255 -0
266 lines not on this page · raw message
tools/perf/util/libunwind-arch/libunwind-x86_64.c +253 -0
265 lines not on this page · raw message
tools/perf/util/libunwind/arm64.c deleted +0 -35
@@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* This file setups defines to compile arch specific binary from the -* generic one. -* -* The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch -* name and the definition of this function is included directly from -* 'arch/arm64/util/unwind-libunwind.c', to make sure that this function -* is defined no matter what arch the host is. -* -* Finally, the arch specific unwind methods are exported which will -* be assigned to each arm64 thread. -*/ - -#define REMOTE_UNWIND_LIBUNWIND - -#include "unwind.h" -#include "libunwind-aarch64.h" -#define perf_event_arm_regs perf_event_arm64_regs -#include <../../../arch/arm64/include/uapi/asm/perf_regs.h> -#undef perf_event_arm_regs -#include "../../arch/arm64/util/unwind-libunwind.c" - -/* NO_LIBUNWIND_DEBUG_FRAME is a feature flag for local libunwind, -* assign NO_LIBUNWIND_DEBUG_FRAME_AARCH64 to it for compiling arm64 -* unwind methods. -*/ -#undef NO_LIBUNWIND_DEBUG_FRAME -#ifdef NO_LIBUNWIND_DEBUG_FRAME_AARCH64 -#define NO_LIBUNWIND_DEBUG_FRAME -#endif -#include "util/unwind-libunwind-local.c" - -struct unwind_libunwind_ops * -arm64_unwind_libunwind_ops = &_unwind_libunwind_ops;
tools/perf/util/libunwind/x86_32.c deleted +0 -29
@@ -1,29 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* This file setups defines to compile arch specific binary from the -* generic one. -* -* The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch -* name and the definition of this function is included directly from -* 'arch/x86/util/unwind-libunwind.c', to make sure that this function -* is defined no matter what arch the host is. -* -* Finally, the arch specific unwind methods are exported which will -* be assigned to each x86 thread. -*/ - -#define REMOTE_UNWIND_LIBUNWIND - -#include "unwind.h" -#include "libunwind-x86.h" - -/* Explicitly define NO_LIBUNWIND_DEBUG_FRAME, because non-ARM has no -* dwarf_find_debug_frame() function. -*/ -#ifndef NO_LIBUNWIND_DEBUG_FRAME -#define NO_LIBUNWIND_DEBUG_FRAME -#endif -#include "util/unwind-libunwind-local.c" - -struct unwind_libunwind_ops * -x86_32_unwind_libunwind_ops = &_unwind_libunwind_ops;
tools/perf/util/maps.c +0 -10
@@ -198,16 +198,6 @@ void maps__set_addr_space(struct maps *maps, void *addr_space)RC_CHK_ACCESS (maps)->addr_space = addr_space; } -const struct unwind_libunwind_ops *maps__unwind_libunwind_ops (const struct maps *maps) -{ -return RC_CHK_ACCESS (maps)->unwind_libunwind_ops; -} - -void maps__set_unwind_libunwind_ops (struct maps *maps,const struct unwind_libunwind_ops *ops) -{ -RC_CHK_ACCESS (maps)->unwind_libunwind_ops = ops; -} -uint16_t maps__e_machine (const struct maps *maps) {return RC_CHK_ACCESS (maps)->e_machine;
tools/perf/util/maps.h +0 -2
@@ -49,8 +49,6 @@ refcount_t *maps__refcnt(struct maps *maps); /* Test only. */#ifdef HAVE_LIBUNWIND_SUPPORT void *maps__addr_space (const struct maps *maps);void maps__set_addr_space (struct maps *maps,void *addr_space); -const struct unwind_libunwind_ops *maps__unwind_libunwind_ops (const struct maps *maps); -void maps__set_unwind_libunwind_ops (struct maps *maps,const struct unwind_libunwind_ops *ops);uint16_t maps__e_machine (const struct maps *maps);void maps__set_e_machine (struct maps *maps,uint16_t e_machine);#endif
tools/perf/util/unwind-libdw.c +2 -2
@@ -353,7 +353,7 @@ int libdw__get_entries(unwind_entry_cb_t cb, void *arg,static struct unwind_info *ui;Dwfl *dwfl;Dwarf_Word ip; -int err = -EINVAL , i; +int err = -EINVAL , i, entries;if (!data->user_regs || !data->user_regs->regs)return 0 ;
@@ -430,7 +430,7 @@ int libdw__get_entries(unwind_entry_cb_t cb, void *arg,map_symbol__exit (&ui->entries[i].ms); dwfl_ui_ti->ui =NULL ; -int entries = (int )ui->idx; + entries = (int )ui->idx;free (ui);/* * Unwinder return contract:
tools/perf/util/unwind-libunwind-local.c deleted +0 -834
59 lines not on this page · raw message
tools/perf/util/unwind-libunwind.c +639 -35
674 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Part of the diff is not shown here. View the raw message.
Ian Rogers
reviewerPATCH v5 7/7 perf unwind-libunwind: Add RISC-V libunwind support
In reply to Ian RogersAdd a RISC-V implementation for unwinding.
--- tools/perf/util/libunwind-arch/Build | 1 + .../perf/util/libunwind-arch/libunwind-arch.c | 21 ++ .../perf/util/libunwind-arch/libunwind-arch.h | 22 ++ .../util/libunwind-arch/libunwind-riscv.c | 297 ++++++++++++++++++ 4 files changed, 341 insertions(+) create mode 100644 tools/perf/util/libunwind-arch/libunwind-riscv.c
tools/perf/util/libunwind-arch/Build +1 -0
@@ -5,6 +5,7 @@ perf-util-$(CONFIG_LIBUNWIND) += libunwind-loongarch.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-mips.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-ppc32.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-ppc64.o +perf-util-$(CONFIG_LIBUNWIND) += libunwind-riscv.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-s390.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-i386.o perf-util-$(CONFIG_LIBUNWIND) += libunwind-x86_64.o
tools/perf/util/libunwind-arch/libunwind-arch.c +21 -0
@@ -20,6 +20,8 @@ int get_perf_regnum_for_unw_regnum(unsigned int e_machine, int unw_regnum)return __get_perf_regnum_for_unw_regnum_ppc32 (unw_regnum);case EM_PPC64 :return __get_perf_regnum_for_unw_regnum_ppc64 (unw_regnum); +case EM_RISCV : +return __get_perf_regnum_for_unw_regnum_riscv (unw_regnum);case EM_S390 :return __get_perf_regnum_for_unw_regnum_s390 (unw_regnum);case EM_386 :
@@ -58,6 +60,9 @@ void libunwind_arch__flush_access(struct maps *maps)case EM_PPC64 :__libunwind_arch__flush_access_ppc64 (maps);break ; +case EM_RISCV : +__libunwind_arch__flush_access_riscv (maps); +break ;case EM_S390 :__libunwind_arch__flush_access_s390 (maps);break ;
@@ -98,6 +103,9 @@ void libunwind_arch__finish_access(struct maps *maps)case EM_PPC64 :__libunwind_arch__finish_access_ppc64 (maps);break ; +case EM_RISCV : +__libunwind_arch__finish_access_riscv (maps); +break ;case EM_S390 :__libunwind_arch__finish_access_s390 (maps);break ;
@@ -128,6 +136,8 @@ void *libunwind_arch__create_addr_space(unsigned int e_machine)return __libunwind_arch__create_addr_space_ppc32 ();case EM_PPC64 :return __libunwind_arch__create_addr_space_ppc64 (); +case EM_RISCV : +return __libunwind_arch__create_addr_space_riscv ();case EM_S390 :return __libunwind_arch__create_addr_space_s390 ();case EM_386 :
@@ -167,6 +177,9 @@ int libunwind_arch__dwarf_search_unwind_table(unsigned int e_machine,case EM_PPC64 :return __libunwind_arch__dwarf_search_unwind_table_ppc64 (as, ip, di, pi, need_unwind_info, arg); +case EM_RISCV : +return __libunwind_arch__dwarf_search_unwind_table_riscv (as, ip, di, pi, + need_unwind_info, arg);case EM_S390 :return __libunwind_arch__dwarf_search_unwind_table_s390 (as, ip, di, pi, need_unwind_info, arg);
@@ -211,6 +224,9 @@ int libunwind_arch__dwarf_find_debug_frame(unsigned int e_machine,case EM_PPC64 :return __libunwind_arch__dwarf_find_debug_frame_ppc64 (found, di_debug, ip, segbase, obj_name, start, end); +case EM_RISCV : +return __libunwind_arch__dwarf_find_debug_frame_riscv (found, di_debug, ip, segbase, + obj_name, start, end);case EM_S390 :return __libunwind_arch__dwarf_find_debug_frame_s390 (found, di_debug, ip, segbase, obj_name, start, end);
@@ -250,6 +266,9 @@ struct unwind_info *libunwind_arch_unwind_info__new(struct thread *thread,case EM_PPC64 :return __libunwind_arch_unwind_info__new_ppc64 (thread, sample, max_stack, best_effort, first_ip); +case EM_RISCV : +return __libunwind_arch_unwind_info__new_riscv (thread, sample, max_stack, + best_effort, first_ip);case EM_S390 :return __libunwind_arch_unwind_info__new_s390 (thread, sample, max_stack, best_effort, first_ip);
@@ -285,6 +304,8 @@ int libunwind_arch__unwind_step(struct unwind_info *ui)return __libunwind_arch__unwind_step_ppc32 (ui);case EM_PPC64 :return __libunwind_arch__unwind_step_ppc64 (ui); +case EM_RISCV : +return __libunwind_arch__unwind_step_riscv (ui);case EM_S390 :return __libunwind_arch__unwind_step_s390 (ui);case EM_386 :
tools/perf/util/libunwind-arch/libunwind-arch.h +22 -0
@@ -39,6 +39,7 @@ int __get_perf_regnum_for_unw_regnum_loongarch(int unw_regnum);int __get_perf_regnum_for_unw_regnum_mips (int unw_regnum);int __get_perf_regnum_for_unw_regnum_ppc32 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_ppc64 (int unw_regnum); +int __get_perf_regnum_for_unw_regnum_riscv (int unw_regnum);int __get_perf_regnum_for_unw_regnum_s390 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_i386 (int unw_regnum);int __get_perf_regnum_for_unw_regnum_x86_64 (int unw_regnum);
@@ -50,6 +51,7 @@ void __libunwind_arch__flush_access_loongarch(struct maps *maps);void __libunwind_arch__flush_access_mips (struct maps *maps);void __libunwind_arch__flush_access_ppc32 (struct maps *maps);void __libunwind_arch__flush_access_ppc64 (struct maps *maps); +void __libunwind_arch__flush_access_riscv (struct maps *maps);void __libunwind_arch__flush_access_s390 (struct maps *maps);void __libunwind_arch__flush_access_i386 (struct maps *maps);void __libunwind_arch__flush_access_x86_64 (struct maps *maps);
@@ -61,6 +63,7 @@ void __libunwind_arch__finish_access_loongarch(struct maps *maps);void __libunwind_arch__finish_access_mips (struct maps *maps);void __libunwind_arch__finish_access_ppc32 (struct maps *maps);void __libunwind_arch__finish_access_ppc64 (struct maps *maps); +void __libunwind_arch__finish_access_riscv (struct maps *maps);void __libunwind_arch__finish_access_s390 (struct maps *maps);void __libunwind_arch__finish_access_i386 (struct maps *maps);void __libunwind_arch__finish_access_x86_64 (struct maps *maps);
@@ -72,6 +75,7 @@ void *__libunwind_arch__create_addr_space_loongarch(void);void *__libunwind_arch__create_addr_space_mips (void );void *__libunwind_arch__create_addr_space_ppc32 (void );void *__libunwind_arch__create_addr_space_ppc64 (void ); +void *__libunwind_arch__create_addr_space_riscv (void );void *__libunwind_arch__create_addr_space_s390 (void );void *__libunwind_arch__create_addr_space_i386 (void );void *__libunwind_arch__create_addr_space_x86_64 (void );
@@ -111,6 +115,11 @@ int __libunwind_arch__dwarf_search_unwind_table_ppc64(void *as, uint64_t ip,void *pi, int need_unwind_info, void *arg); +int __libunwind_arch__dwarf_search_unwind_table_riscv (void *as,uint64_t ip, +struct libarch_unwind__dyn_info *di, +void *pi, +int need_unwind_info, +void *arg); int __libunwind_arch__dwarf_search_unwind_table_s390(void *as, uint64_t ip, struct libarch_unwind__dyn_info *di, void *pi,
@@ -176,6 +185,13 @@ int __libunwind_arch__dwarf_find_debug_frame_ppc64(int found,const char *obj_name, uint64_t start, uint64_t end); +int __libunwind_arch__dwarf_find_debug_frame_riscv (int found, +struct libarch_unwind__dyn_info *di_debug, +uint64_t ip, +uint64_t segbase, +const char *obj_name, +uint64_t start, +uint64_t end); int __libunwind_arch__dwarf_find_debug_frame_s390(int found, struct libarch_unwind__dyn_info *di_debug, uint64_t ip,
@@ -236,6 +252,11 @@ struct unwind_info *__libunwind_arch_unwind_info__new_ppc64(struct thread *threaint max_stack, bool best_effort, uint64_t first_ip); +struct unwind_info *__libunwind_arch_unwind_info__new_riscv (struct thread *thread, +struct perf_sample *sample, +int max_stack, +bool best_effort, +uint64_t first_ip); struct unwind_info *__libunwind_arch_unwind_info__new_s390(struct thread *thread, struct perf_sample *sample, int max_stack,
@@ -266,6 +287,7 @@ int __libunwind_arch__unwind_step_loongarch(struct unwind_info *ui);int __libunwind_arch__unwind_step_mips (struct unwind_info *ui);int __libunwind_arch__unwind_step_ppc32 (struct unwind_info *ui);int __libunwind_arch__unwind_step_ppc64 (struct unwind_info *ui); +int __libunwind_arch__unwind_step_riscv (struct unwind_info *ui);int __libunwind_arch__unwind_step_s390 (struct unwind_info *ui);int __libunwind_arch__unwind_step_i386 (struct unwind_info *ui);int __libunwind_arch__unwind_step_x86_64 (struct unwind_info *ui);
tools/perf/util/libunwind-arch/libunwind-riscv.c new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Ian Rogers
reviewerQuoted 15 lines · Ian Rogers
Fix the libunwind build for when libdw and libunwind are feature detected, currently failing with a duplicate symbol.
Refactor the libunwind support so that whenever a remote target is available, perf functions using the ELF machine can use that remote target regardless of what the host/local machine is. Migrate existing libunwind supported architectures like powerpc, arm64 and loongarch so that they can work in a cross-architecture way. Add support for RISC-V. Make the code more regular in function names, etc. and avoid including a C-file. This increases the lines of code. It is similar in style to the unwind-libdw implementation. It is hoped that the more uniform nature of the code will help with refactoring the perf registers for SIMD/APX support.
Quoted 3 lines
Aside from local host testing these patches are under tested, in part as I'm failing to see how to build libunwind with support for multiple remote targets. Please could I get help in testing.
So the patches failed to apply in Sashiko:
https://sashiko.dev/#/patchset/20260513233151.572332-1-irogers%40google.com
The baseline logs show perf-tools-next was at commit 8c8f20936143 ("perf build: Remove NO_GTK2 build test") which is 6 patches out-of-date compared to the current tip these patches are against. I ran Sashiko locally, so I don't expect a huge amount from the reviews. Currently Sashiko is catching up with a backlog because its tokens have a lower priority and there was high load earlier in the week. Anyway, I could repost the patches for Sashiko review but given the backlog I think that would just create noise at the moment. Hopefully I can get human review so we can move forward with merging these improvements.
Thanks,
Ian
Quoted 149 lines
v5: Rebase dropping merged loong arch fix patch. Fixes to Sashiko
review feedback:
- Patch 1: Hookedunwind__configure()intoperf_default_config(). Standardized unwinder return contracts (>0 success, 0 fallback, <0 fatal). FixedUNWIND_STYLE_UNKNOWNfallback and addedmemset()to clear config array on override.
- Patch 2: Dynamically populated FILES list intools/build/feature/MakefileusingLIBUNWIND_ARCHS. Added libunwind cases toFEATURE_TESTS_EXTRAintools/build/Makefile.featurefor proper FEATURE-DUMP caching.
- Patch 3: Restored core -lunwind linkage toFEATURE_CHECK_LDFLAGS. RestoredNO_LIBUNWINDfallback validation, corrected EXTLIBS evaluation ordering for BIONIC/Android compatibility, and restored static linking multiple definition flags.
- Patch 4: Fixed out-of-bounds array read bugs (>=ARRAY_SIZE) inlibunwind-i386.candlibunwind-x86_64.c. Fixed constant typos across LoongArch, PowerPC, and s390x.
- Patch 5: Added earlyEM_NONEand ops validation checks to prevent warnings and NULL dereferences. Checked return value ofunwind__prepare_access()inmaps__copy_from(). Corrected architecture binding inthread__insert_map()by calculatinge_machineafter map insertion.
- Patch 6: Aligned all remote architecture accessors to match 5-argument generic declarations (removing trailingsizeof(unw_word_t)). Prevented frame discard on stack depth limit by returning 0 instead of -1 inunwind_step(). Fixed 32-bit big-endian register corruption by replacingmemcpy()with conditional type-casted assignment. Fixedmax_stack== 1 fallback trigger. Fixed .debug_frame layout union corruption by changing di.u.rti to di.u.ti across all DWARF find wrappers.
- Patch 7: Applied the same corrections (5-argument accessors, u.ti union accessors, 0 return onmax_ips) to the newly introducedlibunwind-riscv.c.v4: Rebase, in particular the
zalloc->callocchange conflicted.
https://lore.kernel.org/linux-perf-users/[email protected]/v3: Minor whitespace clean up and warn when a dynamic choice of libdw
or libunwind is selected for unwinding and support is missing (Arnaldo).
https://lore.kernel.org/lkml/[email protected]/v2: Move two fixes patches to position 1 and 2 in the series. Fix
struct naming inconsistency, Andrew Jones <[email protected]>. Fix other inconsistencies and potential non-x86 build issues.
https://lore.kernel.org/lkml/[email protected]/v1: https://lore.kernel.org/lkml/[email protected]/
Ian Rogers (7):
perf unwind: Refactorget_entriesto allow dynamic libdw/libunwind
selection
tools build: Deduplicate test-libunwind for different architectures perf build: Be more programmatic when setting up libunwind variables perf unwind-libunwind: Make libunwind register reading cross platform perf unwind-libunwind: Move flush/finish access out of local perf unwind-libunwind: Remove libunwind-local
perf unwind-libunwind: Add RISC-V libunwind supporttools/build/Makefile.feature | 12 +- tools/build/feature/Makefile | 46 +- tools/build/feature/test-libunwind-aarch64.c | 27 - tools/build/feature/test-libunwind-arm.c | 28 - .../test-libunwind-debug-frame-aarch64.c | 17 - .../feature/test-libunwind-debug-frame-arm.c | 17 - .../feature/test-libunwind-debug-frame.c | 1 - tools/build/feature/test-libunwind-x86.c | 28 - tools/build/feature/test-libunwind-x86_64.c | 28 - tools/build/feature/test-libunwind.c | 1 - tools/perf/Makefile.config | 226 +++-- tools/perf/arch/arm/util/Build | 2 - tools/perf/arch/arm/util/unwind-libunwind.c | 50 -- tools/perf/arch/arm64/util/Build | 1 - tools/perf/arch/arm64/util/unwind-libunwind.c | 17 - tools/perf/arch/loongarch/util/Build | 2 - .../arch/loongarch/util/unwind-libunwind.c | 82 -- tools/perf/arch/mips/Build | 1 - tools/perf/arch/mips/util/Build | 1 - tools/perf/arch/mips/util/unwind-libunwind.c | 22 - tools/perf/arch/powerpc/util/Build | 1 - .../perf/arch/powerpc/util/unwind-libunwind.c | 92 -- tools/perf/arch/x86/util/Build | 3 - tools/perf/arch/x86/util/unwind-libunwind.c | 115 --- tools/perf/builtin-inject.c | 4 + tools/perf/builtin-report.c | 4 + tools/perf/builtin-script.c | 4 + tools/perf/util/Build | 5 +- tools/perf/util/config.c | 4 + tools/perf/util/libunwind-arch/Build | 11 + .../perf/util/libunwind-arch/libunwind-arch.c | 319 +++++++ .../perf/util/libunwind-arch/libunwind-arch.h | 296 +++++++ .../perf/util/libunwind-arch/libunwind-arm.c | 290 ++++++ .../util/libunwind-arch/libunwind-arm64.c | 289 ++++++ .../perf/util/libunwind-arch/libunwind-i386.c | 312 +++++++ .../util/libunwind-arch/libunwind-loongarch.c | 297 +++++++ .../perf/util/libunwind-arch/libunwind-mips.c | 299 +++++++ .../util/libunwind-arch/libunwind-ppc32.c | 301 +++++++ .../util/libunwind-arch/libunwind-ppc64.c | 303 +++++++ .../util/libunwind-arch/libunwind-riscv.c | 297 +++++++ .../perf/util/libunwind-arch/libunwind-s390.c | 299 +++++++ .../util/libunwind-arch/libunwind-x86_64.c | 320 +++++++ tools/perf/util/libunwind/arm64.c | 40 - tools/perf/util/libunwind/x86_32.c | 41 - tools/perf/util/maps.c | 34 +- tools/perf/util/maps.h | 4 +- tools/perf/util/symbol_conf.h | 10 + tools/perf/util/thread.c | 32 +- tools/perf/util/unwind-libdw.c | 20 +- tools/perf/util/unwind-libunwind-local.c | 831 ------------------ tools/perf/util/unwind-libunwind.c | 699 +++++++++++++-- tools/perf/util/unwind.c | 104 +++ tools/perf/util/unwind.h | 73 +- 53 files changed, 4623 insertions(+), 1739 deletions(-) delete mode 100644 tools/build/feature/test-libunwind-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-arm.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-aarch64.c delete mode 100644 tools/build/feature/test-libunwind-debug-frame-arm.c delete mode 100644 tools/build/feature/test-libunwind-x86.c delete mode 100644 tools/build/feature/test-libunwind-x86_64.c delete mode 100644 tools/perf/arch/arm/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/arm64/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/loongarch/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/mips/Build delete mode 100644 tools/perf/arch/mips/util/Build delete mode 100644 tools/perf/arch/mips/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/powerpc/util/unwind-libunwind.c delete mode 100644 tools/perf/arch/x86/util/unwind-libunwind.c create mode 100644 tools/perf/util/libunwind-arch/Build create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arch.h create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-arm64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-i386.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-loongarch.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-mips.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc32.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-ppc64.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-riscv.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-s390.c create mode 100644 tools/perf/util/libunwind-arch/libunwind-x86_64.c delete mode 100644 tools/perf/util/libunwind/arm64.c delete mode 100644 tools/perf/util/libunwind/x86_32.c delete mode 100644 tools/perf/util/unwind-libunwind-local.c create mode 100644 tools/perf/util/unwind.c--
2.54.0.563.g4f69b47b94-goog
Arnaldo Carvalho de Melo
maintainerQuoted 19 lines · Ian Rogers
Quoted 14 lines · Ian Rogers
Fix the libunwind build for when libdw and libunwind are feature detected, currently failing with a duplicate symbol.
Refactor the libunwind support so that whenever a remote target is available, perf functions using the ELF machine can use that remote target regardless of what the host/local machine is. Migrate existing libunwind supported architectures like powerpc, arm64 and loongarch so that they can work in a cross-architecture way. Add support for RISC-V. Make the code more regular in function names, etc. and avoid including a C-file. This increases the lines of code. It is similar in style to the unwind-libdw implementation. It is hoped that the more uniform nature of the code will help with refactoring the perf registers for SIMD/APX support.
Quoted 3 lines
Aside from local host testing these patches are under tested, in part as I'm failing to see how to build libunwind with support for multiple remote targets. Please could I get help in testing.
Quoted 12 lines
So the patches failed to apply in Sashiko:
https://sashiko.dev/#/patchset/20260513233151.572332-1-irogers%40google.com
The baseline logs show perf-tools-next was at commit8c8f20936143("perf build: RemoveNO_GTK2build test") which is 6 patches out-of-date compared to the current tip these patches are against. I ran Sashiko locally, so I don't expect a huge amount from the reviews. Currently Sashiko is catching up with a backlog because its tokens have a lower priority and there was high load earlier in the week. Anyway, I could repost the patches for Sashiko review but given the backlog I think that would just create noise at the moment. Hopefully I can get human review so we can move forward with merging these improvements.
Trying to apply it now, will also run sashiko locally.
- Arnaldo
Arnaldo Carvalho de Melo
maintainerQuoted 33 lines · Arnaldo Carvalho de Melo
Quoted 19 lines · Ian Rogers
Quoted 14 lines · Ian Rogers
Fix the libunwind build for when libdw and libunwind are feature detected, currently failing with a duplicate symbol.
Refactor the libunwind support so that whenever a remote target is available, perf functions using the ELF machine can use that remote target regardless of what the host/local machine is. Migrate existing libunwind supported architectures like powerpc, arm64 and loongarch so that they can work in a cross-architecture way. Add support for RISC-V. Make the code more regular in function names, etc. and avoid including a C-file. This increases the lines of code. It is similar in style to the unwind-libdw implementation. It is hoped that the more uniform nature of the code will help with refactoring the perf registers for SIMD/APX support.
Quoted 3 lines
Aside from local host testing these patches are under tested, in part as I'm failing to see how to build libunwind with support for multiple remote targets. Please could I get help in testing.
Quoted 12 lines
So the patches failed to apply in Sashiko:
https://sashiko.dev/#/patchset/20260513233151.572332-1-irogers%40google.com
The baseline logs show perf-tools-next was at commit8c8f20936143("perf build: RemoveNO_GTK2build test") which is 6 patches out-of-date compared to the current tip these patches are against. I ran Sashiko locally, so I don't expect a huge amount from the reviews. Currently Sashiko is catching up with a backlog because its tokens have a lower priority and there was high load earlier in the week. Anyway, I could repost the patches for Sashiko review but given the backlog I think that would just create noise at the moment. Hopefully I can get human review so we can move forward with merging these improvements.
Quoted 1 line
Trying to apply it now, will also run sashiko locally.
Its in perf-tools-next tmp.perf-tools-next,
Running build tests now and will let sashiko running locally, probably will push out tomorrow morning if nothing major is reported.
To make progress I think we can go on addressing some Sashiko reviews with followup series otherwise it drags for a long time.
- Arnaldo