public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries.
@ 2015-11-19 19:09 Brian Robbins
  2015-11-19 19:31 ` Peter Zijlstra
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Robbins @ 2015-11-19 19:09 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: Brian Robbins, linux-kernel

Programs can execute code contained in files that don't conform
to the ELF standard.  This is common for cross-platform runtimes
that support ahead-of-time compilation.  In this case, perf is
unable to resolve addresses to symbolic names, as the format of
the mmap'd file is unknown to perf.

Make perf fallback to JIT support (/tmp/perf-%pid.map) when
resolving function names if the file containing the code is not
an ELF binary.

Signed-off-by: Brian Robbins <brianrob@microsoft.com>
---
 tools/perf/util/map.c    |  1 +
 tools/perf/util/map.h    |  1 +
 tools/perf/util/symbol.c | 33 +++++++++++++++++++++++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 4e38c39..b33d460 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -164,6 +164,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		map->ino_generation = ino_gen;
 		map->prot = prot;
 		map->flags = flags;
+		map->pid = pid;
 
 		if ((anon || no_dso) && type == MAP__FUNCTION) {
 			snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid);
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 7309d64..ba80f13 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -52,6 +52,7 @@ struct map {
 	struct dso		*dso;
 	struct map_groups	*groups;
 	atomic_t		refcnt;
+	u32			pid;
 };
 
 struct kmap {
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b4cc766..12bc2f5 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1516,7 +1516,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 	}
 
 	if (!runtime_ss && !syms_ss)
-		goto out_free;
+		goto jit_fallback;
 
 	if (runtime_ss && !syms_ss) {
 		syms_ss = runtime_ss;
@@ -1541,7 +1541,36 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 
 	for (; ss_pos > 0; ss_pos--)
 		symsrc__destroy(&ss_[ss_pos - 1]);
-out_free:
+
+jit_fallback:
+	/* If we couldn't load symbols, fall back to /tmp/perf-%pid.map. */
+	if (ret < 0) {
+		struct stat st;
+		const char *origlongname;
+		snprintf(name, PATH_MAX, "/tmp/perf-%d.map", map->pid);
+
+		if (lstat(name, &st) < 0)
+			goto out;
+
+		if (st.st_uid && (st.st_uid != geteuid())) {
+			pr_warning("File %s not owned by current user or root, "
+				"ignoring it.\n", name);
+			goto out;
+		}
+
+		origlongname = dso->long_name;
+		dso->long_name = name;
+
+		ret = dso__load_perf_map(dso, map, filter);
+
+		dso->long_name = origlongname;
+		dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
+					     DSO_BINARY_TYPE__NOT_FOUND;
+
+		if (ret > 0)
+			map->map_ip = map->unmap_ip = identity__map_ip;
+	}
+
 	free(name);
 	if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
 		ret = 0;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-11-23 17:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-19 19:09 [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries Brian Robbins
2015-11-19 19:31 ` Peter Zijlstra
2015-11-19 23:45   ` Brian Robbins
2015-11-20  0:09     ` Stephane Eranian
2015-11-20 18:36       ` Brian Robbins
2015-11-20 19:32     ` Peter Zijlstra
2015-11-20 21:18       ` Brian Robbins
2015-11-21 21:41         ` Arnaldo Carvalho de Melo
2015-11-23 17:36         ` Stephane Eranian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox