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