linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] mksysmap: update comment about __crc_*
@ 2022-09-26  9:02 Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 2/5] kbuild: reuse mksysmap output for kallsyms Masahiro Yamada
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-09-26  9:02 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, linux-arch, Masahiro Yamada, Michal Marek,
	Nick Desaulniers

Since commit 7b4537199a4a ("kbuild: link symbol CRCs at final link,
removing CONFIG_MODULE_REL_CRCS"), __crc_* symbols never become
absolute.

Keep ignoring __crc_*, but update the comment.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mksysmap | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/mksysmap b/scripts/mksysmap
index ad8bbc52267d..bc5396e255d8 100755
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -37,8 +37,8 @@
 
 # readprofile starts reading symbols when _stext is found, and
 # continue until it finds a symbol which is not either of 'T', 't',
-# 'W' or 'w'. __crc_ are 'A' and placed in the middle
-# so we just ignore them to let readprofile continue to work.
-# (At least sparc64 has __crc_ in the middle).
-
+# 'W' or 'w'.
+#
+# Ignored prefixes:
+#  __crc_               - modversions
 $NM -n $1 | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)\|\( \.L\)\|\( L0\)' > $2
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/5] kbuild: reuse mksysmap output for kallsyms
  2022-09-26  9:02 [PATCH 1/5] mksysmap: update comment about __crc_* Masahiro Yamada
@ 2022-09-26  9:02 ` Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 3/5] kallsyms: drop duplicated ignore patterns from kallsyms.c Masahiro Yamada
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-09-26  9:02 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, linux-arch, Masahiro Yamada, Michal Marek,
	Nick Desaulniers

scripts/mksysmap internally runs ${NM} (dropping some symbols).

When CONFIG_KALLSYMS=y, mksysmap creates .tmp_System.map, but it is
almost the same as the output from the ${NM} invocation in kallsyms().
It is true scripts/mksysmap drops some symbols, but scripts/kallsyms.c
ignores more anyway.

Keep the mksysmap output as *.syms, and reuse it for kallsyms and
'cmp -s'. It saves one ${NM} invocation.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/link-vmlinux.sh | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 23ac13fd9d89..6492c0862657 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -157,7 +157,7 @@ kallsyms()
 	fi
 
 	info KSYMS ${2}
-	${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${2}
+	cat ${1} | scripts/kallsyms ${kallsymopt} > ${2}
 }
 
 # Perform one step in kallsyms generation, including temporary linking of
@@ -170,7 +170,8 @@ kallsyms_step()
 	kallsyms_S=${kallsyms_vmlinux}.S
 
 	vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o}
-	kallsyms ${kallsyms_vmlinux} ${kallsyms_S}
+	mksysmap ${kallsyms_vmlinux} ${kallsyms_vmlinux}.syms
+	kallsyms ${kallsyms_vmlinux}.syms ${kallsyms_S}
 
 	info AS ${kallsyms_S}
 	${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \
@@ -182,6 +183,7 @@ kallsyms_step()
 # See mksymap for additional details
 mksysmap()
 {
+	info NM ${2}
 	${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2}
 }
 
@@ -283,7 +285,6 @@ if is_enabled CONFIG_DEBUG_INFO_BTF && is_enabled CONFIG_BPF; then
 	${RESOLVE_BTFIDS} vmlinux
 fi
 
-info SYSMAP System.map
 mksysmap vmlinux System.map
 
 if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then
@@ -296,9 +297,7 @@ fi
 
 # step a (see comment above)
 if is_enabled CONFIG_KALLSYMS; then
-	mksysmap ${kallsyms_vmlinux} .tmp_System.map
-
-	if ! cmp -s System.map .tmp_System.map; then
+	if ! cmp -s System.map ${kallsyms_vmlinux}.syms; then
 		echo >&2 Inconsistent kallsyms data
 		echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround
 		exit 1
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/5] kallsyms: drop duplicated ignore patterns from kallsyms.c
  2022-09-26  9:02 [PATCH 1/5] mksysmap: update comment about __crc_* Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 2/5] kbuild: reuse mksysmap output for kallsyms Masahiro Yamada
@ 2022-09-26  9:02 ` Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 4/5] kallsyms: take the input file instead of reading stdin Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 5/5] kallsyms: ignore __kstrtab_* and __kstrtabns_* symbols Masahiro Yamada
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-09-26  9:02 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, linux-arch, Masahiro Yamada, Changbin Du,
	Fuad Tabba, Kalesh Singh, Michal Marek, Nick Desaulniers,
	Yuntao Wang

Now that kallsyms.c parses the output from mksysmap, some symbols have
already been dropped.

Move comments to scripts/mksysmap. Also, make the grep command readable.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kallsyms.c |  3 ---
 scripts/mksysmap   | 14 +++++++++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index f18e6dfc68c5..313cc8161123 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -107,9 +107,6 @@ static bool is_ignored_symbol(const char *name, char type)
 
 	/* Symbol names that begin with the following are ignored.*/
 	static const char * const ignored_prefixes[] = {
-		"$",			/* local symbols for ARM, MIPS, etc. */
-		".L",			/* local labels, .LBB,.Ltmpxxx,.L__unnamed_xx,.LASANPC, etc. */
-		"__crc_",		/* modversions */
 		"__efistub_",		/* arm64 EFI stub namespace */
 		"__kvm_nvhe_$",		/* arm64 local symbols in non-VHE KVM namespace */
 		"__kvm_nvhe_.L",	/* arm64 local symbols in non-VHE KVM namespace */
diff --git a/scripts/mksysmap b/scripts/mksysmap
index bc5396e255d8..75f3dfd1c156 100755
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -40,5 +40,17 @@
 # 'W' or 'w'.
 #
 # Ignored prefixes:
+#  $                    - local symbols for ARM, MIPS, etc.
+#  .L                   - local labels, .LBB,.Ltmpxxx,.L__unnamed_xx,.LASANPC, etc.
 #  __crc_               - modversions
-$NM -n $1 | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)\|\( \.L\)\|\( L0\)' > $2
+#
+# Ignored symbols:
+#  L0                   - for LoongArch?
+
+$NM -n $1 | grep -v		\
+	-e ' [aNUw] '		\
+	-e ' \$'		\
+	-e ' \.L'		\
+	-e ' __crc_'		\
+	-e ' L0$'		\
+> $2
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/5] kallsyms: take the input file instead of reading stdin
  2022-09-26  9:02 [PATCH 1/5] mksysmap: update comment about __crc_* Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 2/5] kbuild: reuse mksysmap output for kallsyms Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 3/5] kallsyms: drop duplicated ignore patterns from kallsyms.c Masahiro Yamada
@ 2022-09-26  9:02 ` Masahiro Yamada
  2022-09-26  9:02 ` [PATCH 5/5] kallsyms: ignore __kstrtab_* and __kstrtabns_* symbols Masahiro Yamada
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-09-26  9:02 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, linux-arch, Masahiro Yamada, Changbin Du,
	Fuad Tabba, Kalesh Singh, Michal Marek, Nick Desaulniers,
	Yuntao Wang

This gets rid of the pipe operator connected with 'cat'.

Also use getopt_long() to parse the command line.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/kallsyms.c      | 51 ++++++++++++++++++++++++++---------------
 scripts/link-vmlinux.sh |  2 +-
 2 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 313cc8161123..5b091625d4c5 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -18,6 +18,7 @@
  *
  */
 
+#include <getopt.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -71,7 +72,7 @@ static unsigned char best_table_len[256];
 static void usage(void)
 {
 	fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] "
-			"[--base-relative] < in.map > out.S\n");
+			"[--base-relative] in.map > out.S\n");
 	exit(1);
 }
 
@@ -310,12 +311,19 @@ static void shrink_table(void)
 	}
 }
 
-static void read_map(FILE *in)
+static void read_map(const char *in)
 {
+	FILE *fp;
 	struct sym_entry *sym;
 
-	while (!feof(in)) {
-		sym = read_symbol(in);
+	fp = fopen(in, "r");
+	if (!fp) {
+		perror(in);
+		exit(1);
+	}
+
+	while (!feof(fp)) {
+		sym = read_symbol(fp);
 		if (!sym)
 			continue;
 
@@ -326,12 +334,15 @@ static void read_map(FILE *in)
 			table = realloc(table, sizeof(*table) * table_size);
 			if (!table) {
 				fprintf(stderr, "out of memory\n");
+				fclose(fp);
 				exit (1);
 			}
 		}
 
 		table[table_cnt++] = sym;
 	}
+
+	fclose(fp);
 }
 
 static void output_label(const char *label)
@@ -762,22 +773,26 @@ static void record_relative_base(void)
 
 int main(int argc, char **argv)
 {
-	if (argc >= 2) {
-		int i;
-		for (i = 1; i < argc; i++) {
-			if(strcmp(argv[i], "--all-symbols") == 0)
-				all_symbols = 1;
-			else if (strcmp(argv[i], "--absolute-percpu") == 0)
-				absolute_percpu = 1;
-			else if (strcmp(argv[i], "--base-relative") == 0)
-				base_relative = 1;
-			else
-				usage();
-		}
-	} else if (argc != 1)
+	while (1) {
+		static struct option long_options[] = {
+			{"all-symbols",     no_argument, &all_symbols,     1},
+			{"absolute-percpu", no_argument, &absolute_percpu, 1},
+			{"base-relative",   no_argument, &base_relative,   1},
+			{},
+		};
+
+		int c = getopt_long(argc, argv, "", long_options, NULL);
+
+		if (c == -1)
+			break;
+		if (c != 0)
+			usage();
+	}
+
+	if (optind >= argc)
 		usage();
 
-	read_map(stdin);
+	read_map(argv[optind]);
 	shrink_table();
 	if (absolute_percpu)
 		make_percpus_absolute();
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 6492c0862657..2782c5d1518b 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -157,7 +157,7 @@ kallsyms()
 	fi
 
 	info KSYMS ${2}
-	cat ${1} | scripts/kallsyms ${kallsymopt} > ${2}
+	scripts/kallsyms ${kallsymopt} ${1} > ${2}
 }
 
 # Perform one step in kallsyms generation, including temporary linking of
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 5/5] kallsyms: ignore __kstrtab_* and __kstrtabns_* symbols
  2022-09-26  9:02 [PATCH 1/5] mksysmap: update comment about __crc_* Masahiro Yamada
                   ` (2 preceding siblings ...)
  2022-09-26  9:02 ` [PATCH 4/5] kallsyms: take the input file instead of reading stdin Masahiro Yamada
@ 2022-09-26  9:02 ` Masahiro Yamada
  3 siblings, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2022-09-26  9:02 UTC (permalink / raw)
  To: linux-kbuild
  Cc: linux-kernel, linux-arch, Masahiro Yamada, Michal Marek,
	Nick Desaulniers

Every EXPORT_SYMBOL creates __kstrtab_* and __kstrtabns_*, which
consumes 15-20% of the kallsyms entries.

For x86_64 defconfig,

  $ cat /proc/kallsyms | wc
     129527    388581   5685465
  $ cat /proc/kallsyms | grep __kstrtab | wc
      23489     70467   1187932

We already ignore __crc_* symbols populated by EXPORT_SYMBOL, so it
should be fine to ignore __kstrtab_* and __kstrtabns_* as well.

This makes vmlinux a bit smaller.

  $ size vmlinux.before vmlinux.after
     text    data     bss     dec     hex filename
  22785374        8559694 1413328 32758396        1f3da7c vmlinux.before
  22785374        8137806 1413328 32336508        1ed6a7c vmlinux.after

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mksysmap | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/mksysmap b/scripts/mksysmap
index 75f3dfd1c156..16a08b8ef2f8 100755
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -43,6 +43,8 @@
 #  $                    - local symbols for ARM, MIPS, etc.
 #  .L                   - local labels, .LBB,.Ltmpxxx,.L__unnamed_xx,.LASANPC, etc.
 #  __crc_               - modversions
+#  __kstrtab_           - EXPORT_SYMBOL (symbol name)
+#  __kstrtabns_         - EXPORT_SYMBOL (namespace)
 #
 # Ignored symbols:
 #  L0                   - for LoongArch?
@@ -52,5 +54,7 @@ $NM -n $1 | grep -v		\
 	-e ' \$'		\
 	-e ' \.L'		\
 	-e ' __crc_'		\
+	-e ' __kstrtab_'	\
+	-e ' __kstrtabns_'	\
 	-e ' L0$'		\
 > $2
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-26  9:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26  9:02 [PATCH 1/5] mksysmap: update comment about __crc_* Masahiro Yamada
2022-09-26  9:02 ` [PATCH 2/5] kbuild: reuse mksysmap output for kallsyms Masahiro Yamada
2022-09-26  9:02 ` [PATCH 3/5] kallsyms: drop duplicated ignore patterns from kallsyms.c Masahiro Yamada
2022-09-26  9:02 ` [PATCH 4/5] kallsyms: take the input file instead of reading stdin Masahiro Yamada
2022-09-26  9:02 ` [PATCH 5/5] kallsyms: ignore __kstrtab_* and __kstrtabns_* symbols Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).