kernel: bump 6.1 to 6.1.79
[openwrt/staging/stintel.git] / target / linux / generic / hack-6.1 / 204-module_strip.patch
1 From a779a482fb9b9f8fcdf8b2519c789b4b9bb5dd05 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Fri, 7 Jul 2017 16:56:48 +0200
4 Subject: build: add a hack for removing non-essential module info
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8 include/linux/module.h | 13 ++++++++-----
9 include/linux/moduleparam.h | 15 ++++++++++++---
10 init/Kconfig | 7 +++++++
11 kernel/module.c | 5 ++++-
12 scripts/mod/modpost.c | 12 ++++++++++++
13 5 files changed, 43 insertions(+), 9 deletions(-)
14
15 --- a/include/linux/module.h
16 +++ b/include/linux/module.h
17 @@ -163,6 +163,7 @@ extern void cleanup_module(void);
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 @@ -232,12 +233,12 @@ extern void cleanup_module(void);
26 * Author(s), use "Name <email>" or just "Name", for multiple
27 * authors use multiple MODULE_AUTHOR() statements/lines.
28 */
29 -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
30 +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author)
31
32 /* What your module does. */
33 -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
34 +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description)
35
36 -#ifdef MODULE
37 +#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED)
38 /* Creates an alias so file2alias.c can find device table. */
39 #define MODULE_DEVICE_TABLE(type, name) \
40 extern typeof(name) __mod_##type##__##name##_device_table \
41 @@ -264,7 +265,9 @@ extern typeof(name) __mod_##type##__##na
42 */
43
44 #if defined(MODULE) || !defined(CONFIG_SYSFS)
45 -#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
46 +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version)
47 +#elif defined(CONFIG_MODULE_STRIPPED)
48 +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version)
49 #else
50 #define MODULE_VERSION(_version) \
51 MODULE_INFO(version, _version); \
52 @@ -287,7 +290,7 @@ extern typeof(name) __mod_##type##__##na
53 /* Optional firmware file (or files) needed by the module
54 * format is simply firmware file name. Multiple firmware
55 * files require multiple MODULE_FIRMWARE() specifiers */
56 -#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
57 +#define MODULE_FIRMWARE(_firmware) MODULE_INFO_STRIP(firmware, _firmware)
58
59 #define MODULE_IMPORT_NS(ns) MODULE_INFO(import_ns, __stringify(ns))
60
61 --- a/include/linux/moduleparam.h
62 +++ b/include/linux/moduleparam.h
63 @@ -20,6 +20,16 @@
64 /* Chosen so that structs with an unsigned long line up. */
65 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
66
67 +/* This struct is here for syntactic coherency, it is not used */
68 +#define __MODULE_INFO_DISABLED(name) \
69 + struct __UNIQUE_ID(name) {}
70 +
71 +#ifdef CONFIG_MODULE_STRIPPED
72 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name)
73 +#else
74 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info)
75 +#endif
76 +
77 #define __MODULE_INFO(tag, name, info) \
78 static const char __UNIQUE_ID(name)[] \
79 __used __section(".modinfo") __aligned(1) \
80 @@ -31,7 +41,7 @@
81 /* One for each parameter, describing how to use it. Some files do
82 multiple of these per line, so can't just use MODULE_INFO. */
83 #define MODULE_PARM_DESC(_parm, desc) \
84 - __MODULE_INFO(parm, _parm, #_parm ":" desc)
85 + __MODULE_INFO_STRIP(parm, _parm, #_parm ":" desc)
86
87 struct kernel_param;
88
89 --- a/kernel/module/Kconfig
90 +++ b/kernel/module/Kconfig
91 @@ -290,4 +290,11 @@ config MODULES_TREE_LOOKUP
92 def_bool y
93 depends on PERF_EVENTS || TRACING || CFI_CLANG
94
95 +config MODULE_STRIPPED
96 + bool "Reduce module size"
97 + depends on MODULES
98 + help
99 + Remove module parameter descriptions, author info, version, aliases,
100 + device tables, etc.
101 +
102 endif # MODULES
103 --- a/kernel/module/main.c
104 +++ b/kernel/module/main.c
105 @@ -988,6 +988,7 @@ size_t modinfo_attrs_count = ARRAY_SIZE(
106
107 static const char vermagic[] = VERMAGIC_STRING;
108
109 +#if defined(CONFIG_MODVERSIONS) || !defined(CONFIG_MODULE_STRIPPED)
110 int try_to_force_load(struct module *mod, const char *reason)
111 {
112 #ifdef CONFIG_MODULE_FORCE_LOAD
113 @@ -999,6 +1000,7 @@ int try_to_force_load(struct module *mod
114 return -ENOEXEC;
115 #endif
116 }
117 +#endif
118
119 static char *get_modinfo(const struct load_info *info, const char *tag);
120 static char *get_next_modinfo(const struct load_info *info, const char *tag,
121 @@ -1958,9 +1960,11 @@ static int setup_load_info(struct load_i
122
123 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
124 {
125 - const char *modmagic = get_modinfo(info, "vermagic");
126 int err;
127
128 +#ifndef CONFIG_MODULE_STRIPPED
129 + const char *modmagic = get_modinfo(info, "vermagic");
130 +
131 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
132 modmagic = NULL;
133
134 @@ -1981,6 +1985,7 @@ static int check_modinfo(struct module *
135 mod->name);
136 add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
137 }
138 +#endif
139
140 check_modinfo_retpoline(mod, info);
141
142 --- a/scripts/mod/modpost.c
143 +++ b/scripts/mod/modpost.c
144 @@ -1785,7 +1785,9 @@ static void read_symbols(const char *mod
145 symname = remove_dot(info.strtab + sym->st_name);
146
147 handle_symbol(mod, &info, sym, symname);
148 +#ifndef CONFIG_MODULE_STRIPPED
149 handle_moddevtable(mod, &info, sym, symname);
150 +#endif
151 }
152
153 for (sym = info.symtab_start; sym < info.symtab_stop; sym++) {
154 @@ -1948,8 +1950,10 @@ static void add_header(struct buffer *b,
155 buf_printf(b, "BUILD_SALT;\n");
156 buf_printf(b, "BUILD_LTO_INFO;\n");
157 buf_printf(b, "\n");
158 +#ifndef CONFIG_MODULE_STRIPPED
159 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
160 buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n");
161 +#endif
162 buf_printf(b, "\n");
163 buf_printf(b, "__visible struct module __this_module\n");
164 buf_printf(b, "__section(\".gnu.linkonce.this_module\") = {\n");
165 @@ -1963,8 +1967,10 @@ static void add_header(struct buffer *b,
166 buf_printf(b, "\t.arch = MODULE_ARCH_INIT,\n");
167 buf_printf(b, "};\n");
168
169 +#ifndef CONFIG_MODULE_STRIPPED
170 if (!external_module)
171 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
172 +#endif
173
174 buf_printf(b,
175 "\n"
176 @@ -1972,8 +1978,10 @@ static void add_header(struct buffer *b,
177 "MODULE_INFO(retpoline, \"Y\");\n"
178 "#endif\n");
179
180 +#ifndef CONFIG_MODULE_STRIPPED
181 if (strstarts(mod->name, "drivers/staging"))
182 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
183 +#endif
184
185 if (strstarts(mod->name, "tools/testing"))
186 buf_printf(b, "\nMODULE_INFO(test, \"Y\");\n");
187 @@ -2069,11 +2077,13 @@ static void add_depends(struct buffer *b
188
189 static void add_srcversion(struct buffer *b, struct module *mod)
190 {
191 +#ifndef CONFIG_MODULE_STRIPPED
192 if (mod->srcversion[0]) {
193 buf_printf(b, "\n");
194 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
195 mod->srcversion);
196 }
197 +#endif
198 }
199
200 static void write_buf(struct buffer *b, const char *fname)
201 @@ -2159,7 +2169,9 @@ static void write_mod_c_file(struct modu
202 add_exported_symbols(&buf, mod);
203 add_versions(&buf, mod);
204 add_depends(&buf, mod);
205 +#ifndef CONFIG_MODULE_STRIPPED
206 add_moddevtable(&buf, mod);
207 +#endif
208 add_srcversion(&buf, mod);
209
210 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);