summaryrefslogtreecommitdiffstats
path: root/target/linux/generic/pending-6.6/203-kallsyms_uncompressed.patch
blob: c23811ed3987e495659ae1be94f5465c2d82ca67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
From: Felix Fietkau <nbd@nbd.name>
Subject: kernel: add a config option for keeping the kallsyms table uncompressed, saving ~9kb kernel size after lzma on ar71xx

[john@phrozen.org: added to my upstream queue 30.12.2016]
lede-commit: e0e3509b5ce2ccf93d4d67ea907613f5f7ec2eed
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 init/Kconfig            | 11 +++++++++++
 kernel/kallsyms.c       |  8 ++++++++
 scripts/kallsyms.c      | 12 ++++++++++++
 scripts/link-vmlinux.sh |  4 ++++
 4 files changed, 35 insertions(+)

--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1451,6 +1451,17 @@ config SYSCTL_ARCH_UNALIGN_ALLOW
 	  the unaligned access emulation.
 	  see arch/parisc/kernel/unaligned.c for reference
 
+config KALLSYMS_UNCOMPRESSED
+	bool "Keep kallsyms uncompressed"
+	depends on KALLSYMS
+	help
+		Normally kallsyms contains compressed symbols (using a token table),
+		reducing the uncompressed kernel image size. Keeping the symbol table
+		uncompressed significantly improves the size of this part in compressed
+		kernel images.
+
+		Say N unless you need compressed kernel images to be small.
+
 config HAVE_PCSPKR_PLATFORM
 	bool
 
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -69,6 +69,11 @@ static unsigned int kallsyms_expand_symb
 	 * For every byte on the compressed symbol data, copy the table
 	 * entry for that byte.
 	 */
+#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
+	memcpy(result, data + 1, len - 1);
+	result += len - 1;
+	len = 0;
+#endif
 	while (len) {
 		tptr = &kallsyms_token_table[kallsyms_token_index[*data]];
 		data++;
@@ -101,6 +106,9 @@ tail:
  */
 static char kallsyms_get_symbol_type(unsigned int off)
 {
+#ifdef CONFIG_KALLSYMS_UNCOMPRESSED
+	return kallsyms_names[off + 1];
+#endif
 	/*
 	 * Get just the first code, look it up in the token table,
 	 * and return the first char from this token.
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -62,6 +62,7 @@ static struct addr_range percpu_range =
 static struct sym_entry **table;
 static unsigned int table_size, table_cnt;
 static int all_symbols;
+static int uncompressed;
 static int absolute_percpu;
 static int base_relative;
 static int lto_clang;
@@ -453,13 +454,15 @@ static void write_src(void)
 	}
 	printf("\n");
 
-	/*
-	 * Now that we wrote out the compressed symbol names, restore the
-	 * original names, which are needed in some of the later steps.
-	 */
-	for (i = 0; i < table_cnt; i++) {
-		expand_symbol(table[i]->sym, table[i]->len, buf);
-		strcpy((char *)table[i]->sym, buf);
+	if (!uncompressed) {
+		/*
+		 * Now that we wrote out the compressed symbol names, restore the
+		 * original names, which are needed in some of the later steps.
+		 */
+		for (i = 0; i < table_cnt; i++) {
+			expand_symbol(table[i]->sym, table[i]->len, buf);
+			strcpy((char *)table[i]->sym, buf);
+		}
 	}
 
 	output_label("kallsyms_markers");
@@ -469,20 +472,22 @@ static void write_src(void)
 
 	free(markers);
 
-	output_label("kallsyms_token_table");
-	off = 0;
-	for (i = 0; i < 256; i++) {
-		best_idx[i] = off;
-		expand_symbol(best_table[i], best_table_len[i], buf);
-		printf("\t.asciz\t\"%s\"\n", buf);
-		off += strlen(buf) + 1;
-	}
-	printf("\n");
+	if (!uncompressed) {
+		output_label("kallsyms_token_table");
+		off = 0;
+		for (i = 0; i < 256; i++) {
+			best_idx[i] = off;
+			expand_symbol(best_table[i], best_table_len[i], buf);
+			printf("\t.asciz\t\"%s\"\n", buf);
+			off += strlen(buf) + 1;
+		}
+		printf("\n");
 
-	output_label("kallsyms_token_index");
-	for (i = 0; i < 256; i++)
-		printf("\t.short\t%d\n", best_idx[i]);
-	printf("\n");
+		output_label("kallsyms_token_index");
+		for (i = 0; i < 256; i++)
+			printf("\t.short\t%d\n", best_idx[i]);
+		printf("\n");
+	}
 
 	if (!base_relative)
 		output_label("kallsyms_addresses");
@@ -582,6 +587,9 @@ static unsigned char *find_token(unsigne
 {
 	int i;
 
+	if (uncompressed)
+		return NULL;
+
 	for (i = 0; i < len - 1; i++) {
 		if (str[i] == token[0] && str[i+1] == token[1])
 			return &str[i];
@@ -654,6 +662,9 @@ static void optimize_result(void)
 {
 	int i, best;
 
+	if (uncompressed)
+		return;
+
 	/* using the '\0' symbol last allows compress_symbols to use standard
 	 * fast string functions */
 	for (i = 255; i >= 0; i--) {
@@ -815,6 +826,7 @@ int main(int argc, char **argv)
 			{"absolute-percpu", no_argument, &absolute_percpu, 1},
 			{"base-relative",   no_argument, &base_relative,   1},
 			{"lto-clang",       no_argument, &lto_clang,       1},
+			{"uncompressed",   no_argument, &uncompressed,   1},
 			{},
 		};
 
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -165,6 +165,10 @@ kallsyms()
 		kallsymopt="${kallsymopt} --lto-clang"
 	fi
 
+	if is_enabled CONFIG_KALLSYMS_UNCOMPRESSED; then
+		kallsymopt="${kallsymopt} --uncompressed"
+	fi
+
 	info KSYMS ${2}
 	scripts/kallsyms ${kallsymopt} ${1} > ${2}
 }