public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Zhen Lei <thunder.leizhen@huawei.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 6/8] scripts/kallsyms: change the output order
Date: Wed,  8 Mar 2023 20:52:41 +0900	[thread overview]
Message-ID: <20230308115243.82592-6-masahiroy@kernel.org> (raw)
In-Reply-To: <20230308115243.82592-1-masahiroy@kernel.org>

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@kernel.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


  parent reply	other threads:[~2023-03-08 11:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 11:52 [PATCH 1/8] scripts/kallsyms: remove redundant code for omitting U and N Masahiro Yamada
2023-03-08 11:52 ` [PATCH 2/8] scripts/mksysmap: remove comments described in nm(1) Masahiro Yamada
2023-04-07 18:46   ` Nick Desaulniers
2023-04-10  9:38     ` Masahiro Yamada
2023-03-08 11:52 ` [PATCH 3/8] scripts/mksysmap: use sed with in-line comments Masahiro Yamada
2023-04-07 18:59   ` Nick Desaulniers
2023-04-07 19:01     ` Nick Desaulniers
2023-04-08 15:01       ` Masahiro Yamada
2023-04-08 14:29     ` Masahiro Yamada
2023-04-10  9:38       ` Masahiro Yamada
2023-03-08 11:52 ` [PATCH 4/8] scripts/kallsyms: exclude symbols generated by itself dynamically Masahiro Yamada
2023-04-07 20:12   ` Nick Desaulniers
2023-04-10  9:38     ` Masahiro Yamada
2023-03-08 11:52 ` [PATCH 5/8] scripts/kallsyms: move compiler-generated symbol patterns to mksysmap Masahiro Yamada
2023-04-07 20:16   ` Nick Desaulniers
2023-03-08 11:52 ` Masahiro Yamada [this message]
2023-03-08 11:52 ` [PATCH 7/8] scripts/kallsyms: decrease expand_symbol() / cleanup_symbol_name() calls Masahiro Yamada
2023-03-08 11:52 ` [PATCH 8/8] scripts/kallsyms: update the usage in the comment block Masahiro Yamada
2023-04-07 20:25   ` Nick Desaulniers
2023-04-07 18:53 ` [PATCH 1/8] scripts/kallsyms: remove redundant code for omitting U and N Nick Desaulniers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308115243.82592-6-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thunder.leizhen@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox