Re: [PATCH V3 11/14] tools/perf: Add support to use libcapstone in powerpc
From: Adrian Hunter
Date: Tue Jun 11 2024 - 12:31:24 EST
On 10/06/24 15:20, Athira Rajeev wrote:
>
>
>> On 3 Jun 2024, at 10:28 PM, Adrian Hunter <adrian.hunter@xxxxxxxxx> wrote:
>>
>> On 3/06/24 19:30, Ian Rogers wrote:
>>> On Fri, May 31, 2024 at 11:10 PM Athira Rajeev
>>> <atrajeev@xxxxxxxxxxxxxxxxxx> wrote:
>>>>
>>>> Now perf uses the capstone library to disassemble the instructions in
>>>> x86. capstone is used (if available) for perf annotate to speed up.
>>>> Currently it only supports x86 architecture. Patch includes changes to
>>>> enable this in powerpc. For now, only for data type sort keys, this
>>>> method is used and only binary code (raw instruction) is read. This is
>>>> because powerpc approach to understand instructions and reg fields uses
>>>> raw instruction. The "cs_disasm" is currently not enabled. While
>>>> attempting to do cs_disasm, observation is that some of the instructions
>>>> were not identified (ex: extswsli, maddld) and it had to fallback to use
>>>> objdump. Hence enabling "cs_disasm" is added in comment section as a
>>>> TODO for powerpc.
>>>>
>>>> Signed-off-by: Athira Rajeev <atrajeev@xxxxxxxxxxxxxxxxxx>
>>>> ---
>>>> tools/perf/util/disasm.c | 148 ++++++++++++++++++++++++++++++++++++++-
>>>> 1 file changed, 146 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
>>>> index d8b357055302..915508d2e197 100644
>>>> --- a/tools/perf/util/disasm.c
>>>> +++ b/tools/perf/util/disasm.c
>>>> @@ -1540,12 +1540,18 @@ static int open_capstone_handle(struct annotate_args *args, bool is_64bit,
>>>> {
>>>> struct annotation_options *opt = args->options;
>>>> cs_mode mode = is_64bit ? CS_MODE_64 : CS_MODE_32;
>>>> + int ret;
>>>>
>>>> /* TODO: support more architectures */
>>>> - if (!arch__is(args->arch, "x86"))
>>>> + if ((!arch__is(args->arch, "x86")) && (!arch__is(args->arch, "powerpc")))
>>>> return -1;
>>>>
>>>> - if (cs_open(CS_ARCH_X86, mode, handle) != CS_ERR_OK)
>>>> + if (arch__is(args->arch, "x86"))
>>>> + ret = cs_open(CS_ARCH_X86, mode, handle);
>>>> + else
>>>> + ret = cs_open(CS_ARCH_PPC, mode, handle);
>>>> +
>>>> + if (ret != CS_ERR_OK)
>>>> return -1;
>>>
>>> There looks to be a pretty/more robust capstone_init function in
>>> print_insn.c, should we factor this code out and recycle:
>>> https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/print_insn.c?h=perf-tools-next#n40
>>
>> On a slightly related note, there is a compile error
>> been around for a while in util/disasm.c on Ubuntu 22.04
>>
>> In file included from /usr/include/capstone/capstone.h:279,
>> from util/disasm.c:1354:
>> /usr/include/capstone/bpf.h:94:14: error: ‘bpf_insn’ defined as wrong
>> kind of tag
>> 94 | typedef enum bpf_insn {
>> | ^~~~~~~~
>>
>
> Hi Adrian
>
> I tried compilation on Ubuntu 22.04, but didn’t face this issue.
> The libcapstone version I have is libcapstone4 which doesn’t have the include for “bpf.h”
> What is the version of libcapstone in the setup where you are seeing this issue ?
Yes, sorry. I got confused. Ubuntu was OK. The original issue
was with Fedora 40, but even then it requires binutils-devel
and BUILD_NONDISTRO=1