* [PATCH] perf lookup of ppc64 symbols
@ 2010-06-14 13:56 Eric B Munson
2010-06-17 14:46 ` Anton Blanchard
2010-06-18 10:16 ` [tip:perf/core] perf symbols: Function descriptor symbol lookup tip-bot for Eric B Munson
0 siblings, 2 replies; 5+ messages in thread
From: Eric B Munson @ 2010-06-14 13:56 UTC (permalink / raw)
To: mingo
Cc: a.p.zijlstra, paulus, acme, linux-kernel, Eric B Munson,
Anton Blanchard
Currently symbol resolution does not work for 64-bit programs
using perf. For this to work perf needs to lookup symbol names in
the OPD. This patch adds this functionality. The OPD data is
used to find symbol names when available.
Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
---
tools/perf/util/symbol.c | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b63e571..971d0a0 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -933,6 +933,25 @@ static bool elf_sec__is_a(GElf_Shdr *self, Elf_Data *secstrs, enum map_type type
}
}
+static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)
+{
+ Elf_Scn *sec = NULL;
+ GElf_Shdr shdr;
+ size_t cnt = 1;
+
+ while ((sec = elf_nextscn(elf, sec)) != NULL) {
+ gelf_getshdr(sec, &shdr);
+
+ if ((addr >= shdr.sh_addr) &&
+ (addr < (shdr.sh_addr + shdr.sh_size)))
+ return cnt;
+
+ ++cnt;
+ }
+
+ return -1;
+}
+
static int dso__load_sym(struct dso *self, struct map *map, const char *name,
int fd, symbol_filter_t filter, int kmodule)
{
@@ -944,12 +963,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
int err = -1;
uint32_t idx;
GElf_Ehdr ehdr;
- GElf_Shdr shdr;
- Elf_Data *syms;
+ GElf_Shdr shdr, opdshdr;
+ Elf_Data *syms, *opddata = NULL;
GElf_Sym sym;
- Elf_Scn *sec, *sec_strndx;
+ Elf_Scn *sec, *sec_strndx, *opdsec;
Elf *elf;
int nr = 0;
+ size_t opdidx = 0;
elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
if (elf == NULL) {
@@ -969,6 +989,10 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
goto out_elf_end;
}
+ opdsec = elf_section_by_name(elf, &ehdr, &opdshdr, ".opd", &opdidx);
+ if (opdsec)
+ opddata = elf_rawdata(opdsec, NULL);
+
syms = elf_getdata(sec, NULL);
if (syms == NULL)
goto out_elf_end;
@@ -1013,6 +1037,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
if (!is_label && !elf_sym__is_a(&sym, map->type))
continue;
+ if (opdsec && sym.st_shndx == opdidx) {
+ u32 offset = sym.st_value - opdshdr.sh_addr;
+ u64 *opd = opddata->d_buf + offset;
+ sym.st_value = *opd;
+ sym.st_shndx = elf_addr_to_index(elf, sym.st_value);
+ }
+
sec = elf_getscn(elf, sym.st_shndx);
if (!sec)
goto out_elf_end;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] perf lookup of ppc64 symbols
2010-06-14 13:56 [PATCH] perf lookup of ppc64 symbols Eric B Munson
@ 2010-06-17 14:46 ` Anton Blanchard
2010-06-17 15:17 ` Arnaldo Carvalho de Melo
2010-06-18 10:16 ` [tip:perf/core] perf symbols: Function descriptor symbol lookup tip-bot for Eric B Munson
1 sibling, 1 reply; 5+ messages in thread
From: Anton Blanchard @ 2010-06-17 14:46 UTC (permalink / raw)
To: Eric B Munson; +Cc: mingo, a.p.zijlstra, paulus, acme, linux-kernel, amodra
Hi,
> Currently symbol resolution does not work for 64-bit programs
> using perf. For this to work perf needs to lookup symbol names in
> the OPD. This patch adds this functionality. The OPD data is
> used to find symbol names when available.
To clarify, this is an issue with 64bit architectures that use function
descriptors (eg ppc64). The problem is that a symbol doesn't point to a text
address, it points to a data area that contains (amongst other things) a
pointer to the text address.
We look for a section called ".opd" which is the function descriptor
area. To create the full symbol table, when we see a symbol in the function
descriptor section we load the first pointer and use that as the text
address. The only tricky part here is working out which section the
text address is in. Right now we have a loop which is sub optimal:
> + while ((sec = elf_nextscn(elf, sec)) != NULL) {
> + gelf_getshdr(sec, &shdr);
> +
> + if ((addr >= shdr.sh_addr) &&
> + (addr < (shdr.sh_addr + shdr.sh_size)))
> + return cnt;
> +
> + ++cnt;
> + }
Anton
> Signed-off-by: Anton Blanchard <anton@samba.org>
> Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
> ---
> tools/perf/util/symbol.c | 37 ++++++++++++++++++++++++++++++++++---
> 1 files changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index b63e571..971d0a0 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -933,6 +933,25 @@ static bool elf_sec__is_a(GElf_Shdr *self, Elf_Data *secstrs, enum map_type type
> }
> }
>
> +static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)
> +{
> + Elf_Scn *sec = NULL;
> + GElf_Shdr shdr;
> + size_t cnt = 1;
> +
> + while ((sec = elf_nextscn(elf, sec)) != NULL) {
> + gelf_getshdr(sec, &shdr);
> +
> + if ((addr >= shdr.sh_addr) &&
> + (addr < (shdr.sh_addr + shdr.sh_size)))
> + return cnt;
> +
> + ++cnt;
> + }
> +
> + return -1;
> +}
> +
> static int dso__load_sym(struct dso *self, struct map *map, const char *name,
> int fd, symbol_filter_t filter, int kmodule)
> {
> @@ -944,12 +963,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
> int err = -1;
> uint32_t idx;
> GElf_Ehdr ehdr;
> - GElf_Shdr shdr;
> - Elf_Data *syms;
> + GElf_Shdr shdr, opdshdr;
> + Elf_Data *syms, *opddata = NULL;
> GElf_Sym sym;
> - Elf_Scn *sec, *sec_strndx;
> + Elf_Scn *sec, *sec_strndx, *opdsec;
> Elf *elf;
> int nr = 0;
> + size_t opdidx = 0;
>
> elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
> if (elf == NULL) {
> @@ -969,6 +989,10 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
> goto out_elf_end;
> }
>
> + opdsec = elf_section_by_name(elf, &ehdr, &opdshdr, ".opd", &opdidx);
> + if (opdsec)
> + opddata = elf_rawdata(opdsec, NULL);
> +
> syms = elf_getdata(sec, NULL);
> if (syms == NULL)
> goto out_elf_end;
> @@ -1013,6 +1037,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
> if (!is_label && !elf_sym__is_a(&sym, map->type))
> continue;
>
> + if (opdsec && sym.st_shndx == opdidx) {
> + u32 offset = sym.st_value - opdshdr.sh_addr;
> + u64 *opd = opddata->d_buf + offset;
> + sym.st_value = *opd;
> + sym.st_shndx = elf_addr_to_index(elf, sym.st_value);
> + }
> +
> sec = elf_getscn(elf, sym.st_shndx);
> if (!sec)
> goto out_elf_end;
> --
> 1.7.0.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf lookup of ppc64 symbols
2010-06-17 14:46 ` Anton Blanchard
@ 2010-06-17 15:17 ` Arnaldo Carvalho de Melo
2010-06-17 15:19 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-06-17 15:17 UTC (permalink / raw)
To: Anton Blanchard
Cc: Eric B Munson, mingo, a.p.zijlstra, paulus, linux-kernel, amodra
Em Fri, Jun 18, 2010 at 12:46:08AM +1000, Anton Blanchard escreveu:
>
> Hi,
>
> > Currently symbol resolution does not work for 64-bit programs
> > using perf. For this to work perf needs to lookup symbol names in
> > the OPD. This patch adds this functionality. The OPD data is
> > used to find symbol names when available.
>
> To clarify, this is an issue with 64bit architectures that use function
> descriptors (eg ppc64). The problem is that a symbol doesn't point to a text
> address, it points to a data area that contains (amongst other things) a
> pointer to the text address.
>
> We look for a section called ".opd" which is the function descriptor
> area. To create the full symbol table, when we see a symbol in the function
> descriptor section we load the first pointer and use that as the text
> address. The only tricky part here is working out which section the
> text address is in. Right now we have a loop which is sub optimal:
I'll update the comment in Eric's patch and apply this to perf/core, for
.36, we can optimize this later, correctness first :-)
- Arnaldo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf lookup of ppc64 symbols
2010-06-17 15:17 ` Arnaldo Carvalho de Melo
@ 2010-06-17 15:19 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2010-06-17 15:19 UTC (permalink / raw)
To: Anton Blanchard
Cc: Eric B Munson, mingo, a.p.zijlstra, paulus, linux-kernel, amodra
Em Thu, Jun 17, 2010 at 12:17:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jun 18, 2010 at 12:46:08AM +1000, Anton Blanchard escreveu:
> > address. The only tricky part here is working out which section the
> > text address is in. Right now we have a loop which is sub optimal:
>
> I'll update the comment in Eric's patch and apply this to perf/core, for
> .36, we can optimize this later, correctness first :-)
Also we only call dso__load lazily, when we find a hit in that DSO that
we want to resolve to a symbol, so it should be ok as-is.
- Arnaldo
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip:perf/core] perf symbols: Function descriptor symbol lookup
2010-06-14 13:56 [PATCH] perf lookup of ppc64 symbols Eric B Munson
2010-06-17 14:46 ` Anton Blanchard
@ 2010-06-18 10:16 ` tip-bot for Eric B Munson
1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Eric B Munson @ 2010-06-18 10:16 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, anton, linux-kernel, paulus, hpa, mingo, peterz, ebmunson,
tglx, mingo
Commit-ID: 70c3856b2f1304e0abc65f1b96a8c60ddfc0fb9e
Gitweb: http://git.kernel.org/tip/70c3856b2f1304e0abc65f1b96a8c60ddfc0fb9e
Author: Eric B Munson <ebmunson@us.ibm.com>
AuthorDate: Mon, 14 Jun 2010 14:56:33 +0100
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 17 Jun 2010 10:06:27 -0300
perf symbols: Function descriptor symbol lookup
Currently symbol resolution does not work for 64-bit programs on architectures
that use function descriptors such as ppc64.
The problem is that a symbol doesn't point to a text address, it points to a
data area that contains (amongst other things) a pointer to the text address.
We look for a section called ".opd" which is the function descriptor area. To
create the full symbol table, when we see a symbol in the function descriptor
section we load the first pointer and use that as the text address.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
LKML-Reference: <1276523793-15422-1-git-send-email-ebmunson@us.ibm.com>
Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/symbol.c | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b63e571..971d0a0 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -933,6 +933,25 @@ static bool elf_sec__is_a(GElf_Shdr *self, Elf_Data *secstrs, enum map_type type
}
}
+static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr)
+{
+ Elf_Scn *sec = NULL;
+ GElf_Shdr shdr;
+ size_t cnt = 1;
+
+ while ((sec = elf_nextscn(elf, sec)) != NULL) {
+ gelf_getshdr(sec, &shdr);
+
+ if ((addr >= shdr.sh_addr) &&
+ (addr < (shdr.sh_addr + shdr.sh_size)))
+ return cnt;
+
+ ++cnt;
+ }
+
+ return -1;
+}
+
static int dso__load_sym(struct dso *self, struct map *map, const char *name,
int fd, symbol_filter_t filter, int kmodule)
{
@@ -944,12 +963,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
int err = -1;
uint32_t idx;
GElf_Ehdr ehdr;
- GElf_Shdr shdr;
- Elf_Data *syms;
+ GElf_Shdr shdr, opdshdr;
+ Elf_Data *syms, *opddata = NULL;
GElf_Sym sym;
- Elf_Scn *sec, *sec_strndx;
+ Elf_Scn *sec, *sec_strndx, *opdsec;
Elf *elf;
int nr = 0;
+ size_t opdidx = 0;
elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
if (elf == NULL) {
@@ -969,6 +989,10 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
goto out_elf_end;
}
+ opdsec = elf_section_by_name(elf, &ehdr, &opdshdr, ".opd", &opdidx);
+ if (opdsec)
+ opddata = elf_rawdata(opdsec, NULL);
+
syms = elf_getdata(sec, NULL);
if (syms == NULL)
goto out_elf_end;
@@ -1013,6 +1037,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
if (!is_label && !elf_sym__is_a(&sym, map->type))
continue;
+ if (opdsec && sym.st_shndx == opdidx) {
+ u32 offset = sym.st_value - opdshdr.sh_addr;
+ u64 *opd = opddata->d_buf + offset;
+ sym.st_value = *opd;
+ sym.st_shndx = elf_addr_to_index(elf, sym.st_value);
+ }
+
sec = elf_getscn(elf, sym.st_shndx);
if (!sec)
goto out_elf_end;
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-06-18 10:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-14 13:56 [PATCH] perf lookup of ppc64 symbols Eric B Munson
2010-06-17 14:46 ` Anton Blanchard
2010-06-17 15:17 ` Arnaldo Carvalho de Melo
2010-06-17 15:19 ` Arnaldo Carvalho de Melo
2010-06-18 10:16 ` [tip:perf/core] perf symbols: Function descriptor symbol lookup tip-bot for Eric B Munson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox