* [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations
@ 2019-11-23 13:27 Masahiro Yamada
2019-11-23 13:27 ` [PATCH 01/16] scripts/kallsyms: remove unneeded #ifndef ARRAY_SIZE Masahiro Yamada
` (15 more replies)
0 siblings, 16 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Masahiro Yamada (16):
scripts/kallsyms: remove unneeded #ifndef ARRAY_SIZE
scripts/kallsyms: fix definitely-lost memory leak
scripts/kallsyms: set relative_base more effectively
scripts/kallsyms: remove redundant is_arm_mapping_symbol()
scripts/kallsyms: remove unneeded length check for prefix matching
scripts/kallsyms: add sym_name() to mitigate cast ugliness
scripts/kallsyms: replace prefix_underscores_count() with strspn()
scripts/kallsyms: make find_token() return (unsigned char *)
scripts/kallsyms: add const qualifiers where possible
scripts/kallsyms: skip ignored symbols very early
scripts/kallsyms: move more patterns to the ignored_prefixes array
scripts/kallsyms: move ignored symbol types to is_ignored_symbol()
scripts/kallsyms: make check_symbol_range() void function
scripts/kallsyms: check no valid symbol earlier
scripts/kallsyms: put check_symbol_range() calls close together
scripts/kallsyms: remove redundant initializers
scripts/kallsyms.c | 254 +++++++++++++++++++++------------------------
1 file changed, 121 insertions(+), 133 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 01/16] scripts/kallsyms: remove unneeded #ifndef ARRAY_SIZE
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 02/16] scripts/kallsyms: fix definitely-lost memory leak Masahiro Yamada
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
This is not defined in the standard headers. #ifndef is unneeded.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index ae6504d07fd6..918c2ba071b5 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -24,9 +24,7 @@
#include <ctype.h>
#include <limits.h>
-#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
-#endif
#define KSYM_NAME_LEN 128
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 02/16] scripts/kallsyms: fix definitely-lost memory leak
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
2019-11-23 13:27 ` [PATCH 01/16] scripts/kallsyms: remove unneeded #ifndef ARRAY_SIZE Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 03/16] scripts/kallsyms: set relative_base more effectively Masahiro Yamada
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
build_initial_tok_table() overwrites unused sym_entry to shrink the
table size. Before the entry is overwritten, table[i].sym must be freed
since it is malloc'ed data.
This fixes the 'definitely lost' report from valgrind. I ran valgrind
against x86_64_defconfig of v5.4-rc8 kernel, and here is the summary:
[Before the fix]
LEAK SUMMARY:
definitely lost: 53,184 bytes in 2,874 blocks
[After the fix]
LEAK SUMMARY:
definitely lost: 0 bytes in 0 blocks
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 918c2ba071b5..79641874d860 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -487,6 +487,8 @@ static void build_initial_tok_table(void)
table[pos] = table[i];
learn_symbol(table[pos].sym, table[pos].len);
pos++;
+ } else {
+ free(table[i].sym);
}
}
table_cnt = pos;
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 03/16] scripts/kallsyms: set relative_base more effectively
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
2019-11-23 13:27 ` [PATCH 01/16] scripts/kallsyms: remove unneeded #ifndef ARRAY_SIZE Masahiro Yamada
2019-11-23 13:27 ` [PATCH 02/16] scripts/kallsyms: fix definitely-lost memory leak Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 04/16] scripts/kallsyms: remove redundant is_arm_mapping_symbol() Masahiro Yamada
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Currently, record_relative_base() iterates over the entire table to
find the minimum address, but it is not efficient because we sort
the table anyway.
After sort_symbol(), the table is sorted by address. (kallsyms parses
the 'nm -n' output, so the data is already sorted by address, but this
commit does not rely on it.)
Move record_relative_base() after sort_symbols(), and take the first
non-absolute symbol value.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 79641874d860..0959e1de381c 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -731,11 +731,15 @@ static void record_relative_base(void)
{
unsigned int i;
- relative_base = -1ULL;
for (i = 0; i < table_cnt; i++)
- if (!symbol_absolute(&table[i]) &&
- table[i].addr < relative_base)
+ if (!symbol_absolute(&table[i])) {
+ /*
+ * The table is sorted by address.
+ * Take the first non-absolute symbol value.
+ */
relative_base = table[i].addr;
+ return;
+ }
}
int main(int argc, char **argv)
@@ -758,9 +762,9 @@ int main(int argc, char **argv)
read_map(stdin);
if (absolute_percpu)
make_percpus_absolute();
+ sort_symbols();
if (base_relative)
record_relative_base();
- sort_symbols();
optimize_token_table();
write_src();
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 04/16] scripts/kallsyms: remove redundant is_arm_mapping_symbol()
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (2 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 03/16] scripts/kallsyms: set relative_base more effectively Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 05/16] scripts/kallsyms: remove unneeded length check for prefix matching Masahiro Yamada
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Since commit 6f00df24ee39 ("[PATCH] Strip local symbols from kallsyms"),
all symbols starting '$' are ignored.
is_arm_mapping_symbol() particularly ignores $a, $t, etc. but it is
redundant.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 0959e1de381c..265475d3cffb 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -74,16 +74,6 @@ static void usage(void)
exit(1);
}
-/*
- * This ignores the intensely annoying "mapping symbols" found
- * in ARM ELF files: $a, $t and $d.
- */
-static int is_arm_mapping_symbol(const char *str)
-{
- return str[0] == '$' && strchr("axtd", str[1])
- && (str[2] == '\0' || str[2] == '.');
-}
-
static int check_symbol_range(const char *sym, unsigned long long addr,
struct addr_range *ranges, int entries)
{
@@ -139,10 +129,13 @@ static int read_symbol(FILE *in, struct sym_entry *s)
return -1;
}
- else if (toupper(stype) == 'U' ||
- is_arm_mapping_symbol(sym))
+ else if (toupper(stype) == 'U')
return -1;
- /* exclude also MIPS ELF local symbols ($L123 instead of .L123) */
+ /*
+ * Ignore generated symbols such as:
+ * - mapping symbols in ARM ELF files ($a, $t, and $d)
+ * - MIPS ELF local symbols ($L123 instead of .L123)
+ */
else if (sym[0] == '$')
return -1;
/* exclude debugging symbols */
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 05/16] scripts/kallsyms: remove unneeded length check for prefix matching
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (3 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 04/16] scripts/kallsyms: remove redundant is_arm_mapping_symbol() Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 06/16] scripts/kallsyms: add sym_name() to mitigate cast ugliness Masahiro Yamada
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
l <= strlen(sym_name) is unnecessary for prefix matching.
strncmp() will do.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 265475d3cffb..d06f373b3a96 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -246,8 +246,7 @@ static int symbol_valid(struct sym_entry *s)
for (i = 0; special_prefixes[i]; i++) {
int l = strlen(special_prefixes[i]);
- if (l <= strlen(sym_name) &&
- strncmp(sym_name, special_prefixes[i], l) == 0)
+ if (strncmp(sym_name, special_prefixes[i], l) == 0)
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 06/16] scripts/kallsyms: add sym_name() to mitigate cast ugliness
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (4 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 05/16] scripts/kallsyms: remove unneeded length check for prefix matching Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 07/16] scripts/kallsyms: replace prefix_underscores_count() with strspn() Masahiro Yamada
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
sym_entry::sym is (unsigned char *) instead of (char *) because
kallsyms exploits the MSB for compression, and the characters are
used as the index of token_profit array.
However, it requires casting (unsigned char *) to (char *) in some
places since standard library functions such as strcmp(), strlen()
expect (char *).
Introduce a new helper, sym_name(), which advances the given pointer
by 1 and casts it to (char *).
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index d06f373b3a96..7b00b4030be4 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -74,6 +74,11 @@ static void usage(void)
exit(1);
}
+static char *sym_name(const struct sym_entry *s)
+{
+ return (char *)s->sym + 1;
+}
+
static int check_symbol_range(const char *sym, unsigned long long addr,
struct addr_range *ranges, int entries)
{
@@ -154,7 +159,7 @@ static int read_symbol(FILE *in, struct sym_entry *s)
"unable to allocate required amount of memory\n");
exit(EXIT_FAILURE);
}
- strcpy((char *)s->sym + 1, sym);
+ strcpy(sym_name(s), sym);
s->sym[0] = stype;
s->percpu_absolute = 0;
@@ -215,7 +220,7 @@ static int symbol_valid(struct sym_entry *s)
NULL };
int i;
- char *sym_name = (char *)s->sym + 1;
+ const char *name = sym_name(s);
/* if --all-symbols is not specified, then symbols outside the text
* and inittext sections are discarded */
@@ -230,30 +235,28 @@ static int symbol_valid(struct sym_entry *s)
* rules.
*/
if ((s->addr == text_range_text->end &&
- strcmp(sym_name,
- text_range_text->end_sym)) ||
+ strcmp(name, text_range_text->end_sym)) ||
(s->addr == text_range_inittext->end &&
- strcmp(sym_name,
- text_range_inittext->end_sym)))
+ strcmp(name, text_range_inittext->end_sym)))
return 0;
}
/* Exclude symbols which vary between passes. */
for (i = 0; special_symbols[i]; i++)
- if (strcmp(sym_name, special_symbols[i]) == 0)
+ if (strcmp(name, special_symbols[i]) == 0)
return 0;
for (i = 0; special_prefixes[i]; i++) {
int l = strlen(special_prefixes[i]);
- if (strncmp(sym_name, special_prefixes[i], l) == 0)
+ if (strncmp(name, special_prefixes[i], l) == 0)
return 0;
}
for (i = 0; special_suffixes[i]; i++) {
- int l = strlen(sym_name) - strlen(special_suffixes[i]);
+ int l = strlen(name) - strlen(special_suffixes[i]);
- if (l >= 0 && strcmp(sym_name + l, special_suffixes[i]) == 0)
+ if (l >= 0 && strcmp(name + l, special_suffixes[i]) == 0)
return 0;
}
@@ -618,7 +621,7 @@ static void optimize_token_table(void)
/* guess for "linker script provide" symbol */
static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
{
- const char *symbol = (char *)se->sym + 1;
+ const char *symbol = sym_name(se);
int len = se->len - 1;
if (len < 8)
@@ -688,8 +691,8 @@ static int compare_symbols(const void *a, const void *b)
return wa - wb;
/* sort by the number of prefix underscores */
- wa = prefix_underscores_count((const char *)sa->sym + 1);
- wb = prefix_underscores_count((const char *)sb->sym + 1);
+ wa = prefix_underscores_count(sym_name(sa));
+ wb = prefix_underscores_count(sym_name(sb));
if (wa != wb)
return wa - wb;
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 07/16] scripts/kallsyms: replace prefix_underscores_count() with strspn()
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (5 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 06/16] scripts/kallsyms: add sym_name() to mitigate cast ugliness Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 08/16] scripts/kallsyms: make find_token() return (unsigned char *) Masahiro Yamada
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
You can do equivalent with strspn(). I do not see noticeable performance
difference.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 7b00b4030be4..a007d901c3a5 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -653,16 +653,6 @@ static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
return 0;
}
-static int prefix_underscores_count(const char *str)
-{
- const char *tail = str;
-
- while (*tail == '_')
- tail++;
-
- return tail - str;
-}
-
static int compare_symbols(const void *a, const void *b)
{
const struct sym_entry *sa;
@@ -691,8 +681,8 @@ static int compare_symbols(const void *a, const void *b)
return wa - wb;
/* sort by the number of prefix underscores */
- wa = prefix_underscores_count(sym_name(sa));
- wb = prefix_underscores_count(sym_name(sb));
+ wa = strspn(sym_name(sa), "_");
+ wb = strspn(sym_name(sb), "_");
if (wa != wb)
return wa - wb;
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 08/16] scripts/kallsyms: make find_token() return (unsigned char *)
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (6 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 07/16] scripts/kallsyms: replace prefix_underscores_count() with strspn() Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 09/16] scripts/kallsyms: add const qualifiers where possible Masahiro Yamada
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
The callers of this function expect (unsigned char *). I do not see
a good reason to make this function return (void *).
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index a007d901c3a5..c4f7f20ecfb7 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -489,7 +489,8 @@ static void build_initial_tok_table(void)
table_cnt = pos;
}
-static void *find_token(unsigned char *str, int len, unsigned char *token)
+static unsigned char *find_token(unsigned char *str, int len,
+ unsigned char *token)
{
int i;
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 09/16] scripts/kallsyms: add const qualifiers where possible
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (7 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 08/16] scripts/kallsyms: make find_token() return (unsigned char *) Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 10/16] scripts/kallsyms: skip ignored symbols very early Masahiro Yamada
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Add 'const' where a function does not write to the pointer dereferenes.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index c4f7f20ecfb7..d745fd2c7247 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -170,11 +170,11 @@ static int read_symbol(FILE *in, struct sym_entry *s)
return 0;
}
-static int symbol_in_range(struct sym_entry *s, struct addr_range *ranges,
- int entries)
+static int symbol_in_range(const struct sym_entry *s,
+ const struct addr_range *ranges, int entries)
{
size_t i;
- struct addr_range *ar;
+ const struct addr_range *ar;
for (i = 0; i < entries; ++i) {
ar = &ranges[i];
@@ -186,14 +186,14 @@ static int symbol_in_range(struct sym_entry *s, struct addr_range *ranges,
return 0;
}
-static int symbol_valid(struct sym_entry *s)
+static int symbol_valid(const struct sym_entry *s)
{
/* Symbols which vary between passes. Passes 1 and 2 must have
* identical symbol lists. The kallsyms_* symbols below are only added
* after pass 1, they would be included in pass 2 when --all-symbols is
* specified so exclude them to get a stable symbol list.
*/
- static char *special_symbols[] = {
+ static const char * const special_symbols[] = {
"kallsyms_addresses",
"kallsyms_offsets",
"kallsyms_relative_base",
@@ -208,12 +208,12 @@ static int symbol_valid(struct sym_entry *s)
"_SDA2_BASE_", /* ppc */
NULL };
- static char *special_prefixes[] = {
+ static const char * const special_prefixes[] = {
"__crc_", /* modversions */
"__efistub_", /* arm64 EFI stub namespace */
NULL };
- static char *special_suffixes[] = {
+ static const char * const special_suffixes[] = {
"_veneer", /* arm */
"_from_arm", /* arm */
"_from_thumb", /* arm */
@@ -281,7 +281,7 @@ static void read_map(FILE *in)
}
}
-static void output_label(char *label)
+static void output_label(const char *label)
{
printf(".globl %s\n", label);
printf("\tALGN\n");
@@ -290,7 +290,7 @@ static void output_label(char *label)
/* uncompress a compressed symbol. When this function is called, the best table
* might still be compressed itself, so the function needs to be recursive */
-static int expand_symbol(unsigned char *data, int len, char *result)
+static int expand_symbol(const unsigned char *data, int len, char *result)
{
int c, rlen, total=0;
@@ -315,7 +315,7 @@ static int expand_symbol(unsigned char *data, int len, char *result)
return total;
}
-static int symbol_absolute(struct sym_entry *s)
+static int symbol_absolute(const struct sym_entry *s)
{
return s->percpu_absolute;
}
@@ -453,7 +453,7 @@ static void write_src(void)
/* table lookup compression functions */
/* count all the possible tokens in a symbol */
-static void learn_symbol(unsigned char *symbol, int len)
+static void learn_symbol(const unsigned char *symbol, int len)
{
int i;
@@ -462,7 +462,7 @@ static void learn_symbol(unsigned char *symbol, int len)
}
/* decrease the count for all the possible tokens in a symbol */
-static void forget_symbol(unsigned char *symbol, int len)
+static void forget_symbol(const unsigned char *symbol, int len)
{
int i;
@@ -490,7 +490,7 @@ static void build_initial_tok_table(void)
}
static unsigned char *find_token(unsigned char *str, int len,
- unsigned char *token)
+ const unsigned char *token)
{
int i;
@@ -503,7 +503,7 @@ static unsigned char *find_token(unsigned char *str, int len,
/* replace a given token in all the valid symbols. Use the sampled symbols
* to update the counts */
-static void compress_symbols(unsigned char *str, int idx)
+static void compress_symbols(const unsigned char *str, int idx)
{
unsigned int i, len, size;
unsigned char *p1, *p2;
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 10/16] scripts/kallsyms: skip ignored symbols very early
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (8 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 09/16] scripts/kallsyms: add const qualifiers where possible Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 11/16] scripts/kallsyms: move more patterns to the ignored_prefixes array Masahiro Yamada
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Unless the address range matters, symbols can be ignored earlier,
which avoids unneeded memory allocation.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 113 +++++++++++++++++++++++++--------------------
1 file changed, 62 insertions(+), 51 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index d745fd2c7247..5553843631d4 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -18,6 +18,7 @@
*
*/
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -79,6 +80,64 @@ static char *sym_name(const struct sym_entry *s)
return (char *)s->sym + 1;
}
+static bool is_ignored_symbol(const char *name, char type)
+{
+ static const char * const ignored_symbols[] = {
+ /*
+ * Symbols which vary between passes. Passes 1 and 2 must have
+ * identical symbol lists. The kallsyms_* symbols below are
+ * only added after pass 1, they would be included in pass 2
+ * when --all-symbols is specified so exclude them to get a
+ * stable symbol list.
+ */
+ "kallsyms_addresses",
+ "kallsyms_offsets",
+ "kallsyms_relative_base",
+ "kallsyms_num_syms",
+ "kallsyms_names",
+ "kallsyms_markers",
+ "kallsyms_token_table",
+ "kallsyms_token_index",
+ /* Exclude linker generated symbols which vary between passes */
+ "_SDA_BASE_", /* ppc */
+ "_SDA2_BASE_", /* ppc */
+ NULL
+ };
+
+ static const char * const ignored_prefixes[] = {
+ "__crc_", /* modversions */
+ "__efistub_", /* arm64 EFI stub namespace */
+ NULL
+ };
+
+ static const char * const ignored_suffixes[] = {
+ "_from_arm", /* arm */
+ "_from_thumb", /* arm */
+ "_veneer", /* arm */
+ NULL
+ };
+
+ const char * const *p;
+
+ /* Exclude symbols which vary between passes. */
+ for (p = ignored_symbols; *p; p++)
+ if (!strcmp(name, *p))
+ return true;
+
+ for (p = ignored_prefixes; *p; p++)
+ if (!strncmp(name, *p, strlen(*p)))
+ return true;
+
+ for (p = ignored_suffixes; *p; p++) {
+ int l = strlen(name) - strlen(*p);
+
+ if (l >= 0 && !strcmp(name + l, *p))
+ return true;
+ }
+
+ return false;
+}
+
static int check_symbol_range(const char *sym, unsigned long long addr,
struct addr_range *ranges, int entries)
{
@@ -118,6 +177,9 @@ static int read_symbol(FILE *in, struct sym_entry *s)
return -1;
}
+ if (is_ignored_symbol(sym, stype))
+ return -1;
+
/* Ignore most absolute/undefined (?) symbols. */
if (strcmp(sym, "_text") == 0)
_text = s->addr;
@@ -188,38 +250,6 @@ static int symbol_in_range(const struct sym_entry *s,
static int symbol_valid(const struct sym_entry *s)
{
- /* Symbols which vary between passes. Passes 1 and 2 must have
- * identical symbol lists. The kallsyms_* symbols below are only added
- * after pass 1, they would be included in pass 2 when --all-symbols is
- * specified so exclude them to get a stable symbol list.
- */
- static const char * const special_symbols[] = {
- "kallsyms_addresses",
- "kallsyms_offsets",
- "kallsyms_relative_base",
- "kallsyms_num_syms",
- "kallsyms_names",
- "kallsyms_markers",
- "kallsyms_token_table",
- "kallsyms_token_index",
-
- /* Exclude linker generated symbols which vary between passes */
- "_SDA_BASE_", /* ppc */
- "_SDA2_BASE_", /* ppc */
- NULL };
-
- static const char * const special_prefixes[] = {
- "__crc_", /* modversions */
- "__efistub_", /* arm64 EFI stub namespace */
- NULL };
-
- static const char * const special_suffixes[] = {
- "_veneer", /* arm */
- "_from_arm", /* arm */
- "_from_thumb", /* arm */
- NULL };
-
- int i;
const char *name = sym_name(s);
/* if --all-symbols is not specified, then symbols outside the text
@@ -241,25 +271,6 @@ static int symbol_valid(const struct sym_entry *s)
return 0;
}
- /* Exclude symbols which vary between passes. */
- for (i = 0; special_symbols[i]; i++)
- if (strcmp(name, special_symbols[i]) == 0)
- return 0;
-
- for (i = 0; special_prefixes[i]; i++) {
- int l = strlen(special_prefixes[i]);
-
- if (strncmp(name, special_prefixes[i], l) == 0)
- return 0;
- }
-
- for (i = 0; special_suffixes[i]; i++) {
- int l = strlen(name) - strlen(special_suffixes[i]);
-
- if (l >= 0 && strcmp(name + l, special_suffixes[i]) == 0)
- return 0;
- }
-
return 1;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 11/16] scripts/kallsyms: move more patterns to the ignored_prefixes array
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (9 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 10/16] scripts/kallsyms: skip ignored symbols very early Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 12/16] scripts/kallsyms: move ignored symbol types to is_ignored_symbol() Masahiro Yamada
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Refactoring for shortening the code.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 5553843631d4..63473924d4de 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -105,6 +105,8 @@ static bool is_ignored_symbol(const char *name, char type)
};
static const char * const ignored_prefixes[] = {
+ "$", /* local symbols for ARM, MIPS, etc. */
+ ".LASANPC", /* s390 kasan local symbols */
"__crc_", /* modversions */
"__efistub_", /* arm64 EFI stub namespace */
NULL
@@ -198,19 +200,9 @@ static int read_symbol(FILE *in, struct sym_entry *s)
}
else if (toupper(stype) == 'U')
return -1;
- /*
- * Ignore generated symbols such as:
- * - mapping symbols in ARM ELF files ($a, $t, and $d)
- * - MIPS ELF local symbols ($L123 instead of .L123)
- */
- else if (sym[0] == '$')
- return -1;
/* exclude debugging symbols */
else if (stype == 'N' || stype == 'n')
return -1;
- /* exclude s390 kasan local symbols */
- else if (!strncmp(sym, ".LASANPC", 8))
- return -1;
/* include the type field in the symbol name, so that it gets
* compressed together */
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 12/16] scripts/kallsyms: move ignored symbol types to is_ignored_symbol()
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (10 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 11/16] scripts/kallsyms: move more patterns to the ignored_prefixes array Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 13/16] scripts/kallsyms: make check_symbol_range() void function Masahiro Yamada
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Collect the ignored patterns to is_ignored_symbol().
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 63473924d4de..21f4d347f371 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -137,6 +137,21 @@ static bool is_ignored_symbol(const char *name, char type)
return true;
}
+ if (type == 'U' || type == 'u')
+ return true;
+ /* exclude debugging symbols */
+ if (type == 'N' || type == 'n')
+ return true;
+
+ if (toupper(type) == 'A') {
+ /* Keep these useful absolute symbols */
+ if (strcmp(name, "__kernel_syscall_via_break") &&
+ strcmp(name, "__kernel_syscall_via_epc") &&
+ strcmp(name, "__kernel_sigtramp") &&
+ strcmp(name, "__gp"))
+ return true;
+ }
+
return false;
}
@@ -188,21 +203,6 @@ static int read_symbol(FILE *in, struct sym_entry *s)
else if (check_symbol_range(sym, s->addr, text_ranges,
ARRAY_SIZE(text_ranges)) == 0)
/* nothing to do */;
- else if (toupper(stype) == 'A')
- {
- /* Keep these useful absolute symbols */
- if (strcmp(sym, "__kernel_syscall_via_break") &&
- strcmp(sym, "__kernel_syscall_via_epc") &&
- strcmp(sym, "__kernel_sigtramp") &&
- strcmp(sym, "__gp"))
- return -1;
-
- }
- else if (toupper(stype) == 'U')
- return -1;
- /* exclude debugging symbols */
- else if (stype == 'N' || stype == 'n')
- return -1;
/* include the type field in the symbol name, so that it gets
* compressed together */
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 13/16] scripts/kallsyms: make check_symbol_range() void function
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (11 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 12/16] scripts/kallsyms: move ignored symbol types to is_ignored_symbol() Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 14/16] scripts/kallsyms: check no valid symbol earlier Masahiro Yamada
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
There is no more reason to check the return value of
check_symbol_range().
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 21f4d347f371..144f43363c4d 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -155,8 +155,8 @@ static bool is_ignored_symbol(const char *name, char type)
return false;
}
-static int check_symbol_range(const char *sym, unsigned long long addr,
- struct addr_range *ranges, int entries)
+static void check_symbol_range(const char *sym, unsigned long long addr,
+ struct addr_range *ranges, int entries)
{
size_t i;
struct addr_range *ar;
@@ -166,14 +166,12 @@ static int check_symbol_range(const char *sym, unsigned long long addr,
if (strcmp(sym, ar->start_sym) == 0) {
ar->start = addr;
- return 0;
+ return;
} else if (strcmp(sym, ar->end_sym) == 0) {
ar->end = addr;
- return 0;
+ return;
}
}
-
- return 1;
}
static int read_symbol(FILE *in, struct sym_entry *s)
@@ -200,9 +198,8 @@ static int read_symbol(FILE *in, struct sym_entry *s)
/* Ignore most absolute/undefined (?) symbols. */
if (strcmp(sym, "_text") == 0)
_text = s->addr;
- else if (check_symbol_range(sym, s->addr, text_ranges,
- ARRAY_SIZE(text_ranges)) == 0)
- /* nothing to do */;
+
+ check_symbol_range(sym, s->addr, text_ranges, ARRAY_SIZE(text_ranges));
/* include the type field in the symbol name, so that it gets
* compressed together */
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 14/16] scripts/kallsyms: check no valid symbol earlier
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (12 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 13/16] scripts/kallsyms: make check_symbol_range() void function Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 15/16] scripts/kallsyms: put check_symbol_range() calls close together Masahiro Yamada
2019-11-23 13:27 ` [PATCH 16/16] scripts/kallsyms: remove redundant initializers Masahiro Yamada
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
insert_real_symbols_in_table() does not touch table_cnt, so the
no valid symbol check can be moved before it.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 144f43363c4d..919cb45ce9db 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -608,14 +608,14 @@ static void optimize_token_table(void)
{
build_initial_tok_table();
- insert_real_symbols_in_table();
-
/* When valid symbol is not registered, exit to error */
if (!table_cnt) {
fprintf(stderr, "No valid symbol.\n");
exit(1);
}
+ insert_real_symbols_in_table();
+
optimize_result();
}
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 15/16] scripts/kallsyms: put check_symbol_range() calls close together
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (13 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 14/16] scripts/kallsyms: check no valid symbol earlier Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
2019-11-23 13:27 ` [PATCH 16/16] scripts/kallsyms: remove redundant initializers Masahiro Yamada
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
Put the relevant code close together.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 919cb45ce9db..22ff206e2533 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -200,6 +200,7 @@ static int read_symbol(FILE *in, struct sym_entry *s)
_text = s->addr;
check_symbol_range(sym, s->addr, text_ranges, ARRAY_SIZE(text_ranges));
+ check_symbol_range(sym, s->addr, &percpu_range, 1);
/* include the type field in the symbol name, so that it gets
* compressed together */
@@ -215,9 +216,6 @@ static int read_symbol(FILE *in, struct sym_entry *s)
s->percpu_absolute = 0;
- /* Record if we've found __per_cpu_start/end. */
- check_symbol_range(sym, s->addr, &percpu_range, 1);
-
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 16/16] scripts/kallsyms: remove redundant initializers
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
` (14 preceding siblings ...)
2019-11-23 13:27 ` [PATCH 15/16] scripts/kallsyms: put check_symbol_range() calls close together Masahiro Yamada
@ 2019-11-23 13:27 ` Masahiro Yamada
15 siblings, 0 replies; 17+ messages in thread
From: Masahiro Yamada @ 2019-11-23 13:27 UTC (permalink / raw)
To: linux-kbuild; +Cc: Masahiro Yamada, linux-kernel
These are set to zero without the explicit initializers.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
scripts/kallsyms.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 22ff206e2533..803df71e5069 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -57,9 +57,9 @@ static struct addr_range percpu_range = {
static struct sym_entry *table;
static unsigned int table_size, table_cnt;
-static int all_symbols = 0;
-static int absolute_percpu = 0;
-static int base_relative = 0;
+static int all_symbols;
+static int absolute_percpu;
+static int base_relative;
static int token_profit[0x10000];
--
2.17.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2019-11-23 13:29 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-23 13:27 [PATCH 00/16] scripts/kallsyms: various cleanups and optimizations Masahiro Yamada
2019-11-23 13:27 ` [PATCH 01/16] scripts/kallsyms: remove unneeded #ifndef ARRAY_SIZE Masahiro Yamada
2019-11-23 13:27 ` [PATCH 02/16] scripts/kallsyms: fix definitely-lost memory leak Masahiro Yamada
2019-11-23 13:27 ` [PATCH 03/16] scripts/kallsyms: set relative_base more effectively Masahiro Yamada
2019-11-23 13:27 ` [PATCH 04/16] scripts/kallsyms: remove redundant is_arm_mapping_symbol() Masahiro Yamada
2019-11-23 13:27 ` [PATCH 05/16] scripts/kallsyms: remove unneeded length check for prefix matching Masahiro Yamada
2019-11-23 13:27 ` [PATCH 06/16] scripts/kallsyms: add sym_name() to mitigate cast ugliness Masahiro Yamada
2019-11-23 13:27 ` [PATCH 07/16] scripts/kallsyms: replace prefix_underscores_count() with strspn() Masahiro Yamada
2019-11-23 13:27 ` [PATCH 08/16] scripts/kallsyms: make find_token() return (unsigned char *) Masahiro Yamada
2019-11-23 13:27 ` [PATCH 09/16] scripts/kallsyms: add const qualifiers where possible Masahiro Yamada
2019-11-23 13:27 ` [PATCH 10/16] scripts/kallsyms: skip ignored symbols very early Masahiro Yamada
2019-11-23 13:27 ` [PATCH 11/16] scripts/kallsyms: move more patterns to the ignored_prefixes array Masahiro Yamada
2019-11-23 13:27 ` [PATCH 12/16] scripts/kallsyms: move ignored symbol types to is_ignored_symbol() Masahiro Yamada
2019-11-23 13:27 ` [PATCH 13/16] scripts/kallsyms: make check_symbol_range() void function Masahiro Yamada
2019-11-23 13:27 ` [PATCH 14/16] scripts/kallsyms: check no valid symbol earlier Masahiro Yamada
2019-11-23 13:27 ` [PATCH 15/16] scripts/kallsyms: put check_symbol_range() calls close together Masahiro Yamada
2019-11-23 13:27 ` [PATCH 16/16] scripts/kallsyms: remove redundant initializers 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).