Commit f6537f2f authored by Ming Lei's avatar Ming Lei Committed by Rusty Russell

scripts/kallsyms: filter symbols not in kernel address space

This patch uses CONFIG_PAGE_OFFSET to filter symbols which
are not in kernel address space because these symbols are
generally for generating code purpose and can't be run at
kernel mode, so we needn't keep them in /proc/kallsyms.

For example, on ARM there are some symbols which may be
linked in relocatable code section, then perf can't parse
symbols any more from /proc/kallsyms, this patch fixes the
problem (introduced b9b32bf7)

Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Michal Marek <mmarek@suse.cz>
Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Cc: stable@vger.kernel.org
parent 12aee278
...@@ -55,6 +55,7 @@ static struct sym_entry *table; ...@@ -55,6 +55,7 @@ static struct sym_entry *table;
static unsigned int table_size, table_cnt; static unsigned int table_size, table_cnt;
static int all_symbols = 0; static int all_symbols = 0;
static char symbol_prefix_char = '\0'; static char symbol_prefix_char = '\0';
static unsigned long long kernel_start_addr = 0;
int token_profit[0x10000]; int token_profit[0x10000];
...@@ -65,7 +66,10 @@ unsigned char best_table_len[256]; ...@@ -65,7 +66,10 @@ unsigned char best_table_len[256];
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: kallsyms [--all-symbols] [--symbol-prefix=<prefix char>] < in.map > out.S\n"); fprintf(stderr, "Usage: kallsyms [--all-symbols] "
"[--symbol-prefix=<prefix char>] "
"[--page-offset=<CONFIG_PAGE_OFFSET>] "
"< in.map > out.S\n");
exit(1); exit(1);
} }
...@@ -194,6 +198,9 @@ static int symbol_valid(struct sym_entry *s) ...@@ -194,6 +198,9 @@ static int symbol_valid(struct sym_entry *s)
int i; int i;
int offset = 1; int offset = 1;
if (s->addr < kernel_start_addr)
return 0;
/* skip prefix char */ /* skip prefix char */
if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char) if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char)
offset++; offset++;
...@@ -646,6 +653,9 @@ int main(int argc, char **argv) ...@@ -646,6 +653,9 @@ int main(int argc, char **argv)
if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\'')) if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\''))
p++; p++;
symbol_prefix_char = *p; symbol_prefix_char = *p;
} else if (strncmp(argv[i], "--page-offset=", 14) == 0) {
const char *p = &argv[i][14];
kernel_start_addr = strtoull(p, NULL, 16);
} else } else
usage(); usage();
} }
......
...@@ -82,6 +82,8 @@ kallsyms() ...@@ -82,6 +82,8 @@ kallsyms()
kallsymopt="${kallsymopt} --all-symbols" kallsymopt="${kallsymopt} --all-symbols"
fi fi
kallsymopt="${kallsymopt} --page-offset=$CONFIG_PAGE_OFFSET"
local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}" ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment