Skip to content

Commit d3b7022

Browse files
ahunter6acmel
authored andcommitted
perf buildid-cache: Check relocation when checking for existing kcore
perf buildid-cache does not make another copy of kcore if the buildid and modules match an existing copy. That does not take into account the possibility that the kernel has been relocated. Extend the check to check if the reference relocation symbol matches too, otherwise do make a copy. Signed-off-by: Adrian Hunter <[email protected]> Tested-by: Jiri Olsa <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d9b62ab commit d3b7022

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

tools/perf/builtin-buildid-cache.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,35 @@ static int build_id_cache__kcore_dir(char *dir, size_t sz)
6363
return 0;
6464
}
6565

66+
static bool same_kallsyms_reloc(const char *from_dir, char *to_dir)
67+
{
68+
char from[PATH_MAX];
69+
char to[PATH_MAX];
70+
const char *name;
71+
u64 addr1 = 0, addr2 = 0;
72+
int i;
73+
74+
scnprintf(from, sizeof(from), "%s/kallsyms", from_dir);
75+
scnprintf(to, sizeof(to), "%s/kallsyms", to_dir);
76+
77+
for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
78+
addr1 = kallsyms__get_function_start(from, name);
79+
if (addr1)
80+
break;
81+
}
82+
83+
if (name)
84+
addr2 = kallsyms__get_function_start(to, name);
85+
86+
return addr1 == addr2;
87+
}
88+
6689
static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
6790
size_t to_dir_sz)
6891
{
6992
char from[PATH_MAX];
7093
char to[PATH_MAX];
94+
char to_subdir[PATH_MAX];
7195
struct dirent *dent;
7296
int ret = -1;
7397
DIR *d;
@@ -86,10 +110,11 @@ static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
86110
continue;
87111
scnprintf(to, sizeof(to), "%s/%s/modules", to_dir,
88112
dent->d_name);
89-
if (!compare_proc_modules(from, to)) {
90-
scnprintf(to, sizeof(to), "%s/%s", to_dir,
91-
dent->d_name);
92-
strlcpy(to_dir, to, to_dir_sz);
113+
scnprintf(to_subdir, sizeof(to_subdir), "%s/%s",
114+
to_dir, dent->d_name);
115+
if (!compare_proc_modules(from, to) &&
116+
same_kallsyms_reloc(from_dir, to_subdir)) {
117+
strlcpy(to_dir, to_subdir, to_dir_sz);
93118
ret = 0;
94119
break;
95120
}

0 commit comments

Comments
 (0)