sym-handling.c 3.0 KB

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