Skip to content

Commit ca81e74

Browse files
captain5050namhyung
authored andcommitted
perf symbol-elf: Add support for the block argument for libbfd
James Clark caught that the BUILD_NONDISTRO=1 build with libbfd was broken due to an update to the read_build_id function adding a blocking argument. Add support for this argument by first opening the file blocking or non-blocking, then switching from bfd_openr to bfd_fdopenr and passing the opened fd. bfd_fdopenr closes the fd on error and when bfd_close are called. Reported-by: James Clark <[email protected]> Closes: https://lore.kernel.org/lkml/20250903-james-perf-read-build-id-fix-v1-2-6a694d0a980f@linaro.org/ Fixes: 2c369d9 ("perf symbol: Add blocking argument to filename__read_build_id") Signed-off-by: Ian Rogers <[email protected]> Reviewed-by: James Clark <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 744175e commit ca81e74

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/perf/util/symbol-elf.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,17 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
873873

874874
#ifdef HAVE_LIBBFD_BUILDID_SUPPORT
875875

876-
static int read_build_id(const char *filename, struct build_id *bid)
876+
static int read_build_id(const char *filename, struct build_id *bid, bool block)
877877
{
878878
size_t size = sizeof(bid->data);
879-
int err = -1;
879+
int err = -1, fd;
880880
bfd *abfd;
881881

882-
abfd = bfd_openr(filename, NULL);
882+
fd = open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK));
883+
if (fd < 0)
884+
return -1;
885+
886+
abfd = bfd_fdopenr(filename, /*target=*/NULL, fd);
883887
if (!abfd)
884888
return -1;
885889

0 commit comments

Comments
 (0)