All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Aditya Gupta <adityag@linux.ibm.com>,
	"Steinar H. Gunderson" <sesse@google.com>,
	Charlie Jenkins <charlie@rivosinc.com>,
	Changbin Du <changbin.du@huawei.com>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	James Clark <james.clark@linaro.org>,
	Kajol Jain <kjain@linux.ibm.com>,
	Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
	Li Huafei <lihuafei1@huawei.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Andi Kleen <ak@linux.intel.com>,
	Chaitanya S Prakash <chaitanyas.prakash@arm.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	llvm@lists.linux.dev, Song Liu <song@kernel.org>,
	bpf@vger.kernel.org
Subject: Re: [PATCH v3 06/18] perf capstone: Support for dlopen-ing libcapstone.so
Date: Tue, 28 Jan 2025 12:58:00 -0800	[thread overview]
Message-ID: <Z5lE2MC0wh3WDVnX@google.com> (raw)
In-Reply-To: <CAP-5=fWNy8CM8nKOAH=aXyNKg5h4U4vWfB92io_T5KpCsSgv9Q@mail.gmail.com>

On Fri, Jan 24, 2025 at 09:20:15PM -0800, Ian Rogers wrote:
> On Fri, Jan 24, 2025 at 2:22 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > On Wed, Jan 22, 2025 at 09:42:56AM -0800, Ian Rogers wrote:
> > > If perf wasn't built against libcapstone, no HAVE_LIBCAPSTONE_SUPPORT,
> > > support dlopen-ing libcapstone.so and then calling the necessary
> > > functions by looking them up using dlsym. Reverse engineer the types
> > > in the API using pahole, adding only what's used in the perf code or
> > > necessary for the sake of struct size and alignment.
> > >
> > > Signed-off-by: Ian Rogers <irogers@google.com>
> > > ---
> > >  tools/perf/util/capstone.c | 287 ++++++++++++++++++++++++++++++++-----
> > >  1 file changed, 248 insertions(+), 39 deletions(-)
> > >
> > > diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c
> > > index c9845e4d8781..8d65c7a55a8b 100644
> > > --- a/tools/perf/util/capstone.c
> > > +++ b/tools/perf/util/capstone.c
> > > @@ -11,19 +11,249 @@
> > >  #include "print_insn.h"
> > >  #include "symbol.h"
> > >  #include "thread.h"
> > > +#include <dlfcn.h>
> > >  #include <fcntl.h>
> > > +#include <inttypes.h>
> >
> > These two can go under #else (!HAVE_LIBCAPSTONE_SUPPORT).
> 
> Ack.
> 
> > >  #include <string.h>
> > >
> > >  #ifdef HAVE_LIBCAPSTONE_SUPPORT
> > >  #include <capstone/capstone.h>
> > > +#else
> > > +typedef size_t csh;
> > > +enum cs_arch {
> > > +     CS_ARCH_ARM = 0,
> > > +     CS_ARCH_ARM64 = 1,
> > > +     CS_ARCH_X86 = 3,
> > > +     CS_ARCH_SYSZ = 6,
> > > +};
> > > +enum cs_mode {
> > > +     CS_MODE_ARM = 0,
> > > +     CS_MODE_32 = 1 << 2,
> > > +     CS_MODE_64 = 1 << 3,
> > > +     CS_MODE_V8 = 1 << 6,
> > > +     CS_MODE_BIG_ENDIAN = 1 << 31,
> > > +};
> > > +enum cs_opt_type {
> > > +     CS_OPT_SYNTAX = 1,
> > > +     CS_OPT_DETAIL = 2,
> > > +};
> > > +enum cs_opt_value {
> > > +     CS_OPT_SYNTAX_ATT = 2,
> > > +     CS_OPT_ON = 3,
> > > +};
> > > +enum cs_err {
> > > +     CS_ERR_OK = 0,
> > > +     CS_ERR_HANDLE = 3,
> > > +};
> > > +enum x86_op_type {
> > > +     X86_OP_IMM = 2,
> > > +     X86_OP_MEM = 3,
> > > +};
> > > +enum x86_reg {
> > > +     X86_REG_RIP = 41,
> > > +};
> > > +typedef int32_t x86_avx_bcast;
> > > +struct x86_op_mem {
> > > +     enum x86_reg segment;
> > > +     enum x86_reg base;
> > > +     enum x86_reg index;
> > > +     int scale;
> > > +     int64_t disp;
> > > +};
> > > +
> > > +struct cs_x86_op {
> > > +     enum x86_op_type type;
> > > +     union {
> > > +             enum x86_reg  reg;
> > > +             int64_t imm;
> > > +             struct x86_op_mem mem;
> > > +     };
> > > +     uint8_t size;
> > > +     uint8_t access;
> > > +     x86_avx_bcast avx_bcast;
> > > +     bool avx_zero_opmask;
> > > +};
> > > +struct cs_x86_encoding {
> > > +     uint8_t modrm_offset;
> > > +     uint8_t disp_offset;
> > > +     uint8_t disp_size;
> > > +     uint8_t imm_offset;
> > > +     uint8_t imm_size;
> > > +};
> > > +typedef int32_t  x86_xop_cc;
> > > +typedef int32_t  x86_sse_cc;
> > > +typedef int32_t  x86_avx_cc;
> > > +typedef int32_t  x86_avx_rm;
> > > +struct cs_x86 {
> > > +     uint8_t prefix[4];
> > > +     uint8_t opcode[4];
> > > +     uint8_t rex;
> > > +     uint8_t addr_size;
> > > +     uint8_t modrm;
> > > +     uint8_t sib;
> > > +     int64_t disp;
> > > +     enum x86_reg sib_index;
> > > +     int8_t sib_scale;
> > > +     enum x86_reg sib_base;
> > > +     x86_xop_cc xop_cc;
> > > +     x86_sse_cc sse_cc;
> > > +     x86_avx_cc avx_cc;
> > > +     bool avx_sae;
> > > +     x86_avx_rm avx_rm;
> > > +     union {
> > > +             uint64_t eflags;
> > > +             uint64_t fpu_flags;
> > > +     };
> > > +     uint8_t op_count;
> > > +     struct cs_x86_op operands[8];
> > > +     struct cs_x86_encoding encoding;
> > > +};
> > > +struct cs_detail {
> > > +     uint16_t regs_read[12];
> > > +     uint8_t regs_read_count;
> > > +     uint16_t regs_write[20];
> > > +     uint8_t regs_write_count;
> > > +     uint8_t groups[8];
> > > +     uint8_t groups_count;
> > > +
> > > +     union {
> > > +             struct cs_x86 x86;
> > > +     };
> > > +};
> >
> > As discussed, let's remove the detail part.
> 
> I kind of feel there should be a #warning in that case. I'd rather
> leave it as is and not have a build warning.

What kind of build warning are you talking about?

Thanks,
Namhyung


  reply	other threads:[~2025-01-28 20:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22 17:42 [PATCH v3 00/18] Support dynamic opening of capstone/llvm remove BUILD_NONDISTRO Ian Rogers
2025-01-22 17:42 ` [PATCH v3 01/18] perf build: Remove libtracefs configuration Ian Rogers
2025-01-22 17:42 ` [PATCH v3 02/18] perf map: Constify objdump offset/address conversion APIs Ian Rogers
2025-01-22 17:42 ` [PATCH v3 03/18] perf capstone: Move capstone functionality into its own file Ian Rogers
2025-01-24 21:58   ` Namhyung Kim
2025-01-25  0:59     ` Ian Rogers
2025-01-28 20:56       ` Namhyung Kim
2025-01-28 22:16         ` Ian Rogers
2025-01-22 17:42 ` [PATCH v3 04/18] perf llvm: Move llvm " Ian Rogers
2025-01-24 22:04   ` Namhyung Kim
2025-01-22 17:42 ` [PATCH v3 05/18] perf capstone: Remove open_capstone_handle Ian Rogers
2025-01-22 17:42 ` [PATCH v3 06/18] perf capstone: Support for dlopen-ing libcapstone.so Ian Rogers
2025-01-24 22:22   ` Namhyung Kim
2025-01-25  5:20     ` Ian Rogers
2025-01-28 20:58       ` Namhyung Kim [this message]
2025-01-28 22:13         ` Ian Rogers
2025-01-22 17:42 ` [PATCH v3 07/18] perf llvm: Support for dlopen-ing libLLVM.so Ian Rogers
2025-01-24 22:54   ` Namhyung Kim
2025-01-25  1:21     ` Ian Rogers
2025-01-22 17:42 ` [PATCH v3 08/18] perf llvm: Mangle libperf-llvm.so function names Ian Rogers
2025-01-22 17:42 ` [PATCH v3 09/18] perf dso: Move read_symbol from llvm/capstone to dso Ian Rogers
2025-01-22 17:43 ` [PATCH v3 10/18] perf dso: Support BPF programs in dso__read_symbol Ian Rogers
2025-03-25 17:44   ` Ian Rogers
2025-01-22 17:43 ` [PATCH v3 11/18] perf llvm: Disassemble cleanup Ian Rogers
2025-01-22 17:43 ` [PATCH v3 12/18] perf dso: Clean up read_symbol error handling Ian Rogers
2025-01-22 17:43 ` [PATCH v3 13/18] perf build: Remove libbfd support Ian Rogers
2025-01-29  0:31   ` Daniel Xu
2025-01-29  1:40     ` Ian Rogers
2025-01-29 16:46       ` Daniel Xu
2025-01-29 19:36         ` Ian Rogers
2025-01-22 17:43 ` [PATCH v3 14/18] perf build: Remove libiberty support Ian Rogers
2025-01-22 17:43 ` [PATCH v3 15/18] perf build: Remove unused defines Ian Rogers
2025-01-22 17:43 ` [PATCH v3 16/18] perf disasm: Remove disasm_bpf Ian Rogers
2025-01-22 17:43 ` [PATCH v3 17/18] perf disasm: Make ins__scnprintf and ins__is_nop static Ian Rogers
2025-01-22 17:43 ` [PATCH v3 18/18] perf srcline: Fallback between addr2line implementations Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z5lE2MC0wh3WDVnX@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adityag@linux.ibm.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=chaitanyas.prakash@arm.com \
    --cc=changbin.du@huawei.com \
    --cc=charlie@rivosinc.com \
    --cc=dvyukov@google.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=kjain@linux.ibm.com \
    --cc=lihuafei1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=sesse@google.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.