[PATCH v5 02/11] perf tools: Check ELF section type with name

From: Namhyung Kim

Date: Tue Oct 13 2026 - 17:19:55 EST


In filename__has_section(), it just checks the name of the section but
it's possible that the section header is present without actual data.
In that case, it'll have SHT_NOBITS type and can confuse the result.

Update the function to check the section type as well. Normally we
want to check if the section content is present in the file so it'd
have SHT_PROGBITS. All the current callers of the function expect
the section with SHT_PROGBITS type (even for debug info).

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/symbol-elf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index e955c3feddcd62d0..1e2716c6af45712a 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -228,7 +228,8 @@ bool filename__has_section(const char *filename, const char *sec)
if (gelf_getehdr(elf, &ehdr) == NULL)
goto elf_out;

- found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL);
+ found = !!elf_section_by_name(elf, &ehdr, &shdr, sec, NULL) &&
+ shdr.sh_type == SHT_PROGBITS;

elf_out:
elf_end(elf);
--
2.56.0.385.gd3acb90ef8-goog