public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@redhat.com>
To: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>, Ingo Molnar <mingo@elte.hu>,
	Jens Axboe <jens.axboe@oracle.com>,
	Anton Blanchard <anton@samba.org>,
	davem@davemloft.net, linux-kernel@vger.kernel.org,
	a.p.zijlstra@chello.nl, fweisbec@gmail.com,
	benh@kernel.crashing.org, penberg@cs.helsinki.fi,
	vegard.nossum@gmail.com, paulus@samba.org, williams@redhat.com
Subject: Re: [PATCH] basic perf support for sparc
Date: Sun, 2 Aug 2009 22:54:30 -0300	[thread overview]
Message-ID: <20090803015430.GG25334@ghostprotocols.net> (raw)
In-Reply-To: <20090802204701.GE25334@ghostprotocols.net>

Em Sun, Aug 02, 2009 at 05:47:01PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Sun, Aug 02, 2009 at 04:11:32PM -0400, Kyle McMartin escreveu:
> > On Sun, Aug 02, 2009 at 09:50:43PM +0200, Ingo Molnar wrote:
> > > We are sticking to a given version of the API. We could turn that 
> > > into a function pointer and fill it in during startup via dlopen(). 
> > > If it's NULL then we dont call it and assume a value of NULL.
> > > 
> > > Mind submitting such a version of your fix? It would nicely decrease 
> > > the build requirements cross section surface of perf.
> > > 
> > 
> > Assuming I remember how to use dlopen/dlsym, this might work.
> > Unfortunately I can't easily test anything this weekend, so
> > I don't actually know if it works... but it links ok.
> > 
> > cheers, Kyle
> 
> Doesn't seem to work, tried with firefox, with matching
> xulrunner-debuginfo package installed and symbols didn't got properly
> demangled, gotta be afk now, but will try to figure this out later.

The problem is that at least on f11, libbfd.so is a... linker script,
not an ELF shared library as the name seemed to imply.

But if I cheat and do a dlopen on the full name, that includes the
version, it works. Argh, I don't know why this has to be so contorted,
does anybody here understands this?

Anyway, the reworked patch below works and additionally doesn't dlopens
at each DSO, but just once and only if it finds a symbol starting with
an underscore, an heuristic to avoid loading bfd if we don't need it.

Looking at each DW_AT_language attribute in the DW_TAG_compile_unit
tags, trying to figure out if there is a C++ object in the mix seems too
much, we would have to traverse all of the compile units, touching most
of the debuginfo file :-\

- Arnaldo

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 4b20fa4..8fb2e12 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -345,7 +345,7 @@ BUILTIN_OBJS += builtin-stat.o
 BUILTIN_OBJS += builtin-top.o
 
 PERFLIBS = $(LIB_FILE)
-EXTLIBS = -lbfd -liberty
+EXTLIBS = -ldl
 
 #
 # Platform specific tweaks
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b4fe057..625f975 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -4,9 +4,9 @@
 #include "symbol.h"
 
 #include <libelf.h>
+#include <dlfcn.h>
 #include <gelf.h>
 #include <elf.h>
-#include <bfd.h>
 
 const char *sym_hist_filter;
 
@@ -512,6 +512,30 @@ out:
 	return 0;
 }
 
+static char *def_perf_bfd_demangle(void __used *v, const char __used *name,
+				   int __used opt)
+{
+	return NULL;
+}
+
+static char *(*perf_bfd_demangle)(void *v, const char *name, int opt);
+
+static void load_perf_bfd_demangle(void)
+{
+	void *handle = dlopen("libbfd-2.19.51.0.2-17.fc11.so", RTLD_NOW);
+
+	if (handle) {
+		perf_bfd_demangle = dlsym(handle, "bfd_demangle");
+		if (perf_bfd_demangle)
+			return;
+		dlclose(handle);
+	} else
+		fprintf(stderr, "%s: problems finding bfd_demangle: %s.\n",
+			__func__, dlerror());
+
+	perf_bfd_demangle = def_perf_bfd_demangle;
+}
+
 static int dso__load_sym(struct dso *self, int fd, const char *name,
 			 symbol_filter_t filter, int verbose, struct module *mod)
 {
@@ -581,7 +605,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
 	elf_symtab__for_each_symbol(syms, nr_syms, index, sym) {
 		struct symbol *f;
 		const char *name;
-		char *demangled;
+		char *demangled = NULL;
 		u64 obj_start;
 		struct section *section = NULL;
 		int is_label = elf_sym__is_label(&sym);
@@ -626,9 +650,16 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
 		 * to it...
 		 */
 		name = elf_sym__name(&sym, symstrs);
-		demangled = bfd_demangle(NULL, name, DMGL_PARAMS | DMGL_ANSI);
-		if (demangled != NULL)
-			name = demangled;
+		if (name && name[0] == '_') {
+			if (perf_bfd_demangle == NULL)
+				load_perf_bfd_demangle();
+
+			if (perf_bfd_demangle != NULL) {
+				demangled = perf_bfd_demangle(NULL, name, DMGL_PARAMS | DMGL_ANSI);
+				if (demangled != NULL)
+					name = demangled;
+			}
+		}
 
 		f = symbol__new(sym.st_value, sym.st_size, name,
 				self->sym_priv_size, obj_start, verbose);

  reply	other threads:[~2009-08-03  2:00 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-29 11:25 [PATCH] basic perf support for sparc Jens Axboe
2009-07-29 19:28 ` Jens Axboe
2009-08-01  1:14   ` Anton Blanchard
2009-08-01  8:20     ` Jens Axboe
2009-08-01 18:22       ` Arnaldo Carvalho de Melo
2009-08-02 18:41         ` Ingo Molnar
2009-08-02 19:44           ` Kyle McMartin
2009-08-02 19:50             ` Ingo Molnar
2009-08-02 20:11               ` Kyle McMartin
2009-08-02 20:33                 ` Ingo Molnar
2009-08-02 20:47                 ` Arnaldo Carvalho de Melo
2009-08-03  1:54                   ` Arnaldo Carvalho de Melo [this message]
2009-08-04  3:33                     ` Kyle McMartin
2009-08-04  9:25                     ` Ingo Molnar
2009-08-04  9:29                       ` Peter Zijlstra
2009-08-04 13:02                         ` David Miller
2009-08-04 10:32                       ` Frederic Riss
2009-08-04 10:38                         ` Peter Zijlstra
2009-08-04 11:23                           ` Frederic Riss
2009-08-04 11:28                       ` Ingo Molnar
2009-08-05 12:10             ` Peter Zijlstra
2009-08-05 12:21               ` Jens Axboe
2009-08-05 12:33                 ` Ingo Molnar
2009-08-05 12:16       ` [tip:perfcounters/urgent] perf: Auto-detect libbfd tip-bot for Peter Zijlstra
2009-08-05 14:29         ` Peter Zijlstra
2009-08-05 18:58           ` Peter Zijlstra
2009-08-02 20:17 ` [PATCH] basic perf support for sparc David Miller
2009-08-02 20:25   ` Ingo Molnar
2009-08-06  7:02   ` Jens Axboe
2009-08-12 18:06     ` David Miller
2009-08-12 18:13       ` Jens Axboe
2009-08-17  1:31     ` David Miller
2009-08-17  6:48       ` Jens Axboe
2009-08-17  7:57         ` Ingo Molnar
2009-09-04  4:37         ` David Miller
2009-09-04  5:02           ` Ingo Molnar
2009-09-04  5:09             ` David Miller
2009-09-04  5:20               ` Jens Axboe
2009-09-04  6:34                 ` Jens Axboe
2009-09-04  6:44                   ` Ingo Molnar
2009-09-04  9:57                   ` David Miller

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=20090803015430.GG25334@ghostprotocols.net \
    --to=acme@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=fweisbec@gmail.com \
    --cc=jens.axboe@oracle.com \
    --cc=kyle@mcmartin.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=vegard.nossum@gmail.com \
    --cc=williams@redhat.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