Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf inject: Fix GEN_ELF_TEXT_OFFSET for jit

When a program header was added, it moved the text section but
GEN_ELF_TEXT_OFFSET was not updated.

Fix by adding the program header size and aligning.

Fixes: babd04386b1df8c3 ("perf jit: Include program header in ELF files")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Lieven Hey <lieven.hey@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20221014170905.64069-7-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
89b15d00 973db240

+3 -1
+3 -1
tools/perf/util/genelf.h
··· 2 2 #ifndef __GENELF_H__ 3 3 #define __GENELF_H__ 4 4 5 + #include <linux/math.h> 6 + 5 7 /* genelf.c */ 6 8 int jit_write_elf(int fd, uint64_t code_addr, const char *sym, 7 9 const void *code, int csize, void *debug, int nr_debug_entries, ··· 78 76 #endif 79 77 80 78 /* The .text section is directly after the ELF header */ 81 - #define GEN_ELF_TEXT_OFFSET sizeof(Elf_Ehdr) 79 + #define GEN_ELF_TEXT_OFFSET round_up(sizeof(Elf_Ehdr) + sizeof(Elf_Phdr), 16) 82 80 83 81 #endif