ramips: add support for ELECOM WMC-S1267GS2
[openwrt/openwrt.git] / target / linux / generic / pending-6.6 / 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 @@ -1451,6 +1451,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 @@ -62,6 +62,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 @@ -453,13 +454,15 @@ static void write_src(void)
69 }
70 printf("\n");
71
72 - /*
73 - * Now that we wrote out the compressed symbol names, restore the
74 - * original names, which are needed in some of the later steps.
75 - */
76 - for (i = 0; i < table_cnt; i++) {
77 - expand_symbol(table[i]->sym, table[i]->len, buf);
78 - strcpy((char *)table[i]->sym, buf);
79 + if (!uncompressed) {
80 + /*
81 + * Now that we wrote out the compressed symbol names, restore the
82 + * original names, which are needed in some of the later steps.
83 + */
84 + for (i = 0; i < table_cnt; i++) {
85 + expand_symbol(table[i]->sym, table[i]->len, buf);
86 + strcpy((char *)table[i]->sym, buf);
87 + }
88 }
89
90 output_label("kallsyms_markers");
91 @@ -469,20 +472,22 @@ static void write_src(void)
92
93 free(markers);
94
95 - output_label("kallsyms_token_table");
96 - off = 0;
97 - for (i = 0; i < 256; i++) {
98 - best_idx[i] = off;
99 - expand_symbol(best_table[i], best_table_len[i], buf);
100 - printf("\t.asciz\t\"%s\"\n", buf);
101 - off += strlen(buf) + 1;
102 - }
103 - printf("\n");
104 + if (!uncompressed) {
105 + output_label("kallsyms_token_table");
106 + off = 0;
107 + for (i = 0; i < 256; i++) {
108 + best_idx[i] = off;
109 + expand_symbol(best_table[i], best_table_len[i], buf);
110 + printf("\t.asciz\t\"%s\"\n", buf);
111 + off += strlen(buf) + 1;
112 + }
113 + printf("\n");
114
115 - output_label("kallsyms_token_index");
116 - for (i = 0; i < 256; i++)
117 - printf("\t.short\t%d\n", best_idx[i]);
118 - printf("\n");
119 + output_label("kallsyms_token_index");
120 + for (i = 0; i < 256; i++)
121 + printf("\t.short\t%d\n", best_idx[i]);
122 + printf("\n");
123 + }
124
125 if (!base_relative)
126 output_label("kallsyms_addresses");
127 @@ -582,6 +587,9 @@ static unsigned char *find_token(unsigne
128 {
129 int i;
130
131 + if (uncompressed)
132 + return NULL;
133 +
134 for (i = 0; i < len - 1; i++) {
135 if (str[i] == token[0] && str[i+1] == token[1])
136 return &str[i];
137 @@ -654,6 +662,9 @@ static void optimize_result(void)
138 {
139 int i, best;
140
141 + if (uncompressed)
142 + return;
143 +
144 /* using the '\0' symbol last allows compress_symbols to use standard
145 * fast string functions */
146 for (i = 255; i >= 0; i--) {
147 @@ -815,6 +826,7 @@ int main(int argc, char **argv)
148 {"absolute-percpu", no_argument, &absolute_percpu, 1},
149 {"base-relative", no_argument, &base_relative, 1},
150 {"lto-clang", no_argument, &lto_clang, 1},
151 + {"uncompressed", no_argument, &uncompressed, 1},
152 {},
153 };
154
155 --- a/scripts/link-vmlinux.sh
156 +++ b/scripts/link-vmlinux.sh
157 @@ -165,6 +165,10 @@ kallsyms()
158 kallsymopt="${kallsymopt} --lto-clang"
159 fi
160
161 + if is_enabled CONFIG_KALLSYMS_UNCOMPRESSED; then
162 + kallsymopt="${kallsymopt} --uncompressed"
163 + fi
164 +
165 info KSYMS ${2}
166 scripts/kallsyms ${kallsymopt} ${1} > ${2}
167 }