kernel: bump 5.4 to 5.4.48
[oweals/openwrt.git] / target / linux / generic / pending-5.4 / 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 --- a/init/Kconfig
15 +++ b/init/Kconfig
16 @@ -1277,6 +1277,17 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
17           the unaligned access emulation.
18           see arch/parisc/kernel/unaligned.c for reference
19  
20 +config KALLSYMS_UNCOMPRESSED
21 +       bool "Keep kallsyms uncompressed"
22 +       depends on KALLSYMS
23 +       help
24 +               Normally kallsyms contains compressed symbols (using a token table),
25 +               reducing the uncompressed kernel image size. Keeping the symbol table
26 +               uncompressed significantly improves the size of this part in compressed
27 +               kernel images.
28 +
29 +               Say N unless you need compressed kernel images to be small.
30 +
31  config HAVE_PCSPKR_PLATFORM
32         bool
33  
34 --- a/kernel/kallsyms.c
35 +++ b/kernel/kallsyms.c
36 @@ -75,6 +75,11 @@ static unsigned int kallsyms_expand_symb
37          * For every byte on the compressed symbol data, copy the table
38          * entry for that byte.
39          */
40 +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
41 +       memcpy(result, data + 1, len - 1);
42 +       result += len - 1;
43 +       len = 0;
44 +#endif
45         while (len) {
46                 tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
47                 data++;
48 @@ -107,6 +112,9 @@ tail:
49   */
50  static char kallsyms_get_symbol_type(unsigned int off)
51  {
52 +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
53 +       return kallsyms_names[off + 1];
54 +#endif
55         /*
56          * Get just the first code, look it up in the token table,
57          * and return the first char from this token.
58 --- a/scripts/kallsyms.c
59 +++ b/scripts/kallsyms.c
60 @@ -59,6 +59,7 @@ static struct addr_range percpu_range =
61  static struct sym_entry *table;
62  static unsigned int table_size, table_cnt;
63  static int all_symbols = 0;
64 +static int uncompressed = 0;
65  static int absolute_percpu = 0;
66  static int base_relative = 0;
67  
68 @@ -440,6 +441,9 @@ static void write_src(void)
69  
70         free(markers);
71  
72 +       if (uncompressed)
73 +               return;
74 +
75         output_label("kallsyms_token_table");
76         off = 0;
77         for (i = 0; i < 256; i++) {
78 @@ -500,6 +504,9 @@ static void *find_token(unsigned char *s
79  {
80         int i;
81  
82 +       if (uncompressed)
83 +               return NULL;
84 +
85         for (i = 0; i < len - 1; i++) {
86                 if (str[i] == token[0] && str[i+1] == token[1])
87                         return &str[i];
88 @@ -572,6 +579,9 @@ static void optimize_result(void)
89  {
90         int i, best;
91  
92 +       if (uncompressed)
93 +               return;
94 +
95         /* using the '\0' symbol last allows compress_symbols to use standard
96          * fast string functions */
97         for (i = 255; i >= 0; i--) {
98 @@ -751,6 +761,8 @@ int main(int argc, char **argv)
99                                 absolute_percpu = 1;
100                         else if (strcmp(argv[i], "--base-relative") == 0)
101                                 base_relative = 1;
102 +                       else if (strcmp(argv[i], "--uncompressed") == 0)
103 +                               uncompressed = 1;
104                         else
105                                 usage();
106                 }
107 --- a/scripts/link-vmlinux.sh
108 +++ b/scripts/link-vmlinux.sh
109 @@ -160,6 +160,10 @@ kallsyms()
110                 kallsymopt="${kallsymopt} --base-relative"
111         fi
112  
113 +       if [ -n "${CONFIG_KALLSYMS_UNCOMPRESSED}" ]; then
114 +               kallsymopt="${kallsymopt} --uncompressed"
115 +       fi
116 +
117         local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL}               \
118                       ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
119