perf dso: Use libbfd to read build_id and .gnu_debuglink section
PATCH v3 1/3 perf dso: Use libbfd to read build_id and .gnu_debuglink section
Wine generates PE binaries for most of its modules and perf is unable to parse these files to get build_id or .gnu_debuglink section.
Using libbfd when available, instead of libelf, makes it possible to resolve debug file location regardless of the dso binary format.
---
v3: Rebase and small changes to PATCH 2/3 and and PATCH 3/3.
tools/perf/util/symbol-elf.c | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)
tools/perf/util/symbol-elf.c +77 -3
@@ -50,6 +50,10 @@ typedef Elf64_Nhdr GElf_Nhdr;#define DMGL_ANSI (1 << 1)/* Include const, volatile, etc */ #endif +#ifdef HAVE_LIBBFD_SUPPORT +#define PACKAGE 'perf' +#include <bfd.h> +#else #ifdef HAVE_CPLUS_DEMANGLE_SUPPORT extern char *cplus_demangle (const char *,int );
@@ -65,9 +69,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, {return NULL ; } -#else -#define PACKAGE 'perf' -#include <bfd.h> +#endif #endif #endif
@@ -530,6 +532,36 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_build_id (const char *filename,void *bf,size_t size) +{ +int err =-1 ; +bfd *abfd; + + abfd =bfd_openr (filename,NULL ); +if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + +if (!abfd->build_id || abfd->build_id->size > size) + goto out_close; + +memcpy (bf, abfd->build_id->data, abfd->build_id->size); +memset (bf + abfd->build_id->size,0 , size - abfd->build_id->size); + err = abfd->build_id->size; + +out_close: +bfd_close (abfd); +return err; +} + +#else +int filename__read_build_id (const char *filename,void *bf,size_t size) {int fd, err =-1 ;
@@ -557,6 +589,8 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) return err; } +#endif +int sysfs__read_build_id (const char *filename,void *build_id,size_t size) {int fd, err =-1 ;
@@ -608,6 +642,44 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_debuglink (const char *filename,char *debuglink, +size_t size) +{ +int err =-1 ; +asection *section; +bfd *abfd; + + abfd =bfd_openr (filename,NULL ); +if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + + section =bfd_get_section_by_name (abfd,".gnu_debuglink" ); +if (!section) + goto out_close; + +if (section->size > size) + goto out_close; + +if (!bfd_get_section_contents (abfd, section, debuglink,0 , + section->size)) + goto out_close; + + err =0 ; + +out_close: +bfd_close (abfd); +return err; +} + +#else +int filename__read_debuglink (const char *filename,char *debuglink,size_t size) {
@@ -660,6 +732,8 @@ int filename__read_debuglink(const char *filename, char *debuglink, return err; } +#endif +static int dso__swap_init (struct dso *dso,unsigned char eidata) {static unsigned int const endian =1 ;
Signature · 1 line
2.28.0
PATCH v3 2/3 perf symbols: Try reading the symbol table with libbfd
Wine generates PE binaries for its code modules and also generates debug files in PE or PDB formats, which perf cannot parse either.
Trying to read symbols on non-ELF binaries with libbfd, when supported, makes it possible for perf to report symbols and annotations for Windows applications running under Wine.
Because libbfd doesn't provide symbol size (probably because of some backends not supporting it), we compute it by first sorting the symbols by addresses and then considering that they are sequential in a given section.
---
v3: Also include local and weak bfd symbols and mark them as such, only
global symbols were previously reported, and that caused a very imprecise address to symbol resolution.
tools/perf/util/symbol.c | 140 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/symbol.h | 4 ++ 2 files changed, 144 insertions(+)
tools/perf/util/symbol.c +140 -0
@@ -1525,6 +1525,138 @@ static int dso__load_perf_map(const char *map_path, struct dso *dso)return -1 ; } +#ifdef HAVE_LIBBFD_SUPPORT +#define PACKAGE 'perf' +#include <bfd.h> + +static int bfd_symbols__cmpvalue (const void *a,const void *b) +{ +const asymbol *as = *(const asymbol **)a, *bs = *(const asymbol **)b; + +if (bfd_asymbol_value (as) !=bfd_asymbol_value (bs)) +return bfd_asymbol_value (as) -bfd_asymbol_value (bs); + +return bfd_asymbol_name (as)[0 ] -bfd_asymbol_name (bs)[0 ]; +} + +static int bfd2elf_binding (asymbol *symbol) +{ +if (symbol->flags &BSF_WEAK ) +return STB_WEAK ; +if (symbol->flags &BSF_GLOBAL ) +return STB_GLOBAL ; +if (symbol->flags &BSF_LOCAL ) +return STB_LOCAL ; +return -1 ; +} + +int dso__load_bfd_symbols (struct dso *dso,const char *debugfile) +{ +int err =-1 ; +long symbols_size, symbols_count; +asection *section; +asymbol **symbols, *sym; +struct symbol *symbol; +bfd *abfd; +u_int i; +u64 start, len; + + abfd =bfd_openr (dso->long_name,NULL ); +if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, + dso->long_name); + goto out_close; + } + +if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) + goto out_close; + + section =bfd_get_section_by_name (abfd,".text" ); +if (section) + dso->text_offset = section->vma - section->filepos; + +bfd_close (abfd); + + abfd =bfd_openr (debugfile,NULL ); +if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, + debugfile); + goto out_close; + } + +if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) + goto out_close; + + symbols_size =bfd_get_symtab_upper_bound (abfd); +if (symbols_size ==0 ) { +bfd_close (abfd); +return 0 ; + } + +if (symbols_size <0 ) + goto out_close; + + symbols =malloc (symbols_size); +if (!symbols) + goto out_close; + + symbols_count =bfd_canonicalize_symtab (abfd, symbols); +if (symbols_count <0 ) + goto out_free; + +qsort (symbols, symbols_count,sizeof (asymbol *), bfd_symbols__cmpvalue); + +#ifdef bfd_get_section +#define bfd_asymbol_section bfd_get_section +#endif +for (i =0 ; i < symbols_count; ++i) { + sym = symbols[i]; + section =bfd_asymbol_section (sym); +if (bfd2elf_binding (sym) <0 ) +continue ; + +while (i +1 < symbols_count && +bfd_asymbol_section (symbols[i +1 ]) == section && +bfd2elf_binding (symbols[i +1 ]) <0 ) + i++; + +if (i +1 < symbols_count && +bfd_asymbol_section (symbols[i +1 ]) == section) + len = symbols[i +1 ]->value - sym->value; +else + len = section->size - sym->value; + + start =bfd_asymbol_value (sym) - dso->text_offset; + symbol =symbol__new (start, len,bfd2elf_binding (sym),STT_FUNC , +bfd_asymbol_name (sym)); +if (!symbol) + goto out_free; + +symbols__insert (&dso->symbols, symbol); + } +#ifdef bfd_get_section +#undef bfd_asymbol_section +#endif + +symbols__fixup_end (&dso->symbols); +symbols__fixup_duplicate (&dso->symbols); + dso->adjust_symbols =1 ; + + err =0 ; +out_free: +free (symbols); +out_close: +bfd_close (abfd); +return err; +} +#endif +static bool dso__is_compatible_symtab_type (struct dso *dso,bool kmod,enum dso_binary_type type) {
@@ -1698,6 +1830,7 @@ int dso__load(struct dso *dso, struct map *map)bool next_slot = false;bool is_reg;bool nsexit; +int bfdrc =-1 ;int sirc =-1 ;enum dso_binary_type symtab_type = binary_type_symtab[i];
@@ -1716,12 +1849,19 @@ int dso__load(struct dso *dso, struct map *map)nsinfo__mountns_exit (&nsc); is_reg =is_regular_file (name); +#ifdef HAVE_LIBBFD_SUPPORT if (is_reg) + bfdrc =dso__load_bfd_symbols (dso, name); +#endif +if (is_reg && bfdrc <0 ) sirc =symsrc__init (ss, dso, name, symtab_type);if (nsexit)nsinfo__mountns_enter (dso->nsinfo, &nsc); +if (bfdrc ==0 ) +break ; +if (!is_reg || sirc <0 )continue ;
tools/perf/util/symbol.h +4 -0
@@ -175,6 +175,10 @@ 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.28.0
PATCH v3 3/3 perf tests: Add test for PE binary format support
In reply to Remi BernonThis adds a precompiled file in PE binary format, with split debug file, and tries to read its build_id and .gnu_debuglink sections, as well as looking up the main symbol from the debug file. This should succeed if libbfd is supported.
---
v3: Add a dso != NULL check after dso__new.
tools/perf/Makefile.perf | 1 + tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 4 ++ tools/perf/tests/pe-file-parsing.c | 98 +++++++++++++++++++++++++++++ tools/perf/tests/pe-file.c | 14 +++++ tools/perf/tests/pe-file.exe | Bin 0 -> 75595 bytes tools/perf/tests/pe-file.exe.debug | Bin 0 -> 141644 bytes tools/perf/tests/tests.h | 1 + 8 files changed, 119 insertions(+) create mode 100644 tools/perf/tests/pe-file-parsing.c create mode 100644 tools/perf/tests/pe-file.c create mode 100644 tools/perf/tests/pe-file.exe create mode 100644 tools/perf/tests/pe-file.exe.debug
tools/perf/Makefile.perf +1 -0
@@ -961,6 +961,7 @@ install-tests: all install-gtk $(call QUIET_INSTALL, tests) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ + $(INSTALL) tests/pe-file.exe* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ $(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/shell'; \
tools/perf/tests/Build +1 -0
@@ -60,6 +60,7 @@ perf-y += api-io.o perf-y += demangle-java-test.o perf-y += pfm.o perf-y += parse-metric.o +perf-y += pe-file-parsing.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir)
tools/perf/tests/builtin-test.c +4 -0
@@ -341,6 +341,10 @@ static struct test generic_tests[] = { .desc = "Parse and process metrics", .func = test__parse_metric, }, + { + .desc = "PE file support", + .func = test__pe_file_parsing, + }, { .func = NULL, },
tools/perf/tests/pe-file-parsing.c new file +98 -0
98 lines not on this page · raw message
tools/perf/tests/pe-file.c new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 + +// pe-file.exe and pe-file.exe.debug built with; +// x86_64-w64-mingw32-gcc -o pe-file.exe pe-file.c +// -Wl,--file-alignment,4096 -Wl,--build-id +// x86_64-w64-mingw32-objcopy --only-keep-debug +// --compress-debug-sections pe-file.exe pe-file.exe.debug +// x86_64-w64-mingw32-objcopy --strip-debug +// --add-gnu-debuglink=pe-file.exe.debug pe-file.exe + +int main (int argc,char const *argv[]) +{ +return 0 ; +}
tools/perf/tests/pe-file.exe new file binary +0 -0
tools/perf/tests/pe-file.exe.debug new file binary +0 -0
tools/perf/tests/tests.h +1 -0
@@ -122,6 +122,7 @@ int test__pfm(struct test *test, int subtest);const char *test__pfm_subtest_get_desc (int subtest);int test__pfm_subtest_get_nr (void );int test__parse_metric (struct test *test,int subtest); +int test__pe_file_parsing (struct test *test,int subtest);bool test__bp_signal_is_supported (void );bool test__bp_account_is_supported (void );
Signature · 1 line
2.28.0
Quoted 15 lines · Remi Bernon
Wine generates PE binaries for most of its modules and perf is unable to parse these files to get
build_idor .gnu_debuglink section.Using libbfd when available, instead of libelf, makes it possible to resolve debug file location regardless of the dso binary format.
Signed-off-by Remi Bernon <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Mark Rutland <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jacek Caban <[email protected]>
Quoted 3 lines
---
v3: Rebase and small changes to PATCH 2/3 and and PATCH 3/3.
all 3 patches look ok to me especially since I found out the new code for loading symbols is for non ELF objects only ;-)
it'd be great if somebody with libbfd skills could review this, but for me it looks ok.. for patchset:
thanks,
jirka
Quoted 133 lines
tools/perf/util/symbol-elf.c | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)tools/perf/util/symbol-elf.c +77
-3@@ -50,6 +50,10 @@ typedef Elf64_Nhdr GElf_Nhdr;#define DMGL_ANSI (1 << 1)/* Include const, volatile, etc */ #endif +#ifdef HAVE_LIBBFD_SUPPORT +#define PACKAGE 'perf' +#include <bfd.h> +#else #ifdef HAVE_CPLUS_DEMANGLE_SUPPORT extern char *cplus_demangle (const char *,int );@@ -65,9 +69,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, {return NULL ; } -#else -#define PACKAGE 'perf' -#include <bfd.h> +#endif #endif #endif @@ -530,6 +532,36 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_build_id (const char *filename,void *bf,size_t size) +{ +int err =-1 ; +bfd *abfd; + + abfd =bfd_openr (filename,NULL ); +if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + +if (!abfd->build_id || abfd->build_id->size > size) + goto out_close; + +memcpy (bf, abfd->build_id->data, abfd->build_id->size); +memset (bf + abfd->build_id->size,0 , size - abfd->build_id->size); + err = abfd->build_id->size; + +out_close: +bfd_close (abfd); +return err; +} + +#else +int filename__read_build_id (const char *filename,void *bf,size_t size) {int fd, err =-1 ;@@ -557,6 +589,8 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) return err; } +#endif +int sysfs__read_build_id (const char *filename,void *build_id,size_t size) {int fd, err =-1 ;@@ -608,6 +642,44 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_debuglink (const char *filename,char *debuglink, +size_t size) +{ +int err =-1 ; +asection *section; +bfd *abfd; + + abfd =bfd_openr (filename,NULL ); +if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + + section =bfd_get_section_by_name (abfd,".gnu_debuglink" ); +if (!section) + goto out_close; + +if (section->size > size) + goto out_close; + +if (!bfd_get_section_contents (abfd, section, debuglink,0 , + section->size)) + goto out_close; + + err =0 ; + +out_close: +bfd_close (abfd); +return err; +} + +#else +int filename__read_debuglink (const char *filename,char *debuglink,size_t size) {@@ -660,6 +732,8 @@ int filename__read_debuglink(const char *filename, char *debuglink, return err; } +#endif +static int dso__swap_init (struct dso *dso,unsigned char eidata) {static unsigned int const endian =1 ;Signature · 1 line
2.28.0
Arnaldo Carvalho de Melo
maintainerEm Fri, Aug 21, 2020 at 06:52:36PM +0200, Remi Bernon escreveu:
Quoted 27 lines
Wine generates PE binaries for most of its modules and perf is unable to parse these files to get
build_idor .gnu_debuglink section.Using libbfd when available, instead of libelf, makes it possible to resolve debug file location regardless of the dso binary format.
Signed-off-by Remi Bernon <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Mark Rutland <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jacek Caban <[email protected]>---
v3: Rebase and small changes to PATCH 2/3 and and PATCH 3/3.
tools/perf/util/symbol-elf.c | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)tools/perf/util/symbol-elf.c +0
-0
tools/perf/util/symbol-elf.c typedef Elf64_Nhdr GElf_Nhdr; · line 53
Quoted 4 lines
tools/perf/util/symbol-elf.c +1
-0@@ -50,6 +50,10 @@ typedef Elf64_Nhdr GElf_Nhdr;#define DMGL_ANSI (1 << 1)/* Include const, volatile, etc */ #endif +#ifdef HAVE_LIBBFD_SUPPORT
So, the feature test should also test for the buildid struct field, see below:
Quoted 29 lines
tools/perf/util/symbol-elf.c +12
-3+#define PACKAGE 'perf' +#include <bfd.h> +#else #ifdef HAVE_CPLUS_DEMANGLE_SUPPORT extern char *cplus_demangle (const char *,int );@@ -65,9 +69,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, {return NULL ; } -#else -#define PACKAGE 'perf' -#include <bfd.h> +#endif #endif #endif @@ -530,6 +532,36 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_build_id (const char *filename,void *bf,size_t size) +{ +int err =-1 ; +bfd *abfd; + + abfd =bfd_openr (filename,NULL );
tools/perf/util/symbol-elf.c static int elf_read_build_id(Elf *elf, void *bf, size_t size) · line 552
Quoted 10 lines
tools/perf/util/symbol-elf.c +10
-0+if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + +if (!abfd->build_id || abfd->build_id->size > size) + goto out_close;
amazonlinux:1, centos:6, debian:8, mageia:5, oraclelinux:6, ubuntu:14.04 fail, its all old stuff, but adding a reference to abfd->build_id to the feature test that ends up defining HAVE_LIBBFD_SUPPORT will solve that, I'll do it tomorrow morning if you don't beat me to it.
util/symbol-elf.c: In function 'filename__read_build_id':util/symbol-elf.c:551:11: error: 'bfd {aka struct bfd}' has no member named 'build_id'
if (!abfd->build_id || abfd->build_id->size > size)
^~
util/symbol-elf.c:551:29: error: 'bfd {aka struct bfd}' has no member named 'build_id'
if (!abfd->build_id || abfd->build_id->size > size)
^~
util/symbol-elf.c:554:17: error: 'bfd {aka struct bfd}' has no member named 'build_id'
memcpy(bf, abfd->build_id->data, abfd->build_id->size);
^~
util/symbol-elf.c:554:39: error: 'bfd {aka struct bfd}' has no member named 'build_id'
memcpy(bf, abfd->build_id->data, abfd->build_id->size);
^~
util/symbol-elf.c:555:18: error: 'bfd {aka struct bfd}' has no member named 'build_id'
memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size);
^~
util/symbol-elf.c:555:50: error: 'bfd {aka struct bfd}' has no member named 'build_id'
memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size);
^~
util/symbol-elf.c:556:12: error: 'bfd {aka struct bfd}' has no member named 'build_id'
err = abfd->build_id->size;
^~ CC /tmp/build/perf/util/cap.o
make[4]: *** [/tmp/build/perf/util/symbol-elf.o] Error 1 make[4]: *** Waiting for unfinished jobs....
LD /tmp/build/perf/util/scripting-engines/perf-in.o
LD /tmp/build/perf/util/intel-pt-decoder/perf-in.o
make[3]: *** [util] Error 2
make[2]: *** [/tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/git/linux/tools/perf'
+ exit 1
[perfbuilder@five ~]$
Arnaldo Carvalho de Melo
maintainerEm Wed, Sep 02, 2020 at 09:25:19PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 103 lines
Em Fri, Aug 21, 2020 at 06:52:36PM +0200, Remi Bernon escreveu:
Quoted 27 lines
Wine generates PE binaries for most of its modules and perf is unable to parse these files to get
build_idor .gnu_debuglink section.Using libbfd when available, instead of libelf, makes it possible to resolve debug file location regardless of the dso binary format.
Signed-off-by Remi Bernon <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Mark Rutland <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jacek Caban <[email protected]>---
v3: Rebase and small changes to PATCH 2/3 and and PATCH 3/3.
tools/perf/util/symbol-elf.c | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)tools/perf/util/symbol-elf.c +0
-0tools/perf/util/symbol-elf.c typedef Elf64_Nhdr GElf_Nhdr; · line 53
Quoted 4 lines
tools/perf/util/symbol-elf.c +1
-0@@ -50,6 +50,10 @@ typedef Elf64_Nhdr GElf_Nhdr;#define DMGL_ANSI (1 << 1)/* Include const, volatile, etc */ #endif +#ifdef HAVE_LIBBFD_SUPPORT So, the feature test should also test for the buildid struct field, see below:
Quoted 29 lines
tools/perf/util/symbol-elf.c +12
-3+#define PACKAGE 'perf' +#include <bfd.h> +#else #ifdef HAVE_CPLUS_DEMANGLE_SUPPORT extern char *cplus_demangle (const char *,int );@@ -65,9 +69,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, {return NULL ; } -#else -#define PACKAGE 'perf' -#include <bfd.h> +#endif #endif #endif @@ -530,6 +532,36 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_build_id (const char *filename,void *bf,size_t size) +{ +int err =-1 ; +bfd *abfd; + + abfd =bfd_openr (filename,NULL );tools/perf/util/symbol-elf.c static int elf_read_build_id(Elf *elf, void *bf, size_t size) · line 552
Quoted 10 lines
tools/perf/util/symbol-elf.c +10
-0+if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + +if (!abfd->build_id || abfd->build_id->size > size) + goto out_close;amazonlinux:1, centos:6, debian:8, mageia:5, oraclelinux:6, ubuntu:14.04 fail, its all old stuff, but adding a reference to
abfd->build_idto the feature test that ends up definingHAVE_LIBBFD_SUPPORTwill solve that, I'll do it tomorrow morning if you don't beat me to it.
util/symbol-elf.c: In function 'filename__read_build_id':util/symbol-elf.c:551:11: error: 'bfd {aka struct bfd}' has no member named 'build_id'
if (!abfd->build_id ||abfd->build_id->size> size)^~ util/symbol-elf.c:551:29: error: 'bfd {aka struct bfd}' has no member named 'build_id' if (!abfd->build_id || abfd->build_id->size > size) ^~ util/symbol-elf.c:554:17: error: 'bfd {aka struct bfd}' has no member named 'build_id' memcpy(bf, abfd->build_id->data, abfd->build_id->size); ^~ util/symbol-elf.c:554:39: error: 'bfd {aka struct bfd}' has no member named 'build_id' memcpy(bf, abfd->build_id->data, abfd->build_id->size); ^~ util/symbol-elf.c:555:18: error: 'bfd {aka struct bfd}' has no member named 'build_id' memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size); ^~ util/symbol-elf.c:555:50: error: 'bfd {aka struct bfd}' has no member named 'build_id' memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size); ^~ util/symbol-elf.c:556:12: error: 'bfd {aka struct bfd}' has no member named 'build_id' err = abfd->build_id->size; ^~
Quoted 13 lines
CC
/tmp/build/perf/util/cap.o
make[4]: *** [/tmp/build/perf/util/symbol-elf.o] Error 1 make[4]: *** Waiting for unfinished jobs....
LD/tmp/build/perf/util/scripting-engines/perf-in.o
LD/tmp/build/perf/util/intel-pt-decoder/perf-in.o
make[3]: *** [util] Error 2
make[2]: *** [/tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/git/linux/tools/perf'
+ exit 1
[perfbuilder@five ~]$
So, I have the cset at the end of this message in front of your series + the following patch applied to your patch, the debuglink part seems ok and can continue depending on just libbfd, having or not abfd->buildid.
- Arnaldo
tools/perf/util/symbol-elf.c +3 -3
@@ -532,7 +532,7 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } -#ifdef HAVE_LIBBFD_SUPPORT +#ifdef HAVE_LIBBFD_BUILDID_SUPPORT int filename__read_build_id (const char *filename,void *bf,size_t size) {
@@ -560,7 +560,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) return err; } -#else +#else // HAVE_LIBBFD_BUILDID_SUPPORT int filename__read_build_id (const char *filename,void *bf,size_t size) {
@@ -589,7 +589,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size) return err; } -#endif +#endif // HAVE_LIBBFD_BUILDID_SUPPORT int sysfs__read_build_id (const char *filename,void *build_id,size_t size) {
Quoted 118 lines · Arnaldo Carvalho de Melo
Em Wed, Sep 02, 2020 at 09:25:19PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 103 lines
Em Fri, Aug 21, 2020 at 06:52:36PM +0200, Remi Bernon escreveu:
Quoted 27 lines
Wine generates PE binaries for most of its modules and perf is unable to parse these files to get
build_idor .gnu_debuglink section.Using libbfd when available, instead of libelf, makes it possible to resolve debug file location regardless of the dso binary format.
Signed-off-by Remi Bernon <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Mark Rutland <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jacek Caban <[email protected]>---
v3: Rebase and small changes to PATCH 2/3 and and PATCH 3/3.
tools/perf/util/symbol-elf.c | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)tools/perf/util/symbol-elf.c +0
-0tools/perf/util/symbol-elf.c typedef Elf64_Nhdr GElf_Nhdr; · line 53
Quoted 4 lines
tools/perf/util/symbol-elf.c +1
-0@@ -50,6 +50,10 @@ typedef Elf64_Nhdr GElf_Nhdr;#define DMGL_ANSI (1 << 1)/* Include const, volatile, etc */ #endif +#ifdef HAVE_LIBBFD_SUPPORT So, the feature test should also test for the buildid struct field, see below:
Quoted 29 lines
tools/perf/util/symbol-elf.c +12
-3+#define PACKAGE 'perf' +#include <bfd.h> +#else #ifdef HAVE_CPLUS_DEMANGLE_SUPPORT extern char *cplus_demangle (const char *,int );@@ -65,9 +69,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, {return NULL ; } -#else -#define PACKAGE 'perf' -#include <bfd.h> +#endif #endif #endif @@ -530,6 +532,36 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_build_id (const char *filename,void *bf,size_t size) +{ +int err =-1 ; +bfd *abfd; + + abfd =bfd_openr (filename,NULL );tools/perf/util/symbol-elf.c static int elf_read_build_id(Elf *elf, void *bf, size_t size) · line 552
Quoted 10 lines
tools/perf/util/symbol-elf.c +10
-0+if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + +if (!abfd->build_id || abfd->build_id->size > size) + goto out_close;amazonlinux:1, centos:6, debian:8, mageia:5, oraclelinux:6, ubuntu:14.04 fail, its all old stuff, but adding a reference to
abfd->build_idto the feature test that ends up definingHAVE_LIBBFD_SUPPORTwill solve that, I'll do it tomorrow morning if you don't beat me to it.
util/symbol-elf.c: In function 'filename__read_build_id':util/symbol-elf.c:551:11: error: 'bfd {aka struct bfd}' has no member named 'build_id'
if (!abfd->build_id ||abfd->build_id->size> size)^~ util/symbol-elf.c:551:29: error: 'bfd {aka struct bfd}' has no member named 'build_id' if (!abfd->build_id || abfd->build_id->size > size) ^~ util/symbol-elf.c:554:17: error: 'bfd {aka struct bfd}' has no member named 'build_id' memcpy(bf, abfd->build_id->data, abfd->build_id->size); ^~ util/symbol-elf.c:554:39: error: 'bfd {aka struct bfd}' has no member named 'build_id' memcpy(bf, abfd->build_id->data, abfd->build_id->size); ^~ util/symbol-elf.c:555:18: error: 'bfd {aka struct bfd}' has no member named 'build_id' memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size); ^~ util/symbol-elf.c:555:50: error: 'bfd {aka struct bfd}' has no member named 'build_id' memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size); ^~ util/symbol-elf.c:556:12: error: 'bfd {aka struct bfd}' has no member named 'build_id' err = abfd->build_id->size; ^~Quoted 13 lines
CC
/tmp/build/perf/util/cap.o
make[4]: *** [/tmp/build/perf/util/symbol-elf.o] Error 1 make[4]: *** Waiting for unfinished jobs....
LD/tmp/build/perf/util/scripting-engines/perf-in.o
LD/tmp/build/perf/util/intel-pt-decoder/perf-in.o
make[3]: *** [util] Error 2
make[2]: *** [/tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/git/linux/tools/perf'
+ exit 1
[perfbuilder@five ~]$
Quoted 4 lines
So, I have the cset at the end of this message in front of your series + the following patch applied to your patch, the debuglink part seems ok and can continue depending on just libbfd, having or not
abfd->buildid.
Thanks! I may have missed the first changeset you mention -- IIUC the one adding the feature check -- but it sounds good to me nonetheless.
Should I do anything?
Signature · 1 line
Rémi Bernon <[email protected]>
Arnaldo Carvalho de Melo
maintainerEm Fri, Sep 04, 2020 at 09:57:33AM +0200, Remi Bernon escreveu:
Quoted 120 lines · Arnaldo Carvalho de Melo
Quoted 114 lines
Em Wed, Sep 02, 2020 at 09:25:19PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 99 lines
Em Fri, Aug 21, 2020 at 06:52:36PM +0200, Remi Bernon escreveu:
Quoted 27 lines
Wine generates PE binaries for most of its modules and perf is unable to parse these files to get
build_idor .gnu_debuglink section.Using libbfd when available, instead of libelf, makes it possible to resolve debug file location regardless of the dso binary format.
Signed-off-by Remi Bernon <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Mark Rutland <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Jacek Caban <[email protected]>---
v3: Rebase and small changes to PATCH 2/3 and and PATCH 3/3.
tools/perf/util/symbol-elf.c | 80 ++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)tools/perf/util/symbol-elf.c +0
-0tools/perf/util/symbol-elf.c typedef Elf64_Nhdr GElf_Nhdr; · line 52
Quoted 3 lines
tools/perf/util/symbol-elf.c +1
-0@@ -50,6 +50,10 @@ typedef Elf64_Nhdr GElf_Nhdr;#define DMGL_ANSI (1 << 1)/* Include const, volatile, etc */ #endif +#ifdef HAVE_LIBBFD_SUPPORT So, the feature test should also test for the buildid struct field, see below:
Quoted 26 lines
tools/perf/util/symbol-elf.c +12
-3+#define PACKAGE 'perf' +#include <bfd.h> +#else #ifdef HAVE_CPLUS_DEMANGLE_SUPPORT extern char *cplus_demangle (const char *,int );@@ -65,9 +69,7 @@ static inline char *bfd_demangle(void __maybe_unused *v, {return NULL ; } -#else -#define PACKAGE 'perf' -#include <bfd.h> +#endif #endif #endif @@ -530,6 +532,36 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)return err; } +#ifdef HAVE_LIBBFD_SUPPORT + +int filename__read_build_id (const char *filename,void *bf,size_t size) +{ +int err =-1 ; +bfd *abfd; + + abfd =bfd_openr (filename,NULL );tools/perf/util/symbol-elf.c static int elf_read_build_id(Elf *elf, void *bf, size_t size) · line 551
Quoted 10 lines
tools/perf/util/symbol-elf.c +10
-0+if (!abfd) +return -1 ; + +if (!bfd_check_format (abfd, bfd_object)) { +pr_debug2 ("%s: cannot read %s bfd file.\n" , __func__, filename); + goto out_close; + } + +if (!abfd->build_id || abfd->build_id->size > size) + goto out_close;amazonlinux:1, centos:6, debian:8, mageia:5, oraclelinux:6, ubuntu:14.04 fail, its all old stuff, but adding a reference to
abfd->build_idto the feature test that ends up definingHAVE_LIBBFD_SUPPORTwill solve that, I'll do it tomorrow morning if you don't beat me to it.
util/symbol-elf.c: In function 'filename__read_build_id':util/symbol-elf.c:551:11: error: 'bfd {aka struct bfd}' has no member named 'build_id'
if (!abfd->build_id ||abfd->build_id->size> size)^~ util/symbol-elf.c:551:29: error: 'bfd {aka struct bfd}' has no member named 'build_id' if (!abfd->build_id || abfd->build_id->size > size) ^~ util/symbol-elf.c:554:17: error: 'bfd {aka struct bfd}' has no member named 'build_id' memcpy(bf, abfd->build_id->data, abfd->build_id->size); ^~ util/symbol-elf.c:554:39: error: 'bfd {aka struct bfd}' has no member named 'build_id' memcpy(bf, abfd->build_id->data, abfd->build_id->size); ^~ util/symbol-elf.c:555:18: error: 'bfd {aka struct bfd}' has no member named 'build_id' memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size); ^~ util/symbol-elf.c:555:50: error: 'bfd {aka struct bfd}' has no member named 'build_id' memset(bf + abfd->build_id->size, 0, size - abfd->build_id->size); ^~ util/symbol-elf.c:556:12: error: 'bfd {aka struct bfd}' has no member named 'build_id' err = abfd->build_id->size; ^~Quoted 13 lines
CC
/tmp/build/perf/util/cap.o
make[4]: *** [/tmp/build/perf/util/symbol-elf.o] Error 1 make[4]: *** Waiting for unfinished jobs....
LD/tmp/build/perf/util/scripting-engines/perf-in.o
LD/tmp/build/perf/util/intel-pt-decoder/perf-in.o
make[3]: *** [util] Error 2
make[2]: *** [/tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [sub-make] Error 2
make: *** [all] Error 2
make: Leaving directory `/git/linux/tools/perf'
+ exit 1
[perfbuilder@five ~]$Quoted 4 lines
So, I have the cset at the end of this message in front of your series + the following patch applied to your patch, the debuglink part seems ok and can continue depending on just libbfd, having or not
abfd->buildid.
Quoted 4 lines
Thanks! I may have missed the first changeset you mention -- IIUC the one adding the feature check -- but it sounds good to me nonetheless.
Should I do anything?
No need at this time, here is the new feature test that ends up being used to check if that abfd->build_id is present:
[acme@five perf]$ git log torvalds/master.. --onelined39497a94c1672c2 (HEAD -> perf/core) perf: ftrace: Add filter support for option -F/--funcs 6330d59303482407 perf tools: Consolidate close_control_option()'s into one function bd0c035c66c933ee perf intel-pt: Document snapshot control command 7f5b197269a34f9a perf annotate: Add 'ret' (intel disasm style) as an alias for 'retq' 2481b0089bddb6b6 perf annotate: Allow configuring the 'disassembler_style' knob via 'perf config' d20aff1512f013fa (quaco/perf/core) perf record: Add 'snapshot' control command a8fcbd269b4340c3 perf tools: Add FIFO file names as alternative options to --control 1f4390d825cc04e9 perf tools: Use AsciiDoc formatting for --control option documentation 40db8ff59e75af10 perf tools: Handle read errors from ctl_fd9864a66defeb8df0 perf tools: Consolidate --control option parsing into one function ed21d6d7c48e6e96 perf tests: Add test for PE binary format support eac9a4342e5447ca perf symbols: Try reading the symbol table with libbfd ba0509dcb7f80640 perf dso: Use libbfd to read build_id and .gnu_debuglink section e71e19a9ea70952a tools features: Add feature test to check if libbfd has buildid support [acme@five perf]$
$ git show e71e19a9ea70952a commit e71e19a9ea70952a53d58a99971820ce6c1794a8 Author: Arnaldo Carvalho de Melo <[email protected]> Date: Thu Sep 3 13:44:39 2020 -0300
tools features: Add feature test to check if libbfd has buildid support
Which is needed by the PE executable support, for instance.
tools/build/Makefile.feature +2 -0
@@ -41,6 +41,7 @@ FEATURE_TESTS_BASIC := \ gtk2 \ gtk2-infobar \ libbfd \ + libbfd-buildid \ libcap \ libelf \ libelf-getphdrnum \
@@ -113,6 +114,7 @@ FEATURE_DISPLAY ?= \ glibc \ gtk2 \ libbfd \ + libbfd-buildid \ libcap \ libelf \ libnuma \
tools/build/feature/Makefile +4 -0
@@ -15,6 +15,7 @@ FILES= \ test-hello.bin \ test-libaudit.bin \ test-libbfd.bin \ + test-libbfd-buildid.bin \ test-disassembler-four-args.bin \ test-reallocarray.bin \ test-libbfd-liberty.bin \
@@ -229,6 +230,9 @@ $(OUTPUT)test-libpython-version.bin: $(OUTPUT)test-libbfd.bin: $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl +$(OUTPUT)test-libbfd-buildid.bin: + $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl + $(OUTPUT)test-disassembler-four-args.bin: $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes
tools/build/feature/test-all.c +5 -0
@@ -90,6 +90,10 @@# include "test-libbfd.c" #undef main +#define main main_test_libbfd_buildid +# include "test-libbfd-buildid.c" +#undef main +#define main main_test_backtrace# include "test-backtrace.c" #undef main
@@ -208,6 +212,7 @@ int main(int argc, char *argv[])main_test_gtk2 (argc, argv);main_test_gtk2_infobar (argc, argv);main_test_libbfd (); +main_test_libbfd_buildid ();main_test_backtrace ();main_test_libnuma ();main_test_numa_num_possible_cpus ();
tools/build/feature/test-libbfd-buildid.c new file +8 -0
@@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <bfd.h> + +int main (void ) +{ +bfd *abfd =bfd_openr ("Pedro" ,0 ); +return abfd && (!abfd->build_id || abfd->build_id->size >0x506564726f ); +}
tools/perf/Makefile.config +6 -0
@@ -825,6 +825,12 @@ else $(call feature_check,disassembler-four-args) endif +ifeq ($(feature-libbfd-buildid), 1) + CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT +else + msg := $(warning Old version of libbfd/binutils things like PE executable profiling will not be available); +endif + ifdef NO_DEMANGLE CFLAGS += -DNO_DEMANGLE else