perf jit: Include program header in elf files
PATCH v2 1/1 perf jit: Include program header in elf files
The missing header makes it hard for programs like elfutils to open these files.
Fixes 2d86612aacb7805f ("perf symbol: Correct address for bss symbols")
Signed-off-by Lieven Hey <[email protected]>
Reviewed-by Leo Yan <[email protected]>
Tested-by Leo Yan <[email protected]>
--- tools/perf/util/genelf.c | 14 ++++++++++++++ tools/perf/util/genelf.h | 4 ++++ 2 files changed, 18 insertions(+)
tools/perf/util/genelf.c +14 -0
@@ -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 */
tools/perf/util/genelf.h +4 -0
@@ -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)
Signature · 1 line
2.37.3
Em Thu, Sep 15, 2022 at 11:29:10AM +0200, Lieven Hey escreveu:
Quoted 7 lines
The missing header makes it hard for programs like elfutils to open these files.
Fixes 2d86612aacb7805f ("perf symbol: Correct address for bss symbols")Signed-off-by Lieven Hey <[email protected]>Reviewed-by Leo Yan <[email protected]>Tested-by Leo Yan <[email protected]>
Thanks, applied.
- Arnaldo
Quoted 65 lines
--- tools/perf/util/genelf.c | 14 ++++++++++++++ tools/perf/util/genelf.h | 4 ++++ 2 files changed, 18 insertions(+)tools/perf/util/genelf.c +14
-0@@ -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 */ tools/perf/util/genelf.h +4
-0@@ -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)Signature · 1 line
2.37.3
Signature · 1 line
- Arnaldo