1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/kernel.h>
10 #include <sys/param.h>
22 #include "namespaces.h"
25 #include "sane_ctype.h"
29 #include <symbol/kallsyms.h>
30 #include <sys/utsname.h>
32 static int dso__load_kernel_sym(struct dso *dso, struct map *map);
33 static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map);
34 static bool symbol__is_idle(const char *name);
36 int vmlinux_path__nr_entries;
39 struct symbol_conf symbol_conf = {
41 .try_vmlinux_path = true,
44 .demangle_kernel = false,
45 .cumulate_callchain = true,
46 .show_hist_headers = true,
51 static enum dso_binary_type binary_type_symtab[] = {
52 DSO_BINARY_TYPE__KALLSYMS,
53 DSO_BINARY_TYPE__GUEST_KALLSYMS,
54 DSO_BINARY_TYPE__JAVA_JIT,
55 DSO_BINARY_TYPE__DEBUGLINK,
56 DSO_BINARY_TYPE__BUILD_ID_CACHE,
57 DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO,
58 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
59 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
60 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
61 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
62 DSO_BINARY_TYPE__GUEST_KMODULE,
63 DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
64 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
65 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
66 DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
67 DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO,
68 DSO_BINARY_TYPE__NOT_FOUND,
71 #define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
73 bool symbol_type__is_a(char symbol_type, enum map_type map_type)
75 symbol_type = toupper(symbol_type);
79 return symbol_type == 'T' || symbol_type == 'W';
81 return symbol_type == 'D';
87 static int prefix_underscores_count(const char *str)
89 const char *tail = str;
97 void __weak arch__symbols__fixup_end(struct symbol *p, struct symbol *c)
102 const char * __weak arch__normalize_symbol_name(const char *name)
107 int __weak arch__compare_symbol_names(const char *namea, const char *nameb)
109 return strcmp(namea, nameb);
112 int __weak arch__compare_symbol_names_n(const char *namea, const char *nameb,
115 return strncmp(namea, nameb, n);
118 int __weak arch__choose_best_symbol(struct symbol *syma,
119 struct symbol *symb __maybe_unused)
121 /* Avoid "SyS" kernel syscall aliases */
122 if (strlen(syma->name) >= 3 && !strncmp(syma->name, "SyS", 3))
124 if (strlen(syma->name) >= 10 && !strncmp(syma->name, "compat_SyS", 10))
130 static int choose_best_symbol(struct symbol *syma, struct symbol *symb)
136 /* Prefer a symbol with non zero length */
137 a = syma->end - syma->start;
138 b = symb->end - symb->start;
139 if ((b == 0) && (a > 0))
141 else if ((a == 0) && (b > 0))
144 /* Prefer a non weak symbol over a weak one */
145 a = syma->binding == STB_WEAK;
146 b = symb->binding == STB_WEAK;
152 /* Prefer a global symbol over a non global one */
153 a = syma->binding == STB_GLOBAL;
154 b = symb->binding == STB_GLOBAL;
160 /* Prefer a symbol with less underscores */
161 a = prefix_underscores_count(syma->name);
162 b = prefix_underscores_count(symb->name);
168 /* Choose the symbol with the longest name */
169 na = strlen(syma->name);
170 nb = strlen(symb->name);
176 return arch__choose_best_symbol(syma, symb);
179 void symbols__fixup_duplicate(struct rb_root *symbols)
182 struct symbol *curr, *next;
184 if (symbol_conf.allow_aliases)
187 nd = rb_first(symbols);
190 curr = rb_entry(nd, struct symbol, rb_node);
192 nd = rb_next(&curr->rb_node);
193 next = rb_entry(nd, struct symbol, rb_node);
198 if (curr->start != next->start)
201 if (choose_best_symbol(curr, next) == SYMBOL_A) {
202 rb_erase(&next->rb_node, symbols);
203 symbol__delete(next);
206 nd = rb_next(&curr->rb_node);
207 rb_erase(&curr->rb_node, symbols);
208 symbol__delete(curr);
213 void symbols__fixup_end(struct rb_root *symbols)
215 struct rb_node *nd, *prevnd = rb_first(symbols);
216 struct symbol *curr, *prev;
221 curr = rb_entry(prevnd, struct symbol, rb_node);
223 for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
225 curr = rb_entry(nd, struct symbol, rb_node);
227 if (prev->end == prev->start || prev->end != curr->start)
228 arch__symbols__fixup_end(prev, curr);
232 if (curr->end == curr->start)
233 curr->end = roundup(curr->start, 4096) + 4096;
236 void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
238 struct maps *maps = &mg->maps[type];
239 struct map *next, *curr;
241 pthread_rwlock_wrlock(&maps->lock);
243 curr = maps__first(maps);
247 for (next = map__next(curr); next; next = map__next(curr)) {
249 curr->end = next->start;
254 * We still haven't the actual symbols, so guess the
255 * last map final address.
261 pthread_rwlock_unlock(&maps->lock);
264 struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
266 size_t namelen = strlen(name) + 1;
267 struct symbol *sym = calloc(1, (symbol_conf.priv_size +
268 sizeof(*sym) + namelen));
272 if (symbol_conf.priv_size) {
273 if (symbol_conf.init_annotation) {
274 struct annotation *notes = (void *)sym;
275 pthread_mutex_init(¬es->lock, NULL);
277 sym = ((void *)sym) + symbol_conf.priv_size;
281 sym->end = len ? start + len : start;
282 sym->binding = binding;
283 sym->namelen = namelen - 1;
285 pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
286 __func__, name, start, sym->end);
287 memcpy(sym->name, name, namelen);
292 void symbol__delete(struct symbol *sym)
294 free(((void *)sym) - symbol_conf.priv_size);
297 void symbols__delete(struct rb_root *symbols)
300 struct rb_node *next = rb_first(symbols);
303 pos = rb_entry(next, struct symbol, rb_node);
304 next = rb_next(&pos->rb_node);
305 rb_erase(&pos->rb_node, symbols);
310 void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel)
312 struct rb_node **p = &symbols->rb_node;
313 struct rb_node *parent = NULL;
314 const u64 ip = sym->start;
318 const char *name = sym->name;
320 * ppc64 uses function descriptors and appends a '.' to the
321 * start of every instruction address. Remove it.
325 sym->idle = symbol__is_idle(name);
330 s = rb_entry(parent, struct symbol, rb_node);
336 rb_link_node(&sym->rb_node, parent, p);
337 rb_insert_color(&sym->rb_node, symbols);
340 void symbols__insert(struct rb_root *symbols, struct symbol *sym)
342 __symbols__insert(symbols, sym, false);
345 static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
352 n = symbols->rb_node;
355 struct symbol *s = rb_entry(n, struct symbol, rb_node);
359 else if (ip > s->end || (ip == s->end && ip != s->start))
368 static struct symbol *symbols__first(struct rb_root *symbols)
370 struct rb_node *n = rb_first(symbols);
373 return rb_entry(n, struct symbol, rb_node);
378 static struct symbol *symbols__last(struct rb_root *symbols)
380 struct rb_node *n = rb_last(symbols);
383 return rb_entry(n, struct symbol, rb_node);
388 static struct symbol *symbols__next(struct symbol *sym)
390 struct rb_node *n = rb_next(&sym->rb_node);
393 return rb_entry(n, struct symbol, rb_node);
398 static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym)
400 struct rb_node **p = &symbols->rb_node;
401 struct rb_node *parent = NULL;
402 struct symbol_name_rb_node *symn, *s;
404 symn = container_of(sym, struct symbol_name_rb_node, sym);
408 s = rb_entry(parent, struct symbol_name_rb_node, rb_node);
409 if (strcmp(sym->name, s->sym.name) < 0)
414 rb_link_node(&symn->rb_node, parent, p);
415 rb_insert_color(&symn->rb_node, symbols);
418 static void symbols__sort_by_name(struct rb_root *symbols,
419 struct rb_root *source)
423 for (nd = rb_first(source); nd; nd = rb_next(nd)) {
424 struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
425 symbols__insert_by_name(symbols, pos);
429 int symbol__match_symbol_name(const char *name, const char *str,
430 enum symbol_tag_include includes)
432 const char *versioning;
434 if (includes == SYMBOL_TAG_INCLUDE__DEFAULT_ONLY &&
435 (versioning = strstr(name, "@@"))) {
436 int len = strlen(str);
438 if (len < versioning - name)
439 len = versioning - name;
441 return arch__compare_symbol_names_n(name, str, len);
443 return arch__compare_symbol_names(name, str);
446 static struct symbol *symbols__find_by_name(struct rb_root *symbols,
448 enum symbol_tag_include includes)
451 struct symbol_name_rb_node *s = NULL;
456 n = symbols->rb_node;
461 s = rb_entry(n, struct symbol_name_rb_node, rb_node);
462 cmp = symbol__match_symbol_name(s->sym.name, name, includes);
475 if (includes != SYMBOL_TAG_INCLUDE__DEFAULT_ONLY)
476 /* return first symbol that has same name (if any) */
477 for (n = rb_prev(n); n; n = rb_prev(n)) {
478 struct symbol_name_rb_node *tmp;
480 tmp = rb_entry(n, struct symbol_name_rb_node, rb_node);
481 if (arch__compare_symbol_names(tmp->sym.name, s->sym.name))
490 void dso__reset_find_symbol_cache(struct dso *dso)
494 for (type = MAP__FUNCTION; type <= MAP__VARIABLE; ++type) {
495 dso->last_find_result[type].addr = 0;
496 dso->last_find_result[type].symbol = NULL;
500 void dso__insert_symbol(struct dso *dso, enum map_type type, struct symbol *sym)
502 __symbols__insert(&dso->symbols[type], sym, dso->kernel);
504 /* update the symbol cache if necessary */
505 if (dso->last_find_result[type].addr >= sym->start &&
506 (dso->last_find_result[type].addr < sym->end ||
507 sym->start == sym->end)) {
508 dso->last_find_result[type].symbol = sym;
512 struct symbol *dso__find_symbol(struct dso *dso,
513 enum map_type type, u64 addr)
515 if (dso->last_find_result[type].addr != addr || dso->last_find_result[type].symbol == NULL) {
516 dso->last_find_result[type].addr = addr;
517 dso->last_find_result[type].symbol = symbols__find(&dso->symbols[type], addr);
520 return dso->last_find_result[type].symbol;
523 struct symbol *dso__first_symbol(struct dso *dso, enum map_type type)
525 return symbols__first(&dso->symbols[type]);
528 struct symbol *dso__last_symbol(struct dso *dso, enum map_type type)
530 return symbols__last(&dso->symbols[type]);
533 struct symbol *dso__next_symbol(struct symbol *sym)
535 return symbols__next(sym);
538 struct symbol *symbol__next_by_name(struct symbol *sym)
540 struct symbol_name_rb_node *s = container_of(sym, struct symbol_name_rb_node, sym);
541 struct rb_node *n = rb_next(&s->rb_node);
543 return n ? &rb_entry(n, struct symbol_name_rb_node, rb_node)->sym : NULL;
547 * Teturns first symbol that matched with @name.
549 struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
552 struct symbol *s = symbols__find_by_name(&dso->symbol_names[type], name,
553 SYMBOL_TAG_INCLUDE__NONE);
555 s = symbols__find_by_name(&dso->symbol_names[type], name,
556 SYMBOL_TAG_INCLUDE__DEFAULT_ONLY);
560 void dso__sort_by_name(struct dso *dso, enum map_type type)
562 dso__set_sorted_by_name(dso, type);
563 return symbols__sort_by_name(&dso->symbol_names[type],
564 &dso->symbols[type]);
567 int modules__parse(const char *filename, void *arg,
568 int (*process_module)(void *arg, const char *name,
569 u64 start, u64 size))
576 file = fopen(filename, "r");
586 line_len = getline(&line, &n, file);
599 line[--line_len] = '\0'; /* \n */
601 sep = strrchr(line, 'x');
605 hex2u64(sep + 1, &start);
607 sep = strchr(line, ' ');
613 scnprintf(name, sizeof(name), "[%s]", line);
615 size = strtoul(sep + 1, &endptr, 0);
616 if (*endptr != ' ' && *endptr != '\t')
619 err = process_module(arg, name, start, size);
629 struct process_kallsyms_args {
635 * These are symbols in the kernel image, so make sure that
636 * sym is from a kernel DSO.
638 static bool symbol__is_idle(const char *name)
640 const char * const idle_symbols[] = {
649 "mwait_idle_with_hints",
651 "ppc64_runlatch_off",
652 "pseries_dedicated_idle_sleep",
657 for (i = 0; idle_symbols[i]; i++) {
658 if (!strcmp(idle_symbols[i], name))
665 static int map__process_kallsym_symbol(void *arg, const char *name,
666 char type, u64 start)
669 struct process_kallsyms_args *a = arg;
670 struct rb_root *root = &a->dso->symbols[a->map->type];
672 if (!symbol_type__is_a(type, a->map->type))
676 * module symbols are not sorted so we add all
677 * symbols, setting length to 0, and rely on
678 * symbols__fixup_end() to fix it up.
680 sym = symbol__new(start, 0, kallsyms2elf_binding(type), name);
684 * We will pass the symbols to the filter later, in
685 * map__split_kallsyms, when we have split the maps per module
687 __symbols__insert(root, sym, !strchr(name, '['));
693 * Loads the function entries in /proc/kallsyms into kernel_map->dso,
694 * so that we can in the next step set the symbol ->end address and then
695 * call kernel_maps__split_kallsyms.
697 static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
700 struct process_kallsyms_args args = { .map = map, .dso = dso, };
701 return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
704 static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
706 struct map_groups *kmaps = map__kmaps(map);
707 struct map *curr_map;
710 struct rb_root old_root = dso->symbols[map->type];
711 struct rb_root *root = &dso->symbols[map->type];
712 struct rb_node *next = rb_first(root);
722 pos = rb_entry(next, struct symbol, rb_node);
723 next = rb_next(&pos->rb_node);
725 rb_erase_init(&pos->rb_node, &old_root);
727 module = strchr(pos->name, '\t');
731 curr_map = map_groups__find(kmaps, map->type, pos->start);
738 pos->start -= curr_map->start - curr_map->pgoff;
740 pos->end -= curr_map->start - curr_map->pgoff;
741 symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
745 /* Symbols have been adjusted */
746 dso->adjust_symbols = 1;
752 * Split the symbols into maps, making sure there are no overlaps, i.e. the
753 * kernel range is broken in several maps, named [kernel].N, as we don't have
754 * the original ELF section names vmlinux have.
756 static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
758 struct map_groups *kmaps = map__kmaps(map);
759 struct machine *machine;
760 struct map *curr_map = map;
762 int count = 0, moved = 0;
763 struct rb_root *root = &dso->symbols[map->type];
764 struct rb_node *next = rb_first(root);
765 int kernel_range = 0;
770 machine = kmaps->machine;
775 pos = rb_entry(next, struct symbol, rb_node);
776 next = rb_next(&pos->rb_node);
778 module = strchr(pos->name, '\t');
780 if (!symbol_conf.use_modules)
785 if (strcmp(curr_map->dso->short_name, module)) {
786 if (curr_map != map &&
787 dso->kernel == DSO_TYPE_GUEST_KERNEL &&
788 machine__is_default_guest(machine)) {
790 * We assume all symbols of a module are
791 * continuous in * kallsyms, so curr_map
792 * points to a module and all its
793 * symbols are in its kmap. Mark it as
796 dso__set_loaded(curr_map->dso,
800 curr_map = map_groups__find_by_name(kmaps,
802 if (curr_map == NULL) {
803 pr_debug("%s/proc/{kallsyms,modules} "
804 "inconsistency while looking "
805 "for \"%s\" module!\n",
806 machine->root_dir, module);
811 if (curr_map->dso->loaded &&
812 !machine__is_default_guest(machine))
816 * So that we look just like we get from .ko files,
817 * i.e. not prelinked, relative to map->start.
819 pos->start = curr_map->map_ip(curr_map, pos->start);
820 pos->end = curr_map->map_ip(curr_map, pos->end);
821 } else if (curr_map != map) {
822 char dso_name[PATH_MAX];
826 /* Kernel was relocated at boot time */
836 if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
837 snprintf(dso_name, sizeof(dso_name),
841 snprintf(dso_name, sizeof(dso_name),
845 ndso = dso__new(dso_name);
849 ndso->kernel = dso->kernel;
851 curr_map = map__new2(pos->start, ndso, map->type);
852 if (curr_map == NULL) {
857 curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
858 map_groups__insert(kmaps, curr_map);
861 /* Kernel was relocated at boot time */
866 if (curr_map != map) {
867 rb_erase(&pos->rb_node, root);
868 symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
875 rb_erase(&pos->rb_node, root);
879 if (curr_map != map &&
880 dso->kernel == DSO_TYPE_GUEST_KERNEL &&
881 machine__is_default_guest(kmaps->machine)) {
882 dso__set_loaded(curr_map->dso, curr_map->type);
885 return count + moved;
888 bool symbol__restricted_filename(const char *filename,
889 const char *restricted_filename)
891 bool restricted = false;
893 if (symbol_conf.kptr_restrict) {
894 char *r = realpath(filename, NULL);
897 restricted = strcmp(r, restricted_filename) == 0;
907 struct rb_node rb_node;
912 static void add_module(struct module_info *mi, struct rb_root *modules)
914 struct rb_node **p = &modules->rb_node;
915 struct rb_node *parent = NULL;
916 struct module_info *m;
920 m = rb_entry(parent, struct module_info, rb_node);
921 if (strcmp(mi->name, m->name) < 0)
926 rb_link_node(&mi->rb_node, parent, p);
927 rb_insert_color(&mi->rb_node, modules);
930 static void delete_modules(struct rb_root *modules)
932 struct module_info *mi;
933 struct rb_node *next = rb_first(modules);
936 mi = rb_entry(next, struct module_info, rb_node);
937 next = rb_next(&mi->rb_node);
938 rb_erase(&mi->rb_node, modules);
944 static struct module_info *find_module(const char *name,
945 struct rb_root *modules)
947 struct rb_node *n = modules->rb_node;
950 struct module_info *m;
953 m = rb_entry(n, struct module_info, rb_node);
954 cmp = strcmp(name, m->name);
966 static int __read_proc_modules(void *arg, const char *name, u64 start,
967 u64 size __maybe_unused)
969 struct rb_root *modules = arg;
970 struct module_info *mi;
972 mi = zalloc(sizeof(struct module_info));
976 mi->name = strdup(name);
984 add_module(mi, modules);
989 static int read_proc_modules(const char *filename, struct rb_root *modules)
991 if (symbol__restricted_filename(filename, "/proc/modules"))
994 if (modules__parse(filename, modules, __read_proc_modules)) {
995 delete_modules(modules);
1002 int compare_proc_modules(const char *from, const char *to)
1004 struct rb_root from_modules = RB_ROOT;
1005 struct rb_root to_modules = RB_ROOT;
1006 struct rb_node *from_node, *to_node;
1007 struct module_info *from_m, *to_m;
1010 if (read_proc_modules(from, &from_modules))
1013 if (read_proc_modules(to, &to_modules))
1014 goto out_delete_from;
1016 from_node = rb_first(&from_modules);
1017 to_node = rb_first(&to_modules);
1022 from_m = rb_entry(from_node, struct module_info, rb_node);
1023 to_m = rb_entry(to_node, struct module_info, rb_node);
1025 if (from_m->start != to_m->start ||
1026 strcmp(from_m->name, to_m->name))
1029 from_node = rb_next(from_node);
1030 to_node = rb_next(to_node);
1033 if (!from_node && !to_node)
1036 delete_modules(&to_modules);
1038 delete_modules(&from_modules);
1043 static int do_validate_kcore_modules(const char *filename, struct map *map,
1044 struct map_groups *kmaps)
1046 struct rb_root modules = RB_ROOT;
1047 struct map *old_map;
1050 err = read_proc_modules(filename, &modules);
1054 old_map = map_groups__first(kmaps, map->type);
1056 struct map *next = map_groups__next(old_map);
1057 struct module_info *mi;
1059 if (old_map == map || old_map->start == map->start) {
1060 /* The kernel map */
1065 /* Module must be in memory at the same address */
1066 mi = find_module(old_map->dso->short_name, &modules);
1067 if (!mi || mi->start != old_map->start) {
1075 delete_modules(&modules);
1080 * If kallsyms is referenced by name then we look for filename in the same
1083 static bool filename_from_kallsyms_filename(char *filename,
1084 const char *base_name,
1085 const char *kallsyms_filename)
1089 strcpy(filename, kallsyms_filename);
1090 name = strrchr(filename, '/');
1096 if (!strcmp(name, "kallsyms")) {
1097 strcpy(name, base_name);
1104 static int validate_kcore_modules(const char *kallsyms_filename,
1107 struct map_groups *kmaps = map__kmaps(map);
1108 char modules_filename[PATH_MAX];
1113 if (!filename_from_kallsyms_filename(modules_filename, "modules",
1117 if (do_validate_kcore_modules(modules_filename, map, kmaps))
1123 static int validate_kcore_addresses(const char *kallsyms_filename,
1126 struct kmap *kmap = map__kmap(map);
1131 if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
1134 if (kallsyms__get_function_start(kallsyms_filename,
1135 kmap->ref_reloc_sym->name, &start))
1137 if (start != kmap->ref_reloc_sym->addr)
1141 return validate_kcore_modules(kallsyms_filename, map);
1144 struct kcore_mapfn_data {
1147 struct list_head maps;
1150 static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
1152 struct kcore_mapfn_data *md = data;
1155 map = map__new2(start, md->dso, md->type);
1159 map->end = map->start + len;
1162 list_add(&map->node, &md->maps);
1167 static int dso__load_kcore(struct dso *dso, struct map *map,
1168 const char *kallsyms_filename)
1170 struct map_groups *kmaps = map__kmaps(map);
1171 struct machine *machine;
1172 struct kcore_mapfn_data md;
1173 struct map *old_map, *new_map, *replacement_map = NULL;
1176 char kcore_filename[PATH_MAX];
1182 machine = kmaps->machine;
1184 /* This function requires that the map is the kernel map */
1185 if (map != machine->vmlinux_maps[map->type])
1188 if (!filename_from_kallsyms_filename(kcore_filename, "kcore",
1192 /* Modules and kernel must be present at their original addresses */
1193 if (validate_kcore_addresses(kallsyms_filename, map))
1197 md.type = map->type;
1198 INIT_LIST_HEAD(&md.maps);
1200 fd = open(kcore_filename, O_RDONLY);
1202 pr_debug("Failed to open %s. Note /proc/kcore requires CAP_SYS_RAWIO capability to access.\n",
1207 /* Read new maps into temporary lists */
1208 err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,
1212 dso->is_64_bit = is_64_bit;
1214 if (list_empty(&md.maps)) {
1219 /* Remove old maps */
1220 old_map = map_groups__first(kmaps, map->type);
1222 struct map *next = map_groups__next(old_map);
1225 map_groups__remove(kmaps, old_map);
1229 /* Find the kernel map using the first symbol */
1230 sym = dso__first_symbol(dso, map->type);
1231 list_for_each_entry(new_map, &md.maps, node) {
1232 if (sym && sym->start >= new_map->start &&
1233 sym->start < new_map->end) {
1234 replacement_map = new_map;
1239 if (!replacement_map)
1240 replacement_map = list_entry(md.maps.next, struct map, node);
1243 while (!list_empty(&md.maps)) {
1244 new_map = list_entry(md.maps.next, struct map, node);
1245 list_del_init(&new_map->node);
1246 if (new_map == replacement_map) {
1247 map->start = new_map->start;
1248 map->end = new_map->end;
1249 map->pgoff = new_map->pgoff;
1250 map->map_ip = new_map->map_ip;
1251 map->unmap_ip = new_map->unmap_ip;
1252 /* Ensure maps are correctly ordered */
1254 map_groups__remove(kmaps, map);
1255 map_groups__insert(kmaps, map);
1258 map_groups__insert(kmaps, new_map);
1265 * Set the data type and long name so that kcore can be read via
1266 * dso__data_read_addr().
1268 if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
1269 dso->binary_type = DSO_BINARY_TYPE__GUEST_KCORE;
1271 dso->binary_type = DSO_BINARY_TYPE__KCORE;
1272 dso__set_long_name(dso, strdup(kcore_filename), true);
1276 if (map->type == MAP__FUNCTION)
1277 pr_debug("Using %s for kernel object code\n", kcore_filename);
1279 pr_debug("Using %s for kernel data\n", kcore_filename);
1284 while (!list_empty(&md.maps)) {
1285 map = list_entry(md.maps.next, struct map, node);
1286 list_del_init(&map->node);
1294 * If the kernel is relocated at boot time, kallsyms won't match. Compute the
1295 * delta based on the relocation reference symbol.
1297 static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
1299 struct kmap *kmap = map__kmap(map);
1305 if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->name)
1308 if (kallsyms__get_function_start(filename, kmap->ref_reloc_sym->name, &addr))
1311 *delta = addr - kmap->ref_reloc_sym->addr;
1315 int __dso__load_kallsyms(struct dso *dso, const char *filename,
1316 struct map *map, bool no_kcore)
1320 if (symbol__restricted_filename(filename, "/proc/kallsyms"))
1323 if (dso__load_all_kallsyms(dso, filename, map) < 0)
1326 if (kallsyms__delta(map, filename, &delta))
1329 symbols__fixup_end(&dso->symbols[map->type]);
1330 symbols__fixup_duplicate(&dso->symbols[map->type]);
1332 if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
1333 dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
1335 dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
1337 if (!no_kcore && !dso__load_kcore(dso, map, filename))
1338 return dso__split_kallsyms_for_kcore(dso, map);
1340 return dso__split_kallsyms(dso, map, delta);
1343 int dso__load_kallsyms(struct dso *dso, const char *filename,
1346 return __dso__load_kallsyms(dso, filename, map, false);
1349 static int dso__load_perf_map(const char *map_path, struct dso *dso,
1357 file = fopen(map_path, "r");
1361 while (!feof(file)) {
1366 line_len = getline(&line, &n, file);
1373 line[--line_len] = '\0'; /* \n */
1375 len = hex2u64(line, &start);
1378 if (len + 2 >= line_len)
1381 len += hex2u64(line + len, &size);
1384 if (len + 2 >= line_len)
1387 sym = symbol__new(start, size, STB_GLOBAL, line + len);
1390 goto out_delete_line;
1392 symbols__insert(&dso->symbols[map->type], sym);
1407 static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
1408 enum dso_binary_type type)
1411 case DSO_BINARY_TYPE__JAVA_JIT:
1412 case DSO_BINARY_TYPE__DEBUGLINK:
1413 case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
1414 case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
1415 case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
1416 case DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO:
1417 case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
1418 case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
1419 return !kmod && dso->kernel == DSO_TYPE_USER;
1421 case DSO_BINARY_TYPE__KALLSYMS:
1422 case DSO_BINARY_TYPE__VMLINUX:
1423 case DSO_BINARY_TYPE__KCORE:
1424 return dso->kernel == DSO_TYPE_KERNEL;
1426 case DSO_BINARY_TYPE__GUEST_KALLSYMS:
1427 case DSO_BINARY_TYPE__GUEST_VMLINUX:
1428 case DSO_BINARY_TYPE__GUEST_KCORE:
1429 return dso->kernel == DSO_TYPE_GUEST_KERNEL;
1431 case DSO_BINARY_TYPE__GUEST_KMODULE:
1432 case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
1433 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
1434 case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
1436 * kernel modules know their symtab type - it's set when
1437 * creating a module dso in machine__findnew_module_map().
1439 return kmod && dso->symtab_type == type;
1441 case DSO_BINARY_TYPE__BUILD_ID_CACHE:
1442 case DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO:
1445 case DSO_BINARY_TYPE__NOT_FOUND:
1451 /* Checks for the existence of the perf-<pid>.map file in two different
1452 * locations. First, if the process is a separate mount namespace, check in
1453 * that namespace using the pid of the innermost pid namespace. If's not in a
1454 * namespace, or the file can't be found there, try in the mount namespace of
1455 * the tracing process using our view of its pid.
1457 static int dso__find_perf_map(char *filebuf, size_t bufsz,
1458 struct nsinfo **nsip)
1460 struct nscookie nsc;
1462 struct nsinfo *nnsi;
1467 if (nsi->need_setns) {
1468 snprintf(filebuf, bufsz, "/tmp/perf-%d.map", nsi->nstgid);
1469 nsinfo__mountns_enter(nsi, &nsc);
1470 rc = access(filebuf, R_OK);
1471 nsinfo__mountns_exit(&nsc);
1476 nnsi = nsinfo__copy(nsi);
1480 nnsi->need_setns = false;
1481 snprintf(filebuf, bufsz, "/tmp/perf-%d.map", nnsi->tgid);
1489 int dso__load(struct dso *dso, struct map *map)
1494 struct machine *machine;
1495 char *root_dir = (char *) "";
1497 struct symsrc ss_[2];
1498 struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
1501 unsigned char build_id[BUILD_ID_SIZE];
1502 struct nscookie nsc;
1503 char newmapname[PATH_MAX];
1504 const char *map_path = dso->long_name;
1506 perfmap = strncmp(dso->name, "/tmp/perf-", 10) == 0;
1508 if (dso->nsinfo && (dso__find_perf_map(newmapname,
1509 sizeof(newmapname), &dso->nsinfo) == 0)) {
1510 map_path = newmapname;
1514 nsinfo__mountns_enter(dso->nsinfo, &nsc);
1515 pthread_mutex_lock(&dso->lock);
1517 /* check again under the dso->lock */
1518 if (dso__loaded(dso, map->type)) {
1523 if (map->groups && map->groups->machine)
1524 machine = map->groups->machine;
1529 if (dso->kernel == DSO_TYPE_KERNEL)
1530 ret = dso__load_kernel_sym(dso, map);
1531 else if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
1532 ret = dso__load_guest_kernel_sym(dso, map);
1534 if (machine__is(machine, "x86_64"))
1535 machine__map_x86_64_entry_trampolines(machine, dso);
1539 dso->adjust_symbols = 0;
1544 if (lstat(map_path, &st) < 0)
1547 if (!symbol_conf.force && st.st_uid && (st.st_uid != geteuid())) {
1548 pr_warning("File %s not owned by current user or root, "
1549 "ignoring it (use -f to override).\n", map_path);
1553 ret = dso__load_perf_map(map_path, dso, map);
1554 dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
1555 DSO_BINARY_TYPE__NOT_FOUND;
1560 root_dir = machine->root_dir;
1562 name = malloc(PATH_MAX);
1566 kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
1567 dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
1568 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
1569 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
1573 * Read the build id if possible. This is required for
1574 * DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work
1576 if (!dso->has_build_id &&
1577 is_regular_file(dso->long_name)) {
1578 __symbol__join_symfs(name, PATH_MAX, dso->long_name);
1579 if (filename__read_build_id(name, build_id, BUILD_ID_SIZE) > 0)
1580 dso__set_build_id(dso, build_id);
1584 * Iterate over candidate debug images.
1585 * Keep track of "interesting" ones (those which have a symtab, dynsym,
1586 * and/or opd section) for processing.
1588 for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
1589 struct symsrc *ss = &ss_[ss_pos];
1590 bool next_slot = false;
1595 enum dso_binary_type symtab_type = binary_type_symtab[i];
1597 nsexit = (symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE ||
1598 symtab_type == DSO_BINARY_TYPE__BUILD_ID_CACHE_DEBUGINFO);
1600 if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
1603 if (dso__read_binary_type_filename(dso, symtab_type,
1604 root_dir, name, PATH_MAX))
1608 nsinfo__mountns_exit(&nsc);
1610 is_reg = is_regular_file(name);
1611 sirc = symsrc__init(ss, dso, name, symtab_type);
1614 nsinfo__mountns_enter(dso->nsinfo, &nsc);
1616 if (!is_reg || sirc < 0) {
1618 symsrc__destroy(ss);
1622 if (!syms_ss && symsrc__has_symtab(ss)) {
1625 if (!dso->symsrc_filename)
1626 dso->symsrc_filename = strdup(name);
1629 if (!runtime_ss && symsrc__possibly_runtime(ss)) {
1637 if (syms_ss && runtime_ss)
1640 symsrc__destroy(ss);
1645 if (!runtime_ss && !syms_ss)
1648 if (runtime_ss && !syms_ss) {
1649 syms_ss = runtime_ss;
1652 /* We'll have to hope for the best */
1653 if (!runtime_ss && syms_ss)
1654 runtime_ss = syms_ss;
1657 ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
1664 nr_plt = dso__synthesize_plt_symbols(dso, runtime_ss, map);
1669 for (; ss_pos > 0; ss_pos--)
1670 symsrc__destroy(&ss_[ss_pos - 1]);
1673 if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
1676 dso__set_loaded(dso, map->type);
1677 pthread_mutex_unlock(&dso->lock);
1678 nsinfo__mountns_exit(&nsc);
1683 struct map *map_groups__find_by_name(struct map_groups *mg,
1684 enum map_type type, const char *name)
1686 struct maps *maps = &mg->maps[type];
1689 pthread_rwlock_rdlock(&maps->lock);
1691 for (map = maps__first(maps); map; map = map__next(map)) {
1692 if (map->dso && strcmp(map->dso->short_name, name) == 0)
1699 pthread_rwlock_unlock(&maps->lock);
1703 int dso__load_vmlinux(struct dso *dso, struct map *map,
1704 const char *vmlinux, bool vmlinux_allocated)
1708 char symfs_vmlinux[PATH_MAX];
1709 enum dso_binary_type symtab_type;
1711 if (vmlinux[0] == '/')
1712 snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux);
1714 symbol__join_symfs(symfs_vmlinux, vmlinux);
1716 if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
1717 symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
1719 symtab_type = DSO_BINARY_TYPE__VMLINUX;
1721 if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
1724 err = dso__load_sym(dso, map, &ss, &ss, 0);
1725 symsrc__destroy(&ss);
1728 if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
1729 dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
1731 dso->binary_type = DSO_BINARY_TYPE__VMLINUX;
1732 dso__set_long_name(dso, vmlinux, vmlinux_allocated);
1733 dso__set_loaded(dso, map->type);
1734 pr_debug("Using %s for symbols\n", symfs_vmlinux);
1740 int dso__load_vmlinux_path(struct dso *dso, struct map *map)
1743 char *filename = NULL;
1745 pr_debug("Looking at the vmlinux_path (%d entries long)\n",
1746 vmlinux_path__nr_entries + 1);
1748 for (i = 0; i < vmlinux_path__nr_entries; ++i) {
1749 err = dso__load_vmlinux(dso, map, vmlinux_path[i], false);
1754 if (!symbol_conf.ignore_vmlinux_buildid)
1755 filename = dso__build_id_filename(dso, NULL, 0, false);
1756 if (filename != NULL) {
1757 err = dso__load_vmlinux(dso, map, filename, true);
1766 static bool visible_dir_filter(const char *name, struct dirent *d)
1768 if (d->d_type != DT_DIR)
1770 return lsdir_no_dot_filter(name, d);
1773 static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
1775 char kallsyms_filename[PATH_MAX];
1777 struct strlist *dirs;
1778 struct str_node *nd;
1780 dirs = lsdir(dir, visible_dir_filter);
1784 strlist__for_each_entry(nd, dirs) {
1785 scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
1786 "%s/%s/kallsyms", dir, nd->s);
1787 if (!validate_kcore_addresses(kallsyms_filename, map)) {
1788 strlcpy(dir, kallsyms_filename, dir_sz);
1794 strlist__delete(dirs);
1800 * Use open(O_RDONLY) to check readability directly instead of access(R_OK)
1801 * since access(R_OK) only checks with real UID/GID but open() use effective
1802 * UID/GID and actual capabilities (e.g. /proc/kcore requires CAP_SYS_RAWIO).
1804 static bool filename__readable(const char *file)
1806 int fd = open(file, O_RDONLY);
1813 static char *dso__find_kallsyms(struct dso *dso, struct map *map)
1815 u8 host_build_id[BUILD_ID_SIZE];
1816 char sbuild_id[SBUILD_ID_SIZE];
1817 bool is_host = false;
1818 char path[PATH_MAX];
1820 if (!dso->has_build_id) {
1822 * Last resort, if we don't have a build-id and couldn't find
1823 * any vmlinux file, try the running kernel kallsyms table.
1828 if (sysfs__read_build_id("/sys/kernel/notes", host_build_id,
1829 sizeof(host_build_id)) == 0)
1830 is_host = dso__build_id_equal(dso, host_build_id);
1832 /* Try a fast path for /proc/kallsyms if possible */
1835 * Do not check the build-id cache, unless we know we cannot use
1836 * /proc/kcore or module maps don't match to /proc/kallsyms.
1837 * To check readability of /proc/kcore, do not use access(R_OK)
1838 * since /proc/kcore requires CAP_SYS_RAWIO to read and access
1841 if (filename__readable("/proc/kcore") &&
1842 !validate_kcore_addresses("/proc/kallsyms", map))
1846 build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
1848 /* Find kallsyms in build-id cache with kcore */
1849 scnprintf(path, sizeof(path), "%s/%s/%s",
1850 buildid_dir, DSO__NAME_KCORE, sbuild_id);
1852 if (!find_matching_kcore(map, path, sizeof(path)))
1853 return strdup(path);
1855 /* Use current /proc/kallsyms if possible */
1858 return strdup("/proc/kallsyms");
1861 /* Finally, find a cache of kallsyms */
1862 if (!build_id_cache__kallsyms_path(sbuild_id, path, sizeof(path))) {
1863 pr_err("No kallsyms or vmlinux with build-id %s was found\n",
1868 return strdup(path);
1871 static int dso__load_kernel_sym(struct dso *dso, struct map *map)
1874 const char *kallsyms_filename = NULL;
1875 char *kallsyms_allocated_filename = NULL;
1877 * Step 1: if the user specified a kallsyms or vmlinux filename, use
1878 * it and only it, reporting errors to the user if it cannot be used.
1880 * For instance, try to analyse an ARM perf.data file _without_ a
1881 * build-id, or if the user specifies the wrong path to the right
1882 * vmlinux file, obviously we can't fallback to another vmlinux (a
1883 * x86_86 one, on the machine where analysis is being performed, say),
1884 * or worse, /proc/kallsyms.
1886 * If the specified file _has_ a build-id and there is a build-id
1887 * section in the perf.data file, we will still do the expected
1888 * validation in dso__load_vmlinux and will bail out if they don't
1891 if (symbol_conf.kallsyms_name != NULL) {
1892 kallsyms_filename = symbol_conf.kallsyms_name;
1896 if (!symbol_conf.ignore_vmlinux && symbol_conf.vmlinux_name != NULL) {
1897 return dso__load_vmlinux(dso, map, symbol_conf.vmlinux_name, false);
1900 if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) {
1901 err = dso__load_vmlinux_path(dso, map);
1906 /* do not try local files if a symfs was given */
1907 if (symbol_conf.symfs[0] != 0)
1910 kallsyms_allocated_filename = dso__find_kallsyms(dso, map);
1911 if (!kallsyms_allocated_filename)
1914 kallsyms_filename = kallsyms_allocated_filename;
1917 err = dso__load_kallsyms(dso, kallsyms_filename, map);
1919 pr_debug("Using %s for symbols\n", kallsyms_filename);
1920 free(kallsyms_allocated_filename);
1922 if (err > 0 && !dso__is_kcore(dso)) {
1923 dso->binary_type = DSO_BINARY_TYPE__KALLSYMS;
1924 dso__set_long_name(dso, DSO__NAME_KALLSYMS, false);
1925 map__fixup_start(map);
1926 map__fixup_end(map);
1932 static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)
1935 const char *kallsyms_filename = NULL;
1936 struct machine *machine;
1937 char path[PATH_MAX];
1940 pr_debug("Guest kernel map hasn't the point to groups\n");
1943 machine = map->groups->machine;
1945 if (machine__is_default_guest(machine)) {
1947 * if the user specified a vmlinux filename, use it and only
1948 * it, reporting errors to the user if it cannot be used.
1949 * Or use file guest_kallsyms inputted by user on commandline
1951 if (symbol_conf.default_guest_vmlinux_name != NULL) {
1952 err = dso__load_vmlinux(dso, map,
1953 symbol_conf.default_guest_vmlinux_name,
1958 kallsyms_filename = symbol_conf.default_guest_kallsyms;
1959 if (!kallsyms_filename)
1962 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
1963 kallsyms_filename = path;
1966 err = dso__load_kallsyms(dso, kallsyms_filename, map);
1968 pr_debug("Using %s for symbols\n", kallsyms_filename);
1969 if (err > 0 && !dso__is_kcore(dso)) {
1970 dso->binary_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
1971 machine__mmap_name(machine, path, sizeof(path));
1972 dso__set_long_name(dso, strdup(path), true);
1973 map__fixup_start(map);
1974 map__fixup_end(map);
1980 static void vmlinux_path__exit(void)
1982 while (--vmlinux_path__nr_entries >= 0)
1983 zfree(&vmlinux_path[vmlinux_path__nr_entries]);
1984 vmlinux_path__nr_entries = 0;
1986 zfree(&vmlinux_path);
1989 static const char * const vmlinux_paths[] = {
1994 static const char * const vmlinux_paths_upd[] = {
1996 "/usr/lib/debug/boot/vmlinux-%s",
1997 "/lib/modules/%s/build/vmlinux",
1998 "/usr/lib/debug/lib/modules/%s/vmlinux",
1999 "/usr/lib/debug/boot/vmlinux-%s.debug"
2002 static int vmlinux_path__add(const char *new_entry)
2004 vmlinux_path[vmlinux_path__nr_entries] = strdup(new_entry);
2005 if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
2007 ++vmlinux_path__nr_entries;
2012 static int vmlinux_path__init(struct perf_env *env)
2016 char *kernel_version;
2019 vmlinux_path = malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) +
2020 ARRAY_SIZE(vmlinux_paths_upd)));
2021 if (vmlinux_path == NULL)
2024 for (i = 0; i < ARRAY_SIZE(vmlinux_paths); i++)
2025 if (vmlinux_path__add(vmlinux_paths[i]) < 0)
2028 /* only try kernel version if no symfs was given */
2029 if (symbol_conf.symfs[0] != 0)
2033 kernel_version = env->os_release;
2035 if (uname(&uts) < 0)
2038 kernel_version = uts.release;
2041 for (i = 0; i < ARRAY_SIZE(vmlinux_paths_upd); i++) {
2042 snprintf(bf, sizeof(bf), vmlinux_paths_upd[i], kernel_version);
2043 if (vmlinux_path__add(bf) < 0)
2050 vmlinux_path__exit();
2054 int setup_list(struct strlist **list, const char *list_str,
2055 const char *list_name)
2057 if (list_str == NULL)
2060 *list = strlist__new(list_str, NULL);
2062 pr_err("problems parsing %s list\n", list_name);
2066 symbol_conf.has_filter = true;
2070 int setup_intlist(struct intlist **list, const char *list_str,
2071 const char *list_name)
2073 if (list_str == NULL)
2076 *list = intlist__new(list_str);
2078 pr_err("problems parsing %s list\n", list_name);
2084 static bool symbol__read_kptr_restrict(void)
2087 FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
2092 if (fgets(line, sizeof(line), fp) != NULL)
2093 value = ((geteuid() != 0) || (getuid() != 0)) ?
2103 int symbol__annotation_init(void)
2105 if (symbol_conf.init_annotation)
2108 if (symbol_conf.initialized) {
2109 pr_err("Annotation needs to be init before symbol__init()\n");
2113 symbol_conf.priv_size += sizeof(struct annotation);
2114 symbol_conf.init_annotation = true;
2118 int symbol__init(struct perf_env *env)
2122 if (symbol_conf.initialized)
2125 symbol_conf.priv_size = PERF_ALIGN(symbol_conf.priv_size, sizeof(u64));
2129 if (symbol_conf.sort_by_name)
2130 symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
2131 sizeof(struct symbol));
2133 if (symbol_conf.try_vmlinux_path && vmlinux_path__init(env) < 0)
2136 if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') {
2137 pr_err("'.' is the only non valid --field-separator argument\n");
2141 if (setup_list(&symbol_conf.dso_list,
2142 symbol_conf.dso_list_str, "dso") < 0)
2145 if (setup_list(&symbol_conf.comm_list,
2146 symbol_conf.comm_list_str, "comm") < 0)
2147 goto out_free_dso_list;
2149 if (setup_intlist(&symbol_conf.pid_list,
2150 symbol_conf.pid_list_str, "pid") < 0)
2151 goto out_free_comm_list;
2153 if (setup_intlist(&symbol_conf.tid_list,
2154 symbol_conf.tid_list_str, "tid") < 0)
2155 goto out_free_pid_list;
2157 if (setup_list(&symbol_conf.sym_list,
2158 symbol_conf.sym_list_str, "symbol") < 0)
2159 goto out_free_tid_list;
2161 if (setup_list(&symbol_conf.bt_stop_list,
2162 symbol_conf.bt_stop_list_str, "symbol") < 0)
2163 goto out_free_sym_list;
2166 * A path to symbols of "/" is identical to ""
2167 * reset here for simplicity.
2169 symfs = realpath(symbol_conf.symfs, NULL);
2171 symfs = symbol_conf.symfs;
2172 if (strcmp(symfs, "/") == 0)
2173 symbol_conf.symfs = "";
2174 if (symfs != symbol_conf.symfs)
2175 free((void *)symfs);
2177 symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
2179 symbol_conf.initialized = true;
2183 strlist__delete(symbol_conf.sym_list);
2185 intlist__delete(symbol_conf.tid_list);
2187 intlist__delete(symbol_conf.pid_list);
2189 strlist__delete(symbol_conf.comm_list);
2191 strlist__delete(symbol_conf.dso_list);
2195 void symbol__exit(void)
2197 if (!symbol_conf.initialized)
2199 strlist__delete(symbol_conf.bt_stop_list);
2200 strlist__delete(symbol_conf.sym_list);
2201 strlist__delete(symbol_conf.dso_list);
2202 strlist__delete(symbol_conf.comm_list);
2203 intlist__delete(symbol_conf.tid_list);
2204 intlist__delete(symbol_conf.pid_list);
2205 vmlinux_path__exit();
2206 symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
2207 symbol_conf.bt_stop_list = NULL;
2208 symbol_conf.initialized = false;
2211 int symbol__config_symfs(const struct option *opt __maybe_unused,
2212 const char *dir, int unset __maybe_unused)
2217 symbol_conf.symfs = strdup(dir);
2218 if (symbol_conf.symfs == NULL)
2221 /* skip the locally configured cache if a symfs is given, and
2222 * config buildid dir to symfs/.debug
2224 ret = asprintf(&bf, "%s/%s", dir, ".debug");
2228 set_buildid_dir(bf);