From 6ebfe7d2af327dad9c9d4c5b2733ba55bd81571c Mon Sep 17 00:00:00 2001
From: jiang-dawei15 <jiangdawei15@huawei.com>
Date: Tue, 1 Mar 2022 20:00:58 +0800
Subject: [PATCH 2/2] kpatch_parse: fix failed to recognize .cold

the .cold suffix have two forms of expression: func.cold or
func.cold.NUM, we need to support recognizing both patterns.

Signed-off-by: Bihong Yu <yubihong@huawei.com>
---
 src/arch/x86/arch_parse.c                       |  4 ++--
 src/include/kpatch_parse.h                      |  2 +-
 src/kpatch_parse.c                              | 14 ++++++--------
 tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh | 11 +++++++----
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/arch/x86/arch_parse.c b/src/arch/x86/arch_parse.c
index 31caa46..aee82b8 100644
--- a/src/arch/x86/arch_parse.c
+++ b/src/arch/x86/arch_parse.c
@@ -72,10 +72,10 @@ void recog_func_attr(struct kp_file *f, int i, kpstr_t *nm, int *cnt)
 		get_type_args(cline(f, i), &func_nm, &func_attr);
 		if(!kpstrcmpz(&func_attr, "@function")) {
 			if(func_nm.l > nm->l)
-				remove_cold_hot_suffix(&func_nm);    /* remove .cold. / .hot. */
+				remove_cold_suffix(&func_nm);    /* remove .cold */
 
 			if(!kpstrcmp(&func_nm, nm))         /* verify name matches */
-				++(*cnt);  
+				++(*cnt);
 		}
 	}
 }
diff --git a/src/include/kpatch_parse.h b/src/include/kpatch_parse.h
index c52a1e3..d2225c5 100644
--- a/src/include/kpatch_parse.h
+++ b/src/include/kpatch_parse.h
@@ -106,7 +106,7 @@ struct cblock {
 
 void get_token(char **str, kpstr_t *x);
 void __get_token(char **str, kpstr_t *x, const char *delim);
-void remove_cold_hot_suffix(kpstr_t *nm);
+void remove_cold_suffix(kpstr_t *nm);
 
 int is_function_start(struct kp_file *f, int l, kpstr_t *nm);
 int is_function_end(struct kp_file *f, int l, kpstr_t *nm);
diff --git a/src/kpatch_parse.c b/src/kpatch_parse.c
index 0885cbe..43c885c 100644
--- a/src/kpatch_parse.c
+++ b/src/kpatch_parse.c
@@ -78,17 +78,15 @@ void get_token(char **str, kpstr_t *x)
 	__get_token(str, x, delim);
 }
 
-/* remove .cold. / .hot. in function name */
-void remove_cold_hot_suffix(kpstr_t *nm)
+/* remove .cold in function name */
+void remove_cold_suffix(kpstr_t *nm)
 {
 	if(!nm->s)
 		return;
-	
-	char *suffix_loc = strstr(nm->s, ".cold.");
-	if(!suffix_loc)
-		suffix_loc = strstr(nm->s, ".hot.");
+
+	char *suffix_loc = strstr(nm->s, ".cold");
 	if(suffix_loc)
-		nm->l = suffix_loc - nm->s;			/* remove .cold. / .hot. */
+		nm->l = suffix_loc - nm->s;			/* remove .cold */
 }
 
 /* ------------------------------  as directives parsing ---------------------------------- */
@@ -790,7 +788,7 @@ int is_function_end(struct kp_file *f, int l, kpstr_t *nm)
 	get_token(&s, &nm2);
 
 	if(nm2.l > nm->l)
-		remove_cold_hot_suffix(&nm2);   /* remove .cold. / .hot. */
+		remove_cold_suffix(&nm2);   /* remove .cold */
 
 	if (kpstrcmp(nm, &nm2)) /* verify name matches */
 		return 0;
diff --git a/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh b/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh
index 4534038..b508e99 100755
--- a/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh
+++ b/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh
@@ -22,12 +22,12 @@ for SOURCE in $SOURCE_SET; do
     FILENAME=${SOURCE##*/}
     CASENAME=${FILENAME%.orig.s}
     if [ $CASENAME == "cold_func_suffix" ]; then
-        KEY_WORD="\.cold."
+        KEY_WORD="\.cold"
     else
         KEY_WORD=$CASENAME
     fi
 
-    KEY_WORD_LINE=$(grep -c $KEY_WORD $SOURCE)
+    KEY_WORD_LINE=$(grep -c "$KEY_WORD" $SOURCE)
     if [ $KEY_WORD_LINE -lt "2" ]; then
         echo "SKIP: $CASENAME, $KEY_WORD not found"
         SKIP_CNT=$(($SKIP_CNT+1))
@@ -37,7 +37,7 @@ for SOURCE in $SOURCE_SET; do
     $KPATCH_GENSRC --os=rhel6 -i $SOURCE -i $SOURCE -o ${SOURCE/.orig/.o}
     sed -i '/^#/d' ${SOURCE/.orig/.o}
 
-    DIFF_LINE=$(diff $SOURCE ${SOURCE/.orig/.o} | grep -c $KEY_WORD)
+    DIFF_LINE=$(diff $SOURCE ${SOURCE/.orig/.o} | grep -c "$KEY_WORD")
     if [ $DIFF_LINE -gt "0" ]; then
         echo "TEST $CASENAME IS FAIL"
         FAIL_CNT=$(($FAIL_CNT+1))
@@ -48,4 +48,7 @@ for SOURCE in $SOURCE_SET; do
 done
 
 echo "OK $OK_CNT FAIL $FAIL_CNT SKIP $SKIP_CNT TOTAL $TOTAL_CASE"
-exit 0
\ No newline at end of file
+if [ $FAIL_CNT -ne 0 ]; then
+    exit 1
+fi
+exit 0
-- 
2.27.0

