All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 3/3] perf tools: adjust symbol address
Date: Wed, 30 Dec 2009 11:18:55 +0800	[thread overview]
Message-ID: <4B3AC69F.4070901@cn.fujitsu.com> (raw)
In-Reply-To: <4B3AC5CD.1000502@cn.fujitsu.com>

Using relocation offset adjust symbol address if we get
kernel symbol name form elf file

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 tools/perf/builtin-record.c |    3 +++
 tools/perf/util/session.c   |    6 ++++++
 tools/perf/util/symbol.c    |   13 +++++++++++++
 tools/perf/util/symbol.h    |    2 ++
 4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d13601d..4d86969 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -436,6 +436,9 @@ static int __cmd_record(int argc, const char **argv)
 	signal(SIGCHLD, sig_handler);
 	signal(SIGINT, sig_handler);
 
+	/* Always get relocation offset */
+	inject_events |= PERF_INJECT_RELOCATE_OFFSET;
+
 	if (forks && (pipe(child_ready_pipe) < 0 || pipe(go_pipe) < 0)) {
 		perror("failed to create pipes");
 		exit(-1);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 74f43af..92d4811 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -243,6 +243,12 @@ static int perf_session__process_event(struct perf_session *self,
 	case PERF_RECORD_UNTHROTTLE:
 		return ops->unthrottle(event, self);
 	case PERF_RECORD_INJECT:
+		if (event->inject.inject_event_id ==
+		    PERF_INJECT_RELOCATE_OFFSET) {
+			update_relocate_offset((s32)event->inject.value);
+			return 0;
+		}
+
 		return ops->inject(event, self);
 	default:
 		self->unknown_events++;
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 79ca6a0..5b58d34 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -19,6 +19,18 @@
 #define NT_GNU_BUILD_ID 3
 #endif
 
+static s32 relocate_offset;
+void update_relocate_offset(s32 offset)
+{
+	relocate_offset = offset;
+}
+
+static inline void update_kernel_address(GElf_Sym *sym, bool kernel)
+{
+	if (kernel)
+		sym->st_value += relocate_offset;
+}
+
 enum dso_origin {
 	DSO__ORIG_KERNEL = 0,
 	DSO__ORIG_JAVA_JIT,
@@ -1012,6 +1024,7 @@ static int dso__load_sym(struct dso *self, struct map *map,
 		if (demangled != NULL)
 			elf_name = demangled;
 new_symbol:
+		update_kernel_address(&sym, kernel);
 		f = symbol__new(sym.st_value, sym.st_size, elf_name);
 		free(demangled);
 		if (!f)
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index f27e158..129b4ec 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -10,6 +10,8 @@
 
 #define DEBUG_CACHE_DIR ".debug"
 
+void update_relocate_offset(s32 offset);
+
 #ifdef HAVE_CPLUS_DEMANGLE
 extern char *cplus_demangle(const char *, int);
 
-- 
1.6.1.2



  parent reply	other threads:[~2009-12-30  3:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-30  3:15 [PATCH 0/3] perf_event: fix getting symbol error if kernel is relocatable Xiao Guangrong
2009-12-30  3:16 ` [PATCH 1/3] x86: record relocation offset Xiao Guangrong
2009-12-30 13:15   ` Arnaldo Carvalho de Melo
2009-12-30 19:45     ` H. Peter Anvin
2009-12-30 20:39       ` Arnaldo Carvalho de Melo
2009-12-30 21:58         ` Arnaldo Carvalho de Melo
2009-12-30 22:22           ` James Bottomley
2009-12-30  3:17 ` [PATCH 2/3] perf_event: support getting " Xiao Guangrong
2009-12-30  3:18 ` Xiao Guangrong [this message]
2009-12-30 13:10   ` [PATCH 3/3] perf tools: adjust symbol address Arnaldo Carvalho de Melo
2009-12-31  2:59     ` Xiao Guangrong
2009-12-31 10:29       ` Arnaldo Carvalho de Melo
2009-12-31 10:49         ` Xiao Guangrong
2009-12-31 11:08           ` Arnaldo Carvalho de Melo
2009-12-31 11:30             ` Xiao Guangrong

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=4B3AC69F.4070901@cn.fujitsu.com \
    --to=xiaoguangrong@cn.fujitsu.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.