From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E804CC6FA82 for ; Tue, 13 Sep 2022 13:34:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbiIMNeZ (ORCPT ); Tue, 13 Sep 2022 09:34:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbiIMNeX (ORCPT ); Tue, 13 Sep 2022 09:34:23 -0400 Received: from mail.kdab.com (mail.kdab.com [176.9.126.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49F1F20189 for ; Tue, 13 Sep 2022 06:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kdab.com; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:references:content-language:subject:subject :mime-version:date:date:message-id; s=dkim; t=1663076059; x= 1663940060; bh=SBmn9TN4QrEBobGltSfTOn4OJaEs7iHgnoE+mtJAoeY=; b=e 5tTRH2c5lPljvnfvNfjJIC4KMFVQUr+f5J5LgoLO2hoKXDTye0jaKu3PzDEuVEtk gNAHyLcacJtYWlpJ7OXE/JXRW6i+s9krYdIipv4r50qZ+OPA9IaCwTuupYURBHuh 7e6EFlABcoL5EKJfGTBrepiNldSBlPZEEQawpvTIMA= X-Virus-Scanned: amavisd-new at kdab.com Message-ID: <1b701f63-4f78-dbc8-cac4-bfbf7be84134@kdab.com> Date: Tue, 13 Sep 2022 15:34:18 +0200 MIME-Version: 1.0 Subject: Re: [PATCH] include program header in elf files generated by perf inject Content-Language: en-US To: James Clark , leo.yan@linaro.org References: <20220825084923.167140-1-lieven.hey@kdab.com> <80f54486-1470-c355-d639-1a27b4d1ea22@arm.com> <6e0ebfb6-9fbf-073c-94b0-a799b9ec657f@kdab.com> <1cc13a5d-bb41-edbb-ade7-62d4a678c0f9@kdab.com> Cc: linux-perf-users@vger.kernel.org, acme@kernel.org From: Lieven Hey In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Hi, perf is unable to open elf files generated by perf inject. Example: Create a file named test.dart with the following content: void main() { print("Hello World"); } and then run perf record --call-graph dwarf -k 1 dart --generate-perf-jitdump test.dar= t perf inject -j -i perf.data -o perf.data.jitted The problem exists since 2d86612aacb78. The commit added some code that=20 now requires an elf file to have a valid program header. Cheers Lieven Am 13.09.22 um 11:56 schrieb James Clark: >=20 >=20 > On 09/09/2022 14:47, Lieven Hey wrote: >> Hi James, >> >> I looked into this again. Commit 2d86612aacb78 changed the elf loading >> code so that a program header is now required. >> >=20 > Can you reply-all on the original mailing list thread with this and a > 'to' to Leo. It's probably best to continue the discussion there so Leo > is aware. >=20 > Thanks >=20 >> Am 25.08.22 um 17:24 schrieb James Clark: >>> >>> >>> On 25/08/2022 14:56, Lieven Hey wrote: >>>> Hi James, >>>> >>>> I created a file named test.dart with the following content: >>>> >>>> void main() { >>>> =C2=A0=C2=A0 print("Hello World"); >>>> } >>>> >>>> and then run >>>> >>>> perf record --call-graph dwarf -k 1 dart --generate-perf-jitdump >>>> test.dart >>>> perf inject -j -i perf.data -o perf.data.jitted >>>> >>>> If you now open perf.data.jitted with perf report you can see lots o= f >>>> errors regarding the missing program header. >>> >>> Do I need a debug build of dart or some extra dependency linked into >>> perf? I don't see any errors but I do see a load of addresses without >>> symbols: >>> >>> =C2=A0=C2=A0=C2=A0=C2=A0 13.27%=C2=A0=C2=A0=C2=A0=C2=A0 0.00%=C2=A0 = dart=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ld-2.31.so=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=C2=A0=C2=A0=C2=A0 | >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |--3.81%--0xf= fffffff85a7831a >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |--2.49%--0xf= fffffff85252e72 >>> >>> >>> >>>> >>>> Cheers, >>>> Lieven >>>> >>>> Am 25.08.22 um 15:51 schrieb James Clark: >>>>> >>>>> >>>>> On 25/08/2022 09:49, Lieven Hey wrote: >>>>>> The missing header makes it hard for programs like elfutils to ope= n >>>>>> these files. >>>>> >>>>> Hi Lieven, >>>>> >>>>> Do you have an example command that demonstrates this? I'm >>>>> interested in >>>>> trying it out. >>>>> >>>>> I was also only aware of the elf files put in ~/.debug after perf >>>>> record, but not perf inject. >>>>> >>>>> Thanks >>>>> James >>>>> >>>>>> --- >>>>>> =C2=A0=C2=A0 tools/perf/util/genelf.c | 14 ++++++++++++++ >>>>>> =C2=A0=C2=A0 tools/perf/util/genelf.h |=C2=A0 4 ++++ >>>>>> =C2=A0=C2=A0 2 files changed, 18 insertions(+) >>>>>> >>>>>> diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c >>>>>> index 953338b9e887..02cd9f75e3d2 100644 >>>>>> --- a/tools/perf/util/genelf.c >>>>>> +++ b/tools/perf/util/genelf.c >>>>>> @@ -251,6 +251,7 @@ jit_write_elf(int fd, uint64_t load_addr, cons= t >>>>>> char *sym, >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Elf_Data *d; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Elf_Scn *scn; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Elf_Ehdr *ehdr; >>>>>> +=C2=A0=C2=A0=C2=A0 Elf_Phdr *phdr; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Elf_Shdr *shdr; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 uint64_t eh_frame_base_offse= t; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 char *strsym =3D NULL; >>>>>> @@ -285,6 +286,19 @@ jit_write_elf(int fd, uint64_t load_addr, con= st >>>>>> char *sym, >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ehdr->e_version =3D EV_CURRE= NT; >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ehdr->e_shstrndx=3D unwindin= g ? 4 : 2; /* shdr index for section >>>>>> name */ >>>>>> =C2=A0=C2=A0 +=C2=A0=C2=A0=C2=A0 /* >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0 * setup program header >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>>>> +=C2=A0=C2=A0=C2=A0 phdr =3D elf_newphdr(e, 1); >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_type =3D PT_LOAD; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_offset =3D 0; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_vaddr =3D 0; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_paddr =3D 0; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_filesz =3D csize; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_memsz =3D csize; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_flags =3D PF_X | PF_R; >>>>>> +=C2=A0=C2=A0=C2=A0 phdr[0].p_align =3D 8; >>>>>> + >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * setup text section >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>>>> diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h >>>>>> index ae138afe6c56..b5c909546e3f 100644 >>>>>> --- a/tools/perf/util/genelf.h >>>>>> +++ b/tools/perf/util/genelf.h >>>>>> @@ -53,8 +53,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_ad= dr, >>>>>> void *debug, int nr_debug_ent >>>>>> =C2=A0=C2=A0 =C2=A0 #if GEN_ELF_CLASS =3D=3D ELFCLASS64 >>>>>> =C2=A0=C2=A0 #define elf_newehdr=C2=A0=C2=A0=C2=A0 elf64_newehdr >>>>>> +#define elf_newphdr=C2=A0=C2=A0=C2=A0 elf64_newphdr >>>>>> =C2=A0=C2=A0 #define elf_getshdr=C2=A0=C2=A0=C2=A0 elf64_getshdr >>>>>> =C2=A0=C2=A0 #define Elf_Ehdr=C2=A0=C2=A0=C2=A0 Elf64_Ehdr >>>>>> +#define Elf_Phdr=C2=A0=C2=A0=C2=A0 Elf64_Phdr >>>>>> =C2=A0=C2=A0 #define Elf_Shdr=C2=A0=C2=A0=C2=A0 Elf64_Shdr >>>>>> =C2=A0=C2=A0 #define Elf_Sym=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Elf64_Sym >>>>>> =C2=A0=C2=A0 #define ELF_ST_TYPE(a)=C2=A0=C2=A0=C2=A0 ELF64_ST_TY= PE(a) >>>>>> @@ -62,8 +64,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_ad= dr, >>>>>> void *debug, int nr_debug_ent >>>>>> =C2=A0=C2=A0 #define ELF_ST_VIS(a)=C2=A0=C2=A0=C2=A0 ELF64_ST_VIS= IBILITY(a) >>>>>> =C2=A0=C2=A0 #else >>>>>> =C2=A0=C2=A0 #define elf_newehdr=C2=A0=C2=A0=C2=A0 elf32_newehdr >>>>>> +#define elf_newphdr=C2=A0=C2=A0=C2=A0 elf32_newphdr >>>>>> =C2=A0=C2=A0 #define elf_getshdr=C2=A0=C2=A0=C2=A0 elf32_getshdr >>>>>> =C2=A0=C2=A0 #define Elf_Ehdr=C2=A0=C2=A0=C2=A0 Elf32_Ehdr >>>>>> +#define Elf_Phdr=C2=A0=C2=A0=C2=A0 Elf32_Phdr >>>>>> =C2=A0=C2=A0 #define Elf_Shdr=C2=A0=C2=A0=C2=A0 Elf32_Shdr >>>>>> =C2=A0=C2=A0 #define Elf_Sym=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Elf32_Sym >>>>>> =C2=A0=C2=A0 #define ELF_ST_TYPE(a)=C2=A0=C2=A0=C2=A0 ELF32_ST_TY= PE(a) >>>> >> --=20 Lieven Hey | lieven.hey@kdab.com | Software Developer KDAB (Deutschland) GmbH, a KDAB Group company Tel: +49-30-521325470 KDAB - The Qt, C++ and OpenGL Experts