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 @@ -1081,6 +1081,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 @@ -108,6 +108,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 @@ -140,6 +145,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 @@ -61,6 +61,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 char symbol_prefix_char = '\0';
67 static int base_relative = 0;
68 @@ -457,6 +458,9 @@ static void write_src(void)
75 output_label("kallsyms_token_table");
77 for (i = 0; i < 256; i++) {
78 @@ -515,6 +519,9 @@ static void *find_token(unsigned char *s
85 for (i = 0; i < len - 1; i++) {
86 if (str[i] == token[0] && str[i+1] == token[1])
88 @@ -587,6 +594,9 @@ static void optimize_result(void)
95 /* using the '\0' symbol last allows compress_symbols to use standard
96 * fast string functions */
97 for (i = 255; i >= 0; i--) {
98 @@ -775,6 +785,8 @@ int main(int argc, char **argv)
99 symbol_prefix_char = *p;
100 } else if (strcmp(argv[i], "--base-relative") == 0)
102 + else if (strcmp(argv[i], "--uncompressed") == 0)
107 --- a/scripts/link-vmlinux.sh
108 +++ b/scripts/link-vmlinux.sh
109 @@ -164,6 +164,10 @@ kallsyms()
110 kallsymopt="${kallsymopt} --base-relative"
113 + if [ -n "${CONFIG_KALLSYMS_UNCOMPRESSED}" ]; then
114 + kallsymopt="${kallsymopt} --uncompressed"
117 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
118 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"