Blob Blame History Raw
From 47d1b39ba7686e2368c1ad24af274dfd9f54ecf9 Mon Sep 17 00:00:00 2001
From: Song Liu <songliubraving@fb.com>
Date: Wed, 13 Oct 2021 00:10:20 -0700
Subject: [PATCH 103/107] 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 <songliubraving@fb.com>
---
 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 fec57b8..e88cb3b 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1053,6 +1053,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)
 {
@@ -1062,8 +1064,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_ubsan_sec(sec_orig->name))
-- 
2.37.3