[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1447960147-2681-1-git-send-email-brianrob@microsoft.com>
Date: Thu, 19 Nov 2015 11:09:07 -0800
From: Brian Robbins <brianrob@...rosoft.com>
To: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Brian Robbins <brianrob@...rosoft.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries.
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@...rosoft.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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists