perf symbol: Properly set DSO binary/symtab types
Namhyung Kim
maintainercover perf symbol: Properly set DSO binary/symtab types
Hello,
Currently we have 3 types for a DSO.
* binary type: determines where to read binary instruction or data of the DSO. Basically used by annotate. Some (special) DSOs like kallsyms or JIT may not have the data though.
* symtab type: determines where to read symbol tables. Set when symbols in the DSO are loaded.
* debug info type: determines where to read debug info. Used by srcline, DWARF unwinding, data type profiling and so on. Often debug info is saved in a separate file.
Some DSOs may have the same type for 3 and others can have all different. Previously it generally assumed binary type would be same as symtab type but now I think we should not and only set the binary type as it's used.
Also it should make sure that symtab type is set properly after loading symbols in the DSO.
Probably this patchset won't make any practical difference in runtime behaviors but I think it's good to track them accurately.
Thanks,
Namhyung
Namhyung Kim (7):
perf tools: Remove redundant dso data init
perf tools: Try linked debug files for DSO debug info perf symbol: Update symtab type of vmlinux from build-id cache perf symbol: Set binary/symtab type for split kallsyms perf symbol: Set dso symtab type for libbfd
perf symbol: Set binary type for JIT map DSOs
perf symbol: Do not set binary type from symtab type
tools/perf/util/dso.c | 3 +-- tools/perf/util/symbol.c | 23 ++++++++--------------- 2 files changed, 9 insertions(+), 17 deletions(-)
Signature · 1 line
2.55.0
Namhyung Kim
maintainerPATCH 1/7 perf tools: Remove redundant dso data init
The fd and status are initialized later with cache.
--- tools/perf/util/dso.c | 2 -- 1 file changed, 2 deletions(-)
tools/perf/util/dso.c +0 -2
@@ -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 ;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 1/7] perf tools: Remove redundant dso data init
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 3 lines
The fd and status are initialized later with cache.
Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Namhyung Kim
maintainerPATCH 2/7 perf tools: Try linked debug files for DSO debug info
In reply to Namhyung KimThe 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.
--- tools/perf/util/dso.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/dso.c +1 -0
@@ -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;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 2/7] perf tools: Try linked debug files for DSO debug info
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
The
dso__find_dbginfo_type()should tryDSO_BINARY_TYPE__DEBUGLINKso it can follow the .gnu_debuglink and find the debug information in the separate file.Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Namhyung Kim
maintainerPATCH 3/7 perf symbol: Update symtab type of vmlinux from build-id cache
In reply to Namhyung KimCurrently 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.
--- tools/perf/util/symbol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/symbol.c +4 -2
@@ -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 ) {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 3/7] perf symbol: Update symtab type of vmlinux from build-id cache
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Namhyung Kim
maintainerPATCH 4/7 perf symbol: Set binary/symtab type for split kallsyms
In reply to Namhyung KimWhen it creates new DSOs for split kallsyms, set the binary and symtab type to KALLSYMS properly.
--- tools/perf/util/symbol.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/symbol.c +2 -0
@@ -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);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 4/7] perf symbol: Set binary/symtab type for split kallsyms
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
When it creates new DSOs for split kallsyms, set the binary and symtab type to KALLSYMS properly.
Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Namhyung Kim
maintainerPATCH 5/7 perf symbol: Set dso symtab type for libbfd
In reply to Namhyung KimIt 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().
--- tools/perf/util/symbol.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/symbol.c +1 -0
@@ -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 ; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 5/7] perf symbol: Set dso symtab type for libbfd
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
It missed to set the dso symtab type when the symbols are loaded by libbfd. When it happens both
syms_ssandruntime_ssmay not be set and won't calldso__load_sym().Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Namhyung Kim
maintainerPATCH 6/7 perf symbol: Set binary type for JIT map DSOs
In reply to Namhyung KimThe 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.
--- tools/perf/util/symbol.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/symbol.c +1 -0
@@ -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 );
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 6/7] perf symbol: Set binary type for JIT map DSOs
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf: annotate regression on JIT map files due to unhandled binary type --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: annotate regression on JIT map files due to unhandled binary type --
commit 79781ef5615895fe2ec492b108f82094b6a0246b
Author: Namhyung Kim <[email protected]>
perf symbol: Set binary type for JIT map DSOs
This commit explicitly sets the binary type of JIT map DSOs to JAVA_JIT. This ensures they are identified correctly and bypass attempts to load dso_data, as they only contain symbol names and lack binary instructions.
tools/perf/util/symbol.c int dso__load(struct dso *dso, struct map *map) · line 1862
Quoted 8 lines
tools/perf/util/symbol.c +1
-0@@ -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 );
[Severity: Medium]
Does setting the binary type to DSO_BINARY_TYPE__JAVA_JIT here bypass the historical early exit guard in symbol__disassemble()?
Looking at symbol__disassemble() in tools/perf/util/disasm.c, it guards against unsupported files with:
if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
}With the type now explicitly set to DSO_BINARY_TYPE__JAVA_JIT, this check fails and allows perf annotate to incorrectly attempt disassembling the text map file.
The fallback binary disassemblers inevitably fail to parse the text file as ELF and return -1. This propagates back to symbol__strerror_disassemble(), which handles the -1 return by printing an unhelpful message to the user instead of gracefully exiting:
default:
scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
break;Should symbol__disassemble() be updated to check for DSO_BINARY_TYPE__JAVA_JIT so that it can exit gracefully when users try to annotate a JIT symbol profile?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Namhyung Kim
maintainerRe: [PATCH v1 6/7] perf symbol: Set binary type for JIT map DSOs
Quoted 42 lines · On Mon, Oct 05, 2026 at 06:46:16AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: annotate regression on JIT map files due to unhandled binary type --commit
79781ef5615895fe2ec492b108f82094b6a0246b
Author: Namhyung Kim <[email protected]>perf symbol: Set binary type for JIT map DSOs
This commit explicitly sets the binary type of JIT map DSOs to
JAVA_JIT. This ensures they are identified correctly and bypass attempts to loaddso_data, as they only contain symbol names and lack binary instructions.tools/perf/util/symbol.c int dso__load(struct dso *dso, struct map *map) · line 1862
Quoted 8 lines
tools/perf/util/symbol.c +1
-0@@ -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 );[Severity: Medium]
Does setting the binary type toDSO_BINARY_TYPE__JAVA_JIThere bypass the historical early exit guard insymbol__disassemble()?Looking at
symbol__disassemble()intools/perf/util/disasm.c, it guards against unsupported files with:if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) { return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE; }With the type now explicitly set to
DSO_BINARY_TYPE__JAVA_JIT, this check fails and allows perf annotate to incorrectly attempt disassembling the text map file.The fallback binary disassemblers inevitably fail to parse the text file as ELF and return -1. This propagates back to
symbol__strerror_disassemble(), which handles the -1 return by printing an unhelpful message to the user instead of gracefully exiting:
Quoted 6 lines
default: scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum); break;Should
symbol__disassemble()be updated to check forDSO_BINARY_TYPE__JAVA_JITso that it can exit gracefully when users try to annotate a JIT symbol profile?
Ok, but I think the dso__disassemble_filename() should be updated to set binary type correctly and just use dso__get_filename(). Will do in v2.
Thanks,
Namhyung
Namhyung Kim
maintainerPATCH 7/7 perf symbol: Do not set binary type from symtab type
In reply to Namhyung KimThe 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.
--- tools/perf/util/symbol.c | 13 ------------- 1 file changed, 13 deletions(-)
tools/perf/util/symbol.c +0 -13
@@ -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 {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v1 7/7] perf symbol: Do not set binary type from symtab type
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf: `perf annotate` and guest module data read broken by missing `binary_type` --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: perf annotate and guest module data read broken by missing binary_type --
commit 7196d300589913af007226f7522345f0d46a1af3
Author: Namhyung Kim <[email protected]>
perf symbol: Do not set binary type from symtab type
The commit separates DSO binary type from symtab type and removes the logic that sets the binary type from the symtab type in dso__load.
Quoted 11 lines
tools/perf/util/symbol.c +0
-3@@ -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
tools/perf/util/symbol.c int dso__load(struct dso *dso, struct map *map) · line 1971
Quoted 10 lines
tools/perf/util/symbol.c +0
-10-* 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); -
[Severity: Medium]
Will this removal cause perf annotate and guest module data reads to fail?
Without this logic, binary_type defaults to DSO_BINARY_TYPE__NOT_FOUND for generic DSOs, guest kernel modules, or binaries using debuginfo/system paths.
When tools/perf/util/dso.c:try_to_open_dso() is later called to read data, it only iterates over BUILD_ID_CACHE and SYSTEM_PATH_DSO when the binary type is NOT_FOUND, completely ignoring guest-specific paths that require machine->root_dir:
enum dso_binary_type binary_type_data[] = {
DSO_BINARY_TYPE__BUILD_ID_CACHE,
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
DSO_BINARY_TYPE__NOT_FOUND,
};Additionally, tools/perf/util/disasm.c:symbol__disassemble() explicitly returns an error if binary_type remains unset:
if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) {
return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE;
}Does this unintentionally break disassembly for binaries not in the build-id cache, or binary data reads for guest kernel modules?
Quoted 3 lines
tools/perf/util/symbol.c +0
-0if (syms_ss && runtime_ss)break ; }else {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Namhyung Kim
maintainerRe: [PATCH v1 7/7] perf symbol: Do not set binary type from symtab type
Quoted 28 lines · On Mon, Oct 05, 2026 at 06:45:30AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf:perf annotateand guest module data read broken by missingbinary_type--commit
7196d300589913af007226f7522345f0d46a1af3
Author: Namhyung Kim <[email protected]>perf symbol: Do not set binary type from symtab type
The commit separates DSO binary type from symtab type and removes the logic that sets the binary type from the symtab type in
dso__load.Quoted 16 lines
tools/perf/util/symbol.c +0
-8@@ -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 ||
Quoted 8 lines
tools/perf/util/symbol.c int dso__load(struct dso *dso, struct map *map) · line 1971
Quoted 5 lines
tools/perf/util/symbol.c +0
-5- 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); -[Severity: Medium]
Will this removal cause perf annotate and guest module data reads to fail?
I'm not sure if perf annotate would work well for guest modules.
Quoted 10 lines
Without this logic,
binary_typedefaults toDSO_BINARY_TYPE__NOT_FOUNDfor generic DSOs, guest kernel modules, or binaries using debuginfo/system paths.When tools/perf/util/dso.c:try_to_open_dso() is later called to read data, it only iterates over
BUILD_ID_CACHEandSYSTEM_PATH_DSOwhen the binary type isNOT_FOUND, completely ignoring guest-specific paths that requiremachine->root_dir:
Quoted 5 lines
enum dso_binary_type binary_type_data[] = {
DSO_BINARY_TYPE__BUILD_ID_CACHE,
DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
DSO_BINARY_TYPE__NOT_FOUND,
};I believe guest modules always need machine->root_dir to access the file. It won't get the correct file contents without it so the current code didn't work well.
Quoted 10 lines
Additionally, tools/perf/util/disasm.c:symbol__disassemble() explicitly returns an error if
binary_typeremains unset:if (dso__binary_type(dso) == DSO_BINARY_TYPE__NOT_FOUND) { return SYMBOL_ANNOTATE_ERRNO__COULDNT_DETERMINE_FILE_TYPE; }Does this unintentionally break disassembly for binaries not in the build-id cache, or binary data reads for guest kernel modules?
As I said in other reply, it should be updated to use binary type of the dso. I'll update the code in v2.
Thanks,
Namhyung