Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1273410

[PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries.

From Brian Robbins <brianrob@microsoft.com>
Newsgroups linux.kernel
Subject [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries.
Date 2015-11-19 20:10 +0100
Message-ID <qwCKJ-549-9@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries. Brian Robbins <brianrob@microsoft.com> - 2015-11-19 20:10 +0100
  Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF  binaries. Peter Zijlstra <peterz@infradead.org> - 2015-11-19 20:40 +0100
    Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF  binaries. Brian Robbins <brianrob@microsoft.com> - 2015-11-20 00:50 +0100
      Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries. Stephane Eranian <eranian@google.com> - 2015-11-20 01:20 +0100
        Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF  binaries. Brian Robbins <brianrob@microsoft.com> - 2015-11-20 19:40 +0100
      Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF  binaries. Peter Zijlstra <peterz@infradead.org> - 2015-11-20 20:40 +0100
        Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF  binaries. Brian Robbins <brianrob@microsoft.com> - 2015-11-20 22:40 +0100
          Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF  binaries. Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-11-21 22:50 +0100
          Re: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries. Stephane Eranian <eranian@google.com> - 2015-11-23 18:40 +0100

csiph-web