linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] Module:- Do not store unnecessary symbols for kernel modules
       [not found] ` <CGME20200624104045epcas5p43d47f01a4536d794c1d1e7c2ca78cb6e@epcas5p4.samsung.com>
@ 2020-06-24 10:18   ` Vishal Goel
  0 siblings, 0 replies; only message in thread
From: Vishal Goel @ 2020-06-24 10:18 UTC (permalink / raw)
  To: rusty, linux-kernel; +Cc: Vishal Goel, Amit Sahrawat

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-24 11:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Do not store unnecessary symbols for kernel modules>
     [not found] ` <CGME20200624104045epcas5p43d47f01a4536d794c1d1e7c2ca78cb6e@epcas5p4.samsung.com>
2020-06-24 10:18   ` [PATCH 1/1] Module:- Do not store unnecessary symbols for kernel modules Vishal Goel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).