perf: Refactor/add fallbacks for reading build-id and debuglink
Ian Rogers
reviewerv2 cover perf: Refactor/add fallbacks for reading build-id and debuglink
This cleans up some tech debt mentioned in the thread:
https://lore.kernel.org/lkml/[email protected]/
The perf tool has fallbacks for objdump but not in the case of build-id and debuglink reading. Refactor the code so that in the case of read_build_id it now looks like:
```
...
int filename__read_build_id(const char *filename, struct build_id *bid)
{
struct kmod_path m = { .name = NULL, };
char path[PATH_MAX];
int err, fd;
if (!filename)
return -EFAULT;
if (!is_regular_file(filename))
return -EWOULDBLOCK;
err = kmod_path__parse(&m, filename);
if (err)
return -1;
if (m.comp) {
int error = 0;
fd = filename__decompress(filename, path, sizeof(path), m.comp, &error);
if (fd < 0) {
pr_debug("Failed to decompress (error %d) %s\n",
error, filename);
return -1;
}
lseek(fd, 0, SEEK_SET);
filename = path;
} else {
fd = open(filename, O_RDONLY);
if (fd < 0) {
pr_debug("Failed to open %s\n", filename);
return -1;
}
}
err = libbfd__read_build_id(fd, filename, bid);
if (err == 0)
goto out;
err = libelf__read_build_id(fd, filename, bid);
if (err == 0)
goto out;
err = sym_min__read_build_id(fd, filename, bid);
out:
close(fd);
if (m.comp)
unlink(filename);
return err;
}
...
```That is what was previously symbol-elf decompression code is now made common for all cases of reading. The handling of "is_regular_file" is now common. There is a clear fallback from libbfd to libelf to the symbol-minimal (sym_min) versions of the functions.
To support this there is refactoring of code into a perf-libelf.c file, to follow patterns established for the capstone, LLVM and libbfd code.
v2: Rebase, resolving merge conflict with James' removal of the block
argument:
https://lore.kernel.org/lkml/[email protected]/
Add a patch fixing an issue with return values from filename__read_build_id. Some tweaks to the PPC arch__sym_update patch commit message and make it 64-bit only. Change the sysfs__read_build_id code combining the libelf and minimal implementations but avoiding the memory read overhead, avoiding a potential buffer overrun if the descsz was particularly large in a build ID note, avoid reads and just using seeks.
v1: https://lore.kernel.org/lkml/[email protected]/
Ian Rogers (10):
perf symbol: Reduce scope of elf__needs_adjust_symbols perf symbol: Reduce scope of arch__sym_update perf symbol: Move libelf code to its own file/header perf symbol: Remove unused includes
perf symbol: Move dso__load_bfd_symbols out of symbol.h perf symbol: Use fallbacks with filename__read_build_id perf symbol: Use fallbacks for filename__read_debuglink perf symbol: Make a common sysfs__read_build_id perf dso: Move type helpers out of symbol and use fallbacks perf symbol: Fix ENOENT case for filename__read_build_id
tools/perf/arch/powerpc/util/sym-handling.c | 7 - tools/perf/builtin-annotate.c | 47 +-- tools/perf/builtin-buildid-cache.c | 6 +- tools/perf/builtin-c2c.c | 58 +-- tools/perf/builtin-diff.c | 22 +- tools/perf/builtin-inject.c | 19 +- tools/perf/builtin-kmem.c | 41 ++- tools/perf/builtin-kwork.c | 9 +- tools/perf/builtin-mem.c | 16 +- tools/perf/builtin-report.c | 76 ++-- tools/perf/builtin-sched.c | 50 ++- tools/perf/builtin-script.c | 89 ++--- tools/perf/builtin-timechart.c | 34 +- tools/perf/builtin-top.c | 85 +++-- tools/perf/builtin-trace.c | 82 ++--- .../scripts/python/Perf-Trace-Util/Context.c | 11 +- tools/perf/tests/code-reading.c | 1 + tools/perf/tests/hists_cumulate.c | 1 + tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_link.c | 1 + tools/perf/tests/hists_output.c | 1 + tools/perf/tests/mmap-thread-lookup.c | 1 + tools/perf/tests/pe-file-parsing.c | 5 +- tools/perf/util/Build | 6 +- tools/perf/util/annotate-data.c | 7 +- tools/perf/util/auxtrace.h | 1 + tools/perf/util/block-info.c | 11 +- tools/perf/util/build-id.c | 28 +- tools/perf/util/callchain.c | 1 + tools/perf/util/cs-etm.c | 1 + tools/perf/util/data-convert-json.c | 30 +- tools/perf/util/db-export.c | 16 +- tools/perf/util/dlfilter.c | 11 +- tools/perf/util/dlfilter.h | 1 + tools/perf/util/dso.c | 57 +-- tools/perf/util/event.c | 41 ++- tools/perf/util/evsel_fprintf.c | 14 +- tools/perf/util/hist.c | 29 +- tools/perf/util/intel-pt.c | 35 +- tools/perf/util/kvm-stat.h | 5 +- tools/perf/util/libbfd.c | 9 +- tools/perf/util/libbfd.h | 12 +- tools/perf/util/machine.c | 34 +- tools/perf/util/perf-libelf.c | 235 ++++++++++++ tools/perf/util/perf-libelf.h | 58 +++ tools/perf/util/print_insn.c | 14 +- tools/perf/util/probe-event.c | 1 + tools/perf/util/probe-finder.c | 1 + .../util/scripting-engines/trace-event-perl.c | 1 + .../scripting-engines/trace-event-python.c | 1 + tools/perf/util/symbol-elf.c | 338 +----------------- tools/perf/util/symbol-minimal.c | 166 +++++---- tools/perf/util/symbol-minimal.h | 13 + tools/perf/util/symbol.c | 107 +++++- tools/perf/util/symbol.h | 44 +-- tools/perf/util/symbol_fprintf.c | 1 + tools/perf/util/thread-stack.c | 12 +- tools/perf/util/thread.c | 18 +- tools/perf/util/unwind-libdw.c | 15 +- 59 files changed, 1079 insertions(+), 958 deletions(-) create mode 100644 tools/perf/util/perf-libelf.c create mode 100644 tools/perf/util/perf-libelf.h create mode 100644 tools/perf/util/symbol-minimal.h
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 1/10 perf symbol: Reduce scope of elf__needs_adjust_symbols
Function is only used by symsrc__init in symbol-elf.c, make static to reduce scope. Switch to not passing the argument by value but as a pointer.
--- tools/perf/util/symbol-elf.c | 8 ++++---- tools/perf/util/symbol.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/util/symbol-elf.c +4 -4
@@ -1052,15 +1052,15 @@ void symsrc__destroy(struct symsrc *ss)close (ss->fd); } -bool elf__needs_adjust_symbols (GElf_Ehdr ehdr) +static bool elf__needs_adjust_symbols (const GElf_Ehdr *ehdr) {/* * Usually vmlinux is an ELF file with type ET_EXEC for most * architectures; except Arm64 kernel is linked with option * '-share', so need to check type ET_DYN. */ -return ehdr.e_type ==ET_EXEC || ehdr.e_type ==ET_REL || - ehdr.e_type ==ET_DYN ; +return ehdr->e_type ==ET_EXEC || ehdr->e_type ==ET_REL || + ehdr->e_type ==ET_DYN ; }static Elf *read_gnu_debugdata (struct dso *dso,Elf *elf,const char *name,int *fd_ret)
@@ -1233,7 +1233,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,if (dso__kernel (dso) ==DSO_SPACE__USER ) ss->adjust_symbols = true;else - ss->adjust_symbols =elf__needs_adjust_symbols (ehdr); + ss->adjust_symbols =elf__needs_adjust_symbols (&ehdr); ss->name =strdup (name);if (!ss->name) {
tools/perf/util/symbol.h +0 -1
@@ -217,7 +217,6 @@ int setup_intlist(struct intlist **list, const char *list_str, const char *list_name);#ifdef HAVE_LIBELF_SUPPORT -bool elf__needs_adjust_symbols (GElf_Ehdr ehdr);void arch__sym_update (struct symbol *s,GElf_Sym *sym);#endif
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 2/10 perf symbol: Reduce scope of arch__sym_update
In reply to Ian RogersRather than being a weak arch function, use the e_machine from the ELF header to determine whether to update or not. This should make the function work cross-platform, it also reduces the function's scope.
Note, the previous PPC code would compile both for 32 and 64-bit and when _CALL_ELF==2. Similar testing could be done using the ELF file's e_machine for PPC32 and e_flags for not EF_PPC_EMB. It can also be done on the symbol for a non-zero st_other. Given we're just copying the value, which would otherwise be 0, there's no need to introduce a st_other != 0 test. The value is only used in arch__fix_tev_from_maps on PowerPC in the PPC64_LOCAL_ENTRY_OFFSET macro, where 64-bit is assumed.
--- tools/perf/arch/powerpc/util/sym-handling.c | 7 ------- tools/perf/util/symbol-elf.c | 9 ++++++--- tools/perf/util/symbol.h | 4 ---- 3 files changed, 6 insertions(+), 14 deletions(-)
tools/perf/arch/powerpc/util/sym-handling.c +0 -7
@@ -66,13 +66,6 @@ const char *arch__normalize_symbol_name(const char *name)#if defined(_CALL_ELF) && _CALL_ELF ==2 -#ifdef HAVE_LIBELF_SUPPORT -void arch__sym_update (struct symbol *s,GElf_Sym *sym) -{ - s->arch_sym = sym->st_other; -} -#endif -#define PPC64LE_LEP_OFFSET 8 void arch__fix_tev_from_maps(struct perf_probe_event *pev,
tools/perf/util/symbol-elf.c +6 -3
@@ -1338,8 +1338,11 @@ static u64 ref_reloc(struct kmap *kmap)return 0 ; } -void __weak arch__sym_update (struct symbol *s__maybe_unused , -GElf_Sym *sym__maybe_unused ) { } +static void arch__sym_update (int e_machine,const GElf_Sym *sym,struct symbol *s) +{ +if (e_machine ==EM_PPC64 ) + s->arch_sym = sym->st_other; +} static int dso__process_kernel_symbol(struct dso *dso, struct map *map, GElf_Sym *sym, GElf_Shdr *shdr,
@@ -1718,7 +1721,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,if (!f) goto out_elf_end; -arch__sym_update (f, &sym); +arch__sym_update (ehdr.e_machine, &sym, f);__symbols__insert (dso__symbols (curr_dso), f,dso__kernel (dso)); nr++;
tools/perf/util/symbol.h +0 -4
@@ -216,10 +216,6 @@ int setup_list(struct strlist **list, const char *list_str,int setup_intlist (struct intlist **list,const char *list_str,const char *list_name); -#ifdef HAVE_LIBELF_SUPPORT -void arch__sym_update (struct symbol *s,GElf_Sym *sym); -#endif -const char *arch__normalize_symbol_name (const char *name);#define SYMBOL_A 0#define SYMBOL_B 1
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 3/10 perf symbol: Move libelf code to its own file/header
In reply to Ian RogersMove perf declarations depending on libelf out of symbol.h into perf-libelf.h. Move the corresponding C code into perf-libelf.c. This is motivated by trying to make it clearer the symbol.[ch] is generic code without library dependencies.
--- tools/perf/util/Build | 1 + tools/perf/util/perf-libelf.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 25 +++++++++++++++++++++++++ tools/perf/util/probe-event.c | 1 + tools/perf/util/probe-finder.c | 1 + tools/perf/util/symbol-elf.c | 27 +-------------------------- tools/perf/util/symbol.h | 19 ------------------- 7 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 tools/perf/util/perf-libelf.c create mode 100644 tools/perf/util/perf-libelf.h
tools/perf/util/Build +1 -0
@@ -193,6 +193,7 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-util-$(CONFIG_PERF_BPF_SKEL) += bpf_kwork_top.o endif +perf-util-$(CONFIG_LIBELF) += perf-libelf.o perf-util-$(CONFIG_LIBELF) += symbol-elf.o perf-util-$(CONFIG_LIBELF) += probe-file.o perf-util-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/perf-libelf.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "perf-libelf.h" + +#include <stddef.h> +#include <string.h> + +Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep, +GElf_Shdr *shp,const char *name,size_t *idx) +{ +Elf_Scn *sec =NULL ; +size_t cnt =1 ; + +/* ELF is corrupted/truncated, avoid calling elf_strptr. */ +if (!elf_rawdata (elf_getscn (elf, ep->e_shstrndx),NULL )) +return NULL ; + +while ((sec =elf_nextscn (elf, sec)) !=NULL ) { +char *str; + +gelf_getshdr (sec, shp); + str =elf_strptr (elf, ep->e_shstrndx, shp->sh_name); +if (str && !strcmp (name, str)) { +if (idx) + *idx = cnt; +return sec; + } + ++cnt; + } + +return NULL ; +} +
tools/perf/util/perf-libelf.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_LIBELF_H +#define __PERF_LIBELF_H + +#ifdef HAVE_LIBELF_SUPPORT + +#include <libelf.h> +#include <gelf.h> + +/* +* libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; +* for newer versions we can use mmap to reduce memory usage: +*/ +#ifdef ELF_C_READ_MMAP +# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP +#else +# define PERF_ELF_C_READ_MMAP ELF_C_READ +#endif + +Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep,GElf_Shdr *shp,const char *name, +size_t *idx); + +#endif // defined(HAVE_LIBELF_SUPPORT) + +#endif /* __PERF_LIBELF_H */
tools/perf/util/probe-event.c +1 -0
@@ -23,6 +23,7 @@#include "build-id.h" #include "event.h" #include "namespaces.h" +#include "perf-libelf.h" #include "strlist.h" #include "strfilter.h" #include "debug.h"
tools/perf/util/probe-finder.c +1 -0
@@ -25,6 +25,7 @@#include "debug.h" #include "debuginfo.h" #include "intlist.h" +#include "perf-libelf.h" #include "strbuf.h" #include "strlist.h" #include "symbol.h"
tools/perf/util/symbol-elf.c +1 -26
@@ -12,6 +12,7 @@#include "libbfd.h" #include "map.h" #include "maps.h" +#include "perf-libelf.h" #include "symbol.h" #include "symsrc.h" #include "machine.h"
@@ -183,32 +184,6 @@ static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)return -1 ; } -Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep, -GElf_Shdr *shp,const char *name,size_t *idx) -{ -Elf_Scn *sec =NULL ; -size_t cnt =1 ; - -/* ELF is corrupted/truncated, avoid calling elf_strptr. */ -if (!elf_rawdata (elf_getscn (elf, ep->e_shstrndx),NULL )) -return NULL ; - -while ((sec =elf_nextscn (elf, sec)) !=NULL ) { -char *str; - -gelf_getshdr (sec, shp); - str =elf_strptr (elf, ep->e_shstrndx, shp->sh_name); -if (str && !strcmp (name, str)) { -if (idx) - *idx = cnt; -return sec; - } - ++cnt; - } - -return NULL ; -} -bool filename__has_section (const char *filename,const char *sec) {int fd;
tools/perf/util/symbol.h +0 -19
@@ -14,10 +14,6 @@#include "symbol_conf.h" #include "spark.h" -#ifdef HAVE_LIBELF_SUPPORT -#include <libelf.h> -#include <gelf.h> -#endif #include <elf.h> struct dso ;
@@ -26,21 +22,6 @@ struct maps;struct option ;struct build_id ; -/* -* libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; -* for newer versions we can use mmap to reduce memory usage: -*/ -#ifdef ELF_C_READ_MMAP -# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP -#else -# define PERF_ELF_C_READ_MMAP ELF_C_READ -#endif - -#ifdef HAVE_LIBELF_SUPPORT -Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep, -GElf_Shdr *shp,const char *name,size_t *idx); -#endif -/** * A symtab entry. When allocated this may be preceded by an annotation (see * symbol__annotation) and/or a browser_index (see symbol__browser_index).
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 4/10 perf symbol: Remove unused includes
In reply to Ian RogersRemove the includes of addr_location.h, spark.h, <elf.h>, <linux/refcount.h> and <stdint.h> as they're not used in the file. This caused an issue particularly with addr_location.h where there were lots of transitive dependencies. Resolve those by adding the include to the C file.
When adding the necessary includes, sort the includes and fix any other transitive dependency issues. Also, fix paths to files in util, erroneously in ../, etc.
--- tools/perf/builtin-annotate.c | 47 +++++----- tools/perf/builtin-c2c.c | 58 ++++++------ tools/perf/builtin-diff.c | 22 ++--- tools/perf/builtin-inject.c | 19 ++-- tools/perf/builtin-kmem.c | 41 +++++---- tools/perf/builtin-kwork.c | 9 +- tools/perf/builtin-mem.c | 16 ++-- tools/perf/builtin-report.c | 76 ++++++++-------- tools/perf/builtin-sched.c | 50 +++++------ tools/perf/builtin-script.c | 89 ++++++++++--------- tools/perf/builtin-timechart.c | 34 +++---- tools/perf/builtin-top.c | 85 +++++++++--------- tools/perf/builtin-trace.c | 82 ++++++++--------- .../scripts/python/Perf-Trace-Util/Context.c | 11 +-- tools/perf/tests/code-reading.c | 1 + tools/perf/tests/hists_cumulate.c | 1 + tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_link.c | 1 + tools/perf/tests/hists_output.c | 1 + tools/perf/tests/mmap-thread-lookup.c | 1 + tools/perf/util/annotate-data.c | 7 +- tools/perf/util/auxtrace.h | 1 + tools/perf/util/block-info.c | 11 +-- tools/perf/util/build-id.c | 28 +++--- tools/perf/util/callchain.c | 1 + tools/perf/util/cs-etm.c | 1 + tools/perf/util/data-convert-json.c | 30 ++++--- tools/perf/util/db-export.c | 16 ++-- tools/perf/util/dlfilter.c | 11 +-- tools/perf/util/dlfilter.h | 1 + tools/perf/util/event.c | 41 +++++---- tools/perf/util/evsel_fprintf.c | 14 +-- tools/perf/util/hist.c | 29 +++--- tools/perf/util/intel-pt.c | 35 ++++---- tools/perf/util/kvm-stat.h | 5 +- tools/perf/util/machine.c | 34 +++---- tools/perf/util/print_insn.c | 14 +-- .../util/scripting-engines/trace-event-perl.c | 1 + .../scripting-engines/trace-event-python.c | 1 + tools/perf/util/symbol.h | 14 ++- tools/perf/util/symbol_fprintf.c | 1 + tools/perf/util/thread-stack.c | 12 +-- tools/perf/util/thread.c | 18 ++-- tools/perf/util/unwind-libdw.c | 15 ++-- 44 files changed, 518 insertions(+), 468 deletions(-)
tools/perf/builtin-annotate.c +24 -23
@@ -6,45 +6,46 @@* look up and read DSOs and symbol information and display * a histogram of results, along various sorting keys. */ + +#include <dlfcn.h> +#include <errno.h> +#include <inttypes.h> +#include "builtin.h" #include "perf.h" -#include "util/color.h" -#include <linux/list.h> +#include "arch/common.h" +#include "ui/progress.h" +#include "util/addr_location.h" +#include "util/annotate-data.h" +#include "util/annotate.h" +#include "util/block-range.h" +#include "util/branch.h" #include "util/cache.h" -#include <linux/rbtree.h> -#include <linux/zalloc.h> -#include "util/symbol.h" - +#include "util/color.h" +#include "util/data.h" #include "util/debug.h" - +#include "util/dso.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" -#include "util/annotate.h" -#include "util/annotate-data.h" -#include "util/event.h" -#include <subcmd/parse-options.h> -#include "util/parse-events.h" -#include "util/sort.h" #include "util/hist.h" -#include "util/dso.h" #include "util/machine.h" #include "util/map.h" +#include "util/map_symbol.h" +#include "util/parse-events.h" #include "util/session.h" +#include "util/sort.h" +#include "util/symbol.h" #include "util/tool.h" -#include "util/data.h" -#include "arch/common.h" -#include "util/block-range.h" -#include "util/map_symbol.h" -#include "util/branch.h" #include "util/util.h" -#include "ui/progress.h" -#include <dlfcn.h> -#include <errno.h> #include <linux/bitmap.h> #include <linux/err.h> -#include <inttypes.h> +#include <linux/list.h> +#include <linux/rbtree.h> +#include <linux/zalloc.h> +#include <subcmd/parse-options.h> struct perf_annotate {struct perf_tool tool;
tools/perf/builtin-c2c.c +31 -27
72 lines not on this page · raw message
tools/perf/builtin-diff.c +12 -10
@@ -8,25 +8,27 @@#include "builtin.h" #include "perf.h" +#include "util/addr_location.h" +#include "util/annotate.h" +#include "util/block-info.h" +#include "util/config.h" +#include "util/data.h" #include "util/debug.h" #include "util/event.h" -#include "util/hist.h" -#include "util/evsel.h" #include "util/evlist.h" +#include "util/evsel.h" +#include "util/hist.h" +#include "util/map.h" #include "util/session.h" -#include "util/tool.h" #include "util/sort.h" +#include "util/spark.h" #include "util/srcline.h" +#include "util/stream.h" #include "util/symbol.h" -#include "util/data.h" -#include "util/config.h" #include "util/time-utils.h" -#include "util/annotate.h" -#include "util/map.h" -#include "util/spark.h" -#include "util/block-info.h" -#include "util/stream.h" +#include "util/tool.h" #include "util/util.h" +#include <linux/err.h> #include <linux/zalloc.h> #include <subcmd/pager.h>
tools/perf/builtin-inject.c +10 -9
@@ -8,26 +8,27 @@*/ #include "builtin.h" +#include "util/addr_location.h" +#include "util/auxtrace.h" +#include "util/build-id.h" #include "util/color.h" +#include "util/data.h" +#include "util/debug.h" #include "util/dso.h" -#include "util/vdso.h" #include "util/evlist.h" #include "util/evsel.h" +#include "util/jit.h" #include "util/map.h" +#include "util/namespaces.h" #include "util/session.h" -#include "util/tool.h" -#include "util/debug.h" -#include "util/build-id.h" -#include "util/data.h" -#include "util/auxtrace.h" -#include "util/jit.h" #include "util/string2.h" #include "util/symbol.h" #include "util/synthetic-events.h" #include "util/thread.h" -#include "util/namespaces.h" -#include "util/util.h" +#include "util/tool.h" #include "util/tsc.h" +#include "util/util.h" +#include "util/vdso.h" #include <internal/lib.h>
tools/perf/builtin-kmem.c +20 -21
62 lines not on this page · raw message
tools/perf/builtin-kwork.c +5 -4
@@ -8,18 +8,19 @@#include "builtin.h" #include "perf.h" +#include "util/addr_location.h" +#include "util/callchain.h" #include "util/data.h" +#include "util/debug.h" #include "util/evlist.h" #include "util/evsel.h" +#include "util/evsel_fprintf.h" #include "util/header.h" #include "util/kwork.h" -#include "util/debug.h" #include "util/session.h" +#include "util/string2.h" #include "util/symbol.h" #include "util/thread.h" -#include "util/string2.h" -#include "util/callchain.h" -#include "util/evsel_fprintf.h" #include "util/util.h" #include <subcmd/pager.h>
tools/perf/builtin-mem.c +9 -7
@@ -7,24 +7,26 @@#include "builtin.h" #include "perf.h" -#include <subcmd/parse-options.h> +#include "util/addr_location.h" #include "util/auxtrace.h" -#include "util/trace-event.h" -#include "util/tool.h" -#include "util/session.h" #include "util/data.h" -#include "util/map_symbol.h" -#include "util/mem-events.h" #include "util/debug.h" #include "util/dso.h" #include "util/map.h" -#include "util/symbol.h" +#include "util/map_symbol.h" +#include "util/mem-events.h" #include "util/pmus.h" #include "util/sample.h" +#include "util/session.h" #include "util/sort.h" #include "util/string2.h" +#include "util/symbol.h" +#include "util/tool.h" +#include "util/trace-event.h" #include "util/util.h" +#include <linux/err.h> +#include <subcmd/parse-options.h> #define MEM_OPERATION_LOAD 0x1#define MEM_OPERATION_STORE 0x2
tools/perf/builtin-report.c +37 -39
105 lines not on this page · raw message
tools/perf/builtin-sched.c +24 -26
75 lines not on this page · raw message
tools/perf/builtin-script.c +46 -43
119 lines not on this page · raw message
tools/perf/builtin-timechart.c +18 -16
@@ -12,33 +12,35 @@#include <inttypes.h> #include "builtin.h" + +#include "util/addr_location.h" +#include "util/callchain.h" #include "util/color.h" -#include <linux/list.h> +#include "util/data.h" +#include "util/debug.h" +#include "util/event.h" #include "util/evlist.h" // for struct evsel_str_handler #include "util/evsel.h" -#include <linux/kernel.h> -#include <linux/rbtree.h> -#include <linux/time64.h> -#include <linux/zalloc.h> -#include "util/symbol.h" -#include "util/thread.h" -#include "util/callchain.h" -#include "util/header.h" -#include <subcmd/pager.h> -#include <subcmd/parse-options.h> #include "util/parse-events.h" -#include "util/event.h" #include "util/session.h" +#include "util/string2.h" #include "util/svghelper.h" +#include "util/symbol.h" +#include "util/thread.h" #include "util/tool.h" -#include "util/data.h" -#include "util/debug.h" -#include "util/string2.h" #include "util/tracepoint.h" #include "util/util.h" -#include <linux/err.h> +#include <event-parse.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/rbtree.h> +#include <linux/time64.h> +#include <linux/zalloc.h> +#include <subcmd/pager.h> +#include <subcmd/parse-options.h> #ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE FILE *open_memstream (char **ptr,size_t *sizeloc);
tools/perf/builtin-top.c +40 -45
117 lines not on this page · raw message
tools/perf/builtin-trace.c +42 -40
119 lines not on this page · raw message
tools/perf/scripts/python/Perf-Trace-Util/Context.c +6 -5
@@ -12,17 +12,18 @@#define PY_SSIZE_T_CLEAN #include <Python.h> +#include "../../../util/addr_location.h" +#include "../../../util/auxtrace.h" #include "../../../util/config.h" -#include "../../../util/trace-event.h" #include "../../../util/event.h" -#include "../../../util/symbol.h" -#include "../../../util/thread.h" #include "../../../util/map.h" #include "../../../util/maps.h" -#include "../../../util/auxtrace.h" #include "../../../util/session.h" -#include "../../../util/srcline.h" #include "../../../util/srccode.h" +#include "../../../util/srcline.h" +#include "../../../util/symbol.h" +#include "../../../util/thread.h" +#include "../../../util/trace-event.h" #define _PyCapsule_GetPointer (arg1, arg2) \ PyCapsule_GetPointer((arg1), (arg2))
tools/perf/tests/code-reading.c +1 -0
@@ -15,6 +15,7 @@#include <perf/evlist.h> #include <perf/mmap.h> +#include "addr_location.h" #include "debug.h" #include "dso.h" #include "env.h"
tools/perf/tests/hists_cumulate.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include "util/addr_location.h" #include "util/debug.h" #include "util/dso.h" #include "util/event.h"
tools/perf/tests/hists_filter.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include "util/addr_location.h" #include "util/debug.h" #include "util/map.h" #include "util/symbol.h"
tools/perf/tests/hists_link.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include "tests.h" +#include "addr_location.h" #include "debug.h" #include "symbol.h" #include "sort.h"
tools/perf/tests/hists_output.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include "util/addr_location.h" #include "util/debug.h" #include "util/dso.h" #include "util/event.h"
tools/perf/tests/mmap-thread-lookup.c +1 -0
@@ -7,6 +7,7 @@#include <pthread.h> #include <stdlib.h> #include <stdio.h> +#include "addr_location.h" #include "debug.h" #include "env.h" #include "event.h"
tools/perf/util/annotate-data.c +4 -3
@@ -10,14 +10,15 @@#include <inttypes.h> #include <linux/zalloc.h> -#include "annotate.h" +#include "addr_location.h" #include "annotate-data.h" -#include "debuginfo.h" +#include "annotate.h" #include "debug.h" +#include "debuginfo.h" #include "dso.h" #include "dwarf-regs.h" -#include "evsel.h" #include "evlist.h" +#include "evsel.h" #include "map.h" #include "map_symbol.h" #include "sort.h"
tools/perf/util/auxtrace.h +1 -0
@@ -8,6 +8,7 @@#define __PERF_AUXTRACE_H#include <stdio.h> // FILE +#include <unistd.h> // pid_t #include <linux/perf_event.h> #include <linux/types.h> #include <asm/barrier.h>
tools/perf/util/block-info.c +6 -5
@@ -2,15 +2,16 @@#include <stdlib.h> #include <string.h> #include <linux/zalloc.h> -#include "block-info.h" -#include "sort.h" +#include "addr_location.h" #include "annotate.h" -#include "symbol.h" +#include "block-info.h" #include "dso.h" -#include "map.h" -#include "srcline.h" #include "evlist.h" #include "hist.h" +#include "map.h" +#include "sort.h" +#include "srcline.h" +#include "symbol.h" #include "ui/browsers/hists.h" static struct block_header_column {
tools/perf/util/build-id.c +15 -13
@@ -7,38 +7,40 @@* Copyright (C) 2009, 2010 Red Hat Inc. * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo <[email protected]> */ -#include "util.h" // lsdir(), mkdir_p(), rm_rf() #include <dirent.h> #include <errno.h> #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> -#include "util/copyfile.h" -#include "dso.h" + +#include "addr_location.h" #include "build-id.h" +#include "copyfile.h" +#include "debug.h" +#include "dso.h" #include "event.h" -#include "namespaces.h" +#include "header.h" #include "map.h" +#include "namespaces.h" +#include "path.h" +#include "probe-file.h" +#include "session.h" +#include "strlist.h" #include "symbol.h" #include "thread.h" -#include <linux/kernel.h> -#include "debug.h" -#include "session.h" #include "tool.h" -#include "header.h" +#include "util.h" // lsdir(), mkdir_p(), rm_rf() #include "vdso.h" -#include "path.h" -#include "probe-file.h" -#include "strlist.h" #ifdef HAVE_DEBUGINFOD_SUPPORT #include <elfutils/debuginfod.h> #endif +#include <asm/bug.h> #include <linux/ctype.h> -#include <linux/zalloc.h> +#include <linux/kernel.h> #include <linux/string.h> -#include <asm/bug.h> +#include <linux/zalloc.h> static bool no_buildid_cache;
tools/perf/util/callchain.c +1 -0
@@ -21,6 +21,7 @@#include "asm/bug.h" +#include "addr_location.h" #include "debug.h" #include "dso.h" #include "event.h"
tools/perf/util/cs-etm.c +1 -0
@@ -17,6 +17,7 @@#include <stdlib.h> +#include "addr_location.h" #include "auxtrace.h" #include "color.h" #include "cs-etm.h"
tools/perf/util/data-convert-json.c +16 -14
@@ -12,20 +12,22 @@#include <sys/stat.h> #include <unistd.h> -#include "linux/compiler.h" -#include "linux/err.h" -#include "util/auxtrace.h" -#include "util/debug.h" -#include "util/dso.h" -#include "util/event.h" -#include "util/evsel.h" -#include "util/evlist.h" -#include "util/header.h" -#include "util/map.h" -#include "util/session.h" -#include "util/symbol.h" -#include "util/thread.h" -#include "util/tool.h" +#include "addr_location.h" +#include "auxtrace.h" +#include "debug.h" +#include "dso.h" +#include "event.h" +#include "evlist.h" +#include "evsel.h" +#include "header.h" +#include "map.h" +#include "session.h" +#include "symbol.h" +#include "thread.h" +#include "tool.h" + +#include <linux/compiler.h> +#include <linux/err.h> #ifdef HAVE_LIBTRACEEVENT #include <event-parse.h>
tools/perf/util/db-export.c +9 -7
@@ -7,18 +7,20 @@#include <errno.h> #include <stdlib.h> +#include "addr_location.h" +#include "call-path.h" +#include "callchain.h" +#include "comm.h" +#include "db-export.h" #include "dso.h" +#include "event.h" #include "evsel.h" #include "machine.h" -#include "thread.h" -#include "comm.h" -#include "symbol.h" #include "map.h" -#include "event.h" +#include "symbol.h" #include "thread-stack.h" -#include "callchain.h" -#include "call-path.h" -#include "db-export.h" +#include "thread.h" +#include <linux/zalloc.h> int db_export__init (struct db_export *dbe)
tools/perf/util/dlfilter.c +6 -5
@@ -13,17 +13,18 @@#include <linux/kernel.h> #include <linux/string.h> +#include "../include/perf/perf_dlfilter.h" +#include "addr_location.h" #include "debug.h" +#include "dlfilter.h" +#include "dso.h" #include "event.h" #include "evsel.h" -#include "dso.h" #include "map.h" +#include "srcline.h" +#include "symbol.h" #include "thread.h" #include "trace-event.h" -#include "symbol.h" -#include "srcline.h" -#include "dlfilter.h" -#include "../include/perf/perf_dlfilter.h" static void al_to_d_al (struct addr_location *al,struct perf_dlfilter_al *d_al) {
tools/perf/util/dlfilter.h +1 -0
@@ -13,6 +13,7 @@ struct perf_sample;struct evsel ;struct machine ;struct addr_location ; +struct option ;struct perf_dlfilter_fns ;struct perf_dlfilter_sample ;struct perf_dlfilter_al ;
tools/perf/util/event.c +22 -19
64 lines not on this page · raw message
tools/perf/util/evsel_fprintf.c +8 -6
@@ -2,16 +2,18 @@#include <inttypes.h> #include <stdio.h> #include <stdbool.h> -#include "util/evlist.h" -#include "evsel.h" -#include "util/evsel_fprintf.h" -#include "util/event.h" + +#include "addr_location.h" #include "callchain.h" +#include "dso.h" +#include "event.h" +#include "evlist.h" +#include "evsel.h" +#include "evsel_fprintf.h" #include "map.h" +#include "srcline.h" #include "strlist.h" #include "symbol.h" -#include "srcline.h" -#include "dso.h" #ifdef HAVE_LIBTRACEEVENT #include <event-parse.h>
tools/perf/util/hist.c +16 -13
@@ -1,32 +1,35 @@// SPDX-License-Identifier: GPL-2.0 +#include <errno.h> +#include <math.h> +#include <inttypes.h> +#include <sys/param.h> + +#include "addr_location.h" +#include "annotate.h" +#include "block-info.h" +#include "branch.h" +#include "build-id.h" #include "callchain.h" +#include "cgroup.h" #include "debug.h" #include "dso.h" -#include "build-id.h" +#include "evlist.h" +#include "evsel.h" #include "hist.h" #include "kvm-stat.h" #include "map.h" #include "map_symbol.h" -#include "branch.h" #include "mem-events.h" #include "mem-info.h" -#include "session.h" #include "namespaces.h" -#include "cgroup.h" +#include "session.h" #include "sort.h" -#include "units.h" -#include "evlist.h" -#include "evsel.h" -#include "annotate.h" #include "srcline.h" #include "symbol.h" #include "thread.h" -#include "block-info.h" #include "ui/progress.h" -#include <errno.h> -#include <math.h> -#include <inttypes.h> -#include <sys/param.h> +#include "units.h" +#include <linux/rbtree.h> #include <linux/string.h> #include <linux/time64.h>
tools/perf/util/intel-pt.c +18 -17
@@ -14,29 +14,30 @@#include <linux/types.h> #include <linux/zalloc.h> -#include "session.h" -#include "machine.h" -#include "memswap.h" -#include "sort.h" -#include "tool.h" +#include "addr_location.h" +#include "auxtrace.h" +#include "callchain.h" +#include "color.h" +#include "config.h" +#include "debug.h" +#include "dso.h" #include "event.h" #include "evlist.h" #include "evsel.h" +#include "intel-pt.h" +#include "machine.h" #include "map.h" -#include "color.h" -#include "thread.h" -#include "thread-stack.h" +#include "memswap.h" +#include "perf_api_probe.h" +#include "session.h" +#include "sort.h" #include "symbol.h" -#include "callchain.h" -#include "dso.h" -#include "debug.h" -#include "auxtrace.h" -#include "tsc.h" -#include "intel-pt.h" -#include "config.h" -#include "util/perf_api_probe.h" -#include "util/synthetic-events.h" +#include "synthetic-events.h" +#include "thread-stack.h" +#include "thread.h" #include "time-utils.h" +#include "tool.h" +#include "tsc.h" #include "../arch/x86/include/uapi/asm/perf_regs.h"
tools/perf/util/kvm-stat.h +3 -2
@@ -4,11 +4,12 @@#ifdef HAVE_KVM_STAT_SUPPORT -#include "tool.h" +#include "addr_location.h" +#include "record.h" #include "sort.h" #include "stat.h" #include "symbol.h" -#include "record.h" +#include "tool.h" #include <errno.h> #include <stdlib.h>
tools/perf/util/machine.c +18 -16
@@ -3,8 +3,19 @@#include <errno.h> #include <inttypes.h> #include <regex.h> +#include <stdbool.h> #include <stdlib.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +#include "addr_location.h" +#include "arm64-frame-pointer-unwind-support.h" +#include "asm/bug.h" +#include "bpf-event.h" +#include "branch.h" #include "callchain.h" +#include "cgroup.h" #include "debug.h" #include "dso.h" #include "env.h"
@@ -14,37 +25,28 @@#include "machine.h" #include "map.h" #include "map_symbol.h" -#include "branch.h" #include "mem-events.h" #include "mem-info.h" #include "path.h" +#include "sort.h" #include "srcline.h" +#include "strlist.h" #include "symbol.h" #include "synthetic-events.h" -#include "sort.h" -#include "strlist.h" #include "target.h" #include "thread.h" +#include "unwind.h" #include "util.h" #include "vdso.h" -#include <stdbool.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include "unwind.h" -#include "linux/hash.h" -#include "asm/bug.h" -#include "bpf-event.h" -#include <internal/lib.h> // page_size -#include "cgroup.h" -#include "arm64-frame-pointer-unwind-support.h" -#include <api/io_dir.h> +#include <api/io_dir.h> +#include <internal/lib.h> // page_size #include <linux/ctype.h> -#include <symbol/kallsyms.h> +#include <linux/hash.h> #include <linux/mman.h> #include <linux/string.h> #include <linux/zalloc.h> +#include <symbol/kallsyms.h> static struct dso *machine__kernel_dso (struct machine *machine) {
tools/perf/util/print_insn.c +8 -6
@@ -5,18 +5,20 @@* Author(s): Changbin Du <[email protected]> */ #include <inttypes.h> -#include <string.h> #include <stdbool.h> +#include <string.h> + +#include "addr_location.h" #include "capstone.h" #include "debug.h" +#include "dso.h" +#include "dump-insn.h" +#include "machine.h" +#include "map.h" +#include "print_insn.h" #include "sample.h" #include "symbol.h" -#include "machine.h" #include "thread.h" -#include "print_insn.h" -#include "dump-insn.h" -#include "map.h" -#include "dso.h" size_t sample__fprintf_insn_raw (struct perf_sample *sample,FILE *fp) {
tools/perf/util/scripting-engines/trace-event-perl.c +1 -0
@@ -35,6 +35,7 @@#include <EXTERN.h> #include <perl.h> +#include "../addr_location.h" #include "../callchain.h" #include "../dso.h" #include "../machine.h"
tools/perf/util/scripting-engines/trace-event-python.c +1 -0
@@ -34,6 +34,7 @@#include <event-parse.h> #endif +#include "../addr_location.h" #include "../build-id.h" #include "../counts.h" #include "../debug.h"
tools/perf/util/symbol.h +6 -8
@@ -2,20 +2,18 @@#ifndef __PERF_SYMBOL#define __PERF_SYMBOL 1 -#include <linux/types.h> -#include <linux/refcount.h> #include <stdbool.h> -#include <stdint.h> +#include <stdio.h> +#include <elf.h> + +#include <linux/types.h> #include <linux/list.h> #include <linux/rbtree.h> -#include <stdio.h> -#include "addr_location.h" +#include "path.h" #include "symbol_conf.h" -#include "spark.h" - -#include <elf.h> +struct addr_location ;struct dso ;struct map ;struct maps ;
tools/perf/util/symbol_fprintf.c +1 -0
@@ -3,6 +3,7 @@#include <inttypes.h> #include <stdio.h> +#include "addr_location.h" #include "dso.h" #include "map.h" #include "symbol.h"
tools/perf/util/thread-stack.c +7 -5
@@ -11,15 +11,17 @@#include <errno.h> #include <stdlib.h> #include <string.h> -#include "thread.h" + +#include "addr_location.h" +#include "call-path.h" +#include "comm.h" +#include "debug.h" +#include "env.h" #include "event.h" #include "machine.h" -#include "env.h" -#include "debug.h" #include "symbol.h" -#include "comm.h" -#include "call-path.h" #include "thread-stack.h" +#include "thread.h" #define STACK_GROWTH 2048
tools/perf/util/thread.c +10 -8
@@ -7,18 +7,20 @@#include <string.h> #include <linux/kernel.h> #include <linux/zalloc.h> -#include "dso.h" -#include "session.h" -#include "thread.h" -#include "thread-stack.h" -#include "debug.h" -#include "namespaces.h" + +#include "addr_location.h" +#include "callchain.h" #include "comm.h" +#include "debug.h" +#include "dso.h" +#include "dwarf-regs.h" #include "map.h" +#include "namespaces.h" +#include "session.h" #include "symbol.h" +#include "thread-stack.h" +#include "thread.h" #include "unwind.h" -#include "callchain.h" -#include "dwarf-regs.h" #include <api/fs/fs.h>
tools/perf/util/unwind-libdw.c +9 -6
@@ -4,20 +4,23 @@#include <elfutils/libdwfl.h> #include <inttypes.h> #include <errno.h> + +#include "addr_location.h" +#include "callchain.h" #include "debug.h" #include "dso.h" -#include "unwind.h" -#include "unwind-libdw.h" +#include "env.h" +#include "event.h" #include "machine.h" #include "map.h" +#include "perf_regs.h" #include "symbol.h" #include "thread.h" +#include "unwind-libdw.h" +#include "unwind.h" +#include <linux/types.h> #include <linux/zalloc.h> -#include "event.h" -#include "perf_regs.h" -#include "callchain.h" -#include "util/env.h" static char *debuginfo_path;
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 5/10 perf symbol: Move dso__load_bfd_symbols out of symbol.h
In reply to Ian RogersMove into libbfd.h where the code is and to make it clear that symbol.h and symbol.c are generic code. Add libbfd.h to symbol.c includes and organize the includes.
--- tools/perf/tests/pe-file-parsing.c | 5 ++-- tools/perf/util/libbfd.h | 7 ++++++ tools/perf/util/symbol.c | 38 +++++++++++++++++------------- tools/perf/util/symbol.h | 4 ---- 4 files changed, 31 insertions(+), 23 deletions(-)
tools/perf/tests/pe-file-parsing.c +3 -2
@@ -11,10 +11,11 @@#include <unistd.h> #include <subcmd/exec-cmd.h> -#include "debug.h" #include "util/build-id.h" -#include "util/symbol.h" +#include "util/debug.h" #include "util/dso.h" +#include "util/libbfd.h" +#include "util/symbol.h" #include "tests.h"
tools/perf/util/libbfd.h +7 -0
@@ -21,6 +21,7 @@ int libbfd__addr2line(const char *dso_name, u64 addr,void dso__free_a2l_libbfd (struct dso *dso); +int dso__load_bfd_symbols (struct dso *dso,const char *debugfile);int symbol__disassemble_libbfd (const char *filename,struct symbol *sym,struct annotate_args *args);
@@ -51,6 +52,12 @@ static inline void dso__free_a2l_libbfd(struct dso *dso __always_unused) { } +static inline int dso__load_bfd_symbols (struct dso *dso__always_unused , +const char *debugfile__always_unused ) +{ +return -1 ; +} +static inline int symbol__disassemble_libbfd (const char *filename__always_unused ,struct symbol *sym__always_unused ,struct annotate_args *args__always_unused )
tools/perf/util/symbol.c +21 -17
@@ -1,47 +1,51 @@// SPDX-License-Identifier: GPL-2.0 #include <dirent.h> #include <errno.h> -#include <stdlib.h> +#include <fcntl.h> +#include <inttypes.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <linux/capability.h> -#include <linux/kernel.h> -#include <linux/mman.h> -#include <linux/string.h> -#include <linux/time64.h> -#include <sys/types.h> -#include <sys/stat.h> #include <sys/param.h> -#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> -#include <inttypes.h> +#include "annotate.h" #include "build-id.h" #include "cap.h" #include "cpumap.h" #include "debug.h" +#include "debug.h" #include "demangle-cxx.h" #include "demangle-java.h" #include "demangle-ocaml.h" #include "demangle-rust-v0.h" #include "dso.h" -#include "util.h" // lsdir() -#include "debug.h" #include "event.h" +#include "header.h" +#include "intlist.h" +#include "libbfd.h" #include "machine.h" #include "map.h" -#include "symbol.h" #include "map_symbol.h" #include "mem-events.h" #include "mem-info.h" -#include "symsrc.h" -#include "strlist.h" -#include "intlist.h" #include "namespaces.h" -#include "header.h" #include "path.h" +#include "perf-libelf.h" +#include "strlist.h" +#include "symbol.h" +#include "symsrc.h" +#include "util.h" // lsdir() + +#include <linux/capability.h> #include <linux/ctype.h> +#include <linux/kernel.h> #include <linux/log2.h> +#include <linux/mman.h> +#include <linux/string.h> +#include <linux/time64.h> #include <linux/zalloc.h> #include <elf.h>
tools/perf/util/symbol.h +0 -4
@@ -153,10 +153,6 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,struct symsrc ; -#ifdef HAVE_LIBBFD_SUPPORT -int dso__load_bfd_symbols (struct dso *dso,const char *debugfile); -#endif -int dso__load_sym (struct dso *dso,struct map *map,struct symsrc *syms_ss,struct symsrc *runtime_ss,int kmodule);int dso__synthesize_plt_symbols (struct dso *dso,struct symsrc *ss);
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 6/10 perf symbol: Use fallbacks with filename__read_build_id
In reply to Ian RogersTry libbfd, libelf and then symbol-minimal when trying to read a build ID. Always compile in symbol-minimal so that it is the fallback of last resort. Rename libelf reading code. Move the decompression code into symbol.c and allow its use with the symbol-minimal version.
--- tools/perf/util/Build | 5 +- tools/perf/util/libbfd.c | 9 +- tools/perf/util/libbfd.h | 5 +- tools/perf/util/perf-libelf.c | 113 ++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 20 ++++ tools/perf/util/symbol-elf.c | 155 +------------------------------ tools/perf/util/symbol-minimal.c | 17 ++-- tools/perf/util/symbol-minimal.h | 9 ++ tools/perf/util/symbol.c | 52 +++++++++++ 9 files changed, 211 insertions(+), 174 deletions(-) create mode 100644 tools/perf/util/symbol-minimal.h
tools/perf/util/Build +1 -4
@@ -54,6 +54,7 @@ perf-util-y += usage.o perf-util-y += dso.o perf-util-y += dsos.o perf-util-y += symbol.o +perf-util-y += symbol-minimal.o perf-util-y += symbol_fprintf.o perf-util-y += map_symbol.o perf-util-y += color.o
@@ -209,10 +210,6 @@ ifdef hashmap perf-util-y += hashmap.o endif -ifndef CONFIG_LIBELF -perf-util-y += symbol-minimal.o -endif - ifndef CONFIG_SETNS perf-util-y += setns.o endif
tools/perf/util/libbfd.c +2 -7
@@ -418,18 +418,13 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)return err; } -int libbfd__read_build_id (const char *filename,struct build_id *bid) +int libbfd__read_build_id (int _fd,const char *filename,struct build_id *bid) {size_t size =sizeof (bid->data);int err =-1 , fd;bfd *abfd; -if (!filename) -return -EFAULT ; -if (!is_regular_file (filename)) -return -EWOULDBLOCK ; - - fd =open (filename,O_RDONLY ); + fd =dup (_fd);if (fd <0 )return -1 ;
tools/perf/util/libbfd.h +3 -2
@@ -26,7 +26,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile);int symbol__disassemble_libbfd (const char *filename,struct symbol *sym,struct annotate_args *args); -int libbfd__read_build_id (const char *filename,struct build_id *bid); +int libbfd__read_build_id (int fd,const char *filename,struct build_id *bid);int libbfd_filename__read_debuglink (const char *filename,char *debuglink,size_t size);
@@ -65,7 +65,8 @@ static inline int symbol__disassemble_libbfd(const char *filename __always_unusereturn -1 ; } -static inline int libbfd__read_build_id (const char *filename__always_unused , +static inline int libbfd__read_build_id (int fd__always_unused , +const char *filename__always_unused ,struct build_id *bid__always_unused ) {return -1 ;
tools/perf/util/perf-libelf.c +113 -0
122 lines not on this page · raw message
tools/perf/util/perf-libelf.h +20 -0
@@ -2,6 +2,8 @@#ifndef __PERF_LIBELF_H#define __PERF_LIBELF_H +struct build_id ; +#ifdef HAVE_LIBELF_SUPPORT #include <libelf.h>
@@ -17,9 +19,27 @@# define PERF_ELF_C_READ_MMAP ELF_C_READ#endif +/* +* Align offset to 4 bytes as needed for note name and descriptor data. +*/ +#define NOTE_ALIGN (n) (((n) + 3) & -4U) +Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep,GElf_Shdr *shp,const char *name,size_t *idx); +int __libelf__read_build_id (Elf *elf,void *bf,size_t size); + +int libelf__read_build_id (int _fd,const char *filename,struct build_id *bid); + +#else // !defined(HAVE_LIBELF_SUPPORT) + +static inline int libelf__read_build_id (int fd__always_unused , +const char *filename__always_unused , +struct build_id *bid__always_unused ) +{ +return -1 ; +} +#endif // defined(HAVE_LIBELF_SUPPORT) #endif /* __PERF_LIBELF_H */
tools/perf/util/symbol-elf.c +1 -154
167 lines not on this page · raw message
tools/perf/util/symbol-minimal.c +10 -7
@@ -1,5 +1,7 @@ +#include "debug.h" #include "dso.h" #include "symbol.h" +#include "symbol-minimal.h" #include "symsrc.h" #include <errno.h>
@@ -75,17 +77,19 @@ static int read_build_id(void *note_data, size_t note_len, struct build_id *bid,return -1 ; } +#ifndef HAVE_LIBELF_SUPPORT int filename__read_debuglink (const char *filename__maybe_unused ,char *debuglink__maybe_unused ,size_t size__maybe_unused ) {return -1 ; } +#endif /* * Just try PT_NOTE header otherwise fails */ -int filename__read_build_id (const char *filename,struct build_id *bid) +int sym_min__read_build_id (int _fd,const char *filename,struct build_id *bid) {int fd, ret =-1 ;bool need_swap = false, elf32;
@@ -102,12 +106,7 @@ int filename__read_build_id(const char *filename, struct build_id *bid)void *phdr, *buf =NULL ;ssize_t phdr_size, ehdr_size, buf_size =0 ; -if (!filename) -return -EFAULT ; -if (!is_regular_file (filename)) -return -EWOULDBLOCK ; - - fd =open (filename,O_RDONLY ); + fd =dup (_fd);if (fd <0 )return -1 ;
@@ -199,9 +198,12 @@ int filename__read_build_id(const char *filename, struct build_id *bid)free (phdr); out:close (fd); +if (ret) +pr_debug ("Error reading build-id from %s\n" , filename);return ret; } +#ifndef HAVE_LIBELF_SUPPORT int sysfs__read_build_id (const char *filename,struct build_id *bid) {int fd;
@@ -363,3 +365,4 @@ bool filename__has_section(const char *filename __maybe_unused, const char *sec {return false; } +#endif // HAVE_LIBELF_SUPPORT
tools/perf/util/symbol-minimal.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_SYMBOL_MINIMAL_H +#define __PERF_SYMBOL_MINIMAL_H + +struct build_id ; + +int sym_min__read_build_id (int _fd,const char *filename,struct build_id *bid); + +#endif /* __PERF_SYMBOL_MINIMAL_H */
tools/perf/util/symbol.c +52 -0
64 lines not on this page · raw message
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 7/10 perf symbol: Use fallbacks for filename__read_debuglink
In reply to Ian RogersTry libbfd and then libelf in symbol.c. Remove the non-existent symbol-minimal version.
--- tools/perf/util/perf-libelf.c | 52 +++++++++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 10 ++++++ tools/perf/util/symbol-elf.c | 56 -------------------------------- tools/perf/util/symbol-minimal.c | 9 ----- tools/perf/util/symbol.c | 10 ++++++ 5 files changed, 72 insertions(+), 65 deletions(-)
tools/perf/util/perf-libelf.c +52 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include "perf-libelf.h" +#include <fcntl.h> #include <stddef.h> #include <string.h> #include <unistd.h>
@@ -143,3 +144,54 @@ int libelf__read_build_id(int _fd, const char *filename, struct build_id *bid) out:return err; } + +int libelf_filename__read_debuglink (const char *filename,char *debuglink,size_t size) +{ +int fd, err =-1 ; +Elf *elf; +GElf_Ehdr ehdr; +GElf_Shdr shdr; +Elf_Data *data; +Elf_Scn *sec; +Elf_Kind ek; + + fd =open (filename,O_RDONLY ); +if (fd <0 ) + goto out; + + elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); +if (elf ==NULL ) { +pr_debug2 ("%s: cannot read %s ELF file.\n" , __func__, filename); + goto out_close; + } + + ek =elf_kind (elf); +if (ek !=ELF_K_ELF ) + goto out_elf_end; + +if (gelf_getehdr (elf, &ehdr) ==NULL ) { +pr_err ("%s: cannot get elf header.\n" , __func__); + goto out_elf_end; + } + + sec =elf_section_by_name (elf, &ehdr, &shdr, +".gnu_debuglink" ,NULL ); +if (sec ==NULL ) + goto out_elf_end; + + data =elf_getdata (sec,NULL ); +if (data ==NULL ) + goto out_elf_end; + +/* the start of this section is a zero-terminated string */ +strncpy (debuglink, data->d_buf, size); + + err =0 ; + +out_elf_end: +elf_end (elf); +out_close: +close (fd); +out: +return err; +}
tools/perf/util/perf-libelf.h +10 -0
@@ -2,6 +2,8 @@#ifndef __PERF_LIBELF_H#define __PERF_LIBELF_H +#include <stddef.h> +struct build_id ;#ifdef HAVE_LIBELF_SUPPORT
@@ -30,6 +32,7 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const charint __libelf__read_build_id (Elf *elf,void *bf,size_t size);int libelf__read_build_id (int _fd,const char *filename,struct build_id *bid); +int libelf_filename__read_debuglink (const char *filename,char *debuglink,size_t size);#else // !defined(HAVE_LIBELF_SUPPORT)
@@ -40,6 +43,13 @@ static inline int libelf__read_build_id(int fd __always_unused,return -1 ; } +static inline int libelf_filename__read_debuglink (const char *filename__always_unused , +char *debuglink__always_unused , +size_t size__always_unused ) +{ +return -1 ; +} +#endif // defined(HAVE_LIBELF_SUPPORT) #endif /* __PERF_LIBELF_H */
tools/perf/util/symbol-elf.c +0 -56
62 lines not on this page · raw message
tools/perf/util/symbol-minimal.c +0 -9
@@ -77,15 +77,6 @@ static int read_build_id(void *note_data, size_t note_len, struct build_id *bid,return -1 ; } -#ifndef HAVE_LIBELF_SUPPORT -int filename__read_debuglink (const char *filename__maybe_unused , -char *debuglink__maybe_unused , -size_t size__maybe_unused ) -{ -return -1 ; -} -#endif -/* * Just try PT_NOTE header otherwise fails */
tools/perf/util/symbol.c +10 -0
@@ -2050,6 +2050,16 @@ int filename__read_build_id(const char *filename, struct build_id *bid)return err; } +int filename__read_debuglink (const char *filename,char *debuglink,size_t size) +{ +int err =libbfd_filename__read_debuglink (filename, debuglink, size); + +if (err ==0 ) +return 0 ; + +return libelf_filename__read_debuglink (filename, debuglink, size); +} +static char *dso__find_kallsyms (struct dso *dso,struct map *map) {struct build_id bid = { .size =0 , };
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 8/10 perf symbol: Make a common sysfs__read_build_id
In reply to Ian RogersThe libelf version of sysfs__read_build_id would read through the file, the symbol-minimal version would read the whole file and then use regular build-id parsing. Given we prefer the libelf code, make both implementations use the libelf implementation and not require reading the whole file. As the libelf implementation uses libelf structs, move the code to symbol-minimal and use the style/implementation that exists there already in the in memory read_build_id code. Note, this means we could avoid reading phdrs where read_build_id is used and switch to read_build_id_fd to potentially avoid some memory allocation.
Clean up how bf was being used as it bound checked bf when a build ID note was found but not when the name wasn't "GNU". Switch to just lseek-ing forward the file to avoid any buffer overrun problems and unnecessary reading.
Reduce scope of NOTE_ALIGN macro in perf-libelf.h.
--- tools/perf/util/perf-libelf.c | 5 ++ tools/perf/util/perf-libelf.h | 5 -- tools/perf/util/symbol-elf.c | 50 -------------------- tools/perf/util/symbol-minimal.c | 80 +++++++++++++++++++++++--------- tools/perf/util/symbol-minimal.h | 1 + tools/perf/util/symbol.c | 6 +++ 6 files changed, 69 insertions(+), 78 deletions(-)
tools/perf/util/perf-libelf.c +5 -0
@@ -9,6 +9,11 @@#include "build-id.h" #include "debug.h" +/* +* Align offset to 4 bytes as needed for note name and descriptor data. +*/ +#define NOTE_ALIGN (n) (((n) + 3) & -4U) +Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep,GElf_Shdr *shp,const char *name,size_t *idx) {
tools/perf/util/perf-libelf.h +0 -5
@@ -21,11 +21,6 @@ struct build_id;# define PERF_ELF_C_READ_MMAP ELF_C_READ#endif -/* -* Align offset to 4 bytes as needed for note name and descriptor data. -*/ -#define NOTE_ALIGN (n) (((n) + 3) & -4U) -Elf_Scn *elf_section_by_name (Elf *elf,GElf_Ehdr *ep,GElf_Shdr *shp,const char *name,size_t *idx);
tools/perf/util/symbol-elf.c +0 -50
56 lines not on this page · raw message
tools/perf/util/symbol-minimal.c +57 -23
101 lines not on this page · raw message
tools/perf/util/symbol-minimal.h +1 -0
@@ -5,5 +5,6 @@struct build_id ;int sym_min__read_build_id (int _fd,const char *filename,struct build_id *bid); +int sym_min_sysfs__read_build_id (const char *filename,struct build_id *bid);#endif /* __PERF_SYMBOL_MINIMAL_H */
tools/perf/util/symbol.c +6 -0
@@ -2050,6 +2050,12 @@ int filename__read_build_id(const char *filename, struct build_id *bid)return err; } +int sysfs__read_build_id (const char *filename,struct build_id *bid) +{ +/* Doesn't mmap file into memory. */ +return sym_min_sysfs__read_build_id (filename, bid); +} +int filename__read_debuglink (const char *filename,char *debuglink,size_t size) {int err =libbfd_filename__read_debuglink (filename, debuglink, size);
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 9/10 perf dso: Move type helpers out of symbol and use fallbacks
In reply to Ian RogersFallback between libelf and symbol-minimal versions. Remove the symbol.c code and just directly inline into the only caller in dso.c.
--- tools/perf/util/dso.c | 57 ++++++++++++++---------- tools/perf/util/perf-libelf.c | 33 ++++++++++++++ tools/perf/util/perf-libelf.h | 8 ++++ tools/perf/util/symbol-elf.c | 33 -------------- tools/perf/util/symbol-minimal.c | 76 ++++++++++++++++---------------- tools/perf/util/symbol-minimal.h | 3 ++ tools/perf/util/symbol.h | 2 - 7 files changed, 115 insertions(+), 97 deletions(-)
tools/perf/util/dso.c +33 -24
@@ -1,37 +1,42 @@// SPDX-License-Identifier: GPL-2.0 -#include <asm/bug.h> -#include <linux/kernel.h> -#include <linux/string.h> -#include <linux/zalloc.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <errno.h> #include <fcntl.h> #include <stdlib.h> -#ifdef HAVE_LIBBPF_SUPPORT -#include <bpf/libbpf.h> -#include "bpf-event.h" -#include "bpf-utils.h" -#endif +#include <sys/resource.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> + +#include "annotate-data.h" +#include "auxtrace.h" #include "compress.h" +#include "debug.h" +#include "dso.h" +#include "dsos.h" #include "env.h" +#include "machine.h" +#include "map.h" #include "namespaces.h" #include "path.h" -#include "map.h" -#include "symbol.h" +#include "perf-libelf.h" #include "srcline.h" -#include "dso.h" -#include "dsos.h" -#include "machine.h" -#include "auxtrace.h" -#include "util.h" /* O_CLOEXEC for older systems */ -#include "debug.h" #include "string2.h" +#include "symbol-minimal.h" +#include "symbol.h" +#include "util.h" /* O_CLOEXEC for older systems */ #include "vdso.h" -#include "annotate-data.h" + +#include <asm/bug.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/zalloc.h> + +#ifdef HAVE_LIBBPF_SUPPORT +#include <bpf/libbpf.h> +#include "bpf-event.h" +#include "bpf-utils.h" +#endif static const char *const debuglink_paths[] = {"%.0s%s" ,
@@ -1747,7 +1752,11 @@ enum dso_type dso__type(struct dso *dso, struct machine *machine)enum dso_type type =DSO__TYPE_UNKNOWN ;if (dso__data_get_fd (dso, machine, &fd)) { - type =dso__type_fd (fd); + type =libelf_dso__type_fd (fd); + +if (type ==DSO__TYPE_UNKNOWN ) + type =sym_min_dso__type_fd (fd); +dso__data_put_fd (dso); }
tools/perf/util/perf-libelf.c +33 -0
@@ -200,3 +200,36 @@ int libelf_filename__read_debuglink(const char *filename, char *debuglink, size_ out:return err; } + +enum dso_type libelf_dso__type_fd (int fd) +{ +enum dso_type dso_type =DSO__TYPE_UNKNOWN ; +GElf_Ehdr ehdr; +Elf_Kind ek; +Elf *elf; + + elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); +if (elf ==NULL ) + goto out; + + ek =elf_kind (elf); +if (ek !=ELF_K_ELF ) + goto out_end; + +if (gelf_getclass (elf) ==ELFCLASS64 ) { + dso_type =DSO__TYPE_64BIT ; + goto out_end; + } + +if (gelf_getehdr (elf, &ehdr) ==NULL ) + goto out_end; + +if (ehdr.e_machine ==EM_X86_64 ) + dso_type =DSO__TYPE_X32BIT ; +else + dso_type =DSO__TYPE_32BIT ; +out_end: +elf_end (elf); +out: +return dso_type; +}
tools/perf/util/perf-libelf.h +8 -0
@@ -4,6 +4,8 @@#include <stddef.h> +#include "dso.h" +struct build_id ;#ifdef HAVE_LIBELF_SUPPORT
@@ -28,6 +30,7 @@ int __libelf__read_build_id(Elf *elf, void *bf, size_t size);int libelf__read_build_id (int _fd,const char *filename,struct build_id *bid);int libelf_filename__read_debuglink (const char *filename,char *debuglink,size_t size); +enum dso_type libelf_dso__type_fd (int fd);#else // !defined(HAVE_LIBELF_SUPPORT)
@@ -45,6 +48,11 @@ static inline int libelf_filename__read_debuglink(const char *filename __always_return -1 ; } +enum dso_type libelf_dso__type_fd (int fd__always_unused ) +{ +return DSO__TYPE_UNKNOWN ; +} +#endif // defined(HAVE_LIBELF_SUPPORT) #endif /* __PERF_LIBELF_H */
tools/perf/util/symbol-elf.c +0 -33
@@ -1572,39 +1572,6 @@ int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,return err; } -enum dso_type dso__type_fd (int fd) -{ -enum dso_type dso_type =DSO__TYPE_UNKNOWN ; -GElf_Ehdr ehdr; -Elf_Kind ek; -Elf *elf; - - elf =elf_begin (fd,PERF_ELF_C_READ_MMAP ,NULL ); -if (elf ==NULL ) - goto out; - - ek =elf_kind (elf); -if (ek !=ELF_K_ELF ) - goto out_end; - -if (gelf_getclass (elf) ==ELFCLASS64 ) { - dso_type =DSO__TYPE_64BIT ; - goto out_end; - } - -if (gelf_getehdr (elf, &ehdr) ==NULL ) - goto out_end; - -if (ehdr.e_machine ==EM_X86_64 ) - dso_type =DSO__TYPE_X32BIT ; -else - dso_type =DSO__TYPE_32BIT ; -out_end: -elf_end (elf); -out: -return dso_type; -} -static int copy_bytes (int from,off_t from_offs,int to,off_t to_offs,u64 len) {ssize_t r;
tools/perf/util/symbol-minimal.c +38 -38
88 lines not on this page · raw message
tools/perf/util/symbol-minimal.h +3 -0
@@ -2,9 +2,12 @@#ifndef __PERF_SYMBOL_MINIMAL_H#define __PERF_SYMBOL_MINIMAL_H +#include "dso.h" +struct build_id ;int sym_min__read_build_id (int _fd,const char *filename,struct build_id *bid);int sym_min_sysfs__read_build_id (const char *filename,struct build_id *bid); +enum dso_type sym_min_dso__type_fd (int fd);#endif /* __PERF_SYMBOL_MINIMAL_H */
tools/perf/util/symbol.h +0 -2
@@ -117,8 +117,6 @@ struct symbol *dso__first_symbol(struct dso *dso);struct symbol *dso__last_symbol (struct dso *dso);struct symbol *dso__next_symbol (struct symbol *sym); -enum dso_type dso__type_fd (int fd); -int filename__read_build_id (const char *filename,struct build_id *id);int sysfs__read_build_id (const char *filename,struct build_id *bid); int modules__parse(const char *filename, void *arg,
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerPATCH v2 10/10 perf symbol: Fix ENOENT case for filename__read_build_id
In reply to Ian RogersSome callers of filename__read_build_id assume the error value must be -1, fix by making them handle all < 0 values.
If is_regular_file fails in filename__read_build_id then it could be the file is missing (ENOENT) and it would be wrong to return -EWOULDBLOCK in that case. Fix the logic so -EWOULDBLOCK is only reported if other errors with stat haven't occurred.
--- tools/perf/builtin-buildid-cache.c | 6 ++++-- tools/perf/util/symbol.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)
tools/perf/builtin-buildid-cache.c +4 -2
@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) {char filename[PATH_MAX ];struct build_id bid = { .size =0 , }; +int err;if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true; -if (filename__read_build_id (filename, &bid) ==-1 ) { -if (errno ==ENOENT ) + err =filename__read_build_id (filename, &bid); +if (err <0 ) { +if (err == -ENOENT )return false; pr_warning("Problems with %s file, consider removing it from the cache\n",
tools/perf/util/symbol.c +2 -1
@@ -2008,8 +2008,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid)if (!filename)return -EFAULT ; + errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno; err =kmod_path__parse (&m, filename);if (err)
Signature · 1 line
2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerRe: [PATCH v2 10/10] perf symbol: Fix ENOENT case for filename__read_build_id
Quoted 10 lines · Ian Rogers
Some callers of
filename__read_build_idassume the error value must be -1, fix by making them handle all < 0 values.If
is_regular_filefails infilename__read_build_idthen it could be the file is missing (ENOENT) and it would be wrong to return-EWOULDBLOCKin that case. Fix the logic so-EWOULDBLOCKis only reported if other errors with stat haven't occurred.Fixes 834ebb5678d7 ("perf tools: Don't read build-ids from non-regular files")
We might want to prioritize this fix.
Quoted 11 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-buildid-cache.c | 6 ++++-- tools/perf/util/symbol.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)tools/perf/builtin-buildid-cache.c +0
-0
tools/perf/builtin-buildid-cache.c static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) · line 283
Quoted 9 lines
tools/perf/builtin-buildid-cache.c +1
-1@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) {char filename[PATH_MAX ];struct build_id bid = { .size =0 , }; +int err;if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true; -if (filename__read_build_id (filename, &bid) ==-1 ) {
This check here is clearly wrong when -EWOULDBLOCK is returned from James' change.
Quoted 12 lines
tools/perf/builtin-buildid-cache.c +3
-1-if (errno ==ENOENT ) + err =filename__read_build_id (filename, &bid); +if (err <0 ) { +if (err == -ENOENT )return false; pr_warning("Problems with %s file, consider removing it from the cache\n",tools/perf/util/symbol.c +0
-0
tools/perf/util/symbol.c int filename__read_build_id(const char *filename, struct build_id *bid) · line 2013
Quoted 7 lines
tools/perf/util/symbol.c +2
-1@@ -2008,8 +2008,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid)if (!filename)return -EFAULT ; + errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno;
I've made the fix after the other changes as it is simpler to fix in one filename__read_build_id rather than all the libbfd, .. variants. If we don't want the series in the short-term perhaps we still want to carry some parts of this fix.
Thanks,
Ian
Quoted 6 lines
tools/perf/util/symbol.c +0
-1err =kmod_path__parse (&m, filename);if (err) --2.52.0.158.g65b55ccf14-goog
Namhyung Kim
maintainerRe: [PATCH v2 10/10] perf symbol: Fix ENOENT case for filename__read_build_id
Hi Ian,
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Ian Rogers
Some callers of
filename__read_build_idassume the error value must be -1, fix by making them handle all < 0 values.
Quoted 8 lines
Quoted 6 lines
If
is_regular_filefails infilename__read_build_idthen it could be the file is missing (ENOENT) and it would be wrong to return-EWOULDBLOCKin that case. Fix the logic so-EWOULDBLOCKis only reported if other errors with stat haven't occurred.Fixes 834ebb5678d7 ("perf tools: Don't read build-ids from non-regular files")We might want to prioritize this fix.
Sure.
Quoted 40 lines
Quoted 12 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-buildid-cache.c | 6 ++++-- tools/perf/util/symbol.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)tools/perf/builtin-buildid-cache.c +0
-0tools/perf/builtin-buildid-cache.c static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) · line 283
Quoted 9 lines
tools/perf/builtin-buildid-cache.c +1
-1@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) {char filename[PATH_MAX ];struct build_id bid = { .size =0 , }; +int err;if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true; -if (filename__read_build_id (filename, &bid) ==-1 ) {This check here is clearly wrong when
-EWOULDBLOCKis returned from James' change.Quoted 15 lines
tools/perf/builtin-buildid-cache.c +3
-1-if (errno ==ENOENT ) + err =filename__read_build_id (filename, &bid); +if (err <0 ) { +if (err == -ENOENT )return false; pr_warning("Problems with %s file, consider removing it from the cache\n",tools/perf/util/symbol.c +0
-0@@ -2008,8 +2008,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid)if (!filename)return -EFAULT ;
Quoted 9 lines
tools/perf/util/symbol.c int filename__read_build_id(const char *filename, struct build_id *bid) · line 2013
Quoted 4 lines
tools/perf/util/symbol.c +2
-1+ errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno;I've made the fix after the other changes as it is simpler to fix in one
filename__read_build_idrather than all the libbfd, .. variants. If we don't want the series in the short-term perhaps we still want to carry some parts of this fix.
Yeah, I hesitate to merge a big series at this moment unless it's a critical and obvious fix. Can you please separate this change and send it out?
Thanks,
Namhyung
Quoted 7 lines
Quoted 7 lines
tools/perf/util/symbol.c +0
-1err =kmod_path__parse (&m, filename);if (err) --2.52.0.158.g65b55ccf14-goog
Ian Rogers
reviewerRe: [PATCH v2 10/10] perf symbol: Fix ENOENT case for filename__read_build_id
Quoted 70 lines · Namhyung Kim
Hi Ian,
Quoted 5 lines · Ian Rogers
Quoted 4 lines · Ian Rogers
Some callers of
filename__read_build_idassume the error value must be -1, fix by making them handle all < 0 values.Quoted 8 lines
Quoted 6 lines
If
is_regular_filefails infilename__read_build_idthen it could be the file is missing (ENOENT) and it would be wrong to return-EWOULDBLOCKin that case. Fix the logic so-EWOULDBLOCKis only reported if other errors with stat haven't occurred.Fixes 834ebb5678d7 ("perf tools: Don't read build-ids from non-regular files")We might want to prioritize this fix.
Sure.
Quoted 40 lines
Quoted 12 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/builtin-buildid-cache.c | 6 ++++-- tools/perf/util/symbol.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)tools/perf/builtin-buildid-cache.c +0
-0tools/perf/builtin-buildid-cache.c static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) · line 283
Quoted 9 lines
tools/perf/builtin-buildid-cache.c +1
-1@@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused) {char filename[PATH_MAX ];struct build_id bid = { .size =0 , }; +int err;if (!dso__build_id_filename (dso, filename,sizeof (filename), false))return true; -if (filename__read_build_id (filename, &bid) ==-1 ) {This check here is clearly wrong when
-EWOULDBLOCKis returned from James' change.Quoted 15 lines
tools/perf/builtin-buildid-cache.c +3
-1-if (errno ==ENOENT ) + err =filename__read_build_id (filename, &bid); +if (err <0 ) { +if (err == -ENOENT )return false; pr_warning("Problems with %s file, consider removing it from the cache\n",tools/perf/util/symbol.c +0
-0@@ -2008,8 +2008,9 @@ int filename__read_build_id(const char *filename, struct build_id *bid)if (!filename)return -EFAULT ;Quoted 9 lines
tools/perf/util/symbol.c int filename__read_build_id(const char *filename, struct build_id *bid) · line 2013
Quoted 4 lines
tools/perf/util/symbol.c +2
-1+ errno =0 ;if (!is_regular_file (filename)) -return -EWOULDBLOCK ; +return errno ==0 ? -EWOULDBLOCK : -errno;I've made the fix after the other changes as it is simpler to fix in one
filename__read_build_idrather than all the libbfd, .. variants. If we don't want the series in the short-term perhaps we still want to carry some parts of this fix.
Quoted 3 lines
Yeah, I hesitate to merge a big series at this moment unless it's a critical and obvious fix. Can you please separate this change and send it out?
Sent in:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Ian
Quoted 11 lines
Thanks,
NamhyungQuoted 7 lines
Quoted 7 lines
tools/perf/util/symbol.c +0
-1err =kmod_path__parse (&m, filename);if (err) --2.52.0.158.g65b55ccf14-goog