Re: [RFC PATCH 1/2] perf dso: Use libbfd to read build_id and .gnu_debuglink section

From: Jiri Olsa
Date: Mon Jun 01 2020 - 13:48:37 EST


On Mon, Jun 01, 2020 at 01:19:14PM +0200, Rémi Bernon wrote:

SNIP

> int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
> @@ -611,6 +638,37 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
> int filename__read_debuglink(const char *filename, char *debuglink,
> size_t size)
> {
> +#ifdef HAVE_LIBBFD_SUPPORT
> + int err = -1;
> + asection *section;
> + bfd *abfd;
> +
> + abfd = bfd_openr(filename, NULL);
> + if (!abfd)
> + return -1;
> +
> + if (!bfd_check_format(abfd, bfd_object)) {
> + pr_debug2("%s: cannot read %s bfd file.\n", __func__, filename);
> + goto out_close;
> + }
> +
> + section = bfd_get_section_by_name(abfd, ".gnu_debuglink");
> + if (!section)
> + goto out_close;
> +
> + if (section->size > size)
> + goto out_close;
> +
> + if (!bfd_get_section_contents(abfd, section, debuglink, 0,
> + section->size))
> + goto out_close;
> +
> + err = 0;
> +
> +out_close:
> + bfd_close(abfd);
> + return err;
> +#else

please define 2 filename__read_debuglink functions
for each ifdef leg

thanks,
jirka

> int fd, err = -1;
> Elf *elf;
> GElf_Ehdr ehdr;
> @@ -658,6 +716,7 @@ int filename__read_debuglink(const char *filename, char *debuglink,
> close(fd);
> out:
> return err;
> +#endif
> }
>
> static int dso__swap_init(struct dso *dso, unsigned char eidata)
> --
> 2.26.1
>