Blame 0107-create-diff-object-compare-section-name-with-kpatch_.patch

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