Naveen N. Rao | d233209 | 2015-04-28 17:35:35 +0530 | [diff] [blame] | 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 | |
| 9 | #include "debug.h" |
| 10 | #include "symbol.h" |
Naveen N. Rao | 031b84c | 2015-04-28 17:35:37 +0530 | [diff] [blame] | 11 | #include "map.h" |
Naveen N. Rao | d5c2e2c | 2015-04-28 17:35:39 +0530 | [diff] [blame] | 12 | #include "probe-event.h" |
Naveen N. Rao | d233209 | 2015-04-28 17:35:35 +0530 | [diff] [blame] | 13 | |
| 14 | #ifdef HAVE_LIBELF_SUPPORT |
| 15 | bool elf__needs_adjust_symbols(GElf_Ehdr ehdr) |
| 16 | { |
| 17 | return ehdr.e_type == ET_EXEC || |
| 18 | ehdr.e_type == ET_REL || |
| 19 | ehdr.e_type == ET_DYN; |
| 20 | } |
Ananth N Mavinakayanahalli | c50fc0a | 2015-04-28 17:35:38 +0530 | [diff] [blame] | 21 | |
Naveen N. Rao | d233209 | 2015-04-28 17:35:35 +0530 | [diff] [blame] | 22 | #endif |
Naveen N. Rao | fb6d594 | 2015-04-28 17:35:36 +0530 | [diff] [blame] | 23 | |
| 24 | #if !defined(_CALL_ELF) || _CALL_ELF != 2 |
| 25 | int arch__choose_best_symbol(struct symbol *syma, |
| 26 | struct symbol *symb __maybe_unused) |
| 27 | { |
| 28 | char *sym = syma->name; |
| 29 | |
| 30 | /* Skip over any initial dot */ |
| 31 | if (*sym == '.') |
| 32 | sym++; |
| 33 | |
| 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 | |
| 40 | return SYMBOL_A; |
| 41 | } |
Naveen N. Rao | 031b84c | 2015-04-28 17:35:37 +0530 | [diff] [blame] | 42 | |
| 43 | /* Allow matching against dot variants */ |
| 44 | int arch__compare_symbol_names(const char *namea, const char *nameb) |
| 45 | { |
| 46 | /* Skip over initial dot */ |
| 47 | if (*namea == '.') |
| 48 | namea++; |
| 49 | if (*nameb == '.') |
| 50 | nameb++; |
| 51 | |
| 52 | return strcmp(namea, nameb); |
| 53 | } |
Naveen N. Rao | fb6d594 | 2015-04-28 17:35:36 +0530 | [diff] [blame] | 54 | #endif |
Naveen N. Rao | d5c2e2c | 2015-04-28 17:35:39 +0530 | [diff] [blame] | 55 | |
| 56 | #if defined(_CALL_ELF) && _CALL_ELF == 2 |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 57 | |
Naveen N. Rao | 0b3c226 | 2016-04-12 14:40:50 +0530 | [diff] [blame] | 58 | #ifdef HAVE_LIBELF_SUPPORT |
| 59 | void arch__sym_update(struct symbol *s, GElf_Sym *sym) |
| 60 | { |
| 61 | s->arch_sym = sym->st_other; |
| 62 | } |
| 63 | #endif |
| 64 | |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 65 | #define PPC64LE_LEP_OFFSET 8 |
| 66 | |
| 67 | void arch__fix_tev_from_maps(struct perf_probe_event *pev, |
Naveen N. Rao | 0b3c226 | 2016-04-12 14:40:50 +0530 | [diff] [blame] | 68 | struct probe_trace_event *tev, struct map *map, |
| 69 | struct symbol *sym) |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 70 | { |
Naveen N. Rao | 0b3c226 | 2016-04-12 14:40:50 +0530 | [diff] [blame] | 71 | int lep_offset; |
| 72 | |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 73 | /* |
Naveen N. Rao | 239aeba | 2016-04-12 14:40:49 +0530 | [diff] [blame] | 74 | * When probing at a function entry point, we normally always want the |
| 75 | * LEP since that catches calls to the function through both the GEP and |
| 76 | * the LEP. Hence, we would like to probe at an offset of 8 bytes if |
| 77 | * the user only specified the function entry. |
| 78 | * |
| 79 | * However, if the user specifies an offset, we fall back to using the |
| 80 | * GEP since all userspace applications (objdump/readelf) show function |
| 81 | * disassembly with offsets from the GEP. |
| 82 | * |
| 83 | * In addition, we shouldn't specify an offset for kretprobes. |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 84 | */ |
Naveen N. Rao | 0b3c226 | 2016-04-12 14:40:50 +0530 | [diff] [blame] | 85 | if (pev->point.offset || pev->point.retprobe || !map || !sym) |
Naveen N. Rao | 239aeba | 2016-04-12 14:40:49 +0530 | [diff] [blame] | 86 | return; |
| 87 | |
Naveen N. Rao | 0b3c226 | 2016-04-12 14:40:50 +0530 | [diff] [blame] | 88 | lep_offset = PPC64_LOCAL_ENTRY_OFFSET(sym->arch_sym); |
| 89 | |
Naveen N. Rao | 239aeba | 2016-04-12 14:40:49 +0530 | [diff] [blame] | 90 | if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 91 | tev->point.offset += PPC64LE_LEP_OFFSET; |
Naveen N. Rao | 0b3c226 | 2016-04-12 14:40:50 +0530 | [diff] [blame] | 92 | else if (lep_offset) { |
| 93 | if (pev->uprobes) |
| 94 | tev->point.address += lep_offset; |
| 95 | else |
| 96 | tev->point.offset += lep_offset; |
| 97 | } |
Naveen N. Rao | 7b6ff0b | 2015-04-28 17:35:40 +0530 | [diff] [blame] | 98 | } |
Ravi Bangoria | 99e608b | 2016-08-09 01:23:25 -0500 | [diff] [blame] | 99 | |
Ravi Bangoria | f046f3d | 2016-08-11 14:43:59 -0300 | [diff] [blame] | 100 | #ifdef HAVE_LIBELF_SUPPORT |
Ravi Bangoria | 99e608b | 2016-08-09 01:23:25 -0500 | [diff] [blame] | 101 | void arch__post_process_probe_trace_events(struct perf_probe_event *pev, |
| 102 | int ntevs) |
| 103 | { |
| 104 | struct probe_trace_event *tev; |
| 105 | struct map *map; |
| 106 | struct symbol *sym = NULL; |
| 107 | struct rb_node *tmp; |
| 108 | int i = 0; |
| 109 | |
| 110 | map = get_target_map(pev->target, pev->uprobes); |
| 111 | if (!map || map__load(map, NULL) < 0) |
| 112 | return; |
| 113 | |
| 114 | for (i = 0; i < ntevs; i++) { |
| 115 | tev = &pev->tevs[i]; |
| 116 | map__for_each_symbol(map, sym, tmp) { |
| 117 | if (map->unmap_ip(map, sym->start) == tev->point.address) |
| 118 | arch__fix_tev_from_maps(pev, tev, map, sym); |
| 119 | } |
| 120 | } |
| 121 | } |
Ravi Bangoria | f046f3d | 2016-08-11 14:43:59 -0300 | [diff] [blame] | 122 | #endif /* HAVE_LIBELF_SUPPORT */ |
Ravi Bangoria | 99e608b | 2016-08-09 01:23:25 -0500 | [diff] [blame] | 123 | |
Naveen N. Rao | d5c2e2c | 2015-04-28 17:35:39 +0530 | [diff] [blame] | 124 | #endif |