[PATCH perf-tools-next v7 3/6] perf symbol: Introduce vmlinux_path__find() helper
From: Aaron Tomlin
Date: Sat Oct 17 2026 - 22:14:10 EST
The vmlinux_path array maintains standard paths used by perf to locate
the kernel image (e.g. "vmlinux", "/boot/vmlinux",
"/lib/modules/%s/build/vmlinux", "/usr/lib/debug/..."). While
vmlinux_path__init() populates these candidates and dso__load_vmlinux_path()
loads symbols into a DSO/map, callers (such as test suites or probing tools)
often need to verify the existence of an accessible vmlinux on disk before
attempting machine setup or test execution.
Introduce vmlinux_path__find() to search through the configured vmlinux_path
entries (or symbol_conf.vmlinux_name if explicitly set) and return the
path to the first readable vmlinux file, or NULL if none is accessible.
Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>
---
tools/perf/util/symbol.c | 30 ++++++++++++++++++++++++++++++
tools/perf/util/symbol.h | 2 ++
2 files changed, 32 insertions(+)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 5d98888d068c..a46fd2f3f6a3 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2390,6 +2390,36 @@ static int vmlinux_path__init(struct perf_env *env)
return -1;
}
+/**
+ * vmlinux_path__find - Locate the first accessible vmlinux file
+ *
+ * Check symbol_conf.vmlinux_name first if set, then search through the
+ * initialized paths in vmlinux_path.
+ *
+ * Return: A pointer to the path of the first readable vmlinux file, or NULL if
+ * none is accessible.
+ */
+const char *vmlinux_path__find(void)
+{
+ int i;
+
+ if (symbol_conf.vmlinux_name && access(symbol_conf.vmlinux_name, R_OK) == 0)
+ return symbol_conf.vmlinux_name;
+
+ if (!vmlinux_path) {
+ symbol_conf.try_vmlinux_path = true;
+ if (vmlinux_path__init(NULL) < 0)
+ return NULL;
+ }
+
+ for (i = 0; i < vmlinux_path__nr_entries; ++i) {
+ if (access(vmlinux_path[i], R_OK) == 0)
+ return vmlinux_path[i];
+ }
+
+ return NULL;
+}
+
int setup_list(struct strlist **list, const char *list_str,
const char *list_name)
{
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index d0bac824c79c..6d1eb08076ab 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -184,6 +184,8 @@ static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
extern int vmlinux_path__nr_entries;
extern char **vmlinux_path;
+const char *vmlinux_path__find(void);
+
static inline void *symbol__priv(struct symbol *sym)
{
return ((void *)sym) - symbol_conf.priv_size;
--
2.55.0