Skip to contentSkip to conversation

perf symbol: Properly seto DSO binary/symtab types

PATCH Superseded Namhyung Kim 2 participants 24 messages Oct 12 – Oct 13 perf events

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

v4 cover perf symbol: Properly seto 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.

v4 changes)

* add Ian's Reviewed-by tags
* make sure to grab _dso__data_open_lock only once
* check open file count before closing the cache
* clear errno so that it won't have a stale value

v3: https://lore.kernel.org/r/[email protected]

* set KALLSYM type for split kallsyms DSOs
* take dso lock in dso__find_binary_type()
* handle EMFILE failures in dso__find_binary_type()
* drop the libbfd change as it need a separate patchset
* lookup binary type in dso__e_machine_endian()
* get rid of machine_or_dso_e_machine() due to a lock problem
* fixed a bug symbol__disassemble() for BPF and kcore

v2: https://lore.kernel.org/r/[email protected]

* add dso__find_binary_type() for checking ".text" section
* make perf annotate use the dso's binary type directly

v1: https://lore.kernel.org/r/[email protected]

Thanks,
Namhyung

Namhyung Kim (10):
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: Get rid of machine_or_dso_e_machine()
perf tools: Factor out dso__find_binary_type()
perf symbol: Set binary type for JIT map DSOs
perf symbol: Do not set binary type from symtab type perf annotate: Simplify symbol__disassemble() with dso binary_type perf test: Fix dso data tests

 tools/perf/tests/dso-data.c |   7 ++
 tools/perf/util/disasm.c    | 124 ++++++-------------------------
 tools/perf/util/dso.c       | 143 ++++++++++++++++++++++++++++++++----
 tools/perf/util/dso.h       |  13 ++++
 tools/perf/util/symbol.c    |  50 ++++---------
 5 files changed, 187 insertions(+), 150 deletions(-)
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
author maintainer
#1 lore raw

PATCH v4 1/10 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
index d3017c82ffb5f4b1..df03f84c9723560e 100644
@@ -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.56.0.385.gd3acb90ef8-goog
#2 lore raw

Re: [PATCH v4 01/10] perf tools: Remove redundant dso data init

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

The fd and status are initialized later with cache.

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
author maintainer
#3 lore raw

PATCH v4 2/10 perf tools: Try linked debug files for DSO debug info

In reply to Namhyung Kim

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.

---
 tools/perf/util/dso.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/dso.c +1 -0
index df03f84c9723560e..913877b84b2d437e 100644
@@ -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.56.0.385.gd3acb90ef8-goog
#4 lore raw

Re: [PATCH v4 02/10] perf tools: Try linked debug files for DSO debug info

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf dso: DEBUGLINK path resolution flaws in dso__read_binary_type_filename --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf dso: DEBUGLINK path resolution flaws in dso__read_binary_type_filename --

commit 0c61bd07a4d26ed6f7bfc347b3ec0fe6ffc13ca0
Author: Namhyung Kim <[email protected]>

perf tools: Try linked debug files for DSO debug info

This commit modifies dso__find_dbginfo_type() to include DSO_BINARY_TYPE__DEBUGLINK in its search array. This allows perf to follow .gnu_debuglink to locate debug information in separate files.

tools/perf/util/dso.c void dso__find_dbginfo_type(struct dso *dso) · line 2114

Quoted 9 lines
tools/perf/util/dso.c +1 -0
index df03f84c97235..913877b84b2d4 100644
@@ -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,

[Severity: Medium]
Enabling DSO_BINARY_TYPE__DEBUGLINK here exposes path resolution regressions in dso__read_binary_type_filename().

If the filename lacks slashes, does this logic create an empty string for dso_dir, breaking relative paths?

tools/perf/util/dso.c:dso__read_binary_type_filename() {
	...
	last_slash = filename + len;
	while (last_slash != filename && *last_slash != '/')
		last_slash--;

	strncpy(dso_dir, filename, last_slash - filename);
	dso_dir[last_slash-filename] = '\0';
	...
}

Additionally, does this direct host filesystem I/O bypass the container mount namespace (/proc/<pid>/root/) fallback context?

tools/perf/util/dso.c:dso__read_binary_type_filename() {
	...
	if (!is_regular_file(filename)) {
		ret = -1;
		break;
	}

	ret = filename__read_debuglink(filename, symfile, PATH_MAX);
	...
}

Finally, does this inject the symfs-prefixed dso_dir into the middle of the /usr/lib/debug path, searching the host filesystem instead of the symfs chroot?

tools/perf/util/dso.c:dso__read_binary_type_filename() {
	...
	for (i = 0; i < ARRAY_SIZE(debuglink_paths); i++) {
		snprintf(filename, size,
				debuglink_paths[i], dso_dir, symfile);
	...
}
Quoted 3 lines
tools/perf/util/dso.c +0 -0
 		DSO_BINARY_TYPE__NOT_FOUND,
 	};
 	const enum dso_binary_type *type;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#5 lore raw

Re: [PATCH v4 02/10] perf tools: Try linked debug files for DSO debug info

Quoted 30 lines · On Mon, Oct 12, 2026 at 11:56:52PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf dso: DEBUGLINK path resolution flaws in dso__read_binary_type_filename --

commit 0c61bd07a4d26ed6f7bfc347b3ec0fe6ffc13ca0
Author: Namhyung Kim <[email protected]>

perf tools: Try linked debug files for DSO debug info

This commit modifies dso__find_dbginfo_type() to include DSO_BINARY_TYPE__DEBUGLINK in its search array. This allows perf to follow .gnu_debuglink to locate debug information in separate files.

tools/perf/util/dso.c void dso__find_dbginfo_type(struct dso *dso) · line 2114

Quoted 9 lines
tools/perf/util/dso.c +1 -0
index df03f84c97235..913877b84b2d4 100644
@@ -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,

[Severity: Medium]
Enabling DSO_BINARY_TYPE__DEBUGLINK here exposes path resolution regressions in dso__read_binary_type_filename().

If the filename lacks slashes, does this logic create an empty string for dso_dir, breaking relative paths?

Quoted 10 lines
tools/perf/util/dso.c:dso__read_binary_type_filename() {
	...
	last_slash = filename + len;
	while (last_slash != filename && *last_slash != '/')
		last_slash--;

	strncpy(dso_dir, filename, last_slash - filename);
	dso_dir[last_slash-filename] = '\0';
	...
}

Then it'd be a separate, pre-existing issue. Will handle it independently.

Quoted 15 lines

Additionally, does this direct host filesystem I/O bypass the container mount namespace (/proc/<pid>/root/) fallback context?

tools/perf/util/dso.c:dso__read_binary_type_filename() {
	...
	if (!is_regular_file(filename)) {
		ret = -1;
		break;
	}

	ret = filename__read_debuglink(filename, symfile, PATH_MAX);
	...
}
Quoted 3 lines

Finally, does this inject the symfs-prefixed dso_dir into the middle of the /usr/lib/debug path, searching the host filesystem instead of the symfs chroot?

Also this is known, separate issue. Let me handle it in a separate series after this.

Thanks,
Namhyung

Quoted 15 lines
tools/perf/util/dso.c:dso__read_binary_type_filename() {
	...
	for (i = 0; i < ARRAY_SIZE(debuglink_paths); i++) {
		snprintf(filename, size,
				debuglink_paths[i], dso_dir, symfile);
	...
}
Quoted 3 lines
tools/perf/util/dso.c +0 -0
 		DSO_BINARY_TYPE__NOT_FOUND,
 	};
 	const enum dso_binary_type *type;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#6 lore raw

PATCH v4 3/10 perf symbol: Update symtab type of vmlinux from build-id cache

In reply to Namhyung Kim

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.

---
 tools/perf/util/symbol.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/symbol.c +4 -2
index 5d98888d068c741a..cf099cbd29f268ec 100644
@@ -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.56.0.385.gd3acb90ef8-goog
#7 lore raw

Re: [PATCH v4 03/10] perf symbol: Update symtab type of vmlinux from build-id cache

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 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.

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
author maintainer
#8 lore raw

PATCH v4 4/10 perf symbol: Set binary/symtab type for split kallsyms

In reply to Namhyung Kim

When it creates new DSOs for split kallsyms, set the binary and symtab type to KALLSYMS properly.

---
 tools/perf/util/symbol.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/util/symbol.c +7 -0
index cf099cbd29f268ec..56b8d75966133f87 100644
@@ -1099,6 +1099,13 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 				return -1;
 
 			dso__set_kernel(ndso, dso__kernel(dso));
+			if (dso__kernel(dso) == DSO_SPACE__KERNEL_GUEST) {
+				dso__set_binary_type(ndso, DSO_BINARY_TYPE__GUEST_KALLSYMS);
+				dso__set_symtab_type(ndso, DSO_BINARY_TYPE__GUEST_KALLSYMS);
+			} else {
+				dso__set_binary_type(ndso, DSO_BINARY_TYPE__KALLSYMS);
+				dso__set_symtab_type(ndso, DSO_BINARY_TYPE__KALLSYMS);
+			}
 			dso__set_loaded(ndso);
 
 			curr_map = map__new2(pos->start, ndso);
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#9 lore raw

Re: [PATCH v4 04/10] perf symbol: Set binary/symtab type for split kallsyms

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

When it creates new DSOs for split kallsyms, set the binary and symtab type to KALLSYMS properly.

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
author maintainer
#10 lore raw

PATCH v4 5/10 perf symbol: Get rid of machine_or_dso_e_machine()

In reply to Namhyung Kim

The function tries to get e_machine from a DSO (preferred) or env from the machine. But currently it's only used for kernel DSO's during the load which refers to /proc/kallsyms most likely and it doesn't have an ELF header.

Also machine->env would have proper information about the kernel so no need to check DSO in this case. Actually check DSO's e_machine requires a correct binary type to be set but it'd cause a recursive locking problem. I think it's ok to use machine->env info for the kernel.

---
 tools/perf/util/symbol.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)
tools/perf/util/symbol.c +3 -20
index 56b8d75966133f87..a7afecb5816c25f8 100644
@@ -967,23 +967,6 @@ static int maps__split_kallsyms_for_kcore(struct maps *kmaps, struct dso *dso)
 	return count;
 }
 
-static uint16_t machine_or_dso_e_machine(struct machine *machine, struct dso *dso)
-{
-	uint16_t e_machine = EM_NONE;
-	/* DSO should be most accurate */
-	if (dso)
-		e_machine = dso__e_machine(dso, machine, /*e_flags=*/NULL);
-
-	if (e_machine != EM_NONE)
-		return e_machine;
-
-	/* Check the global environment next. */
-	if (machine && machine->env && machine->env->e_machine != EM_NONE)
-		return machine->env->e_machine;
-
-	return perf_env__e_machine(machine ? machine->env : NULL, /*e_flags=*/NULL);
-}
-
 /*
  * Split the symbols into maps, making sure there are no overlaps, i.e. the
  * kernel range is broken in several maps, named [kernel].N, as we don't have
@@ -1005,7 +988,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
 		return -1;
 
 	machine = maps__machine(kmaps);
-	e_machine = machine_or_dso_e_machine(machine, dso);
+	e_machine = perf_env__e_machine(machine->env, /*e_flags=*/NULL);
 
 	while (next) {
 		char *module;
@@ -1567,7 +1550,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		free(new_node);
 	}
 
-	if (machine_or_dso_e_machine(machine, dso) == EM_X86_64) {
+	if (perf_env__e_machine(machine->env, /*e_flags=*/NULL) == EM_X86_64) {
 		u64 addr;
 
 		/*
@@ -1855,7 +1838,7 @@ int dso__load(struct dso *dso, struct map *map)
 			ret = dso__load_guest_kernel_sym(dso, map);
 
 		machine = maps__machine(map__kmaps(map));
-		if (machine && machine_or_dso_e_machine(machine, dso) == EM_X86_64)
+		if (perf_env__e_machine(machine->env, /*e_flags=*/NULL) == EM_X86_64)
 			machine__map_x86_64_entry_trampolines(machine, dso);
 		goto out;
 	}
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#11 lore raw

Re: [PATCH v4 05/10] perf symbol: Get rid of machine_or_dso_e_machine()

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

The function tries to get e_machine from a DSO (preferred) or env from the machine. But currently it's only used for kernel DSO's during the load which refers to /proc/kallsyms most likely and it doesn't have an ELF header.

Quoted 7 lines

Also machine->env would have proper information about the kernel so no need to check DSO in this case. Actually check DSO's e_machine requires a correct binary type to be set but it'd cause a recursive locking problem. I think it's ok to use machine->env info for the kernel.

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
author maintainer
#12 lore raw

PATCH v4 6/10 perf tools: Factor out dso__find_binary_type()

In reply to Namhyung Kim

Separate out the logic to detect binary type of a DSO. It checks if the candidate file contains ".text" section. There could be data-only DSOs but as our use cases focus on the code (perf annotate or intel PT), we can ignore them for now.

But it also can fail due to open file limit. Handle the case by retrying with _dso__data_open_lock.

Introduce bintype_searched flag and it accessors to prevent repeated (failed) search.

---
 tools/perf/util/dso.c | 137 ++++++++++++++++++++++++++++++++++++++----
 tools/perf/util/dso.h |  13 ++++
 2 files changed, 138 insertions(+), 12 deletions(-)
tools/perf/util/dso.c +125 -12
index 913877b84b2d437e..c42ad0c5c66a7bcd 100644
@@ -833,34 +833,147 @@ 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)
-	EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
+static int dso__find_binary_type_locked(struct dso *dso)
+	EXCLUSIVE_LOCKS_REQUIRED(dso__lock(dso))
 {
 	enum dso_binary_type binary_type_data[] = {
 		DSO_BINARY_TYPE__BUILD_ID_CACHE,
 		DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
+		dso__symtab_type(dso),
 		DSO_BINARY_TYPE__NOT_FOUND,
 	};
 	int i = 0;
-	struct dso_data *dso_data = dso__data(dso);
+	char *path;
+	bool found = false;
+	bool decomp = false;
+	int saved_errno;
 
-	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) {
+			if (errno == EMFILE)
+				goto open_err;
+			continue;
+		}
+
+		errno = 0;
+		found = filename__has_section(path, ".text");
+		if (!found)
+			saved_errno = errno;
+		dso__put_filename(dso, path, decomp);
+
+		if (found)
+			return dso__binary_type(dso);
+		else if (saved_errno == EMFILE)
+			goto open_err;
 
 	} while (dso__binary_type(dso) != DSO_BINARY_TYPE__NOT_FOUND);
-out:
+
+	return dso__binary_type(dso);
+
+open_err:
+	/* Too many open files.  Allow retry after closing one. */
+	RC_CHK_ACCESS(dso)->bintype_searched = 0;
+	dso__set_binary_type(dso, DSO_BINARY_TYPE__NOT_FOUND);
+	return -1;
+}
+
+#define FIND_MAX_RETRY  3
+static int __dso__find_binary_type(struct dso *dso, bool needs_open_lock)
+{
+	int ret;
+	int retry = 0;
+
+again:
+	mutex_lock(dso__lock(dso));
+	ret = dso__find_binary_type_locked(dso);
+	mutex_unlock(dso__lock(dso));
+
+	if (ret == -1 && retry++ < FIND_MAX_RETRY) {
+		if (needs_open_lock && retry == 1)
+			mutex_lock(dso__data_open_lock());
+
+		if (dso__data_open_cnt) {
+			close_first_dso();
+			goto again;
+		}
+	}
+
+	if (retry > 0 && needs_open_lock)
+		mutex_unlock(dso__data_open_lock());
+
+	if (ret == -1) {
+		mutex_lock(dso__lock(dso));
+		ret = dso__binary_type(dso);
+		dso__set_bintype_searched(dso);
+		mutex_unlock(dso__lock(dso));
+	}
+
+	return ret;
+}
+#undef FIND_MAX_RETRY
+
+enum dso_binary_type dso__find_binary_type(struct dso *dso)
+{
+	return __dso__find_binary_type(dso, /*needs_open_lock=*/true);
+}
+
+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, /*needs_open_lock=*/false);
+	dso_data->fd = open_dso(dso, machine);
+
 	if (dso_data->fd >= 0)
 		dso_data->status = DSO_DATA_STATUS_OK;
 	else
tools/perf/util/dso.h +13 -0
index 3f08d45e7f53a508..3329f417810c25a4 100644
@@ -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);
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#13 lore raw

Re: [PATCH v4 06/10] perf tools: Factor out dso__find_binary_type()

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf: spurious FD-eviction and DSO failure due to uninitialized errno --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: spurious FD-eviction and DSO failure due to uninitialized errno --

commit 00af7deeab2857b031fe6b82dcee452b2fe4afb8
Author: Namhyung Kim <[email protected]>

perf tools: Factor out dso__find_binary_type()

This commit separates out the logic to detect the binary type of a DSO by checking if the candidate file contains a .text section. It ignores data-only DSOs and adds handling to retry with the DSO data open lock if the search fails due to hitting the open file limit.

Quoted 4 lines
tools/perf/util/dso.c +0 -0
index 913877b84b2d4..c42ad0c5c66a7 100644

[ ... ]

tools/perf/util/dso.c void dso__data_close(struct dso *dso) · line 900

Quoted 10 lines
tools/perf/util/dso.c +6 -3
+	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) {
+			if (errno == EMFILE)
+				goto open_err;

[Severity: Medium]
Could this lead to spurious FD evictions and failure to find the binary type if errno is already EMFILE from a prior, unrelated operation?

If dso__get_filename() returns NULL for a normal reason (such as a missing build-id cache) without touching errno, it appears a stale EMFILE would cause an early abort to the open_err label.

Since the caller __dso__find_binary_type() evicts a DSO and retries up to 3 times, and errno would remain EMFILE across those retries, it seems this might permanently mark the DSO binary type as NOT_FOUND.

Would it make sense to clear errno before calling dso__get_filename()?

Quoted 5 lines
tools/perf/util/dso.c +5 -0
+			continue;
+		}
+
+		errno = 0;
+		found = filename__has_section(path, ".text");

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
author maintainer
#14 lore raw

Re: [PATCH v4 06/10] perf tools: Factor out dso__find_binary_type()

Quoted 38 lines · On Mon, Oct 12, 2026 at 11:58:48PM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: spurious FD-eviction and DSO failure due to uninitialized errno --

commit 00af7deeab2857b031fe6b82dcee452b2fe4afb8
Author: Namhyung Kim <[email protected]>

perf tools: Factor out dso__find_binary_type()

This commit separates out the logic to detect the binary type of a DSO by checking if the candidate file contains a .text section. It ignores data-only DSOs and adds handling to retry with the DSO data open lock if the search fails due to hitting the open file limit.

Quoted 4 lines
tools/perf/util/dso.c +0 -0
index 913877b84b2d4..c42ad0c5c66a7 100644

[ ... ]

tools/perf/util/dso.c void dso__data_close(struct dso *dso) · line 900

Quoted 10 lines
tools/perf/util/dso.c +6 -3
+	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) {
+			if (errno == EMFILE)
+				goto open_err;

[Severity: Medium]
Could this lead to spurious FD evictions and failure to find the binary type if errno is already EMFILE from a prior, unrelated operation?

If dso__get_filename() returns NULL for a normal reason (such as a missing build-id cache) without touching errno, it appears a stale EMFILE would cause an early abort to the open_err label.

Quoted 5 lines

Since the caller __dso__find_binary_type() evicts a DSO and retries up to 3 times, and errno would remain EMFILE across those retries, it seems this might permanently mark the DSO binary type as NOT_FOUND.

Would it make sense to clear errno before calling dso__get_filename()?

Ok, I'll add that too.

Thanks,
Namhyung

Quoted 10 lines
Quoted 6 lines
tools/perf/util/dso.c +5 -0
+			continue;
+		}
+
+		errno = 0;
+		found = filename__has_section(path, ".text");

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
author maintainer
#15 lore raw

PATCH v4 7/10 perf symbol: Set binary type for JIT map DSOs

In reply to Namhyung Kim

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.

---
 tools/perf/util/symbol.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/symbol.c +1 -0
index a7afecb5816c25f8..4a8c298039447cec 100644
@@ -1847,6 +1847,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.56.0.385.gd3acb90ef8-goog
#16 lore raw

Re: [PATCH v4 07/10] perf symbol: Set binary type for JIT map DSOs

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

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.

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=7
author maintainer
#17 lore raw

PATCH v4 8/10 perf symbol: Do not set binary type from symtab type

In reply to Namhyung Kim

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.

---
 tools/perf/util/dso.c    |  3 ++-
 tools/perf/util/symbol.c | 13 -------------
 2 files changed, 2 insertions(+), 14 deletions(-)
tools/perf/util/dso.c +2 -1
index c42ad0c5c66a7bcd..5d25f766172b1fcb 100644
@@ -1490,9 +1490,10 @@ uint16_t dso__e_machine_endian(struct dso *dso, struct machine *machine, uint32_
 			       bool *is_big_endian)
 {
 	uint16_t e_machine = EM_NONE;
+	enum dso_binary_type dbt = dso__find_binary_type(dso);
 	int fd;
 
-	switch (dso__binary_type(dso)) {
+	switch (dbt) {
 	case DSO_BINARY_TYPE__KALLSYMS:
 	case DSO_BINARY_TYPE__GUEST_KALLSYMS:
 	case DSO_BINARY_TYPE__VMLINUX:
tools/perf/util/symbol.c +0 -13
index 4a8c298039447cec..116870595f75c7dd 100644
@@ -1943,19 +1943,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.56.0.385.gd3acb90ef8-goog
#18 lore raw

Re: [PATCH v4 08/10] 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: fully stripped executables falsely rejected for data access --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: fully stripped executables falsely rejected for data access --

commit 6b9e46855d4e0d8df1dcaaed600da2f693471adb
Author: Namhyung Kim <[email protected]>

perf symbol: Do not set binary type from symtab type

This commit separates tracking of the DSO binary type from the symtab type. It removes the explicit setting of the binary type during symbol loading, deferring it until the DSO is actually opened.

Quoted 11 lines
tools/perf/util/symbol.c +0 -3
index 4a8c298039447..116870595f75c 100644
@@ -1943,19 +1943,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 1958

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 removing this explicit assignment cause fully stripped executables to be falsely rejected during data access operations like perf annotate?

By leaving the DSO binary type as NOT_FOUND here, disassembly paths are forced to fall back to dso__find_binary_type_locked() to identify the file type. That logic attempts to verify the file using filename__has_section() for the .text section:

tools/perf/util/dso.c:dso__find_binary_type_locked() {
    ...
    found = filename__has_section(path, ".text");
    ...
}

For stripped executables (which have had their section headers removed but still have valid PT_LOAD segments), this check returns false. Previously, because dso__load() set the binary type directly when locating the system path DSO, it bypassed the strict .text check.

Consequently, tools like objdump that can parse PT_LOAD segments are never invoked, and operations fail with COULDNT_DETERMINE_FILE_TYPE.

Additionally, could this cause debuginfo files to be incorrectly selected for data reads, since their SHT_NOBITS .text sections might falsely satisfy the check?

Quoted 3 lines
tools/perf/util/symbol.c +0 -0
 			if (syms_ss && runtime_ss)
 				break;
 		} else {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
author maintainer
#19 lore raw

Re: [PATCH v4 08/10] perf symbol: Do not set binary type from symtab type

Quoted 50 lines · On Tue, Oct 13, 2026 at 12:08:12AM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: fully stripped executables falsely rejected for data access --

commit 6b9e46855d4e0d8df1dcaaed600da2f693471adb
Author: Namhyung Kim <[email protected]>

perf symbol: Do not set binary type from symtab type

This commit separates tracking of the DSO binary type from the symtab type. It removes the explicit setting of the binary type during symbol loading, deferring it until the DSO is actually opened.

Quoted 11 lines
tools/perf/util/symbol.c +0 -3
index 4a8c298039447..116870595f75c 100644
@@ -1943,19 +1943,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 1958

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 removing this explicit assignment cause fully stripped executables to be falsely rejected during data access operations like perf annotate?

By leaving the DSO binary type as NOT_FOUND here, disassembly paths are forced to fall back to dso__find_binary_type_locked() to identify the file type. That logic attempts to verify the file using filename__has_section() for the .text section:

tools/perf/util/dso.c:dso__find_binary_type_locked() {
    ...
    found = filename__has_section(path, ".text");
    ...
}
Quoted 7 lines

For stripped executables (which have had their section headers removed but still have valid PT_LOAD segments), this check returns false. Previously, because dso__load() set the binary type directly when locating the system path DSO, it bypassed the strict .text check.

Consequently, tools like objdump that can parse PT_LOAD segments are never invoked, and operations fail with COULDNT_DETERMINE_FILE_TYPE.

Hmm.. ok. But I don't think this is a common case and we have many places to check section headers. So practically we require section headers to support it.

Quoted 4 lines

Additionally, could this cause debuginfo files to be incorrectly selected for data reads, since their SHT_NOBITS .text sections might falsely satisfy the check?

The function never tries such debuginfo file types. But probably better to chek section types.

Thanks,
Namhyung

author maintainer
#20 lore raw

PATCH v4 9/10 perf annotate: Simplify symbol__disassemble() with dso binary_type

In reply to Namhyung Kim

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.

---
 tools/perf/util/disasm.c | 124 ++++++++-------------------------------
 1 file changed, 24 insertions(+), 100 deletions(-)
tools/perf/util/disasm.c +24 -100
index 5478c134e7e3b8df..7c289b67b5bde899 100644
@@ -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,14 +1488,29 @@ 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;
+
+	mutex_lock(dso__lock(dso));
+	symfs_filename = dso__get_filename(dso, "", &decomp, dbt);
+	mutex_unlock(dso__lock(dso));
+
+	if (symfs_filename == NULL) {
+		if (dbt == DSO_BINARY_TYPE__BPF_PROG_INFO ||
+		    dbt == DSO_BINARY_TYPE__BPF_IMAGE)
+			symfs_filename = (char *)dso__long_name(dso);
+		else
+			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),
@@ -1581,9 +1518,7 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 
 	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;
@@ -1591,18 +1526,8 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 
 		if (!kcore_extract__create(&kce)) {
 			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);
+			dso__put_filename(dso, symfs_filename, decomp);
+			symfs_filename = kce.extract_filename;
 		}
 	}
 
@@ -1660,11 +1585,10 @@ 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);
-
 	if (delete_extract)
 		kcore_extract__delete(&kce);
+	else if (dbt != DSO_BINARY_TYPE__BPF_PROG_INFO && dbt != DSO_BINARY_TYPE__BPF_IMAGE)
+		dso__put_filename(dso, symfs_filename, decomp);
 
 	return err;
 }
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#21 lore raw

Re: [PATCH v4 09/10] perf annotate: Simplify symbol__disassemble() with dso binary_type

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

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.

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=9
author maintainer
#22 lore raw

PATCH v4 10/10 perf test: Fix dso data tests

In reply to Namhyung Kim

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.

---
 tools/perf/tests/dso-data.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/perf/tests/dso-data.c +7 -0
index 46bc3f59726004fa..18b7052a2dc575c2 100644
@@ -138,6 +138,10 @@ static int test__dso_data(struct test_suite *test __maybe_unused, int subtest __
 	dsos__init(&machine.dsos);
 
 	dso = dso__new(file);
+	TEST_ASSERT_VAL("Failed to get dso", dso);
+	/* 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);
@@ -226,6 +230,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);
 		TEST_ASSERT_VAL("failed to get dso", dso);
+		/* 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(dsos, dso));
 		dso__put(dso);
 	}
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#23 lore raw

Re: [PATCH v4 10/10] perf test: Fix dso data tests

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

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.

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=10