From ce97c8ef720bd288fbc53aad51969571a1c2c1e6 Mon Sep 17 00:00:00 2001 From: Song Liu Date: Wed, 13 Oct 2021 00:10:20 -0700 Subject: [PATCH 107/108] create-diff-object: compare section name with kpatch_section_function_name Profile-Guided Optimization (PGO) uses profiling data to help the compiler to evaluate the properties of a function, and thus adds different prefixes to the section/function. For example, with -ffunction-sections, the compiler will prefix some sectiones with .text.unlikely. However, if a function changes from the version in the profiling data, the compiler may ignore the profiling data. This often happens to the patched function when kpatch-build builds the patch. As a result, the original function and the patch function may have different prefix, i.e., one of them has .text, the other has .text.unlikely. To correlate these functions properly, use kpatch_section_function_name() in kpatch_correlate_sections() to find matching sections. Signed-off-by: Song Liu --- kpatch-build/create-diff-object.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 1967bd8..6f08c4d 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -986,6 +986,8 @@ static void kpatch_correlate_section(struct section *sec_orig, kpatch_correlate_symbol(sec_orig->sym, sec_patched->sym); } +static char *kpatch_section_function_name(struct section *sec); + static void kpatch_correlate_sections(struct list_head *seclist_orig, struct list_head *seclist_patched) { @@ -995,8 +997,9 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig, if (sec_orig->twin) continue; list_for_each_entry(sec_patched, seclist_patched, list) { - if (kpatch_mangled_strcmp(sec_orig->name, sec_patched->name) || - sec_patched->twin) + if (sec_patched->twin || + kpatch_mangled_strcmp(kpatch_section_function_name(sec_orig), + kpatch_section_function_name(sec_patched))) continue; if (is_special_static(is_rela_section(sec_orig) ? -- 2.37.3