perf dso: Fix kallsyms DSO detection with fallback logic
PATCH 1/1 perf dso: Fix kallsyms DSO detection with fallback logic
The current kallsyms detection in dso__is_kallsyms() uses the dso_binary_type enum which fixes the issue of kallsyms being cached in the build-id cache for out-of-tree modules.
However, during build-id injection in perf record/inject, dso_binary_type has not been explicitly set yet,so dso__binary_type() returns DSO_BINARY_TYPE__NOT_FOUND instead of DSO_BINARY_TYPE__KALLSYMS for the kernel DSO. The current check then fails to identify it as kallsyms, causing build-id symlinks to not be created in ~/.debug/.build-id/ and perf archive to fail with "Cannot stat" errors.
Steps to reproduce the issue:
1. rm -rf ~/.debug/.build-id
2. perf record sleep 1
3. perf archive
Fix by falling back to matching long_name against the known kallsyms strings explicitly when binary_type is not yet set
(== DSO_BINARY_TYPE__NOT_FOUND).
--- tools/perf/util/dso.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/perf/util/dso.h +10 -0
@@ -9,6 +9,7 @@#include <stdbool.h> #include <stdio.h> #include <linux/bitops.h> +#include <string.h> #include "build-id.h" #include "debuginfo.h" #include "mutex.h"
@@ -20,6 +21,7 @@ struct perf_env;#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"#define DSO__NAME_KCORE "[kernel.kcore]" +#define DSO__NAME_GUEST_KALLSYMS "[guest.kernel.kallsyms"/** * enum dso_binary_type - The kind of DSO generally associated with a memory
@@ -915,6 +917,14 @@ static inline bool dso__is_kallsyms(const struct dso *dso) {enum dso_binary_type bt =dso__binary_type (dso); +if (bt ==DSO_BINARY_TYPE__NOT_FOUND ) { +return RC_CHK_ACCESS (dso)->kernel && + ((strncmp (RC_CHK_ACCESS (dso)->long_name,DSO__NAME_KALLSYMS , +strlen (DSO__NAME_KALLSYMS )) ==0 ) || + (strncmp (RC_CHK_ACCESS (dso)->long_name,DSO__NAME_GUEST_KALLSYMS , +strlen (DSO__NAME_GUEST_KALLSYMS )) ==0 )); + } +return bt ==DSO_BINARY_TYPE__KALLSYMS || bt ==DSO_BINARY_TYPE__GUEST_KALLSYMS ; }
Signature · 1 line
2.47.3
[email protected]
AI reviewSashiko AI review found 1 potential issue(s): - [Low] The macro `DSO__NAME_GUEST_KALLSYMS` is defined with an unbalanced bracket, which is deceptive and prone to misuse. --
Sashiko AI review found 1 potential issue(s):
- [Low] The macro DSO__NAME_GUEST_KALLSYMS is defined with an unbalanced bracket, which is deceptive and prone to misuse. --
commit bff739892129d9369935f2dfb42b44d83b2f857d
Author: Tanushree Shah <[email protected]>
perf dso: Fix kallsyms DSO detection with fallback logic
This commit fixes kallsyms DSO detection during build-id injection when the binary type is not yet explicitly set. It implements a fallback that matches the long_name against known kallsyms strings to correctly identify the kernel DSO.
Quoted 4 lines
tools/perf/util/dso.h +0
-0
[ ... ]
tools/perf/util/dso.h struct perf_env; · line 24
Quoted 5 lines
tools/perf/util/dso.h +1
-0@@ -20,6 +21,7 @@ struct perf_env;#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"#define DSO__NAME_KCORE "[kernel.kcore]" +#define DSO__NAME_GUEST_KALLSYMS "[guest.kernel.kallsyms"
This isn't a bug, but there is a missing closing bracket in this macro definition.
While it looks like this was done intentionally to allow prefix matching against dynamic guest kallsyms names (which append a PID) using strncmp later in the patch, naming it DSO__NAME_GUEST_KALLSYMS implies it represents a complete, well-formed identifier like DSO__NAME_KALLSYMS.
Could this macro be renamed to something like DSO__PREFIX_GUEST_KALLSYMS to make its intended use as a prefix clear, preventing it from being accidentally used in contexts expecting a full name?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks for the suggestion. The missing closing bracket is intentional. I Will rename it to DSO__PREFIX_GUEST_KALLSYMS to make this intent explicit and avoid confusion with complete name macros like DSO__NAME_KALLSYMS
Quoted 37 lines · On 10/04/26 13:47, [email protected] wrote:
Sashiko AI review found 1 potential issue(s):
- [Low] The macroDSO__NAME_GUEST_KALLSYMSis defined with an unbalanced bracket, which is deceptive and prone to misuse. --commit
bff739892129d9369935f2dfb42b44d83b2f857d
Author: Tanushree Shah <[email protected]>perf dso: Fix kallsyms DSO detection with fallback logic
This commit fixes kallsyms DSO detection during build-id injection when the binary type is not yet explicitly set. It implements a fallback that matches the
long_nameagainst known kallsyms strings to correctly identify the kernel DSO.Quoted 4 lines
tools/perf/util/dso.h +0
-0[ ... ]
tools/perf/util/dso.h struct perf_env; · line 24
Quoted 5 lines
tools/perf/util/dso.h +1
-0@@ -20,6 +21,7 @@ struct perf_env;#define DSO__NAME_KALLSYMS "[kernel.kallsyms]"#define DSO__NAME_KCORE "[kernel.kcore]" +#define DSO__NAME_GUEST_KALLSYMS "[guest.kernel.kallsyms"This isn't a bug, but there is a missing closing bracket in this macro definition.
While it looks like this was done intentionally to allow prefix matching against dynamic guest kallsyms names (which append a PID) using strncmp later in the patch, naming it
DSO__NAME_GUEST_KALLSYMSimplies it represents a complete, well-formed identifier likeDSO__NAME_KALLSYMS.Could this macro be renamed to something like
DSO__PREFIX_GUEST_KALLSYMSto make its intended use as a prefix clear, preventing it from being accidentally used in contexts expecting a full name?