kpatch/0042-create-diff-object-fix-__UNIQUE_ID-variable-correlat.patch
Zhipeng Xie dcbfd17440 backport upstream patches
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2023-07-29 14:57:18 +08:00

70 lines
1.8 KiB
Diff

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