diff options
| author | Tiezhu Yang <yangtiezhu@loongson.cn> | 2026-08-20 20:50:06 +0800 |
|---|---|---|
| committer | Petr Pavlu <petr.pavlu@suse.com> | 2026-09-09 12:15:36 +0200 |
| commit | 67059a02f5e26e4c5c890792d720bbff235bb1d5 (patch) | |
| tree | 90e500d979cfe6a7b4f2256d058dcce2558c47ff | |
| parent | db91da8f05185706f492841d96864ad78893dd62 (diff) | |
| download | linux-next-67059a02f5e26e4c5c890792d720bbff235bb1d5.tar.gz linux-next-67059a02f5e26e4c5c890792d720bbff235bb1d5.zip | |
module/kallsyms: Refactor current symbol filtering into is_core_symbol()
Currently, the loops in layout_symtab() and add_kallsyms() duplicate the
exact same checks (i == 0 || is_livepatch_module() || is_core_symbol())
to determine whether a symbol should be preserved in the module's core
symbol table.
Move the entire checking logic inside is_core_symbol(), including the
special handlers for the first symbol and livepatch modules.
No functional changes.
Suggested-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
| -rw-r--r-- | kernel/module/kallsyms.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index a52942fd0e07..d75c9f60d360 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -75,23 +75,26 @@ static char elf_type(const Elf_Sym *sym, const struct load_info *info) return '?'; } -static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, - unsigned int shnum, unsigned int pcpundx) +static bool is_core_symbol(struct module *mod, const struct load_info *info, + unsigned int symnum, const Elf_Sym *src) { const Elf_Shdr *sec; enum mod_mem_type type; + if (symnum == 0 || is_livepatch_module(mod)) + return true; + if (src->st_shndx == SHN_UNDEF || - src->st_shndx >= shnum || + src->st_shndx >= info->hdr->e_shnum || !src->st_name) return false; #ifdef CONFIG_KALLSYMS_ALL - if (src->st_shndx == pcpundx) + if (src->st_shndx == info->index.pcpu) return true; #endif - sec = sechdrs + src->st_shndx; + sec = info->sechdrs + src->st_shndx; type = sec->sh_entsize >> SH_ENTSIZE_TYPE_SHIFT; if (!(sec->sh_flags & SHF_ALLOC) #ifndef CONFIG_KALLSYMS_ALL @@ -130,12 +133,11 @@ void layout_symtab(struct module *mod, struct load_info *info) /* Compute total space required for the core symbols' strtab. */ for (ndst = i = 0; i < nsrc; i++) { - if (i == 0 || is_livepatch_module(mod) || - is_core_symbol(src + i, info->sechdrs, info->hdr->e_shnum, - info->index.pcpu)) { - strtab_size += strlen(&info->strtab[src[i].st_name]) + 1; - ndst++; - } + if (!is_core_symbol(mod, info, i, src + i)) + continue; + + strtab_size += strlen(&info->strtab[src[i].st_name]) + 1; + ndst++; } /* Append room for core symbols at end of core part. */ @@ -197,23 +199,21 @@ void add_kallsyms(struct module *mod, const struct load_info *info) strtab_size = info->core_typeoffs - info->stroffs; src = kallsyms->symtab; for (ndst = i = 0; i < kallsyms->num_symtab; i++) { + ssize_t ret; + kallsyms->typetab[i] = elf_type(src + i, info); - if (i == 0 || is_livepatch_module(mod) || - is_core_symbol(src + i, info->sechdrs, info->hdr->e_shnum, - info->index.pcpu)) { - ssize_t ret; - - mod->core_kallsyms.typetab[ndst] = - kallsyms->typetab[i]; - dst[ndst] = src[i]; - dst[ndst++].st_name = s - mod->core_kallsyms.strtab; - ret = strscpy(s, &kallsyms->strtab[src[i].st_name], - strtab_size); - if (ret < 0) - break; - s += ret + 1; - strtab_size -= ret + 1; - } + + if (!is_core_symbol(mod, info, i, src + i)) + continue; + + mod->core_kallsyms.typetab[ndst] = kallsyms->typetab[i]; + dst[ndst] = src[i]; + dst[ndst++].st_name = s - mod->core_kallsyms.strtab; + ret = strscpy(s, &kallsyms->strtab[src[i].st_name], strtab_size); + if (ret < 0) + break; + s += ret + 1; + strtab_size -= ret + 1; } /* Set up to point into init section. */ |
