mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba.org>
To: sukadev@linux.vnet.ibm.com, mpe@ellerman.id.au,
	aneesh.kumar@linux.vnet.ibm.com, acme@redhat.com,
	a.p.zijlstra@chello.nl, paulus@samba.org, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] perf symbols: symbol to section name mapping broken with debuginfo files
Date: Mon, 25 Aug 2014 18:20:31 +1000	[thread overview]
Message-ID: <20140825182031.2b209f27@kryten> (raw)

elf_sec__is_a and elf_sec__name maps a symbol back to its section name.
It does this by getting the Elf_Scn *, which contains an offset into
the strings section.

At the moment we use the Elf_Scn * from the runtime object and the
section strings from the debuginfo object, which is wrong. They are not
required to match, for example:

# readelf --string-dump=.shstrtab /lib/x86_64-linux-gnu/libc-2.19.so | md5sum
55ec050a37f64db113b42979a18a40ef  -

# readelf --string-dump=.shstrtab /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.19.so | md5sum
5ba4e37aae29b48418297f0c5b76b797  -

This issue was first found on ppc64le, where PLT entries (which are
labels with no type) were not getting resolved to symbols.

This looks to have been introduced in 261360b6e90a (perf symbols:
Convert dso__load_syms to take 2 symsrc's)

Cc: stable@vger.kernel.org # 3.8+
Signed-off-by: Anton Blanchard <anton@samba.org>
---

Index: b/tools/perf/util/symbol-elf.c
===================================================================
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -569,6 +569,7 @@ int symsrc__init(struct symsrc *ss, stru
 	GElf_Ehdr ehdr;
 	Elf *elf;
 	int fd;
+	Elf_Scn *sec_strndx;
 
 	fd = open(name, O_RDONLY);
 	if (fd < 0)
@@ -618,6 +619,14 @@ int symsrc__init(struct symsrc *ss, stru
 	if (ss->opdshdr.sh_type != SHT_PROGBITS)
 		ss->opdsec = NULL;
 
+	sec_strndx = elf_getscn(elf, ehdr.e_shstrndx);
+	if (sec_strndx == NULL)
+		goto out_elf_end;
+
+	ss->secstrs = elf_getdata(sec_strndx, NULL);
+	if (ss->secstrs == NULL)
+		goto out_elf_end;
+
 	if (dso->kernel == DSO_TYPE_USER) {
 		GElf_Shdr shdr;
 		ss->adjust_symbols = (ehdr.e_type == ET_EXEC ||
@@ -687,7 +696,7 @@ int dso__load_sym(struct dso *dso, struc
 	struct kmap *kmap = dso->kernel ? map__kmap(map) : NULL;
 	struct map *curr_map = map;
 	struct dso *curr_dso = dso;
-	Elf_Data *symstrs, *secstrs;
+	Elf_Data *symstrs;
 	uint32_t nr_syms;
 	int err = -1;
 	uint32_t idx;
@@ -695,7 +704,7 @@ int dso__load_sym(struct dso *dso, struc
 	GElf_Shdr shdr;
 	Elf_Data *syms, *opddata = NULL;
 	GElf_Sym sym;
-	Elf_Scn *sec, *sec_strndx;
+	Elf_Scn *sec;
 	Elf *elf;
 	int nr = 0;
 	bool remap_kernel = false, adjust_kernel_syms = false;
@@ -736,13 +745,6 @@ int dso__load_sym(struct dso *dso, struc
 	if (symstrs == NULL)
 		goto out_elf_end;
 
-	sec_strndx = elf_getscn(elf, ehdr.e_shstrndx);
-	if (sec_strndx == NULL)
-		goto out_elf_end;
-
-	secstrs = elf_getdata(sec_strndx, NULL);
-	if (secstrs == NULL)
-		goto out_elf_end;
 
 	nr_syms = shdr.sh_size / shdr.sh_entsize;
 
@@ -821,10 +823,10 @@ int dso__load_sym(struct dso *dso, struc
 
 		gelf_getshdr(sec, &shdr);
 
-		if (is_label && !elf_sec__is_a(&shdr, secstrs, map->type))
+		if (is_label && !elf_sec__is_a(&shdr, runtime_ss->secstrs, map->type))
 			continue;
 
-		section_name = elf_sec__name(&shdr, secstrs);
+		section_name = elf_sec__name(&shdr, runtime_ss->secstrs);
 
 		/* On ARM, symbols for thumb functions have 1 added to
 		 * the symbol address as a flag - remove it */
Index: b/tools/perf/util/symbol.h
===================================================================
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -215,6 +215,8 @@ struct symsrc {
 	size_t dynsym_idx;
 	GElf_Shdr dynshdr;
 
+	Elf_Data *secstrs;
+
 	bool adjust_symbols;
 	bool is_64_bit;
 #endif

                 reply	other threads:[~2014-08-25  8:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20140825182031.2b209f27@kryten \
    --to=anton@samba.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=sukadev@linux.vnet.ibm.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

all inboxes | Powered by JetHome®