Re: [PATCH 1/3] perf genelf: Set ELF program header addresses properly

From: Ian Rogers
Date: Tue Dec 12 2023 - 13:08:16 EST


On Mon, Dec 11, 2023 at 11:05 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> The text section starts after the ELF headers so PHDR.p_vaddr and
> others should have the correct addresses.
>
> Fixes: babd04386b1d ("perf jit: Include program header in ELF files")
> Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks,
Ian

> ---
> tools/perf/util/genelf.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
> index fefc72066c4e..ac17a3cb59dc 100644
> --- a/tools/perf/util/genelf.c
> +++ b/tools/perf/util/genelf.c
> @@ -293,9 +293,9 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
> */
> 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_offset = GEN_ELF_TEXT_OFFSET;
> + phdr[0].p_vaddr = GEN_ELF_TEXT_OFFSET;
> + phdr[0].p_paddr = GEN_ELF_TEXT_OFFSET;
> phdr[0].p_filesz = csize;
> phdr[0].p_memsz = csize;
> phdr[0].p_flags = PF_X | PF_R;
> --
> 2.43.0.472.g3155946c3a-goog
>