From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Milian Wolff <milian.wolff@kdab.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf symbols: Demangle symbols for synthesized @plt entries.
Date: Tue, 30 Aug 2016 10:17:33 -0300 [thread overview]
Message-ID: <20160830131733.GA11113@kernel.org> (raw)
In-Reply-To: <20160830114102.30863-1-milian.wolff@kdab.com>
Em Tue, Aug 30, 2016 at 01:41:02PM +0200, Milian Wolff escreveu:
> The symbols in the synthesized @plt entries where not demangled
> before, i.e. we could end up with entries such as:
Thanks, applied.
Please CC linux-kernel@vger.kernel.org for wider exposure, as there are
many perf users (and developers) that don't subscribe to this list.
- Arnaldo
> $ perf report
> Samples: 7K of event 'cycles:ppp', Event count (approx.): 6223833141
> Children Self Command Shared Object Symbol
> - 93.63% 28.89% lab_mandelbrot lab_mandelbrot [.] main
> - 73.81% main
> - 33.57% hypot
> 27.76% __hypot_finite
> 15.97% __muldc3
> 2.90% __muldc3@plt
> 2.40% _ZNK6QImage6heightEv@plt
> + 2.14% QColor::rgb
> 1.94% _ZNK6QImage5widthEv@plt
> 1.92% cabs@plt
>
> This patch remedies this issue by also applying demangling to the
> synthesized symbols. The output for the above is now:
>
> $ perf report
> Samples: 7K of event 'cycles:ppp', Event count (approx.): 6223833141
> Children Self Command Shared Object Symbol
> - 93.63% 28.89% lab_mandelbrot lab_mandelbrot [.] main
> - 73.81% main
> - 33.57% hypot
> 27.76% __hypot_finite
> 15.97% __muldc3
> 2.90% __muldc3@plt
> 2.40% QImage::height() const@plt
> + 2.14% QColor::rgb
> 1.94% QImage::width() const@plt
> 1.92% cabs@plt
>
> Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> ---
> tools/perf/util/symbol-elf.c | 81 ++++++++++++++++++++++++++++----------------
> 1 file changed, 52 insertions(+), 29 deletions(-)
>
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index a811c13..fbe31ef 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -206,6 +206,37 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
> return NULL;
> }
>
> +static bool want_demangle(bool is_kernel_sym)
> +{
> + return is_kernel_sym ? symbol_conf.demangle_kernel : symbol_conf.demangle;
> +}
> +
> +static char *demangle_sym(struct dso *dso, int kmodule, const char *elf_name)
> +{
> + int demangle_flags = verbose ? (DMGL_PARAMS | DMGL_ANSI) : DMGL_NO_OPTS;
> + char *demangled = NULL;
> +
> + /*
> + * We need to figure out if the object was created from C++ sources
> + * DWARF DW_compile_unit has this, but we don't always have access
> + * to it...
> + */
> + if (!want_demangle(dso->kernel || kmodule))
> + return demangled;
> +
> + demangled = bfd_demangle(NULL, elf_name, demangle_flags);
> + if (demangled == NULL)
> + demangled = java_demangle_sym(elf_name, JAVA_DEMANGLE_NORET);
> + else if (rust_is_mangled(demangled))
> + /*
> + * Input to Rust demangling is the BFD-demangled
> + * name which it Rust-demangles in place.
> + */
> + rust_demangle_sym(demangled);
> +
> + return demangled;
> +}
> +
> #define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \
> for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \
> idx < nr_entries; \
> @@ -301,11 +332,19 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, struct map *
>
> elf_section__for_each_rela(reldata, pos, pos_mem, idx,
> nr_rel_entries) {
> + const char *elf_name = NULL;
> + char *demangled = NULL;
> symidx = GELF_R_SYM(pos->r_info);
> plt_offset += shdr_plt.sh_entsize;
> gelf_getsym(syms, symidx, &sym);
> +
> + elf_name = elf_sym__name(&sym, symstrs);
> + demangled = demangle_sym(dso, 0, elf_name);
> + if (demangled != NULL)
> + elf_name = demangled;
> snprintf(sympltname, sizeof(sympltname),
> - "%s@plt", elf_sym__name(&sym, symstrs));
> + "%s@plt", elf_name);
> + free(demangled);
>
> f = symbol__new(plt_offset, shdr_plt.sh_entsize,
> STB_GLOBAL, sympltname);
> @@ -323,11 +362,19 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, struct map *
> GElf_Rel pos_mem, *pos;
> elf_section__for_each_rel(reldata, pos, pos_mem, idx,
> nr_rel_entries) {
> + const char *elf_name = NULL;
> + char *demangled = NULL;
> symidx = GELF_R_SYM(pos->r_info);
> plt_offset += shdr_plt.sh_entsize;
> gelf_getsym(syms, symidx, &sym);
> +
> + elf_name = elf_sym__name(&sym, symstrs);
> + demangled = demangle_sym(dso, 0, elf_name);
> + if (demangled != NULL)
> + elf_name = demangled;
> snprintf(sympltname, sizeof(sympltname),
> - "%s@plt", elf_sym__name(&sym, symstrs));
> + "%s@plt", elf_name);
> + free(demangled);
>
> f = symbol__new(plt_offset, shdr_plt.sh_entsize,
> STB_GLOBAL, sympltname);
> @@ -775,11 +822,6 @@ static u64 ref_reloc(struct kmap *kmap)
> return 0;
> }
>
> -static bool want_demangle(bool is_kernel_sym)
> -{
> - return is_kernel_sym ? symbol_conf.demangle_kernel : symbol_conf.demangle;
> -}
> -
> void __weak arch__sym_update(struct symbol *s __maybe_unused,
> GElf_Sym *sym __maybe_unused) { }
>
> @@ -1070,29 +1112,10 @@ int dso__load_sym(struct dso *dso, struct map *map,
> sym.st_value -= shdr.sh_addr - shdr.sh_offset;
> }
> new_symbol:
> - /*
> - * We need to figure out if the object was created from C++ sources
> - * DWARF DW_compile_unit has this, but we don't always have access
> - * to it...
> - */
> - if (want_demangle(dso->kernel || kmodule)) {
> - int demangle_flags = DMGL_NO_OPTS;
> - if (verbose)
> - demangle_flags = DMGL_PARAMS | DMGL_ANSI;
> -
> - demangled = bfd_demangle(NULL, elf_name, demangle_flags);
> - if (demangled == NULL)
> - demangled = java_demangle_sym(elf_name, JAVA_DEMANGLE_NORET);
> - else if (rust_is_mangled(demangled))
> - /*
> - * Input to Rust demangling is the BFD-demangled
> - * name which it Rust-demangles in place.
> - */
> - rust_demangle_sym(demangled);
> + demangled = demangle_sym(dso, kmodule, elf_name);
> + if (demangled != NULL)
> + elf_name = demangled;
>
> - if (demangled != NULL)
> - elf_name = demangled;
> - }
> f = symbol__new(sym.st_value, sym.st_size,
> GELF_ST_BIND(sym.st_info), elf_name);
> free(demangled);
> --
> 2.9.3
next prev parent reply other threads:[~2016-08-30 13:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-30 11:41 [PATCH] perf symbols: Demangle symbols for synthesized @plt entries Milian Wolff
2016-08-30 13:17 ` Arnaldo Carvalho de Melo [this message]
2016-08-30 14:42 ` Milian Wolff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160830131733.GA11113@kernel.org \
--to=acme@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=milian.wolff@kdab.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).