e066ad3cf304855cc998e3f8dac26a60f8aade75
[openwrt/staging/stintel.git] / target / linux / generic / pending-6.1 / 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 @@ -1481,6 +1481,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 @@ -69,6 +69,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 @@ -101,6 +106,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 @@ -77,6 +77,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;
64 +static int uncompressed;
65 static int absolute_percpu;
66 static int base_relative;
67 static int lto_clang;
68 @@ -605,6 +606,9 @@ static void write_src(void)
69 printf("\t.long\t%u\n", table[i]->seq);
70 printf("\n");
71
72 + if (uncompressed)
73 + return;
74 +
75 output_label("kallsyms_token_table");
76 off = 0;
77 for (i = 0; i < 256; i++) {
78 @@ -656,6 +660,9 @@ static unsigned char *find_token(unsigne
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 @@ -728,6 +735,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 @@ -889,6 +899,7 @@ int main(int argc, char **argv)
99 {"absolute-percpu", no_argument, &absolute_percpu, 1},
100 {"base-relative", no_argument, &base_relative, 1},
101 {"lto-clang", no_argument, &lto_clang, 1},
102 + {"uncompressed", no_argument, &uncompressed, 1},
103 {},
104 };
105
106 --- a/scripts/link-vmlinux.sh
107 +++ b/scripts/link-vmlinux.sh
108 @@ -160,6 +160,10 @@ kallsyms()
109 kallsymopt="${kallsymopt} --lto-clang"
110 fi
111
112 + if is_enabled CONFIG_KALLSYMS_UNCOMPRESSED; then
113 + kallsymopt="${kallsymopt} --uncompressed"
114 + fi
115 +
116 info KSYMS ${2}
117 scripts/kallsyms ${kallsymopt} ${1} > ${2}
118 }