Skip to content

Commit db68a17

Browse files
committed
kpatch-build: let locals_match to match 90% of local symbols
With clang PGO is used, the compiler uses function signature to match functions to profile data. When the signature of a function changed as part of livepatch, the profile data is ignore. This may cause the compiler to make different inline decisions, and thus cause mismatch in local functions. To adapt to this case, let locals_match to count the number of match and mismatch symbols. If 90% of the symbols match, we consider the two files are the same. Signed-off-by: Song Liu <song@kernel.org>
1 parent b7fa713 commit db68a17

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

kpatch-build/lookup.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ static bool maybe_discarded_sym(const char *name)
9191
}
9292

9393
static bool locals_match(struct lookup_table *table, int idx,
94-
struct symbol *file_sym, struct list_head *sym_list)
94+
struct symbol *file_sym, struct list_head *sym_list,
95+
int match_pct)
9596
{
9697
struct symbol *sym;
9798
struct object_symbol *table_sym;
9899
int i, found;
100+
int match_cnt = 0, mismatch_cnt = 0;
99101

100102
i = idx + 1;
101103
for_each_obj_symbol_continue(i, table_sym, table) {
@@ -121,10 +123,18 @@ static bool locals_match(struct lookup_table *table, int idx,
121123
}
122124
}
123125

124-
if (!found)
125-
return false;
126+
if (found)
127+
match_cnt++;
128+
else
129+
mismatch_cnt++;
126130
}
127131

132+
if (match_cnt * 100 < (match_cnt + mismatch_cnt) * match_pct)
133+
return false;
134+
135+
match_cnt = 0;
136+
mismatch_cnt = 0;
137+
128138
sym = file_sym;
129139
list_for_each_entry_continue(sym, sym_list, list) {
130140
if (sym->type == STT_FILE)
@@ -157,11 +167,13 @@ static bool locals_match(struct lookup_table *table, int idx,
157167
}
158168
}
159169

160-
if (!found)
161-
return false;
170+
if (found)
171+
match_cnt++;
172+
else
173+
mismatch_cnt++;
162174
}
163175

164-
return true;
176+
return match_cnt * 100 >= (match_cnt + mismatch_cnt) * match_pct;
165177
}
166178

167179
static void find_local_syms(struct lookup_table *table, struct symbol *file_sym,
@@ -176,7 +188,7 @@ static void find_local_syms(struct lookup_table *table, struct symbol *file_sym,
176188
continue;
177189
if (strcmp(file_sym->name, sym->name))
178190
continue;
179-
if (!locals_match(table, i, file_sym, sym_list))
191+
if (!locals_match(table, i, file_sym, sym_list, 90 /* match_pct */))
180192
continue;
181193
if (lookup_table_file_sym)
182194
ERROR("found duplicate matches for %s local symbols in %s symbol table",

0 commit comments

Comments
 (0)