Skip to content

Commit a3b923f

Browse files
lievenheygregkh
authored andcommitted
perf jit: Include program header in ELF files
[ Upstream commit babd043 ] The missing header makes it hard for programs like elfutils to open these files. Fixes: 2d86612 ("perf symbol: Correct address for bss symbols") Reviewed-by: Leo Yan <[email protected]> Signed-off-by: Lieven Hey <[email protected]> Tested-by: Leo Yan <[email protected]> Cc: Leo Yan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 39dc6cc commit a3b923f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tools/perf/util/genelf.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
251251
Elf_Data *d;
252252
Elf_Scn *scn;
253253
Elf_Ehdr *ehdr;
254+
Elf_Phdr *phdr;
254255
Elf_Shdr *shdr;
255256
uint64_t eh_frame_base_offset;
256257
char *strsym = NULL;
@@ -285,6 +286,19 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
285286
ehdr->e_version = EV_CURRENT;
286287
ehdr->e_shstrndx= unwinding ? 4 : 2; /* shdr index for section name */
287288

289+
/*
290+
* setup program header
291+
*/
292+
phdr = elf_newphdr(e, 1);
293+
phdr[0].p_type = PT_LOAD;
294+
phdr[0].p_offset = 0;
295+
phdr[0].p_vaddr = 0;
296+
phdr[0].p_paddr = 0;
297+
phdr[0].p_filesz = csize;
298+
phdr[0].p_memsz = csize;
299+
phdr[0].p_flags = PF_X | PF_R;
300+
phdr[0].p_align = 8;
301+
288302
/*
289303
* setup text section
290304
*/

tools/perf/util/genelf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent
5050

5151
#if GEN_ELF_CLASS == ELFCLASS64
5252
#define elf_newehdr elf64_newehdr
53+
#define elf_newphdr elf64_newphdr
5354
#define elf_getshdr elf64_getshdr
5455
#define Elf_Ehdr Elf64_Ehdr
56+
#define Elf_Phdr Elf64_Phdr
5557
#define Elf_Shdr Elf64_Shdr
5658
#define Elf_Sym Elf64_Sym
5759
#define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
5860
#define ELF_ST_BIND(a) ELF64_ST_BIND(a)
5961
#define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
6062
#else
6163
#define elf_newehdr elf32_newehdr
64+
#define elf_newphdr elf32_newphdr
6265
#define elf_getshdr elf32_getshdr
6366
#define Elf_Ehdr Elf32_Ehdr
67+
#define Elf_Phdr Elf32_Phdr
6468
#define Elf_Shdr Elf32_Shdr
6569
#define Elf_Sym Elf32_Sym
6670
#define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)

0 commit comments

Comments
 (0)