204-module_strip.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. From: Felix Fietkau <nbd@openwrt.org>
  2. Subject: [PATCH] build: add a hack for removing non-essential module info
  3. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
  4. ---
  5. --- a/include/linux/module.h
  6. +++ b/include/linux/module.h
  7. @@ -82,7 +82,7 @@ void sort_extable(struct exception_table
  8. void sort_main_extable(void);
  9. void trim_init_extable(struct module *m);
  10. -#ifdef MODULE
  11. +#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED)
  12. #define MODULE_GENERIC_TABLE(gtype,name) \
  13. extern const struct gtype##_id __mod_##gtype##_table \
  14. __attribute__ ((unused, alias(__stringify(name))))
  15. @@ -93,9 +93,10 @@ extern const struct gtype##_id __mod_##g
  16. /* Generic info of form tag = "info" */
  17. #define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
  18. +#define MODULE_INFO_STRIP(tag, info) __MODULE_INFO_STRIP(tag, tag, info)
  19. /* For userspace: you can also call me... */
  20. -#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)
  21. +#define MODULE_ALIAS(_alias) MODULE_INFO_STRIP(alias, _alias)
  22. /*
  23. * The following license idents are currently accepted as indicating free
  24. @@ -131,10 +132,10 @@ extern const struct gtype##_id __mod_##g
  25. * Author(s), use "Name <email>" or just "Name", for multiple
  26. * authors use multiple MODULE_AUTHOR() statements/lines.
  27. */
  28. -#define MODULE_AUTHOR(_author) MODULE_INFO(author, _author)
  29. +#define MODULE_AUTHOR(_author) MODULE_INFO_STRIP(author, _author)
  30. /* What your module does. */
  31. -#define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
  32. +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description)
  33. #define MODULE_DEVICE_TABLE(type,name) \
  34. MODULE_GENERIC_TABLE(type##_device,name)
  35. @@ -155,7 +156,9 @@ extern const struct gtype##_id __mod_##g
  36. */
  37. #if defined(MODULE) || !defined(CONFIG_SYSFS)
  38. -#define MODULE_VERSION(_version) MODULE_INFO(version, _version)
  39. +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version)
  40. +#elif defined(CONFIG_MODULE_STRIPPED)
  41. +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version)
  42. #else
  43. #define MODULE_VERSION(_version) \
  44. static struct module_version_attribute ___modver_attr = { \
  45. @@ -177,7 +180,7 @@ extern const struct gtype##_id __mod_##g
  46. /* Optional firmware file (or files) needed by the module
  47. * format is simply firmware file name. Multiple firmware
  48. * files require multiple MODULE_FIRMWARE() specifiers */
  49. -#define MODULE_FIRMWARE(_firmware) MODULE_INFO(firmware, _firmware)
  50. +#define MODULE_FIRMWARE(_firmware) MODULE_INFO_STRIP(firmware, _firmware)
  51. /* Given an address, look for it in the exception tables */
  52. const struct exception_table_entry *search_exception_tables(unsigned long add);
  53. --- a/include/linux/moduleparam.h
  54. +++ b/include/linux/moduleparam.h
  55. @@ -16,6 +16,16 @@
  56. /* Chosen so that structs with an unsigned long line up. */
  57. #define MAX_PARAM_PREFIX_LEN (64 - sizeof(unsigned long))
  58. +/* This struct is here for syntactic coherency, it is not used */
  59. +#define __MODULE_INFO_DISABLED(name) \
  60. + struct __UNIQUE_ID(name) {}
  61. +
  62. +#ifdef CONFIG_MODULE_STRIPPED
  63. +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name)
  64. +#else
  65. +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info)
  66. +#endif
  67. +
  68. #ifdef MODULE
  69. #define __MODULE_INFO(tag, name, info) \
  70. static const char __UNIQUE_ID(name)[] \
  71. @@ -23,8 +33,7 @@ static const char __UNIQUE_ID(name)[]
  72. = __stringify(tag) "=" info
  73. #else /* !MODULE */
  74. /* This struct is here for syntactic coherency, it is not used */
  75. -#define __MODULE_INFO(tag, name, info) \
  76. - struct __UNIQUE_ID(name) {}
  77. +#define __MODULE_INFO(tag, name, info) __MODULE_INFO_DISABLED(name)
  78. #endif
  79. #define __MODULE_PARM_TYPE(name, _type) \
  80. __MODULE_INFO(parmtype, name##type, #name ":" _type)
  81. @@ -32,7 +41,7 @@ static const char __UNIQUE_ID(name)[]
  82. /* One for each parameter, describing how to use it. Some files do
  83. multiple of these per line, so can't just use MODULE_INFO. */
  84. #define MODULE_PARM_DESC(_parm, desc) \
  85. - __MODULE_INFO(parm, _parm, #_parm ":" desc)
  86. + __MODULE_INFO_STRIP(parm, _parm, #_parm ":" desc)
  87. struct kernel_param;
  88. --- a/init/Kconfig
  89. +++ b/init/Kconfig
  90. @@ -1708,6 +1708,13 @@ config MODULE_SIG_SHA512
  91. endchoice
  92. +config MODULE_STRIPPED
  93. + bool "Reduce module size"
  94. + depends on MODULES
  95. + help
  96. + Remove module parameter descriptions, author info, version, aliases,
  97. + device tables, etc.
  98. +
  99. endif # MODULES
  100. config INIT_ALL_POSSIBLE
  101. --- a/kernel/module.c
  102. +++ b/kernel/module.c
  103. @@ -2682,6 +2682,7 @@ static struct module *setup_load_info(st
  104. static int check_modinfo(struct module *mod, struct load_info *info, int flags)
  105. {
  106. +#ifndef CONFIG_MODULE_STRIPPED
  107. const char *modmagic = get_modinfo(info, "vermagic");
  108. int err;
  109. @@ -2708,6 +2709,7 @@ static int check_modinfo(struct module *
  110. " the quality is unknown, you have been warned.\n",
  111. mod->name);
  112. }
  113. +#endif
  114. /* Set up license info based on the info section */
  115. set_license(mod, get_modinfo(info, "license"));
  116. --- a/scripts/mod/modpost.c
  117. +++ b/scripts/mod/modpost.c
  118. @@ -1736,7 +1736,9 @@ static void read_symbols(char *modname)
  119. symname = info.strtab + sym->st_name;
  120. handle_modversions(mod, &info, sym, symname);
  121. +#ifndef CONFIG_MODULE_STRIPPED
  122. handle_moddevtable(mod, &info, sym, symname);
  123. +#endif
  124. }
  125. if (!is_vmlinux(modname) ||
  126. (is_vmlinux(modname) && vmlinux_section_warnings))
  127. @@ -1859,7 +1861,9 @@ static void add_header(struct buffer *b,
  128. buf_printf(b, "#include <linux/vermagic.h>\n");
  129. buf_printf(b, "#include <linux/compiler.h>\n");
  130. buf_printf(b, "\n");
  131. +#ifndef CONFIG_MODULE_STRIPPED
  132. buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n");
  133. +#endif
  134. buf_printf(b, "\n");
  135. buf_printf(b, "struct module __this_module\n");
  136. buf_printf(b, "__attribute__((section(\".gnu.linkonce.this_module\"))) = {\n");
  137. @@ -1876,16 +1880,20 @@ static void add_header(struct buffer *b,
  138. static void add_intree_flag(struct buffer *b, int is_intree)
  139. {
  140. +#ifndef CONFIG_MODULE_STRIPPED
  141. if (is_intree)
  142. buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
  143. +#endif
  144. }
  145. static void add_staging_flag(struct buffer *b, const char *name)
  146. {
  147. +#ifndef CONFIG_MODULE_STRIPPED
  148. static const char *staging_dir = "drivers/staging";
  149. if (strncmp(staging_dir, name, strlen(staging_dir)) == 0)
  150. buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
  151. +#endif
  152. }
  153. /**
  154. @@ -1977,11 +1985,13 @@ static void add_depends(struct buffer *b
  155. static void add_srcversion(struct buffer *b, struct module *mod)
  156. {
  157. +#ifndef CONFIG_MODULE_STRIPPED
  158. if (mod->srcversion[0]) {
  159. buf_printf(b, "\n");
  160. buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n",
  161. mod->srcversion);
  162. }
  163. +#endif
  164. }
  165. static void write_if_changed(struct buffer *b, const char *fname)
  166. @@ -2204,7 +2214,9 @@ int main(int argc, char **argv)
  167. add_staging_flag(&buf, mod->name);
  168. err |= add_versions(&buf, mod);
  169. add_depends(&buf, mod, modules);
  170. +#ifndef CONFIG_MODULE_STRIPPED
  171. add_moddevtable(&buf, mod);
  172. +#endif
  173. add_srcversion(&buf, mod);
  174. sprintf(fname, "%s.mod.c", mod->name);