Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1 | #define _GNU_SOURCE |
| 2 | #include <ctype.h> |
| 3 | #include <dirent.h> |
| 4 | #include <errno.h> |
| 5 | #include <libgen.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <stdio.h> |
| 8 | #include <string.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <sys/param.h> |
| 12 | #include <fcntl.h> |
| 13 | #include <unistd.h> |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 14 | #include "symbol.h" |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 15 | #include "strlist.h" |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 16 | |
| 17 | #include <libelf.h> |
| 18 | #include <gelf.h> |
| 19 | #include <elf.h> |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 20 | #include <limits.h> |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 21 | #include <sys/utsname.h> |
Peter Zijlstra | 2cdbc46 | 2009-08-05 14:05:16 +0200 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | c12e15e | 2009-11-21 14:31:25 -0200 | [diff] [blame] | 23 | #ifndef NT_GNU_BUILD_ID |
| 24 | #define NT_GNU_BUILD_ID 3 |
| 25 | #endif |
| 26 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 27 | static void dsos__add(struct list_head *head, struct dso *dso); |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 28 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type); |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 29 | static int dso__load_kernel_sym(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 30 | symbol_filter_t filter); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 31 | static int dso__load_guest_kernel_sym(struct dso *self, struct map *map, |
| 32 | symbol_filter_t filter); |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 33 | static int vmlinux_path__nr_entries; |
| 34 | static char **vmlinux_path; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 35 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 36 | struct symbol_conf symbol_conf = { |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 37 | .exclude_other = true, |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 38 | .use_modules = true, |
| 39 | .try_vmlinux_path = true, |
| 40 | }; |
| 41 | |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 42 | bool dso__loaded(const struct dso *self, enum map_type type) |
| 43 | { |
| 44 | return self->loaded & (1 << type); |
| 45 | } |
| 46 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 47 | bool dso__sorted_by_name(const struct dso *self, enum map_type type) |
| 48 | { |
| 49 | return self->sorted_by_name & (1 << type); |
| 50 | } |
| 51 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 52 | static void dso__set_sorted_by_name(struct dso *self, enum map_type type) |
| 53 | { |
| 54 | self->sorted_by_name |= (1 << type); |
| 55 | } |
| 56 | |
Arnaldo Carvalho de Melo | 36a3e64 | 2010-01-04 16:19:27 -0200 | [diff] [blame] | 57 | bool symbol_type__is_a(char symbol_type, enum map_type map_type) |
Arnaldo Carvalho de Melo | 6893d4e | 2009-12-11 14:50:37 -0200 | [diff] [blame] | 58 | { |
| 59 | switch (map_type) { |
| 60 | case MAP__FUNCTION: |
| 61 | return symbol_type == 'T' || symbol_type == 'W'; |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 62 | case MAP__VARIABLE: |
| 63 | return symbol_type == 'D' || symbol_type == 'd'; |
Arnaldo Carvalho de Melo | 6893d4e | 2009-12-11 14:50:37 -0200 | [diff] [blame] | 64 | default: |
| 65 | return false; |
| 66 | } |
| 67 | } |
| 68 | |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 69 | static void symbols__fixup_end(struct rb_root *self) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 70 | { |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 71 | struct rb_node *nd, *prevnd = rb_first(self); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 72 | struct symbol *curr, *prev; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 73 | |
| 74 | if (prevnd == NULL) |
| 75 | return; |
| 76 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 77 | curr = rb_entry(prevnd, struct symbol, rb_node); |
| 78 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 79 | for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 80 | prev = curr; |
| 81 | curr = rb_entry(nd, struct symbol, rb_node); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 82 | |
| 83 | if (prev->end == prev->start) |
| 84 | prev->end = curr->start - 1; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 85 | } |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 86 | |
| 87 | /* Last entry */ |
| 88 | if (curr->end == curr->start) |
| 89 | curr->end = roundup(curr->start, 4096); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 90 | } |
| 91 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 92 | static void __map_groups__fixup_end(struct map_groups *self, enum map_type type) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 93 | { |
| 94 | struct map *prev, *curr; |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 95 | struct rb_node *nd, *prevnd = rb_first(&self->maps[type]); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 96 | |
| 97 | if (prevnd == NULL) |
| 98 | return; |
| 99 | |
| 100 | curr = rb_entry(prevnd, struct map, rb_node); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 101 | |
| 102 | for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) { |
| 103 | prev = curr; |
| 104 | curr = rb_entry(nd, struct map, rb_node); |
| 105 | prev->end = curr->start - 1; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 106 | } |
Arnaldo Carvalho de Melo | 90c8321 | 2009-11-21 14:31:24 -0200 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * We still haven't the actual symbols, so guess the |
| 110 | * last map final address. |
| 111 | */ |
| 112 | curr->end = ~0UL; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 113 | } |
| 114 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 115 | static void map_groups__fixup_end(struct map_groups *self) |
Arnaldo Carvalho de Melo | 23ea4a3 | 2009-11-27 16:29:19 -0200 | [diff] [blame] | 116 | { |
| 117 | int i; |
| 118 | for (i = 0; i < MAP__NR_TYPES; ++i) |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 119 | __map_groups__fixup_end(self, i); |
Arnaldo Carvalho de Melo | 23ea4a3 | 2009-11-27 16:29:19 -0200 | [diff] [blame] | 120 | } |
| 121 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 122 | static struct symbol *symbol__new(u64 start, u64 len, const char *name) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 123 | { |
Arnaldo Carvalho de Melo | 0085c954 | 2009-05-28 14:55:13 -0300 | [diff] [blame] | 124 | size_t namelen = strlen(name) + 1; |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 125 | struct symbol *self = calloc(1, (symbol_conf.priv_size + |
| 126 | sizeof(*self) + namelen)); |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 127 | if (self == NULL) |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 128 | return NULL; |
| 129 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 130 | if (symbol_conf.priv_size) |
| 131 | self = ((void *)self) + symbol_conf.priv_size; |
Arnaldo Carvalho de Melo | 3647948 | 2009-11-24 12:05:16 -0200 | [diff] [blame] | 132 | |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame^] | 133 | self->start = start; |
| 134 | self->end = len ? start + len - 1 : start; |
| 135 | self->namelen = namelen - 1; |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 136 | |
Arnaldo Carvalho de Melo | 29a9f66 | 2010-02-03 16:52:06 -0200 | [diff] [blame] | 137 | pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 138 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 139 | memcpy(self->name, name, namelen); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 140 | |
| 141 | return self; |
| 142 | } |
| 143 | |
Arnaldo Carvalho de Melo | 628ada0 | 2010-02-25 12:57:40 -0300 | [diff] [blame] | 144 | void symbol__delete(struct symbol *self) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 145 | { |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 146 | free(((void *)self) - symbol_conf.priv_size); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static size_t symbol__fprintf(struct symbol *self, FILE *fp) |
| 150 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 151 | return fprintf(fp, " %llx-%llx %s\n", |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 152 | self->start, self->end, self->name); |
| 153 | } |
| 154 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 155 | void dso__set_long_name(struct dso *self, char *name) |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 156 | { |
Arnaldo Carvalho de Melo | ef6ae72 | 2009-11-20 20:51:29 -0200 | [diff] [blame] | 157 | if (name == NULL) |
| 158 | return; |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 159 | self->long_name = name; |
| 160 | self->long_name_len = strlen(name); |
| 161 | } |
| 162 | |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 163 | static void dso__set_short_name(struct dso *self, const char *name) |
| 164 | { |
| 165 | if (name == NULL) |
| 166 | return; |
| 167 | self->short_name = name; |
| 168 | self->short_name_len = strlen(name); |
| 169 | } |
| 170 | |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 171 | static void dso__set_basename(struct dso *self) |
| 172 | { |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 173 | dso__set_short_name(self, basename(self->long_name)); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 174 | } |
| 175 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 176 | struct dso *dso__new(const char *name) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 177 | { |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 178 | struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 179 | |
| 180 | if (self != NULL) { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 181 | int i; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 182 | strcpy(self->name, name); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 183 | dso__set_long_name(self, self->name); |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 184 | dso__set_short_name(self, self->name); |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 185 | for (i = 0; i < MAP__NR_TYPES; ++i) |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 186 | self->symbols[i] = self->symbol_names[i] = RB_ROOT; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 187 | self->slen_calculated = 0; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 188 | self->origin = DSO__ORIG_NOT_FOUND; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 189 | self->loaded = 0; |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 190 | self->sorted_by_name = 0; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 191 | self->has_build_id = 0; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 192 | self->kernel = DSO_TYPE_USER; |
Masami Hiramatsu | 0ab061c | 2010-04-21 15:56:16 -0400 | [diff] [blame] | 193 | INIT_LIST_HEAD(&self->node); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | return self; |
| 197 | } |
| 198 | |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 199 | static void symbols__delete(struct rb_root *self) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 200 | { |
| 201 | struct symbol *pos; |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 202 | struct rb_node *next = rb_first(self); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 203 | |
| 204 | while (next) { |
| 205 | pos = rb_entry(next, struct symbol, rb_node); |
| 206 | next = rb_next(&pos->rb_node); |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 207 | rb_erase(&pos->rb_node, self); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 208 | symbol__delete(pos); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
| 212 | void dso__delete(struct dso *self) |
| 213 | { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 214 | int i; |
| 215 | for (i = 0; i < MAP__NR_TYPES; ++i) |
| 216 | symbols__delete(&self->symbols[i]); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 217 | if (self->long_name != self->name) |
| 218 | free(self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 219 | free(self); |
| 220 | } |
| 221 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 222 | void dso__set_build_id(struct dso *self, void *build_id) |
| 223 | { |
| 224 | memcpy(self->build_id, build_id, sizeof(self->build_id)); |
| 225 | self->has_build_id = 1; |
| 226 | } |
| 227 | |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 228 | static void symbols__insert(struct rb_root *self, struct symbol *sym) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 229 | { |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 230 | struct rb_node **p = &self->rb_node; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 231 | struct rb_node *parent = NULL; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 232 | const u64 ip = sym->start; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 233 | struct symbol *s; |
| 234 | |
| 235 | while (*p != NULL) { |
| 236 | parent = *p; |
| 237 | s = rb_entry(parent, struct symbol, rb_node); |
| 238 | if (ip < s->start) |
| 239 | p = &(*p)->rb_left; |
| 240 | else |
| 241 | p = &(*p)->rb_right; |
| 242 | } |
| 243 | rb_link_node(&sym->rb_node, parent, p); |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 244 | rb_insert_color(&sym->rb_node, self); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 245 | } |
| 246 | |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 247 | static struct symbol *symbols__find(struct rb_root *self, u64 ip) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 248 | { |
| 249 | struct rb_node *n; |
| 250 | |
| 251 | if (self == NULL) |
| 252 | return NULL; |
| 253 | |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 254 | n = self->rb_node; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 255 | |
| 256 | while (n) { |
| 257 | struct symbol *s = rb_entry(n, struct symbol, rb_node); |
| 258 | |
| 259 | if (ip < s->start) |
| 260 | n = n->rb_left; |
| 261 | else if (ip > s->end) |
| 262 | n = n->rb_right; |
| 263 | else |
| 264 | return s; |
| 265 | } |
| 266 | |
| 267 | return NULL; |
| 268 | } |
| 269 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 270 | struct symbol_name_rb_node { |
| 271 | struct rb_node rb_node; |
| 272 | struct symbol sym; |
| 273 | }; |
| 274 | |
| 275 | static void symbols__insert_by_name(struct rb_root *self, struct symbol *sym) |
| 276 | { |
| 277 | struct rb_node **p = &self->rb_node; |
| 278 | struct rb_node *parent = NULL; |
| 279 | struct symbol_name_rb_node *symn = ((void *)sym) - sizeof(*parent), *s; |
| 280 | |
| 281 | while (*p != NULL) { |
| 282 | parent = *p; |
| 283 | s = rb_entry(parent, struct symbol_name_rb_node, rb_node); |
| 284 | if (strcmp(sym->name, s->sym.name) < 0) |
| 285 | p = &(*p)->rb_left; |
| 286 | else |
| 287 | p = &(*p)->rb_right; |
| 288 | } |
| 289 | rb_link_node(&symn->rb_node, parent, p); |
| 290 | rb_insert_color(&symn->rb_node, self); |
| 291 | } |
| 292 | |
| 293 | static void symbols__sort_by_name(struct rb_root *self, struct rb_root *source) |
| 294 | { |
| 295 | struct rb_node *nd; |
| 296 | |
| 297 | for (nd = rb_first(source); nd; nd = rb_next(nd)) { |
| 298 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); |
| 299 | symbols__insert_by_name(self, pos); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | static struct symbol *symbols__find_by_name(struct rb_root *self, const char *name) |
| 304 | { |
| 305 | struct rb_node *n; |
| 306 | |
| 307 | if (self == NULL) |
| 308 | return NULL; |
| 309 | |
| 310 | n = self->rb_node; |
| 311 | |
| 312 | while (n) { |
| 313 | struct symbol_name_rb_node *s; |
| 314 | int cmp; |
| 315 | |
| 316 | s = rb_entry(n, struct symbol_name_rb_node, rb_node); |
| 317 | cmp = strcmp(name, s->sym.name); |
| 318 | |
| 319 | if (cmp < 0) |
| 320 | n = n->rb_left; |
| 321 | else if (cmp > 0) |
| 322 | n = n->rb_right; |
| 323 | else |
| 324 | return &s->sym; |
| 325 | } |
| 326 | |
| 327 | return NULL; |
| 328 | } |
| 329 | |
| 330 | struct symbol *dso__find_symbol(struct dso *self, |
| 331 | enum map_type type, u64 addr) |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 332 | { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 333 | return symbols__find(&self->symbols[type], addr); |
Arnaldo Carvalho de Melo | fcf1203 | 2009-11-24 13:01:52 -0200 | [diff] [blame] | 334 | } |
| 335 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 336 | struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type, |
| 337 | const char *name) |
| 338 | { |
| 339 | return symbols__find_by_name(&self->symbol_names[type], name); |
| 340 | } |
| 341 | |
| 342 | void dso__sort_by_name(struct dso *self, enum map_type type) |
| 343 | { |
| 344 | dso__set_sorted_by_name(self, type); |
| 345 | return symbols__sort_by_name(&self->symbol_names[type], |
| 346 | &self->symbols[type]); |
| 347 | } |
| 348 | |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 349 | int build_id__sprintf(const u8 *self, int len, char *bf) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 350 | { |
| 351 | char *bid = bf; |
Arnaldo Carvalho de Melo | ef12a14 | 2010-01-20 15:28:45 -0200 | [diff] [blame] | 352 | const u8 *raw = self; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 353 | int i; |
| 354 | |
| 355 | for (i = 0; i < len; ++i) { |
| 356 | sprintf(bid, "%02x", *raw); |
| 357 | ++raw; |
| 358 | bid += 2; |
| 359 | } |
| 360 | |
| 361 | return raw - self; |
| 362 | } |
| 363 | |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 364 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 365 | { |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 366 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 367 | |
| 368 | build_id__sprintf(self->build_id, sizeof(self->build_id), sbuild_id); |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 369 | return fprintf(fp, "%s", sbuild_id); |
| 370 | } |
| 371 | |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 372 | size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp) |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 373 | { |
| 374 | struct rb_node *nd; |
| 375 | size_t ret = fprintf(fp, "dso: %s (", self->short_name); |
| 376 | |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 377 | if (self->short_name != self->long_name) |
| 378 | ret += fprintf(fp, "%s, ", self->long_name); |
| 379 | ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type], |
| 380 | self->loaded ? "" : "NOT "); |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 381 | ret += dso__fprintf_buildid(self, fp); |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 382 | ret += fprintf(fp, ")\n"); |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 383 | for (nd = rb_first(&self->symbols[type]); nd; nd = rb_next(nd)) { |
| 384 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); |
| 385 | ret += symbol__fprintf(pos, fp); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | return ret; |
| 389 | } |
| 390 | |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 391 | int kallsyms__parse(const char *filename, void *arg, |
| 392 | int (*process_symbol)(void *arg, const char *name, |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 393 | char type, u64 start)) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 394 | { |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 395 | char *line = NULL; |
| 396 | size_t n; |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 397 | int err = 0; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 398 | FILE *file = fopen(filename, "r"); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 399 | |
| 400 | if (file == NULL) |
| 401 | goto out_failure; |
| 402 | |
| 403 | while (!feof(file)) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 404 | u64 start; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 405 | int line_len, len; |
| 406 | char symbol_type; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 407 | char *symbol_name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 408 | |
| 409 | line_len = getline(&line, &n, file); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 410 | if (line_len < 0 || !line) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 411 | break; |
| 412 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 413 | line[--line_len] = '\0'; /* \n */ |
| 414 | |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 415 | len = hex2u64(line, &start); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 416 | |
| 417 | len++; |
| 418 | if (len + 2 >= line_len) |
| 419 | continue; |
| 420 | |
| 421 | symbol_type = toupper(line[len]); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 422 | symbol_name = line + len + 2; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 423 | |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 424 | err = process_symbol(arg, symbol_name, symbol_type, start); |
| 425 | if (err) |
| 426 | break; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | free(line); |
| 430 | fclose(file); |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 431 | return err; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 432 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 433 | out_failure: |
| 434 | return -1; |
| 435 | } |
| 436 | |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 437 | struct process_kallsyms_args { |
| 438 | struct map *map; |
| 439 | struct dso *dso; |
| 440 | }; |
| 441 | |
| 442 | static int map__process_kallsym_symbol(void *arg, const char *name, |
| 443 | char type, u64 start) |
| 444 | { |
| 445 | struct symbol *sym; |
| 446 | struct process_kallsyms_args *a = arg; |
| 447 | struct rb_root *root = &a->dso->symbols[a->map->type]; |
| 448 | |
| 449 | if (!symbol_type__is_a(type, a->map->type)) |
| 450 | return 0; |
| 451 | |
| 452 | /* |
| 453 | * Will fix up the end later, when we have all symbols sorted. |
| 454 | */ |
| 455 | sym = symbol__new(start, 0, name); |
| 456 | |
| 457 | if (sym == NULL) |
| 458 | return -ENOMEM; |
| 459 | /* |
| 460 | * We will pass the symbols to the filter later, in |
| 461 | * map__split_kallsyms, when we have split the maps per module |
| 462 | */ |
| 463 | symbols__insert(root, sym); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 464 | |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * Loads the function entries in /proc/kallsyms into kernel_map->dso, |
| 470 | * so that we can in the next step set the symbol ->end address and then |
| 471 | * call kernel_maps__split_kallsyms. |
| 472 | */ |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 473 | static int dso__load_all_kallsyms(struct dso *self, const char *filename, |
| 474 | struct map *map) |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 475 | { |
| 476 | struct process_kallsyms_args args = { .map = map, .dso = self, }; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 477 | return kallsyms__parse(filename, &args, map__process_kallsym_symbol); |
Arnaldo Carvalho de Melo | 682b335 | 2010-01-04 16:19:26 -0200 | [diff] [blame] | 478 | } |
| 479 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 480 | /* |
| 481 | * Split the symbols into maps, making sure there are no overlaps, i.e. the |
| 482 | * kernel range is broken in several maps, named [kernel].N, as we don't have |
| 483 | * the original ELF section names vmlinux have. |
| 484 | */ |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 485 | static int dso__split_kallsyms(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 486 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 487 | { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 488 | struct map_groups *kmaps = map__kmap(map)->kmaps; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 489 | struct machine *machine = kmaps->machine; |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 490 | struct map *curr_map = map; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 491 | struct symbol *pos; |
| 492 | int count = 0; |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 493 | struct rb_root *root = &self->symbols[map->type]; |
| 494 | struct rb_node *next = rb_first(root); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 495 | int kernel_range = 0; |
| 496 | |
| 497 | while (next) { |
| 498 | char *module; |
| 499 | |
| 500 | pos = rb_entry(next, struct symbol, rb_node); |
| 501 | next = rb_next(&pos->rb_node); |
| 502 | |
| 503 | module = strchr(pos->name, '\t'); |
| 504 | if (module) { |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 505 | if (!symbol_conf.use_modules) |
Arnaldo Carvalho de Melo | 1de8e24 | 2009-11-27 16:29:21 -0200 | [diff] [blame] | 506 | goto discard_symbol; |
| 507 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 508 | *module++ = '\0'; |
| 509 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 510 | if (strcmp(curr_map->dso->short_name, module)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 511 | if (curr_map != map && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 512 | self->kernel == DSO_TYPE_GUEST_KERNEL && |
| 513 | machine__is_default_guest(machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 514 | /* |
| 515 | * We assume all symbols of a module are |
| 516 | * continuous in * kallsyms, so curr_map |
| 517 | * points to a module and all its |
| 518 | * symbols are in its kmap. Mark it as |
| 519 | * loaded. |
| 520 | */ |
| 521 | dso__set_loaded(curr_map->dso, |
| 522 | curr_map->type); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 523 | } |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 524 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 525 | curr_map = map_groups__find_by_name(kmaps, |
| 526 | map->type, module); |
| 527 | if (curr_map == NULL) { |
| 528 | pr_err("%s/proc/{kallsyms,modules} " |
| 529 | "inconsistency while looking " |
| 530 | "for \"%s\" module!\n", |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 531 | machine->root_dir, module); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 532 | curr_map = map; |
| 533 | goto discard_symbol; |
| 534 | } |
| 535 | |
| 536 | if (curr_map->dso->loaded && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 537 | !machine__is_default_guest(machine)) |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 538 | goto discard_symbol; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 539 | } |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 540 | /* |
| 541 | * So that we look just like we get from .ko files, |
| 542 | * i.e. not prelinked, relative to map->start. |
| 543 | */ |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 544 | pos->start = curr_map->map_ip(curr_map, pos->start); |
| 545 | pos->end = curr_map->map_ip(curr_map, pos->end); |
| 546 | } else if (curr_map != map) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 547 | char dso_name[PATH_MAX]; |
| 548 | struct dso *dso; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 549 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 550 | if (self->kernel == DSO_TYPE_GUEST_KERNEL) |
| 551 | snprintf(dso_name, sizeof(dso_name), |
| 552 | "[guest.kernel].%d", |
| 553 | kernel_range++); |
| 554 | else |
| 555 | snprintf(dso_name, sizeof(dso_name), |
| 556 | "[kernel].%d", |
| 557 | kernel_range++); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 558 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 559 | dso = dso__new(dso_name); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 560 | if (dso == NULL) |
| 561 | return -1; |
| 562 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 563 | dso->kernel = self->kernel; |
| 564 | |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 565 | curr_map = map__new2(pos->start, dso, map->type); |
Zhang, Yanmin | 37fe5fc | 2010-02-25 11:00:51 +0800 | [diff] [blame] | 566 | if (curr_map == NULL) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 567 | dso__delete(dso); |
| 568 | return -1; |
| 569 | } |
| 570 | |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 571 | curr_map->map_ip = curr_map->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 572 | map_groups__insert(kmaps, curr_map); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 573 | ++kernel_range; |
| 574 | } |
| 575 | |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 576 | if (filter && filter(curr_map, pos)) { |
Arnaldo Carvalho de Melo | 1de8e24 | 2009-11-27 16:29:21 -0200 | [diff] [blame] | 577 | discard_symbol: rb_erase(&pos->rb_node, root); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 578 | symbol__delete(pos); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 579 | } else { |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 580 | if (curr_map != map) { |
| 581 | rb_erase(&pos->rb_node, root); |
| 582 | symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 583 | } |
Mike Galbraith | 9974f49 | 2009-07-02 08:05:58 +0200 | [diff] [blame] | 584 | count++; |
| 585 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 586 | } |
| 587 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 588 | if (curr_map != map && |
| 589 | self->kernel == DSO_TYPE_GUEST_KERNEL && |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 590 | machine__is_default_guest(kmaps->machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 591 | dso__set_loaded(curr_map->dso, curr_map->type); |
| 592 | } |
| 593 | |
Mike Galbraith | 9974f49 | 2009-07-02 08:05:58 +0200 | [diff] [blame] | 594 | return count; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 595 | } |
| 596 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 597 | int dso__load_kallsyms(struct dso *self, const char *filename, |
| 598 | struct map *map, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 599 | { |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 600 | if (dso__load_all_kallsyms(self, filename, map) < 0) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 601 | return -1; |
| 602 | |
Arnaldo Carvalho de Melo | 4e06255 | 2009-11-27 16:29:18 -0200 | [diff] [blame] | 603 | symbols__fixup_end(&self->symbols[map->type]); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 604 | if (self->kernel == DSO_TYPE_GUEST_KERNEL) |
| 605 | self->origin = DSO__ORIG_GUEST_KERNEL; |
| 606 | else |
| 607 | self->origin = DSO__ORIG_KERNEL; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 608 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 609 | return dso__split_kallsyms(self, map, filter); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 610 | } |
| 611 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 612 | static int dso__load_perf_map(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 613 | symbol_filter_t filter) |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 614 | { |
| 615 | char *line = NULL; |
| 616 | size_t n; |
| 617 | FILE *file; |
| 618 | int nr_syms = 0; |
| 619 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 620 | file = fopen(self->long_name, "r"); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 621 | if (file == NULL) |
| 622 | goto out_failure; |
| 623 | |
| 624 | while (!feof(file)) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 625 | u64 start, size; |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 626 | struct symbol *sym; |
| 627 | int line_len, len; |
| 628 | |
| 629 | line_len = getline(&line, &n, file); |
| 630 | if (line_len < 0) |
| 631 | break; |
| 632 | |
| 633 | if (!line) |
| 634 | goto out_failure; |
| 635 | |
| 636 | line[--line_len] = '\0'; /* \n */ |
| 637 | |
| 638 | len = hex2u64(line, &start); |
| 639 | |
| 640 | len++; |
| 641 | if (len + 2 >= line_len) |
| 642 | continue; |
| 643 | |
| 644 | len += hex2u64(line + len, &size); |
| 645 | |
| 646 | len++; |
| 647 | if (len + 2 >= line_len) |
| 648 | continue; |
| 649 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 650 | sym = symbol__new(start, size, line + len); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 651 | |
| 652 | if (sym == NULL) |
| 653 | goto out_delete_line; |
| 654 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 655 | if (filter && filter(map, sym)) |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 656 | symbol__delete(sym); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 657 | else { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 658 | symbols__insert(&self->symbols[map->type], sym); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 659 | nr_syms++; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | free(line); |
| 664 | fclose(file); |
| 665 | |
| 666 | return nr_syms; |
| 667 | |
| 668 | out_delete_line: |
| 669 | free(line); |
| 670 | out_failure: |
| 671 | return -1; |
| 672 | } |
| 673 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 674 | /** |
| 675 | * elf_symtab__for_each_symbol - iterate thru all the symbols |
| 676 | * |
| 677 | * @self: struct elf_symtab instance to iterate |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 678 | * @idx: uint32_t idx |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 679 | * @sym: GElf_Sym iterator |
| 680 | */ |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 681 | #define elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) \ |
| 682 | for (idx = 0, gelf_getsym(syms, idx, &sym);\ |
| 683 | idx < nr_syms; \ |
| 684 | idx++, gelf_getsym(syms, idx, &sym)) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 685 | |
| 686 | static inline uint8_t elf_sym__type(const GElf_Sym *sym) |
| 687 | { |
| 688 | return GELF_ST_TYPE(sym->st_info); |
| 689 | } |
| 690 | |
| 691 | static inline int elf_sym__is_function(const GElf_Sym *sym) |
| 692 | { |
| 693 | return elf_sym__type(sym) == STT_FUNC && |
| 694 | sym->st_name != 0 && |
Arnaldo Carvalho de Melo | 8183313 | 2009-10-05 23:35:03 -0300 | [diff] [blame] | 695 | sym->st_shndx != SHN_UNDEF; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 696 | } |
| 697 | |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 698 | static inline bool elf_sym__is_object(const GElf_Sym *sym) |
| 699 | { |
| 700 | return elf_sym__type(sym) == STT_OBJECT && |
| 701 | sym->st_name != 0 && |
| 702 | sym->st_shndx != SHN_UNDEF; |
| 703 | } |
| 704 | |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 705 | static inline int elf_sym__is_label(const GElf_Sym *sym) |
| 706 | { |
| 707 | return elf_sym__type(sym) == STT_NOTYPE && |
| 708 | sym->st_name != 0 && |
| 709 | sym->st_shndx != SHN_UNDEF && |
| 710 | sym->st_shndx != SHN_ABS; |
| 711 | } |
| 712 | |
| 713 | static inline const char *elf_sec__name(const GElf_Shdr *shdr, |
| 714 | const Elf_Data *secstrs) |
| 715 | { |
| 716 | return secstrs->d_buf + shdr->sh_name; |
| 717 | } |
| 718 | |
| 719 | static inline int elf_sec__is_text(const GElf_Shdr *shdr, |
| 720 | const Elf_Data *secstrs) |
| 721 | { |
| 722 | return strstr(elf_sec__name(shdr, secstrs), "text") != NULL; |
| 723 | } |
| 724 | |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 725 | static inline bool elf_sec__is_data(const GElf_Shdr *shdr, |
| 726 | const Elf_Data *secstrs) |
| 727 | { |
| 728 | return strstr(elf_sec__name(shdr, secstrs), "data") != NULL; |
| 729 | } |
| 730 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 731 | static inline const char *elf_sym__name(const GElf_Sym *sym, |
| 732 | const Elf_Data *symstrs) |
| 733 | { |
| 734 | return symstrs->d_buf + sym->st_name; |
| 735 | } |
| 736 | |
| 737 | static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, |
| 738 | GElf_Shdr *shp, const char *name, |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 739 | size_t *idx) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 740 | { |
| 741 | Elf_Scn *sec = NULL; |
| 742 | size_t cnt = 1; |
| 743 | |
| 744 | while ((sec = elf_nextscn(elf, sec)) != NULL) { |
| 745 | char *str; |
| 746 | |
| 747 | gelf_getshdr(sec, shp); |
| 748 | str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); |
| 749 | if (!strcmp(name, str)) { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 750 | if (idx) |
| 751 | *idx = cnt; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | ++cnt; |
| 755 | } |
| 756 | |
| 757 | return sec; |
| 758 | } |
| 759 | |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 760 | #define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \ |
| 761 | for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \ |
| 762 | idx < nr_entries; \ |
| 763 | ++idx, pos = gelf_getrel(reldata, idx, &pos_mem)) |
| 764 | |
| 765 | #define elf_section__for_each_rela(reldata, pos, pos_mem, idx, nr_entries) \ |
| 766 | for (idx = 0, pos = gelf_getrela(reldata, 0, &pos_mem); \ |
| 767 | idx < nr_entries; \ |
| 768 | ++idx, pos = gelf_getrela(reldata, idx, &pos_mem)) |
| 769 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 770 | /* |
| 771 | * We need to check if we have a .dynsym, so that we can handle the |
| 772 | * .plt, synthesizing its symbols, that aren't on the symtabs (be it |
| 773 | * .dynsym or .symtab). |
| 774 | * And always look at the original dso, not at debuginfo packages, that |
| 775 | * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS). |
| 776 | */ |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 777 | static int dso__synthesize_plt_symbols(struct dso *self, struct map *map, |
| 778 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 779 | { |
| 780 | uint32_t nr_rel_entries, idx; |
| 781 | GElf_Sym sym; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 782 | u64 plt_offset; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 783 | GElf_Shdr shdr_plt; |
| 784 | struct symbol *f; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 785 | GElf_Shdr shdr_rel_plt, shdr_dynsym; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 786 | Elf_Data *reldata, *syms, *symstrs; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 787 | Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym; |
| 788 | size_t dynsym_idx; |
| 789 | GElf_Ehdr ehdr; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 790 | char sympltname[1024]; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 791 | Elf *elf; |
| 792 | int nr = 0, symidx, fd, err = 0; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 793 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 794 | fd = open(self->long_name, O_RDONLY); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 795 | if (fd < 0) |
| 796 | goto out; |
| 797 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 798 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 799 | if (elf == NULL) |
| 800 | goto out_close; |
| 801 | |
| 802 | if (gelf_getehdr(elf, &ehdr) == NULL) |
| 803 | goto out_elf_end; |
| 804 | |
| 805 | scn_dynsym = elf_section_by_name(elf, &ehdr, &shdr_dynsym, |
| 806 | ".dynsym", &dynsym_idx); |
| 807 | if (scn_dynsym == NULL) |
| 808 | goto out_elf_end; |
| 809 | |
| 810 | scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 811 | ".rela.plt", NULL); |
| 812 | if (scn_plt_rel == NULL) { |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 813 | scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 814 | ".rel.plt", NULL); |
| 815 | if (scn_plt_rel == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 816 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 817 | } |
| 818 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 819 | err = -1; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 820 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 821 | if (shdr_rel_plt.sh_link != dynsym_idx) |
| 822 | goto out_elf_end; |
| 823 | |
| 824 | if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL) |
| 825 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 826 | |
| 827 | /* |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 828 | * Fetch the relocation section to find the idxes to the GOT |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 829 | * and the symbols in the .dynsym they refer to. |
| 830 | */ |
| 831 | reldata = elf_getdata(scn_plt_rel, NULL); |
| 832 | if (reldata == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 833 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 834 | |
| 835 | syms = elf_getdata(scn_dynsym, NULL); |
| 836 | if (syms == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 837 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 838 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 839 | scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link); |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 840 | if (scn_symstrs == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 841 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 842 | |
| 843 | symstrs = elf_getdata(scn_symstrs, NULL); |
| 844 | if (symstrs == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 845 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 846 | |
| 847 | nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize; |
| 848 | plt_offset = shdr_plt.sh_offset; |
| 849 | |
| 850 | if (shdr_rel_plt.sh_type == SHT_RELA) { |
| 851 | GElf_Rela pos_mem, *pos; |
| 852 | |
| 853 | elf_section__for_each_rela(reldata, pos, pos_mem, idx, |
| 854 | nr_rel_entries) { |
| 855 | symidx = GELF_R_SYM(pos->r_info); |
| 856 | plt_offset += shdr_plt.sh_entsize; |
| 857 | gelf_getsym(syms, symidx, &sym); |
| 858 | snprintf(sympltname, sizeof(sympltname), |
| 859 | "%s@plt", elf_sym__name(&sym, symstrs)); |
| 860 | |
| 861 | f = symbol__new(plt_offset, shdr_plt.sh_entsize, |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 862 | sympltname); |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 863 | if (!f) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 864 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 865 | |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 866 | if (filter && filter(map, f)) |
| 867 | symbol__delete(f); |
| 868 | else { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 869 | symbols__insert(&self->symbols[map->type], f); |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 870 | ++nr; |
| 871 | } |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 872 | } |
| 873 | } else if (shdr_rel_plt.sh_type == SHT_REL) { |
| 874 | GElf_Rel pos_mem, *pos; |
| 875 | elf_section__for_each_rel(reldata, pos, pos_mem, idx, |
| 876 | nr_rel_entries) { |
| 877 | symidx = GELF_R_SYM(pos->r_info); |
| 878 | plt_offset += shdr_plt.sh_entsize; |
| 879 | gelf_getsym(syms, symidx, &sym); |
| 880 | snprintf(sympltname, sizeof(sympltname), |
| 881 | "%s@plt", elf_sym__name(&sym, symstrs)); |
| 882 | |
| 883 | f = symbol__new(plt_offset, shdr_plt.sh_entsize, |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 884 | sympltname); |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 885 | if (!f) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 886 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 887 | |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 888 | if (filter && filter(map, f)) |
| 889 | symbol__delete(f); |
| 890 | else { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 891 | symbols__insert(&self->symbols[map->type], f); |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 892 | ++nr; |
| 893 | } |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 894 | } |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 895 | } |
| 896 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 897 | err = 0; |
| 898 | out_elf_end: |
| 899 | elf_end(elf); |
| 900 | out_close: |
| 901 | close(fd); |
| 902 | |
| 903 | if (err == 0) |
| 904 | return nr; |
| 905 | out: |
Arnaldo Carvalho de Melo | fe2197b | 2010-03-11 20:12:40 -0300 | [diff] [blame] | 906 | pr_debug("%s: problems reading %s PLT info.\n", |
| 907 | __func__, self->long_name); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 908 | return 0; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 909 | } |
| 910 | |
Arnaldo Carvalho de Melo | d45868d | 2009-12-11 14:50:38 -0200 | [diff] [blame] | 911 | static bool elf_sym__is_a(GElf_Sym *self, enum map_type type) |
| 912 | { |
| 913 | switch (type) { |
| 914 | case MAP__FUNCTION: |
| 915 | return elf_sym__is_function(self); |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 916 | case MAP__VARIABLE: |
| 917 | return elf_sym__is_object(self); |
Arnaldo Carvalho de Melo | d45868d | 2009-12-11 14:50:38 -0200 | [diff] [blame] | 918 | default: |
| 919 | return false; |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | static bool elf_sec__is_a(GElf_Shdr *self, Elf_Data *secstrs, enum map_type type) |
| 924 | { |
| 925 | switch (type) { |
| 926 | case MAP__FUNCTION: |
| 927 | return elf_sec__is_text(self, secstrs); |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 928 | case MAP__VARIABLE: |
| 929 | return elf_sec__is_data(self, secstrs); |
Arnaldo Carvalho de Melo | d45868d | 2009-12-11 14:50:38 -0200 | [diff] [blame] | 930 | default: |
| 931 | return false; |
| 932 | } |
| 933 | } |
| 934 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 935 | static int dso__load_sym(struct dso *self, struct map *map, const char *name, |
| 936 | int fd, symbol_filter_t filter, int kmodule) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 937 | { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 938 | struct kmap *kmap = self->kernel ? map__kmap(map) : NULL; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 939 | struct map *curr_map = map; |
| 940 | struct dso *curr_dso = self; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 941 | Elf_Data *symstrs, *secstrs; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 942 | uint32_t nr_syms; |
| 943 | int err = -1; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 944 | uint32_t idx; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 945 | GElf_Ehdr ehdr; |
| 946 | GElf_Shdr shdr; |
| 947 | Elf_Data *syms; |
| 948 | GElf_Sym sym; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 949 | Elf_Scn *sec, *sec_strndx; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 950 | Elf *elf; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 951 | int nr = 0; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 952 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 953 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 954 | if (elf == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 955 | pr_err("%s: cannot read %s ELF file.\n", __func__, name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 956 | goto out_close; |
| 957 | } |
| 958 | |
| 959 | if (gelf_getehdr(elf, &ehdr) == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 960 | pr_err("%s: cannot get elf header.\n", __func__); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 961 | goto out_elf_end; |
| 962 | } |
| 963 | |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 964 | sec = elf_section_by_name(elf, &ehdr, &shdr, ".symtab", NULL); |
| 965 | if (sec == NULL) { |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 966 | sec = elf_section_by_name(elf, &ehdr, &shdr, ".dynsym", NULL); |
| 967 | if (sec == NULL) |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 968 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 969 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 970 | |
| 971 | syms = elf_getdata(sec, NULL); |
| 972 | if (syms == NULL) |
| 973 | goto out_elf_end; |
| 974 | |
| 975 | sec = elf_getscn(elf, shdr.sh_link); |
| 976 | if (sec == NULL) |
| 977 | goto out_elf_end; |
| 978 | |
| 979 | symstrs = elf_getdata(sec, NULL); |
| 980 | if (symstrs == NULL) |
| 981 | goto out_elf_end; |
| 982 | |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 983 | sec_strndx = elf_getscn(elf, ehdr.e_shstrndx); |
| 984 | if (sec_strndx == NULL) |
| 985 | goto out_elf_end; |
| 986 | |
| 987 | secstrs = elf_getdata(sec_strndx, NULL); |
Stoyan Gaydarov | 9b30a26 | 2009-07-30 05:25:29 -0500 | [diff] [blame] | 988 | if (secstrs == NULL) |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 989 | goto out_elf_end; |
| 990 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 991 | nr_syms = shdr.sh_size / shdr.sh_entsize; |
| 992 | |
Arjan van de Ven | e9fbc9d | 2009-06-06 21:22:33 +0200 | [diff] [blame] | 993 | memset(&sym, 0, sizeof(sym)); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 994 | if (self->kernel == DSO_TYPE_USER) { |
Mike Galbraith | d20ff6b | 2009-07-20 14:01:38 +0200 | [diff] [blame] | 995 | self->adjust_symbols = (ehdr.e_type == ET_EXEC || |
Arnaldo Carvalho de Melo | 30d7a77 | 2009-07-02 21:24:14 -0300 | [diff] [blame] | 996 | elf_section_by_name(elf, &ehdr, &shdr, |
| 997 | ".gnu.prelink_undo", |
| 998 | NULL) != NULL); |
Mike Galbraith | d20ff6b | 2009-07-20 14:01:38 +0200 | [diff] [blame] | 999 | } else self->adjust_symbols = 0; |
| 1000 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 1001 | elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) { |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1002 | struct symbol *f; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1003 | const char *elf_name = elf_sym__name(&sym, symstrs); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1004 | char *demangled = NULL; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1005 | int is_label = elf_sym__is_label(&sym); |
| 1006 | const char *section_name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1007 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1008 | if (kmap && kmap->ref_reloc_sym && kmap->ref_reloc_sym->name && |
| 1009 | strcmp(elf_name, kmap->ref_reloc_sym->name) == 0) |
| 1010 | kmap->ref_reloc_sym->unrelocated_addr = sym.st_value; |
Arnaldo Carvalho de Melo | 56b03f3 | 2010-01-05 16:50:31 -0200 | [diff] [blame] | 1011 | |
Arnaldo Carvalho de Melo | d45868d | 2009-12-11 14:50:38 -0200 | [diff] [blame] | 1012 | if (!is_label && !elf_sym__is_a(&sym, map->type)) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1013 | continue; |
| 1014 | |
| 1015 | sec = elf_getscn(elf, sym.st_shndx); |
| 1016 | if (!sec) |
| 1017 | goto out_elf_end; |
| 1018 | |
| 1019 | gelf_getshdr(sec, &shdr); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1020 | |
Arnaldo Carvalho de Melo | d45868d | 2009-12-11 14:50:38 -0200 | [diff] [blame] | 1021 | if (is_label && !elf_sec__is_a(&shdr, secstrs, map->type)) |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1022 | continue; |
| 1023 | |
| 1024 | section_name = elf_sec__name(&shdr, secstrs); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 1025 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1026 | if (self->kernel != DSO_TYPE_USER || kmodule) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1027 | char dso_name[PATH_MAX]; |
| 1028 | |
| 1029 | if (strcmp(section_name, |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 1030 | (curr_dso->short_name + |
| 1031 | self->short_name_len)) == 0) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1032 | goto new_symbol; |
| 1033 | |
| 1034 | if (strcmp(section_name, ".text") == 0) { |
| 1035 | curr_map = map; |
| 1036 | curr_dso = self; |
| 1037 | goto new_symbol; |
| 1038 | } |
| 1039 | |
| 1040 | snprintf(dso_name, sizeof(dso_name), |
| 1041 | "%s%s", self->short_name, section_name); |
| 1042 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1043 | curr_map = map_groups__find_by_name(kmap->kmaps, map->type, dso_name); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1044 | if (curr_map == NULL) { |
| 1045 | u64 start = sym.st_value; |
| 1046 | |
| 1047 | if (kmodule) |
| 1048 | start += map->start + shdr.sh_offset; |
| 1049 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1050 | curr_dso = dso__new(dso_name); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1051 | if (curr_dso == NULL) |
| 1052 | goto out_elf_end; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1053 | curr_dso->kernel = self->kernel; |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 1054 | curr_map = map__new2(start, curr_dso, |
Arnaldo Carvalho de Melo | 6275ce2 | 2010-02-03 16:52:01 -0200 | [diff] [blame] | 1055 | map->type); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1056 | if (curr_map == NULL) { |
| 1057 | dso__delete(curr_dso); |
| 1058 | goto out_elf_end; |
| 1059 | } |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 1060 | curr_map->map_ip = identity__map_ip; |
| 1061 | curr_map->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 1062 | curr_dso->origin = self->origin; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1063 | map_groups__insert(kmap->kmaps, curr_map); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1064 | dsos__add(&self->node, curr_dso); |
Arnaldo Carvalho de Melo | 6275ce2 | 2010-02-03 16:52:01 -0200 | [diff] [blame] | 1065 | dso__set_loaded(curr_dso, map->type); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1066 | } else |
| 1067 | curr_dso = curr_map->dso; |
| 1068 | |
| 1069 | goto new_symbol; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 1070 | } |
| 1071 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1072 | if (curr_dso->adjust_symbols) { |
Arnaldo Carvalho de Melo | 29a9f66 | 2010-02-03 16:52:06 -0200 | [diff] [blame] | 1073 | pr_debug4("%s: adjusting symbol: st_value: %#Lx " |
| 1074 | "sh_addr: %#Lx sh_offset: %#Lx\n", __func__, |
| 1075 | (u64)sym.st_value, (u64)shdr.sh_addr, |
| 1076 | (u64)shdr.sh_offset); |
Arnaldo Carvalho de Melo | f5812a7 | 2009-06-30 11:43:17 -0300 | [diff] [blame] | 1077 | sym.st_value -= shdr.sh_addr - shdr.sh_offset; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 1078 | } |
Arnaldo Carvalho de Melo | 28ac909 | 2009-07-20 14:14:12 -0300 | [diff] [blame] | 1079 | /* |
| 1080 | * We need to figure out if the object was created from C++ sources |
| 1081 | * DWARF DW_compile_unit has this, but we don't always have access |
| 1082 | * to it... |
| 1083 | */ |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 1084 | demangled = bfd_demangle(NULL, elf_name, DMGL_PARAMS | DMGL_ANSI); |
Arnaldo Carvalho de Melo | 28ac909 | 2009-07-20 14:14:12 -0300 | [diff] [blame] | 1085 | if (demangled != NULL) |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 1086 | elf_name = demangled; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1087 | new_symbol: |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1088 | f = symbol__new(sym.st_value, sym.st_size, elf_name); |
Arnaldo Carvalho de Melo | 28ac909 | 2009-07-20 14:14:12 -0300 | [diff] [blame] | 1089 | free(demangled); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1090 | if (!f) |
| 1091 | goto out_elf_end; |
| 1092 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1093 | if (filter && filter(curr_map, f)) |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1094 | symbol__delete(f); |
Arnaldo Carvalho de Melo | 69ee69f | 2009-05-28 14:55:26 -0300 | [diff] [blame] | 1095 | else { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 1096 | symbols__insert(&curr_dso->symbols[curr_map->type], f); |
Arnaldo Carvalho de Melo | 69ee69f | 2009-05-28 14:55:26 -0300 | [diff] [blame] | 1097 | nr++; |
| 1098 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1099 | } |
| 1100 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1101 | /* |
| 1102 | * For misannotated, zeroed, ASM function sizes. |
| 1103 | */ |
Arnaldo Carvalho de Melo | 6275ce2 | 2010-02-03 16:52:01 -0200 | [diff] [blame] | 1104 | if (nr > 0) { |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 1105 | symbols__fixup_end(&self->symbols[map->type]); |
Arnaldo Carvalho de Melo | 6275ce2 | 2010-02-03 16:52:01 -0200 | [diff] [blame] | 1106 | if (kmap) { |
| 1107 | /* |
| 1108 | * We need to fixup this here too because we create new |
| 1109 | * maps here, for things like vsyscall sections. |
| 1110 | */ |
| 1111 | __map_groups__fixup_end(kmap->kmaps, map->type); |
| 1112 | } |
| 1113 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1114 | err = nr; |
| 1115 | out_elf_end: |
| 1116 | elf_end(elf); |
| 1117 | out_close: |
| 1118 | return err; |
| 1119 | } |
| 1120 | |
Arnaldo Carvalho de Melo | 78075ca | 2009-11-20 20:51:26 -0200 | [diff] [blame] | 1121 | static bool dso__build_id_equal(const struct dso *self, u8 *build_id) |
| 1122 | { |
| 1123 | return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0; |
| 1124 | } |
| 1125 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1126 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits) |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 1127 | { |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 1128 | bool have_build_id = false; |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 1129 | struct dso *pos; |
| 1130 | |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1131 | list_for_each_entry(pos, head, node) { |
| 1132 | if (with_hits && !pos->hit) |
| 1133 | continue; |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 1134 | if (filename__read_build_id(pos->long_name, pos->build_id, |
| 1135 | sizeof(pos->build_id)) > 0) { |
| 1136 | have_build_id = true; |
| 1137 | pos->has_build_id = true; |
| 1138 | } |
Arnaldo Carvalho de Melo | 6122e4e | 2010-02-03 16:52:05 -0200 | [diff] [blame] | 1139 | } |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 1140 | |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 1141 | return have_build_id; |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1144 | /* |
| 1145 | * Align offset to 4 bytes as needed for note name and descriptor data. |
| 1146 | */ |
| 1147 | #define NOTE_ALIGN(n) (((n) + 3) & -4U) |
| 1148 | |
Arnaldo Carvalho de Melo | 2643ce114 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 1149 | int filename__read_build_id(const char *filename, void *bf, size_t size) |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1150 | { |
Arnaldo Carvalho de Melo | 2643ce114 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 1151 | int fd, err = -1; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1152 | GElf_Ehdr ehdr; |
| 1153 | GElf_Shdr shdr; |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1154 | Elf_Data *data; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1155 | Elf_Scn *sec; |
Pekka Enberg | e57cfcd | 2009-11-22 12:29:44 +0200 | [diff] [blame] | 1156 | Elf_Kind ek; |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1157 | void *ptr; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1158 | Elf *elf; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1159 | |
Arnaldo Carvalho de Melo | 2643ce114 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 1160 | if (size < BUILD_ID_SIZE) |
| 1161 | goto out; |
| 1162 | |
| 1163 | fd = open(filename, O_RDONLY); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1164 | if (fd < 0) |
| 1165 | goto out; |
| 1166 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 1167 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1168 | if (elf == NULL) { |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1169 | pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1170 | goto out_close; |
| 1171 | } |
| 1172 | |
Pekka Enberg | e57cfcd | 2009-11-22 12:29:44 +0200 | [diff] [blame] | 1173 | ek = elf_kind(elf); |
| 1174 | if (ek != ELF_K_ELF) |
| 1175 | goto out_elf_end; |
| 1176 | |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1177 | if (gelf_getehdr(elf, &ehdr) == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1178 | pr_err("%s: cannot get elf header.\n", __func__); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1179 | goto out_elf_end; |
| 1180 | } |
| 1181 | |
Arnaldo Carvalho de Melo | 2643ce114 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 1182 | sec = elf_section_by_name(elf, &ehdr, &shdr, |
| 1183 | ".note.gnu.build-id", NULL); |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1184 | if (sec == NULL) { |
| 1185 | sec = elf_section_by_name(elf, &ehdr, &shdr, |
| 1186 | ".notes", NULL); |
| 1187 | if (sec == NULL) |
| 1188 | goto out_elf_end; |
| 1189 | } |
| 1190 | |
| 1191 | data = elf_getdata(sec, NULL); |
| 1192 | if (data == NULL) |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1193 | goto out_elf_end; |
| 1194 | |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1195 | ptr = data->d_buf; |
| 1196 | while (ptr < (data->d_buf + data->d_size)) { |
| 1197 | GElf_Nhdr *nhdr = ptr; |
| 1198 | int namesz = NOTE_ALIGN(nhdr->n_namesz), |
| 1199 | descsz = NOTE_ALIGN(nhdr->n_descsz); |
| 1200 | const char *name; |
| 1201 | |
| 1202 | ptr += sizeof(*nhdr); |
| 1203 | name = ptr; |
| 1204 | ptr += namesz; |
| 1205 | if (nhdr->n_type == NT_GNU_BUILD_ID && |
| 1206 | nhdr->n_namesz == sizeof("GNU")) { |
| 1207 | if (memcmp(name, "GNU", sizeof("GNU")) == 0) { |
| 1208 | memcpy(bf, ptr, BUILD_ID_SIZE); |
| 1209 | err = BUILD_ID_SIZE; |
| 1210 | break; |
| 1211 | } |
| 1212 | } |
| 1213 | ptr += descsz; |
| 1214 | } |
Arnaldo Carvalho de Melo | 2643ce114 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 1215 | out_elf_end: |
| 1216 | elf_end(elf); |
| 1217 | out_close: |
| 1218 | close(fd); |
| 1219 | out: |
| 1220 | return err; |
| 1221 | } |
| 1222 | |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 1223 | int sysfs__read_build_id(const char *filename, void *build_id, size_t size) |
| 1224 | { |
| 1225 | int fd, err = -1; |
| 1226 | |
| 1227 | if (size < BUILD_ID_SIZE) |
| 1228 | goto out; |
| 1229 | |
| 1230 | fd = open(filename, O_RDONLY); |
| 1231 | if (fd < 0) |
| 1232 | goto out; |
| 1233 | |
| 1234 | while (1) { |
| 1235 | char bf[BUFSIZ]; |
| 1236 | GElf_Nhdr nhdr; |
| 1237 | int namesz, descsz; |
| 1238 | |
| 1239 | if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr)) |
| 1240 | break; |
| 1241 | |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1242 | namesz = NOTE_ALIGN(nhdr.n_namesz); |
| 1243 | descsz = NOTE_ALIGN(nhdr.n_descsz); |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 1244 | if (nhdr.n_type == NT_GNU_BUILD_ID && |
| 1245 | nhdr.n_namesz == sizeof("GNU")) { |
| 1246 | if (read(fd, bf, namesz) != namesz) |
| 1247 | break; |
| 1248 | if (memcmp(bf, "GNU", sizeof("GNU")) == 0) { |
| 1249 | if (read(fd, build_id, |
| 1250 | BUILD_ID_SIZE) == BUILD_ID_SIZE) { |
| 1251 | err = 0; |
| 1252 | break; |
| 1253 | } |
| 1254 | } else if (read(fd, bf, descsz) != descsz) |
| 1255 | break; |
| 1256 | } else { |
| 1257 | int n = namesz + descsz; |
| 1258 | if (read(fd, bf, n) != n) |
| 1259 | break; |
| 1260 | } |
| 1261 | } |
| 1262 | close(fd); |
| 1263 | out: |
| 1264 | return err; |
| 1265 | } |
| 1266 | |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1267 | char dso__symtab_origin(const struct dso *self) |
| 1268 | { |
| 1269 | static const char origin[] = { |
| 1270 | [DSO__ORIG_KERNEL] = 'k', |
| 1271 | [DSO__ORIG_JAVA_JIT] = 'j', |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 1272 | [DSO__ORIG_BUILD_ID_CACHE] = 'B', |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1273 | [DSO__ORIG_FEDORA] = 'f', |
| 1274 | [DSO__ORIG_UBUNTU] = 'u', |
| 1275 | [DSO__ORIG_BUILDID] = 'b', |
| 1276 | [DSO__ORIG_DSO] = 'd', |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1277 | [DSO__ORIG_KMODULE] = 'K', |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1278 | [DSO__ORIG_GUEST_KERNEL] = 'g', |
| 1279 | [DSO__ORIG_GUEST_KMODULE] = 'G', |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1280 | }; |
| 1281 | |
| 1282 | if (self == NULL || self->origin == DSO__ORIG_NOT_FOUND) |
| 1283 | return '!'; |
| 1284 | return origin[self->origin]; |
| 1285 | } |
| 1286 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1287 | int dso__load(struct dso *self, struct map *map, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1288 | { |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1289 | int size = PATH_MAX; |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 1290 | char *name; |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1291 | u8 build_id[BUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 1292 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1293 | int ret = -1; |
| 1294 | int fd; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1295 | struct machine *machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1296 | const char *root_dir; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1297 | |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 1298 | dso__set_loaded(self, map->type); |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1299 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1300 | if (self->kernel == DSO_TYPE_KERNEL) |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1301 | return dso__load_kernel_sym(self, map, filter); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1302 | else if (self->kernel == DSO_TYPE_GUEST_KERNEL) |
| 1303 | return dso__load_guest_kernel_sym(self, map, filter); |
| 1304 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1305 | if (map->groups && map->groups->machine) |
| 1306 | machine = map->groups->machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1307 | else |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1308 | machine = NULL; |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 1309 | |
| 1310 | name = malloc(size); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1311 | if (!name) |
| 1312 | return -1; |
| 1313 | |
Arnaldo Carvalho de Melo | 30d7a77 | 2009-07-02 21:24:14 -0300 | [diff] [blame] | 1314 | self->adjust_symbols = 0; |
Arnaldo Carvalho de Melo | f5812a7 | 2009-06-30 11:43:17 -0300 | [diff] [blame] | 1315 | |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1316 | if (strncmp(self->name, "/tmp/perf-", 10) == 0) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1317 | ret = dso__load_perf_map(self, map, filter); |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1318 | self->origin = ret > 0 ? DSO__ORIG_JAVA_JIT : |
| 1319 | DSO__ORIG_NOT_FOUND; |
| 1320 | return ret; |
| 1321 | } |
| 1322 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 1323 | self->origin = DSO__ORIG_BUILD_ID_CACHE; |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 1324 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 1325 | if (self->has_build_id) { |
| 1326 | build_id__sprintf(self->build_id, sizeof(self->build_id), |
| 1327 | build_id_hex); |
| 1328 | snprintf(name, size, "%s/%s/.build-id/%.2s/%s", |
| 1329 | getenv("HOME"), DEBUG_CACHE_DIR, |
| 1330 | build_id_hex, build_id_hex + 2); |
| 1331 | goto open_file; |
| 1332 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1333 | more: |
| 1334 | do { |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1335 | self->origin++; |
| 1336 | switch (self->origin) { |
| 1337 | case DSO__ORIG_FEDORA: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1338 | snprintf(name, size, "/usr/lib/debug%s.debug", |
| 1339 | self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1340 | break; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1341 | case DSO__ORIG_UBUNTU: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1342 | snprintf(name, size, "/usr/lib/debug%s", |
| 1343 | self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1344 | break; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1345 | case DSO__ORIG_BUILDID: |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1346 | if (filename__read_build_id(self->long_name, build_id, |
| 1347 | sizeof(build_id))) { |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1348 | build_id__sprintf(build_id, sizeof(build_id), |
| 1349 | build_id_hex); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1350 | snprintf(name, size, |
| 1351 | "/usr/lib/debug/.build-id/%.2s/%s.debug", |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1352 | build_id_hex, build_id_hex + 2); |
| 1353 | if (self->has_build_id) |
| 1354 | goto compare_build_id; |
| 1355 | break; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1356 | } |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1357 | self->origin++; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1358 | /* Fall thru */ |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1359 | case DSO__ORIG_DSO: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1360 | snprintf(name, size, "%s", self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1361 | break; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1362 | case DSO__ORIG_GUEST_KMODULE: |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1363 | if (map->groups && map->groups->machine) |
| 1364 | root_dir = map->groups->machine->root_dir; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1365 | else |
| 1366 | root_dir = ""; |
| 1367 | snprintf(name, size, "%s%s", root_dir, self->long_name); |
| 1368 | break; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1369 | |
| 1370 | default: |
| 1371 | goto out; |
| 1372 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1373 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1374 | if (self->has_build_id) { |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1375 | if (filename__read_build_id(name, build_id, |
| 1376 | sizeof(build_id)) < 0) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1377 | goto more; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1378 | compare_build_id: |
Arnaldo Carvalho de Melo | 78075ca | 2009-11-20 20:51:26 -0200 | [diff] [blame] | 1379 | if (!dso__build_id_equal(self, build_id)) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1380 | goto more; |
| 1381 | } |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 1382 | open_file: |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1383 | fd = open(name, O_RDONLY); |
| 1384 | } while (fd < 0); |
| 1385 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1386 | ret = dso__load_sym(self, map, name, fd, filter, 0); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1387 | close(fd); |
| 1388 | |
| 1389 | /* |
| 1390 | * Some people seem to have debuginfo files _WITHOUT_ debug info!?!? |
| 1391 | */ |
| 1392 | if (!ret) |
| 1393 | goto more; |
| 1394 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 1395 | if (ret > 0) { |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 1396 | int nr_plt = dso__synthesize_plt_symbols(self, map, filter); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 1397 | if (nr_plt > 0) |
| 1398 | ret += nr_plt; |
| 1399 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1400 | out: |
| 1401 | free(name); |
Arnaldo Carvalho de Melo | 1340e6b | 2009-08-11 17:04:36 -0300 | [diff] [blame] | 1402 | if (ret < 0 && strstr(self->name, " (deleted)") != NULL) |
| 1403 | return 0; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1404 | return ret; |
| 1405 | } |
| 1406 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 1407 | struct map *map_groups__find_by_name(struct map_groups *self, |
| 1408 | enum map_type type, const char *name) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1409 | { |
| 1410 | struct rb_node *nd; |
| 1411 | |
Arnaldo Carvalho de Melo | 79406cd | 2009-12-11 18:50:22 -0200 | [diff] [blame] | 1412 | for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1413 | struct map *map = rb_entry(nd, struct map, rb_node); |
| 1414 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1415 | if (map->dso && strcmp(map->dso->short_name, name) == 0) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1416 | return map; |
| 1417 | } |
| 1418 | |
| 1419 | return NULL; |
| 1420 | } |
| 1421 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1422 | static int dso__kernel_module_get_build_id(struct dso *self, |
| 1423 | const char *root_dir) |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1424 | { |
| 1425 | char filename[PATH_MAX]; |
| 1426 | /* |
| 1427 | * kernel module short names are of the form "[module]" and |
| 1428 | * we need just "module" here. |
| 1429 | */ |
| 1430 | const char *name = self->short_name + 1; |
| 1431 | |
| 1432 | snprintf(filename, sizeof(filename), |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1433 | "%s/sys/module/%.*s/notes/.note.gnu.build-id", |
| 1434 | root_dir, (int)strlen(name) - 1, name); |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1435 | |
| 1436 | if (sysfs__read_build_id(filename, self->build_id, |
| 1437 | sizeof(self->build_id)) == 0) |
| 1438 | self->has_build_id = true; |
| 1439 | |
| 1440 | return 0; |
| 1441 | } |
| 1442 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1443 | static int map_groups__set_modules_path_dir(struct map_groups *self, |
| 1444 | const char *dir_name) |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1445 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1446 | struct dirent *dent; |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1447 | DIR *dir = opendir(dir_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1448 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1449 | if (!dir) { |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1450 | pr_debug("%s: cannot open %s dir\n", __func__, dir_name); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1451 | return -1; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1452 | } |
| 1453 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1454 | while ((dent = readdir(dir)) != NULL) { |
| 1455 | char path[PATH_MAX]; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1456 | struct stat st; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1457 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1458 | /*sshfs might return bad dent->d_type, so we have to stat*/ |
| 1459 | sprintf(path, "%s/%s", dir_name, dent->d_name); |
| 1460 | if (stat(path, &st)) |
| 1461 | continue; |
| 1462 | |
| 1463 | if (S_ISDIR(st.st_mode)) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1464 | if (!strcmp(dent->d_name, ".") || |
| 1465 | !strcmp(dent->d_name, "..")) |
| 1466 | continue; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1467 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1468 | snprintf(path, sizeof(path), "%s/%s", |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1469 | dir_name, dent->d_name); |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1470 | if (map_groups__set_modules_path_dir(self, path) < 0) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1471 | goto failure; |
| 1472 | } else { |
| 1473 | char *dot = strrchr(dent->d_name, '.'), |
| 1474 | dso_name[PATH_MAX]; |
| 1475 | struct map *map; |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1476 | char *long_name; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1477 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1478 | if (dot == NULL || strcmp(dot, ".ko")) |
| 1479 | continue; |
| 1480 | snprintf(dso_name, sizeof(dso_name), "[%.*s]", |
| 1481 | (int)(dot - dent->d_name), dent->d_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1482 | |
Arnaldo Carvalho de Melo | a2a99e8 | 2009-10-05 14:26:18 -0300 | [diff] [blame] | 1483 | strxfrchar(dso_name, '-', '_'); |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1484 | map = map_groups__find_by_name(self, MAP__FUNCTION, dso_name); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1485 | if (map == NULL) |
| 1486 | continue; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1487 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1488 | snprintf(path, sizeof(path), "%s/%s", |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1489 | dir_name, dent->d_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1490 | |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1491 | long_name = strdup(path); |
| 1492 | if (long_name == NULL) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1493 | goto failure; |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1494 | dso__set_long_name(map->dso, long_name); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1495 | dso__kernel_module_get_build_id(map->dso, ""); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1496 | } |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1497 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1498 | |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 1499 | return 0; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1500 | failure: |
| 1501 | closedir(dir); |
| 1502 | return -1; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1505 | static char *get_kernel_version(const char *root_dir) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1506 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1507 | char version[PATH_MAX]; |
| 1508 | FILE *file; |
| 1509 | char *name, *tmp; |
| 1510 | const char *prefix = "Linux version "; |
| 1511 | |
| 1512 | sprintf(version, "%s/proc/version", root_dir); |
| 1513 | file = fopen(version, "r"); |
| 1514 | if (!file) |
| 1515 | return NULL; |
| 1516 | |
| 1517 | version[0] = '\0'; |
| 1518 | tmp = fgets(version, sizeof(version), file); |
| 1519 | fclose(file); |
| 1520 | |
| 1521 | name = strstr(version, prefix); |
| 1522 | if (!name) |
| 1523 | return NULL; |
| 1524 | name += strlen(prefix); |
| 1525 | tmp = strchr(name, ' '); |
| 1526 | if (tmp) |
| 1527 | *tmp = '\0'; |
| 1528 | |
| 1529 | return strdup(name); |
| 1530 | } |
| 1531 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1532 | static int machine__set_modules_path(struct machine *self) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1533 | { |
| 1534 | char *version; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1535 | char modules_path[PATH_MAX]; |
| 1536 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1537 | version = get_kernel_version(self->root_dir); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1538 | if (!version) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1539 | return -1; |
| 1540 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1541 | snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel", |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1542 | self->root_dir, version); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1543 | free(version); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1544 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1545 | return map_groups__set_modules_path_dir(&self->kmaps, modules_path); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /* |
| 1549 | * Constructor variant for modules (where we know from /proc/modules where |
| 1550 | * they are loaded) and for vmlinux, where only after we load all the |
| 1551 | * symbols we'll know where it starts and ends. |
| 1552 | */ |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 1553 | static struct map *map__new2(u64 start, struct dso *dso, enum map_type type) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1554 | { |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 1555 | struct map *self = calloc(1, (sizeof(*self) + |
| 1556 | (dso->kernel ? sizeof(struct kmap) : 0))); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1557 | if (self != NULL) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1558 | /* |
Arnaldo Carvalho de Melo | afb7b4f | 2009-10-30 16:28:23 -0200 | [diff] [blame] | 1559 | * ->end will be filled after we load all the symbols |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1560 | */ |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 1561 | map__init(self, type, start, 0, 0, dso); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1562 | } |
Arnaldo Carvalho de Melo | afb7b4f | 2009-10-30 16:28:23 -0200 | [diff] [blame] | 1563 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1564 | return self; |
| 1565 | } |
| 1566 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1567 | struct map *machine__new_module(struct machine *self, u64 start, |
| 1568 | const char *filename) |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1569 | { |
| 1570 | struct map *map; |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1571 | struct dso *dso = __dsos__findnew(&self->kernel_dsos, filename); |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1572 | |
| 1573 | if (dso == NULL) |
| 1574 | return NULL; |
| 1575 | |
| 1576 | map = map__new2(start, dso, MAP__FUNCTION); |
| 1577 | if (map == NULL) |
| 1578 | return NULL; |
| 1579 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1580 | if (machine__is_host(self)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1581 | dso->origin = DSO__ORIG_KMODULE; |
| 1582 | else |
| 1583 | dso->origin = DSO__ORIG_GUEST_KMODULE; |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1584 | map_groups__insert(&self->kmaps, map); |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1585 | return map; |
| 1586 | } |
| 1587 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1588 | static int machine__create_modules(struct machine *self) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1589 | { |
| 1590 | char *line = NULL; |
| 1591 | size_t n; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1592 | FILE *file; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1593 | struct map *map; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1594 | const char *modules; |
| 1595 | char path[PATH_MAX]; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1596 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1597 | if (machine__is_default_guest(self)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1598 | modules = symbol_conf.default_guest_modules; |
| 1599 | else { |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1600 | sprintf(path, "%s/proc/modules", self->root_dir); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1601 | modules = path; |
| 1602 | } |
| 1603 | |
| 1604 | file = fopen(modules, "r"); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1605 | if (file == NULL) |
| 1606 | return -1; |
| 1607 | |
| 1608 | while (!feof(file)) { |
| 1609 | char name[PATH_MAX]; |
| 1610 | u64 start; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1611 | char *sep; |
| 1612 | int line_len; |
| 1613 | |
| 1614 | line_len = getline(&line, &n, file); |
| 1615 | if (line_len < 0) |
| 1616 | break; |
| 1617 | |
| 1618 | if (!line) |
| 1619 | goto out_failure; |
| 1620 | |
| 1621 | line[--line_len] = '\0'; /* \n */ |
| 1622 | |
| 1623 | sep = strrchr(line, 'x'); |
| 1624 | if (sep == NULL) |
| 1625 | continue; |
| 1626 | |
| 1627 | hex2u64(sep + 1, &start); |
| 1628 | |
| 1629 | sep = strchr(line, ' '); |
| 1630 | if (sep == NULL) |
| 1631 | continue; |
| 1632 | |
| 1633 | *sep = '\0'; |
| 1634 | |
| 1635 | snprintf(name, sizeof(name), "[%s]", line); |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1636 | map = machine__new_module(self, start, name); |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1637 | if (map == NULL) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1638 | goto out_delete_line; |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1639 | dso__kernel_module_get_build_id(map->dso, self->root_dir); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | free(line); |
| 1643 | fclose(file); |
| 1644 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 1645 | return machine__set_modules_path(self); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1646 | |
| 1647 | out_delete_line: |
| 1648 | free(line); |
| 1649 | out_failure: |
| 1650 | return -1; |
| 1651 | } |
| 1652 | |
Arnaldo Carvalho de Melo | 9958e1f | 2009-12-11 14:50:36 -0200 | [diff] [blame] | 1653 | static int dso__load_vmlinux(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1654 | const char *vmlinux, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1655 | { |
Arnaldo Carvalho de Melo | fbd733b | 2009-11-20 20:51:28 -0200 | [diff] [blame] | 1656 | int err = -1, fd; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1657 | |
Arnaldo Carvalho de Melo | fbd733b | 2009-11-20 20:51:28 -0200 | [diff] [blame] | 1658 | if (self->has_build_id) { |
| 1659 | u8 build_id[BUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1660 | |
Arnaldo Carvalho de Melo | fbd733b | 2009-11-20 20:51:28 -0200 | [diff] [blame] | 1661 | if (filename__read_build_id(vmlinux, build_id, |
| 1662 | sizeof(build_id)) < 0) { |
| 1663 | pr_debug("No build_id in %s, ignoring it\n", vmlinux); |
| 1664 | return -1; |
| 1665 | } |
| 1666 | if (!dso__build_id_equal(self, build_id)) { |
| 1667 | char expected_build_id[BUILD_ID_SIZE * 2 + 1], |
| 1668 | vmlinux_build_id[BUILD_ID_SIZE * 2 + 1]; |
| 1669 | |
| 1670 | build_id__sprintf(self->build_id, |
| 1671 | sizeof(self->build_id), |
| 1672 | expected_build_id); |
| 1673 | build_id__sprintf(build_id, sizeof(build_id), |
| 1674 | vmlinux_build_id); |
| 1675 | pr_debug("build_id in %s is %s while expected is %s, " |
| 1676 | "ignoring it\n", vmlinux, vmlinux_build_id, |
| 1677 | expected_build_id); |
| 1678 | return -1; |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | fd = open(vmlinux, O_RDONLY); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1683 | if (fd < 0) |
| 1684 | return -1; |
| 1685 | |
Arnaldo Carvalho de Melo | 3610583 | 2009-11-27 16:29:16 -0200 | [diff] [blame] | 1686 | dso__set_loaded(self, map->type); |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1687 | err = dso__load_sym(self, map, vmlinux, fd, filter, 0); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1688 | close(fd); |
| 1689 | |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1690 | if (err > 0) |
| 1691 | pr_debug("Using %s for symbols\n", vmlinux); |
| 1692 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1693 | return err; |
| 1694 | } |
| 1695 | |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1696 | int dso__load_vmlinux_path(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1697 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1698 | { |
| 1699 | int i, err = 0; |
| 1700 | |
| 1701 | pr_debug("Looking at the vmlinux_path (%d entries long)\n", |
| 1702 | vmlinux_path__nr_entries); |
| 1703 | |
| 1704 | for (i = 0; i < vmlinux_path__nr_entries; ++i) { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1705 | err = dso__load_vmlinux(self, map, vmlinux_path[i], filter); |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1706 | if (err > 0) { |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1707 | dso__set_long_name(self, strdup(vmlinux_path[i])); |
| 1708 | break; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | return err; |
| 1713 | } |
| 1714 | |
Arnaldo Carvalho de Melo | c338aee | 2009-11-20 20:51:27 -0200 | [diff] [blame] | 1715 | static int dso__load_kernel_sym(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1716 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1717 | { |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1718 | int err; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1719 | const char *kallsyms_filename = NULL; |
| 1720 | char *kallsyms_allocated_filename = NULL; |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1721 | /* |
| 1722 | * Step 1: if the user specified a vmlinux filename, use it and only |
| 1723 | * it, reporting errors to the user if it cannot be used. |
| 1724 | * |
| 1725 | * For instance, try to analyse an ARM perf.data file _without_ a |
| 1726 | * build-id, or if the user specifies the wrong path to the right |
| 1727 | * vmlinux file, obviously we can't fallback to another vmlinux (a |
| 1728 | * x86_86 one, on the machine where analysis is being performed, say), |
| 1729 | * or worse, /proc/kallsyms. |
| 1730 | * |
| 1731 | * If the specified file _has_ a build-id and there is a build-id |
| 1732 | * section in the perf.data file, we will still do the expected |
| 1733 | * validation in dso__load_vmlinux and will bail out if they don't |
| 1734 | * match. |
| 1735 | */ |
| 1736 | if (symbol_conf.vmlinux_name != NULL) { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1737 | err = dso__load_vmlinux(self, map, |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1738 | symbol_conf.vmlinux_name, filter); |
| 1739 | goto out_try_fixup; |
| 1740 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1741 | |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1742 | if (vmlinux_path != NULL) { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1743 | err = dso__load_vmlinux_path(self, map, filter); |
Arnaldo Carvalho de Melo | a19afe4 | 2010-01-27 21:05:50 -0200 | [diff] [blame] | 1744 | if (err > 0) |
| 1745 | goto out_fixup; |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1746 | } |
| 1747 | |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1748 | /* |
| 1749 | * Say the kernel DSO was created when processing the build-id header table, |
| 1750 | * we have a build-id, so check if it is the same as the running kernel, |
| 1751 | * using it if it is. |
| 1752 | */ |
| 1753 | if (self->has_build_id) { |
| 1754 | u8 kallsyms_build_id[BUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1755 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
Arnaldo Carvalho de Melo | b7cece76 | 2010-01-13 13:22:17 -0200 | [diff] [blame] | 1756 | |
| 1757 | if (sysfs__read_build_id("/sys/kernel/notes", kallsyms_build_id, |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1758 | sizeof(kallsyms_build_id)) == 0) { |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1759 | if (dso__build_id_equal(self, kallsyms_build_id)) { |
| 1760 | kallsyms_filename = "/proc/kallsyms"; |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1761 | goto do_kallsyms; |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1762 | } |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1763 | } |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1764 | /* |
| 1765 | * Now look if we have it on the build-id cache in |
| 1766 | * $HOME/.debug/[kernel.kallsyms]. |
| 1767 | */ |
Arnaldo Carvalho de Melo | 9e20144 | 2010-01-14 18:30:06 -0200 | [diff] [blame] | 1768 | build_id__sprintf(self->build_id, sizeof(self->build_id), |
| 1769 | sbuild_id); |
| 1770 | |
| 1771 | if (asprintf(&kallsyms_allocated_filename, |
| 1772 | "%s/.debug/[kernel.kallsyms]/%s", |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1773 | getenv("HOME"), sbuild_id) == -1) { |
| 1774 | pr_err("Not enough memory for kallsyms file lookup\n"); |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1775 | return -1; |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1776 | } |
Arnaldo Carvalho de Melo | 8d0591f6 | 2010-01-14 18:30:05 -0200 | [diff] [blame] | 1777 | |
Arnaldo Carvalho de Melo | 19fc2de | 2010-01-22 14:35:02 -0200 | [diff] [blame] | 1778 | kallsyms_filename = kallsyms_allocated_filename; |
| 1779 | |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1780 | if (access(kallsyms_filename, F_OK)) { |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1781 | pr_err("No kallsyms or vmlinux with build-id %s " |
| 1782 | "was found\n", sbuild_id); |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1783 | free(kallsyms_allocated_filename); |
| 1784 | return -1; |
| 1785 | } |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1786 | } else { |
| 1787 | /* |
| 1788 | * Last resort, if we don't have a build-id and couldn't find |
| 1789 | * any vmlinux file, try the running kernel kallsyms table. |
| 1790 | */ |
| 1791 | kallsyms_filename = "/proc/kallsyms"; |
Arnaldo Carvalho de Melo | ef6ae72 | 2009-11-20 20:51:29 -0200 | [diff] [blame] | 1792 | } |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1793 | |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1794 | do_kallsyms: |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 1795 | err = dso__load_kallsyms(self, kallsyms_filename, map, filter); |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 1796 | if (err > 0) |
| 1797 | pr_debug("Using %s for symbols\n", kallsyms_filename); |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1798 | free(kallsyms_allocated_filename); |
| 1799 | |
| 1800 | out_try_fixup: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1801 | if (err > 0) { |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 1802 | out_fixup: |
Arnaldo Carvalho de Melo | e1c7c6a | 2010-01-22 14:35:01 -0200 | [diff] [blame] | 1803 | if (kallsyms_filename != NULL) |
Arnaldo Carvalho de Melo | dc8d6ab | 2010-01-19 10:36:14 -0200 | [diff] [blame] | 1804 | dso__set_long_name(self, strdup("[kernel.kallsyms]")); |
Arnaldo Carvalho de Melo | 6a4694a | 2009-11-27 16:29:17 -0200 | [diff] [blame] | 1805 | map__fixup_start(map); |
| 1806 | map__fixup_end(map); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1807 | } |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1808 | |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1809 | return err; |
| 1810 | } |
| 1811 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1812 | static int dso__load_guest_kernel_sym(struct dso *self, struct map *map, |
| 1813 | symbol_filter_t filter) |
| 1814 | { |
| 1815 | int err; |
| 1816 | const char *kallsyms_filename = NULL; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1817 | struct machine *machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1818 | char path[PATH_MAX]; |
| 1819 | |
| 1820 | if (!map->groups) { |
| 1821 | pr_debug("Guest kernel map hasn't the point to groups\n"); |
| 1822 | return -1; |
| 1823 | } |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1824 | machine = map->groups->machine; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1825 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1826 | if (machine__is_default_guest(machine)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1827 | /* |
| 1828 | * if the user specified a vmlinux filename, use it and only |
| 1829 | * it, reporting errors to the user if it cannot be used. |
| 1830 | * Or use file guest_kallsyms inputted by user on commandline |
| 1831 | */ |
| 1832 | if (symbol_conf.default_guest_vmlinux_name != NULL) { |
| 1833 | err = dso__load_vmlinux(self, map, |
| 1834 | symbol_conf.default_guest_vmlinux_name, filter); |
| 1835 | goto out_try_fixup; |
| 1836 | } |
| 1837 | |
| 1838 | kallsyms_filename = symbol_conf.default_guest_kallsyms; |
| 1839 | if (!kallsyms_filename) |
| 1840 | return -1; |
| 1841 | } else { |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1842 | sprintf(path, "%s/proc/kallsyms", machine->root_dir); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1843 | kallsyms_filename = path; |
| 1844 | } |
| 1845 | |
| 1846 | err = dso__load_kallsyms(self, kallsyms_filename, map, filter); |
| 1847 | if (err > 0) |
| 1848 | pr_debug("Using %s for symbols\n", kallsyms_filename); |
| 1849 | |
| 1850 | out_try_fixup: |
| 1851 | if (err > 0) { |
| 1852 | if (kallsyms_filename != NULL) { |
Arnaldo Carvalho de Melo | 48ea8f5 | 2010-04-27 21:19:05 -0300 | [diff] [blame] | 1853 | machine__mmap_name(machine, path, sizeof(path)); |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1854 | dso__set_long_name(self, strdup(path)); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1855 | } |
| 1856 | map__fixup_start(map); |
| 1857 | map__fixup_end(map); |
| 1858 | } |
| 1859 | |
| 1860 | return err; |
| 1861 | } |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1862 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1863 | static void dsos__add(struct list_head *head, struct dso *dso) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1864 | { |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1865 | list_add_tail(&dso->node, head); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1868 | static struct dso *dsos__find(struct list_head *head, const char *name) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1869 | { |
| 1870 | struct dso *pos; |
| 1871 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1872 | list_for_each_entry(pos, head, node) |
Arnaldo Carvalho de Melo | cf4e5b0 | 2010-01-14 23:45:27 -0200 | [diff] [blame] | 1873 | if (strcmp(pos->long_name, name) == 0) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1874 | return pos; |
| 1875 | return NULL; |
| 1876 | } |
| 1877 | |
Arnaldo Carvalho de Melo | a89e5abe | 2010-01-07 19:59:39 -0200 | [diff] [blame] | 1878 | struct dso *__dsos__findnew(struct list_head *head, const char *name) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1879 | { |
Arnaldo Carvalho de Melo | a89e5abe | 2010-01-07 19:59:39 -0200 | [diff] [blame] | 1880 | struct dso *dso = dsos__find(head, name); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1881 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 1882 | if (!dso) { |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1883 | dso = dso__new(name); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1884 | if (dso != NULL) { |
Arnaldo Carvalho de Melo | a89e5abe | 2010-01-07 19:59:39 -0200 | [diff] [blame] | 1885 | dsos__add(head, dso); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1886 | dso__set_basename(dso); |
| 1887 | } |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1888 | } |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1889 | |
| 1890 | return dso; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1891 | } |
| 1892 | |
Arnaldo Carvalho de Melo | 1f626bc | 2010-05-09 19:57:08 -0300 | [diff] [blame] | 1893 | size_t __dsos__fprintf(struct list_head *head, FILE *fp) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1894 | { |
| 1895 | struct dso *pos; |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1896 | size_t ret = 0; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1897 | |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 1898 | list_for_each_entry(pos, head, node) { |
| 1899 | int i; |
| 1900 | for (i = 0; i < MAP__NR_TYPES; ++i) |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1901 | ret += dso__fprintf(pos, i, fp); |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 1902 | } |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1903 | |
| 1904 | return ret; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1905 | } |
| 1906 | |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1907 | size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp) |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1908 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1909 | struct rb_node *nd; |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1910 | size_t ret = 0; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1911 | |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1912 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1913 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1914 | ret += __dsos__fprintf(&pos->kernel_dsos, fp); |
| 1915 | ret += __dsos__fprintf(&pos->user_dsos, fp); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1916 | } |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1917 | |
| 1918 | return ret; |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1919 | } |
| 1920 | |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame] | 1921 | static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp, |
| 1922 | bool with_hits) |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 1923 | { |
| 1924 | struct dso *pos; |
| 1925 | size_t ret = 0; |
| 1926 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1927 | list_for_each_entry(pos, head, node) { |
Arnaldo Carvalho de Melo | 88d3d9b7 | 2010-01-14 23:45:30 -0200 | [diff] [blame] | 1928 | if (with_hits && !pos->hit) |
| 1929 | continue; |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 1930 | ret += dso__fprintf_buildid(pos, fp); |
Arnaldo Carvalho de Melo | 1124ba7 | 2009-11-16 21:45:25 -0200 | [diff] [blame] | 1931 | ret += fprintf(fp, " %s\n", pos->long_name); |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 1932 | } |
| 1933 | return ret; |
| 1934 | } |
| 1935 | |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1936 | size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits) |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1937 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1938 | struct rb_node *nd; |
| 1939 | size_t ret = 0; |
| 1940 | |
Arnaldo Carvalho de Melo | cbf6968 | 2010-04-27 21:22:44 -0300 | [diff] [blame] | 1941 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1942 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
| 1943 | ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits); |
| 1944 | ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1945 | } |
| 1946 | return ret; |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 1947 | } |
| 1948 | |
Arnaldo Carvalho de Melo | fd1d908 | 2010-01-27 21:05:51 -0200 | [diff] [blame] | 1949 | struct dso *dso__new_kernel(const char *name) |
| 1950 | { |
| 1951 | struct dso *self = dso__new(name ?: "[kernel.kallsyms]"); |
| 1952 | |
| 1953 | if (self != NULL) { |
Arnaldo Carvalho de Melo | b63be8d | 2010-03-15 15:03:50 -0300 | [diff] [blame] | 1954 | dso__set_short_name(self, "[kernel]"); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1955 | self->kernel = DSO_TYPE_KERNEL; |
Arnaldo Carvalho de Melo | fd1d908 | 2010-01-27 21:05:51 -0200 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | return self; |
| 1959 | } |
| 1960 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1961 | static struct dso *dso__new_guest_kernel(struct machine *machine, |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1962 | const char *name) |
Arnaldo Carvalho de Melo | fd1d908 | 2010-01-27 21:05:51 -0200 | [diff] [blame] | 1963 | { |
Arnaldo Carvalho de Melo | 48ea8f5 | 2010-04-27 21:19:05 -0300 | [diff] [blame] | 1964 | char bf[PATH_MAX]; |
| 1965 | struct dso *self = dso__new(name ?: machine__mmap_name(machine, bf, sizeof(bf))); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1966 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1967 | if (self != NULL) { |
| 1968 | dso__set_short_name(self, "[guest.kernel]"); |
| 1969 | self->kernel = DSO_TYPE_GUEST_KERNEL; |
| 1970 | } |
| 1971 | |
| 1972 | return self; |
| 1973 | } |
| 1974 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1975 | void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1976 | { |
| 1977 | char path[PATH_MAX]; |
| 1978 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1979 | if (machine__is_default_guest(machine)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1980 | return; |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 1981 | sprintf(path, "%s/sys/kernel/notes", machine->root_dir); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1982 | if (sysfs__read_build_id(path, self->build_id, |
Arnaldo Carvalho de Melo | fd1d908 | 2010-01-27 21:05:51 -0200 | [diff] [blame] | 1983 | sizeof(self->build_id)) == 0) |
| 1984 | self->has_build_id = true; |
| 1985 | } |
| 1986 | |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 1987 | static struct dso *machine__create_kernel(struct machine *self) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1988 | { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1989 | const char *vmlinux_name = NULL; |
| 1990 | struct dso *kernel; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1991 | |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 1992 | if (machine__is_host(self)) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1993 | vmlinux_name = symbol_conf.vmlinux_name; |
| 1994 | kernel = dso__new_kernel(vmlinux_name); |
| 1995 | } else { |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 1996 | if (machine__is_default_guest(self)) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 1997 | vmlinux_name = symbol_conf.default_guest_vmlinux_name; |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 1998 | kernel = dso__new_guest_kernel(self, vmlinux_name); |
Arnaldo Carvalho de Melo | 8d92c02 | 2010-02-03 16:52:02 -0200 | [diff] [blame] | 1999 | } |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 2000 | |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2001 | if (kernel != NULL) { |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 2002 | dso__read_running_kernel_build_id(kernel, self); |
| 2003 | dsos__add(&self->kernel_dsos, kernel); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2004 | } |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2005 | return kernel; |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2006 | } |
| 2007 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2008 | int __machine__create_kernel_maps(struct machine *self, struct dso *kernel) |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2009 | { |
Arnaldo Carvalho de Melo | de17648 | 2010-01-04 16:19:29 -0200 | [diff] [blame] | 2010 | enum map_type type; |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2011 | |
Arnaldo Carvalho de Melo | de17648 | 2010-01-04 16:19:29 -0200 | [diff] [blame] | 2012 | for (type = 0; type < MAP__NR_TYPES; ++type) { |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 2013 | struct kmap *kmap; |
| 2014 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2015 | self->vmlinux_maps[type] = map__new2(0, kernel, type); |
| 2016 | if (self->vmlinux_maps[type] == NULL) |
Arnaldo Carvalho de Melo | de17648 | 2010-01-04 16:19:29 -0200 | [diff] [blame] | 2017 | return -1; |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2018 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2019 | self->vmlinux_maps[type]->map_ip = |
| 2020 | self->vmlinux_maps[type]->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 2021 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2022 | kmap = map__kmap(self->vmlinux_maps[type]); |
| 2023 | kmap->kmaps = &self->kmaps; |
| 2024 | map_groups__insert(&self->kmaps, self->vmlinux_maps[type]); |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2025 | } |
| 2026 | |
Arnaldo Carvalho de Melo | f1dfa0b | 2009-12-11 14:50:39 -0200 | [diff] [blame] | 2027 | return 0; |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 2030 | int machine__create_kernel_maps(struct machine *self) |
| 2031 | { |
| 2032 | struct dso *kernel = machine__create_kernel(self); |
| 2033 | |
| 2034 | if (kernel == NULL || |
| 2035 | __machine__create_kernel_maps(self, kernel) < 0) |
| 2036 | return -1; |
| 2037 | |
| 2038 | if (symbol_conf.use_modules && machine__create_modules(self) < 0) |
| 2039 | pr_debug("Problems creating module maps, continuing anyway...\n"); |
| 2040 | /* |
| 2041 | * Now that we have all the maps created, just set the ->end of them: |
| 2042 | */ |
| 2043 | map_groups__fixup_end(&self->kmaps); |
| 2044 | return 0; |
| 2045 | } |
| 2046 | |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 2047 | static void vmlinux_path__exit(void) |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 2048 | { |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 2049 | while (--vmlinux_path__nr_entries >= 0) { |
| 2050 | free(vmlinux_path[vmlinux_path__nr_entries]); |
| 2051 | vmlinux_path[vmlinux_path__nr_entries] = NULL; |
| 2052 | } |
| 2053 | |
| 2054 | free(vmlinux_path); |
| 2055 | vmlinux_path = NULL; |
| 2056 | } |
| 2057 | |
| 2058 | static int vmlinux_path__init(void) |
| 2059 | { |
| 2060 | struct utsname uts; |
| 2061 | char bf[PATH_MAX]; |
| 2062 | |
| 2063 | if (uname(&uts) < 0) |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 2064 | return -1; |
| 2065 | |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 2066 | vmlinux_path = malloc(sizeof(char *) * 5); |
| 2067 | if (vmlinux_path == NULL) |
| 2068 | return -1; |
| 2069 | |
| 2070 | vmlinux_path[vmlinux_path__nr_entries] = strdup("vmlinux"); |
| 2071 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 2072 | goto out_fail; |
| 2073 | ++vmlinux_path__nr_entries; |
| 2074 | vmlinux_path[vmlinux_path__nr_entries] = strdup("/boot/vmlinux"); |
| 2075 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 2076 | goto out_fail; |
| 2077 | ++vmlinux_path__nr_entries; |
| 2078 | snprintf(bf, sizeof(bf), "/boot/vmlinux-%s", uts.release); |
| 2079 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); |
| 2080 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 2081 | goto out_fail; |
| 2082 | ++vmlinux_path__nr_entries; |
| 2083 | snprintf(bf, sizeof(bf), "/lib/modules/%s/build/vmlinux", uts.release); |
| 2084 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); |
| 2085 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 2086 | goto out_fail; |
| 2087 | ++vmlinux_path__nr_entries; |
| 2088 | snprintf(bf, sizeof(bf), "/usr/lib/debug/lib/modules/%s/vmlinux", |
| 2089 | uts.release); |
| 2090 | vmlinux_path[vmlinux_path__nr_entries] = strdup(bf); |
| 2091 | if (vmlinux_path[vmlinux_path__nr_entries] == NULL) |
| 2092 | goto out_fail; |
| 2093 | ++vmlinux_path__nr_entries; |
| 2094 | |
| 2095 | return 0; |
| 2096 | |
| 2097 | out_fail: |
| 2098 | vmlinux_path__exit(); |
| 2099 | return -1; |
| 2100 | } |
| 2101 | |
Arnaldo Carvalho de Melo | b0a9ab6 | 2010-03-15 11:46:58 -0300 | [diff] [blame] | 2102 | size_t vmlinux_path__fprintf(FILE *fp) |
| 2103 | { |
| 2104 | int i; |
| 2105 | size_t printed = 0; |
| 2106 | |
| 2107 | for (i = 0; i < vmlinux_path__nr_entries; ++i) |
| 2108 | printed += fprintf(fp, "[%d] %s\n", i, vmlinux_path[i]); |
| 2109 | |
| 2110 | return printed; |
| 2111 | } |
| 2112 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 2113 | static int setup_list(struct strlist **list, const char *list_str, |
| 2114 | const char *list_name) |
| 2115 | { |
| 2116 | if (list_str == NULL) |
| 2117 | return 0; |
| 2118 | |
| 2119 | *list = strlist__new(true, list_str); |
| 2120 | if (!*list) { |
| 2121 | pr_err("problems parsing %s list\n", list_name); |
| 2122 | return -1; |
| 2123 | } |
| 2124 | return 0; |
| 2125 | } |
| 2126 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 2127 | int symbol__init(void) |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 2128 | { |
Arnaldo Carvalho de Melo | 95011c6 | 2009-11-27 16:29:20 -0200 | [diff] [blame] | 2129 | elf_version(EV_CURRENT); |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 2130 | if (symbol_conf.sort_by_name) |
| 2131 | symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) - |
| 2132 | sizeof(struct symbol)); |
Arnaldo Carvalho de Melo | b32d133 | 2009-11-24 12:05:15 -0200 | [diff] [blame] | 2133 | |
Arnaldo Carvalho de Melo | 75be6cf | 2009-12-15 20:04:39 -0200 | [diff] [blame] | 2134 | if (symbol_conf.try_vmlinux_path && vmlinux_path__init() < 0) |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 2135 | return -1; |
| 2136 | |
Arnaldo Carvalho de Melo | c410a33 | 2009-12-15 20:04:41 -0200 | [diff] [blame] | 2137 | if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') { |
| 2138 | pr_err("'.' is the only non valid --field-separator argument\n"); |
| 2139 | return -1; |
| 2140 | } |
| 2141 | |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 2142 | if (setup_list(&symbol_conf.dso_list, |
| 2143 | symbol_conf.dso_list_str, "dso") < 0) |
| 2144 | return -1; |
| 2145 | |
| 2146 | if (setup_list(&symbol_conf.comm_list, |
| 2147 | symbol_conf.comm_list_str, "comm") < 0) |
| 2148 | goto out_free_dso_list; |
| 2149 | |
| 2150 | if (setup_list(&symbol_conf.sym_list, |
| 2151 | symbol_conf.sym_list_str, "symbol") < 0) |
| 2152 | goto out_free_comm_list; |
| 2153 | |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 2154 | return 0; |
Arnaldo Carvalho de Melo | 655000e | 2009-12-15 20:04:40 -0200 | [diff] [blame] | 2155 | |
| 2156 | out_free_dso_list: |
| 2157 | strlist__delete(symbol_conf.dso_list); |
| 2158 | out_free_comm_list: |
| 2159 | strlist__delete(symbol_conf.comm_list); |
| 2160 | return -1; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 2161 | } |
Arnaldo Carvalho de Melo | cc612d8 | 2009-11-23 16:39:10 -0200 | [diff] [blame] | 2162 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2163 | int machines__create_kernel_maps(struct rb_root *self, pid_t pid) |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 2164 | { |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2165 | struct machine *machine = machines__findnew(self, pid); |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 2166 | |
Arnaldo Carvalho de Melo | 23346f2 | 2010-04-27 21:17:50 -0300 | [diff] [blame] | 2167 | if (machine == NULL) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2168 | return -1; |
Arnaldo Carvalho de Melo | 4aa6563 | 2009-12-13 19:50:29 -0200 | [diff] [blame] | 2169 | |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 2170 | return machine__create_kernel_maps(machine); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 2171 | } |
Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 2172 | |
| 2173 | static int hex(char ch) |
| 2174 | { |
| 2175 | if ((ch >= '0') && (ch <= '9')) |
| 2176 | return ch - '0'; |
| 2177 | if ((ch >= 'a') && (ch <= 'f')) |
| 2178 | return ch - 'a' + 10; |
| 2179 | if ((ch >= 'A') && (ch <= 'F')) |
| 2180 | return ch - 'A' + 10; |
| 2181 | return -1; |
| 2182 | } |
| 2183 | |
| 2184 | /* |
| 2185 | * While we find nice hex chars, build a long_val. |
| 2186 | * Return number of chars processed. |
| 2187 | */ |
| 2188 | int hex2u64(const char *ptr, u64 *long_val) |
| 2189 | { |
| 2190 | const char *p = ptr; |
| 2191 | *long_val = 0; |
| 2192 | |
| 2193 | while (*p) { |
| 2194 | const int hex_val = hex(*p); |
| 2195 | |
| 2196 | if (hex_val < 0) |
| 2197 | break; |
| 2198 | |
| 2199 | *long_val = (*long_val << 4) | hex_val; |
| 2200 | p++; |
| 2201 | } |
| 2202 | |
| 2203 | return p - ptr; |
| 2204 | } |
| 2205 | |
| 2206 | char *strxfrchar(char *s, char from, char to) |
| 2207 | { |
| 2208 | char *p = s; |
| 2209 | |
| 2210 | while ((p = strchr(p, from)) != NULL) |
| 2211 | *p++ = to; |
| 2212 | |
| 2213 | return s; |
| 2214 | } |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2215 | |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2216 | int machines__create_guest_kernel_maps(struct rb_root *self) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2217 | { |
| 2218 | int ret = 0; |
| 2219 | struct dirent **namelist = NULL; |
| 2220 | int i, items = 0; |
| 2221 | char path[PATH_MAX]; |
| 2222 | pid_t pid; |
| 2223 | |
| 2224 | if (symbol_conf.default_guest_vmlinux_name || |
| 2225 | symbol_conf.default_guest_modules || |
| 2226 | symbol_conf.default_guest_kallsyms) { |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2227 | machines__create_kernel_maps(self, DEFAULT_GUEST_KERNEL_ID); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | if (symbol_conf.guestmount) { |
| 2231 | items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL); |
| 2232 | if (items <= 0) |
| 2233 | return -ENOENT; |
| 2234 | for (i = 0; i < items; i++) { |
| 2235 | if (!isdigit(namelist[i]->d_name[0])) { |
| 2236 | /* Filter out . and .. */ |
| 2237 | continue; |
| 2238 | } |
| 2239 | pid = atoi(namelist[i]->d_name); |
| 2240 | sprintf(path, "%s/%s/proc/kallsyms", |
| 2241 | symbol_conf.guestmount, |
| 2242 | namelist[i]->d_name); |
| 2243 | ret = access(path, R_OK); |
| 2244 | if (ret) { |
| 2245 | pr_debug("Can't access file %s\n", path); |
| 2246 | goto failure; |
| 2247 | } |
Arnaldo Carvalho de Melo | d28c622 | 2010-04-27 21:20:43 -0300 | [diff] [blame] | 2248 | machines__create_kernel_maps(self, pid); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 2249 | } |
| 2250 | failure: |
| 2251 | free(namelist); |
| 2252 | } |
| 2253 | |
| 2254 | return ret; |
| 2255 | } |
Arnaldo Carvalho de Melo | 5c0541d | 2010-04-29 15:25:23 -0300 | [diff] [blame] | 2256 | |
| 2257 | int machine__load_kallsyms(struct machine *self, const char *filename, |
| 2258 | enum map_type type, symbol_filter_t filter) |
| 2259 | { |
| 2260 | struct map *map = self->vmlinux_maps[type]; |
| 2261 | int ret = dso__load_kallsyms(map->dso, filename, map, filter); |
| 2262 | |
| 2263 | if (ret > 0) { |
| 2264 | dso__set_loaded(map->dso, type); |
| 2265 | /* |
| 2266 | * Since /proc/kallsyms will have multiple sessions for the |
| 2267 | * kernel, with modules between them, fixup the end of all |
| 2268 | * sections. |
| 2269 | */ |
| 2270 | __map_groups__fixup_end(&self->kmaps, type); |
| 2271 | } |
| 2272 | |
| 2273 | return ret; |
| 2274 | } |
| 2275 | |
| 2276 | int machine__load_vmlinux_path(struct machine *self, enum map_type type, |
| 2277 | symbol_filter_t filter) |
| 2278 | { |
| 2279 | struct map *map = self->vmlinux_maps[type]; |
| 2280 | int ret = dso__load_vmlinux_path(map->dso, map, filter); |
| 2281 | |
| 2282 | if (ret > 0) { |
| 2283 | dso__set_loaded(map->dso, type); |
| 2284 | map__reloc_vmlinux(map); |
| 2285 | } |
| 2286 | |
| 2287 | return ret; |
| 2288 | } |