Skip to content

Commit a93f0e5

Browse files
simonqueolsajiri
authored andcommitted
perf symbols: Get kernel start address by symbol name
The function machine__get_kernel_start_addr() was taking the first symbol of kallsyms as the start address. This is incorrect in certain cases where the first symbol is something at 0, while the actual kernel functions begin at a later point (e.g. 0x80200000). This patch fixes machine__get_kernel_start_addr() to search for the symbol "_text" or "_stext", which marks the beginning of kernel mapping. This was already being done in machine__create_kernel_maps(). Thus, this patch is just a refactor, to move that code into machine__get_kernel_start_addr(). Signed-off-by: Simon Que <sque@chromium.org> Link: http://lkml.kernel.org/r/1402943529-13244-1-git-send-email-sque@chromium.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent d755330 commit a93f0e5

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

tools/perf/util/machine.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -496,18 +496,6 @@ struct process_args {
496496
u64 start;
497497
};
498498

499-
static int symbol__in_kernel(void *arg, const char *name,
500-
char type __maybe_unused, u64 start)
501-
{
502-
struct process_args *args = arg;
503-
504-
if (strchr(name, '['))
505-
return 0;
506-
507-
args->start = start;
508-
return 1;
509-
}
510-
511499
static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
512500
size_t bufsz)
513501
{
@@ -517,27 +505,41 @@ static void machine__get_kallsyms_filename(struct machine *machine, char *buf,
517505
scnprintf(buf, bufsz, "%s/proc/kallsyms", machine->root_dir);
518506
}
519507

520-
/* Figure out the start address of kernel map from /proc/kallsyms */
521-
static u64 machine__get_kernel_start_addr(struct machine *machine)
508+
const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
509+
510+
/* Figure out the start address of kernel map from /proc/kallsyms.
511+
* Returns the name of the start symbol in *symbol_name. Pass in NULL as
512+
* symbol_name if it's not that important.
513+
*/
514+
static u64 machine__get_kernel_start_addr(struct machine *machine,
515+
const char **symbol_name)
522516
{
523517
char filename[PATH_MAX];
524-
struct process_args args;
518+
int i;
519+
const char *name;
520+
u64 addr = 0;
525521

526522
machine__get_kallsyms_filename(machine, filename, PATH_MAX);
527523

528524
if (symbol__restricted_filename(filename, "/proc/kallsyms"))
529525
return 0;
530526

531-
if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0)
532-
return 0;
527+
for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
528+
addr = kallsyms__get_function_start(filename, name);
529+
if (addr)
530+
break;
531+
}
532+
533+
if (symbol_name)
534+
*symbol_name = name;
533535

534-
return args.start;
536+
return addr;
535537
}
536538

537539
int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel)
538540
{
539541
enum map_type type;
540-
u64 start = machine__get_kernel_start_addr(machine);
542+
u64 start = machine__get_kernel_start_addr(machine, NULL);
541543

542544
for (type = 0; type < MAP__NR_TYPES; ++type) {
543545
struct kmap *kmap;
@@ -852,23 +854,11 @@ static int machine__create_modules(struct machine *machine)
852854
return 0;
853855
}
854856

855-
const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
856-
857857
int machine__create_kernel_maps(struct machine *machine)
858858
{
859859
struct dso *kernel = machine__get_kernel(machine);
860-
char filename[PATH_MAX];
861860
const char *name;
862-
u64 addr = 0;
863-
int i;
864-
865-
machine__get_kallsyms_filename(machine, filename, PATH_MAX);
866-
867-
for (i = 0; (name = ref_reloc_sym_names[i]) != NULL; i++) {
868-
addr = kallsyms__get_function_start(filename, name);
869-
if (addr)
870-
break;
871-
}
861+
u64 addr = machine__get_kernel_start_addr(machine, &name);
872862
if (!addr)
873863
return -1;
874864

0 commit comments

Comments
 (0)