Skip to contentSkip to conversation

perf symbol-elf: Add support for the block argument for libbfd

PATCH In review Ian Rogers 2 participants 2 messages Sep 4, 2025 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 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.

Fixes 2c369d91d093 ("perf symbol: Add blocking argument to filename__read_build_id")

---
This patch should be applied after:
https://lore.kernel.org/lkml/20250903-james-perf-read-build-id-fix-v1-1-6a694d0a980f@linaro.org/

---
 tools/perf/util/symbol-elf.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/perf/util/symbol-elf.c +7 -3
index 033c79231a54..1346fd180653 100644
@@ -873,13 +873,17 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
 
 #ifdef HAVE_LIBBFD_BUILDID_SUPPORT
 
-static int read_build_id(const char *filename, struct build_id *bid)
+static int read_build_id(const char *filename, struct build_id *bid, bool block)
 {
 	size_t size = sizeof(bid->data);
-	int err = -1;
+	int err = -1, fd;
 	bfd *abfd;
 
-	abfd = bfd_openr(filename, NULL);
+	fd = open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK));
+	if (fd < 0)
+		return -1;
+
+	abfd = bfd_fdopenr(filename, /*target=*/NULL, fd);
 	if (!abfd)
 		return -1;
 
Signature · 1 line
2.51.0.338.gd7d06c2dae-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Ian Rogers

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.

Fixes 2c369d91d093 ("perf symbol: Add blocking argument to filename__read_build_id")

---
This patch should be applied after:
https://lore.kernel.org/lkml/20250903-james-perf-read-build-id-fix-v1-1-6a694d0a980f@linaro.org/

---
  tools/perf/util/symbol-elf.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
tools/perf/util/symbol-elf.c +2 -2
index 033c79231a54..1346fd180653 100644
@@ -873,13 +873,17 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
 
  #ifdef HAVE_LIBBFD_BUILDID_SUPPORT
 
-static int read_build_id(const char *filename, struct build_id *bid)
+static int read_build_id(const char *filename, struct build_id *bid, bool block)
  {
  	size_t size = sizeof(bid->data);
-	int err = -1;
+	int err = -1, fd;
  	bfd *abfd;

tools/perf/util/symbol-elf.c static int elf_read_build_id(Elf *elf, void *bf, size_t size) · line 889

Quoted 10 lines
tools/perf/util/symbol-elf.c +5 -1
 
-	abfd = bfd_openr(filename, NULL);
+	fd = open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK));
+	if (fd < 0)
+		return -1;
+
+	abfd = bfd_fdopenr(filename, /*target=*/NULL, fd);
  	if (!abfd)
  		return -1;
 

Oh that was less awkward than I thought then. Assuming it doesn't mind an fd opened with NONBLOCK?