From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
"David A. Long" <dave.long@linaro.org>,
"Steven Rostedt (Red Hat)" <rostedt@goodmis.org>,
David Ahern <dsahern@gmail.com>, Ingo Molnar <mingo@redhat.com>,
Namhyung Kim <namhyung@kernel.org>,
Oleg Nesterov <oleg@redhat.com>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>,
yrl.pp-manager.tt@hitachi.com,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 16/19] perf symbols: Export elf_section_by_name and reuse
Date: Fri, 17 Jan 2014 11:57:22 -0300 [thread overview]
Message-ID: <1389970645-12075-17-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1389970645-12075-1-git-send-email-acme@infradead.org>
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Remove duplicated elf_section_by_name() functions from unwind.c and
probe-event.c and use one exported elf_section_by_name() instance
defined in symbol-elf.c.
Note that this also moves get_text_start_address() to merge
HAVE_DWARF_SUPPORT defined area.
Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: "David A. Long" <dave.long@linaro.org>
Cc: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: yrl.pp-manager.tt@hitachi.com
Link: http://lkml.kernel.org/r/20140116093949.24403.38093.stgit@kbuild-fedora.novalocal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 76 ++++++++++++++++---------------------------
tools/perf/util/symbol-elf.c | 5 ++-
tools/perf/util/symbol.h | 5 +++
tools/perf/util/unwind.c | 20 ++----------
4 files changed, 37 insertions(+), 69 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index c68711c50f47..a8a9b6cd93a8 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -173,54 +173,6 @@ const char *kernel_get_module_path(const char *module)
return (dso) ? dso->long_name : NULL;
}
-#ifdef HAVE_DWARF_SUPPORT
-/* Copied from unwind.c */
-static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
- GElf_Shdr *shp, const char *name)
-{
- Elf_Scn *sec = NULL;
-
- while ((sec = elf_nextscn(elf, sec)) != NULL) {
- char *str;
-
- gelf_getshdr(sec, shp);
- str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
- if (!strcmp(name, str))
- break;
- }
-
- return sec;
-}
-
-static int get_text_start_address(const char *exec, unsigned long *address)
-{
- Elf *elf;
- GElf_Ehdr ehdr;
- GElf_Shdr shdr;
- int fd, ret = -ENOENT;
-
- fd = open(exec, O_RDONLY);
- if (fd < 0)
- return -errno;
-
- elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
- if (elf == NULL)
- return -EINVAL;
-
- if (gelf_getehdr(elf, &ehdr) == NULL)
- goto out;
-
- if (!elf_section_by_name(elf, &ehdr, &shdr, ".text"))
- goto out;
-
- *address = shdr.sh_addr - shdr.sh_offset;
- ret = 0;
-out:
- elf_end(elf);
- return ret;
-}
-#endif
-
static int init_user_exec(void)
{
int ret = 0;
@@ -341,6 +293,34 @@ static int kprobe_convert_to_perf_probe(struct probe_trace_point *tp,
return 0;
}
+static int get_text_start_address(const char *exec, unsigned long *address)
+{
+ Elf *elf;
+ GElf_Ehdr ehdr;
+ GElf_Shdr shdr;
+ int fd, ret = -ENOENT;
+
+ fd = open(exec, O_RDONLY);
+ if (fd < 0)
+ return -errno;
+
+ elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
+ if (elf == NULL)
+ return -EINVAL;
+
+ if (gelf_getehdr(elf, &ehdr) == NULL)
+ goto out;
+
+ if (!elf_section_by_name(elf, &ehdr, &shdr, ".text", NULL))
+ goto out;
+
+ *address = shdr.sh_addr - shdr.sh_offset;
+ ret = 0;
+out:
+ elf_end(elf);
+ return ret;
+}
+
static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
int ntevs, const char *exec)
{
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 4b0a127a4d3b..759456728703 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -136,9 +136,8 @@ static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)
return -1;
}
-static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
- GElf_Shdr *shp, const char *name,
- size_t *idx)
+Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
+ GElf_Shdr *shp, const char *name, size_t *idx)
{
Elf_Scn *sec = NULL;
size_t cnt = 1;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index cbd680361806..fffe2888a1c7 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -52,6 +52,11 @@ static inline char *bfd_demangle(void __maybe_unused *v,
# define PERF_ELF_C_READ_MMAP ELF_C_READ
#endif
+#ifdef HAVE_LIBELF_SUPPORT
+extern Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
+ GElf_Shdr *shp, const char *name, size_t *idx);
+#endif
+
#ifndef DMGL_PARAMS
#define DMGL_PARAMS (1 << 0) /* Include function args */
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
diff --git a/tools/perf/util/unwind.c b/tools/perf/util/unwind.c
index 416f22bf3693..742f23bf35ff 100644
--- a/tools/perf/util/unwind.c
+++ b/tools/perf/util/unwind.c
@@ -28,6 +28,7 @@
#include "session.h"
#include "perf_regs.h"
#include "unwind.h"
+#include "symbol.h"
#include "util.h"
extern int
@@ -158,23 +159,6 @@ static int __dw_read_encoded_value(u8 **p, u8 *end, u64 *val,
__v; \
})
-static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
- GElf_Shdr *shp, const char *name)
-{
- Elf_Scn *sec = NULL;
-
- while ((sec = elf_nextscn(elf, sec)) != NULL) {
- char *str;
-
- gelf_getshdr(sec, shp);
- str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
- if (!strcmp(name, str))
- break;
- }
-
- return sec;
-}
-
static u64 elf_section_offset(int fd, const char *name)
{
Elf *elf;
@@ -190,7 +174,7 @@ static u64 elf_section_offset(int fd, const char *name)
if (gelf_getehdr(elf, &ehdr) == NULL)
break;
- if (!elf_section_by_name(elf, &ehdr, &shdr, name))
+ if (!elf_section_by_name(elf, &ehdr, &shdr, name, NULL))
break;
offset = shdr.sh_offset;
--
1.8.1.4
next prev parent reply other threads:[~2014-01-17 15:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-17 14:57 [GIT PULL 00/19] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 01/19] tools lib traceevent: Add pevent_unregister_event_handler() Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 02/19] tools lib traceevent: Add pevent_unregister_print_function() Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 03/19] tools lib traceevent: Unregister handler when function plugin is unloaded Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 04/19] tools lib traceevent: Unregister handler when hrtimer " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 05/19] tools lib traceevent: Unregister handler when kmem " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 06/19] tools lib traceevent: Unregister handler when kvm " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 07/19] tools lib traceevent: Unregister handler when sched_switch " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 08/19] tools lib traceevent: Unregister handler when mac80211 " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 09/19] tools lib traceevent: Unregister handler when cfg80211 " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 10/19] tools lib traceevent: Unregister handler when jbd2 plugin is " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 11/19] tools lib traceevent: Unregister handler when scsi plugin " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 12/19] tools lib traceevent: Unregister handler when xen " Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 13/19] perf tools: Add 'build-test' make target Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 14/19] perf probe: Release allocated probe_trace_event if failed Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 15/19] perf probe: Release all dynamically allocated parameters Arnaldo Carvalho de Melo
2014-01-17 14:57 ` Arnaldo Carvalho de Melo [this message]
2014-01-17 14:57 ` [PATCH 17/19] perf tools: Do proper comm override error handling Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 18/19] perf callchain: Spare double comparison of callchain first entry Arnaldo Carvalho de Melo
2014-01-17 14:57 ` [PATCH 19/19] perf tools: Remove unnecessary callchain cursor state restore on unmatch Arnaldo Carvalho de Melo
2014-01-19 12:11 ` [GIT PULL 00/19] perf/core improvements and fixes Ingo Molnar
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=1389970645-12075-17-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=dave.long@linaro.org \
--cc=dsahern@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.com \
--cc=yrl.pp-manager.tt@hitachi.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;
as well as URLs for NNTP newsgroup(s).