OpenWrt – Blame information for rev 3
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | From b14784e7883390c20ed3ff904892255404a5914b Mon Sep 17 00:00:00 2001 |
2 | From: Felix Fietkau <nbd@nbd.name> |
||
3 | Date: Fri, 7 Jul 2017 17:05:53 +0200 |
||
4 | Subject: add an optional config option for stripping all unnecessary symbol exports from the kernel image |
||
5 | |||
6 | lede-commit: bb5a40c64b7c4f4848509fa0a6625055fc9e66cc |
||
7 | Signed-off-by: Felix Fietkau <nbd@nbd.name> |
||
8 | --- |
||
9 | include/asm-generic/vmlinux.lds.h | 18 +++++++++++++++--- |
||
10 | include/linux/export.h | 9 ++++++++- |
||
11 | scripts/Makefile.build | 2 +- |
||
12 | 3 files changed, 24 insertions(+), 5 deletions(-) |
||
13 | |||
14 | --- a/include/asm-generic/vmlinux.lds.h |
||
15 | +++ b/include/asm-generic/vmlinux.lds.h |
||
16 | @@ -54,6 +54,16 @@ |
||
17 | #define LOAD_OFFSET 0 |
||
18 | #endif |
||
19 | |||
20 | +#ifndef SYMTAB_KEEP |
||
21 | +#define SYMTAB_KEEP KEEP(*(SORT(___ksymtab+*))) |
||
22 | +#define SYMTAB_KEEP_GPL KEEP(*(SORT(___ksymtab_gpl+*))) |
||
23 | +#endif |
||
24 | + |
||
25 | +#ifndef SYMTAB_DISCARD |
||
26 | +#define SYMTAB_DISCARD |
||
27 | +#define SYMTAB_DISCARD_GPL |
||
28 | +#endif |
||
29 | + |
||
30 | #include <linux/export.h> |
||
31 | |||
32 | /* Align . to a 8 byte boundary equals to maximum function alignment. */ |
||
33 | @@ -342,14 +352,14 @@ |
||
34 | /* Kernel symbol table: Normal symbols */ \ |
||
35 | __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \ |
||
36 | VMLINUX_SYMBOL(__start___ksymtab) = .; \ |
||
37 | - KEEP(*(SORT(___ksymtab+*))) \ |
||
38 | + SYMTAB_KEEP \ |
||
39 | VMLINUX_SYMBOL(__stop___ksymtab) = .; \ |
||
40 | } \ |
||
41 | \ |
||
42 | /* Kernel symbol table: GPL-only symbols */ \ |
||
43 | __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \ |
||
44 | VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \ |
||
45 | - KEEP(*(SORT(___ksymtab_gpl+*))) \ |
||
46 | + SYMTAB_KEEP_GPL \ |
||
47 | VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \ |
||
48 | } \ |
||
49 | \ |
||
50 | @@ -411,7 +421,7 @@ |
||
51 | \ |
||
52 | /* Kernel symbol table: strings */ \ |
||
53 | __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \ |
||
54 | - *(__ksymtab_strings) \ |
||
55 | + *(__ksymtab_strings+*) \ |
||
56 | } \ |
||
57 | \ |
||
58 | /* __*init sections */ \ |
||
59 | @@ -763,6 +773,8 @@ |
||
60 | EXIT_TEXT \ |
||
61 | EXIT_DATA \ |
||
62 | EXIT_CALL \ |
||
63 | + SYMTAB_DISCARD \ |
||
64 | + SYMTAB_DISCARD_GPL \ |
||
65 | *(.discard) \ |
||
66 | *(.discard.*) \ |
||
67 | } |
||
68 | --- a/include/linux/export.h |
||
69 | +++ b/include/linux/export.h |
||
70 | @@ -53,12 +53,19 @@ extern struct module __this_module; |
||
71 | #define __CRC_SYMBOL(sym, sec) |
||
72 | #endif |
||
73 | |||
74 | +#ifdef MODULE |
||
75 | +#define __EXPORT_SUFFIX(sym) |
||
76 | +#else |
||
77 | +#define __EXPORT_SUFFIX(sym) "+" #sym |
||
78 | +#endif |
||
79 | + |
||
80 | /* For every exported symbol, place a struct in the __ksymtab section */ |
||
81 | #define ___EXPORT_SYMBOL(sym, sec) \ |
||
82 | extern typeof(sym) sym; \ |
||
83 | __CRC_SYMBOL(sym, sec) \ |
||
84 | static const char __kstrtab_##sym[] \ |
||
85 | - __attribute__((section("__ksymtab_strings"), aligned(1))) \ |
||
86 | + __attribute__((section("__ksymtab_strings" \ |
||
87 | + __EXPORT_SUFFIX(sym)), aligned(1))) \ |
||
88 | = VMLINUX_SYMBOL_STR(sym); \ |
||
89 | static const struct kernel_symbol __ksymtab_##sym \ |
||
90 | __used \ |
||
91 | --- a/scripts/Makefile.build |
||
92 | +++ b/scripts/Makefile.build |
||
3 | office | 93 | @@ -401,7 +401,7 @@ targets += $(extra-y) $(MAKECMDGOALS) $( |
1 | office | 94 | # Linker scripts preprocessor (.lds.S -> .lds) |
95 | # --------------------------------------------------------------------------- |
||
96 | quiet_cmd_cpp_lds_S = LDS $@ |
||
97 | - cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \ |
||
98 | + cmd_cpp_lds_S = $(CPP) $(EXTRA_LDSFLAGS) $(cpp_flags) -P -C -U$(ARCH) \ |
||
99 | -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< |
||
100 | |||
101 | $(obj)/%.lds: $(src)/%.lds.S FORCE |