1 From: Felix Fietkau <nbd@openwrt.org>
2 Subject: [PATCH] build: add a hack for removing non-essential module info
4 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
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);
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
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)
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)
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.
33 -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
34 +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author)
36 /* What your module does. */
37 -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
38 +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description)
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
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)
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)
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
65 /* Chosen so that structs with an unsigned long line up. */
66 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
68 +/* This struct is here for syntactic coherency, it is not used */
69 +#define __MODULE_INFO_DISABLED(name) \
70 + struct __UNIQUE_ID(name) {}
72 +#ifdef CONFIG_MODULE_STRIPPED
73 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name)
75 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info)
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
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)
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)
102 @@ -1776,6 +1776,13 @@ config MODULE_SIG_HASH
103 default "sha384" if MODULE_SIG_SHA384
104 default "sha512" if MODULE_SIG_SHA512
106 +config MODULE_STRIPPED
107 + bool "Reduce module size"
110 + Remove module parameter descriptions, author info, version, aliases,
111 + device tables, etc.
115 config INIT_ALL_POSSIBLE
116 --- a/kernel/module.c
117 +++ b/kernel/module.c
118 @@ -2690,6 +2690,7 @@ static struct module *setup_load_info(st
120 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
122 +#ifndef CONFIG_MODULE_STRIPPED
123 const char *modmagic = get_modinfo(info, "vermagic");
126 @@ -2716,6 +2717,7 @@ static int check_modinfo(struct module *
127 " the quality is unknown, you have been warned.\n",
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 @@ -1740,7 +1740,9 @@ static void read_symbols(char *modname)
137 symname = info.strtab + sym->st_name;
139 handle_modversions(mod, &info, sym, symname);
140 +#ifndef CONFIG_MODULE_STRIPPED
141 handle_moddevtable(mod, &info, sym, symname);
144 if (!is_vmlinux(modname) ||
145 (is_vmlinux(modname) && vmlinux_section_warnings))
146 @@ -1884,7 +1886,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");
150 +#ifndef CONFIG_MODULE_STRIPPED
151 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
154 buf_printf(b, "struct module __this_module\n");
155 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
156 @@ -1901,16 +1905,20 @@ static void add_header(struct buffer *b,
158 static void add_intree_flag(struct buffer *b, int is_intree)
160 +#ifndef CONFIG_MODULE_STRIPPED
162 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
166 static void add_staging_flag(struct buffer *b, const char *name)
168 +#ifndef CONFIG_MODULE_STRIPPED
169 static const char *staging_dir = "drivers/staging";
171 if (strncmp(staging_dir, name, strlen(staging_dir)) == 0)
172 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
177 @@ -2003,11 +2011,13 @@ static void add_depends(struct buffer *b
179 static void add_srcversion(struct buffer *b, struct module *mod)
181 +#ifndef CONFIG_MODULE_STRIPPED
182 if (mod->srcversion[0]) {
184 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
190 static void write_if_changed(struct buffer *b, const char *fname)
191 @@ -2233,7 +2243,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);
198 add_srcversion(&buf, mod);
200 sprintf(fname, "%s.mod.c", mod->name);