* [PATCH v2 01/10] perf tools: Remove redundant dso data init
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 02/10] perf tools: Try linked debug files for DSO debug info Namhyung Kim
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
The fd and status are initialized later with cache.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/dso.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index d3017c82ffb5f4b1..df03f84c9723560e 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1722,8 +1722,6 @@ struct dso *dso__new_id(const char *name, const struct dso_id *id)
dso->srclines = RB_ROOT_CACHED;
dso->data_types = RB_ROOT;
dso->global_vars = RB_ROOT;
- dso->data.fd = -1;
- dso->data.status = DSO_DATA_STATUS_UNKNOWN;
dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
dso->binary_type = DSO_BINARY_TYPE__NOT_FOUND;
dso->dbginfo_type = DSO_BINARY_TYPE__NOT_FOUND;
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 02/10] perf tools: Try linked debug files for DSO debug info
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 01/10] perf tools: Remove redundant dso data init Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 03/10] perf symbol: Update symtab type of vmlinux from build-id cache Namhyung Kim
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
The dso__find_dbginfo_type() should try DSO_BINARY_TYPE__DEBUGLINK so it
can follow the .gnu_debuglink and find the debug information in the
separate file.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/dso.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index df03f84c9723560e..913877b84b2d437e 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -2111,6 +2111,7 @@ void dso__find_dbginfo_type(struct dso *dso)
DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
+ DSO_BINARY_TYPE__DEBUGLINK,
DSO_BINARY_TYPE__NOT_FOUND,
};
const enum dso_binary_type *type;
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 03/10] perf symbol: Update symtab type of vmlinux from build-id cache
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 01/10] perf tools: Remove redundant dso data init Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 02/10] perf tools: Try linked debug files for DSO debug info Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 04/10] perf symbol: Set binary/symtab type for split kallsyms Namhyung Kim
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Currently dso__load_vmlinux() sets both binary type and symtab type to
VMLINUX. To precisely track the symtab type of the kernel dso, update
the type to build-id cache if it's loaded from there. It won't have
any functional difference though.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 5d98888d068c741a..cf099cbd29f268ec 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2079,7 +2079,7 @@ int dso__load_vmlinux_path(struct dso *dso, struct map *map)
if (filename != NULL) {
err = dso__load_vmlinux(dso, map, filename, true);
if (err > 0)
- goto out;
+ dso__set_symtab_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE);
}
out:
return err;
@@ -2235,8 +2235,10 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map)
filename = __dso__build_id_filename(dso, NULL, 0, false, false);
if (filename != NULL) {
err = dso__load_vmlinux(dso, map, filename, true);
- if (err > 0)
+ if (err > 0) {
+ dso__set_symtab_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE);
return err;
+ }
}
if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) {
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 04/10] perf symbol: Set binary/symtab type for split kallsyms
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (2 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 03/10] perf symbol: Update symtab type of vmlinux from build-id cache Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 05/10] perf symbol: Set dso symtab type for libbfd Namhyung Kim
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
When it creates new DSOs for split kallsyms, set the binary and symtab
type to KALLSYMS properly.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index cf099cbd29f268ec..fc6e4dff282bc2dc 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1099,6 +1099,8 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
return -1;
dso__set_kernel(ndso, dso__kernel(dso));
+ dso__set_binary_type(ndso, dso__binary_type(dso));
+ dso__set_symtab_type(ndso, dso__symtab_type(dso));
dso__set_loaded(ndso);
curr_map = map__new2(pos->start, ndso);
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 05/10] perf symbol: Set dso symtab type for libbfd
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (3 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 04/10] perf symbol: Set binary/symtab type for split kallsyms Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 06/10] perf tools: Factor out dso__find_binary_type() Namhyung Kim
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
It missed to set the dso symtab type when the symbols are loaded by
libbfd. When it happens both syms_ss and runtime_ss may not be set
and won't call dso__load_sym().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index fc6e4dff282bc2dc..02b096ccbc60ac2a 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1933,6 +1933,7 @@ int dso__load(struct dso *dso, struct map *map)
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
if (bfdrc == 0) {
+ dso__set_symtab_type(dso, symtab_type);
ret = 0;
break;
}
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 06/10] perf tools: Factor out dso__find_binary_type()
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (4 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 05/10] perf symbol: Set dso symtab type for libbfd Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 07/10] perf symbol: Set binary type for JIT map DSOs Namhyung Kim
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Separate out the logic to detect binary type of a DSO. It checks if the
candidate file contains ".text" section. It should be called under the
_dso__data_open_lock.
Introduce bintype_searched flag and it accessors to prevent repeated
(failed) search.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/dso.c | 100 +++++++++++++++++++++++++++++++++++++-----
tools/perf/util/dso.h | 13 ++++++
2 files changed, 102 insertions(+), 11 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 913877b84b2d437e..f5054c18a2e931e7 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -833,7 +833,7 @@ void dso__data_close(struct dso *dso)
mutex_unlock(dso__data_open_lock());
}
-static void try_to_open_dso(struct dso *dso, struct machine *machine)
+static enum dso_binary_type __dso__find_binary_type(struct dso *dso)
EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
{
enum dso_binary_type binary_type_data[] = {
@@ -842,25 +842,103 @@ static void try_to_open_dso(struct dso *dso, struct machine *machine)
DSO_BINARY_TYPE__NOT_FOUND,
};
int i = 0;
- struct dso_data *dso_data = dso__data(dso);
+ char *path;
+ bool found = false;
+ bool decomp = false;
- if (dso_data->fd >= 0)
- return;
+ if (dso__bintype_searched(dso))
+ return dso__binary_type(dso);
+ dso__set_bintype_searched(dso);
- if (dso__binary_type(dso) != DSO_BINARY_TYPE__NOT_FOUND) {
- dso_data->fd = open_dso(dso, machine);
- goto out;
+ switch (dso__binary_type(dso)) {
+ case DSO_BINARY_TYPE__KALLSYMS:
+ case DSO_BINARY_TYPE__GUEST_KALLSYMS:
+ case DSO_BINARY_TYPE__VMLINUX:
+ case DSO_BINARY_TYPE__GUEST_VMLINUX:
+ case DSO_BINARY_TYPE__KCORE:
+ case DSO_BINARY_TYPE__GUEST_KCORE:
+ /* Nothing to do with kernel images */
+ WARN_ON(!dso__kernel(dso));
+ return dso__binary_type(dso);
+ case DSO_BINARY_TYPE__BPF_PROG_INFO:
+ case DSO_BINARY_TYPE__BPF_IMAGE:
+ case DSO_BINARY_TYPE__OOL:
+ case DSO_BINARY_TYPE__JAVA_JIT:
+ /* Same for the special DSOs */
+ return dso__binary_type(dso);
+ case DSO_BINARY_TYPE__GUEST_KMODULE:
+ case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
+ case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
+ case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
+ case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
+ case DSO_BINARY_TYPE__BUILD_ID_CACHE:
+ /* We don't expect these are set; fall through */
+ case DSO_BINARY_TYPE__NOT_FOUND:
+ /* Let's find it out (for user DSOs or kernel modules) */
+ break;
+ case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
+ case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
+ case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO:
+ case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
+ case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO:
+ case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
+ case DSO_BINARY_TYPE__GNU_DEBUGDATA:
+ case DSO_BINARY_TYPE__DEBUGLINK:
+ default:
+ /* Unexpected binary types (usually debug only) */
+ break;
}
do {
dso__set_binary_type(dso, binary_type_data[i++]);
- dso_data->fd = open_dso(dso, machine);
- if (dso_data->fd >= 0)
- goto out;
+ path = dso__get_filename(dso, "", &decomp, dso__binary_type(dso));
+ if (path == NULL)
+ continue;
+
+ found = filename__has_section(path, ".text");
+ dso__put_filename(dso, path, decomp);
+ if (found)
+ return dso__binary_type(dso);
} while (dso__binary_type(dso) != DSO_BINARY_TYPE__NOT_FOUND);
-out:
+
+ if (dso__symtab_type(dso) != DSO_BINARY_TYPE__BUILD_ID_CACHE &&
+ dso__symtab_type(dso) != DSO_BINARY_TYPE__SYSTEM_PATH_DSO) {
+ path = dso__get_filename(dso, "", &decomp, dso__symtab_type(dso));
+ if (path == NULL)
+ return dso__binary_type(dso);
+
+ found = filename__has_section(path, ".text");
+ dso__put_filename(dso, path, decomp);
+ if (found)
+ dso__set_binary_type(dso, dso__symtab_type(dso));
+ }
+ return dso__binary_type(dso);
+}
+
+enum dso_binary_type dso__find_binary_type(struct dso *dso)
+{
+ enum dso_binary_type ret;
+
+ mutex_lock(dso__data_open_lock());
+ ret = __dso__find_binary_type(dso);
+ mutex_unlock(dso__data_open_lock());
+
+ return ret;
+}
+
+static void try_to_open_dso(struct dso *dso, struct machine *machine)
+ EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
+{
+ struct dso_data *dso_data = dso__data(dso);
+
+ if (dso_data->fd >= 0)
+ return;
+
+ __dso__find_binary_type(dso);
+ dso_data->fd = open_dso(dso, machine);
+
if (dso_data->fd >= 0)
dso_data->status = DSO_DATA_STATUS_OK;
else
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 3f08d45e7f53a508..3329f417810c25a4 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -349,6 +349,7 @@ DECLARE_RC_STRUCT(dso) {
u8 short_name_allocated:1;
u8 long_name_allocated:1;
u8 is_64_bit:1;
+ u8 bintype_searched:1;
u8 debuginfo_searched:1;
bool sorted_by_name;
bool loaded;
@@ -957,6 +958,8 @@ void dso__reset_find_symbol_cache(struct dso *dso);
size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
size_t dso__fprintf(struct dso *dso, FILE *fp);
+enum dso_binary_type dso__find_binary_type(struct dso *dso);
+
static inline enum dso_binary_type dso__binary_type(const struct dso *dso)
{
return RC_CHK_ACCESS(dso)->binary_type;
@@ -967,6 +970,16 @@ static inline void dso__set_binary_type(struct dso *dso, enum dso_binary_type bt
RC_CHK_ACCESS(dso)->binary_type = bt;
}
+static inline bool dso__bintype_searched(const struct dso *dso)
+{
+ return RC_CHK_ACCESS(dso)->bintype_searched;
+}
+
+static inline void dso__set_bintype_searched(struct dso *dso)
+{
+ RC_CHK_ACCESS(dso)->bintype_searched = 1;
+}
+
static inline bool dso__is_vmlinux(const struct dso *dso)
{
enum dso_binary_type bt = dso__binary_type(dso);
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 07/10] perf symbol: Set binary type for JIT map DSOs
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (5 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 06/10] perf tools: Factor out dso__find_binary_type() Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 08/10] perf symbol: Do not set binary type from symtab type Namhyung Kim
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
The perf-<pid>.map files contain symbol name of JIT functions.
As they don't have the binary data (instructions) no need to try
for dso_data. Let's set the binary type regardless of the result
of symbol loading so that it can be ignored.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 02b096ccbc60ac2a..389dbd7e5192f4f2 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1859,6 +1859,7 @@ int dso__load(struct dso *dso, struct map *map)
if (perfmap) {
ret = dso__load_perf_map(map_path, dso);
+ dso__set_binary_type(dso, DSO_BINARY_TYPE__JAVA_JIT);
dso__set_symtab_type(dso, ret > 0
? DSO_BINARY_TYPE__JAVA_JIT
: DSO_BINARY_TYPE__NOT_FOUND);
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 08/10] perf symbol: Do not set binary type from symtab type
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (6 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 07/10] perf symbol: Set binary type for JIT map DSOs Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 09/10] perf annotate: Simplify symbol__disassemble() with dso binary_type Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 10/10] perf test: Fix dso data tests Namhyung Kim
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
The DSO binary type is to access the binary (e.g. instruction) data
while symtab type is for the symbol table. They may or may not be in
the same file. We should track them separately and correctly.
As special binaries already set their type before loading symbols, leave
the binary type info and only update it when actually opening the DSO.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 389dbd7e5192f4f2..1175cb60f8206757 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1956,19 +1956,6 @@ int dso__load(struct dso *dso, struct map *map)
if (next_slot) {
ss_pos++;
-
- /*
- * The binary type is used to find the file containing
- * the executed instructions, so prefer the types that
- * refer to the actual object over debug-only files such
- * as DSO_BINARY_TYPE__DEBUGLINK.
- */
- if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND ||
- symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE ||
- (symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_DSO &&
- dso__binary_type(dso) != DSO_BINARY_TYPE__BUILD_ID_CACHE))
- dso__set_binary_type(dso, symtab_type);
-
if (syms_ss && runtime_ss)
break;
} else {
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 09/10] perf annotate: Simplify symbol__disassemble() with dso binary_type
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (7 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 08/10] perf symbol: Do not set binary type from symtab type Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
2026-10-06 23:43 ` [PATCH v2 10/10] perf test: Fix dso data tests Namhyung Kim
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Now it should set the binary type of a DSO properly. No need to figure
out a filename suitable for disassembly.
Just call dso__find_binary_type() and dso__get_filename() for that type.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/disasm.c | 116 ++++++---------------------------------
1 file changed, 16 insertions(+), 100 deletions(-)
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 5478c134e7e3b8df..07a345beb6250a0f 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -1176,84 +1176,6 @@ int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, s
return 0;
}
-static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filename_size)
-{
- char linkname[PATH_MAX];
- char *build_id_filename;
- char *build_id_path = NULL;
- char *pos;
- int len;
-
- if (dso__symtab_type(dso) == DSO_BINARY_TYPE__KALLSYMS &&
- !dso__is_kcore(dso))
- return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;
-
- build_id_filename = dso__build_id_filename(dso, NULL, 0, false);
- if (build_id_filename) {
- /*
- * This is a path in perf's own build id cache, not a path on
- * the profiled system, so the symfs layout does not apply.
- */
- path__join(filename, filename_size, symbol_conf.symfs,
- build_id_filename);
- free(build_id_filename);
- } else {
- if (dso__has_build_id(dso))
- return ENOMEM;
- goto fallback;
- }
-
- build_id_path = strdup(filename);
- if (!build_id_path)
- return ENOMEM;
-
- /*
- * old style build-id cache has name of XX/XXXXXXX.. while
- * new style has XX/XXXXXXX../{elf,kallsyms,vdso}.
- * extract the build-id part of dirname in the new style only.
- */
- pos = strrchr(build_id_path, '/');
- if (pos && strlen(pos) < SBUILD_ID_SIZE - 2)
- dirname(build_id_path);
-
- if (dso__is_kcore(dso))
- goto fallback;
-
- len = readlink(build_id_path, linkname, sizeof(linkname) - 1);
- if (len < 0)
- goto fallback;
-
- linkname[len] = '\0';
- if (strstr(linkname, DSO__NAME_KALLSYMS) ||
- access(filename, R_OK)) {
-fallback:
- /*
- * If we don't have build-ids or the build-id file isn't in the
- * cache, or is just a kallsyms file, well, lets hope that this
- * DSO is the same as when 'perf record' ran.
- */
- if (dso__kernel(dso) && dso__long_name(dso)[0] == '/')
- snprintf(filename, filename_size, "%s", dso__long_name(dso));
- else
- __symbol__join_symfs(filename, filename_size, dso__long_name(dso));
-
- mutex_lock(dso__lock(dso));
- if (access(filename, R_OK) && errno == ENOENT && dso__nsinfo(dso)) {
- char *new_name = dso__filename_with_chroot(dso, filename);
- if (new_name) {
- strlcpy(filename, new_name, filename_size);
- free(new_name);
- }
- }
- mutex_unlock(dso__lock(dso));
- } else if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
- dso__set_binary_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE);
- }
-
- free(build_id_path);
- return 0;
-}
-
static int symbol__disassemble_raw(char *filename, struct symbol *sym,
struct annotate_args *args)
{
@@ -1566,24 +1488,30 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
struct annotation_options *options = args->options;
struct map *map = args->ms->map;
struct dso *dso = map__dso(map);
- char symfs_filename[PATH_MAX];
+ char *symfs_filename;
bool delete_extract = false;
struct kcore_extract kce;
+ enum dso_binary_type dbt;
bool decomp = false;
- int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename));
+ int err;
- if (err)
- return err;
+ dbt = dso__find_binary_type(dso);
+
+ if (dbt == DSO_BINARY_TYPE__KALLSYMS)
+ return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;
+
+ symfs_filename = dso__get_filename(dso, "", &decomp, dbt);
+ if (symfs_filename == NULL && dbt != DSO_BINARY_TYPE__BPF_PROG_INFO &&
+ dbt != DSO_BINARY_TYPE__BPF_IMAGE)
+ return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
- symfs_filename, sym->name, map__unmap_ip(map, sym->start),
- map__unmap_ip(map, sym->end));
+ symfs_filename ?: dso__long_name(dso), sym->name,
+ map__unmap_ip(map, sym->start), map__unmap_ip(map, sym->end));
pr_debug("annotating [%p] %30s : [%p] %30s\n", dso, dso__long_name(dso), sym, sym->name);
- if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
- return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
- } else if (dso__is_kcore(dso)) {
+ if (dso__is_kcore(dso)) {
kce.addr = map__rip_2objdump(map, sym->start);
kce.kcore_filename = symfs_filename;
kce.len = sym->end - sym->start;
@@ -1593,17 +1521,6 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
delete_extract = true;
strlcpy(symfs_filename, kce.extract_filename, sizeof(symfs_filename));
}
- } else if (dso__needs_decompress(dso)) {
- char tmp[KMOD_DECOMP_LEN];
-
- if (dso__decompress_kmodule_path(dso, symfs_filename, tmp, sizeof(tmp)) < 0)
- return -1;
-
- /* empty pathname means file wasn't actually compressed */
- if (tmp[0] != '\0') {
- decomp = true;
- strcpy(symfs_filename, tmp);
- }
}
/*
@@ -1660,8 +1577,7 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
pr_debug("Disassembled with %s\n", perf_disassembler__strs[dis]);
}
out_remove_tmp:
- if (decomp)
- unlink(symfs_filename);
+ dso__put_filename(dso, symfs_filename, decomp);
if (delete_extract)
kcore_extract__delete(&kce);
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 10/10] perf test: Fix dso data tests
2026-10-06 23:43 [PATCH v2 00/10] perf symbol: Properly set DSO binary/symtab types Namhyung Kim
` (8 preceding siblings ...)
2026-10-06 23:43 ` [PATCH v2 09/10] perf annotate: Simplify symbol__disassemble() with dso binary_type Namhyung Kim
@ 2026-10-06 23:43 ` Namhyung Kim
9 siblings, 0 replies; 11+ messages in thread
From: Namhyung Kim @ 2026-10-06 23:43 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Now dso__binary_type() requires that the target file is a valid ELF file
containing ".text" section. But the test only checks cached read/write
operation on a file. Let's set the binary type to bypass the ELF check
to read/write the file properly.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/tests/dso-data.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index 46bc3f59726004fa..5a027ffab541b4a2 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -138,6 +138,9 @@ static int test__dso_data(struct test_suite *test __maybe_unused, int subtest __
dsos__init(&machine.dsos);
dso = dso__new(file);
+ /* override the binary type for dso data access */
+ dso__set_binary_type(dso, DSO_BINARY_TYPE__SYSTEM_PATH_DSO);
+ dso__set_bintype_searched(dso);
TEST_ASSERT_VAL("Failed to add dso", !dsos__add(&machine.dsos, dso));
TEST_ASSERT_VAL("Failed to access to dso",
dso__data_fd(dso, &machine) >= 0);
@@ -225,6 +228,9 @@ static int dsos__create(int cnt, int size, struct dsos *dsos)
TEST_ASSERT_VAL("failed to get dso file", file);
dso = dso__new(file);
+ /* override the binary type for dso data access */
+ dso__set_binary_type(dso, DSO_BINARY_TYPE__SYSTEM_PATH_DSO);
+ dso__set_bintype_searched(dso);
TEST_ASSERT_VAL("failed to get dso", dso);
TEST_ASSERT_VAL("failed to add dso", !dsos__add(dsos, dso));
dso__put(dso);
--
2.56.0.rc1.315.gc6ed9934b7-goog
^ permalink raw reply [flat|nested] 11+ messages in thread