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 b9b32bf70f2fb710b07c94e13afbc729afe221da)

Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Michal Marek <mmarek@suse.cz>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: stable@vger.kernel.org

authored by Ming Lei and committed by Rusty Russell f6537f2f 12aee278

Changed files
+13 -1
scripts
+11 -1
scripts/kallsyms.c
··· 55 55 static unsigned int table_size, table_cnt; 56 56 static int all_symbols = 0; 57 57 static char symbol_prefix_char = '\0'; 58 + static unsigned long long kernel_start_addr = 0; 58 59 59 60 int token_profit[0x10000]; 60 61 ··· 66 65 67 66 static void usage(void) 68 67 { 69 - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--symbol-prefix=<prefix char>] < in.map > out.S\n"); 68 + fprintf(stderr, "Usage: kallsyms [--all-symbols] " 69 + "[--symbol-prefix=<prefix char>] " 70 + "[--page-offset=<CONFIG_PAGE_OFFSET>] " 71 + "< in.map > out.S\n"); 70 72 exit(1); 71 73 } 72 74 ··· 197 193 NULL }; 198 194 int i; 199 195 int offset = 1; 196 + 197 + if (s->addr < kernel_start_addr) 198 + return 0; 200 199 201 200 /* skip prefix char */ 202 201 if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char) ··· 653 646 if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\'')) 654 647 p++; 655 648 symbol_prefix_char = *p; 649 + } else if (strncmp(argv[i], "--page-offset=", 14) == 0) { 650 + const char *p = &argv[i][14]; 651 + kernel_start_addr = strtoull(p, NULL, 16); 656 652 } else 657 653 usage(); 658 654 }