Blame SOURCES/v0.9.7-backport-MR-1314-create-diff-object-fix-__UNI.patch

734205
From c351828bf35121628461095eeb25ea2152e98d38 Mon Sep 17 00:00:00 2001
734205
From: Josh Poimboeuf <jpoimboe@redhat.com>
734205
Date: Mon, 21 Nov 2022 19:32:18 -0800
734205
Subject: [PATCH] v0.9.7 backport: MR!1314 ("create-diff-object: fix
734205
 __UNIQUE_ID() variable correlation")
734205
734205
commit 901445a54fcecbd6852b79878e67153c5048602e
734205
Author: Josh Poimboeuf <jpoimboe@redhat.com>
734205
Date:   Mon Nov 21 19:32:18 2022 -0800
734205
734205
    create-diff-object: fix __UNIQUE_ID() variable correlation
734205
734205
    kpatch_mangled_strcmp() only ignores the digits after the period, but in
734205
    the case of __UNIQUE_ID(), the symbol names have random digits before
734205
    the period due to the use of `__COUNTER__`.  Make sure such symbols are
734205
    properly correlated.
734205
734205
    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
734205
734205
Signed-off-by: Yannick Cote <ycote@redhat.com>
734205
---
734205
 kpatch-build/create-diff-object.c | 32 +++++++++++++++++++++++++++++++
734205
 1 file changed, 32 insertions(+)
734205
734205
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
734205
index 360441111c5e..7106b67cfd25 100644
734205
--- a/kpatch-build/create-diff-object.c
734205
+++ b/kpatch-build/create-diff-object.c
734205
@@ -396,6 +396,35 @@ static bool has_digit_tail(char *tail)
734205
 	return false;
734205
 }
734205
 
734205
+/*
734205
+ * Hack for __UNIQUE_ID().  The following should match:
734205
+ *
734205
+ *   __UNIQUE_ID_ddebug1131.186
734205
+ *   __UNIQUE_ID_ddebug1132.187
734205
+ */
734205
+static int __kpatch_unique_id_strcmp(char *s1, char *s2)
734205
+{
734205
+	/* match '__UNIQUE_ID_ddebug' */
734205
+	while (*s1 == *s2) {
734205
+		if (!*s1)
734205
+			return 0;
734205
+		s1++;
734205
+		s2++;
734205
+	}
734205
+
734205
+	/* skip digits before '.' or EOL */
734205
+	while (isdigit(*s1))
734205
+		s1++;
734205
+	while (isdigit(*s2))
734205
+		s2++;
734205
+
734205
+	if ((!*s1 || has_digit_tail(s1)) &&
734205
+	    (!*s2 || has_digit_tail(s2)))
734205
+		return 0;
734205
+
734205
+	return 1;
734205
+}
734205
+
734205
 /*
734205
  * This is like strcmp, but for gcc-mangled symbols.  It skips the comparison
734205
  * of any substring which consists of '.' followed by any number of digits.
734205
@@ -409,6 +438,9 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
734205
 	if (strstr(s1, ".str1."))
734205
 		return strcmp(s1, s2);
734205
 
734205
+	if (!strncmp(s1, "__UNIQUE_ID_", 12))
734205
+		return __kpatch_unique_id_strcmp(s1, s2);
734205
+
734205
 	while (*s1 == *s2) {
734205
 		if (!*s1)
734205
 			return 0;
734205
-- 
734205
2.38.1
734205