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

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