Commit e57cfcda authored by Pekka Enberg's avatar Pekka Enberg Committed by Ingo Molnar

perf symbols: Fix ELF header errors during "perf kmem record"

The write_event() function in builtin-record.c writes out all
mmap()'d DSOs including non-ELF files like GNOME resource files
and such.

Therefore, check for ELF_K_ELF in filename__read_build_id()
before attempting to read the ELF header with gelf_getehdr().

Fixes the following error messages when running "perf kmem
record":

  penberg@penberg-laptop:~/src/linux/tools/perf$ perf kmem record
  ^C[ perf record: Woken up 2 times to write data ]
  [ perf record: Captured and wrote 0.753 MB perf.data (~32885 samples) ]
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
  filename__read_build_id: cannot get elf header.
Signed-off-by: default avatarPekka Enberg <penberg@cs.helsinki.fi>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1258885784-11709-1-git-send-email-penberg@cs.helsinki.fi>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent f3ced7cd
...@@ -921,6 +921,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) ...@@ -921,6 +921,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
GElf_Shdr shdr; GElf_Shdr shdr;
Elf_Data *data; Elf_Data *data;
Elf_Scn *sec; Elf_Scn *sec;
Elf_Kind ek;
void *ptr; void *ptr;
Elf *elf; Elf *elf;
...@@ -937,6 +938,10 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) ...@@ -937,6 +938,10 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
goto out_close; goto out_close;
} }
ek = elf_kind(elf);
if (ek != ELF_K_ELF)
goto out_elf_end;
if (gelf_getehdr(elf, &ehdr) == NULL) { if (gelf_getehdr(elf, &ehdr) == NULL) {
pr_err("%s: cannot get elf header.\n", __func__); pr_err("%s: cannot get elf header.\n", __func__);
goto out_elf_end; goto out_elf_end;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment