sym-handling.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
  7. */
  8. #include "debug.h"
  9. #include "symbol.h"
  10. #include "map.h"
  11. #include "probe-event.h"
  12. #include "probe-file.h"
  13. #ifdef HAVE_LIBELF_SUPPORT
  14. bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
  15. {
  16. return ehdr.e_type == ET_EXEC ||
  17. ehdr.e_type == ET_REL ||
  18. ehdr.e_type == ET_DYN;
  19. }
  20. #endif
  21. #if !defined(_CALL_ELF) || _CALL_ELF != 2
  22. int arch__choose_best_symbol(struct symbol *syma,
  23. struct symbol *symb __maybe_unused)
  24. {
  25. char *sym = syma->name;
  26. /* Skip over any initial dot */
  27. if (*sym == '.')
  28. sym++;
  29. /* Avoid "SyS" kernel syscall aliases */
  30. if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
  31. return SYMBOL_B;
  32. if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
  33. return SYMBOL_B;
  34. return SYMBOL_A;
  35. }
  36. /* Allow matching against dot variants */
  37. int arch__compare_symbol_names(const char *namea, const char *nameb)
  38. {
  39. /* Skip over initial dot */
  40. if (*namea == '.')
  41. namea++;
  42. if (*nameb == '.')
  43. nameb++;
  44. return strcmp(namea, nameb);
  45. }
  46. #endif
  47. #if defined(_CALL_ELF) && _CALL_ELF == 2
  48. #ifdef HAVE_LIBELF_SUPPORT
  49. void arch__sym_update(struct symbol *s, GElf_Sym *sym)
  50. {
  51. s->arch_sym = sym->st_other;
  52. }
  53. #endif
  54. #define PPC64LE_LEP_OFFSET 8
  55. void arch__fix_tev_from_maps(struct perf_probe_event *pev,
  56. struct probe_trace_event *tev, struct map *map,
  57. struct symbol *sym)
  58. {
  59. int lep_offset;
  60. /*
  61. * When probing at a function entry point, we normally always want the
  62. * LEP since that catches calls to the function through both the GEP and
  63. * the LEP. Hence, we would like to probe at an offset of 8 bytes if
  64. * the user only specified the function entry.
  65. *
  66. * However, if the user specifies an offset, we fall back to using the
  67. * GEP since all userspace applications (objdump/readelf) show function
  68. * disassembly with offsets from the GEP.
  69. */
  70. if (pev->point.offset || !map || !sym)
  71. return;
  72. /* For kretprobes, add an offset only if the kernel supports it */
  73. if (!pev->uprobes && pev->point.retprobe) {
  74. #ifdef HAVE_LIBELF_SUPPORT
  75. if (!kretprobe_offset_is_supported())
  76. #endif
  77. return;
  78. }
  79. lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym);
  80. if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS)
  81. tev->point.offset += PPC64LE_LEP_OFFSET;
  82. else if (lep_offset) {
  83. if (pev->uprobes)
  84. tev->point.address += lep_offset;
  85. else
  86. tev->point.offset += lep_offset;
  87. }
  88. }
  89. #ifdef HAVE_LIBELF_SUPPORT
  90. void arch__post_process_probe_trace_events(struct perf_probe_event *pev,
  91. int ntevs)
  92. {
  93. struct probe_trace_event *tev;
  94. struct map *map;
  95. struct symbol *sym = NULL;
  96. struct rb_node *tmp;
  97. int i = 0;
  98. map = get_target_map(pev->target, pev->uprobes);
  99. if (!map || map__load(map) < 0)
  100. return;
  101. for (i = 0; i < ntevs; i++) {
  102. tev = &pev->tevs[i];
  103. map__for_each_symbol(map, sym, tmp) {
  104. if (map->unmap_ip(map, sym->start) == tev->point.address)
  105. arch__fix_tev_from_maps(pev, tev, map, sym);
  106. }
  107. }
  108. }
  109. #endif /* HAVE_LIBELF_SUPPORT */
  110. #endif