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 Mar 1, 2023
1 parent a45c17f commit 298a4cc
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ 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) {
if (!*s1)
return 0;
s1++;
s2++;

while (isdigit(*s1))
s1++;
while (isdigit(*s2))
s2++;
}

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.
Expand All @@ -446,6 +463,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 298a4cc

Please sign in to comment.