sym-handling.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #if defined(_CALL_ELF) && _CALL_ELF == 2
  20. void arch__elf_sym_adjust(GElf_Sym *sym)
  21. {
  22. sym->st_value += PPC64_LOCAL_ENTRY_OFFSET(sym->st_other);
  23. }
  24. #endif
  25. #endif
  26. #if !defined(_CALL_ELF) || _CALL_ELF != 2
  27. int arch__choose_best_symbol(struct symbol *syma,
  28. struct symbol *symb __maybe_unused)
  29. {
  30. char *sym = syma->name;
  31. /* Skip over any initial dot */
  32. if (*sym == '.')
  33. sym++;
  34. /* Avoid "SyS" kernel syscall aliases */
  35. if (strlen(sym) >= 3 && !strncmp(sym, "SyS", 3))
  36. return SYMBOL_B;
  37. if (strlen(sym) >= 10 && !strncmp(sym, "compat_SyS", 10))
  38. return SYMBOL_B;
  39. return SYMBOL_A;
  40. }
  41. /* Allow matching against dot variants */
  42. int arch__compare_symbol_names(const char *namea, const char *nameb)
  43. {
  44. /* Skip over initial dot */
  45. if (*namea == '.')
  46. namea++;
  47. if (*nameb == '.')
  48. nameb++;
  49. return strcmp(namea, nameb);
  50. }
  51. #endif
  52. #if defined(_CALL_ELF) && _CALL_ELF == 2
  53. bool arch__prefers_symtab(void)
  54. {
  55. return true;
  56. }
  57. #define PPC64LE_LEP_OFFSET 8
  58. void arch__fix_tev_from_maps(struct perf_probe_event *pev,
  59. struct probe_trace_event *tev, struct map *map)
  60. {
  61. /*
  62. * ppc64 ABIv2 local entry point is currently always 2 instructions
  63. * (8 bytes) after the global entry point.
  64. */
  65. if (!pev->uprobes && map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) {
  66. tev->point.address += PPC64LE_LEP_OFFSET;
  67. tev->point.offset += PPC64LE_LEP_OFFSET;
  68. }
  69. }
  70. #endif