Skip to content

Commit babd043

Browse files
lievenheyacmel
authored andcommitted
perf jit: Include program header in ELF files
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]>
1 parent 7901086 commit babd043

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
@@ -253,6 +253,7 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
253253
Elf_Data *d;
254254
Elf_Scn *scn;
255255
Elf_Ehdr *ehdr;
256+
Elf_Phdr *phdr;
256257
Elf_Shdr *shdr;
257258
uint64_t eh_frame_base_offset;
258259
char *strsym = NULL;
@@ -287,6 +288,19 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
287288
ehdr->e_version = EV_CURRENT;
288289
ehdr->e_shstrndx= unwinding ? 4 : 2; /* shdr index for section name */
289290

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

tools/perf/util/genelf.h

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

5454
#if GEN_ELF_CLASS == ELFCLASS64
5555
#define elf_newehdr elf64_newehdr
56+
#define elf_newphdr elf64_newphdr
5657
#define elf_getshdr elf64_getshdr
5758
#define Elf_Ehdr Elf64_Ehdr
59+
#define Elf_Phdr Elf64_Phdr
5860
#define Elf_Shdr Elf64_Shdr
5961
#define Elf_Sym Elf64_Sym
6062
#define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
6163
#define ELF_ST_BIND(a) ELF64_ST_BIND(a)
6264
#define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
6365
#else
6466
#define elf_newehdr elf32_newehdr
67+
#define elf_newphdr elf32_newphdr
6568
#define elf_getshdr elf32_getshdr
6669
#define Elf_Ehdr Elf32_Ehdr
70+
#define Elf_Phdr Elf32_Phdr
6771
#define Elf_Shdr Elf32_Shdr
6872
#define Elf_Sym Elf32_Sym
6973
#define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)

0 commit comments

Comments
 (0)