Blame 0101-create-diff-object-handle-__initcall_stub-with-CONFI.patch

54dc0a
From 3672db9de548ed4ed5e87089a1263f6b5ddc4a11 Mon Sep 17 00:00:00 2001
54dc0a
From: Song Liu <song@kernel.org>
54dc0a
Date: Mon, 13 Feb 2023 15:14:32 -0800
54dc0a
Subject: [PATCH 101/107] create-diff-object: handle __initcall_stub with
54dc0a
 CONFIG_LTO_CLANG
54dc0a
54dc0a
The kernel use a special __initcall_stub() with CONFIG_LTO_CLANG to avoid
54dc0a
name collisions. Handle it in kpatch_mangled_strcmp() by ignoring all
54dc0a
digits for symbols start with __initstub__kmod_syscall__.
54dc0a
54dc0a
Signed-off-by: Song Liu <song@kernel.org>
54dc0a
---
54dc0a
 kpatch-build/create-diff-object.c | 30 ++++++++++++++++++++++++++++++
54dc0a
 1 file changed, 30 insertions(+)
54dc0a
54dc0a
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
54dc0a
index 2d7b072..fec57b8 100644
54dc0a
--- a/kpatch-build/create-diff-object.c
54dc0a
+++ b/kpatch-build/create-diff-object.c
54dc0a
@@ -430,6 +430,23 @@ static int __kpatch_unique_id_strcmp(char *s1, char *s2)
54dc0a
 	return 1;
54dc0a
 }
54dc0a
 
54dc0a
+static int __kpatch_skip_digits_strcmp(char *s1, char *s2)
54dc0a
+{
54dc0a
+	while (*s1 == *s2) {
54dc0a
+		if (!*s1)
54dc0a
+			return 0;
54dc0a
+		s1++;
54dc0a
+		s2++;
54dc0a
+
54dc0a
+		while (isdigit(*s1))
54dc0a
+			s1++;
54dc0a
+		while (isdigit(*s2))
54dc0a
+			s2++;
54dc0a
+	}
54dc0a
+
54dc0a
+	return 1;
54dc0a
+}
54dc0a
+
54dc0a
 /*
54dc0a
  * This is like strcmp, but for gcc-mangled symbols.  It skips the comparison
54dc0a
  * of any substring which consists of '.' followed by any number of digits.
54dc0a
@@ -446,6 +463,19 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
54dc0a
 	if (!strncmp(s1, "__UNIQUE_ID_", 12))
54dc0a
 		return __kpatch_unique_id_strcmp(s1, s2);
54dc0a
 
54dc0a
+	/*
54dc0a
+	 * Hack for __initcall_stub() with CONFIG_LTO_CLANG.
54dc0a
+	 * The following should match:
54dc0a
+	 *
54dc0a
+	 *   __initstub__kmod_syscall__728_5326_bpf_syscall_sysctl_init7
54dc0a
+	 *   __initstub__kmod_syscall__728_5324_bpf_syscall_sysctl_init7
54dc0a
+	 *
54dc0a
+	 * Please refer to __initcall_stub() in include/linux/init.h for
54dc0a
+	 * more details.
54dc0a
+	 */
54dc0a
+	if (!strncmp(s1, "__initstub__kmod_syscall__", 26))
54dc0a
+		return __kpatch_skip_digits_strcmp(s1, s2);
54dc0a
+
54dc0a
 	while (*s1 == *s2) {
54dc0a
 		if (!*s1)
54dc0a
 			return 0;
54dc0a
-- 
54dc0a
2.37.3
54dc0a