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

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