add an optional config option for stripping all unnecessary symbol exports from the...
[openwrt/openwrt.git] / target / linux / generic-2.6 / patches-2.6.30 / 028-module_exports.patch
1 --- a/include/asm-generic/vmlinux.lds.h
2 +++ b/include/asm-generic/vmlinux.lds.h
3 @@ -4,6 +4,18 @@
4 #define LOAD_OFFSET 0
5 #endif
6
7 +#ifndef SYMTAB_KEEP_STR
8 +#define SYMTAB_KEEP_STR *(__ksymtab_strings.*)
9 +#endif
10 +
11 +#ifndef SYMTAB_KEEP
12 +#define SYMTAB_KEEP *(__ksymtab.*)
13 +#endif
14 +
15 +#ifndef SYMTAB_KEEP_GPL
16 +#define SYMTAB_KEEP_GPL *(__ksymtab_gpl.*)
17 +#endif
18 +
19 #ifndef VMLINUX_SYMBOL
20 #define VMLINUX_SYMBOL(_sym_) _sym_
21 #endif
22 @@ -176,35 +188,35 @@
23 /* Kernel symbol table: Normal symbols */ \
24 __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
25 VMLINUX_SYMBOL(__start___ksymtab) = .; \
26 - *(__ksymtab) \
27 + SYMTAB_KEEP \
28 VMLINUX_SYMBOL(__stop___ksymtab) = .; \
29 } \
30 \
31 /* Kernel symbol table: GPL-only symbols */ \
32 __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
33 VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
34 - *(__ksymtab_gpl) \
35 + SYMTAB_KEEP_GPL \
36 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
37 } \
38 \
39 /* Kernel symbol table: Normal unused symbols */ \
40 __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
41 VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
42 - *(__ksymtab_unused) \
43 + *(__ksymtab_unused.*) \
44 VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
45 } \
46 \
47 /* Kernel symbol table: GPL-only unused symbols */ \
48 __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
49 VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
50 - *(__ksymtab_unused_gpl) \
51 + *(__ksymtab_unused_gpl.*) \
52 VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
53 } \
54 \
55 /* Kernel symbol table: GPL-future-only symbols */ \
56 __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
57 VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
58 - *(__ksymtab_gpl_future) \
59 + *(__ksymtab_gpl_future.*) \
60 VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
61 } \
62 \
63 @@ -245,7 +257,13 @@
64 \
65 /* Kernel symbol table: strings */ \
66 __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
67 - *(__ksymtab_strings) \
68 + SYMTAB_KEEP_STR \
69 + } \
70 + \
71 + /DISCARD/ : { \
72 + *(__ksymtab.*) \
73 + *(__ksymtab_gpl.*) \
74 + *(__ksymtab_strings.*) \
75 } \
76 \
77 /* __*init sections */ \
78 --- a/include/linux/module.h
79 +++ b/include/linux/module.h
80 @@ -187,16 +187,24 @@ void *__symbol_get_gpl(const char *symbo
81 #define __CRC_SYMBOL(sym, sec)
82 #endif
83
84 +#ifdef MODULE
85 +#define __EXPORT_SUFFIX(sym)
86 +#else
87 +#define __EXPORT_SUFFIX(sym) "." #sym
88 +#endif
89 +
90 /* For every exported symbol, place a struct in the __ksymtab section */
91 #define __EXPORT_SYMBOL(sym, sec) \
92 extern typeof(sym) sym; \
93 __CRC_SYMBOL(sym, sec) \
94 static const char __kstrtab_##sym[] \
95 - __attribute__((section("__ksymtab_strings"), aligned(1))) \
96 + __attribute__((section("__ksymtab_strings" \
97 + __EXPORT_SUFFIX(sym)), aligned(1))) \
98 = MODULE_SYMBOL_PREFIX #sym; \
99 static const struct kernel_symbol __ksymtab_##sym \
100 __used \
101 - __attribute__((section("__ksymtab" sec), unused)) \
102 + __attribute__((section("__ksymtab" sec \
103 + __EXPORT_SUFFIX(sym)), unused)) \
104 = { (unsigned long)&sym, __kstrtab_##sym }
105
106 #define EXPORT_SYMBOL(sym) \
107 --- a/Makefile
108 +++ b/Makefile
109 @@ -994,7 +994,7 @@ prepare: prepare0
110 # Leave this as default for preprocessing vmlinux.lds.S, which is now
111 # done in arch/$(ARCH)/kernel/Makefile
112
113 -export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
114 +export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH) $(EXTRA_LDSFLAGS)
115
116 # The asm symlink changes when $(ARCH) changes.
117 # Detect this and ask user to run make mrproper