perf symbols: Figure out start address of kernel map from kallsyms

On ARM, module symbol start address is ahead of kernel symbol start address, so
we can't suppose that the start address of kernel map always is zero, otherwise
may cause incorrect .start and .end of kernel map (caused by fixup) when there
are modules loaded, then map_groups__find may return incorrect map for symbol
query.

This patch always figures out the start address of kernel map from
/proc/kallsyms if the file is available, so fix the issues on ARM for module
loaded case.

This patch fixes the following issues on ARM when modules are loaded:

- vmlinux symbol can't be found by kallsyms maps doing 'perf test'
- module symbols are parsed mistakenlly when doing 'perf top'/'perf report'

Cc: Ian Munsie <imunsie@au1.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20101125192725.62d31b42@tom-lei>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by Ming Lei and committed by Arnaldo Carvalho de Melo d214afbd 8a953312

+42 -1
+42 -1
tools/perf/util/symbol.c
··· 2131 2131 return kernel; 2132 2132 } 2133 2133 2134 + struct process_args { 2135 + u64 start; 2136 + }; 2137 + 2138 + static int symbol__in_kernel(void *arg, const char *name, 2139 + char type __used, u64 start) 2140 + { 2141 + struct process_args *args = arg; 2142 + 2143 + if (strchr(name, '[')) 2144 + return 0; 2145 + 2146 + args->start = start; 2147 + return 1; 2148 + } 2149 + 2150 + /* Figure out the start address of kernel map from /proc/kallsyms */ 2151 + static u64 machine__get_kernel_start_addr(struct machine *machine) 2152 + { 2153 + const char *filename; 2154 + char path[PATH_MAX]; 2155 + struct process_args args; 2156 + 2157 + if (machine__is_host(machine)) { 2158 + filename = "/proc/kallsyms"; 2159 + } else { 2160 + if (machine__is_default_guest(machine)) 2161 + filename = (char *)symbol_conf.default_guest_kallsyms; 2162 + else { 2163 + sprintf(path, "%s/proc/kallsyms", machine->root_dir); 2164 + filename = path; 2165 + } 2166 + } 2167 + 2168 + if (kallsyms__parse(filename, &args, symbol__in_kernel) <= 0) 2169 + return 0; 2170 + 2171 + return args.start; 2172 + } 2173 + 2134 2174 int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) 2135 2175 { 2136 2176 enum map_type type; 2177 + u64 start = machine__get_kernel_start_addr(self); 2137 2178 2138 2179 for (type = 0; type < MAP__NR_TYPES; ++type) { 2139 2180 struct kmap *kmap; 2140 2181 2141 - self->vmlinux_maps[type] = map__new2(0, kernel, type); 2182 + self->vmlinux_maps[type] = map__new2(start, kernel, type); 2142 2183 if (self->vmlinux_maps[type] == NULL) 2143 2184 return -1; 2144 2185