Re: [PATCH 06/26] perf tools: Add support to read build id from compressed elf

From: Arnaldo Carvalho de Melo
Date: Mon Sep 14 2020 - 12:18:33 EST


Em Sun, Sep 13, 2020 at 11:02:53PM +0200, Jiri Olsa escreveu:
> Adding support to decompress file before reading build id.
>
> Adding filename__read_build_id and change its current
> versions to read_build_id.

Also a standalone, generally useful, prep patch, applyed.

- Arnaldo

> Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
> ---
> tools/perf/util/symbol-elf.c | 37 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 35 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index 94a156df22d5..6770572620f3 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -534,7 +534,7 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
>
> #ifdef HAVE_LIBBFD_BUILDID_SUPPORT
>
> -int filename__read_build_id(const char *filename, void *bf, size_t size)
> +static int read_build_id(const char *filename, void *bf, size_t size)
> {
> int err = -1;
> bfd *abfd;
> @@ -562,7 +562,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
>
> #else // HAVE_LIBBFD_BUILDID_SUPPORT
>
> -int filename__read_build_id(const char *filename, void *bf, size_t size)
> +static int read_build_id(const char *filename, void *bf, size_t size)
> {
> int fd, err = -1;
> Elf *elf;
> @@ -591,6 +591,39 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
>
> #endif // HAVE_LIBBFD_BUILDID_SUPPORT
>
> +int filename__read_build_id(const char *filename, void *bf, size_t size)
> +{
> + struct kmod_path m = { .name = NULL, };
> + char path[PATH_MAX];
> + int err;
> +
> + if (!filename)
> + return -EFAULT;
> +
> + err = kmod_path__parse(&m, filename);
> + if (err)
> + return -1;
> +
> + if (m.comp) {
> + int error = 0, fd;
> +
> + fd = filename__decompress(filename, path, sizeof(path), m.comp, &error);
> + if (fd < 0) {
> + pr_debug("Failed to decompress (error %d) %s\n",
> + error, filename);
> + return -1;
> + }
> + close(fd);
> + filename = path;
> + }
> +
> + err = read_build_id(filename, bf, size);
> +
> + if (m.comp)
> + unlink(filename);
> + return err;
> +}
> +
> int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
> {
> int fd, err = -1;
> --
> 2.26.2
>

--

- Arnaldo