diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index a4f6dd5a6089..14de0c7bf756 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -159,6 +159,26 @@ static unsigned long kallsyms_sym_address(int idx) return kallsyms_relative_base - 1 - kallsyms_offsets[idx]; } +#if defined(CONFIG_CFI_CLANG) && defined(CONFIG_THINLTO) +/* + * LLVM appends a hash to static function names when ThinLTO and CFI are + * both enabled, which causes confusion and potentially breaks user space + * tools, so we will strip the postfix from expanded symbol names. + */ +static inline char *cleanup_symbol_name(char *s) +{ + char *res = NULL; + + res = strrchr(s, '$'); + if (res) + *res = '\0'; + + return res; +} +#else +static inline char *cleanup_symbol_name(char *s) { return NULL; } +#endif + /* Lookup the address for this symbol. Returns 0 if not found. */ unsigned long kallsyms_lookup_name(const char *name) { @@ -171,6 +191,9 @@ unsigned long kallsyms_lookup_name(const char *name) if (strcmp(namebuf, name) == 0) return kallsyms_sym_address(i); + + if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0) + return kallsyms_sym_address(i); } return module_kallsyms_lookup_name(name); } @@ -269,24 +292,6 @@ int kallsyms_lookup_size_offset(unsigned long addr, unsigned long *symbolsize, !!__bpf_address_lookup(addr, symbolsize, offset, namebuf); } -#if defined(CONFIG_CFI_CLANG) && defined(CONFIG_THINLTO) -/* - * LLVM appends a hash to static function names when ThinLTO and CFI are - * both enabled, which causes confusion and potentially breaks user space - * tools, so we will strip the postfix from expanded symbol names. - */ -static inline void cleanup_symbol_name(char *s) -{ - char *res; - - res = strrchr(s, '$'); - if (res) - *res = '\0'; -} -#else -static inline void cleanup_symbol_name(char *s) {} -#endif - /* * Lookup an address * - modname is set to NULL if it's in the kernel.