kernel: add a patch that reduces module size by removing non-essential information...
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.8 / 204-module_strip.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Subject: [PATCH] build: add a hack for removing non-essential module info
3
4 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
5 ---
6 --- a/include/linux/module.h
7 +++ b/include/linux/module.h
8 @@ -82,7 +82,7 @@ void sort_extable(struct exception_table
9 void sort_main_extable(void);
10 void trim_init_extable(struct module *m);
11
12 -#ifdef MODULE
13 +#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED)
14 #define MODULE_GENERIC_TABLE(gtype,name) \
15 extern const struct gtype##_id __mod_##gtype##_table \
16 __attribute__ ((unused, alias(__stringify(name))))
17 @@ -93,9 +93,10 @@ extern const struct gtype##_id __mod_##g
18
19 /* Generic info of form tag = "info" */
20 #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
21 +#define MODULE_INFO_STRIP(tag, info) __MODULE_INFO_STRIP(tag, tag, info)
22
23 /* For userspace: you can also call me... */
24 -#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
25 +#define MODULE_ALIAS(_alias) MODULE_INFO_STRIP(alias, _alias)
26
27 /*
28 * The following license idents are currently accepted as indicating free
29 @@ -131,10 +132,10 @@ extern const struct gtype##_id __mod_##g
30 * Author(s), use "Name <email>" or just "Name", for multiple
31 * authors use multiple MODULE_AUTHOR() statements/lines.
32 */
33 -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
34 +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author)
35
36 /* What your module does. */
37 -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
38 +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description)
39
40 #define MODULE_DEVICE_TABLE(type,name) \
41 MODULE_GENERIC_TABLE(type##_device,name)
42 @@ -155,7 +156,9 @@ extern const struct gtype##_id __mod_##g
43 */
44
45 #if defined(MODULE) || !defined(CONFIG_SYSFS)
46 -#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
47 +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version)
48 +#elif defined(CONFIG_MODULE_STRIPPED)
49 +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version)
50 #else
51 #define MODULE_VERSION(_version) \
52 static struct module_version_attribute ___modver_attr = { \
53 @@ -177,7 +180,7 @@ extern const struct gtype##_id __mod_##g
54 /* Optional firmware file (or files) needed by the module
55 * format is simply firmware file name. Multiple firmware
56 * files require multiple MODULE_FIRMWARE() specifiers */
57 -#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
58 +#define MODULE_FIRMWARE(_firmware) MODULE_INFO_STRIP(firmware, _firmware)
59
60 /* Given an address, look for it in the exception tables */
61 const struct exception_table_entry *search_exception_tables(unsigned long add);
62 --- a/include/linux/moduleparam.h
63 +++ b/include/linux/moduleparam.h
64 @@ -16,6 +16,16 @@
65 /* Chosen so that structs with an unsigned long line up. */
66 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
67
68 +/* This struct is here for syntactic coherency, it is not used */
69 +#define __MODULE_INFO_DISABLED(name) \
70 + struct __UNIQUE_ID(name) {}
71 +
72 +#ifdef CONFIG_MODULE_STRIPPED
73 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name)
74 +#else
75 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info)
76 +#endif
77 +
78 #ifdef MODULE
79 #define __MODULE_INFO(tag, name, info) \
80 static const char __UNIQUE_ID(name)[] \
81 @@ -23,8 +33,7 @@ static const char __UNIQUE_ID(name)[]
82 = __stringify(tag) "=" info
83 #else /* !MODULE */
84 /* This struct is here for syntactic coherency, it is not used */
85 -#define __MODULE_INFO(tag, name, info) \
86 - struct __UNIQUE_ID(name) {}
87 +#define __MODULE_INFO(tag, name, info) __MODULE_INFO_DISABLED(name)
88 #endif
89 #define __MODULE_PARM_TYPE(name, _type) \
90 __MODULE_INFO(parmtype, name##type, #name ":" _type)
91 @@ -32,7 +41,7 @@ static const char __UNIQUE_ID(name)[]
92 /* One for each parameter, describing how to use it. Some files do
93 multiple of these per line, so can't just use MODULE_INFO. */
94 #define MODULE_PARM_DESC(_parm, desc) \
95 - __MODULE_INFO(parm, _parm, #_parm ":" desc)
96 + __MODULE_INFO_STRIP(parm, _parm, #_parm ":" desc)
97
98 struct kernel_param;
99
100 --- a/init/Kconfig
101 +++ b/init/Kconfig
102 @@ -1708,6 +1708,13 @@ config MODULE_SIG_SHA512
103
104 endchoice
105
106 +config MODULE_STRIPPED
107 + bool "Reduce module size"
108 + depends on MODULES
109 + help
110 + Remove module parameter descriptions, author info, version, aliases,
111 + device tables, etc.
112 +
113 endif # MODULES
114
115 config INIT_ALL_POSSIBLE
116 --- a/kernel/module.c
117 +++ b/kernel/module.c
118 @@ -2682,6 +2682,7 @@ static struct module *setup_load_info(st
119
120 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
121 {
122 +#ifndef CONFIG_MODULE_STRIPPED
123 const char *modmagic = get_modinfo(info, "vermagic");
124 int err;
125
126 @@ -2708,6 +2709,7 @@ static int check_modinfo(struct module *
127 " the quality is unknown, you have been warned.\n",
128 mod->name);
129 }
130 +#endif
131
132 /* Set up license info based on the info section */
133 set_license(mod, get_modinfo(info, "license"));
134 --- a/scripts/mod/modpost.c
135 +++ b/scripts/mod/modpost.c
136 @@ -1736,7 +1736,9 @@ static void read_symbols(char *modname)
137 symname = info.strtab + sym->st_name;
138
139 handle_modversions(mod, &info, sym, symname);
140 +#ifndef CONFIG_MODULE_STRIPPED
141 handle_moddevtable(mod, &info, sym, symname);
142 +#endif
143 }
144 if (!is_vmlinux(modname) ||
145 (is_vmlinux(modname) && vmlinux_section_warnings))
146 @@ -1859,7 +1861,9 @@ static void add_header(struct buffer *b,
147 buf_printf(b, "#include <linux/vermagic.h>\n");
148 buf_printf(b, "#include <linux/compiler.h>\n");
149 buf_printf(b, "\n");
150 +#ifndef CONFIG_MODULE_STRIPPED
151 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
152 +#endif
153 buf_printf(b, "\n");
154 buf_printf(b, "struct module __this_module\n");
155 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
156 @@ -1876,16 +1880,20 @@ static void add_header(struct buffer *b,
157
158 static void add_intree_flag(struct buffer *b, int is_intree)
159 {
160 +#ifndef CONFIG_MODULE_STRIPPED
161 if (is_intree)
162 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
163 +#endif
164 }
165
166 static void add_staging_flag(struct buffer *b, const char *name)
167 {
168 +#ifndef CONFIG_MODULE_STRIPPED
169 static const char *staging_dir = "drivers/staging";
170
171 if (strncmp(staging_dir, name, strlen(staging_dir)) == 0)
172 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
173 +#endif
174 }
175
176 /**
177 @@ -1977,11 +1985,13 @@ static void add_depends(struct buffer *b
178
179 static void add_srcversion(struct buffer *b, struct module *mod)
180 {
181 +#ifndef CONFIG_MODULE_STRIPPED
182 if (mod->srcversion[0]) {
183 buf_printf(b, "\n");
184 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
185 mod->srcversion);
186 }
187 +#endif
188 }
189
190 static void write_if_changed(struct buffer *b, const char *fname)
191 @@ -2204,7 +2214,9 @@ int main(int argc, char **argv)
192 add_staging_flag(&buf, mod->name);
193 err |= add_versions(&buf, mod);
194 add_depends(&buf, mod, modules);
195 +#ifndef CONFIG_MODULE_STRIPPED
196 add_moddevtable(&buf, mod);
197 +#endif
198 add_srcversion(&buf, mod);
199
200 sprintf(fname, "%s.mod.c", mod->name);