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
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>
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(+)
16 @@ -1451,6 +1451,17 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
17 the unaligned access emulation.
18 see arch/parisc/kernel/unaligned.c for reference
20 +config KALLSYMS_UNCOMPRESSED
21 + bool "Keep kallsyms uncompressed"
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
29 + Say N unless you need compressed kernel images to be small.
31 config HAVE_PCSPKR_PLATFORM
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.
40 +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
41 + memcpy(result, data + 1, len - 1);
46 tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
48 @@ -101,6 +106,9 @@ tail:
50 static char kallsyms_get_symbol_type(unsigned int off)
52 +#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
53 + return kallsyms_names[off + 1];
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;
68 @@ -453,13 +454,15 @@ static void write_src(void)
73 - * Now that we wrote out the compressed symbol names, restore the
74 - * original names, which are needed in some of the later steps.
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) {
81 + * Now that we wrote out the compressed symbol names, restore the
82 + * original names, which are needed in some of the later steps.
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);
90 output_label("kallsyms_markers");
91 @@ -469,20 +472,22 @@ static void write_src(void)
95 - output_label("kallsyms_token_table");
97 - for (i = 0; i < 256; i++) {
99 - expand_symbol(best_table[i], best_table_len[i], buf);
100 - printf("\t.asciz\t\"%s\"\n", buf);
101 - off += strlen(buf) + 1;
104 + if (!uncompressed) {
105 + output_label("kallsyms_token_table");
107 + for (i = 0; i < 256; i++) {
109 + expand_symbol(best_table[i], best_table_len[i], buf);
110 + printf("\t.asciz\t\"%s\"\n", buf);
111 + off += strlen(buf) + 1;
115 - output_label("kallsyms_token_index");
116 - for (i = 0; i < 256; i++)
117 - printf("\t.short\t%d\n", best_idx[i]);
119 + output_label("kallsyms_token_index");
120 + for (i = 0; i < 256; i++)
121 + printf("\t.short\t%d\n", best_idx[i]);
126 output_label("kallsyms_addresses");
127 @@ -582,6 +587,9 @@ static unsigned char *find_token(unsigne
134 for (i = 0; i < len - 1; i++) {
135 if (str[i] == token[0] && str[i+1] == token[1])
137 @@ -654,6 +662,9 @@ static void optimize_result(void)
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, <o_clang, 1},
151 + {"uncompressed", no_argument, &uncompressed, 1},
155 --- a/scripts/link-vmlinux.sh
156 +++ b/scripts/link-vmlinux.sh
157 @@ -165,6 +165,10 @@ kallsyms()
158 kallsymopt="${kallsymopt} --lto-clang"
161 + if is_enabled CONFIG_KALLSYMS_UNCOMPRESSED; then
162 + kallsymopt="${kallsymopt} --uncompressed"
166 scripts/kallsyms ${kallsymopt} ${1} > ${2}