220-module_exports.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. --- a/include/asm-generic/vmlinux.lds.h
  2. +++ b/include/asm-generic/vmlinux.lds.h
  3. @@ -52,6 +52,27 @@
  4. #define LOAD_OFFSET 0
  5. #endif
  6. +#ifndef SYMTAB_KEEP_STR
  7. +#define SYMTAB_KEEP_STR *(__ksymtab_strings.*)
  8. +#define SYMTAB_DISCARD_STR
  9. +#else
  10. +#define SYMTAB_DISCARD_STR *(__ksymtab_strings.*)
  11. +#endif
  12. +
  13. +#ifndef SYMTAB_KEEP
  14. +#define SYMTAB_KEEP *(__ksymtab.*)
  15. +#define SYMTAB_DISCARD
  16. +#else
  17. +#define SYMTAB_DISCARD *(__ksymtab.*)
  18. +#endif
  19. +
  20. +#ifndef SYMTAB_KEEP_GPL
  21. +#define SYMTAB_KEEP_GPL *(__ksymtab_gpl.*)
  22. +#define SYMTAB_DISCARD_GPL
  23. +#else
  24. +#define SYMTAB_DISCARD_GPL *(__ksymtab_gpl.*)
  25. +#endif
  26. +
  27. #ifndef SYMBOL_PREFIX
  28. #define VMLINUX_SYMBOL(sym) sym
  29. #else
  30. @@ -267,35 +288,35 @@
  31. /* Kernel symbol table: Normal symbols */ \
  32. __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
  33. VMLINUX_SYMBOL(__start___ksymtab) = .; \
  34. - *(__ksymtab) \
  35. + SYMTAB_KEEP \
  36. VMLINUX_SYMBOL(__stop___ksymtab) = .; \
  37. } \
  38. \
  39. /* Kernel symbol table: GPL-only symbols */ \
  40. __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
  41. VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
  42. - *(__ksymtab_gpl) \
  43. + SYMTAB_KEEP_GPL \
  44. VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
  45. } \
  46. \
  47. /* Kernel symbol table: Normal unused symbols */ \
  48. __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
  49. VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
  50. - *(__ksymtab_unused) \
  51. + *(__ksymtab_unused.*) \
  52. VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
  53. } \
  54. \
  55. /* Kernel symbol table: GPL-only unused symbols */ \
  56. __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
  57. VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
  58. - *(__ksymtab_unused_gpl) \
  59. + *(__ksymtab_unused_gpl.*) \
  60. VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
  61. } \
  62. \
  63. /* Kernel symbol table: GPL-future-only symbols */ \
  64. __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
  65. VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
  66. - *(__ksymtab_gpl_future) \
  67. + *(__ksymtab_gpl_future.*) \
  68. VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
  69. } \
  70. \
  71. @@ -336,7 +357,7 @@
  72. \
  73. /* Kernel symbol table: strings */ \
  74. __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
  75. - *(__ksymtab_strings) \
  76. + SYMTAB_KEEP_STR \
  77. } \
  78. \
  79. /* __*init sections */ \
  80. @@ -660,6 +681,9 @@
  81. EXIT_TEXT \
  82. EXIT_DATA \
  83. EXIT_CALL \
  84. + SYMTAB_DISCARD \
  85. + SYMTAB_DISCARD_GPL \
  86. + SYMTAB_DISCARD_STR \
  87. *(.discard) \
  88. *(.discard.*) \
  89. }
  90. --- a/include/linux/module.h
  91. +++ b/include/linux/module.h
  92. @@ -202,16 +202,24 @@ struct module_use {
  93. #define __CRC_SYMBOL(sym, sec)
  94. #endif
  95. +#ifdef MODULE
  96. +#define __EXPORT_SUFFIX(sym)
  97. +#else
  98. +#define __EXPORT_SUFFIX(sym) "." #sym
  99. +#endif
  100. +
  101. /* For every exported symbol, place a struct in the __ksymtab section */
  102. #define __EXPORT_SYMBOL(sym, sec) \
  103. extern typeof(sym) sym; \
  104. __CRC_SYMBOL(sym, sec) \
  105. static const char __kstrtab_##sym[] \
  106. - __attribute__((section("__ksymtab_strings"), aligned(1))) \
  107. + __attribute__((section("__ksymtab_strings" \
  108. + __EXPORT_SUFFIX(sym)), aligned(1))) \
  109. = MODULE_SYMBOL_PREFIX #sym; \
  110. static const struct kernel_symbol __ksymtab_##sym \
  111. __used \
  112. - __attribute__((section("__ksymtab" sec), unused)) \
  113. + __attribute__((section("__ksymtab" sec \
  114. + __EXPORT_SUFFIX(sym)), unused)) \
  115. = { (unsigned long)&sym, __kstrtab_##sym }
  116. #define EXPORT_SYMBOL(sym) \