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