From: Lieven Hey <lieven.hey@kdab.com>
To: James Clark <james.clark@arm.com>, leo.yan@linaro.org
Cc: linux-perf-users@vger.kernel.org, acme@kernel.org
Subject: Re: [PATCH] include program header in elf files generated by perf inject
Date: Tue, 13 Sep 2022 15:34:18 +0200 [thread overview]
Message-ID: <1b701f63-4f78-dbc8-cac4-bfbf7be84134@kdab.com> (raw)
In-Reply-To: <cf2f3f27-1002-dbd0-d851-465b169c2031@arm.com>
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.dart
perf inject -j -i perf.data -o perf.data.jitted
The problem exists since 2d86612aacb78. The commit added some code that
now requires an elf file to have a valid program header.
Cheers
Lieven
Am 13.09.22 um 11:56 schrieb James Clark:
>
>
> 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.
>>
>
> 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.
>
> Thanks
>
>> 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() {
>>>> 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 of
>>>> 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:
>>>
>>> 13.27% 0.00% dart ld-2.31.so [.] dl_main
>>> |
>>> ---dl_main
>>> |
>>> |--11.82%--_dl_relocate_object
>>> | |
>>> | |--9.56%--0xffffffff85c01284
>>> | | 0xffffffff8507b04c
>>> | | 0xffffffff8507afe8
>>> | | 0xffffffff8507aa59
>>> | | 0xffffffff85253dda
>>> | | 0xffffffff85253a35
>>> | | |
>>> | | |--3.81%--0xffffffff85a7831a
>>> | | |
>>> | | |--2.49%--0xffffffff85252e72
>>>
>>>
>>>
>>>>
>>>> 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 open
>>>>>> 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
>>>>>
>>>>>> ---
>>>>>> tools/perf/util/genelf.c | 14 ++++++++++++++
>>>>>> tools/perf/util/genelf.h | 4 ++++
>>>>>> 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, const
>>>>>> char *sym,
>>>>>> Elf_Data *d;
>>>>>> Elf_Scn *scn;
>>>>>> Elf_Ehdr *ehdr;
>>>>>> + Elf_Phdr *phdr;
>>>>>> Elf_Shdr *shdr;
>>>>>> uint64_t eh_frame_base_offset;
>>>>>> char *strsym = NULL;
>>>>>> @@ -285,6 +286,19 @@ jit_write_elf(int fd, uint64_t load_addr, const
>>>>>> char *sym,
>>>>>> ehdr->e_version = EV_CURRENT;
>>>>>> ehdr->e_shstrndx= unwinding ? 4 : 2; /* shdr index for section
>>>>>> name */
>>>>>> + /*
>>>>>> + * setup program header
>>>>>> + */
>>>>>> + phdr = elf_newphdr(e, 1);
>>>>>> + phdr[0].p_type = PT_LOAD;
>>>>>> + phdr[0].p_offset = 0;
>>>>>> + phdr[0].p_vaddr = 0;
>>>>>> + phdr[0].p_paddr = 0;
>>>>>> + phdr[0].p_filesz = csize;
>>>>>> + phdr[0].p_memsz = csize;
>>>>>> + phdr[0].p_flags = PF_X | PF_R;
>>>>>> + phdr[0].p_align = 8;
>>>>>> +
>>>>>> /*
>>>>>> * setup text section
>>>>>> */
>>>>>> 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_addr,
>>>>>> void *debug, int nr_debug_ent
>>>>>> #if GEN_ELF_CLASS == ELFCLASS64
>>>>>> #define elf_newehdr elf64_newehdr
>>>>>> +#define elf_newphdr elf64_newphdr
>>>>>> #define elf_getshdr elf64_getshdr
>>>>>> #define Elf_Ehdr Elf64_Ehdr
>>>>>> +#define Elf_Phdr Elf64_Phdr
>>>>>> #define Elf_Shdr Elf64_Shdr
>>>>>> #define Elf_Sym Elf64_Sym
>>>>>> #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
>>>>>> @@ -62,8 +64,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr,
>>>>>> void *debug, int nr_debug_ent
>>>>>> #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
>>>>>> #else
>>>>>> #define elf_newehdr elf32_newehdr
>>>>>> +#define elf_newphdr elf32_newphdr
>>>>>> #define elf_getshdr elf32_getshdr
>>>>>> #define Elf_Ehdr Elf32_Ehdr
>>>>>> +#define Elf_Phdr Elf32_Phdr
>>>>>> #define Elf_Shdr Elf32_Shdr
>>>>>> #define Elf_Sym Elf32_Sym
>>>>>> #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
>>>>
>>
--
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
next prev parent reply other threads:[~2022-09-13 13:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-25 8:49 [PATCH] include program header in elf files generated by perf inject Lieven Hey
2022-08-25 13:51 ` James Clark
[not found] ` <6e0ebfb6-9fbf-073c-94b0-a799b9ec657f@kdab.com>
[not found] ` <e3c57763-eb3d-e8cc-c3b7-36a33e86ad6a@arm.com>
[not found] ` <1cc13a5d-bb41-edbb-ade7-62d4a678c0f9@kdab.com>
[not found] ` <cf2f3f27-1002-dbd0-d851-465b169c2031@arm.com>
2022-09-13 13:34 ` Lieven Hey [this message]
2022-09-13 13:49 ` Leo Yan
2022-09-13 14:34 ` Lieven Hey
2022-09-14 13:52 ` Leo Yan
2022-09-15 8:17 ` Lieven Hey
2022-09-15 8:35 ` Leo Yan
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=1b701f63-4f78-dbc8-cac4-bfbf7be84134@kdab.com \
--to=lieven.hey@kdab.com \
--cc=acme@kernel.org \
--cc=james.clark@arm.com \
--cc=leo.yan@linaro.org \
--cc=linux-perf-users@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).