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 @@ -84,9 +84,10 @@ void trim_init_extable(struct module *m)
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)
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)
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.
24 -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
25 +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author)
27 /* What your module does. */
28 -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
29 +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description)
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 typeof(name) __mod_##type##__##name##_device_table \
36 @@ -159,7 +160,9 @@ extern const typeof(name) __mod_##type##
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)
45 #define MODULE_VERSION(_version) \
46 static struct module_version_attribute ___modver_attr = { \
47 @@ -181,7 +184,7 @@ extern const typeof(name) __mod_##type##
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)
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
59 /* Chosen so that structs with an unsigned long line up. */
60 #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
62 +/* This struct is here for syntactic coherency, it is not used */
63 +#define __MODULE_INFO_DISABLED(name) \
64 + struct __UNIQUE_ID(name) {}
66 +#ifdef CONFIG_MODULE_STRIPPED
67 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name)
69 +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info)
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
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)
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)
96 @@ -1998,6 +1998,13 @@ config MODULE_COMPRESS_XZ
100 +config MODULE_STRIPPED
101 + bool "Reduce module size"
104 + Remove module parameter descriptions, author info, version, aliases,
105 + device tables, etc.
109 config INIT_ALL_POSSIBLE
110 --- a/kernel/module.c
111 +++ b/kernel/module.c
112 @@ -2685,6 +2685,7 @@ static struct module *setup_load_info(st
114 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
116 +#ifndef CONFIG_MODULE_STRIPPED
117 const char *modmagic = get_modinfo(info, "vermagic");
120 @@ -2710,6 +2711,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);
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 @@ -1959,7 +1959,9 @@ static void read_symbols(char *modname)
131 symname = remove_dot(info.strtab + sym->st_name);
133 handle_modversions(mod, &info, sym, symname);
134 +#ifndef CONFIG_MODULE_STRIPPED
135 handle_moddevtable(mod, &info, sym, symname);
138 if (!is_vmlinux(modname) ||
139 (is_vmlinux(modname) && vmlinux_section_warnings))
140 @@ -2103,7 +2105,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");
144 +#ifndef CONFIG_MODULE_STRIPPED
145 buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
148 buf_printf(b, "__visible struct module __this_module\n");
149 buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
150 @@ -2120,16 +2124,20 @@ static void add_header(struct buffer *b,
152 static void add_intree_flag(struct buffer *b, int is_intree)
154 +#ifndef CONFIG_MODULE_STRIPPED
156 buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
160 static void add_staging_flag(struct buffer *b, const char *name)
162 +#ifndef CONFIG_MODULE_STRIPPED
163 static const char *staging_dir = "drivers/staging";
165 if (strncmp(staging_dir, name, strlen(staging_dir)) == 0)
166 buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
171 @@ -2222,11 +2230,13 @@ static void add_depends(struct buffer *b
173 static void add_srcversion(struct buffer *b, struct module *mod)
175 +#ifndef CONFIG_MODULE_STRIPPED
176 if (mod->srcversion[0]) {
178 buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
184 static void write_if_changed(struct buffer *b, const char *fname)
185 @@ -2457,7 +2467,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);
192 add_srcversion(&buf, mod);
194 sprintf(fname, "%s.mod.c", mod->name);