Skip to content

Commit

Permalink
create-diff-object: handle __initcall_stub with CONFIG_LTO_CLANG
Browse files Browse the repository at this point in the history
The kernel use a special __initcall_stub() with CONFIG_LTO_CLANG to avoid
name collisions. Handle it in kpatch_mangled_strcmp() by ignoring all
digits for symbols start with __initstub__kmod_syscall__.

Signed-off-by: Song Liu <[email protected]>
  • Loading branch information
liu-song-6 committed Feb 14, 2023
1 parent d5358fa commit f679d9c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,30 @@ static int __kpatch_unique_id_strcmp(char *s1, char *s2)
return 1;
}

static int __kpatch_skip_digits_strcmp(char *s1, char *s2)
{
while (*s1 && *s2) {
while (isdigit(*s1))
s1++;
while (isdigit(*s2))
s2++;
if (*s1 != *s2)
return 0;

/*
* The pointers may be moved to skip the digits, so it is
* necessary to check again before advancing the pointers.
*/
if (*s1 == '\0' || *s2 == '\0')
break;

s1++;
s2++;
}

return *s1 == *s2;
}

/*
* 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.
Expand All @@ -446,6 +470,19 @@ static int kpatch_mangled_strcmp(char *s1, char *s2)
if (!strncmp(s1, "__UNIQUE_ID_", 12))
return __kpatch_unique_id_strcmp(s1, s2);

/*
* Hack for __initcall_stub() with CONFIG_LTO_CLANG.
* The following should match:
*
* __initstub__kmod_syscall__728_5326_bpf_syscall_sysctl_init7
* __initstub__kmod_syscall__728_5324_bpf_syscall_sysctl_init7
*
* Please refer to __initcall_stub() in include/linux/init.h for
* more details.
*/
if (!strncmp(s1, "__initstub__kmod_syscall__", 26))
return __kpatch_skip_digits_strcmp(s1, s2);

while (*s1 == *s2) {
if (!*s1)
return 0;
Expand Down

0 comments on commit f679d9c

Please sign in to comment.