Messages in this thread Patch in this message | | | From | Vishal Goel <> | Subject | [PATCH 1/1] Module:- Do not store unnecessary symbols for kernel modules | Date | Wed, 24 Jun 2020 15:48:18 +0530 |
| |
While loading modules, ignores the mapping symbols found in ARM ELF files: $a, $t and $d. Also ignores symbols starting with .L found in rodata.str sections It will help in saving memory allocated for modules using vmalloc.
It can save around 500KB - 1000KB depending on the number of modules and number of symbols present in them
Signed-off-by: Vishal Goel <vishal.goel@samsung.com> Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com> --- kernel/module.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c index 646f1e2..d5b7b0a 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2550,6 +2550,20 @@ static void free_modinfo(struct module *mod) #ifdef CONFIG_KALLSYMS +/* + * This ignores the intensely annoying "mapping symbols" found + * in ARM ELF files: $a, $t and $d. + * It also ignores symbols starting with .L found in rodata.str sections + */ +static inline int is_arm_mapping_symbol(const char *str) +{ + if (str[0] == '.' && str[1] == 'L') + return true; + return str[0] == '$' && strchr("axtd", str[1]) + && (str[2] == '\0' || str[2] == '.'); +} + + /* Lookup exported symbol in given range of kernel_symbols */ static const struct kernel_symbol *lookup_exported_symbol(const char *name, const struct kernel_symbol *start, @@ -2664,8 +2678,9 @@ static 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)) { + (is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum, + info->index.pcpu) && + !is_arm_mapping_symbol(&info->strtab[src[i].st_name]))) { strtab_size += strlen(&info->strtab[src[i].st_name])+1; ndst++; } @@ -2728,8 +2743,9 @@ static void add_kallsyms(struct module *mod, const struct load_info *info) for (ndst = i = 0; i < mod->kallsyms->num_symtab; i++) { mod->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)) { + (is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum, + info->index.pcpu) && + !is_arm_mapping_symbol(&info->strtab[src[i].st_name]))) { mod->core_kallsyms.typetab[ndst] = mod->kallsyms->typetab[i]; dst[ndst] = src[i]; @@ -3986,17 +4002,6 @@ static inline int within(unsigned long addr, void *start, unsigned long size) } #ifdef CONFIG_KALLSYMS -/* - * This ignores the intensely annoying "mapping symbols" found - * in ARM ELF files: $a, $t and $d. - */ -static inline int is_arm_mapping_symbol(const char *str) -{ - if (str[0] == '.' && str[1] == 'L') - return true; - return str[0] == '$' && strchr("axtd", str[1]) - && (str[2] == '\0' || str[2] == '.'); -} static const char *kallsyms_symbol_name(struct mod_kallsyms *kallsyms, unsigned int symnum) { -- 1.9.1
| |