kernel: add missing patch
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 203-kallsyms_uncompressed.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: kernel: add a config option for keeping the kallsyms table uncompressed, saving ~9kb kernel size after lzma on ar71xx
3
4 [john@phrozen.org: added to my upstream queue 30.12.2016]
5 lede-commit: e0e3509b5ce2ccf93d4d67ea907613f5f7ec2eed
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8  init/Kconfig            | 11 +++++++++++
9  kernel/kallsyms.c       |  8 ++++++++
10  scripts/kallsyms.c      | 12 ++++++++++++
11  scripts/link-vmlinux.sh |  4 ++++
12  4 files changed, 35 insertions(+)
13
14 diff --git a/init/Kconfig b/init/Kconfig
15 index 34407f15e6d3..9063c81b9665 100644
16 --- a/init/Kconfig
17 +++ b/init/Kconfig
18 @@ -1370,6 +1370,17 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
19           the unaligned access emulation.
20           see arch/parisc/kernel/unaligned.c for reference
21  
22 +config KALLSYMS_UNCOMPRESSED
23 +       bool "Keep kallsyms uncompressed"
24 +       depends on KALLSYMS
25 +       help
26 +               Normally kallsyms contains compressed symbols (using a token table),
27 +               reducing the uncompressed kernel image size. Keeping the symbol table
28 +               uncompressed significantly improves the size of this part in compressed
29 +               kernel images.
30 +
31 +               Say N unless you need compressed kernel images to be small.
32 +
33  config HAVE_PCSPKR_PLATFORM
34         bool
35  
36 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
37 index fafd1a3ef0da..abe49579212f 100644
38 --- a/kernel/kallsyms.c
39 +++ b/kernel/kallsyms.c
40 @@ -113,6 +113,11 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
41          * For every byte on the compressed symbol data, copy the table
42          * entry for that byte.
43          */
44 +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
45 +       memcpy(result, data + 1, len - 1);
46 +       result += len - 1;
47 +       len = 0;
48 +#endif
49         while (len) {
50                 tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
51                 data++;
52 @@ -145,6 +150,9 @@ static unsigned int kallsyms_expand_symbol(unsigned int off,
53   */
54  static char kallsyms_get_symbol_type(unsigned int off)
55  {
56 +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
57 +       return kallsyms_names[off + 1];
58 +#endif
59         /*
60          * Get just the first code, look it up in the token table,
61          * and return the first char from this token.
62 diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
63 index 1f22a186c18c..e7f0f19e39a9 100644
64 --- a/scripts/kallsyms.c
65 +++ b/scripts/kallsyms.c
66 @@ -61,6 +61,7 @@ static struct addr_range percpu_range = {
67  static struct sym_entry *table;
68  static unsigned int table_size, table_cnt;
69  static int all_symbols = 0;
70 +static int uncompressed = 0;
71  static int absolute_percpu = 0;
72  static char symbol_prefix_char = '\0';
73  static int base_relative = 0;
74 @@ -446,6 +447,9 @@ static void write_src(void)
75  
76         free(markers);
77  
78 +       if (uncompressed)
79 +               return;
80 +
81         output_label("kallsyms_token_table");
82         off = 0;
83         for (i = 0; i < 256; i++) {
84 @@ -504,6 +508,9 @@ static void *find_token(unsigned char *str, int len, unsigned char *token)
85  {
86         int i;
87  
88 +       if (uncompressed)
89 +               return NULL;
90 +
91         for (i = 0; i < len - 1; i++) {
92                 if (str[i] == token[0] && str[i+1] == token[1])
93                         return &str[i];
94 @@ -576,6 +583,9 @@ static void optimize_result(void)
95  {
96         int i, best;
97  
98 +       if (uncompressed)
99 +               return;
100 +
101         /* using the '\0' symbol last allows compress_symbols to use standard
102          * fast string functions */
103         for (i = 255; i >= 0; i--) {
104 @@ -764,6 +774,8 @@ int main(int argc, char **argv)
105                                 symbol_prefix_char = *p;
106                         } else if (strcmp(argv[i], "--base-relative") == 0)
107                                 base_relative = 1;
108 +                       else if (strcmp(argv[i], "--uncompressed") == 0)
109 +                               uncompressed = 1;
110                         else
111                                 usage();
112                 }
113 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
114 index f742c65108b9..6aabf1d71bb6 100755
115 --- a/scripts/link-vmlinux.sh
116 +++ b/scripts/link-vmlinux.sh
117 @@ -136,6 +136,10 @@ kallsyms()
118                 kallsymopt="${kallsymopt} --base-relative"
119         fi
120  
121 +       if [ -n "${CONFIG_KALLSYMS_UNCOMPRESSED}" ]; then
122 +               kallsymopt="${kallsymopt} --uncompressed"
123 +       fi
124 +
125         local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL}               \
126                       ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
127  
128 -- 
129 2.11.0
130