Skip to content

Commit f6537f2

Browse files
ming1rustyrussell
authored andcommitted
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 b9b32bf) 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
1 parent 12aee27 commit f6537f2

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎scripts/kallsyms.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static struct sym_entry *table;
5555
static unsigned int table_size, table_cnt;
5656
static int all_symbols = 0;
5757
static char symbol_prefix_char = '\0';
58+
static unsigned long long kernel_start_addr = 0;
5859

5960
int token_profit[0x10000];
6061

@@ -65,7 +66,10 @@ unsigned char best_table_len[256];
6566

6667
static void usage(void)
6768
{
68-
fprintf(stderr, "Usage: kallsyms [--all-symbols] [--symbol-prefix=<prefix char>] < in.map > out.S\n");
69+
fprintf(stderr, "Usage: kallsyms [--all-symbols] "
70+
"[--symbol-prefix=<prefix char>] "
71+
"[--page-offset=<CONFIG_PAGE_OFFSET>] "
72+
"< in.map > out.S\n");
6973
exit(1);
7074
}
7175

@@ -194,6 +198,9 @@ static int symbol_valid(struct sym_entry *s)
194198
int i;
195199
int offset = 1;
196200

201+
if (s->addr < kernel_start_addr)
202+
return 0;
203+
197204
/* skip prefix char */
198205
if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char)
199206
offset++;
@@ -646,6 +653,9 @@ int main(int argc, char **argv)
646653
if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\''))
647654
p++;
648655
symbol_prefix_char = *p;
656+
} else if (strncmp(argv[i], "--page-offset=", 14) == 0) {
657+
const char *p = &argv[i][14];
658+
kernel_start_addr = strtoull(p, NULL, 16);
649659
} else
650660
usage();
651661
}

‎scripts/link-vmlinux.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ kallsyms()
8282
kallsymopt="${kallsymopt} --all-symbols"
8383
fi
8484

85+
kallsymopt="${kallsymopt} --page-offset=$CONFIG_PAGE_OFFSET"
86+
8587
local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
8688
${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
8789

0 commit comments

Comments
 (0)