From: Masami Hiramatsu <[email protected]>

In map_groups__find_symbol() map->map_ip is used without ensuring the
map is loaded. Then the address passed to map->map_ip isn't mapped at
the first time.

E.g. below code always fails to get a symbol at the first call;

        addr = /* Somewhere in the kernel text */
        symbol_conf.try_vmlinux_path = true;
        symbol__init();
        host_machine = machine__new_host();
        sym = machine__find_kernel_function(host_machine,
                                         addr, NULL, NULL);
        /* Note that machine__find_kernel_function calls
           map_groups__find_symbol */

This ensures it by calling map__load before using it in
map_groups__find_symbol().

Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: "David A. Long" <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: "Steven Rostedt (Red Hat)" <[email protected]>
Cc: [email protected]
Link: 
http://lkml.kernel.org/r/20140123022950.7206.17357.st...@kbuild-fedora.yrl.intra.hitachi.co.jp
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/map.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index ee1dd687a262..3b97513f0e77 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -386,7 +386,8 @@ struct symbol *map_groups__find_symbol(struct map_groups 
*mg,
 {
        struct map *map = map_groups__find(mg, type, addr);
 
-       if (map != NULL) {
+       /* Ensure map is loaded before using map->map_ip */
+       if (map != NULL && map__load(map, filter) >= 0) {
                if (mapp != NULL)
                        *mapp = map;
                return map__find_symbol(map, map->map_ip(map, addr), filter);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to