]> git.ipfire.org Git - thirdparty/elfutils.git/commit
libebl [1/12]: api for perf register handling, start with x86_64
authorSerhei Makarov <serhei@serhei.io>
Fri, 25 Apr 2025 14:55:43 +0000 (10:55 -0400)
committerAaron Merey <amerey@redhat.com>
Fri, 25 Apr 2025 15:53:46 +0000 (11:53 -0400)
commiteff7efd40e6513cde4a621fa2fa40477fc9e80b6
tree0122491a0f868fc04a1bcf1f57c40120748ed323
parent4d50c9e68808cbdd22dd70c26482ec010aefcbbf
libebl [1/12]: api for perf register handling, start with x86_64

First patch of a series that reworks eu-stacktrace functionality
into a library interface for other profiling tools.

* * *

As it happens, Linux perf_events and DWARF can prescribe completely
different layouts for the register file, requiring non-obvious code
for translation. This makes sense to put in libebl if we want
profilers to handle perf sample data with elfutils.

Start with the x86_64/i386 implementation taken from eu-stacktrace. The
code has been generalized to accept other perf register masks besides
the 'preferred' one.

* backends/Makefile.am (i386_SRCS): Add i386_initreg_sample.c.
  (x86_64_SRCS): Add x86_64_initreg_sample.c.
  (noinst_HEADERS): Add libebl_PERF_FLAGS.h,
  linux-perf-regs.c, x86_initreg_sample.c.
* backends/libebl_PERF_FLAGS.h: New file.
* backends/linux-perf-regs.c: New file.
  (perf_sample_find_reg): Index into a perf register array whose
  contents are described by regs_mask. The target index is the index
  of the register in the enum defined by
  linux arch/N/include/uapi/asm/perf_regs.h on arch N.
* backends/x86_initreg_sample.c: New file, implements a generalized
  version of the eu-stacktrace register shuffling for x86-64/i386.
* backends/x86_64_initreg_sample.c: New file, specializes
  x86_initreg_sample.c for x86-64.
* backends/i386_initreg_sample.c: New file, specializes
  i386_initreg_sample.c for i386.
* backends/x86_64_init.c (x86_64_init): Add initialization for
  set_initial_registers_sample, perf_frame_regs_mask,
  sample_base_addr, sample_pc.
* backends/i386_init.c (i386_init): Add initialization for
  set_initial_registers_sample, perf_frame_regs_mask,
  sample_base_addr, sample_pc.
* libebl/Makefile.am (libebl_a_SOURCES): Add eblinitreg_sample.c.
* libebl/ebl-hooks.h (set_initial_registers_sample): New hook.
  (sample_base_addr): Ditto.
  (sample_pc): Ditto.
* libebl/eblinitreg_sample.c: New file, implements ebl interface to
  set_initial_registers_sample, sample_base_addr, sample_pc
  backend hooks.
* libebl/libebl.h (ebl_set_initial_registers_sample): New function.
  (ebl_perf_frame_regs_mask): New function.
  (ebl_sample_base_addr): New function.
  (ebl_sample_pc): New function.
* libebl/libeblP.h (struct ebl): Add perf_frame_regs_mask field
  giving the preferred register mask.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
13 files changed:
backends/Makefile.am
backends/i386_init.c
backends/i386_initreg_sample.c [new file with mode: 0644]
backends/libebl_PERF_FLAGS.h [new file with mode: 0644]
backends/linux-perf-regs.c [new file with mode: 0644]
backends/x86_64_init.c
backends/x86_64_initreg_sample.c [new file with mode: 0644]
backends/x86_initreg_sample.c [new file with mode: 0644]
libebl/Makefile.am
libebl/ebl-hooks.h
libebl/eblinitreg_sample.c [new file with mode: 0644]
libebl/libebl.h
libebl/libeblP.h