[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230308115243.82592-6-masahiroy@kernel.org>
Date: Wed, 8 Mar 2023 20:52:41 +0900
From: Masahiro Yamada <masahiroy@...nel.org>
To: linux-kbuild@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
Zhen Lei <thunder.leizhen@...wei.com>,
Arnd Bergmann <arnd@...db.de>,
Masahiro Yamada <masahiroy@...nel.org>
Subject: [PATCH 6/8] scripts/kallsyms: change the output order
Currently, this tool outputs symbol data in the following order.
(1) kallsyms_addressed / kallsyms_offsets
(2) kallsyms_relative_base
(3) kallsyms_num_syms
(4) kallsyms_names
(5) kallsyms_markers
(6) kallsyms_seq_of_names
(7) kallsyms_token_table
(8) kallsyms_token_index
This commit changes the order as follows:
(1) kallsyms_num_syms
(2) kallsyms_names
(3) kallsyms_markers
(4) kallsyms_token_table
(5) kallsyms_token_index
(6) kallsyms_addressed / kallsyms_offsets
(7) kallsyms_relative_base
(8) kallsyms_seq_of_names
The motivation is to decrease the number of function calls to
expand_symbol() and cleanup_symbol_name().
The compressed names are only required for writing 'kallsyms_names'.
If you do this first, we can restore the original symbol names.
You do not need to repeat the same operation over again.
The actual refactoring will happen in the next commit.
Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
---
scripts/kallsyms.c | 118 ++++++++++++++++++++++-----------------------
1 file changed, 59 insertions(+), 59 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 97d514c0fc8f..5996f1e61bcf 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -412,56 +412,6 @@ static void write_src(void)
printf("\t.section .rodata, \"a\"\n");
- if (!base_relative)
- output_label("kallsyms_addresses");
- else
- output_label("kallsyms_offsets");
-
- for (i = 0; i < table_cnt; i++) {
- if (base_relative) {
- /*
- * Use the offset relative to the lowest value
- * encountered of all relative symbols, and emit
- * non-relocatable fixed offsets that will be fixed
- * up at runtime.
- */
-
- long long offset;
- int overflow;
-
- if (!absolute_percpu) {
- offset = table[i]->addr - relative_base;
- overflow = (offset < 0 || offset > UINT_MAX);
- } else if (symbol_absolute(table[i])) {
- offset = table[i]->addr;
- overflow = (offset < 0 || offset > INT_MAX);
- } else {
- offset = relative_base - table[i]->addr - 1;
- overflow = (offset < INT_MIN || offset >= 0);
- }
- if (overflow) {
- fprintf(stderr, "kallsyms failure: "
- "%s symbol value %#llx out of range in relative mode\n",
- symbol_absolute(table[i]) ? "absolute" : "relative",
- table[i]->addr);
- exit(EXIT_FAILURE);
- }
- expand_symbol(table[i]->sym, table[i]->len, buf);
- printf("\t.long\t%#x /* %s */\n", (int)offset, buf);
- } else if (!symbol_absolute(table[i])) {
- output_address(table[i]->addr);
- } else {
- printf("\tPTR\t%#llx\n", table[i]->addr);
- }
- }
- printf("\n");
-
- if (base_relative) {
- output_label("kallsyms_relative_base");
- output_address(relative_base);
- printf("\n");
- }
-
output_label("kallsyms_num_syms");
printf("\t.long\t%u\n", table_cnt);
printf("\n");
@@ -521,15 +471,6 @@ static void write_src(void)
free(markers);
- sort_symbols_by_name();
- output_label("kallsyms_seqs_of_names");
- for (i = 0; i < table_cnt; i++)
- printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
- (unsigned char)(table[i]->seq >> 16),
- (unsigned char)(table[i]->seq >> 8),
- (unsigned char)(table[i]->seq >> 0));
- printf("\n");
-
output_label("kallsyms_token_table");
off = 0;
for (i = 0; i < 256; i++) {
@@ -544,6 +485,65 @@ static void write_src(void)
for (i = 0; i < 256; i++)
printf("\t.short\t%d\n", best_idx[i]);
printf("\n");
+
+ if (!base_relative)
+ output_label("kallsyms_addresses");
+ else
+ output_label("kallsyms_offsets");
+
+ for (i = 0; i < table_cnt; i++) {
+ if (base_relative) {
+ /*
+ * Use the offset relative to the lowest value
+ * encountered of all relative symbols, and emit
+ * non-relocatable fixed offsets that will be fixed
+ * up at runtime.
+ */
+
+ long long offset;
+ int overflow;
+
+ if (!absolute_percpu) {
+ offset = table[i]->addr - relative_base;
+ overflow = (offset < 0 || offset > UINT_MAX);
+ } else if (symbol_absolute(table[i])) {
+ offset = table[i]->addr;
+ overflow = (offset < 0 || offset > INT_MAX);
+ } else {
+ offset = relative_base - table[i]->addr - 1;
+ overflow = (offset < INT_MIN || offset >= 0);
+ }
+ if (overflow) {
+ fprintf(stderr, "kallsyms failure: "
+ "%s symbol value %#llx out of range in relative mode\n",
+ symbol_absolute(table[i]) ? "absolute" : "relative",
+ table[i]->addr);
+ exit(EXIT_FAILURE);
+ }
+ expand_symbol(table[i]->sym, table[i]->len, buf);
+ printf("\t.long\t%#x /* %s */\n", (int)offset, buf);
+ } else if (!symbol_absolute(table[i])) {
+ output_address(table[i]->addr);
+ } else {
+ printf("\tPTR\t%#llx\n", table[i]->addr);
+ }
+ }
+ printf("\n");
+
+ if (base_relative) {
+ output_label("kallsyms_relative_base");
+ output_address(relative_base);
+ printf("\n");
+ }
+
+ sort_symbols_by_name();
+ output_label("kallsyms_seqs_of_names");
+ for (i = 0; i < table_cnt; i++)
+ printf("\t.byte 0x%02x, 0x%02x, 0x%02x\n",
+ (unsigned char)(table[i]->seq >> 16),
+ (unsigned char)(table[i]->seq >> 8),
+ (unsigned char)(table[i]->seq >> 0));
+ printf("\n");
}
--
2.34.1
Powered by blists - more mailing lists