public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: fix issue with binaries using 16-bytes buildids (v2)
@ 2010-10-22 15:25 Stephane Eranian
  2011-09-09 17:03 ` Stephane Eranian
  0 siblings, 1 reply; 3+ messages in thread
From: Stephane Eranian @ 2010-10-22 15:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: acme, peterz, mingo, paulus, davem, fweisbec, perfmon2-devel,
	eranian, eranian, robert.richter

Buildid can vary in size. According to the man page of ld, buildid can
be 160 bits (sha1) or 128 bits (md5, uuid). Perf assumes buildid size
of 20 bytes (160 bits) regardless. When dealing with md5 buildids, it
would thus read more than needed and that would cause mismatches and
samples without symbols.

This patch fixes this by taking into account the actual buildid size
as encoded int he section header. The leftover bytes are also cleared.

This second version fixes a minor issue with the memset() base position.

Signed-off-by: Stephane Eranian <eranian@google.com>

---

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b39f499..b4fdb91 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1027,8 +1027,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
 	if (self->has_build_id) {
 		u8 build_id[BUILD_ID_SIZE];
 
-		if (elf_read_build_id(elf, build_id,
-				      BUILD_ID_SIZE) != BUILD_ID_SIZE)
+		if (elf_read_build_id(elf, build_id, BUILD_ID_SIZE) < 0)
 			goto out_elf_end;
 
 		if (!dso__build_id_equal(self, build_id))
@@ -1287,8 +1286,8 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
 	ptr = data->d_buf;
 	while (ptr < (data->d_buf + data->d_size)) {
 		GElf_Nhdr *nhdr = ptr;
-		int namesz = NOTE_ALIGN(nhdr->n_namesz),
-		    descsz = NOTE_ALIGN(nhdr->n_descsz);
+		size_t namesz = NOTE_ALIGN(nhdr->n_namesz),
+		       descsz = NOTE_ALIGN(nhdr->n_descsz);
 		const char *name;
 
 		ptr += sizeof(*nhdr);
@@ -1297,8 +1296,10 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
 		if (nhdr->n_type == NT_GNU_BUILD_ID &&
 		    nhdr->n_namesz == sizeof("GNU")) {
 			if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
-				memcpy(bf, ptr, BUILD_ID_SIZE);
-				err = BUILD_ID_SIZE;
+				size_t sz = min(size, descsz);
+				memcpy(bf, ptr, sz);
+				memset(bf + sz, 0, size - sz);
+				err = descsz;
 				break;
 			}
 		}
@@ -1350,7 +1351,7 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
 	while (1) {
 		char bf[BUFSIZ];
 		GElf_Nhdr nhdr;
-		int namesz, descsz;
+		size_t namesz, descsz;
 
 		if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr))
 			break;
@@ -1359,15 +1360,16 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
 		descsz = NOTE_ALIGN(nhdr.n_descsz);
 		if (nhdr.n_type == NT_GNU_BUILD_ID &&
 		    nhdr.n_namesz == sizeof("GNU")) {
-			if (read(fd, bf, namesz) != namesz)
+			if (read(fd, bf, namesz) != (ssize_t)namesz)
 				break;
 			if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
-				if (read(fd, build_id,
-				    BUILD_ID_SIZE) == BUILD_ID_SIZE) {
+				size_t sz = min(descsz, size);
+				if (read(fd, build_id, sz) == (ssize_t)sz) {
+					memset(build_id + sz, 0, size - sz);
 					err = 0;
 					break;
 				}
-			} else if (read(fd, bf, descsz) != descsz)
+			} else if (read(fd, bf, descsz) != (ssize_t)descsz)
 				break;
 		} else {
 			int n = namesz + descsz;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf: fix issue with binaries using 16-bytes buildids (v2)
  2010-10-22 15:25 [PATCH] perf: fix issue with binaries using 16-bytes buildids (v2) Stephane Eranian
@ 2011-09-09 17:03 ` Stephane Eranian
  2011-09-09 17:28   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Stephane Eranian @ 2011-09-09 17:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, peterz, mingo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 5113 bytes --]

Arnaldo,

To my surprise, this patch from Last October is STILL not in.
People are reporting issues with perf related to md5 buildids..


On Fri, Oct 22, 2010 at 5:25 PM, Stephane Eranian <eranian@google.com> wrote:
> Buildid can vary in size. According to the man page of ld, buildid can
> be 160 bits (sha1) or 128 bits (md5, uuid). Perf assumes buildid size
> of 20 bytes (160 bits) regardless. When dealing with md5 buildids, it
> would thus read more than needed and that would cause mismatches and
> samples without symbols.
>
> This patch fixes this by taking into account the actual buildid size
> as encoded int he section header. The leftover bytes are also cleared.
>
> This second version fixes a minor issue with the memset() base position.
>
> Signed-off-by: Stephane Eranian <eranian@google.com>
>
> ---
>
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index b39f499..b4fdb91 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1027,8 +1027,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
>        if (self->has_build_id) {
>                u8 build_id[BUILD_ID_SIZE];
>
> -               if (elf_read_build_id(elf, build_id,
> -                                     BUILD_ID_SIZE) != BUILD_ID_SIZE)
> +               if (elf_read_build_id(elf, build_id, BUILD_ID_SIZE) < 0)
>                        goto out_elf_end;
>
>                if (!dso__build_id_equal(self, build_id))
> @@ -1287,8 +1286,8 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
>        ptr = data->d_buf;
>        while (ptr < (data->d_buf + data->d_size)) {
>                GElf_Nhdr *nhdr = ptr;
> -               int namesz = NOTE_ALIGN(nhdr->n_namesz),
> -                   descsz = NOTE_ALIGN(nhdr->n_descsz);
> +               size_t namesz = NOTE_ALIGN(nhdr->n_namesz),
> +                      descsz = NOTE_ALIGN(nhdr->n_descsz);
>                const char *name;
>
>                ptr += sizeof(*nhdr);
> @@ -1297,8 +1296,10 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
>                if (nhdr->n_type == NT_GNU_BUILD_ID &&
>                    nhdr->n_namesz == sizeof("GNU")) {
>                        if (memcmp(name, "GNU", sizeof("GNU")) == 0) {
> -                               memcpy(bf, ptr, BUILD_ID_SIZE);
> -                               err = BUILD_ID_SIZE;
> +                               size_t sz = min(size, descsz);
> +                               memcpy(bf, ptr, sz);
> +                               memset(bf + sz, 0, size - sz);
> +                               err = descsz;
>                                break;
>                        }
>                }
> @@ -1350,7 +1351,7 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
>        while (1) {
>                char bf[BUFSIZ];
>                GElf_Nhdr nhdr;
> -               int namesz, descsz;
> +               size_t namesz, descsz;
>
>                if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr))
>                        break;
> @@ -1359,15 +1360,16 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
>                descsz = NOTE_ALIGN(nhdr.n_descsz);
>                if (nhdr.n_type == NT_GNU_BUILD_ID &&
>                    nhdr.n_namesz == sizeof("GNU")) {
> -                       if (read(fd, bf, namesz) != namesz)
> +                       if (read(fd, bf, namesz) != (ssize_t)namesz)
>                                break;
>                        if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
> -                               if (read(fd, build_id,
> -                                   BUILD_ID_SIZE) == BUILD_ID_SIZE) {
> +                               size_t sz = min(descsz, size);
> +                               if (read(fd, build_id, sz) == (ssize_t)sz) {
> +                                       memset(build_id + sz, 0, size - sz);
>                                        err = 0;
>                                        break;
>                                }
> -                       } else if (read(fd, bf, descsz) != descsz)
> +                       } else if (read(fd, bf, descsz) != (ssize_t)descsz)
>                                break;
>                } else {
>                        int n = namesz + descsz;
>
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf: fix issue with binaries using 16-bytes buildids (v2)
  2011-09-09 17:03 ` Stephane Eranian
@ 2011-09-09 17:28   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-09-09 17:28 UTC (permalink / raw)
  To: Stephane Eranian; +Cc: linux-kernel, peterz, mingo

Em Fri, Sep 09, 2011 at 07:03:12PM +0200, Stephane Eranian escreveu:
> Arnaldo,
> 
> To my surprise, this patch from Last October is STILL not in.
> People are reporting issues with perf related to md5 buildids..

Got it now, thanks for resubmitting, will appear on perf/urgent as soon
as things normalize on kernel.org.

- Arnaldo

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-09 17:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-22 15:25 [PATCH] perf: fix issue with binaries using 16-bytes buildids (v2) Stephane Eranian
2011-09-09 17:03 ` Stephane Eranian
2011-09-09 17:28   ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox