aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c104
1 files changed, 52 insertions, 52 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 0b9862351260..3159d47ae1cc 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -21,7 +21,7 @@ enum dso_origin {
21 21
22static struct symbol *symbol__new(u64 start, u64 len, 22static struct symbol *symbol__new(u64 start, u64 len,
23 const char *name, unsigned int priv_size, 23 const char *name, unsigned int priv_size,
24 u64 obj_start, int verbose) 24 u64 obj_start, int v)
25{ 25{
26 size_t namelen = strlen(name) + 1; 26 size_t namelen = strlen(name) + 1;
27 struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen); 27 struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen);
@@ -29,7 +29,7 @@ static struct symbol *symbol__new(u64 start, u64 len,
29 if (!self) 29 if (!self)
30 return NULL; 30 return NULL;
31 31
32 if (verbose >= 2) 32 if (v >= 2)
33 printf("new symbol: %016Lx [%08lx]: %s, hist: %p, obj_start: %p\n", 33 printf("new symbol: %016Lx [%08lx]: %s, hist: %p, obj_start: %p\n",
34 (u64)start, (unsigned long)len, name, self->hist, (void *)(unsigned long)obj_start); 34 (u64)start, (unsigned long)len, name, self->hist, (void *)(unsigned long)obj_start);
35 35
@@ -156,7 +156,7 @@ size_t dso__fprintf(struct dso *self, FILE *fp)
156 return ret; 156 return ret;
157} 157}
158 158
159static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int verbose) 159static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int v)
160{ 160{
161 struct rb_node *nd, *prevnd; 161 struct rb_node *nd, *prevnd;
162 char *line = NULL; 162 char *line = NULL;
@@ -198,7 +198,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter, int verb
198 * Well fix up the end later, when we have all sorted. 198 * Well fix up the end later, when we have all sorted.
199 */ 199 */
200 sym = symbol__new(start, 0xdead, line + len + 2, 200 sym = symbol__new(start, 0xdead, line + len + 2,
201 self->sym_priv_size, 0, verbose); 201 self->sym_priv_size, 0, v);
202 202
203 if (sym == NULL) 203 if (sym == NULL)
204 goto out_delete_line; 204 goto out_delete_line;
@@ -239,7 +239,7 @@ out_failure:
239 return -1; 239 return -1;
240} 240}
241 241
242static int dso__load_perf_map(struct dso *self, symbol_filter_t filter, int verbose) 242static int dso__load_perf_map(struct dso *self, symbol_filter_t filter, int v)
243{ 243{
244 char *line = NULL; 244 char *line = NULL;
245 size_t n; 245 size_t n;
@@ -277,7 +277,7 @@ static int dso__load_perf_map(struct dso *self, symbol_filter_t filter, int verb
277 continue; 277 continue;
278 278
279 sym = symbol__new(start, size, line + len, 279 sym = symbol__new(start, size, line + len,
280 self->sym_priv_size, start, verbose); 280 self->sym_priv_size, start, v);
281 281
282 if (sym == NULL) 282 if (sym == NULL)
283 goto out_delete_line; 283 goto out_delete_line;
@@ -305,13 +305,13 @@ out_failure:
305 * elf_symtab__for_each_symbol - iterate thru all the symbols 305 * elf_symtab__for_each_symbol - iterate thru all the symbols
306 * 306 *
307 * @self: struct elf_symtab instance to iterate 307 * @self: struct elf_symtab instance to iterate
308 * @index: uint32_t index 308 * @idx: uint32_t idx
309 * @sym: GElf_Sym iterator 309 * @sym: GElf_Sym iterator
310 */ 310 */
311#define elf_symtab__for_each_symbol(syms, nr_syms, index, sym) \ 311#define elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) \
312 for (index = 0, gelf_getsym(syms, index, &sym);\ 312 for (idx = 0, gelf_getsym(syms, idx, &sym);\
313 index < nr_syms; \ 313 idx < nr_syms; \
314 index++, gelf_getsym(syms, index, &sym)) 314 idx++, gelf_getsym(syms, idx, &sym))
315 315
316static inline uint8_t elf_sym__type(const GElf_Sym *sym) 316static inline uint8_t elf_sym__type(const GElf_Sym *sym)
317{ 317{
@@ -354,7 +354,7 @@ static inline const char *elf_sym__name(const GElf_Sym *sym,
354 354
355static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, 355static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
356 GElf_Shdr *shp, const char *name, 356 GElf_Shdr *shp, const char *name,
357 size_t *index) 357 size_t *idx)
358{ 358{
359 Elf_Scn *sec = NULL; 359 Elf_Scn *sec = NULL;
360 size_t cnt = 1; 360 size_t cnt = 1;
@@ -365,8 +365,8 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
365 gelf_getshdr(sec, shp); 365 gelf_getshdr(sec, shp);
366 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name); 366 str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
367 if (!strcmp(name, str)) { 367 if (!strcmp(name, str)) {
368 if (index) 368 if (idx)
369 *index = cnt; 369 *idx = cnt;
370 break; 370 break;
371 } 371 }
372 ++cnt; 372 ++cnt;
@@ -392,7 +392,7 @@ static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
392 * And always look at the original dso, not at debuginfo packages, that 392 * And always look at the original dso, not at debuginfo packages, that
393 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS). 393 * have the PLT data stripped out (shdr_rel_plt.sh_type == SHT_NOBITS).
394 */ 394 */
395static int dso__synthesize_plt_symbols(struct dso *self, int verbose) 395static int dso__synthesize_plt_symbols(struct dso *self, int v)
396{ 396{
397 uint32_t nr_rel_entries, idx; 397 uint32_t nr_rel_entries, idx;
398 GElf_Sym sym; 398 GElf_Sym sym;
@@ -442,7 +442,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
442 goto out_elf_end; 442 goto out_elf_end;
443 443
444 /* 444 /*
445 * Fetch the relocation section to find the indexes to the GOT 445 * Fetch the relocation section to find the idxes to the GOT
446 * and the symbols in the .dynsym they refer to. 446 * and the symbols in the .dynsym they refer to.
447 */ 447 */
448 reldata = elf_getdata(scn_plt_rel, NULL); 448 reldata = elf_getdata(scn_plt_rel, NULL);
@@ -476,7 +476,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
476 "%s@plt", elf_sym__name(&sym, symstrs)); 476 "%s@plt", elf_sym__name(&sym, symstrs));
477 477
478 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 478 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
479 sympltname, self->sym_priv_size, 0, verbose); 479 sympltname, self->sym_priv_size, 0, v);
480 if (!f) 480 if (!f)
481 goto out_elf_end; 481 goto out_elf_end;
482 482
@@ -494,7 +494,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int verbose)
494 "%s@plt", elf_sym__name(&sym, symstrs)); 494 "%s@plt", elf_sym__name(&sym, symstrs));
495 495
496 f = symbol__new(plt_offset, shdr_plt.sh_entsize, 496 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
497 sympltname, self->sym_priv_size, 0, verbose); 497 sympltname, self->sym_priv_size, 0, v);
498 if (!f) 498 if (!f)
499 goto out_elf_end; 499 goto out_elf_end;
500 500
@@ -518,12 +518,12 @@ out:
518} 518}
519 519
520static int dso__load_sym(struct dso *self, int fd, const char *name, 520static int dso__load_sym(struct dso *self, int fd, const char *name,
521 symbol_filter_t filter, int verbose, struct module *mod) 521 symbol_filter_t filter, int v, struct module *mod)
522{ 522{
523 Elf_Data *symstrs, *secstrs; 523 Elf_Data *symstrs, *secstrs;
524 uint32_t nr_syms; 524 uint32_t nr_syms;
525 int err = -1; 525 int err = -1;
526 uint32_t index; 526 uint32_t idx;
527 GElf_Ehdr ehdr; 527 GElf_Ehdr ehdr;
528 GElf_Shdr shdr; 528 GElf_Shdr shdr;
529 Elf_Data *syms; 529 Elf_Data *syms;
@@ -534,14 +534,14 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
534 534
535 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); 535 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
536 if (elf == NULL) { 536 if (elf == NULL) {
537 if (verbose) 537 if (v)
538 fprintf(stderr, "%s: cannot read %s ELF file.\n", 538 fprintf(stderr, "%s: cannot read %s ELF file.\n",
539 __func__, name); 539 __func__, name);
540 goto out_close; 540 goto out_close;
541 } 541 }
542 542
543 if (gelf_getehdr(elf, &ehdr) == NULL) { 543 if (gelf_getehdr(elf, &ehdr) == NULL) {
544 if (verbose) 544 if (v)
545 fprintf(stderr, "%s: cannot get elf header.\n", __func__); 545 fprintf(stderr, "%s: cannot get elf header.\n", __func__);
546 goto out_elf_end; 546 goto out_elf_end;
547 } 547 }
@@ -583,9 +583,9 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
583 NULL) != NULL); 583 NULL) != NULL);
584 } else self->adjust_symbols = 0; 584 } else self->adjust_symbols = 0;
585 585
586 elf_symtab__for_each_symbol(syms, nr_syms, index, sym) { 586 elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) {
587 struct symbol *f; 587 struct symbol *f;
588 const char *name; 588 const char *elf_name;
589 char *demangled; 589 char *demangled;
590 u64 obj_start; 590 u64 obj_start;
591 struct section *section = NULL; 591 struct section *section = NULL;
@@ -608,7 +608,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
608 obj_start = sym.st_value; 608 obj_start = sym.st_value;
609 609
610 if (self->adjust_symbols) { 610 if (self->adjust_symbols) {
611 if (verbose >= 2) 611 if (v >= 2)
612 printf("adjusting symbol: st_value: %Lx sh_addr: %Lx sh_offset: %Lx\n", 612 printf("adjusting symbol: st_value: %Lx sh_addr: %Lx sh_offset: %Lx\n",
613 (u64)sym.st_value, (u64)shdr.sh_addr, (u64)shdr.sh_offset); 613 (u64)sym.st_value, (u64)shdr.sh_addr, (u64)shdr.sh_offset);
614 614
@@ -630,13 +630,13 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
630 * DWARF DW_compile_unit has this, but we don't always have access 630 * DWARF DW_compile_unit has this, but we don't always have access
631 * to it... 631 * to it...
632 */ 632 */
633 name = elf_sym__name(&sym, symstrs); 633 elf_name = elf_sym__name(&sym, symstrs);
634 demangled = bfd_demangle(NULL, name, DMGL_PARAMS | DMGL_ANSI); 634 demangled = bfd_demangle(NULL, elf_name, DMGL_PARAMS | DMGL_ANSI);
635 if (demangled != NULL) 635 if (demangled != NULL)
636 name = demangled; 636 elf_name = demangled;
637 637
638 f = symbol__new(sym.st_value, sym.st_size, name, 638 f = symbol__new(sym.st_value, sym.st_size, elf_name,
639 self->sym_priv_size, obj_start, verbose); 639 self->sym_priv_size, obj_start, v);
640 free(demangled); 640 free(demangled);
641 if (!f) 641 if (!f)
642 goto out_elf_end; 642 goto out_elf_end;
@@ -659,7 +659,7 @@ out_close:
659 659
660#define BUILD_ID_SIZE 128 660#define BUILD_ID_SIZE 128
661 661
662static char *dso__read_build_id(struct dso *self, int verbose) 662static char *dso__read_build_id(struct dso *self, int v)
663{ 663{
664 int i; 664 int i;
665 GElf_Ehdr ehdr; 665 GElf_Ehdr ehdr;
@@ -676,14 +676,14 @@ static char *dso__read_build_id(struct dso *self, int verbose)
676 676
677 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); 677 elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
678 if (elf == NULL) { 678 if (elf == NULL) {
679 if (verbose) 679 if (v)
680 fprintf(stderr, "%s: cannot read %s ELF file.\n", 680 fprintf(stderr, "%s: cannot read %s ELF file.\n",
681 __func__, self->name); 681 __func__, self->name);
682 goto out_close; 682 goto out_close;
683 } 683 }
684 684
685 if (gelf_getehdr(elf, &ehdr) == NULL) { 685 if (gelf_getehdr(elf, &ehdr) == NULL) {
686 if (verbose) 686 if (v)
687 fprintf(stderr, "%s: cannot get elf header.\n", __func__); 687 fprintf(stderr, "%s: cannot get elf header.\n", __func__);
688 goto out_elf_end; 688 goto out_elf_end;
689 } 689 }
@@ -706,7 +706,7 @@ static char *dso__read_build_id(struct dso *self, int verbose)
706 ++raw; 706 ++raw;
707 bid += 2; 707 bid += 2;
708 } 708 }
709 if (verbose >= 2) 709 if (v >= 2)
710 printf("%s(%s): %s\n", __func__, self->name, build_id); 710 printf("%s(%s): %s\n", __func__, self->name, build_id);
711out_elf_end: 711out_elf_end:
712 elf_end(elf); 712 elf_end(elf);
@@ -732,7 +732,7 @@ char dso__symtab_origin(const struct dso *self)
732 return origin[self->origin]; 732 return origin[self->origin];
733} 733}
734 734
735int dso__load(struct dso *self, symbol_filter_t filter, int verbose) 735int dso__load(struct dso *self, symbol_filter_t filter, int v)
736{ 736{
737 int size = PATH_MAX; 737 int size = PATH_MAX;
738 char *name = malloc(size), *build_id = NULL; 738 char *name = malloc(size), *build_id = NULL;
@@ -745,7 +745,7 @@ int dso__load(struct dso *self, symbol_filter_t filter, int verbose)
745 self->adjust_symbols = 0; 745 self->adjust_symbols = 0;
746 746
747 if (strncmp(self->name, "/tmp/perf-", 10) == 0) { 747 if (strncmp(self->name, "/tmp/perf-", 10) == 0) {
748 ret = dso__load_perf_map(self, filter, verbose); 748 ret = dso__load_perf_map(self, filter, v);
749 self->origin = ret > 0 ? DSO__ORIG_JAVA_JIT : 749 self->origin = ret > 0 ? DSO__ORIG_JAVA_JIT :
750 DSO__ORIG_NOT_FOUND; 750 DSO__ORIG_NOT_FOUND;
751 return ret; 751 return ret;
@@ -764,7 +764,7 @@ more:
764 snprintf(name, size, "/usr/lib/debug%s", self->name); 764 snprintf(name, size, "/usr/lib/debug%s", self->name);
765 break; 765 break;
766 case DSO__ORIG_BUILDID: 766 case DSO__ORIG_BUILDID:
767 build_id = dso__read_build_id(self, verbose); 767 build_id = dso__read_build_id(self, v);
768 if (build_id != NULL) { 768 if (build_id != NULL) {
769 snprintf(name, size, 769 snprintf(name, size,
770 "/usr/lib/debug/.build-id/%.2s/%s.debug", 770 "/usr/lib/debug/.build-id/%.2s/%s.debug",
@@ -785,7 +785,7 @@ more:
785 fd = open(name, O_RDONLY); 785 fd = open(name, O_RDONLY);
786 } while (fd < 0); 786 } while (fd < 0);
787 787
788 ret = dso__load_sym(self, fd, name, filter, verbose, NULL); 788 ret = dso__load_sym(self, fd, name, filter, v, NULL);
789 close(fd); 789 close(fd);
790 790
791 /* 791 /*
@@ -795,7 +795,7 @@ more:
795 goto more; 795 goto more;
796 796
797 if (ret > 0) { 797 if (ret > 0) {
798 int nr_plt = dso__synthesize_plt_symbols(self, verbose); 798 int nr_plt = dso__synthesize_plt_symbols(self, v);
799 if (nr_plt > 0) 799 if (nr_plt > 0)
800 ret += nr_plt; 800 ret += nr_plt;
801 } 801 }
@@ -807,7 +807,7 @@ out:
807} 807}
808 808
809static int dso__load_module(struct dso *self, struct mod_dso *mods, const char *name, 809static int dso__load_module(struct dso *self, struct mod_dso *mods, const char *name,
810 symbol_filter_t filter, int verbose) 810 symbol_filter_t filter, int v)
811{ 811{
812 struct module *mod = mod_dso__find_module(mods, name); 812 struct module *mod = mod_dso__find_module(mods, name);
813 int err = 0, fd; 813 int err = 0, fd;
@@ -820,13 +820,13 @@ static int dso__load_module(struct dso *self, struct mod_dso *mods, const char *
820 if (fd < 0) 820 if (fd < 0)
821 return err; 821 return err;
822 822
823 err = dso__load_sym(self, fd, name, filter, verbose, mod); 823 err = dso__load_sym(self, fd, name, filter, v, mod);
824 close(fd); 824 close(fd);
825 825
826 return err; 826 return err;
827} 827}
828 828
829int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose) 829int dso__load_modules(struct dso *self, symbol_filter_t filter, int v)
830{ 830{
831 struct mod_dso *mods = mod_dso__new_dso("modules"); 831 struct mod_dso *mods = mod_dso__new_dso("modules");
832 struct module *pos; 832 struct module *pos;
@@ -844,7 +844,7 @@ int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose)
844 next = rb_first(&mods->mods); 844 next = rb_first(&mods->mods);
845 while (next) { 845 while (next) {
846 pos = rb_entry(next, struct module, rb_node); 846 pos = rb_entry(next, struct module, rb_node);
847 err = dso__load_module(self, mods, pos->name, filter, verbose); 847 err = dso__load_module(self, mods, pos->name, filter, v);
848 848
849 if (err < 0) 849 if (err < 0)
850 break; 850 break;
@@ -887,14 +887,14 @@ static inline void dso__fill_symbol_holes(struct dso *self)
887} 887}
888 888
889static int dso__load_vmlinux(struct dso *self, const char *vmlinux, 889static int dso__load_vmlinux(struct dso *self, const char *vmlinux,
890 symbol_filter_t filter, int verbose) 890 symbol_filter_t filter, int v)
891{ 891{
892 int err, fd = open(vmlinux, O_RDONLY); 892 int err, fd = open(vmlinux, O_RDONLY);
893 893
894 if (fd < 0) 894 if (fd < 0)
895 return -1; 895 return -1;
896 896
897 err = dso__load_sym(self, fd, vmlinux, filter, verbose, NULL); 897 err = dso__load_sym(self, fd, vmlinux, filter, v, NULL);
898 898
899 if (err > 0) 899 if (err > 0)
900 dso__fill_symbol_holes(self); 900 dso__fill_symbol_holes(self);
@@ -905,18 +905,18 @@ static int dso__load_vmlinux(struct dso *self, const char *vmlinux,
905} 905}
906 906
907int dso__load_kernel(struct dso *self, const char *vmlinux, 907int dso__load_kernel(struct dso *self, const char *vmlinux,
908 symbol_filter_t filter, int verbose, int modules) 908 symbol_filter_t filter, int v, int use_modules)
909{ 909{
910 int err = -1; 910 int err = -1;
911 911
912 if (vmlinux) { 912 if (vmlinux) {
913 err = dso__load_vmlinux(self, vmlinux, filter, verbose); 913 err = dso__load_vmlinux(self, vmlinux, filter, v);
914 if (err > 0 && modules) 914 if (err > 0 && use_modules)
915 err = dso__load_modules(self, filter, verbose); 915 err = dso__load_modules(self, filter, v);
916 } 916 }
917 917
918 if (err <= 0) 918 if (err <= 0)
919 err = dso__load_kallsyms(self, filter, verbose); 919 err = dso__load_kallsyms(self, filter, v);
920 920
921 if (err > 0) 921 if (err > 0)
922 self->origin = DSO__ORIG_KERNEL; 922 self->origin = DSO__ORIG_KERNEL;
@@ -929,7 +929,7 @@ struct dso *kernel_dso;
929struct dso *vdso; 929struct dso *vdso;
930struct dso *hypervisor_dso; 930struct dso *hypervisor_dso;
931 931
932char *vmlinux = "vmlinux"; 932const char *vmlinux_name = "vmlinux";
933int modules; 933int modules;
934 934
935static void dsos__add(struct dso *dso) 935static void dsos__add(struct dso *dso)
@@ -997,7 +997,7 @@ int load_kernel(void)
997 if (!kernel_dso) 997 if (!kernel_dso)
998 return -1; 998 return -1;
999 999
1000 err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules); 1000 err = dso__load_kernel(kernel_dso, vmlinux_name, NULL, verbose, modules);
1001 if (err <= 0) { 1001 if (err <= 0) {
1002 dso__delete(kernel_dso); 1002 dso__delete(kernel_dso);
1003 kernel_dso = NULL; 1003 kernel_dso = NULL;