Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1 | #include "util.h" |
| 2 | #include "../perf.h" |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 3 | #include "string.h" |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 4 | #include "symbol.h" |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 5 | #include "thread.h" |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 6 | |
Frederic Weisbecker | 8f28827 | 2009-08-16 22:05:48 +0200 | [diff] [blame] | 7 | #include "debug.h" |
| 8 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 9 | #include <libelf.h> |
| 10 | #include <gelf.h> |
| 11 | #include <elf.h> |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 12 | #include <limits.h> |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 13 | #include <sys/utsname.h> |
Peter Zijlstra | 2cdbc46 | 2009-08-05 14:05:16 +0200 | [diff] [blame] | 14 | |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 15 | enum dso_origin { |
| 16 | DSO__ORIG_KERNEL = 0, |
| 17 | DSO__ORIG_JAVA_JIT, |
| 18 | DSO__ORIG_FEDORA, |
| 19 | DSO__ORIG_UBUNTU, |
| 20 | DSO__ORIG_BUILDID, |
| 21 | DSO__ORIG_DSO, |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 22 | DSO__ORIG_KMODULE, |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 23 | DSO__ORIG_NOT_FOUND, |
| 24 | }; |
| 25 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 26 | static void dsos__add(struct dso *dso); |
| 27 | static struct dso *dsos__find(const char *name); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 28 | static struct map *map__new2(u64 start, struct dso *dso); |
| 29 | static void kernel_maps__insert(struct map *map); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 30 | unsigned int symbol__priv_size; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 31 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 32 | static struct rb_root kernel_maps; |
| 33 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 34 | static void dso__fixup_sym_end(struct dso *self) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 35 | { |
| 36 | struct rb_node *nd, *prevnd = rb_first(&self->syms); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 37 | struct symbol *curr, *prev; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 38 | |
| 39 | if (prevnd == NULL) |
| 40 | return; |
| 41 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 42 | curr = rb_entry(prevnd, struct symbol, rb_node); |
| 43 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 44 | for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 45 | prev = curr; |
| 46 | curr = rb_entry(nd, struct symbol, rb_node); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 47 | |
| 48 | if (prev->end == prev->start) |
| 49 | prev->end = curr->start - 1; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 50 | } |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 51 | |
| 52 | /* Last entry */ |
| 53 | if (curr->end == curr->start) |
| 54 | curr->end = roundup(curr->start, 4096); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 55 | } |
| 56 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 57 | static void kernel_maps__fixup_end(void) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 58 | { |
| 59 | struct map *prev, *curr; |
| 60 | struct rb_node *nd, *prevnd = rb_first(&kernel_maps); |
| 61 | |
| 62 | if (prevnd == NULL) |
| 63 | return; |
| 64 | |
| 65 | curr = rb_entry(prevnd, struct map, rb_node); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 66 | |
| 67 | for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) { |
| 68 | prev = curr; |
| 69 | curr = rb_entry(nd, struct map, rb_node); |
| 70 | prev->end = curr->start - 1; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | nd = rb_last(&curr->dso->syms); |
| 74 | if (nd) { |
| 75 | struct symbol *sym = rb_entry(nd, struct symbol, rb_node); |
| 76 | curr->end = sym->end; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 80 | 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] | 81 | { |
Arnaldo Carvalho de Melo | 0085c95 | 2009-05-28 14:55:13 -0300 | [diff] [blame] | 82 | size_t namelen = strlen(name) + 1; |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 83 | struct symbol *self = calloc(1, (symbol__priv_size + |
| 84 | sizeof(*self) + namelen)); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 85 | if (!self) |
| 86 | return NULL; |
| 87 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 88 | if (symbol__priv_size) { |
| 89 | memset(self, 0, symbol__priv_size); |
| 90 | self = ((void *)self) + symbol__priv_size; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 91 | } |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 92 | self->start = start; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 93 | self->end = len ? start + len - 1 : start; |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 94 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 95 | pr_debug3("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end); |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 96 | |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 97 | memcpy(self->name, name, namelen); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 98 | |
| 99 | return self; |
| 100 | } |
| 101 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 102 | static void symbol__delete(struct symbol *self) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 103 | { |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 104 | free(((void *)self) - symbol__priv_size); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static size_t symbol__fprintf(struct symbol *self, FILE *fp) |
| 108 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 109 | return fprintf(fp, " %llx-%llx %s\n", |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 110 | self->start, self->end, self->name); |
| 111 | } |
| 112 | |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 113 | static void dso__set_long_name(struct dso *self, char *name) |
| 114 | { |
| 115 | self->long_name = name; |
| 116 | self->long_name_len = strlen(name); |
| 117 | } |
| 118 | |
| 119 | static void dso__set_basename(struct dso *self) |
| 120 | { |
| 121 | self->short_name = basename(self->long_name); |
| 122 | } |
| 123 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 124 | struct dso *dso__new(const char *name) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 125 | { |
| 126 | struct dso *self = malloc(sizeof(*self) + strlen(name) + 1); |
| 127 | |
| 128 | if (self != NULL) { |
| 129 | strcpy(self->name, name); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 130 | dso__set_long_name(self, self->name); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 131 | self->short_name = self->name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 132 | self->syms = RB_ROOT; |
Peter Zijlstra | fc54db5 | 2009-06-05 14:04:59 +0200 | [diff] [blame] | 133 | self->find_symbol = dso__find_symbol; |
Arnaldo Carvalho de Melo | 52d422d | 2009-07-10 22:47:28 -0300 | [diff] [blame] | 134 | self->slen_calculated = 0; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 135 | self->origin = DSO__ORIG_NOT_FOUND; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 136 | self->loaded = 0; |
| 137 | self->has_build_id = 0; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return self; |
| 141 | } |
| 142 | |
| 143 | static void dso__delete_symbols(struct dso *self) |
| 144 | { |
| 145 | struct symbol *pos; |
| 146 | struct rb_node *next = rb_first(&self->syms); |
| 147 | |
| 148 | while (next) { |
| 149 | pos = rb_entry(next, struct symbol, rb_node); |
| 150 | next = rb_next(&pos->rb_node); |
Arnaldo Carvalho de Melo | c8c9652 | 2009-06-01 17:50:57 -0300 | [diff] [blame] | 151 | rb_erase(&pos->rb_node, &self->syms); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 152 | symbol__delete(pos); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| 156 | void dso__delete(struct dso *self) |
| 157 | { |
| 158 | dso__delete_symbols(self); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 159 | if (self->long_name != self->name) |
| 160 | free(self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 161 | free(self); |
| 162 | } |
| 163 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 164 | void dso__set_build_id(struct dso *self, void *build_id) |
| 165 | { |
| 166 | memcpy(self->build_id, build_id, sizeof(self->build_id)); |
| 167 | self->has_build_id = 1; |
| 168 | } |
| 169 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 170 | static void dso__insert_symbol(struct dso *self, struct symbol *sym) |
| 171 | { |
| 172 | struct rb_node **p = &self->syms.rb_node; |
| 173 | struct rb_node *parent = NULL; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 174 | const u64 ip = sym->start; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 175 | struct symbol *s; |
| 176 | |
| 177 | while (*p != NULL) { |
| 178 | parent = *p; |
| 179 | s = rb_entry(parent, struct symbol, rb_node); |
| 180 | if (ip < s->start) |
| 181 | p = &(*p)->rb_left; |
| 182 | else |
| 183 | p = &(*p)->rb_right; |
| 184 | } |
| 185 | rb_link_node(&sym->rb_node, parent, p); |
| 186 | rb_insert_color(&sym->rb_node, &self->syms); |
| 187 | } |
| 188 | |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 189 | struct symbol *dso__find_symbol(struct dso *self, u64 ip) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 190 | { |
| 191 | struct rb_node *n; |
| 192 | |
| 193 | if (self == NULL) |
| 194 | return NULL; |
| 195 | |
| 196 | n = self->syms.rb_node; |
| 197 | |
| 198 | while (n) { |
| 199 | struct symbol *s = rb_entry(n, struct symbol, rb_node); |
| 200 | |
| 201 | if (ip < s->start) |
| 202 | n = n->rb_left; |
| 203 | else if (ip > s->end) |
| 204 | n = n->rb_right; |
| 205 | else |
| 206 | return s; |
| 207 | } |
| 208 | |
| 209 | return NULL; |
| 210 | } |
| 211 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 212 | int build_id__sprintf(u8 *self, int len, char *bf) |
| 213 | { |
| 214 | char *bid = bf; |
| 215 | u8 *raw = self; |
| 216 | int i; |
| 217 | |
| 218 | for (i = 0; i < len; ++i) { |
| 219 | sprintf(bid, "%02x", *raw); |
| 220 | ++raw; |
| 221 | bid += 2; |
| 222 | } |
| 223 | |
| 224 | return raw - self; |
| 225 | } |
| 226 | |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 227 | size_t dso__fprintf_buildid(struct dso *self, FILE *fp) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 228 | { |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 229 | char sbuild_id[BUILD_ID_SIZE * 2 + 1]; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 230 | |
| 231 | 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] | 232 | return fprintf(fp, "%s", sbuild_id); |
| 233 | } |
| 234 | |
| 235 | size_t dso__fprintf(struct dso *self, FILE *fp) |
| 236 | { |
| 237 | struct rb_node *nd; |
| 238 | size_t ret = fprintf(fp, "dso: %s (", self->short_name); |
| 239 | |
| 240 | ret += dso__fprintf_buildid(self, fp); |
| 241 | ret += fprintf(fp, ")\n"); |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 242 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 243 | for (nd = rb_first(&self->syms); nd; nd = rb_next(nd)) { |
| 244 | struct symbol *pos = rb_entry(nd, struct symbol, rb_node); |
| 245 | ret += symbol__fprintf(pos, fp); |
| 246 | } |
| 247 | |
| 248 | return ret; |
| 249 | } |
| 250 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 251 | /* |
| 252 | * Loads the function entries in /proc/kallsyms into kernel_map->dso, |
| 253 | * so that we can in the next step set the symbol ->end address and then |
| 254 | * call kernel_maps__split_kallsyms. |
| 255 | */ |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 256 | static int kernel_maps__load_all_kallsyms(void) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 257 | { |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 258 | char *line = NULL; |
| 259 | size_t n; |
| 260 | FILE *file = fopen("/proc/kallsyms", "r"); |
| 261 | |
| 262 | if (file == NULL) |
| 263 | goto out_failure; |
| 264 | |
| 265 | while (!feof(file)) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 266 | u64 start; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 267 | struct symbol *sym; |
| 268 | int line_len, len; |
| 269 | char symbol_type; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 270 | char *symbol_name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 271 | |
| 272 | line_len = getline(&line, &n, file); |
| 273 | if (line_len < 0) |
| 274 | break; |
| 275 | |
| 276 | if (!line) |
| 277 | goto out_failure; |
| 278 | |
| 279 | line[--line_len] = '\0'; /* \n */ |
| 280 | |
Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 281 | len = hex2u64(line, &start); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 282 | |
| 283 | len++; |
| 284 | if (len + 2 >= line_len) |
| 285 | continue; |
| 286 | |
| 287 | symbol_type = toupper(line[len]); |
| 288 | /* |
| 289 | * We're interested only in code ('T'ext) |
| 290 | */ |
| 291 | if (symbol_type != 'T' && symbol_type != 'W') |
| 292 | continue; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 293 | |
| 294 | symbol_name = line + len + 2; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 295 | /* |
| 296 | * Will fix up the end later, when we have all symbols sorted. |
| 297 | */ |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 298 | sym = symbol__new(start, 0, symbol_name); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 299 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 300 | if (sym == NULL) |
| 301 | goto out_delete_line; |
| 302 | |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 303 | /* |
| 304 | * We will pass the symbols to the filter later, in |
| 305 | * kernel_maps__split_kallsyms, when we have split the |
| 306 | * maps per module |
| 307 | */ |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 308 | dso__insert_symbol(kernel_map->dso, sym); |
| 309 | } |
| 310 | |
| 311 | free(line); |
| 312 | fclose(file); |
| 313 | |
| 314 | return 0; |
| 315 | |
| 316 | out_delete_line: |
| 317 | free(line); |
| 318 | out_failure: |
| 319 | return -1; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * Split the symbols into maps, making sure there are no overlaps, i.e. the |
| 324 | * kernel range is broken in several maps, named [kernel].N, as we don't have |
| 325 | * the original ELF section names vmlinux have. |
| 326 | */ |
| 327 | static int kernel_maps__split_kallsyms(symbol_filter_t filter, int use_modules) |
| 328 | { |
| 329 | struct map *map = kernel_map; |
| 330 | struct symbol *pos; |
| 331 | int count = 0; |
| 332 | struct rb_node *next = rb_first(&kernel_map->dso->syms); |
| 333 | int kernel_range = 0; |
| 334 | |
| 335 | while (next) { |
| 336 | char *module; |
| 337 | |
| 338 | pos = rb_entry(next, struct symbol, rb_node); |
| 339 | next = rb_next(&pos->rb_node); |
| 340 | |
| 341 | module = strchr(pos->name, '\t'); |
| 342 | if (module) { |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 343 | if (!use_modules) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 344 | goto delete_symbol; |
| 345 | |
| 346 | *module++ = '\0'; |
| 347 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 348 | if (strcmp(map->dso->name, module)) { |
| 349 | map = kernel_maps__find_by_dso_name(module); |
| 350 | if (!map) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 351 | pr_err("/proc/{kallsyms,modules} " |
| 352 | "inconsistency!\n"); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 353 | return -1; |
| 354 | } |
| 355 | } |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 356 | /* |
| 357 | * So that we look just like we get from .ko files, |
| 358 | * i.e. not prelinked, relative to map->start. |
| 359 | */ |
| 360 | pos->start = map->map_ip(map, pos->start); |
| 361 | pos->end = map->map_ip(map, pos->end); |
| 362 | } else if (map != kernel_map) { |
| 363 | char dso_name[PATH_MAX]; |
| 364 | struct dso *dso; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 365 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 366 | snprintf(dso_name, sizeof(dso_name), "[kernel].%d", |
| 367 | kernel_range++); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 368 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 369 | dso = dso__new(dso_name); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 370 | if (dso == NULL) |
| 371 | return -1; |
| 372 | |
| 373 | map = map__new2(pos->start, dso); |
| 374 | if (map == NULL) { |
| 375 | dso__delete(dso); |
| 376 | return -1; |
| 377 | } |
| 378 | |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 379 | map->map_ip = map->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 380 | kernel_maps__insert(map); |
| 381 | ++kernel_range; |
| 382 | } |
| 383 | |
| 384 | if (filter && filter(map, pos)) { |
| 385 | delete_symbol: |
| 386 | rb_erase(&pos->rb_node, &kernel_map->dso->syms); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 387 | symbol__delete(pos); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 388 | } else { |
| 389 | if (map != kernel_map) { |
| 390 | rb_erase(&pos->rb_node, &kernel_map->dso->syms); |
| 391 | dso__insert_symbol(map->dso, pos); |
| 392 | } |
Mike Galbraith | 9974f49 | 2009-07-02 08:05:58 +0200 | [diff] [blame] | 393 | count++; |
| 394 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 395 | } |
| 396 | |
Mike Galbraith | 9974f49 | 2009-07-02 08:05:58 +0200 | [diff] [blame] | 397 | return count; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 398 | } |
| 399 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 400 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 401 | static int kernel_maps__load_kallsyms(symbol_filter_t filter, int use_modules) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 402 | { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 403 | if (kernel_maps__load_all_kallsyms()) |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 404 | return -1; |
| 405 | |
| 406 | dso__fixup_sym_end(kernel_map->dso); |
| 407 | |
| 408 | return kernel_maps__split_kallsyms(filter, use_modules); |
| 409 | } |
| 410 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 411 | static size_t kernel_maps__fprintf(FILE *fp) |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 412 | { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 413 | size_t printed = fprintf(fp, "Kernel maps:\n"); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 414 | struct rb_node *nd; |
| 415 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 416 | for (nd = rb_first(&kernel_maps); nd; nd = rb_next(nd)) { |
| 417 | struct map *pos = rb_entry(nd, struct map, rb_node); |
| 418 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 419 | printed += fprintf(fp, "Map:"); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 420 | printed += map__fprintf(pos, fp); |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 421 | if (verbose > 1) { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 422 | printed += dso__fprintf(pos->dso, fp); |
| 423 | printed += fprintf(fp, "--\n"); |
| 424 | } |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 425 | } |
| 426 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 427 | return printed + fprintf(fp, "END kernel maps\n"); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 428 | } |
| 429 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 430 | 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] | 431 | symbol_filter_t filter) |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 432 | { |
| 433 | char *line = NULL; |
| 434 | size_t n; |
| 435 | FILE *file; |
| 436 | int nr_syms = 0; |
| 437 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 438 | file = fopen(self->long_name, "r"); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 439 | if (file == NULL) |
| 440 | goto out_failure; |
| 441 | |
| 442 | while (!feof(file)) { |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 443 | u64 start, size; |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 444 | struct symbol *sym; |
| 445 | int line_len, len; |
| 446 | |
| 447 | line_len = getline(&line, &n, file); |
| 448 | if (line_len < 0) |
| 449 | break; |
| 450 | |
| 451 | if (!line) |
| 452 | goto out_failure; |
| 453 | |
| 454 | line[--line_len] = '\0'; /* \n */ |
| 455 | |
| 456 | len = hex2u64(line, &start); |
| 457 | |
| 458 | len++; |
| 459 | if (len + 2 >= line_len) |
| 460 | continue; |
| 461 | |
| 462 | len += hex2u64(line + len, &size); |
| 463 | |
| 464 | len++; |
| 465 | if (len + 2 >= line_len) |
| 466 | continue; |
| 467 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 468 | sym = symbol__new(start, size, line + len); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 469 | |
| 470 | if (sym == NULL) |
| 471 | goto out_delete_line; |
| 472 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 473 | if (filter && filter(map, sym)) |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 474 | symbol__delete(sym); |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 475 | else { |
| 476 | dso__insert_symbol(self, sym); |
| 477 | nr_syms++; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | free(line); |
| 482 | fclose(file); |
| 483 | |
| 484 | return nr_syms; |
| 485 | |
| 486 | out_delete_line: |
| 487 | free(line); |
| 488 | out_failure: |
| 489 | return -1; |
| 490 | } |
| 491 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 492 | /** |
| 493 | * elf_symtab__for_each_symbol - iterate thru all the symbols |
| 494 | * |
| 495 | * @self: struct elf_symtab instance to iterate |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 496 | * @idx: uint32_t idx |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 497 | * @sym: GElf_Sym iterator |
| 498 | */ |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 499 | #define elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) \ |
| 500 | for (idx = 0, gelf_getsym(syms, idx, &sym);\ |
| 501 | idx < nr_syms; \ |
| 502 | idx++, gelf_getsym(syms, idx, &sym)) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 503 | |
| 504 | static inline uint8_t elf_sym__type(const GElf_Sym *sym) |
| 505 | { |
| 506 | return GELF_ST_TYPE(sym->st_info); |
| 507 | } |
| 508 | |
| 509 | static inline int elf_sym__is_function(const GElf_Sym *sym) |
| 510 | { |
| 511 | return elf_sym__type(sym) == STT_FUNC && |
| 512 | sym->st_name != 0 && |
Arnaldo Carvalho de Melo | 8183313 | 2009-10-05 23:35:03 -0300 | [diff] [blame] | 513 | sym->st_shndx != SHN_UNDEF; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 514 | } |
| 515 | |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 516 | static inline int elf_sym__is_label(const GElf_Sym *sym) |
| 517 | { |
| 518 | return elf_sym__type(sym) == STT_NOTYPE && |
| 519 | sym->st_name != 0 && |
| 520 | sym->st_shndx != SHN_UNDEF && |
| 521 | sym->st_shndx != SHN_ABS; |
| 522 | } |
| 523 | |
| 524 | static inline const char *elf_sec__name(const GElf_Shdr *shdr, |
| 525 | const Elf_Data *secstrs) |
| 526 | { |
| 527 | return secstrs->d_buf + shdr->sh_name; |
| 528 | } |
| 529 | |
| 530 | static inline int elf_sec__is_text(const GElf_Shdr *shdr, |
| 531 | const Elf_Data *secstrs) |
| 532 | { |
| 533 | return strstr(elf_sec__name(shdr, secstrs), "text") != NULL; |
| 534 | } |
| 535 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 536 | static inline const char *elf_sym__name(const GElf_Sym *sym, |
| 537 | const Elf_Data *symstrs) |
| 538 | { |
| 539 | return symstrs->d_buf + sym->st_name; |
| 540 | } |
| 541 | |
| 542 | static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, |
| 543 | GElf_Shdr *shp, const char *name, |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 544 | size_t *idx) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 545 | { |
| 546 | Elf_Scn *sec = NULL; |
| 547 | size_t cnt = 1; |
| 548 | |
| 549 | while ((sec = elf_nextscn(elf, sec)) != NULL) { |
| 550 | char *str; |
| 551 | |
| 552 | gelf_getshdr(sec, shp); |
| 553 | str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); |
| 554 | if (!strcmp(name, str)) { |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 555 | if (idx) |
| 556 | *idx = cnt; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | ++cnt; |
| 560 | } |
| 561 | |
| 562 | return sec; |
| 563 | } |
| 564 | |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 565 | #define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \ |
| 566 | for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \ |
| 567 | idx < nr_entries; \ |
| 568 | ++idx, pos = gelf_getrel(reldata, idx, &pos_mem)) |
| 569 | |
| 570 | #define elf_section__for_each_rela(reldata, pos, pos_mem, idx, nr_entries) \ |
| 571 | for (idx = 0, pos = gelf_getrela(reldata, 0, &pos_mem); \ |
| 572 | idx < nr_entries; \ |
| 573 | ++idx, pos = gelf_getrela(reldata, idx, &pos_mem)) |
| 574 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 575 | /* |
| 576 | * We need to check if we have a .dynsym, so that we can handle the |
| 577 | * .plt, synthesizing its symbols, that aren't on the symtabs (be it |
| 578 | * .dynsym or .symtab). |
| 579 | * And always look at the original dso, not at debuginfo packages, that |
| 580 | * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS). |
| 581 | */ |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 582 | static int dso__synthesize_plt_symbols(struct dso *self, struct map *map, |
| 583 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 584 | { |
| 585 | uint32_t nr_rel_entries, idx; |
| 586 | GElf_Sym sym; |
Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 587 | u64 plt_offset; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 588 | GElf_Shdr shdr_plt; |
| 589 | struct symbol *f; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 590 | GElf_Shdr shdr_rel_plt, shdr_dynsym; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 591 | Elf_Data *reldata, *syms, *symstrs; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 592 | Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym; |
| 593 | size_t dynsym_idx; |
| 594 | GElf_Ehdr ehdr; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 595 | char sympltname[1024]; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 596 | Elf *elf; |
| 597 | int nr = 0, symidx, fd, err = 0; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 598 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 599 | fd = open(self->long_name, O_RDONLY); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 600 | if (fd < 0) |
| 601 | goto out; |
| 602 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 603 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 604 | if (elf == NULL) |
| 605 | goto out_close; |
| 606 | |
| 607 | if (gelf_getehdr(elf, &ehdr) == NULL) |
| 608 | goto out_elf_end; |
| 609 | |
| 610 | scn_dynsym = elf_section_by_name(elf, &ehdr, &shdr_dynsym, |
| 611 | ".dynsym", &dynsym_idx); |
| 612 | if (scn_dynsym == NULL) |
| 613 | goto out_elf_end; |
| 614 | |
| 615 | 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] | 616 | ".rela.plt", NULL); |
| 617 | if (scn_plt_rel == NULL) { |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 618 | 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] | 619 | ".rel.plt", NULL); |
| 620 | if (scn_plt_rel == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 621 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 622 | } |
| 623 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 624 | err = -1; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 625 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 626 | if (shdr_rel_plt.sh_link != dynsym_idx) |
| 627 | goto out_elf_end; |
| 628 | |
| 629 | if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL) |
| 630 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 631 | |
| 632 | /* |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 633 | * 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] | 634 | * and the symbols in the .dynsym they refer to. |
| 635 | */ |
| 636 | reldata = elf_getdata(scn_plt_rel, NULL); |
| 637 | if (reldata == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 638 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 639 | |
| 640 | syms = elf_getdata(scn_dynsym, NULL); |
| 641 | if (syms == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 642 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 643 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 644 | scn_symstrs = elf_getscn(elf, shdr_dynsym.sh_link); |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 645 | if (scn_symstrs == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 646 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 647 | |
| 648 | symstrs = elf_getdata(scn_symstrs, NULL); |
| 649 | if (symstrs == NULL) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 650 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 651 | |
| 652 | nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize; |
| 653 | plt_offset = shdr_plt.sh_offset; |
| 654 | |
| 655 | if (shdr_rel_plt.sh_type == SHT_RELA) { |
| 656 | GElf_Rela pos_mem, *pos; |
| 657 | |
| 658 | elf_section__for_each_rela(reldata, pos, pos_mem, idx, |
| 659 | nr_rel_entries) { |
| 660 | symidx = GELF_R_SYM(pos->r_info); |
| 661 | plt_offset += shdr_plt.sh_entsize; |
| 662 | gelf_getsym(syms, symidx, &sym); |
| 663 | snprintf(sympltname, sizeof(sympltname), |
| 664 | "%s@plt", elf_sym__name(&sym, symstrs)); |
| 665 | |
| 666 | f = symbol__new(plt_offset, shdr_plt.sh_entsize, |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 667 | sympltname); |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 668 | if (!f) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 669 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 670 | |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 671 | if (filter && filter(map, f)) |
| 672 | symbol__delete(f); |
| 673 | else { |
| 674 | dso__insert_symbol(self, f); |
| 675 | ++nr; |
| 676 | } |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 677 | } |
| 678 | } else if (shdr_rel_plt.sh_type == SHT_REL) { |
| 679 | GElf_Rel pos_mem, *pos; |
| 680 | elf_section__for_each_rel(reldata, pos, pos_mem, idx, |
| 681 | nr_rel_entries) { |
| 682 | symidx = GELF_R_SYM(pos->r_info); |
| 683 | plt_offset += shdr_plt.sh_entsize; |
| 684 | gelf_getsym(syms, symidx, &sym); |
| 685 | snprintf(sympltname, sizeof(sympltname), |
| 686 | "%s@plt", elf_sym__name(&sym, symstrs)); |
| 687 | |
| 688 | f = symbol__new(plt_offset, shdr_plt.sh_entsize, |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 689 | sympltname); |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 690 | if (!f) |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 691 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 692 | |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 693 | if (filter && filter(map, f)) |
| 694 | symbol__delete(f); |
| 695 | else { |
| 696 | dso__insert_symbol(self, f); |
| 697 | ++nr; |
| 698 | } |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 699 | } |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 700 | } |
| 701 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 702 | err = 0; |
| 703 | out_elf_end: |
| 704 | elf_end(elf); |
| 705 | out_close: |
| 706 | close(fd); |
| 707 | |
| 708 | if (err == 0) |
| 709 | return nr; |
| 710 | out: |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 711 | pr_warning("%s: problems reading %s PLT info.\n", |
| 712 | __func__, self->long_name); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 713 | return 0; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 714 | } |
| 715 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 716 | static int dso__load_sym(struct dso *self, struct map *map, const char *name, |
| 717 | int fd, symbol_filter_t filter, int kernel, |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 718 | int kmodule) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 719 | { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 720 | struct map *curr_map = map; |
| 721 | struct dso *curr_dso = self; |
| 722 | size_t dso_name_len = strlen(self->short_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 723 | Elf_Data *symstrs, *secstrs; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 724 | uint32_t nr_syms; |
| 725 | int err = -1; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 726 | uint32_t idx; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 727 | GElf_Ehdr ehdr; |
| 728 | GElf_Shdr shdr; |
| 729 | Elf_Data *syms; |
| 730 | GElf_Sym sym; |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 731 | Elf_Scn *sec, *sec_strndx; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 732 | Elf *elf; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 733 | int nr = 0; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 734 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 735 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 736 | if (elf == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 737 | 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] | 738 | goto out_close; |
| 739 | } |
| 740 | |
| 741 | if (gelf_getehdr(elf, &ehdr) == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 742 | pr_err("%s: cannot get elf header.\n", __func__); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 743 | goto out_elf_end; |
| 744 | } |
| 745 | |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 746 | sec = elf_section_by_name(elf, &ehdr, &shdr, ".symtab", NULL); |
| 747 | if (sec == NULL) { |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 748 | sec = elf_section_by_name(elf, &ehdr, &shdr, ".dynsym", NULL); |
| 749 | if (sec == NULL) |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 750 | goto out_elf_end; |
Arnaldo Carvalho de Melo | 8ce998d | 2009-06-03 00:54:33 -0300 | [diff] [blame] | 751 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 752 | |
| 753 | syms = elf_getdata(sec, NULL); |
| 754 | if (syms == NULL) |
| 755 | goto out_elf_end; |
| 756 | |
| 757 | sec = elf_getscn(elf, shdr.sh_link); |
| 758 | if (sec == NULL) |
| 759 | goto out_elf_end; |
| 760 | |
| 761 | symstrs = elf_getdata(sec, NULL); |
| 762 | if (symstrs == NULL) |
| 763 | goto out_elf_end; |
| 764 | |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 765 | sec_strndx = elf_getscn(elf, ehdr.e_shstrndx); |
| 766 | if (sec_strndx == NULL) |
| 767 | goto out_elf_end; |
| 768 | |
| 769 | secstrs = elf_getdata(sec_strndx, NULL); |
Stoyan Gaydarov | 9b30a26 | 2009-07-30 05:25:29 -0500 | [diff] [blame] | 770 | if (secstrs == NULL) |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 771 | goto out_elf_end; |
| 772 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 773 | nr_syms = shdr.sh_size / shdr.sh_entsize; |
| 774 | |
Arjan van de Ven | e9fbc9d | 2009-06-06 21:22:33 +0200 | [diff] [blame] | 775 | memset(&sym, 0, sizeof(sym)); |
Mike Galbraith | d20ff6b | 2009-07-20 14:01:38 +0200 | [diff] [blame] | 776 | if (!kernel) { |
| 777 | self->adjust_symbols = (ehdr.e_type == ET_EXEC || |
Arnaldo Carvalho de Melo | 30d7a77 | 2009-07-02 21:24:14 -0300 | [diff] [blame] | 778 | elf_section_by_name(elf, &ehdr, &shdr, |
| 779 | ".gnu.prelink_undo", |
| 780 | NULL) != NULL); |
Mike Galbraith | d20ff6b | 2009-07-20 14:01:38 +0200 | [diff] [blame] | 781 | } else self->adjust_symbols = 0; |
| 782 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 783 | elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) { |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 784 | struct symbol *f; |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 785 | const char *elf_name; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 786 | char *demangled = NULL; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 787 | int is_label = elf_sym__is_label(&sym); |
| 788 | const char *section_name; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 789 | |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 790 | if (!is_label && !elf_sym__is_function(&sym)) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 791 | continue; |
| 792 | |
| 793 | sec = elf_getscn(elf, sym.st_shndx); |
| 794 | if (!sec) |
| 795 | goto out_elf_end; |
| 796 | |
| 797 | gelf_getshdr(sec, &shdr); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 798 | |
| 799 | if (is_label && !elf_sec__is_text(&shdr, secstrs)) |
| 800 | continue; |
| 801 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 802 | elf_name = elf_sym__name(&sym, symstrs); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 803 | section_name = elf_sec__name(&shdr, secstrs); |
Ingo Molnar | 0b73da3 | 2009-06-06 15:48:52 +0200 | [diff] [blame] | 804 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 805 | if (kernel || kmodule) { |
| 806 | char dso_name[PATH_MAX]; |
| 807 | |
| 808 | if (strcmp(section_name, |
| 809 | curr_dso->short_name + dso_name_len) == 0) |
| 810 | goto new_symbol; |
| 811 | |
| 812 | if (strcmp(section_name, ".text") == 0) { |
| 813 | curr_map = map; |
| 814 | curr_dso = self; |
| 815 | goto new_symbol; |
| 816 | } |
| 817 | |
| 818 | snprintf(dso_name, sizeof(dso_name), |
| 819 | "%s%s", self->short_name, section_name); |
| 820 | |
| 821 | curr_map = kernel_maps__find_by_dso_name(dso_name); |
| 822 | if (curr_map == NULL) { |
| 823 | u64 start = sym.st_value; |
| 824 | |
| 825 | if (kmodule) |
| 826 | start += map->start + shdr.sh_offset; |
| 827 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 828 | curr_dso = dso__new(dso_name); |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 829 | if (curr_dso == NULL) |
| 830 | goto out_elf_end; |
| 831 | curr_map = map__new2(start, curr_dso); |
| 832 | if (curr_map == NULL) { |
| 833 | dso__delete(curr_dso); |
| 834 | goto out_elf_end; |
| 835 | } |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 836 | curr_map->map_ip = identity__map_ip; |
| 837 | curr_map->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 838 | curr_dso->origin = DSO__ORIG_KERNEL; |
| 839 | kernel_maps__insert(curr_map); |
| 840 | dsos__add(curr_dso); |
| 841 | } else |
| 842 | curr_dso = curr_map->dso; |
| 843 | |
| 844 | goto new_symbol; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 845 | } |
| 846 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 847 | if (curr_dso->adjust_symbols) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 848 | pr_debug2("adjusting symbol: st_value: %Lx sh_addr: " |
| 849 | "%Lx sh_offset: %Lx\n", (u64)sym.st_value, |
| 850 | (u64)shdr.sh_addr, (u64)shdr.sh_offset); |
Arnaldo Carvalho de Melo | f5812a7 | 2009-06-30 11:43:17 -0300 | [diff] [blame] | 851 | sym.st_value -= shdr.sh_addr - shdr.sh_offset; |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 852 | } |
Arnaldo Carvalho de Melo | 28ac909 | 2009-07-20 14:14:12 -0300 | [diff] [blame] | 853 | /* |
| 854 | * We need to figure out if the object was created from C++ sources |
| 855 | * DWARF DW_compile_unit has this, but we don't always have access |
| 856 | * to it... |
| 857 | */ |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 858 | demangled = bfd_demangle(NULL, elf_name, DMGL_PARAMS | DMGL_ANSI); |
Arnaldo Carvalho de Melo | 28ac909 | 2009-07-20 14:14:12 -0300 | [diff] [blame] | 859 | if (demangled != NULL) |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 860 | elf_name = demangled; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 861 | new_symbol: |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 862 | 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] | 863 | free(demangled); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 864 | if (!f) |
| 865 | goto out_elf_end; |
| 866 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 867 | if (filter && filter(curr_map, f)) |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 868 | symbol__delete(f); |
Arnaldo Carvalho de Melo | 69ee69f | 2009-05-28 14:55:26 -0300 | [diff] [blame] | 869 | else { |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 870 | dso__insert_symbol(curr_dso, f); |
Arnaldo Carvalho de Melo | 69ee69f | 2009-05-28 14:55:26 -0300 | [diff] [blame] | 871 | nr++; |
| 872 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 873 | } |
| 874 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 875 | /* |
| 876 | * For misannotated, zeroed, ASM function sizes. |
| 877 | */ |
| 878 | if (nr > 0) |
| 879 | dso__fixup_sym_end(self); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 880 | err = nr; |
| 881 | out_elf_end: |
| 882 | elf_end(elf); |
| 883 | out_close: |
| 884 | return err; |
| 885 | } |
| 886 | |
Arnaldo Carvalho de Melo | 78075ca | 2009-11-20 20:51:26 -0200 | [diff] [blame^] | 887 | static bool dso__build_id_equal(const struct dso *self, u8 *build_id) |
| 888 | { |
| 889 | return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0; |
| 890 | } |
| 891 | |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 892 | bool dsos__read_build_ids(void) |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 893 | { |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 894 | bool have_build_id = false; |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 895 | struct dso *pos; |
| 896 | |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 897 | list_for_each_entry(pos, &dsos, node) |
| 898 | if (filename__read_build_id(pos->long_name, pos->build_id, |
| 899 | sizeof(pos->build_id)) > 0) { |
| 900 | have_build_id = true; |
| 901 | pos->has_build_id = true; |
| 902 | } |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 903 | |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 904 | return have_build_id; |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 907 | /* |
| 908 | * Align offset to 4 bytes as needed for note name and descriptor data. |
| 909 | */ |
| 910 | #define NOTE_ALIGN(n) (((n) + 3) & -4U) |
| 911 | |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 912 | 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] | 913 | { |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 914 | int fd, err = -1; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 915 | GElf_Ehdr ehdr; |
| 916 | GElf_Shdr shdr; |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 917 | Elf_Data *data; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 918 | Elf_Scn *sec; |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 919 | void *ptr; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 920 | Elf *elf; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 921 | |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 922 | if (size < BUILD_ID_SIZE) |
| 923 | goto out; |
| 924 | |
| 925 | fd = open(filename, O_RDONLY); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 926 | if (fd < 0) |
| 927 | goto out; |
| 928 | |
Marti Raudsepp | 8408712 | 2009-10-24 19:10:36 +0300 | [diff] [blame] | 929 | elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 930 | if (elf == NULL) { |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 931 | 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] | 932 | goto out_close; |
| 933 | } |
| 934 | |
| 935 | if (gelf_getehdr(elf, &ehdr) == NULL) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 936 | pr_err("%s: cannot get elf header.\n", __func__); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 937 | goto out_elf_end; |
| 938 | } |
| 939 | |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 940 | sec = elf_section_by_name(elf, &ehdr, &shdr, |
| 941 | ".note.gnu.build-id", NULL); |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 942 | if (sec == NULL) { |
| 943 | sec = elf_section_by_name(elf, &ehdr, &shdr, |
| 944 | ".notes", NULL); |
| 945 | if (sec == NULL) |
| 946 | goto out_elf_end; |
| 947 | } |
| 948 | |
| 949 | data = elf_getdata(sec, NULL); |
| 950 | if (data == NULL) |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 951 | goto out_elf_end; |
| 952 | |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 953 | ptr = data->d_buf; |
| 954 | while (ptr < (data->d_buf + data->d_size)) { |
| 955 | GElf_Nhdr *nhdr = ptr; |
| 956 | int namesz = NOTE_ALIGN(nhdr->n_namesz), |
| 957 | descsz = NOTE_ALIGN(nhdr->n_descsz); |
| 958 | const char *name; |
| 959 | |
| 960 | ptr += sizeof(*nhdr); |
| 961 | name = ptr; |
| 962 | ptr += namesz; |
| 963 | if (nhdr->n_type == NT_GNU_BUILD_ID && |
| 964 | nhdr->n_namesz == sizeof("GNU")) { |
| 965 | if (memcmp(name, "GNU", sizeof("GNU")) == 0) { |
| 966 | memcpy(bf, ptr, BUILD_ID_SIZE); |
| 967 | err = BUILD_ID_SIZE; |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | ptr += descsz; |
| 972 | } |
Arnaldo Carvalho de Melo | 2643ce1 | 2009-11-03 21:46:10 -0200 | [diff] [blame] | 973 | out_elf_end: |
| 974 | elf_end(elf); |
| 975 | out_close: |
| 976 | close(fd); |
| 977 | out: |
| 978 | return err; |
| 979 | } |
| 980 | |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 981 | int sysfs__read_build_id(const char *filename, void *build_id, size_t size) |
| 982 | { |
| 983 | int fd, err = -1; |
| 984 | |
| 985 | if (size < BUILD_ID_SIZE) |
| 986 | goto out; |
| 987 | |
| 988 | fd = open(filename, O_RDONLY); |
| 989 | if (fd < 0) |
| 990 | goto out; |
| 991 | |
| 992 | while (1) { |
| 993 | char bf[BUFSIZ]; |
| 994 | GElf_Nhdr nhdr; |
| 995 | int namesz, descsz; |
| 996 | |
| 997 | if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr)) |
| 998 | break; |
| 999 | |
Arnaldo Carvalho de Melo | fd7a346 | 2009-11-20 20:51:25 -0200 | [diff] [blame] | 1000 | namesz = NOTE_ALIGN(nhdr.n_namesz); |
| 1001 | descsz = NOTE_ALIGN(nhdr.n_descsz); |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 1002 | if (nhdr.n_type == NT_GNU_BUILD_ID && |
| 1003 | nhdr.n_namesz == sizeof("GNU")) { |
| 1004 | if (read(fd, bf, namesz) != namesz) |
| 1005 | break; |
| 1006 | if (memcmp(bf, "GNU", sizeof("GNU")) == 0) { |
| 1007 | if (read(fd, build_id, |
| 1008 | BUILD_ID_SIZE) == BUILD_ID_SIZE) { |
| 1009 | err = 0; |
| 1010 | break; |
| 1011 | } |
| 1012 | } else if (read(fd, bf, descsz) != descsz) |
| 1013 | break; |
| 1014 | } else { |
| 1015 | int n = namesz + descsz; |
| 1016 | if (read(fd, bf, n) != n) |
| 1017 | break; |
| 1018 | } |
| 1019 | } |
| 1020 | close(fd); |
| 1021 | out: |
| 1022 | return err; |
| 1023 | } |
| 1024 | |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1025 | char dso__symtab_origin(const struct dso *self) |
| 1026 | { |
| 1027 | static const char origin[] = { |
| 1028 | [DSO__ORIG_KERNEL] = 'k', |
| 1029 | [DSO__ORIG_JAVA_JIT] = 'j', |
| 1030 | [DSO__ORIG_FEDORA] = 'f', |
| 1031 | [DSO__ORIG_UBUNTU] = 'u', |
| 1032 | [DSO__ORIG_BUILDID] = 'b', |
| 1033 | [DSO__ORIG_DSO] = 'd', |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1034 | [DSO__ORIG_KMODULE] = 'K', |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1035 | }; |
| 1036 | |
| 1037 | if (self == NULL || self->origin == DSO__ORIG_NOT_FOUND) |
| 1038 | return '!'; |
| 1039 | return origin[self->origin]; |
| 1040 | } |
| 1041 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1042 | 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] | 1043 | { |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1044 | int size = PATH_MAX; |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1045 | char *name = malloc(size); |
| 1046 | u8 build_id[BUILD_ID_SIZE]; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1047 | int ret = -1; |
| 1048 | int fd; |
| 1049 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1050 | self->loaded = 1; |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1051 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1052 | if (!name) |
| 1053 | return -1; |
| 1054 | |
Arnaldo Carvalho de Melo | 30d7a77 | 2009-07-02 21:24:14 -0300 | [diff] [blame] | 1055 | self->adjust_symbols = 0; |
Arnaldo Carvalho de Melo | f5812a7 | 2009-06-30 11:43:17 -0300 | [diff] [blame] | 1056 | |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1057 | if (strncmp(self->name, "/tmp/perf-", 10) == 0) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1058 | ret = dso__load_perf_map(self, map, filter); |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1059 | self->origin = ret > 0 ? DSO__ORIG_JAVA_JIT : |
| 1060 | DSO__ORIG_NOT_FOUND; |
| 1061 | return ret; |
| 1062 | } |
| 1063 | |
| 1064 | self->origin = DSO__ORIG_FEDORA - 1; |
Pekka Enberg | 80d496b | 2009-06-08 21:12:48 +0300 | [diff] [blame] | 1065 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1066 | more: |
| 1067 | do { |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1068 | self->origin++; |
| 1069 | switch (self->origin) { |
| 1070 | case DSO__ORIG_FEDORA: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1071 | snprintf(name, size, "/usr/lib/debug%s.debug", |
| 1072 | self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1073 | break; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1074 | case DSO__ORIG_UBUNTU: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1075 | snprintf(name, size, "/usr/lib/debug%s", |
| 1076 | self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1077 | break; |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1078 | case DSO__ORIG_BUILDID: |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1079 | if (filename__read_build_id(self->long_name, build_id, |
| 1080 | sizeof(build_id))) { |
| 1081 | char build_id_hex[BUILD_ID_SIZE * 2 + 1]; |
| 1082 | |
| 1083 | build_id__sprintf(build_id, sizeof(build_id), |
| 1084 | build_id_hex); |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1085 | snprintf(name, size, |
| 1086 | "/usr/lib/debug/.build-id/%.2s/%s.debug", |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1087 | build_id_hex, build_id_hex + 2); |
| 1088 | if (self->has_build_id) |
| 1089 | goto compare_build_id; |
| 1090 | break; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1091 | } |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1092 | self->origin++; |
Arnaldo Carvalho de Melo | 4d1e00a | 2009-08-05 19:02:49 -0300 | [diff] [blame] | 1093 | /* Fall thru */ |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1094 | case DSO__ORIG_DSO: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1095 | snprintf(name, size, "%s", self->long_name); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1096 | break; |
| 1097 | |
| 1098 | default: |
| 1099 | goto out; |
| 1100 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1101 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1102 | if (self->has_build_id) { |
Arnaldo Carvalho de Melo | d3379ab | 2009-11-18 20:20:50 -0200 | [diff] [blame] | 1103 | if (filename__read_build_id(name, build_id, |
| 1104 | sizeof(build_id)) < 0) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1105 | goto more; |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1106 | compare_build_id: |
Arnaldo Carvalho de Melo | 78075ca | 2009-11-20 20:51:26 -0200 | [diff] [blame^] | 1107 | if (!dso__build_id_equal(self, build_id)) |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1108 | goto more; |
| 1109 | } |
| 1110 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1111 | fd = open(name, O_RDONLY); |
| 1112 | } while (fd < 0); |
| 1113 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1114 | ret = dso__load_sym(self, map, name, fd, filter, 0, 0); |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1115 | close(fd); |
| 1116 | |
| 1117 | /* |
| 1118 | * Some people seem to have debuginfo files _WITHOUT_ debug info!?!? |
| 1119 | */ |
| 1120 | if (!ret) |
| 1121 | goto more; |
| 1122 | |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 1123 | if (ret > 0) { |
Arnaldo Carvalho de Melo | 8216416 | 2009-11-16 13:48:11 -0200 | [diff] [blame] | 1124 | int nr_plt = dso__synthesize_plt_symbols(self, map, filter); |
Arnaldo Carvalho de Melo | a25e46c | 2009-07-11 12:18:36 -0300 | [diff] [blame] | 1125 | if (nr_plt > 0) |
| 1126 | ret += nr_plt; |
| 1127 | } |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1128 | out: |
| 1129 | free(name); |
Arnaldo Carvalho de Melo | 1340e6b | 2009-08-11 17:04:36 -0300 | [diff] [blame] | 1130 | if (ret < 0 && strstr(self->name, " (deleted)") != NULL) |
| 1131 | return 0; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1132 | return ret; |
| 1133 | } |
| 1134 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1135 | struct map *kernel_map; |
| 1136 | |
| 1137 | static void kernel_maps__insert(struct map *map) |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1138 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1139 | maps__insert(&kernel_maps, map); |
| 1140 | } |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1141 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1142 | struct symbol *kernel_maps__find_symbol(u64 ip, struct map **mapp) |
| 1143 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1144 | struct map *map = maps__find(&kernel_maps, ip); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1145 | |
| 1146 | if (mapp) |
| 1147 | *mapp = map; |
| 1148 | |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1149 | if (map) { |
| 1150 | ip = map->map_ip(map, ip); |
| 1151 | return map->dso->find_symbol(map->dso, ip); |
| 1152 | } |
| 1153 | |
| 1154 | return NULL; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | struct map *kernel_maps__find_by_dso_name(const char *name) |
| 1158 | { |
| 1159 | struct rb_node *nd; |
| 1160 | |
| 1161 | for (nd = rb_first(&kernel_maps); nd; nd = rb_next(nd)) { |
| 1162 | struct map *map = rb_entry(nd, struct map, rb_node); |
| 1163 | |
| 1164 | if (map->dso && strcmp(map->dso->name, name) == 0) |
| 1165 | return map; |
| 1166 | } |
| 1167 | |
| 1168 | return NULL; |
| 1169 | } |
| 1170 | |
| 1171 | static int dso__load_module_sym(struct dso *self, struct map *map, |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1172 | symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1173 | { |
| 1174 | int err = 0, fd = open(self->long_name, O_RDONLY); |
| 1175 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1176 | self->loaded = 1; |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1177 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1178 | if (fd < 0) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1179 | pr_err("%s: cannot open %s\n", __func__, self->long_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1180 | return err; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1181 | } |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1182 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1183 | err = dso__load_sym(self, map, self->long_name, fd, filter, 0, 1); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1184 | close(fd); |
| 1185 | |
| 1186 | return err; |
| 1187 | } |
| 1188 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1189 | static int dsos__load_modules_sym_dir(char *dirname, symbol_filter_t filter) |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1190 | { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1191 | struct dirent *dent; |
| 1192 | int nr_symbols = 0, err; |
| 1193 | DIR *dir = opendir(dirname); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1194 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1195 | if (!dir) { |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1196 | pr_err("%s: cannot open %s dir\n", __func__, dirname); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1197 | return -1; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1198 | } |
| 1199 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1200 | while ((dent = readdir(dir)) != NULL) { |
| 1201 | char path[PATH_MAX]; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1202 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1203 | if (dent->d_type == DT_DIR) { |
| 1204 | if (!strcmp(dent->d_name, ".") || |
| 1205 | !strcmp(dent->d_name, "..")) |
| 1206 | continue; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1207 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1208 | snprintf(path, sizeof(path), "%s/%s", |
| 1209 | dirname, dent->d_name); |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1210 | err = dsos__load_modules_sym_dir(path, filter); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1211 | if (err < 0) |
| 1212 | goto failure; |
| 1213 | } else { |
| 1214 | char *dot = strrchr(dent->d_name, '.'), |
| 1215 | dso_name[PATH_MAX]; |
| 1216 | struct map *map; |
| 1217 | struct rb_node *last; |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1218 | char *long_name; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1219 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1220 | if (dot == NULL || strcmp(dot, ".ko")) |
| 1221 | continue; |
| 1222 | snprintf(dso_name, sizeof(dso_name), "[%.*s]", |
| 1223 | (int)(dot - dent->d_name), dent->d_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1224 | |
Arnaldo Carvalho de Melo | a2a99e8 | 2009-10-05 14:26:18 -0300 | [diff] [blame] | 1225 | strxfrchar(dso_name, '-', '_'); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1226 | map = kernel_maps__find_by_dso_name(dso_name); |
| 1227 | if (map == NULL) |
| 1228 | continue; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1229 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1230 | snprintf(path, sizeof(path), "%s/%s", |
| 1231 | dirname, dent->d_name); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1232 | |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1233 | long_name = strdup(path); |
| 1234 | if (long_name == NULL) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1235 | goto failure; |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1236 | dso__set_long_name(map->dso, long_name); |
| 1237 | dso__set_basename(map->dso); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1238 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1239 | err = dso__load_module_sym(map->dso, map, filter); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1240 | if (err < 0) |
| 1241 | goto failure; |
| 1242 | last = rb_last(&map->dso->syms); |
| 1243 | if (last) { |
| 1244 | struct symbol *sym; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1245 | /* |
| 1246 | * We do this here as well, even having the |
| 1247 | * symbol size found in the symtab because |
| 1248 | * misannotated ASM symbols may have the size |
| 1249 | * set to zero. |
| 1250 | */ |
| 1251 | dso__fixup_sym_end(map->dso); |
| 1252 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1253 | sym = rb_entry(last, struct symbol, rb_node); |
| 1254 | map->end = map->start + sym->end; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1255 | } |
| 1256 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1257 | nr_symbols += err; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1258 | } |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1259 | |
| 1260 | return nr_symbols; |
| 1261 | failure: |
| 1262 | closedir(dir); |
| 1263 | return -1; |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1264 | } |
| 1265 | |
Arnaldo Carvalho de Melo | 6671cb1 | 2009-11-20 20:51:24 -0200 | [diff] [blame] | 1266 | int dsos__load_modules_sym(symbol_filter_t filter) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1267 | { |
| 1268 | struct utsname uts; |
| 1269 | char modules_path[PATH_MAX]; |
| 1270 | |
| 1271 | if (uname(&uts) < 0) |
| 1272 | return -1; |
| 1273 | |
| 1274 | snprintf(modules_path, sizeof(modules_path), "/lib/modules/%s/kernel", |
| 1275 | uts.release); |
| 1276 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1277 | return dsos__load_modules_sym_dir(modules_path, filter); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | /* |
| 1281 | * Constructor variant for modules (where we know from /proc/modules where |
| 1282 | * they are loaded) and for vmlinux, where only after we load all the |
| 1283 | * symbols we'll know where it starts and ends. |
| 1284 | */ |
| 1285 | static struct map *map__new2(u64 start, struct dso *dso) |
| 1286 | { |
| 1287 | struct map *self = malloc(sizeof(*self)); |
| 1288 | |
| 1289 | if (self != NULL) { |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1290 | /* |
Arnaldo Carvalho de Melo | afb7b4f | 2009-10-30 16:28:23 -0200 | [diff] [blame] | 1291 | * ->end will be filled after we load all the symbols |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1292 | */ |
Arnaldo Carvalho de Melo | afb7b4f | 2009-10-30 16:28:23 -0200 | [diff] [blame] | 1293 | map__init(self, start, 0, 0, dso); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1294 | } |
Arnaldo Carvalho de Melo | afb7b4f | 2009-10-30 16:28:23 -0200 | [diff] [blame] | 1295 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1296 | return self; |
| 1297 | } |
| 1298 | |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 1299 | int dsos__load_modules(void) |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1300 | { |
| 1301 | char *line = NULL; |
| 1302 | size_t n; |
| 1303 | FILE *file = fopen("/proc/modules", "r"); |
| 1304 | struct map *map; |
| 1305 | |
| 1306 | if (file == NULL) |
| 1307 | return -1; |
| 1308 | |
| 1309 | while (!feof(file)) { |
| 1310 | char name[PATH_MAX]; |
| 1311 | u64 start; |
| 1312 | struct dso *dso; |
| 1313 | char *sep; |
| 1314 | int line_len; |
| 1315 | |
| 1316 | line_len = getline(&line, &n, file); |
| 1317 | if (line_len < 0) |
| 1318 | break; |
| 1319 | |
| 1320 | if (!line) |
| 1321 | goto out_failure; |
| 1322 | |
| 1323 | line[--line_len] = '\0'; /* \n */ |
| 1324 | |
| 1325 | sep = strrchr(line, 'x'); |
| 1326 | if (sep == NULL) |
| 1327 | continue; |
| 1328 | |
| 1329 | hex2u64(sep + 1, &start); |
| 1330 | |
| 1331 | sep = strchr(line, ' '); |
| 1332 | if (sep == NULL) |
| 1333 | continue; |
| 1334 | |
| 1335 | *sep = '\0'; |
| 1336 | |
| 1337 | snprintf(name, sizeof(name), "[%s]", line); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1338 | dso = dso__new(name); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1339 | |
| 1340 | if (dso == NULL) |
| 1341 | goto out_delete_line; |
| 1342 | |
| 1343 | map = map__new2(start, dso); |
| 1344 | if (map == NULL) { |
| 1345 | dso__delete(dso); |
| 1346 | goto out_delete_line; |
| 1347 | } |
| 1348 | |
Arnaldo Carvalho de Melo | f1617b4 | 2009-11-18 20:20:52 -0200 | [diff] [blame] | 1349 | snprintf(name, sizeof(name), |
| 1350 | "/sys/module/%s/notes/.note.gnu.build-id", line); |
| 1351 | if (sysfs__read_build_id(name, dso->build_id, |
| 1352 | sizeof(dso->build_id)) == 0) |
| 1353 | dso->has_build_id = true; |
| 1354 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1355 | dso->origin = DSO__ORIG_KMODULE; |
| 1356 | kernel_maps__insert(map); |
| 1357 | dsos__add(dso); |
| 1358 | } |
| 1359 | |
| 1360 | free(line); |
| 1361 | fclose(file); |
| 1362 | |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 1363 | return 0; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1364 | |
| 1365 | out_delete_line: |
| 1366 | free(line); |
| 1367 | out_failure: |
| 1368 | return -1; |
| 1369 | } |
| 1370 | |
| 1371 | 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] | 1372 | const char *vmlinux, symbol_filter_t filter) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1373 | { |
| 1374 | int err, fd = open(vmlinux, O_RDONLY); |
| 1375 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 1376 | self->loaded = 1; |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1377 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1378 | if (fd < 0) |
| 1379 | return -1; |
| 1380 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1381 | err = dso__load_sym(self, map, self->long_name, fd, filter, 1, 0); |
Mike Galbraith | 6cfcc53 | 2009-07-02 08:08:36 +0200 | [diff] [blame] | 1382 | |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1383 | close(fd); |
| 1384 | |
| 1385 | return err; |
| 1386 | } |
| 1387 | |
Arnaldo Carvalho de Melo | 6671cb1 | 2009-11-20 20:51:24 -0200 | [diff] [blame] | 1388 | int dso__load_kernel_sym(struct dso *self, symbol_filter_t filter, |
| 1389 | int use_modules) |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1390 | { |
Arnaldo Carvalho de Melo | 6671cb1 | 2009-11-20 20:51:24 -0200 | [diff] [blame] | 1391 | int err; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1392 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1393 | kernel_map = map__new2(0, self); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1394 | if (kernel_map == NULL) |
Arnaldo Carvalho de Melo | 6671cb1 | 2009-11-20 20:51:24 -0200 | [diff] [blame] | 1395 | return -1; |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1396 | |
Arnaldo Carvalho de Melo | ed52ce2 | 2009-10-19 17:17:57 -0200 | [diff] [blame] | 1397 | kernel_map->map_ip = kernel_map->unmap_ip = identity__map_ip; |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1398 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1399 | err = dso__load_vmlinux(self, kernel_map, self->name, filter); |
Mike Galbraith | 9974f49 | 2009-07-02 08:05:58 +0200 | [diff] [blame] | 1400 | if (err <= 0) |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1401 | err = kernel_maps__load_kallsyms(filter, use_modules); |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1402 | |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1403 | if (err > 0) { |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1404 | struct rb_node *node = rb_first(&self->syms); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1405 | struct symbol *sym = rb_entry(node, struct symbol, rb_node); |
| 1406 | |
| 1407 | kernel_map->start = sym->start; |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1408 | node = rb_last(&self->syms); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1409 | sym = rb_entry(node, struct symbol, rb_node); |
| 1410 | kernel_map->end = sym->end; |
| 1411 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1412 | self->origin = DSO__ORIG_KERNEL; |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1413 | kernel_maps__insert(kernel_map); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1414 | /* |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1415 | * Now that we have all sorted out, just set the ->end of all |
| 1416 | * maps: |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1417 | */ |
Arnaldo Carvalho de Melo | 2e538c4 | 2009-10-07 13:48:56 -0300 | [diff] [blame] | 1418 | kernel_maps__fixup_end(); |
Arnaldo Carvalho de Melo | af427bf | 2009-10-05 14:26:17 -0300 | [diff] [blame] | 1419 | |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 1420 | if (verbose) |
| 1421 | kernel_maps__fprintf(stderr); |
Arnaldo Carvalho de Melo | 439d473 | 2009-10-02 03:29:58 -0300 | [diff] [blame] | 1422 | } |
Arnaldo Carvalho de Melo | 94cb9e3 | 2009-08-06 14:43:17 -0300 | [diff] [blame] | 1423 | |
Arnaldo Carvalho de Melo | a827c87 | 2009-05-28 14:55:19 -0300 | [diff] [blame] | 1424 | return err; |
| 1425 | } |
| 1426 | |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1427 | LIST_HEAD(dsos); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1428 | struct dso *vdso; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1429 | |
Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 1430 | const char *vmlinux_name = "vmlinux"; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1431 | |
| 1432 | static void dsos__add(struct dso *dso) |
| 1433 | { |
| 1434 | list_add_tail(&dso->node, &dsos); |
| 1435 | } |
| 1436 | |
| 1437 | static struct dso *dsos__find(const char *name) |
| 1438 | { |
| 1439 | struct dso *pos; |
| 1440 | |
| 1441 | list_for_each_entry(pos, &dsos, node) |
| 1442 | if (strcmp(pos->name, name) == 0) |
| 1443 | return pos; |
| 1444 | return NULL; |
| 1445 | } |
| 1446 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1447 | struct dso *dsos__findnew(const char *name) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1448 | { |
| 1449 | struct dso *dso = dsos__find(name); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1450 | |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 1451 | if (!dso) { |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1452 | dso = dso__new(name); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1453 | if (dso != NULL) { |
Arnaldo Carvalho de Melo | e420499 | 2009-10-20 14:25:40 -0200 | [diff] [blame] | 1454 | dsos__add(dso); |
Arnaldo Carvalho de Melo | cfc10d3 | 2009-11-17 15:40:53 -0200 | [diff] [blame] | 1455 | dso__set_basename(dso); |
| 1456 | } |
Arnaldo Carvalho de Melo | 66bd842 | 2009-10-28 21:51:21 -0200 | [diff] [blame] | 1457 | } |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1458 | |
| 1459 | return dso; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | void dsos__fprintf(FILE *fp) |
| 1463 | { |
| 1464 | struct dso *pos; |
| 1465 | |
| 1466 | list_for_each_entry(pos, &dsos, node) |
| 1467 | dso__fprintf(pos, fp); |
| 1468 | } |
| 1469 | |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 1470 | size_t dsos__fprintf_buildid(FILE *fp) |
| 1471 | { |
| 1472 | struct dso *pos; |
| 1473 | size_t ret = 0; |
| 1474 | |
| 1475 | list_for_each_entry(pos, &dsos, node) { |
| 1476 | ret += dso__fprintf_buildid(pos, fp); |
Arnaldo Carvalho de Melo | 1124ba7 | 2009-11-16 21:45:25 -0200 | [diff] [blame] | 1477 | ret += fprintf(fp, " %s\n", pos->long_name); |
Arnaldo Carvalho de Melo | 9e03eb2 | 2009-11-16 16:32:44 -0200 | [diff] [blame] | 1478 | } |
| 1479 | return ret; |
| 1480 | } |
| 1481 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1482 | struct dso *dsos__load_kernel(void) |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1483 | { |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1484 | struct dso *kernel = dso__new(vmlinux_name); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1485 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1486 | if (kernel == NULL) |
| 1487 | return NULL; |
| 1488 | |
| 1489 | kernel->short_name = "[kernel]"; |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1490 | vdso = dso__new("[vdso]"); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1491 | if (!vdso) |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1492 | return NULL; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1493 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1494 | if (sysfs__read_build_id("/sys/kernel/notes", kernel->build_id, |
| 1495 | sizeof(kernel->build_id)) == 0) |
| 1496 | kernel->has_build_id = true; |
| 1497 | |
| 1498 | dsos__add(kernel); |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1499 | dsos__add(vdso); |
| 1500 | |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1501 | return kernel; |
| 1502 | } |
| 1503 | |
Arnaldo Carvalho de Melo | 6671cb1 | 2009-11-20 20:51:24 -0200 | [diff] [blame] | 1504 | int load_kernel(symbol_filter_t filter, bool use_modules) |
Arnaldo Carvalho de Melo | 2446042 | 2009-11-18 20:20:53 -0200 | [diff] [blame] | 1505 | { |
| 1506 | struct dso *kernel = dsos__load_kernel(); |
| 1507 | |
| 1508 | if (kernel == NULL) |
| 1509 | return -1; |
| 1510 | |
Arnaldo Carvalho de Melo | 6671cb1 | 2009-11-20 20:51:24 -0200 | [diff] [blame] | 1511 | if (use_modules) { |
| 1512 | if (dsos__load_modules() < 0) |
| 1513 | pr_warning("Failed to load list of modules in use, " |
| 1514 | "continuing...\n"); |
| 1515 | else if (dsos__load_modules_sym(filter) < 0) |
| 1516 | pr_warning("Failed to read module symbols, " |
| 1517 | "continuing...\n"); |
| 1518 | } |
| 1519 | |
| 1520 | if (dso__load_kernel_sym(kernel, filter, use_modules) < 0) |
| 1521 | pr_warning("Failed to read kernel symbols, continuing...\n"); |
| 1522 | |
| 1523 | return 0; |
Frederic Weisbecker | cd84c2a | 2009-08-12 10:03:49 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1526 | void symbol__init(unsigned int priv_size) |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1527 | { |
| 1528 | elf_version(EV_CURRENT); |
Arnaldo Carvalho de Melo | 00a192b | 2009-10-30 16:28:24 -0200 | [diff] [blame] | 1529 | symbol__priv_size = priv_size; |
Arnaldo Carvalho de Melo | a2928c4 | 2009-05-28 14:55:04 -0300 | [diff] [blame] | 1530 | } |