OpenWrt – Diff between revs 2 and 3
?pathlinks?
Rev 2 | Rev 3 | |||
---|---|---|---|---|
1 | From a779a482fb9b9f8fcdf8b2519c789b4b9bb5dd05 Mon Sep 17 00:00:00 2001 |
1 | From a779a482fb9b9f8fcdf8b2519c789b4b9bb5dd05 Mon Sep 17 00:00:00 2001 |
|
2 | From: Felix Fietkau <nbd@nbd.name> |
2 | From: Felix Fietkau <nbd@nbd.name> |
|
3 | Date: Fri, 7 Jul 2017 16:56:48 +0200 |
3 | Date: Fri, 7 Jul 2017 16:56:48 +0200 |
|
4 | Subject: build: add a hack for removing non-essential module info |
4 | Subject: build: add a hack for removing non-essential module info |
|
5 | |
5 | |
|
6 | Signed-off-by: Felix Fietkau <nbd@nbd.name> |
6 | Signed-off-by: Felix Fietkau <nbd@nbd.name> |
|
7 | --- |
7 | --- |
|
8 | include/linux/module.h | 13 ++++++++----- |
8 | include/linux/module.h | 13 ++++++++----- |
|
9 | include/linux/moduleparam.h | 15 ++++++++++++--- |
9 | include/linux/moduleparam.h | 15 ++++++++++++--- |
|
10 | init/Kconfig | 7 +++++++ |
10 | init/Kconfig | 7 +++++++ |
|
11 | kernel/module.c | 5 ++++- |
11 | kernel/module.c | 5 ++++- |
|
12 | scripts/mod/modpost.c | 12 ++++++++++++ |
12 | scripts/mod/modpost.c | 12 ++++++++++++ |
|
13 | 5 files changed, 43 insertions(+), 9 deletions(-) |
13 | 5 files changed, 43 insertions(+), 9 deletions(-) |
|
14 | |
14 | |
|
15 | --- a/include/linux/module.h |
15 | --- a/include/linux/module.h |
|
16 | +++ b/include/linux/module.h |
16 | +++ b/include/linux/module.h |
|
17 | @@ -158,6 +158,7 @@ extern void cleanup_module(void); |
17 | @@ -158,6 +158,7 @@ extern void cleanup_module(void); |
|
18 | |
18 | |
|
19 | /* Generic info of form tag = "info" */ |
19 | /* Generic info of form tag = "info" */ |
|
20 | #define MODULE_INFO(tag, info) __MODULE_INFO(tag, 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) |
21 | +#define MODULE_INFO_STRIP(tag, info) __MODULE_INFO_STRIP(tag, tag, info) |
|
22 | |
22 | |
|
23 | /* For userspace: you can also call me... */ |
23 | /* For userspace: you can also call me... */ |
|
24 | #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) |
24 | #define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias) |
|
25 | @@ -201,12 +202,12 @@ extern void cleanup_module(void); |
25 | @@ -201,12 +202,12 @@ extern void cleanup_module(void); |
|
26 | * Author(s), use "Name <email>" or just "Name", for multiple |
26 | * Author(s), use "Name <email>" or just "Name", for multiple |
|
27 | * authors use multiple MODULE_AUTHOR() statements/lines. |
27 | * authors use multiple MODULE_AUTHOR() statements/lines. |
|
28 | */ |
28 | */ |
|
29 | -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) |
29 | -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author) |
|
30 | +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author) |
30 | +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author) |
|
31 | |
31 | |
|
32 | /* What your module does. */ |
32 | /* What your module does. */ |
|
33 | -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) |
33 | -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description) |
|
34 | +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description) |
34 | +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description) |
|
35 | |
35 | |
|
36 | -#ifdef MODULE |
36 | -#ifdef MODULE |
|
37 | +#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED) |
37 | +#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED) |
|
38 | /* Creates an alias so file2alias.c can find device table. */ |
38 | /* Creates an alias so file2alias.c can find device table. */ |
|
39 | #define MODULE_DEVICE_TABLE(type, name) \ |
39 | #define MODULE_DEVICE_TABLE(type, name) \ |
|
40 | extern typeof(name) __mod_##type##__##name##_device_table \ |
40 | extern typeof(name) __mod_##type##__##name##_device_table \ |
|
41 | @@ -233,7 +234,9 @@ extern typeof(name) __mod_##type##__##na |
41 | @@ -233,7 +234,9 @@ extern typeof(name) __mod_##type##__##na |
|
42 | */ |
42 | */ |
|
43 | |
43 | |
|
44 | #if defined(MODULE) || !defined(CONFIG_SYSFS) |
44 | #if defined(MODULE) || !defined(CONFIG_SYSFS) |
|
45 | -#define MODULE_VERSION(_version) MODULE_INFO(version, _version) |
45 | -#define MODULE_VERSION(_version) MODULE_INFO(version, _version) |
|
46 | +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version) |
46 | +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version) |
|
47 | +#elif defined(CONFIG_MODULE_STRIPPED) |
47 | +#elif defined(CONFIG_MODULE_STRIPPED) |
|
48 | +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version) |
48 | +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version) |
|
49 | #else |
49 | #else |
|
50 | #define MODULE_VERSION(_version) \ |
50 | #define MODULE_VERSION(_version) \ |
|
51 | static struct module_version_attribute ___modver_attr = { \ |
51 | static struct module_version_attribute ___modver_attr = { \ |
|
52 | @@ -255,7 +258,7 @@ extern typeof(name) __mod_##type##__##na |
52 | @@ -255,7 +258,7 @@ extern typeof(name) __mod_##type##__##na |
|
53 | /* Optional firmware file (or files) needed by the module |
53 | /* Optional firmware file (or files) needed by the module |
|
54 | * format is simply firmware file name. Multiple firmware |
54 | * format is simply firmware file name. Multiple firmware |
|
55 | * files require multiple MODULE_FIRMWARE() specifiers */ |
55 | * files require multiple MODULE_FIRMWARE() specifiers */ |
|
56 | -#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) |
56 | -#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware) |
|
57 | +#define MODULE_FIRMWARE(_firmware) MODULE_INFO_STRIP(firmware, _firmware) |
57 | +#define MODULE_FIRMWARE(_firmware) MODULE_INFO_STRIP(firmware, _firmware) |
|
58 | |
58 | |
|
59 | struct notifier_block; |
59 | struct notifier_block; |
|
60 | |
60 | |
|
61 | --- a/include/linux/moduleparam.h |
61 | --- a/include/linux/moduleparam.h |
|
62 | +++ b/include/linux/moduleparam.h |
62 | +++ b/include/linux/moduleparam.h |
|
63 | @@ -17,6 +17,16 @@ |
63 | @@ -17,6 +17,16 @@ |
|
64 | /* Chosen so that structs with an unsigned long line up. */ |
64 | /* Chosen so that structs with an unsigned long line up. */ |
|
65 | #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) |
65 | #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long)) |
|
66 | |
66 | |
|
67 | +/* This struct is here for syntactic coherency, it is not used */ |
67 | +/* This struct is here for syntactic coherency, it is not used */ |
|
68 | +#define __MODULE_INFO_DISABLED(name) \ |
68 | +#define __MODULE_INFO_DISABLED(name) \ |
|
69 | + struct __UNIQUE_ID(name) {} |
69 | + struct __UNIQUE_ID(name) {} |
|
70 | + |
70 | + |
|
71 | +#ifdef CONFIG_MODULE_STRIPPED |
71 | +#ifdef CONFIG_MODULE_STRIPPED |
|
72 | +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name) |
72 | +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name) |
|
73 | +#else |
73 | +#else |
|
74 | +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info) |
74 | +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info) |
|
75 | +#endif |
75 | +#endif |
|
76 | + |
76 | + |
|
77 | #ifdef MODULE |
77 | #ifdef MODULE |
|
78 | #define __MODULE_INFO(tag, name, info) \ |
78 | #define __MODULE_INFO(tag, name, info) \ |
|
79 | static const char __UNIQUE_ID(name)[] \ |
79 | static const char __UNIQUE_ID(name)[] \ |
|
80 | @@ -24,8 +34,7 @@ static const char __UNIQUE_ID(name)[] |
80 | @@ -24,8 +34,7 @@ static const char __UNIQUE_ID(name)[] |
|
81 | = __stringify(tag) "=" info |
81 | = __stringify(tag) "=" info |
|
82 | #else /* !MODULE */ |
82 | #else /* !MODULE */ |
|
83 | /* This struct is here for syntactic coherency, it is not used */ |
83 | /* This struct is here for syntactic coherency, it is not used */ |
|
84 | -#define __MODULE_INFO(tag, name, info) \ |
84 | -#define __MODULE_INFO(tag, name, info) \ |
|
85 | - struct __UNIQUE_ID(name) {} |
85 | - struct __UNIQUE_ID(name) {} |
|
86 | +#define __MODULE_INFO(tag, name, info) __MODULE_INFO_DISABLED(name) |
86 | +#define __MODULE_INFO(tag, name, info) __MODULE_INFO_DISABLED(name) |
|
87 | #endif |
87 | #endif |
|
88 | #define __MODULE_PARM_TYPE(name, _type) \ |
88 | #define __MODULE_PARM_TYPE(name, _type) \ |
|
89 | __MODULE_INFO(parmtype, name##type, #name ":" _type) |
89 | __MODULE_INFO(parmtype, name##type, #name ":" _type) |
|
90 | @@ -33,7 +42,7 @@ static const char __UNIQUE_ID(name)[] |
90 | @@ -33,7 +42,7 @@ static const char __UNIQUE_ID(name)[] |
|
91 | /* One for each parameter, describing how to use it. Some files do |
91 | /* One for each parameter, describing how to use it. Some files do |
|
92 | multiple of these per line, so can't just use MODULE_INFO. */ |
92 | multiple of these per line, so can't just use MODULE_INFO. */ |
|
93 | #define MODULE_PARM_DESC(_parm, desc) \ |
93 | #define MODULE_PARM_DESC(_parm, desc) \ |
|
94 | - __MODULE_INFO(parm, _parm, #_parm ":" desc) |
94 | - __MODULE_INFO(parm, _parm, #_parm ":" desc) |
|
95 | + __MODULE_INFO_STRIP(parm, _parm, #_parm ":" desc) |
95 | + __MODULE_INFO_STRIP(parm, _parm, #_parm ":" desc) |
|
96 | |
96 | |
|
97 | struct kernel_param; |
97 | struct kernel_param; |
|
98 | |
98 | |
|
99 | --- a/init/Kconfig |
99 | --- a/init/Kconfig |
|
100 | +++ b/init/Kconfig |
100 | +++ b/init/Kconfig |
|
101 | @@ -1903,6 +1903,13 @@ config TRIM_UNUSED_KSYMS |
101 | @@ -1903,6 +1903,13 @@ config TRIM_UNUSED_KSYMS |
|
102 | |
102 | |
|
103 | If unsure, or if you need to build out-of-tree modules, say N. |
103 | If unsure, or if you need to build out-of-tree modules, say N. |
|
104 | |
104 | |
|
105 | +config MODULE_STRIPPED |
105 | +config MODULE_STRIPPED |
|
106 | + bool "Reduce module size" |
106 | + bool "Reduce module size" |
|
107 | + depends on MODULES |
107 | + depends on MODULES |
|
108 | + help |
108 | + help |
|
109 | + Remove module parameter descriptions, author info, version, aliases, |
109 | + Remove module parameter descriptions, author info, version, aliases, |
|
110 | + device tables, etc. |
110 | + device tables, etc. |
|
111 | + |
111 | + |
|
112 | endif # MODULES |
112 | endif # MODULES |
|
113 | |
113 | |
|
114 | config MODULES_TREE_LOOKUP |
114 | config MODULES_TREE_LOOKUP |
|
115 | --- a/kernel/module.c |
115 | --- a/kernel/module.c |
|
116 | +++ b/kernel/module.c |
116 | +++ b/kernel/module.c |
|
117 | @@ -3008,9 +3008,11 @@ static struct module *setup_load_info(st |
117 | @@ -3006,9 +3006,11 @@ static struct module *setup_load_info(st |
|
118 | |
118 | |
|
119 | static int check_modinfo(struct module *mod, struct load_info *info, int flags) |
119 | static int check_modinfo(struct module *mod, struct load_info *info, int flags) |
|
120 | { |
120 | { |
|
121 | - const char *modmagic = get_modinfo(info, "vermagic"); |
121 | - const char *modmagic = get_modinfo(info, "vermagic"); |
|
122 | int err; |
122 | int err; |
|
123 | |
123 | |
|
124 | +#ifndef CONFIG_MODULE_STRIPPED |
124 | +#ifndef CONFIG_MODULE_STRIPPED |
|
125 | + const char *modmagic = get_modinfo(info, "vermagic"); |
125 | + const char *modmagic = get_modinfo(info, "vermagic"); |
|
126 | + |
126 | + |
|
127 | if (flags & MODULE_INIT_IGNORE_VERMAGIC) |
127 | if (flags & MODULE_INIT_IGNORE_VERMAGIC) |
|
128 | modmagic = NULL; |
128 | modmagic = NULL; |
|
129 | |
129 | |
|
130 | @@ -3031,6 +3033,7 @@ static int check_modinfo(struct module * |
130 | @@ -3029,6 +3031,7 @@ static int check_modinfo(struct module * |
|
131 | mod->name); |
131 | mod->name); |
|
132 | add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK); |
132 | add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK); |
|
133 | } |
133 | } |
|
134 | +#endif |
134 | +#endif |
|
135 | |
135 | |
|
136 | check_modinfo_retpoline(mod, info); |
136 | check_modinfo_retpoline(mod, info); |
|
137 | |
137 | |
|
138 | --- a/scripts/mod/modpost.c |
138 | --- a/scripts/mod/modpost.c |
|
139 | +++ b/scripts/mod/modpost.c |
139 | +++ b/scripts/mod/modpost.c |
|
140 | @@ -1984,7 +1984,9 @@ static void read_symbols(char *modname) |
140 | @@ -1982,7 +1982,9 @@ static void read_symbols(char *modname) |
|
141 | symname = remove_dot(info.strtab + sym->st_name); |
141 | symname = remove_dot(info.strtab + sym->st_name); |
|
142 | |
142 | |
|
143 | handle_modversions(mod, &info, sym, symname); |
143 | handle_modversions(mod, &info, sym, symname); |
|
144 | +#ifndef CONFIG_MODULE_STRIPPED |
144 | +#ifndef CONFIG_MODULE_STRIPPED |
|
145 | handle_moddevtable(mod, &info, sym, symname); |
145 | handle_moddevtable(mod, &info, sym, symname); |
|
146 | +#endif |
146 | +#endif |
|
147 | } |
147 | } |
|
148 | if (!is_vmlinux(modname) || |
148 | if (!is_vmlinux(modname) || |
|
149 | (is_vmlinux(modname) && vmlinux_section_warnings)) |
149 | (is_vmlinux(modname) && vmlinux_section_warnings)) |
|
150 | @@ -2145,8 +2147,10 @@ static void add_header(struct buffer *b, |
150 | @@ -2143,8 +2145,10 @@ static void add_header(struct buffer *b, |
|
151 | buf_printf(b, "#include <linux/vermagic.h>\n"); |
151 | buf_printf(b, "#include <linux/vermagic.h>\n"); |
|
152 | buf_printf(b, "#include <linux/compiler.h>\n"); |
152 | buf_printf(b, "#include <linux/compiler.h>\n"); |
|
153 | buf_printf(b, "\n"); |
153 | buf_printf(b, "\n"); |
|
154 | +#ifndef CONFIG_MODULE_STRIPPED |
154 | +#ifndef CONFIG_MODULE_STRIPPED |
|
155 | buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); |
155 | buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); |
|
156 | buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); |
156 | buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); |
|
157 | +#endif |
157 | +#endif |
|
158 | buf_printf(b, "\n"); |
158 | buf_printf(b, "\n"); |
|
159 | buf_printf(b, "__visible struct module __this_module\n"); |
159 | buf_printf(b, "__visible struct module __this_module\n"); |
|
160 | buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); |
160 | buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n"); |
|
161 | @@ -2163,8 +2167,10 @@ static void add_header(struct buffer *b, |
161 | @@ -2161,8 +2165,10 @@ static void add_header(struct buffer *b, |
|
162 | |
162 | |
|
163 | static void add_intree_flag(struct buffer *b, int is_intree) |
163 | static void add_intree_flag(struct buffer *b, int is_intree) |
|
164 | { |
164 | { |
|
165 | +#ifndef CONFIG_MODULE_STRIPPED |
165 | +#ifndef CONFIG_MODULE_STRIPPED |
|
166 | if (is_intree) |
166 | if (is_intree) |
|
167 | buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); |
167 | buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); |
|
168 | +#endif |
168 | +#endif |
|
169 | } |
169 | } |
|
170 | |
170 | |
|
171 | /* Cannot check for assembler */ |
171 | /* Cannot check for assembler */ |
|
172 | @@ -2177,10 +2183,12 @@ static void add_retpoline(struct buffer |
172 | @@ -2175,10 +2181,12 @@ static void add_retpoline(struct buffer |
|
173 | |
173 | |
|
174 | static void add_staging_flag(struct buffer *b, const char *name) |
174 | static void add_staging_flag(struct buffer *b, const char *name) |
|
175 | { |
175 | { |
|
176 | +#ifndef CONFIG_MODULE_STRIPPED |
176 | +#ifndef CONFIG_MODULE_STRIPPED |
|
177 | static const char *staging_dir = "drivers/staging"; |
177 | static const char *staging_dir = "drivers/staging"; |
|
178 | |
178 | |
|
179 | if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) |
179 | if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) |
|
180 | buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); |
180 | buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n"); |
|
181 | +#endif |
181 | +#endif |
|
182 | } |
182 | } |
|
183 | |
183 | |
|
184 | /** |
184 | /** |
|
185 | @@ -2279,11 +2287,13 @@ static void add_depends(struct buffer *b |
185 | @@ -2277,11 +2285,13 @@ static void add_depends(struct buffer *b |
|
186 | |
186 | |
|
187 | static void add_srcversion(struct buffer *b, struct module *mod) |
187 | static void add_srcversion(struct buffer *b, struct module *mod) |
|
188 | { |
188 | { |
|
189 | +#ifndef CONFIG_MODULE_STRIPPED |
189 | +#ifndef CONFIG_MODULE_STRIPPED |
|
190 | if (mod->srcversion[0]) { |
190 | if (mod->srcversion[0]) { |
|
191 | buf_printf(b, "\n"); |
191 | buf_printf(b, "\n"); |
|
192 | buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", |
192 | buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", |
|
193 | mod->srcversion); |
193 | mod->srcversion); |
|
194 | } |
194 | } |
|
195 | +#endif |
195 | +#endif |
|
196 | } |
196 | } |
|
197 | |
197 | |
|
198 | static void write_if_changed(struct buffer *b, const char *fname) |
198 | static void write_if_changed(struct buffer *b, const char *fname) |
|
199 | @@ -2520,7 +2530,9 @@ int main(int argc, char **argv) |
199 | @@ -2518,7 +2528,9 @@ int main(int argc, char **argv) |
|
200 | add_staging_flag(&buf, mod->name); |
200 | add_staging_flag(&buf, mod->name); |
|
201 | err |= add_versions(&buf, mod); |
201 | err |= add_versions(&buf, mod); |
|
202 | add_depends(&buf, mod, modules); |
202 | add_depends(&buf, mod, modules); |
|
203 | +#ifndef CONFIG_MODULE_STRIPPED |
203 | +#ifndef CONFIG_MODULE_STRIPPED |
|
204 | add_moddevtable(&buf, mod); |
204 | add_moddevtable(&buf, mod); |
|
205 | +#endif |
205 | +#endif |
|
206 | add_srcversion(&buf, mod); |
206 | add_srcversion(&buf, mod); |
|
207 | |
207 | |
|
208 | sprintf(fname, "%s.mod.c", mod->name); |
208 | sprintf(fname, "%s.mod.c", mod->name); |
|
209 | |
209 | |