lkml.org 
[lkml]   [2015]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries.
Date
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


\
 
 \ /
  Last update: 2015-11-19 20:41    [W:0.061 / U:0.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site