kernel: split patches folder up into backport, pending and hack folders
[oweals/openwrt.git] / target / linux / generic / hack-4.9 / 221-module_exports.patch
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 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
15 index 83784d9492b1..189b5c7a0758 100644
16 --- a/include/asm-generic/vmlinux.lds.h
17 +++ b/include/asm-generic/vmlinux.lds.h
18 @@ -54,6 +54,16 @@
19  #define LOAD_OFFSET 0
20  #endif
21  
22 +#ifndef SYMTAB_KEEP
23 +#define SYMTAB_KEEP KEEP(*(SORT(___ksymtab+*)))
24 +#define SYMTAB_KEEP_GPL KEEP(*(SORT(___ksymtab_gpl+*)))
25 +#endif
26 +
27 +#ifndef SYMTAB_DISCARD
28 +#define SYMTAB_DISCARD
29 +#define SYMTAB_DISCARD_GPL
30 +#endif
31 +
32  #include <linux/export.h>
33  
34  /* Align . to a 8 byte boundary equals to maximum function alignment. */
35 @@ -329,14 +339,14 @@
36         /* Kernel symbol table: Normal symbols */                       \
37         __ksymtab         : AT(ADDR(__ksymtab) - LOAD_OFFSET) {         \
38                 VMLINUX_SYMBOL(__start___ksymtab) = .;                  \
39 -               KEEP(*(SORT(___ksymtab+*)))                             \
40 +               SYMTAB_KEEP                                             \
41                 VMLINUX_SYMBOL(__stop___ksymtab) = .;                   \
42         }                                                               \
43                                                                         \
44         /* Kernel symbol table: GPL-only symbols */                     \
45         __ksymtab_gpl     : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) {     \
46                 VMLINUX_SYMBOL(__start___ksymtab_gpl) = .;              \
47 -               KEEP(*(SORT(___ksymtab_gpl+*)))                         \
48 +               SYMTAB_KEEP_GPL                                         \
49                 VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .;               \
50         }                                                               \
51                                                                         \
52 @@ -398,7 +408,7 @@
53                                                                         \
54         /* Kernel symbol table: strings */                              \
55          __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) {        \
56 -               *(__ksymtab_strings)                                    \
57 +               *(__ksymtab_strings+*)                                  \
58         }                                                               \
59                                                                         \
60         /* __*init sections */                                          \
61 @@ -749,6 +759,8 @@
62         EXIT_TEXT                                                       \
63         EXIT_DATA                                                       \
64         EXIT_CALL                                                       \
65 +       SYMTAB_DISCARD                                                  \
66 +       SYMTAB_DISCARD_GPL                                              \
67         *(.discard)                                                     \
68         *(.discard.*)                                                   \
69         }
70 diff --git a/include/linux/export.h b/include/linux/export.h
71 index 2a0f61fbc731..889331d9643d 100644
72 --- a/include/linux/export.h
73 +++ b/include/linux/export.h
74 @@ -53,12 +53,19 @@ extern struct module __this_module;
75  #define __CRC_SYMBOL(sym, sec)
76  #endif
77  
78 +#ifdef MODULE
79 +#define __EXPORT_SUFFIX(sym)
80 +#else
81 +#define __EXPORT_SUFFIX(sym) "+" #sym
82 +#endif
83 +
84  /* For every exported symbol, place a struct in the __ksymtab section */
85  #define ___EXPORT_SYMBOL(sym, sec)                                     \
86         extern typeof(sym) sym;                                         \
87         __CRC_SYMBOL(sym, sec)                                          \
88         static const char __kstrtab_##sym[]                             \
89 -       __attribute__((section("__ksymtab_strings"), aligned(1)))       \
90 +       __attribute__((section("__ksymtab_strings"                      \
91 +         __EXPORT_SUFFIX(sym)), aligned(1)))                           \
92         = VMLINUX_SYMBOL_STR(sym);                                      \
93         static const struct kernel_symbol __ksymtab_##sym               \
94         __used                                                          \
95 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
96 index 108d73273788..76a0e450123c 100644
97 --- a/scripts/Makefile.build
98 +++ b/scripts/Makefile.build
99 @@ -398,7 +398,7 @@ targets += $(extra-y) $(MAKECMDGOALS) $(always)
100  # Linker scripts preprocessor (.lds.S -> .lds)
101  # ---------------------------------------------------------------------------
102  quiet_cmd_cpp_lds_S = LDS     $@
103 -      cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
104 +      cmd_cpp_lds_S = $(CPP) $(EXTRA_LDSFLAGS) $(cpp_flags) -P -C -U$(ARCH) \
105                              -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
106  
107  $(obj)/%.lds: $(src)/%.lds.S FORCE
108 -- 
109 2.11.0
110