From: Brian Robbins <brianrob@microsoft.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Brian Robbins <brianrob@microsoft.com>, linux-kernel@vger.kernel.org
Subject: [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries.
Date: Thu, 19 Nov 2015 11:09:07 -0800 [thread overview]
Message-ID: <1447960147-2681-1-git-send-email-brianrob@microsoft.com> (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
next reply other threads:[~2015-11-19 19:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-19 19:09 Brian Robbins [this message]
2015-11-19 19:31 ` [PATCH] perf: Fallback to JIT support for mmap'd non-ELF binaries 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
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=1447960147-2681-1-git-send-email-brianrob@microsoft.com \
--to=brianrob@microsoft.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox